From 9ca9a4efd10f109625e81c27b9531cffed55c0bf Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 14 十一月 2023 14:14:35 +0800
Subject: [PATCH] 1、设置id拦截器修改,处理实体没有setId方法的情况 2、用户管理中增加设置用户角色的方法

---
 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java    |   36 ++++++++++++++++++
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java |   13 +++++-
 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java      |   25 ++++++++++++
 3 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
index e9db338..eca91c8 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
@@ -43,8 +43,17 @@
             if (entity instanceof BaseEntity) {
                 //Class<? extends Object> entityClass = entity.getClass();
                 Class<?> entityClass = entity.getClass();
-                Method setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ;
-                setMt.invoke(entity, new IDLongGenerator().generate());
+                Method setMt = null ;
+                try{
+                    //鏈変竴浜涘疄浣撴病鏈塱d锛屼緥濡備腑闂磋〃
+                    setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ;
+                }catch (Exception e){
+                    //褰揺ntityClass娌℃湁setId鏂规硶鏃讹紝浼氭姏鍑哄紓甯�
+                }
+                if(setMt != null){
+                    setMt.invoke(entity, new IDLongGenerator().generate());
+                }
+
                 invocation.getArgs()[PARAMETER_INDEX] = entity;
             }
         }
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
index 9368a24..2e31985 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
@@ -235,6 +235,42 @@
 
 
     /**
+     * 璁剧疆鐢ㄦ埛瑙掕壊
+     * @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 = "setRoles", consumes = MediaType.MULTIPART_FORM_DATA_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) ;
+    }
+
+
+    /**
      * 鍒犻櫎鐢ㄦ埛
      * @param id 鐢ㄦ埛ID
      * @return 鏄惁鎴愬姛
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
index 9eee7c2..eb95297 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
@@ -3,7 +3,9 @@
 
 import com.dy.common.webUtil.QueryResultVo;
 import com.dy.pipIrrGlobal.daoBa.BaUserMapper;
+import com.dy.pipIrrGlobal.daoBa.BaUserRoleMapper;
 import com.dy.pipIrrGlobal.pojoBa.BaUser;
+import com.dy.pipIrrGlobal.pojoBa.BaUserRole;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -19,10 +21,16 @@
 public class UserSv {
 
     private BaUserMapper dao;
+    private BaUserRoleMapper urDao;
 
     @Autowired
     private void setDao(BaUserMapper dao){
         this.dao = dao;
+    }
+
+    @Autowired
+    private void setDao(BaUserRoleMapper dao){
+        this.urDao = dao;
     }
 
     /**
@@ -84,6 +92,23 @@
     }
 
     /**
+     * 璁剧疆鐢ㄦ埛瑙掕壊
+     * @param userId 鐢ㄦ埛id
+     * @param roleIds 閫夋嫨鐨勮鑹瞚d闆嗗悎
+     * @return 鎻掑叆鐢ㄦ埛涓庤鑹插叧鑱旇褰曟暟閲�
+     */
+    public int setRoles(Long userId, Long[] roleIds){
+        this.urDao.deleteByUserId(userId) ;
+        int count = 0 ;
+        if(roleIds != null && roleIds.length > 0){
+            for(Long roleId : roleIds){
+                count += this.urDao.insertSelective(new BaUserRole(userId,roleId)) ;
+            }
+        }
+        return count ;
+    }
+
+    /**
      * 淇濆瓨淇敼瀹炰綋
      * @param id 瀹炰綋ID
      * @return 褰卞搷璁板綍鏁伴噺

--
Gitblit v1.8.0