소스 검색

新增用户工号判定修改为部门

anderx 2 년 전
부모
커밋
7a3bc6badb

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectStaffRecordServiceImpl.java

@@ -361,6 +361,7 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         int failureNum = 0;
         StringBuilder successMsg = new StringBuilder();
         StringBuilder failureMsg = new StringBuilder();
+        Long companyId = deptService.selectCompanyByDeptId();
         for (ProjectStaffRecordOut p : list)
         {
             try
@@ -370,7 +371,7 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
                 if (StringUtils.isNull(projectStaffRecord)){
 //                    BeanValidators.validateWithException(validator, projectStaffRecord);
                     if (StringUtils.isNotBlank(p.getAdminName())){
-                        SysUser sysUser = sysUserMapper.checkJobNumber(p.getJobNumber());
+                        SysUser sysUser = sysUserMapper.checkJobNumber(p.getJobNumber(),companyId);
                         if (StringUtils.isNull(sysUser)){
                             throw new ServiceException(String.format("用户[%s]不存在",p.getAdminName()));
                         }

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

@@ -135,7 +135,7 @@ public interface SysUserMapper
 
     void updateUserProjectSum(@Param("aid") Long aid, @Param("type") Integer type);
 
-    SysUser checkJobNumber(String jobNumber);
+    SysUser checkJobNumber(@Param("jobNumber") String jobNumber, @Param("companyId") Long companyId);
 
     SysUser selectByNikeName(String nikeName);
 

+ 11 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -5,6 +5,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 import javax.validation.Validator;
 
+import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.enums.UserRolesType;
 import com.ruoyi.project.domain.ProjectStaff;
 import com.ruoyi.project.domain.ProjectTask;
@@ -603,7 +604,8 @@ public class SysUserServiceImpl implements ISysUserService
 
     @Override
     public boolean checkJobNumber(SysUser user) {
-        SysUser sysUser = userMapper.checkJobNumber(user.getJobNumber());
+        Long companyId = getCompany(user.getDeptId());
+        SysUser sysUser = userMapper.checkJobNumber(user.getJobNumber(),companyId);
         if (StringUtils.isNotNull(user.getUserId())&&user.getUserId().equals(sysUser.getUserId())){
             return false;
         }else {
@@ -612,4 +614,12 @@ public class SysUserServiceImpl implements ISysUserService
         return false;
     }
 
+    private Long getCompany(Long deptId) {
+        SysDept sysDept = deptService.selectDeptById(deptId);
+        String ancestors = sysDept.getAncestors();
+        String[] split = ancestors.split(",");
+        if (split.length>2)return Long.valueOf(split[2]);
+        else return deptId;
+    }
+
 }

+ 7 - 2
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -201,8 +201,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
 	</select>
 
-	<select id="checkJobNumber" parameterType="String" resultMap="SysUserResult">
-		select user_id, Job_number from sys_user where Job_number = #{JobNumber} and del_flag = '0' limit 1
+	<select id="checkJobNumber"  resultMap="SysUserResult">
+		select user_id, Job_number from sys_user a
+		where Job_number = #{jobNumber}
+		<if test="companyId !=null">
+		AND (a.dept_id = #{companyId} OR a.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{companyId}, ancestors) ))
+		</if>
+		and del_flag = '0' limit 1
 	</select>