Browse Source

用户同步不改变用户角色,新增用户默认普通用户角色

hanzhen 3 years ago
parent
commit
a3c6b70960

+ 2 - 0
src/main/java/com/gz/mapper/system/AdminMapper.java

@@ -24,4 +24,6 @@ public interface AdminMapper extends Mapper<AdminDTO> {
      * @return
      */
     int deleteById(@Param("id") String id);
+
+    List<AdminDTO> selectList(AdminVO vo);
 }

+ 0 - 1
src/main/java/com/gz/service/archive/impl/ArchiveServiceImpl.java

@@ -194,7 +194,6 @@ public class ArchiveServiceImpl implements ArchiveService {
         for (int i = 0; i < parameterMappings.size(); i++) {
             sql = sql.replaceFirst("\\?", String.format("'%s'", stringObjectMap.get(parameterMappings.get(i).getProperty())));
         }
-//        log.info("获取运行的sql:{}",sql);
         return sql;
     }
 

+ 10 - 2
src/main/java/com/gz/service/system/impl/AdminServiceImpl.java

@@ -15,6 +15,7 @@ import com.gz.utils.JwtUtils;
 import com.gz.utils.PasswordUtils;
 import com.gz.vo.system.AdminVO;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -173,24 +174,31 @@ public class AdminServiceImpl implements AdminService {
             }
             for (Map<String, Object> map : user) {
                 AdminDTO adminDTO = new AdminDTO();
+
                 adminDTO.setId(String.valueOf(map.get("guid") == null ? "" : map.get("guid")));
                 adminDTO.setAdminName(String.valueOf(map.get("userName") == null ? "" : map.get("userName")));
                 adminDTO.setAccount(String.valueOf(map.get("loginName") == null ? "" : map.get("loginName")));
-//                adminDTO.setUserOrder(String.valueOf(map.get("sortno") == null ? "" : map.get("sortno")));
                 adminDTO.setPhone(String.valueOf(map.get("mobilephone") == null ? "" : map.get("mobilephone")));
-//                adminDTO.setShowName(String.valueOf(map.get("positionTitle") == null ? "" : map.get("positionTitle")));
                 String state = String.valueOf(map.get("state") == null ? "" : map.get("state"));
+                // 根据用户姓名和用户账号查询用户
+                List<AdminDTO> adminVOS = this.adminMapper.selectByPage(new AdminVO(adminDTO.getAdminName(),adminDTO.getAccount()));
                 //正常
                 if ("1".equals(state)) {
                     List<String> deptids = (List<String>) map.get("orgGuid");
                     if (adminMapper.existsWithPrimaryKey(adminDTO.getId())) {
                         for (String deptid : deptids) {
                             adminDTO.setDeptId(deptid);
+                            // 现有用户同步不改变用户角色(新增用户默认普通用户)
+                            if(CollectionUtils.isNotEmpty(adminVOS)){
+                                adminDTO.setRoleId(adminVOS.get(0).getRoleId());
+                            }
                             adminMapper.updateByPrimaryKeySelective(adminDTO);
                         }
                     }else {
                         for (String deptid : deptids) {
                             adminDTO.setDeptId(deptid);
+                            // 普通用户
+                            adminDTO.setRoleId(8);
                             adminMapper.insertSelective(adminDTO);
                         }
                     }

+ 6 - 0
src/main/java/com/gz/vo/system/AdminVO.java

@@ -2,6 +2,7 @@ package com.gz.vo.system;
 
 import com.gz.vo.PageVO;
 import lombok.Data;
+import org.apache.commons.lang.StringUtils;
 
 /**
  * @author LiuchangLan
@@ -24,4 +25,9 @@ public class AdminVO extends PageVO {
 
     // 权限id
     private String roleId;
+
+    public AdminVO(String adminName,String account){
+        this.adminName = StringUtils.isNotBlank(adminName) ? adminName.trim() : null;
+        this.account = StringUtils.isNotBlank(account) ? account.trim() : null;
+    }
 }

+ 12 - 0
src/main/resources/mapper/adminMapper.xml

@@ -36,4 +36,16 @@
     <delete id="deleteById" parameterType="java.lang.String">
         delete from tab_admin where id = #{id}
     </delete>
+
+    <select id="selectList" resultType="com.gz.dto.system.AdminDTO" parameterType="com.gz.vo.system.AdminVO">
+        select * from tab_admin
+        <where>
+            <if test="adminName != null and adminName != ''">
+                and TRIM(admin_name)  = #{adminName}
+            </if>
+            <if test="account != null and account != ''">
+                and TRIM(account) =  #{account}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 82 - 88
src/main/resources/mapper/archiveMapper.xml

@@ -4,78 +4,68 @@
 
     <select id="searchList" resultType="com.gz.rvo.archive.ArchiveRVO"
             parameterType="com.gz.vo.archive.SearchArchiveVO">
-        SELECT
-        d.dict_name mj_text,
-        a.*
-        FROM `tab_archives` a
-        LEFT JOIN tab_dict d
-        ON a.mj = d.dict_code
-        LEFT JOIN tab_secondary_archive sa
-        ON a.id = sa.archive_id
+        SELECT d.dict_name mj_text, a.*
+        FROM tab_archives a
+        LEFT JOIN tab_dict d ON a.mj = d.dict_code
+        LEFT JOIN tab_secondary_archive sa ON a.id = sa.archive_id
         LEFT JOIN tab_admin u on u.id = a.created
-        <where>
-            a.deleted = 0
-            and ml IN (
-            SELECT
-            `code`
-            FROM
-            tab_archives_tree atr
-            LEFT JOIN tab_menu_role tmr ON atr.id = tmr.menu_id
-            WHERE
-            tmr.role_id = #{roleId}
-            AND tmr.role_type = 1
-            )
-            and mj in (select d.dict_code from tab_dict d left join tab_menu_role mr on d.id = mr.menu_id where
-            mr.role_id = #{roleId} and mr.role_type = 2 )
-
-            <if test="deptId!=null and deptId!=''">
+        where a.deleted = 0
+        and ml IN (
+        SELECT `code` FROM tab_archives_tree atr
+        LEFT JOIN tab_menu_role tmr ON atr.id = tmr.menu_id WHERE tmr.role_id = #{roleId} AND tmr.role_type = 1
+        )
+        and mj in (
+        select d.dict_code from tab_dict d left join tab_menu_role mr on d.id = mr.menu_id
+        where mr.role_id = #{roleId} and mr.role_type = 2
+        )
+        <if test="deptId!=null and deptId!=''">
             and u.dept_id = #{deptId}
-            </if>
-
-            <if test="dh != null and dh != ''">
-                AND a.dh like concat(concat('%',#{dh}),'%')
-            </if>
-            <if test="mlh != null and mlh != ''">
-                AND a.mlh = #{mlh}
-            </if>
-            <if test="wjbh != null and wjbh != ''">
-                AND (a.wjbh like concat(concat('%',#{wjbh}),'%') OR sa.wh like concat(concat('%',#{wjbh}),'%'))
-            </if>
-            <if test="ml != null and ml != ''">
-                AND (a.ml = #{ml} or a.ml in (select `code` FROM tab_archives_tree where parent_id = (SELECT id FROM `tab_archives_tree` where code = #{ml})))
-            </if>
-            <if test="bgqx != null and bgqx != ''">
-                <choose>
-                    <when test="bgqx == 'D10' or bgqx == '005'">
-                        AND a.bgqx in ('D10','005')
-                    </when>
-                    <when test="bgqx == 'D30' or bgqx == '004'">
-                        AND a.bgqx in ('D30','004')
-                    </when>
-                    <when test="bgqx == 'Y'.toString() or bgqx == '001'">
-                        AND a.bgqx in ('Y','001')
-                    </when>
-                    <otherwise>
-                        AND a.bgqx = #{bgqx}
-                    </otherwise>
-                </choose>
-            </if>
-            <if test="mj != null and mj != ''">
-                AND a.mj = #{mj}
-            </if>
-            <if test="gdnd != null and gdnd != ''">
-                AND a.gdnd = #{gdnd}
-            </if>
-            <if test="ztc != null and ztc != ''">
-                AND (a.ztc like concat(concat('%',#{ztc}),'%') OR a.tm like concat(concat('%',#{ztc}),'%') OR sa.tm like concat(concat('%',#{ztc}),'%'))
-            </if>
-            <if test="qzh != null and qzh != ''">
-                AND a.qzh = #{qzh}
-            </if>
-            <if test="sql != null and sql != ''">
-                ${sql}
-            </if>
-        </where>
+        </if>
+        <if test="dh != null and dh != ''">
+            AND a.dh like concat(concat('%',#{dh}),'%')
+        </if>
+        <if test="mlh != null and mlh != ''">
+            AND a.mlh = #{mlh}
+        </if>
+        <if test="wjbh != null and wjbh != ''">
+            AND (a.wjbh like concat(concat('%',#{wjbh}),'%') OR sa.wh like concat(concat('%',#{wjbh}),'%'))
+        </if>
+        <if test="ml != null and ml != ''">
+            AND (a.ml = #{ml} or a.ml in (select `code` FROM tab_archives_tree where parent_id = (SELECT id FROM
+            `tab_archives_tree` where code = #{ml})))
+        </if>
+        <if test="bgqx != null and bgqx != ''">
+            <choose>
+                <when test="bgqx == 'D10' or bgqx == '005'">
+                    AND a.bgqx in ('D10','005')
+                </when>
+                <when test="bgqx == 'D30' or bgqx == '004'">
+                    AND a.bgqx in ('D30','004')
+                </when>
+                <when test="bgqx == 'Y'.toString() or bgqx == '001'">
+                    AND a.bgqx in ('Y','001')
+                </when>
+                <otherwise>
+                    AND a.bgqx = #{bgqx}
+                </otherwise>
+            </choose>
+        </if>
+        <if test="mj != null and mj != ''">
+            AND a.mj = #{mj}
+        </if>
+        <if test="gdnd != null and gdnd != ''">
+            AND a.gdnd = #{gdnd}
+        </if>
+        <if test="ztc != null and ztc != ''">
+            AND (a.ztc like concat(concat('%',#{ztc}),'%') OR a.tm like concat(concat('%',#{ztc}),'%') OR sa.tm like
+            concat(concat('%',#{ztc}),'%'))
+        </if>
+        <if test="qzh != null and qzh != ''">
+            AND a.qzh = #{qzh}
+        </if>
+        <if test="sql != null and sql != ''">
+            ${sql}
+        </if>
         group by a.id
         <if test="field != null and field != '' and order != null and order != ''">
             order by ${field} ${order}
@@ -100,7 +90,8 @@
                 AND (a.wjbh like concat(concat('%',#{wjbh}),'%') OR sa.wh like concat(concat('%',#{wjbh}),'%'))
             </if>
             <if test="ml != null and ml != ''">
-                AND a.ml = #{ml} or a.ml in (select `code` FROM tab_archives_tree where parent_id = (SELECT id FROM `tab_archives_tree` where code = #{ml}))
+                AND a.ml = #{ml} or a.ml in (select `code` FROM tab_archives_tree where parent_id = (SELECT id FROM
+                `tab_archives_tree` where code = #{ml}))
             </if>
             <if test="bgqx != null and bgqx != ''">
                 AND a.bgqx = #{bgqx}
@@ -229,26 +220,24 @@
     </select>
 
     <select id="selectByPk" resultType="com.gz.rvo.archive.ArchiveRVO" parameterType="int">
-        SELECT
-            d.dict_name mj_text,
-            d1.dict_name bgqx_text,
-            d2.title ml_Text,
-            a.*
+        SELECT d.dict_name  mj_text,
+               d1.dict_name bgqx_text,
+               d2.title     ml_Text,
+               a.*
         FROM `tab_archives` a
-         LEFT JOIN tab_dict d ON a.mj = d.dict_code
-         LEFT JOIN tab_dict d1 ON a.bgqx = d1.dict_code
-         LEFT JOIN tab_archives_tree d2 ON a.ml = d2.code
+                 LEFT JOIN tab_dict d ON a.mj = d.dict_code
+                 LEFT JOIN tab_dict d1 ON a.bgqx = d1.dict_code
+                 LEFT JOIN tab_archives_tree d2 ON a.ml = d2.code
         where a.deleted = 0
-        and a.id = #{id}
+          and a.id = #{id}
     </select>
 
 
-    <select id="selectByDh"  resultType="com.gz.rvo.archive.ArchiveRVO" parameterType="string">
-        SELECT
-            d.dict_name mj_text,
-            d1.dict_name bgqx_text,
-            d2.title ml_Text,
-            a.*
+    <select id="selectByDh" resultType="com.gz.rvo.archive.ArchiveRVO" parameterType="string">
+        SELECT d.dict_name  mj_text,
+               d1.dict_name bgqx_text,
+               d2.title     ml_Text,
+               a.*
         FROM `tab_archives` a
                  LEFT JOIN tab_dict d ON a.mj = d.dict_code
                  LEFT JOIN tab_dict d1 ON a.bgqx = d1.dict_code
@@ -258,10 +247,15 @@
     </select>
 
     <select id="getMenuId" resultType="int">
-        select menu_id from tab_menu_role where role_id = #{id} and role_type = 4
+        select menu_id
+        from tab_menu_role
+        where role_id = #{id}
+          and role_type = 4
     </select>
 
     <select id="getDeptId" resultType="string">
-        select dept_id from tab_admin where id=#{id}
+        select dept_id
+        from tab_admin
+        where id = #{id}
     </select>
 </mapper>