|  |  |  | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponse; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
|---|
|  |  |  | import com.dy.common.webUtil.QueryResultVo; | 
|---|
|  |  |  | import com.dy.pmsGlobal.aop.Log; | 
|---|
|  |  |  | import com.dy.pmsGlobal.pojoBa.BaRole; | 
|---|
|  |  |  | import com.dy.pmsGlobal.pojoBa.BaUser; | 
|---|
|  |  |  | import com.dy.pmsGlobal.util.Constant; | 
|---|
|  |  |  | import com.mysql.cj.util.StringUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.http.MediaType; | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | import org.springframework.validation.annotation.Validated; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | //@SsoAop() //只有登录验证,没有权限验证 | 
|---|
|  |  |  | @SsoPowerAop(power = "10100010") //登录与权限同时验证 | 
|---|
|  |  |  | @SsoPowerAop(power = "10100000") //登录与权限同时验证 | 
|---|
|  |  |  | @Log("查询用户") | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<BaUser>>> some(@RequestBody QueryVo vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<BaUser>> res = this.sv.selectSome(vo); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryResultVo<List<BaUser>> res = this.sv.selectSome(vo); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | //@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE)//指前端向后传的参数类型 | 
|---|
|  |  |  | @GetMapping(path = "one") | 
|---|
|  |  |  | //@SsoAop() //只有登录验证,没有权限验证 | 
|---|
|  |  |  | @SsoPowerAop(power = "10100010") //登录与权限同时验证 | 
|---|
|  |  |  | @SsoPowerAop(power = "10100000") //登录与权限同时验证 | 
|---|
|  |  |  | @Log("查询单个用户") | 
|---|
|  |  |  | public BaseResponse<BaUser> one(String id) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id))); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询一个用户数据异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 保存用户信息 | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | //@SsoAop() //只有登录验证,没有权限验证 | 
|---|
|  |  |  | @SsoPowerAop(power = "10100011") //登录与权限同时验证 | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@RequestBody @Valid BaUser po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @SsoPowerAop(power = "10100001") //登录与权限同时验证 | 
|---|
|  |  |  | @Log("保存用户信息") | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@RequestBody @Valid BaUser po) throws Exception{ | 
|---|
|  |  |  | po.id = null; | 
|---|
|  |  |  | Long id; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | po.supperAdmin = Constant.no.byteValue() ; | 
|---|
|  |  |  | po.disabled = false ;//默认不禁用 | 
|---|
|  |  |  | po.deleted = false;//默认不删除 | 
|---|
|  |  |  | if (!StringUtils.isNullOrEmpty(po.password)) { | 
|---|
|  |  |  | po.supperAdmin = Constant.no.byteValue() ; | 
|---|
|  |  |  | //            po.disabled = false ;//默认不禁用 | 
|---|
|  |  |  | po.deleted = false;//默认不删除 | 
|---|
|  |  |  | if (!StringUtils.isNullOrEmpty(po.password)) { | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 如果前端进行了base64加密 | 
|---|
|  |  |  | po.password = new String(Base64.getDecoder().decode(po.password)) ; | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | po.password = MD5.encrypt(po.password);//进行加密码 | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | po.password = MD5.encrypt(defaultPassword); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | id = this.sv.save(po); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | po.password = MD5.encrypt(po.password);//进行加密码 | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | po.password = MD5.encrypt(defaultPassword); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | id = this.sv.save(po); | 
|---|
|  |  |  | if (id <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 更新用户信息 | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | //@SsoAop() //只有登录验证,没有权限验证 | 
|---|
|  |  |  | @SsoPowerAop(power = "10100011") //登录与权限同时验证 | 
|---|
|  |  |  | public BaseResponse<Boolean> update(@RequestBody @Validated BaUser po, BindingResult bindingResult) { | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (po.id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("无数据实体ID"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | po.password = null;//设置为null,不做更新 | 
|---|
|  |  |  | po.supperAdmin = null;//设置为null,不做更新 | 
|---|
|  |  |  | po.deleted = null;//设置为null,不做更新 | 
|---|
|  |  |  | count = this.sv.update(po); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("修改用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | @SsoPowerAop(power = "10100001") //登录与权限同时验证 | 
|---|
|  |  |  | @Log("更新用户信息") | 
|---|
|  |  |  | public BaseResponse<Boolean> update(@RequestBody @Validated BaUser po) { | 
|---|
|  |  |  | po.password = null;//设置为null,不做更新 | 
|---|
|  |  |  | po.supperAdmin = null;//设置为null,不做更新 | 
|---|
|  |  |  | po.deleted = null;//设置为null,不做更新 | 
|---|
|  |  |  | int count = this.sv.update(po); | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 禁用或启用用户信息 | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path="disabled") | 
|---|
|  |  |  | @SsoPowerAop(power = "10100001") | 
|---|
|  |  |  | @Log("禁用或启用用户信息") | 
|---|
|  |  |  | public BaseResponse<BaRole> disabled(@RequestBody BaUser po){ | 
|---|
|  |  |  | int count = sv.disabled(po.id,po.disabled); | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除用户信息 | 
|---|
|  |  |  | * @param id | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "delete") | 
|---|
|  |  |  | @SsoPowerAop(power = "10100001") //登录与权限同时验证 | 
|---|
|  |  |  | @Log("删除用户") | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(Long id) { | 
|---|
|  |  |  | BaUser po = new BaUser(); | 
|---|
|  |  |  | po.id = id; | 
|---|
|  |  |  | po.deleted = true; | 
|---|
|  |  |  | int count = this.sv.update(po); | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | 
|---|
|  |  |  | //@GetMapping(path = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @GetMapping(path = "changePassword") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) { | 
|---|
|  |  |  | @Log("修改密码") | 
|---|
|  |  |  | public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) throws Exception{ | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (id == null) { | 
|---|
|  |  |  | if (id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("旧密码不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(newPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("新密码不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("旧密码不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(newPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("新密码不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 如果前端进行了base64加密 | 
|---|
|  |  |  | oldPassword = new String(Base64.getDecoder().decode(oldPassword)) ; | 
|---|
|  |  |  | newPassword = new String(Base64.getDecoder().decode(newPassword)) ; | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | oldPassword = MD5.encrypt(oldPassword);//进行加密码 | 
|---|
|  |  |  | newPassword = MD5.encrypt(newPassword);//进行加密码 | 
|---|
|  |  |  | oldPassword = MD5.encrypt(oldPassword);//进行加密码 | 
|---|
|  |  |  | newPassword = MD5.encrypt(newPassword);//进行加密码 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long idLg = Long.parseLong(id) ; | 
|---|
|  |  |  | Long idLg = Long.parseLong(id) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BaUser po = this.sv.selectById(idLg); | 
|---|
|  |  |  | if (Objects.isNull(po)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("未得到用户,请求失败"); | 
|---|
|  |  |  | BaUser po = this.sv.selectById(idLg); | 
|---|
|  |  |  | if (Objects.isNull(po)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("未得到用户,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (!po.password.equalsIgnoreCase(oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("旧密码不正确,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (!po.password.equalsIgnoreCase(oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("旧密码不正确,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, newPassword); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, newPassword); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "resetPassword", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | //@SsoAop() //只有登录验证,没有权限验证 | 
|---|
|  |  |  | @SsoPowerAop(power = "10100011") //登录与权限同时验证 | 
|---|
|  |  |  | public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo, BindingResult bindingResult) { | 
|---|
|  |  |  | @SsoPowerAop(power = "10100001") //登录与权限同时验证 | 
|---|
|  |  |  | @Log("重置密码") | 
|---|
|  |  |  | public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo) throws Exception { | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String password = MD5.encrypt(vo.password);//进行加密码 | 
|---|
|  |  |  | Long idLg = Long.parseLong(vo.id); | 
|---|
|  |  |  | BaUser po = this.sv.selectById(idLg); | 
|---|
|  |  |  | if (Objects.isNull(po)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("未得到用户,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, password); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | String password = MD5.encrypt(vo.password);//进行加密码 | 
|---|
|  |  |  | Long idLg = Long.parseLong(vo.id); | 
|---|
|  |  |  | BaUser po = this.sv.selectById(idLg); | 
|---|
|  |  |  | if (Objects.isNull(po)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("未得到用户,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, password); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|