| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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; |
| | |
| | | schema = @Schema(implementation = BaUser.class))} |
| | | ) |
| | | }) |
| | | @PostMapping(path = "some") |
| | | @PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop("-1") |
| | | public BaseResponse<QueryResultVo<List<BaUser>>> some(QueryVo vo){ |
| | | public BaseResponse<QueryResultVo<List<BaUser>>> some(@RequestBody @Parameter(description = "查询form表单json数据", required = true) @Valid QueryVo vo){ |
| | | try { |
| | | QueryResultVo<List<BaUser>> res = this.sv.selectSome(vo) ; |
| | | return BaseResponseUtils.buildSuccess(res); |
| | |
| | | schema = @Schema(implementation = BaUser.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "one") |
| | | @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @SsoAop("-1") |
| | | public BaseResponse<BaUser> one(@Parameter(description = "实体id", required = true) Long id){ |
| | | return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); |
| | | public BaseResponse<BaUser> one(@Parameter(description = "实体id", required = true) String id){ |
| | | return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id))); |
| | | } |
| | | |
| | | /** |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @PostMapping(path = "save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop("-1")//@SsoAop(power = "-1") |
| | | public BaseResponse<Boolean> save(@Parameter(description = "form表单数据", required = true) @Valid BaUser po, @Parameter(hidden = true) BindingResult bindingResult){ |
| | | public BaseResponse<Boolean> save(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid BaUser po, @Parameter(hidden = true) BindingResult bindingResult){ |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @PostMapping(path = "update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop("-1")//@SsoAop(power = "-1") |
| | | public BaseResponse<Boolean> update(@Parameter(description = "form表单数据", required = true) @Valid BaUser po, @Parameter(hidden = true) BindingResult bindingResult){ |
| | | public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid BaUser po, @Parameter(hidden = true) BindingResult bindingResult){ |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | |
| | | }) |
| | | @GetMapping(path = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @SsoAop("-1")//@SsoAop(power = "-1") |
| | | public BaseResponse<Boolean> changePassword(@Parameter(description = "实体id", required = true) Long id, |
| | | public BaseResponse<Boolean> changePassword(@Parameter(description = "实体id", required = true) String id, |
| | | @Parameter(description = "旧密码", required = true) String oldPassword, |
| | | @Parameter(description = "新密码", required = true) String newPassword) throws Exception{ |
| | | if(id == null){ |
| | |
| | | oldPassword = MD5.encrypt(oldPassword) ;//进行加密码 |
| | | newPassword = MD5.encrypt(newPassword) ;//进行加密码 |
| | | |
| | | Long idLg = Long.parseLong(id) ; |
| | | int count ; |
| | | try { |
| | | BaUser po = this.sv.selectById(id); |
| | | BaUser po = this.sv.selectById(idLg); |
| | | if(Objects.isNull(po)){ |
| | | return BaseResponseUtils.buildFail("未得到用户,请求失败") ; |
| | | }else{ |
| | | if(!po.password.equalsIgnoreCase(oldPassword)){ |
| | | return BaseResponseUtils.buildFail("旧密码不正确,请求失败") ; |
| | | }else{ |
| | | count = this.sv.changePassword(id, newPassword) ; |
| | | count = this.sv.changePassword(idLg, newPassword) ; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | }else{ |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置用户角色 |
| | | * @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("-1")//@SsoAop(power = "-1") |
| | | public BaseResponse<Boolean> setRoles(@Parameter(description = "实体id", required = true) 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) ; |
| | | } |
| | | |
| | | |
| | |
| | | }) |
| | | @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) |
| | | @SsoAop("-1")//@SsoAop(power = "-1") |
| | | public BaseResponse<Boolean> delete(@Parameter(description = "实体id", required = true) Long id){ |
| | | public BaseResponse<Boolean> delete(@Parameter(description = "实体id", required = true) 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()) ; |