Bladeren bron

新增获取公司部门数据

anderx 4 maanden geleden
bovenliggende
commit
0b0aa168c0

+ 9 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java

@@ -151,6 +151,15 @@ public class SysUser extends BaseEntity
     private String ddUserId;
     private String tianheId;
     private String kyId;
+    private String kySuperId;
+
+    public String getKySuperId() {
+        return kySuperId;
+    }
+
+    public void setKySuperId(String kySuperId) {
+        this.kySuperId = kySuperId;
+    }
 
     public String getKyId() {
         return kyId;

+ 5 - 5
ruoyi-system/src/main/java/com/ruoyi/project/bo/pushCompanyDataBo.java

@@ -6,7 +6,7 @@ public class pushCompanyDataBo {
 
     private List<pushDataDep> listDep;
     private List<pushDataUser> listUser;
-    private List<pushDataProject> listUserClock;
+    private List<pushDataProject> listUserProject;
 
     public List<pushDataDep> getListDep() {
         return listDep;
@@ -24,11 +24,11 @@ public class pushCompanyDataBo {
         this.listUser = listUser;
     }
 
-    public List<pushDataProject> getListUserClock() {
-        return listUserClock;
+    public List<pushDataProject> getListUserProject() {
+        return listUserProject;
     }
 
-    public void setListUserClock(List<pushDataProject> listUserClock) {
-        this.listUserClock = listUserClock;
+    public void setListUserProject(List<pushDataProject> listUserProject) {
+        this.listUserProject = listUserProject;
     }
 }

+ 54 - 0
ruoyi-system/src/main/java/com/ruoyi/project/bo/pushDataUser.java

@@ -1,4 +1,58 @@
 package com.ruoyi.project.bo;
 
 public class pushDataUser {
+    private String userId;
+    private String kyDeptId;
+    private String userName;
+    private String nickName;
+    private String kyId;
+    private String kySuperId;
+
+    public String getKyDeptId() {
+        return kyDeptId;
+    }
+
+    public void setKyDeptId(String kyDeptId) {
+        this.kyDeptId = kyDeptId;
+    }
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getNickName() {
+        return nickName;
+    }
+
+    public void setNickName(String nickName) {
+        this.nickName = nickName;
+    }
+
+    public String getKyId() {
+        return kyId;
+    }
+
+    public void setKyId(String kyId) {
+        this.kyId = kyId;
+    }
+
+    public String getKySuperId() {
+        return kySuperId;
+    }
+
+    public void setKySuperId(String kySuperId) {
+        this.kySuperId = kySuperId;
+    }
 }

+ 77 - 10
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectTaskServiceImpl.java

@@ -22,8 +22,11 @@ import com.ruoyi.project.mapper.ProjectStaffMapper;
 import com.ruoyi.project.mapper.ProjectStaffRecordMapper;
 import com.ruoyi.project.mapper.ProjectTaskMapper;
 import com.ruoyi.project.service.ProjectTaskService;
+import com.ruoyi.system.domain.SysUserRole;
 import com.ruoyi.system.mapper.SysDeptMapper;
+import com.ruoyi.system.mapper.SysRoleMapper;
 import com.ruoyi.system.mapper.SysUserMapper;
+import com.ruoyi.system.mapper.SysUserRoleMapper;
 import com.ruoyi.system.service.ISysDeptService;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.usermodel.XWPFParagraph;
@@ -69,6 +72,10 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
     private SysDeptMapper sysDeptMapper;
     @Resource
     private TianheService tianheService;
+    @Resource
+    private SysUserRoleMapper sysUserRoleMapper;
+
+
     @Value("${ruoyi.profile}")
     private  String profile=null;
 
@@ -583,20 +590,80 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
     @Override
     public Object pushCompanyData(pushCompanyDataBo in) {
         //导入部门
-        if (!in.getListDep().isEmpty()){
-            List<pushDataDep> listDep = in.getListDep();
-            //假设只设置2级 1级为公司
-            List<pushDataDep> sp1 = listDep.stream().filter(e -> StringUtils.isNotEmpty(e.getUsci())).collect(Collectors.toList());
-            //先新增公司
-            pushDataDep pushDataDep = sp1.get(0);
-            SysDept sysDept1 = sysDeptMapper.selectByusci(pushDataDep.getUsci());
-            if (sysDept1!=null) throw new ServiceException("公司已存在");
-            SysDept sysDept=addCompany(pushDataDep);
-            pushDep(listDep, pushDataDep.getKyId(),sysDept);
+//        if (!in.getListDep().isEmpty()){
+//            List<pushDataDep> listDep = in.getListDep();
+//            //假设只设置2级 1级为公司
+//            List<pushDataDep> sp1 = listDep.stream().filter(e -> StringUtils.isNotEmpty(e.getUsci())).collect(Collectors.toList());
+//            //先新增公司
+//            pushDataDep pushDataDep = sp1.get(0);
+//            SysDept sysDept1 = sysDeptMapper.selectByusci(pushDataDep.getUsci());
+//            if (sysDept1!=null) throw new ServiceException("公司已存在");
+//            SysDept sysDept=addCompany(pushDataDep);
+//            pushDep(listDep, pushDataDep.getKyId(),sysDept);
+//        }
+        //导入用户
+        if (!in.getListUser().isEmpty()){
+            List<pushDataUser> listUser = in.getListUser();
+            //获取未获取到上级的数据
+            List<SysUser> notSuperList = new ArrayList<>();
+            List<SysUser> allUserList =  new ArrayList<>();
+            listUser.stream().forEach(e -> {
+                SysUser sysUser = new SysUser();
+                sysUser.setUserName(e.getUserName());
+                sysUser.setNickName(e.getNickName());
+                sysUser.setKyId(e.getKyId());
+                sysUser.setKySuperId(e.getKySuperId());
+                sysUser.setPassword(SecurityUtils.encryptPassword("123456"));
+                sysUser.setStatus("0");
+                sysUser.setDelFlag("0");
+                if (e.getKyDeptId()!=null){
+                    SysDept sysDept = sysDeptMapper.selectByKyId(e.getKyDeptId());
+                    sysUser.setDeptId(sysDept.getDeptId());
+                }
+                SysUser sysUser1 = userMapper.selectByKyId(e.getKySuperId());
+                if (sysUser1==null){
+                    userMapper.insertUser(sysUser);
+                    notSuperList.add(sysUser);
+                }else {
+                    sysUser.setSuperiorId(sysUser1.getUserId());
+                    userMapper.insertUser(sysUser);
+                }
+                allUserList.add(sysUser);
+            });
+            if (!notSuperList.isEmpty()){
+                notSuperList.stream().forEach(e -> {
+                    SysUser sysUser1 = userMapper.selectByKyId(e.getKySuperId());
+                    if (sysUser1!=null){
+                        e.setSuperiorId(sysUser1.getUserId());
+                    }
+                    userMapper.updateUser(e);
+                });
+            }
+            //设置人员角色
+            List<SysUserRole>  roleList = new ArrayList<>();
+            for (SysUser sysUser : allUserList) {
+                SysUserRole sysUserRole = new SysUserRole();
+                sysUserRole.setUserId(sysUser.getUserId());
+                sysUserRole.setRoleId(2l);
+                roleList.add(sysUserRole);
+            }
+            //每50个执行一次批量新增
+            int maxSize = 50;
+            if (roleList.size() > maxSize){
+                for (int i = 0; i < listUser.size(); i += maxSize) {
+                    int end = Math.min(i + maxSize, listUser.size());
+                    List<SysUserRole> list = roleList.subList(i, end);
+                    sysUserRoleMapper.batchUserRole(list);
+                }
+            }else {
+                sysUserRoleMapper.batchUserRole(roleList);
+            }
+
         }
         return 1;
     }
 
+
     private void pushDep(List<pushDataDep> listDep, String kyId, SysDept pushDataDep) {
         List<pushDataDep> sp2 = listDep.stream().filter(e ->
                 Objects.equals(e.getKySuperId(),kyId)).collect(Collectors.toList());

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java

@@ -147,4 +147,7 @@ public interface SysUserMapper
     SysUser selectDDUserId(Long ddUserId);
 
     List<SysUser> selectByDeptId(Long deptId);
+
+
+    SysUser selectByKyId(String kySuperId);
 }

+ 12 - 4
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -38,7 +38,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="deptName"  column="dept_name"   />
 		<result property="superiorName"       column="superiorName"       />
 		<result property="kyId"       column="ky_id"       />
-        <association property="dept"    javaType="com.ruoyi.common.core.domain.entity.SysUser"         resultMap="deptResult" />
+		<result property="kySuperId" column="ky_super_id" />
+		<association property="dept"    javaType="com.ruoyi.common.core.domain.entity.SysUser"         resultMap="deptResult" />
         <collection  property="roles"   javaType="java.util.List"  resultMap="RoleResult" />
     </resultMap>
 
@@ -68,7 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
         d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,d.ancestors,d.max_duration,u.open_id,d.company_id,
         r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,u.superior_id ,su.nick_name superiorName,
-		u.job_number,u.full_job,u.dd_user_id,u.tianhe_id,u.ky_id
+		u.job_number,u.full_job,u.dd_user_id,u.tianhe_id,u.ky_id,u.ky_super_id
         from sys_user u
 		    left join sys_dept d on u.dept_id = d.dept_id
 		    left join sys_user_role ur on u.user_id = ur.user_id
@@ -80,7 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag,
 		       u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader,u.open_id,u.superior_id,
 		       u.project_quantity,u.job_number,u.full_job,sup.post_id,u.duration,sp.post_name,su.nick_name superiorName,
-			sr.role_id roleId, sr.role_name roleName, u.ky_id
+			sr.role_id roleId, sr.role_name roleName, u.ky_id, u.ky_super_id
 		from sys_user u
 		left join sys_dept d on u.dept_id = d.dept_id
 		left join sys_user_post sup on u.user_id = sup.user_id
@@ -157,7 +158,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 
 	<select id="selectAllocatedList" parameterType="com.ruoyi.common.core.domain.entity.SysUser" resultMap="SysUserResult">
-	    select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time,u.ky_id
+	    select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time,u.ky_id,u.ky_super_id
 	    from sys_user u
 			 left join sys_dept d on u.dept_id = d.dept_id
 			 left join sys_user_role ur on u.user_id = ur.user_id
@@ -246,6 +247,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="ddUserId != null and ddUserId != ''">dd_user_id,</if>
  			<if test="tianheId != null and tianheId != ''">tianhe_id,</if>
 			<if test="kyId != null and kyId != ''">ky_id,</if>
+ 		    <if test="kySuperId != null and kySuperId != ''">ky_super_id,</if>
  			create_time
  		)values(
  			<if test="userId != null and userId != ''">#{userId},</if>
@@ -269,6 +271,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="ddUserId != null and ddUserId != ''">#{ddUserId},</if>
 			<if test="tianheId != null and tianheId != ''">#{tianheId},</if>
  		    <if test="kyId != null and kyId != ''">#{kyId},</if>
+			<if test="kySuperId != null and kySuperId != ''">#{kySuperId},</if>
  			sysdate()
  		)
 	</insert>
@@ -298,6 +301,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="ddUserId != null and ddUserId != ''">dd_user_id=#{ddUserId},</if>
 			<if test="tianheId != null and tianheId != ''">tianhe_id=#{tianheId},</if>
  		    <if test="kyId != null">ky_id= #{kyId,jdbcType=VARCHAR},</if>
+ 		    <if test="kySuperId != null">ky_super_id= #{kySuperId,jdbcType=VARCHAR},</if>
  			update_time = sysdate()
  		</set>
  		where user_id = #{userId}
@@ -401,4 +405,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<include refid="selectUserVo"/>
 		where u.dept_id = #{deptId} and u.del_flag = '0'
 	</select>
+	<select id="selectByKyId" resultMap="SysUserResult">
+		<include refid="selectUserVo"/>
+		where u.ky_id = #{kyId} and u.del_flag = '0'
+	</select>
 </mapper>