2 Commits e242b4a716 ... a3c6b70960

Author SHA1 Message Date
  hanzhen a3c6b70960 用户同步不改变用户角色,新增用户默认普通用户角色 3 years ago
  hanzhen 4e46982281 1、增加用户删除方法 3 years ago

+ 1 - 1
src/main/java/com/gz/controller/system/AdminController.java

@@ -43,7 +43,7 @@ public class AdminController {
 
     @DeleteMapping("delete")
     @TraceLog(module = "管理员管理",business = "删除管理员")
-    public Integer delete( Integer id){
+    public Integer delete(String id){
         return adminService.delete(id);
     }
 

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

@@ -3,6 +3,7 @@ package com.gz.mapper.system;
 import com.gz.dto.system.AdminDTO;
 import com.gz.rvo.system.AdminRVO;
 import com.gz.vo.system.AdminVO;
+import org.apache.ibatis.annotations.Param;
 import tk.mybatis.mapper.common.Mapper;
 
 import java.util.List;
@@ -16,4 +17,13 @@ public interface AdminMapper extends Mapper<AdminDTO> {
     AdminRVO selectByPrimaryKeyDept(String id);
 
     List<AdminDTO> selectByPage(AdminVO vo);
+
+    /**
+     * 删除用户
+     * @param id
+     * @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;
     }
 

+ 1 - 1
src/main/java/com/gz/service/system/AdminService.java

@@ -22,7 +22,7 @@ public interface AdminService {
      * @author LiuChangLan
      * @since 2020/9/4 14:46
      */
-    Integer delete(Integer id);
+    Integer delete(String id);
 
     /**
      * @description 改

+ 12 - 4
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;
 
@@ -51,8 +52,8 @@ public class AdminServiceImpl implements AdminService {
     }
 
     @Override
-    public Integer delete(Integer id) {
-        return adminMapper.deleteByPrimaryKey(id);
+    public Integer delete(String id) {
+        return adminMapper.deleteById(id);
     }
 
     @Override
@@ -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;
+    }
 }

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

@@ -32,4 +32,20 @@
             </if>
         </where>
     </select>
+
+    <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>

+ 6 - 9
src/main/resources/static/page/admin/edit.html

@@ -45,9 +45,9 @@
 
 
     <div class="layui-form-item">
-        <label class="layui-form-label required">手机号</label>
+        <label class="layui-form-label">手机号</label>
         <div class="layui-input-block">
-            <input type="text" name="phone" lay-verify="phone" lay-reqtext="手机号不能为空" placeholder="请输入手机号"
+            <input type="text" name="phone" placeholder="请输入手机号"
                    value="" class="layui-input">
         </div>
     </div>
@@ -104,9 +104,7 @@
         let deptId = ''
         // url参数
         const urlParam = layui.url()
-        console.log('urlParam.id',urlParam.id);
         /**方-------------------------------法-------------------------------定-------------------------------义*/
-
             //保存方法
         let save = function (data) {
                 http.post('system/admin/addOrUpdate', data, true, function (res) {
@@ -145,12 +143,11 @@
                         enable: true
                     }
                 },
+                click: function (d) {
+                    $("#deptId").val(d.current.id);
+                },
                 success: function (res) {
-                    if (deptId != null) {
-                        if (urlParam.id != '' && deptId != '') {
-                            treeSelect.checkNode('deptId', deptId);
-                        }
-                    }
+                    treeSelect.checkNode('deptId', deptId);
                 }
             });
         }