|  |  |  | 
|---|
|  |  |  | import com.dy.pipIrrBase.result.SystemResultCode; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoBa.BaUser; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.util.Constant; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voBa.VoSimpleUser; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voBa.VoUserInfo; | 
|---|
|  |  |  | import com.mysql.cj.util.StringUtils; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Operation; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Value("${user.defaultTrueRandomFalsePassword:true}") | 
|---|
|  |  |  | private Boolean defaultTrueRandomFalsePassword; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${user.defaultPassword:ABC123}") | 
|---|
|  |  |  | @Value("${user.defaultPassword:abc_123}") | 
|---|
|  |  |  | private String defaultPassword; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "some") | 
|---|
|  |  |  | //@PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoUserInfo>>> some(QueryVo vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<VoUserInfo>> res = this.sv.selectSome(vo); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | //            if(res.itemTotal == 0) { | 
|---|
|  |  |  | //                return BaseResponseUtils.buildSuccess(SystemResultCode.THE_USER_NOT_EXIST.getMessage()); | 
|---|
|  |  |  | //            }else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | po.userId = null; | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | po.id = null; | 
|---|
|  |  |  | Long userId; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | po.supperAdmin = Constant.no.byteValue() ; | 
|---|
|  |  |  | po.disabled = Disabled.NO;//默认不禁用 | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | po.password = MD5.encrypt(defaultPassword); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | count = this.sv.save(po); | 
|---|
|  |  |  | this.sv.setRoles(po.userId, po.roleIds); | 
|---|
|  |  |  | userId = this.sv.save(po); | 
|---|
|  |  |  | this.sv.setRoles(userId, po.roleIds); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | if (userId <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (po.userId == null) { | 
|---|
|  |  |  | if (po.id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("无数据实体ID"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | 
|---|
|  |  |  | po.supperAdmin = null;//设置为null,不做更新 | 
|---|
|  |  |  | po.deleted = null;//设置为null,不做更新 | 
|---|
|  |  |  | po.orgTag = null;//设置为null,不做更新 | 
|---|
|  |  |  | //            修改用户信息不进行密码修改 | 
|---|
|  |  |  | //            po.password =  MD5.encrypt(po.password);//进行加密 | 
|---|
|  |  |  | count = this.sv.update(po); | 
|---|
|  |  |  | this.sv.setRoles(po.userId, po.roleIds); | 
|---|
|  |  |  | this.sv.setRoles(po.id, po.roleIds); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改密码 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 用户ID | 
|---|
|  |  |  | * @param   vo | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "修改密码", description = "提交用户ID、旧密码、新密码,进行改密码") | 
|---|
|  |  |  | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | //@GetMapping(path = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @GetMapping(path = "changePassword") | 
|---|
|  |  |  | @PostMapping(path = "changePassword") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) throws Exception { | 
|---|
|  |  |  | if (id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空"); | 
|---|
|  |  |  | public BaseResponse<Boolean> changePassword(@RequestBody ChangePasswordVo vo) throws Exception { | 
|---|
|  |  |  | if (vo.id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("id不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("旧密码不能为空"); | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(vo.oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("旧密码不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(newPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("新密码不能为空"); | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(vo.newPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("新密码不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 如果前端进行了base64加密 | 
|---|
|  |  |  | oldPassword = new String(Base64.getDecoder().decode(oldPassword)) ; | 
|---|
|  |  |  | newPassword = new String(Base64.getDecoder().decode(newPassword)) ; | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | oldPassword = MD5.encrypt(oldPassword);//进行加密码 | 
|---|
|  |  |  | newPassword = MD5.encrypt(newPassword);//进行加密码 | 
|---|
|  |  |  | vo.oldPassword = MD5.encrypt(vo.oldPassword);//进行加密码 | 
|---|
|  |  |  | vo.newPassword = MD5.encrypt(vo.newPassword);//进行加密码 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long idLg = Long.parseLong(id); | 
|---|
|  |  |  | Long idLg = Long.parseLong(vo.id); | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | BaUser po = this.sv.selectById(idLg); | 
|---|
|  |  |  | if (Objects.isNull(po)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("未得到用户,请求失败"); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("未得到用户,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (!po.password.equalsIgnoreCase(oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("旧密码不正确,请求失败"); | 
|---|
|  |  |  | if (!po.password.equalsIgnoreCase(vo.oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("旧密码不正确,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, newPassword); | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, vo.newPassword); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 重置密码 | 
|---|
|  |  |  | * @param vo form表单对象 | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "重置密码", description = "提交数据(form表单json数据),进行密码重置") | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "resetPassword", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> resetPassword(@RequestBody  ResetPasswordVo vo) throws Exception { | 
|---|
|  |  |  | if (vo.id == null) { | 
|---|
|  |  |  | public BaseResponse<Boolean> resetPassword(@RequestBody ResetPasswordVo vo) throws Exception { | 
|---|
|  |  |  | if (vo.id == null || vo.id == "") { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String password = MD5.encrypt(vo.password);//进行加密码 | 
|---|
|  |  |  | Long idLg = Long.parseLong(vo.id); | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | BaUser po = this.sv.selectById(idLg); | 
|---|
|  |  |  | if (Objects.isNull(po)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("未得到用户,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, password); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String defaultPassword1 = MD5.encrypt(defaultPassword);//进行加密码 | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, defaultPassword1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取简单用户数据列表,数据列表查询条件中使用 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "simple_users") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<List<VoSimpleUser>> getSimpleUsers(){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(sv.getSimpleUsers()); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询简单用户信息异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|