瀏覽代碼

用户管理流程梳理

sqg 3 年之前
父節點
當前提交
d1428b2490

+ 45 - 0
tianhu-system/src/main/java/com/tianhu/system/controller/OwnSysUserController.java

@@ -1,5 +1,6 @@
 package com.tianhu.system.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.tianhu.common.core.constant.SalaryConstants;
 import com.tianhu.common.core.utils.CommonUtil;
 import com.tianhu.common.core.utils.StringUtils;
@@ -14,12 +15,15 @@ import com.tianhu.common.security.service.TokenService;
 import com.tianhu.system.api.domain.SysUser;
 import com.tianhu.system.api.model.LoginUser;
 import com.tianhu.system.domain.OwnSysUser;
+import com.tianhu.system.domain.SysCompany;
+import com.tianhu.system.domain.SysUserCompanyRel;
 import com.tianhu.system.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -42,6 +46,12 @@ public class OwnSysUserController extends BaseController
     @Autowired
     private TokenService tokenService;
 
+    @Autowired
+    private ISysCompanyService sysCompanyService;
+
+    @Autowired
+    private ISysUserCompanyRelService sysUserCompanyRelService;
+
     /**
      * 获取用户列表
      */
@@ -135,4 +145,39 @@ public class OwnSysUserController extends BaseController
         List<Map> list = ownSysUserService.selectUser(map);
         return AjaxResult.success(list);
     }
+
+    /**
+     * 获取当前用户信息
+     * @return
+     */
+    @GetMapping("/getNowUser")
+    public AjaxResult getNowUser(){
+        //查询当前操作员
+        LoginUser userInfo = tokenService.getLoginUser();
+        SysUser use = userInfo.getSysUser();
+        return AjaxResult.success(use);
+    }
+
+    /**
+     * 查询此用户下关联的企业
+     * @param userId
+     * @return
+     */
+    @GetMapping(value = { "/", "/{userId}" })
+    public AjaxResult companyList(@PathVariable(value = "userId", required = false) Long userId){
+        List<Map> result = new ArrayList<>();
+        //查询当前用户所关联的企业
+        LambdaQueryWrapper<SysUserCompanyRel> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(SysUserCompanyRel::getSucrUserId,userId);
+        List<SysUserCompanyRel> list = sysUserCompanyRelService.findSysUserCompanyRels(queryWrapper);
+        for (SysUserCompanyRel userCompanyRel : list){
+            String companyId = userCompanyRel.getSucrCompanyId();
+            SysCompany sysCompany = sysCompanyService.getById(companyId);
+            if(sysCompany != null) {
+                result.add(CommonUtil.entityToMap(sysCompany));
+            }
+        }
+        return AjaxResult.success(result);
+    }
+
 }

+ 64 - 37
tianhu-system/src/main/java/com/tianhu/system/controller/SysUserController.java

@@ -24,6 +24,7 @@ import com.tianhu.system.api.domain.SysRole;
 import com.tianhu.system.api.domain.SysUser;
 import com.tianhu.system.api.model.LoginUser;
 import com.tianhu.system.domain.*;
+import com.tianhu.system.domain.vo.TreeSelect;
 import com.tianhu.system.mapper.SysDeptMapper;
 import com.tianhu.system.mapper.SysUserMapper;
 import com.tianhu.system.mapper.SysUserRoleMapper;
@@ -402,29 +403,17 @@ public class SysUserController extends BaseController
     @GetMapping(value = { "/", "/{userId}" })
     public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
     {
-        //System.out.println("添加、修改用户时下拉用户角色");
         //获取当前操作人员
         LoginUser userInfo = tokenService.getLoginUser();
         String companyId = userInfo.getSysUser().getCompanyId();
-//        Long[] roleId = userInfo.getSysUser().getRoleIds();
         AjaxResult ajax = AjaxResult.success();
-        SysUserRole sysUserRole =new SysUserRole();
-        sysUserRole.setUserId(userId);
-        List<SysUserRole> userRole = iSysUserRoleService.selectSysUserRoleList(sysUserRole);
-        SysRole roleId =null;
-        if(userRole.size()>0){
-            roleId = roleService.selectRoleById(userRole.get(0).getRoleId());
-        }
         //角色
         SysRole role = new SysRole();
+        role.setIsAuto("0");
         Map map = new HashMap<>();
         if(!SalaryConstants.OPEX.equals(companyId)){
             map.put("companyId",companyId);
             role.setCompanyId(companyId);
-            if(roleId!=null&&"0".equals(roleId.getIsAuto())){
-                role.setIsAuto("0");
-            }
-
         }
         List<SysRole> roles = roleService.selectRoleAll(role);
         ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin() ).collect(Collectors.toList()));
@@ -499,15 +488,15 @@ public class SysUserController extends BaseController
         userCompanyRelService.createSysUserCompanyRel(userCompanyRel);
 
         // 审批表增加数据
-        Map<String, Object> flowableRes = flowableService.addFlowableUser(String.valueOf(queryUser.getUserId()), user.getNickName(), use.getCompanyId());
-        if (!"200".equals(flowableRes.get("code"))) {
-            throw new Exception("审批数据新增失败!");
-        }
-        SysDept dept = deptMapper.selectDeptById(use.getDeptId());
-        flowableRes = flowableService.addFlowableUser(String.valueOf(queryUser.getUserId()), user.getNickName(), dept.getAlternateNumber());
-        if (!"200".equals(flowableRes.get("code"))) {
-            throw new Exception("审批数据新增失败!");
-        }
+//        Map<String, Object> flowableRes = flowableService.addFlowableUser(String.valueOf(queryUser.getUserId()), user.getNickName(), use.getCompanyId());
+//        if (!"200".equals(flowableRes.get("code"))) {
+//            throw new Exception("审批数据新增失败!");
+//        }
+//        SysDept dept = deptMapper.selectDeptById(use.getDeptId());
+//        flowableRes = flowableService.addFlowableUser(String.valueOf(queryUser.getUserId()), user.getNickName(), dept.getAlternateNumber());
+//        if (!"200".equals(flowableRes.get("code"))) {
+//            throw new Exception("审批数据新增失败!");
+//        }
         return toAjax(1);
     }
 
@@ -522,21 +511,29 @@ public class SysUserController extends BaseController
     {
         LoginUser userInfo = tokenService.getLoginUser();
         SysUser use = userInfo.getSysUser();
-        //用户id
-        String userId = CommonUtil.objToString(userInfo.getUserid());
-        userService.checkUserAllowed(user);
-        if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
-        {
-            return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
-        }
-        //||use.getEmail().equals(user.getEmail())
-        else if (UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
-        {
-            return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
-        }
-        user.setUpdateBy(SecurityUtils.getUsername());
-        if(!SysConstant.PLATFORM_NO.equals(use.getCompanyId()) ){
-            user.setCompanyId(use.getCompanyId());
+        String companyId = use.getCompanyId();
+        if(SalaryConstants.OPEX.equals(companyId)) {
+            String com = user.getCompanyId();
+            if (CommonUtil.isEmpty(com)) {
+                return AjaxResult.error("修改用户'" + user.getNickName() + "'失败,请选择公司");
+            }
+            userService.checkUserAllowed(user);
+            if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
+                return AjaxResult.error("修改用户'" + user.getNickName() + "'失败,手机号码已存在");
+            }
+            else if (UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
+                return AjaxResult.error("修改用户'" + user.getNickName() + "'失败,邮箱账号已存在");
+            }
+            user.setUpdateBy(CommonUtil.objToString(SecurityUtils.getUserId()));
+        }else if(!SalaryConstants.OPEX.equals(companyId)){
+            userService.checkUserAllowed(user);
+            if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
+                return AjaxResult.error("修改用户'" + user.getNickName() + "'失败,手机号码已存在");
+            }
+            else if (UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
+                return AjaxResult.error("修改用户'" + user.getNickName() + "'失败,邮箱账号已存在");
+            }
+            user.setUpdateBy(CommonUtil.objToString(SecurityUtils.getUserId()));
         }
         return toAjax(userService.updateUser(user));
     }
@@ -584,4 +581,34 @@ public class SysUserController extends BaseController
         user.setUpdateBy(SecurityUtils.getUsername());
         return toAjax(userService.updateUserStatus(user));
     }
+
+    /**
+     * 根据企业id获取部门与角色信息
+     * @param companyId
+     * @return
+     */
+    @GetMapping("getRoleDept/{companyId}")
+    public AjaxResult getRoleDept(@PathVariable String companyId)
+    {
+        //获取部门信息
+        SysDept sysDept = new SysDept();
+        sysDept.setCompanyId(companyId);
+        sysDept.setStatus("0");
+        sysDept.setDelFlag("0");
+        List<SysDept> deptList = deptService.selectDeptList(sysDept);
+        List<TreeSelect> deptTreeSelect = deptService.buildDeptTreeSelect(deptList);
+        //获取角色信息
+        SysRole sysRole = new SysRole();
+        sysRole.setIsAuto("0");
+        sysRole.setCompanyId(companyId);
+        sysRole.setStatus("0");
+        sysRole.setDelFlag("0");
+        List<SysRole> roleList = roleService.selectRoleList(sysRole);
+        //传入前台
+        AjaxResult ajax = AjaxResult.success();
+        ajax.put("deptList", deptTreeSelect);
+        ajax.put("roleList", roleList);
+        return ajax;
+    }
+
 }

+ 7 - 0
tianhu-system/src/main/java/com/tianhu/system/mapper/SysUserRoleMapper.java

@@ -117,4 +117,11 @@ public interface SysUserRoleMapper
      * @return 结果
      */
     public int deleteSysUserRoleByIds(Long[] userIds);
+
+    /**
+     * 查询要删除的数据
+     * @param map
+     * @return
+     */
+    public List<Map> selectDeleteQuery(Map map);
 }

+ 9 - 0
tianhu-system/src/main/java/com/tianhu/system/service/ISysUserRoleService.java

@@ -1,6 +1,8 @@
 package com.tianhu.system.service;
 
 import java.util.List;
+import java.util.Map;
+
 import com.tianhu.system.domain.SysUserRole;
 
 /**
@@ -58,4 +60,11 @@ public interface ISysUserRoleService
      * @return 结果
      */
     public int deleteSysUserRoleById(Long userId);
+
+    /**
+     * 查询要删除的数据
+     * @param map
+     * @return
+     */
+    public List<Map> selectDeleteQuery(Map map);
 }

+ 14 - 0
tianhu-system/src/main/java/com/tianhu/system/service/impl/SysUserRoleServiceImpl.java

@@ -1,6 +1,8 @@
 package com.tianhu.system.service.impl;
 
 import java.util.List;
+import java.util.Map;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.tianhu.system.mapper.SysUserRoleMapper;
@@ -90,4 +92,16 @@ public class SysUserRoleServiceImpl implements ISysUserRoleService
     {
         return sysUserRoleMapper.deleteSysUserRoleById(userId);
     }
+
+    /**
+     * 查询要删除的数据
+     * @param map
+     * @return
+     */
+    @Override
+    public List<Map> selectDeleteQuery(Map map)
+    {
+        return sysUserRoleMapper.selectDeleteQuery(map);
+    }
+
 }

+ 16 - 6
tianhu-system/src/main/java/com/tianhu/system/service/impl/SysUserServiceImpl.java

@@ -3,6 +3,7 @@ package com.tianhu.system.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.tianhu.common.core.constant.UserConstants;
 import com.tianhu.common.core.exception.CustomException;
+import com.tianhu.common.core.utils.CommonUtil;
 import com.tianhu.common.core.utils.DateUtils;
 import com.tianhu.common.core.utils.SecurityUtils;
 import com.tianhu.common.core.utils.StringUtils;
@@ -280,11 +281,21 @@ public class SysUserServiceImpl implements ISysUserService
     public int updateUser(SysUser user)
     {
         Long userId = user.getUserId();
-        Map<String, Object> param = new HashMap<>();
-        param.put("userId", userId);
-        param.put("companyId", user.getCompanyId());
-        // 删除用户与角色关联
-        userRoleMapper.deleteUserRoleByUserId(param);
+        Map map = new HashMap();
+        map.put("userId",userId);
+        map.put("companyId",user.getCompanyId());
+        List<Map> list = userRoleMapper.selectDeleteQuery(map);
+        if(list.size() > 0){
+            for (Map m :list){
+                String id = CommonUtil.objToString(m.get("userId"));
+                String roId = CommonUtil.objToString(m.get("roleId"));
+                Map<String, Object> param = new HashMap<>();
+                param.put("userId", id);
+                param.put("roleId", roId);
+                // 删除用户与角色关联
+                userRoleMapper.deleteUserRoleByUserId(param);
+            }
+        }
         // 新增用户与角色管理
         insertUserRole(user);
 
@@ -522,7 +533,6 @@ public class SysUserServiceImpl implements ISysUserService
         // 删除用户与角色关联
         userRoleMapper.deleteUserRole(userIds);
         // 删除用户与岗位关联
-        userPostMapper.deleteUserPost(userIds);
         return userMapper.deleteUserByIds(userIds);
     }
 

+ 2 - 18
tianhu-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -142,45 +142,29 @@
 	<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
 		insert into sys_user(
 		<if test="userId != null and userId != 0">user_id,</if>
-		<if test="deptId != null and deptId != 0">dept_id,</if>
 		<if test="userName != null and userName != ''">user_name,</if>
-		<if test="companyId != null and companyId != ''">company_id,</if>
 		<if test="nickName != null and nickName != ''">nick_name,</if>
 		<if test="email != null and email != ''">email,</if>
 		<if test="avatar != null and avatar != ''">avatar,</if>
-		<if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
 		<if test="sex != null and sex != ''">sex,</if>
 		<if test="password != null and password != ''">password,</if>
 		<if test="status != null and status != ''">status,</if>
+		<if test="delFlag != null and delFlag != ''">del_flag,</if>
 		<if test="createBy != null and createBy != ''">create_by,</if>
 		<if test="remark != null and remark != ''">remark,</if>
-		<if test="staffCode != null and staffCode != ''">staff_code,</if>
-		<if test="birthDate != null and birthDate != ''">birth_date,</if>
-		<if test="entryDate != null and entryDate != ''">entry_date,</if>
-		<if test="leaveDate != null and leaveDate != ''">leave_date,</if>
-		<if test="education != null and education != ''">education,</if>
-		<if test="position != null and position != ''">position,</if>
 		create_time
 		)values(
 		<if test="userId != null and userId != ''">#{userId},</if>
-		<if test="deptId != null and deptId != ''">#{deptId},</if>
 		<if test="userName != null and userName != ''">#{userName},</if>
-		<if test="companyId != null and companyId != ''">#{companyId},</if>
 		<if test="nickName != null and nickName != ''">#{nickName},</if>
 		<if test="email != null and email != ''">#{email},</if>
 		<if test="avatar != null and avatar != ''">#{avatar},</if>
-		<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
 		<if test="sex != null and sex != ''">#{sex},</if>
 		<if test="password != null and password != ''">#{password},</if>
 		<if test="status != null and status != ''">#{status},</if>
+		<if test="delFlag != null and delFlag != ''">#{delFlag},</if>
 		<if test="createBy != null and createBy != ''">#{createBy},</if>
 		<if test="remark != null and remark != ''">#{remark},</if>
-		<if test="staffCode != null and staffCode != ''">#{staffCode},</if>
-		<if test="birthDate != null and birthDate != ''">#{birthDate},</if>
-		<if test="entryDate != null and entryDate != ''">#{entryDate},</if>
-		<if test="leaveDate != null and leaveDate != ''">#{leaveDate},</if>
-		<if test="education != null and education != ''">#{education},</if>
-		<if test="position != null and position != ''">#{position},</if>
 		sysdate()
 		)
 	</insert>

+ 11 - 3
tianhu-system/src/main/resources/mapper/system/SysUserRoleMapper.xml

@@ -11,9 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 	<delete id="deleteUserRoleByUserId" parameterType="map">
 		delete from sys_user_role where user_id = #{userId}
-		<if test = "companyId != null and companyId != ''">
-			and company_id = #{companyId}
-		</if>
+		and role_id = #{roleId}
 	</delete>
 	
 	<select id="countUserRoleByRoleId" resultType="Integer">
@@ -61,5 +59,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		 where user_id=#{userId}
 	</select>
 
+	<select id="selectDeleteQuery" parameterType="map" resultType="java.util.Map">
+		select r.user_id 'userId',r.role_id 'roleId'
+		from sys_user_role r
+		left join sys_role s on s.role_id = r.role_id
+		where r.user_id = #{userId}
+		and s.is_auto = '0'
+		<if test="companyId != null and companyId != ''">
+		and s.company_id = #{companyId}
+		</if>
+	</select>
 
 </mapper>