|  |  |  | 
|---|
|  |  |  | package com.dy.pipIrrBase.role; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSONArray; | 
|---|
|  |  |  | import com.dy.common.aop.SsoAop; | 
|---|
|  |  |  | import com.dy.common.mybatis.envm.Deleted; | 
|---|
|  |  |  | 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.user.QueryVo; | 
|---|
|  |  |  | import com.dy.pipIrrBase.result.SystemResultCode; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoBa.BaRole; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoBa.BaRolePermissions; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voBa.VoRole; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voSe.VoActiveCard; | 
|---|
|  |  |  | 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 io.swagger.v3.oas.annotations.responses.ApiResponses; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.tags.Tag; | 
|---|
|  |  |  | import jakarta.validation.Valid; | 
|---|
|  |  |  | import lombok.RequiredArgsConstructor; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.http.MediaType; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Tag(name = "角色管理", description = "角色增删改查等操作") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path="role") | 
|---|
|  |  |  | @RequiredArgsConstructor | 
|---|
|  |  |  | @SuppressWarnings("unchecked")//java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked") | 
|---|
|  |  |  | public class RoleCtrl { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private RoleSv sv ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setSv(RoleSv sv){ | 
|---|
|  |  |  | this.sv = sv ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private final RoleSv roleSv; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 客户端请求得到所有角色数据 | 
|---|
|  |  |  | * @return 所有角色数据 | 
|---|
|  |  |  | * 根据指定条件(角色编号、角色名称)获取角色列表 | 
|---|
|  |  |  | * 当获取一条记录时,传入roleId即可 | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得全部角色", description = "返回全部角色数据") | 
|---|
|  |  |  | @Operation(summary = "获得一页角色记录", description = "返回一页角色数据") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回全部角色数据(BaseResponse.content:QueryResultVo[{}])", | 
|---|
|  |  |  | description = "返回一页控制器数据(BaseResponse.content:QueryResultVo[{}])", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = BaRole.class))} | 
|---|
|  |  |  | schema = @Schema(implementation = VoActiveCard.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "all") | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<BaRole>>> all(){ | 
|---|
|  |  |  | @GetMapping(path = "/roles") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoRole>>> getRoles(QueryVo vo){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<BaRole>> res = this.sv.selectAll() ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询角色异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //BaRolePermissions baRolePermissions = roleSv.getRolePermissionsById(2023122018334500002L); | 
|---|
|  |  |  | //return BaseResponseUtils.buildSuccess(baRolePermissions); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 客户端请求得到一页角色数据 | 
|---|
|  |  |  | * @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 = BaRole.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<BaRole>>> some(@RequestBody @Parameter(description = "查询form表单json数据", required = true) @Valid QueryVo vo){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<BaRole>> res = this.sv.selectSome(vo) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询角色异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到一个角色数据 | 
|---|
|  |  |  | * @return 一个角色数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "一个角色", description = "得到一个角色数据") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回一个角色数据(BaseResponse.content:{})", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = BaRole.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @SsoAop("-1") | 
|---|
|  |  |  | public BaseResponse<BaRole> one(@Parameter(description = "实体id", required = true) Long id){ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 保存角色 | 
|---|
|  |  |  | * @param po 保存角色form表单对象 | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "保存角色", description = "提交角色数据(form表单),进行保存") | 
|---|
|  |  |  | @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 = "save", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid BaRole po, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | po.id = null ; | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | po.deleted = Deleted.NO ;//默认不删除 | 
|---|
|  |  |  | count = this.sv.save(po); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存角色异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 编辑修改角色 | 
|---|
|  |  |  | * @param po 保存角色form表单对象 | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "编辑修改角色", description = "提交角色数据(form表单),进行修改") | 
|---|
|  |  |  | @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 = "update", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid BaRole po, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(po.id == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("无数据实体ID") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | po.deleted = null ;//设置为null,不做更新 | 
|---|
|  |  |  | count = this.sv.update(po); | 
|---|
|  |  |  | } 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,及所选择的权限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 = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> setPrivileges(@Parameter(description = "实体id", required = true) Long id, | 
|---|
|  |  |  | @Parameter(description = "权限id数组") Long[] privIds){ | 
|---|
|  |  |  | Long[] privIds_lg = null ; | 
|---|
|  |  |  | if(privIds != null && privIds.length > 0){ | 
|---|
|  |  |  | privIds_lg = new Long[privIds.length] ; | 
|---|
|  |  |  | int index = 0 ; | 
|---|
|  |  |  | for(Long privId : privIds){ | 
|---|
|  |  |  | privIds_lg[index++] = privId ; | 
|---|
|  |  |  | QueryResultVo<List<VoRole>> res = roleSv.getRoles(vo); | 
|---|
|  |  |  | if(res.itemTotal != null && res.itemTotal > 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(SystemResultCode.NO_ROLES.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | this.sv.setRoles(id, privIds_lg); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | log.error("获取开卡记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 角色授权 | 
|---|
|  |  |  | * 1. 如果roleid和roleName都空:提示错误信息 | 
|---|
|  |  |  | * 2. 如果roleid为空:新建角色且授权 | 
|---|
|  |  |  | *      1. 添加角色记录 | 
|---|
|  |  |  | *      2. 添加角色、权限关联记录 | 
|---|
|  |  |  | * 3. 如果roleid不为空:修改角色及授权 | 
|---|
|  |  |  | *      1. 删除角色、权限记录 | 
|---|
|  |  |  | *      2. 修改角色信息 | 
|---|
|  |  |  | *      3. 添加角色、权限记录 | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "授权", description = "授权") | 
|---|
|  |  |  | @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 = "addPermissions", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> permission(@RequestBody  @Valid DtoRole po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long roleId = Optional.ofNullable(po.getRoleId()).orElse(0L); | 
|---|
|  |  |  | String roleName = Optional.ofNullable(po.getRoleName()).orElse(""); | 
|---|
|  |  |  | JSONArray permissions = Optional.ofNullable(JSONArray.parseArray(po.getPermissions())).orElse(JSONArray.parseArray("[]")); | 
|---|
|  |  |  | Long operator = Optional.ofNullable(po.getOperator()).orElse(0L); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(roleId == 0 && roleName.length() == 0) | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(SystemResultCode.PERMISSION_ERROR.getMessage()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 新建角色且授权 | 
|---|
|  |  |  | if(roleId == 0) { | 
|---|
|  |  |  | BaRole baRole = new BaRole(); | 
|---|
|  |  |  | baRole.setName(roleName); | 
|---|
|  |  |  | baRole.setOperator(operator); | 
|---|
|  |  |  | Date operateTime = new Date(); | 
|---|
|  |  |  | baRole.setOperateDt(operateTime); | 
|---|
|  |  |  | baRole.setDeleted(Deleted.NO.getCode()); | 
|---|
|  |  |  | roleId = Optional.ofNullable(roleSv.addRole(baRole)).orElse(0L); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BaRolePermissions baRolePermissions = new BaRolePermissions(); | 
|---|
|  |  |  | baRolePermissions.setRoleid(roleId); | 
|---|
|  |  |  | baRolePermissions.setPermissions(permissions); | 
|---|
|  |  |  | roleSv.addPermissions(baRolePermissions); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改角色信息 | 
|---|
|  |  |  | BaRole baRole = new BaRole(); | 
|---|
|  |  |  | baRole.setId(roleId); | 
|---|
|  |  |  | baRole.setName(roleName); | 
|---|
|  |  |  | baRole.setOperator(operator); | 
|---|
|  |  |  | Date operateTime = new Date(); | 
|---|
|  |  |  | baRole.setOperateDt(operateTime); | 
|---|
|  |  |  | roleSv.updateRole(baRole); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改角色授权 | 
|---|
|  |  |  | BaRolePermissions baRolePermissions = new BaRolePermissions(); | 
|---|
|  |  |  | baRolePermissions.setRoleid(roleId); | 
|---|
|  |  |  | baRolePermissions.setPermissions(permissions); | 
|---|
|  |  |  | roleSv.delPermissionsByRoleId(roleId); | 
|---|
|  |  |  | roleSv.addPermissions(baRolePermissions); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除角色 | 
|---|
|  |  |  | * @param id 角色ID | 
|---|
|  |  |  | *  逻辑删除角色记录,物理删除角色授权记录 | 
|---|
|  |  |  | * @param map | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "删除角色", description = "提交角色ID,进行逻辑删除") | 
|---|
|  |  |  | 
|---|
|  |  |  | 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不能为空") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | //@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) | 
|---|
|  |  |  | @PostMapping(path = "delete", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(@RequestBody Map map){ | 
|---|
|  |  |  | Long id = Optional.ofNullable(Long.parseLong(map.get("id").toString())).orElse(0L); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(id == 0) | 
|---|
|  |  |  | return BaseResponseUtils.buildException(SystemResultCode.PLEASE_INPUT_ROLE_ID.getMessage()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | count = this.sv.delete(id); | 
|---|
|  |  |  | // 逻辑删除角色记录,物理删除角色授权记录 | 
|---|
|  |  |  | Integer res_role = Optional.ofNullable(roleSv.deleteRoleById(id)).orElse(0); | 
|---|
|  |  |  | Integer res_per = Optional.ofNullable(roleSv.delPermissionsByRoleId(id)).orElse(0); | 
|---|
|  |  |  | if(res_role == 0 || res_per == 0) | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(SystemResultCode.DELETE_ROLE_FAIL.getMessage()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存角色异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|