From f715601d0c0bdcba41e63c8063f8641c4838e438 Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期三, 10 一月 2024 19:23:04 +0800
Subject: [PATCH] 2024-01-10 朱宝民 重构角色5个接口
---
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java | 4
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java | 13 ++
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java | 22 ++-
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml | 5
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java | 289 +++++++++++++-----------------------------------
5 files changed, 113 insertions(+), 220 deletions(-)
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java
index dee40df..d88cdf1 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java
@@ -1,7 +1,9 @@
package com.dy.pipIrrGlobal.daoBa;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dy.pipIrrGlobal.pojoBa.BaRole;
import com.dy.pipIrrGlobal.voBa.VoRole;
+import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@@ -13,7 +15,9 @@
* @LastEditTime 2024-01-10 11:00
* @Description
*/
-public interface BaRoleMapper {
+
+@Mapper
+public interface BaRoleMapper extends BaseMapper<BaRole> {
int deleteByPrimaryKey(Long id);
int insert(BaRole record);
@@ -46,4 +50,11 @@
* @return
*/
List<VoRole> getRoles(Map<?, ?> params);
+
+ /**
+ * 鏍规嵁roleId閫昏緫鍒犻櫎瑙掕壊瀵硅薄
+ * @param roleId
+ * @return
+ */
+ Integer deleteRoleById(@Param("roleId") Long roleId);
}
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml
index da62340..c9c866e 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml
@@ -161,4 +161,9 @@
) t
, (SELECT @i:=0) AS itable
</select>
+
+ <!--鏍规嵁roleId閫昏緫鍒犻櫎瑙掕壊瀵硅薄-->
+ <update id="deleteRoleById">
+ UPDATE ba_role SET deleted = 1 WHERE id = ${roleId}
+ </update>
</mapper>
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java
index dda4a73..fc185ae 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java
@@ -19,7 +19,9 @@
PERMISSION_ERROR(10001, "鎺堟潈閿欒"),
ADD_ROLE_FAIL(10002, "瑙掕壊娣诲姞澶辫触"),
ROLE_NAME_EXIST(10003, "瑙掕壊鍚嶇О宸插瓨鍦�"),
- NO_ROLES(10004, "娌℃湁绗﹀悎鏉′欢鐨勮鑹茶褰�");
+ NO_ROLES(10004, "娌℃湁绗﹀悎鏉′欢鐨勮鑹茶褰�"),
+ PLEASE_INPUT_ROLE_ID(10005, "瑙掕壊缂栧彿涓嶈兘涓虹┖"),
+ DELETE_ROLE_FAIL(10006, "鍒犻櫎瑙掕壊澶辫触");
private final Integer code;
private final String message;
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java
index dbd6ed1..60cce2a 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java
@@ -25,10 +25,7 @@
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
@Slf4j
@Tag(name = "瑙掕壊绠$悊", description = "瑙掕壊澧炲垹鏀规煡绛夋搷浣�")
@@ -76,112 +73,6 @@
return BaseResponseUtils.buildException(e.getMessage()) ;
}
}
-
- /**
- * 瀹㈡埛绔姹傚緱鍒版墍鏈夎鑹叉暟鎹�
- * @return 鎵�鏈夎鑹叉暟鎹�
- */
- //@Operation(summary = "鑾峰緱鍏ㄩ儴瑙掕壊", description = "杩斿洖鍏ㄩ儴瑙掕壊鏁版嵁")
- //@ApiResponses(value = {
- // @ApiResponse(
- // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
- // description = "杩斿洖鍏ㄩ儴瑙掕壊鏁版嵁锛圔aseResponse.content:QueryResultVo[{}]锛�",
- // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- // schema = @Schema(implementation = BaRole.class))}
- // )
- //})
- //@GetMapping(path = "all")
- //@SsoAop()
- //public BaseResponse<QueryResultVo<List<BaRole>>> all(){
- // try {
- // QueryResultVo<List<BaRole>> res = this.sv.selectAll() ;
- // 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:QueryResultVo[{}]锛�",
- // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- // schema = @Schema(implementation = BaRole.class))}
- // )
- //})
- //@PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE)
- //@SsoAop()
- //public BaseResponse<QueryResultVo<List<BaRole>>> some(@RequestBody @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)
- //@GetMapping(path = "one")
- //@SsoAop()
- //public BaseResponse<BaRole> one(Long id){
- // return BaseResponseUtils.buildSuccess(this.sv.selectById(id));
- //}
-
- /**
- * 淇濆瓨瑙掕壊
- * @param po 淇濆瓨瑙掕壊form琛ㄥ崟瀵硅薄
- * @return 鏄惁鎴愬姛
- */
- //@Operation(summary = "淇濆瓨瑙掕壊", description = "鎻愪氦瑙掕壊鏁版嵁锛坒orm琛ㄥ崟锛夛紝杩涜淇濆瓨")
- //@ApiResponses(value = {
- // @ApiResponse(
- // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
- // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
- // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- // schema = @Schema(implementation = Boolean.class))}
- // )
- //})
- //@PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE)
- //@SsoAop()
- //public BaseResponse<Boolean> save(@RequestBody @Valid BaRole po, BindingResult bindingResult){
- // if(bindingResult != null && bindingResult.hasErrors()){
- // return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- // }
- // po.id = null ;
- // Long 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) ;
- // }
- //}
/**
* 娣诲姞瑙掕壊鍙婃潈闄愬垪琛紝娣诲姞鍓嶅垽鏂鑹插悕鏄惁宸插瓨鍦�
@@ -312,114 +203,90 @@
}
/**
- * 缂栬緫淇敼瑙掕壊
+ * 淇敼瑙掕壊
* @param po 淇濆瓨瑙掕壊form琛ㄥ崟瀵硅薄
* @return 鏄惁鎴愬姛
*/
- //@Operation(summary = "缂栬緫淇敼瑙掕壊", description = "鎻愪氦瑙掕壊鏁版嵁锛坒orm琛ㄥ崟锛夛紝杩涜淇敼")
- //@ApiResponses(value = {
- // @ApiResponse(
- // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
- // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
- // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- // schema = @Schema(implementation = Boolean.class))}
- // )
- //})
- //@PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
- //@SsoAop()
- //public BaseResponse<Boolean> update(@RequestBody @Valid BaRole po, BindingResult bindingResult){
- // if(bindingResult != null && bindingResult.hasErrors()){
- // return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- // }
- // if(po.id == null){
- // return BaseResponseUtils.buildFail("鏃犳暟鎹疄浣揑D") ;
- // }
- // int count;
- // try {
- // po.deleted = null ;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
- // 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) ;
- // }
- //}
+ @Operation(summary = "淇敼瑙掕壊", description = "鎻愪氦瑙掕壊鏁版嵁锛岃繘琛屼慨鏀�")
+ @ApiResponses(value = {
+ @ApiResponse(
+ responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+ description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
+ content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+ schema = @Schema(implementation = Boolean.class))}
+ )
+ })
+ @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
+ @SsoAop()
+ public BaseResponse<Boolean> update(@RequestBody @Valid BaRole po, BindingResult bindingResult){
+ if(bindingResult != null && bindingResult.hasErrors()){
+ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+ }
+ // 鎺ユ敹瑙掕壊缂栧彿銆佽鑹插悕绉般�佹搷浣滀汉缂栧彿
+ Long roleId = Optional.ofNullable(po.getId()).orElse(0L);
+ String roleName = Optional.ofNullable(po.getName()).orElse("");
+ Long operator = Optional.ofNullable(po.getOperator()).orElse(0L);
+ // 鍒ゆ柇涓婚敭鏄惁涓虹┖
+ if(roleId == 0)
+ return BaseResponseUtils.buildFail(SystemResultCode.PLEASE_INPUT_ROLE_ID.getMessage()) ;
- ///**
- // * 璁剧疆瑙掕壊鏉冮檺
- // * @param id 瑙掕壊ID
- // * @return 鏄惁鎴愬姛
- // */
- //@Operation(summary = "璁剧疆瑙掕壊鏉冮檺", description = "鎻愪氦瑙掕壊ID锛屽強鎵�閫夋嫨鐨勬潈闄怚D闆嗗悎锛堟暟缁勶級")
- //@ApiResponses(value = {
- // @ApiResponse(
- // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
- // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
- // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- // schema = @Schema(implementation = Boolean.class))}
- // )
- //})
- ////@GetMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE)
- //@PostMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE)
- //@SsoAop()
- //public BaseResponse<Boolean> setPrivileges(Long 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 ;
- // }
- // }
- // try {
- // this.sv.setRoles(id, privIds_lg);
- // } catch (Exception e) {
- // log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
- // return BaseResponseUtils.buildException(e.getMessage()) ;
- // }
- // return BaseResponseUtils.buildSuccess(true) ;
- //}
- ///**
- // * 鍒犻櫎瑙掕壊
- // * @param id 瑙掕壊ID
- // * @return 鏄惁鎴愬姛
- // */
- //@Operation(summary = "鍒犻櫎瑙掕壊", description = "鎻愪氦瑙掕壊ID锛岃繘琛岄�昏緫鍒犻櫎")
- //@ApiResponses(value = {
- // @ApiResponse(
- // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
- // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
- // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
- // schema = @Schema(implementation = Boolean.class))}
- // )
- //})
- ////@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE)
- //@GetMapping(path = "delete")
- //@SsoAop()
- //public BaseResponse<Boolean> delete(Long id){
- // if(id == null){
- // return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ;
- // }
- // int count;
- // try {
- // count = this.sv.delete(id);
- // } catch (Exception e) {
- // log.error("淇濆瓨瑙掕壊寮傚父", e);
- // return BaseResponseUtils.buildException(e.getMessage()) ;
- // }
- // if(count <= 0){
- // return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ;
- // }else{
- // return BaseResponseUtils.buildSuccess(true) ;
- // }
- //}
+ Integer recordCount = 0;
+ try {
+ po.setName(roleName);
+ po.setOperator(operator);
+ Date operateTime = new Date();
+ po.setOperateDt(operateTime);
+ //po.deleted = null ;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
+ recordCount = roleSv.updateRole(po);
+ } catch (Exception e) {
+ return BaseResponseUtils.buildException(e.getMessage()) ;
+ }
+ if(recordCount <= 0)
+ return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ;
+
+ return BaseResponseUtils.buildSuccess(true) ;
+ }
+
+ /**
+ * 鍒犻櫎瑙掕壊
+ * 閫昏緫鍒犻櫎瑙掕壊璁板綍锛岀墿鐞嗗垹闄よ鑹叉巿鏉冭褰�
+ * @param map
+ * @return 鏄惁鎴愬姛
+ */
+ @Operation(summary = "鍒犻櫎瑙掕壊", description = "鎻愪氦瑙掕壊ID锛岃繘琛岄�昏緫鍒犻櫎")
+ @ApiResponses(value = {
+ @ApiResponse(
+ responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+ description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
+ content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+ schema = @Schema(implementation = Boolean.class))}
+ )
+ })
+ //@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 {
+ // 閫昏緫鍒犻櫎瑙掕壊璁板綍锛岀墿鐞嗗垹闄よ鑹叉巿鏉冭褰�
+ 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) {
+ return BaseResponseUtils.buildException(e.getMessage()) ;
+ }
+ }
}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java
index af117e5..be9c7e8 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java
@@ -133,14 +133,22 @@
}
/**
- * 淇濆瓨淇敼瀹炰綋
- * @param po 瀹炰綋
- * @return 褰卞搷璁板綍鏁伴噺
+ * 淇敼瑙掕壊
+ * @param record
+ * @return
*/
- //@Transactional
- //public int update(BaRole po){
- // return this.dao.updateByPrimaryKeySelective(po) ;
- //}
+ public int updateRole(BaRole record) {
+ return baRoleMapper.updateByPrimaryKeySelective(record);
+ }
+
+ /**
+ * 鏍规嵁roleId閫昏緫鍒犻櫎瑙掕壊瀵硅薄
+ * @param roleId 瑙掕壊缂栧彿
+ * @return
+ */
+ public Integer deleteRoleById(Long roleId) {
+ return baRoleMapper.deleteRoleById(roleId);
+ }
/**
* 璁剧疆瑙掕壊鏉冮檺
--
Gitblit v1.8.0