|  |  |  | 
|---|
|  |  |  | package com.dy.pipIrrBase.user; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.aop.SsoAop; | 
|---|
|  |  |  | import com.dy.common.multiDataSource.DataSourceContext; | 
|---|
|  |  |  | import com.dy.common.mybatis.envm.Deleted; | 
|---|
|  |  |  | import com.dy.common.mybatis.envm.Disabled; | 
|---|
|  |  |  | import com.dy.common.util.MD5; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponse; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
|---|
|  |  |  | import com.dy.common.webUtil.QueryResultVo; | 
|---|
|  |  |  | import com.dy.common.webUtil.ResultCodeMsg; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Parameter; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.media.Content; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.media.Schema; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.responses.ApiResponse; | 
|---|
|  |  |  | 
|---|
|  |  |  | import jakarta.validation.Valid; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | 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.web.bind.annotation.GetMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.PostMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Tag(name = "用户管理", description = "用户增删改查等操作") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path="user") | 
|---|
|  |  |  | @RequestMapping(path = "user") | 
|---|
|  |  |  | @SuppressWarnings("unchecked")//java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked") | 
|---|
|  |  |  | public class UserCtrl { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private UserSv sv ; | 
|---|
|  |  |  | private UserSv sv; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${user.defaultTrueRandomFalsePassword:true}") | 
|---|
|  |  |  | private Boolean defaultTrueRandomFalsePassword; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${user.defaultPassword:abc_123}") | 
|---|
|  |  |  | private String defaultPassword; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setSv(UserSv sv){ | 
|---|
|  |  |  | this.sv = sv ; | 
|---|
|  |  |  | private void setSv(UserSv sv) { | 
|---|
|  |  |  | this.sv = sv; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 客户端请求得到默认密码 | 
|---|
|  |  |  | * @return 默认密码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得默认密码", description = "获得默认密码") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回默认密码(BaseResponse.content:password)", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = String.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "defaultPassword") | 
|---|
|  |  |  | public BaseResponse<String> defaultPassword(){ | 
|---|
|  |  |  | if(defaultTrueRandomFalsePassword){ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(defaultPassword) ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | String password = this.sv.getStringRandom(6) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(password) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 客户端请求得到所有用户数据 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return 所有用户数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得一页用户", description = "返回一页用户数据") | 
|---|
|  |  |  | 
|---|
|  |  |  | schema = @Schema(implementation = BaUser.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "some") | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<BaUser>>> some(QueryVo vo){ | 
|---|
|  |  |  | @GetMapping(path = "some") | 
|---|
|  |  |  | //@PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoUserInfo>>> some(QueryVo vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<BaUser>> res = this.sv.selectSome(vo) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | QueryResultVo<List<VoUserInfo>> res = this.sv.selectSome(vo); | 
|---|
|  |  |  | //            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()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到一个用户数据 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return 一个用户数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "一个用户", description = "得到一个用户数据") | 
|---|
|  |  |  | 
|---|
|  |  |  | schema = @Schema(implementation = BaUser.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | //@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @GetMapping(path = "one") | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | public BaseResponse<BaUser> one(@Parameter(description = "实体id", required = true) Long id){ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<BaUser> one(String id) { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 保存用户 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po 保存用户form表单对象 | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | schema = @Schema(implementation = Boolean.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@Parameter(description = "form表单数据", required = true) @Valid BaUser po, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@RequestBody @Valid BaUser po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | po.id = null ; | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | po.id = null; | 
|---|
|  |  |  | Long userId; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | count = this.sv.save(po); | 
|---|
|  |  |  | po.supperAdmin = Constant.no.byteValue() ; | 
|---|
|  |  |  | po.disabled = Disabled.NO;//默认不禁用 | 
|---|
|  |  |  | po.deleted = Deleted.NO;//默认不删除 | 
|---|
|  |  |  | po.orgTag = DataSourceContext.get();//机构标签 | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userId = this.sv.save(po); | 
|---|
|  |  |  | this.sv.setRoles(userId, po.roleIds); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | if (userId <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 编辑修改用户 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po 保存用户form表单对象 | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | schema = @Schema(implementation = Boolean.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> update(@Parameter(description = "form表单数据", required = true) @Valid BaUser po, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> update(@RequestBody @Valid BaUser po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(po.id == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("无数据实体ID") ; | 
|---|
|  |  |  | if (po.id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("无数据实体ID"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | 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.id, po.roleIds); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改密码 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param   vo | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "修改密码", description = "提交用户ID、旧密码、新密码,进行改密码") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "操作结果:true:成功,false:失败(BaseResponse.content)", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = Boolean.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | //@GetMapping(path = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @PostMapping(path = "changePassword") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> changePassword(@RequestBody ChangePasswordVo vo) throws Exception { | 
|---|
|  |  |  | if (vo.id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("id不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(vo.oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("旧密码不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.isNullOrEmpty(vo.newPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("新密码不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 如果前端进行了base64加密 | 
|---|
|  |  |  | oldPassword = new String(Base64.getDecoder().decode(oldPassword)) ; | 
|---|
|  |  |  | newPassword = new String(Base64.getDecoder().decode(newPassword)) ; | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | vo.oldPassword = MD5.encrypt(vo.oldPassword);//进行加密码 | 
|---|
|  |  |  | vo.newPassword = MD5.encrypt(vo.newPassword);//进行加密码 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long idLg = Long.parseLong(vo.id); | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | BaUser po = this.sv.selectById(idLg); | 
|---|
|  |  |  | if (Objects.isNull(po)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("未得到用户,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (!po.password.equalsIgnoreCase(vo.oldPassword)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("旧密码不正确,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, vo.newPassword); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 重置密码 | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "重置密码", description = "提交数据(form表单json数据),进行密码重置") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "操作结果:true:成功,false:失败(BaseResponse.content)", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = Boolean.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "resetPassword", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> resetPassword(@RequestBody ResetPasswordVo vo) throws Exception { | 
|---|
|  |  |  | if (vo.id == null || vo.id == "") { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long idLg = Long.parseLong(vo.id); | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | BaUser po = this.sv.selectById(idLg); | 
|---|
|  |  |  | if (Objects.isNull(po)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("未得到用户,请求失败"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String defaultPassword1 = MD5.encrypt(defaultPassword);//进行加密码 | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, defaultPassword1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | * 重置密码为默认值 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 用户ID | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Operation(summary = "重置密码为默认密码", description = "提交用户ID") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "操作结果:true:成功,false:失败(BaseResponse.content)", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = Boolean.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "resetPasswordByDefault", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> resetPasswordByDefault(String id) throws Exception { | 
|---|
|  |  |  | if (id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String password = MD5.encrypt(defaultPassword);//进行加密码 | 
|---|
|  |  |  | Long idLg = Long.parseLong(id); | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | * 重置密码为随机数字加字母 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 用户ID | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Operation(summary = "重置密码为随机数字加字母", description = "提交用户ID") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "操作结果:true:成功,false:失败(BaseResponse.content)", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = Boolean.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "resetPasswordByRandom", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<String> resetPasswordByRandom(String id) throws Exception { | 
|---|
|  |  |  | if (id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String randomPassword = this.sv.getStringRandom(6); | 
|---|
|  |  |  | String password = MD5.encrypt(randomPassword);//进行加密码 | 
|---|
|  |  |  | Long idLg = Long.parseLong(id); | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(randomPassword); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | * 2023-12-05 在 save和update方法中进行了角色设置关联,本方法废弃 | 
|---|
|  |  |  | * 设置用户角色 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 用户ID | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Operation(summary = "设置用户角色", description = "提交用户ID,及所选择的角色ID集合(数组)") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "操作结果:true:成功,false:失败(BaseResponse.content)", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = Boolean.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "setRoles", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> setRoles(String id, | 
|---|
|  |  |  | @Parameter(description = "角色id数组") String[] roleIds) { | 
|---|
|  |  |  | Long[] roleId_lg = null; | 
|---|
|  |  |  | if (roleIds != null && roleIds.length > 0) { | 
|---|
|  |  |  | roleId_lg = new Long[roleIds.length]; | 
|---|
|  |  |  | int index = 0; | 
|---|
|  |  |  | for (String roleId : roleIds) { | 
|---|
|  |  |  | roleId_lg[index++] = Long.parseLong(roleId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | this.sv.setRoles(Long.parseLong(id), roleId_lg); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除用户 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 用户ID | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | schema = @Schema(implementation = Boolean.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(@Parameter(description = "实体id", required = true) Long id){ | 
|---|
|  |  |  | if(id == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空") ; | 
|---|
|  |  |  | //@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @GetMapping(path = "delete") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(String id) { | 
|---|
|  |  |  | if (id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | count = this.sv.delete(id); | 
|---|
|  |  |  | count = this.sv.delete(Long.parseLong(id)); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(SystemResultCode.USER_NOT_EXIST.getMessage()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据用户编号获取用户信息 | 
|---|
|  |  |  | * @param userId 用户编号 | 
|---|
|  |  |  | * @return 用户信息列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得全部用户信息", description = "返回全部用户信息数据") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回全部用户数据(BaseResponse.content:QueryResultVo[{}])", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = BaUser.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping("/getUserInfos/{userId}") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<VoUserInfo>> getUserInfos(@PathVariable("userId") Long userId) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | VoUserInfo res = this.sv.getUserInfos(userId); | 
|---|
|  |  |  | if(res == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildException(SystemResultCode.THE_USER_NOT_EXIST.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | System.out.println("   :" + res); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } 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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|