|  |  | 
 |  |  | import com.ruoyi.common.constant.UserConstants; | 
 |  |  | import com.ruoyi.common.core.domain.entity.*; | 
 |  |  | import com.ruoyi.common.exception.ServiceException; | 
 |  |  | import com.ruoyi.common.utils.DtoConversionUtils; | 
 |  |  | import com.ruoyi.common.utils.SecurityUtils; | 
 |  |  | import com.ruoyi.common.utils.StringUtils; | 
 |  |  | import com.ruoyi.common.utils.bean.BeanValidators; | 
 |  |  | 
 |  |  | import com.ruoyi.system.mapper.*; | 
 |  |  | import com.ruoyi.system.service.ISysConfigService; | 
 |  |  | import com.ruoyi.system.service.ISysUserService; | 
 |  |  | import com.smartor.domain.SvyTaskVO; | 
 |  |  | import com.smartor.mapper.SysUserDeptMapper; | 
 |  |  | import org.slf4j.Logger; | 
 |  |  | import org.slf4j.LoggerFactory; | 
 |  |  | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  | import org.springframework.util.ObjectUtils; | 
 |  |  |  | 
 |  |  | import javax.validation.Validator; | 
 |  |  | import java.util.*; | 
 |  |  | 
 |  |  |     @Override | 
 |  |  |     public SysUser selectUserByUserName2(String userName) { | 
 |  |  |         String[] split = userName.split("&"); | 
 |  |  |         SysUser sysUser = userMapper.selectUserByUserNameByCondition(split[0], split[1]); | 
 |  |  |         SysUser sysUser = userMapper.selectUserByUserNameByCondition(split[0], split[1], null); | 
 |  |  |         if (Objects.isNull(sysUser)) return sysUser; | 
 |  |  |         List<SysDept> sysDepts = null; | 
 |  |  |         if (StringUtils.isNotEmpty(split[0]) && split[0].equals("admin")) { | 
 |  |  | 
 |  |  |         SysUserDept sysUserDept = new SysUserDept(); | 
 |  |  |         sysUserDept.setUserId(sysUser.getUserId()); | 
 |  |  |         sysUserDept.setDeptType(sysUser.getSearchscope()); | 
 |  |  |         sysUserDept.setOrgid(split[1]); | 
 |  |  |         List<SysUserDept> sysUserDeptKSs = null; | 
 |  |  |         List<SysUserDept> sysUserDeptBQs = null; | 
 |  |  |         if (StringUtils.isNotEmpty(sysUser.getSearchscope()) && sysUser.getSearchscope().equals("0")) { | 
 |  |  | 
 |  |  |             sysUserDeptBQs = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); | 
 |  |  |             //如果是admin,需要对sysUserDeptBQs,sysUserDeptBQs去重 | 
 |  |  |             if (StringUtils.isNotEmpty(split[0]) && split[0].equals("admin")) { | 
 |  |  |                 //如果是admin,只能去sys_dept去取数据 | 
 |  |  |                 SysDept dept = new SysDept(); | 
 |  |  |                 dept.setOrgid(split[1]); | 
 |  |  |                 dept.setDeptType("1"); | 
 |  |  |                 sysDepts = sysDeptMapper.selectDeptList(dept); | 
 |  |  |                 sysUserDeptKSs = DtoConversionUtils.sourceToTarget(sysDepts, SysUserDept.class); | 
 |  |  |  | 
 |  |  |                 dept.setDeptType("2"); | 
 |  |  |                 sysDepts = sysDeptMapper.selectDeptList(dept); | 
 |  |  |                 sysUserDeptBQs = DtoConversionUtils.sourceToTarget(sysDepts, SysUserDept.class); | 
 |  |  |  | 
 |  |  |                 List<SysUserDept> distinctUserDepts = new ArrayList<>(); | 
 |  |  |                 Set<String> uniqueDeptCodes = new HashSet<>(); | 
 |  |  |                 for (SysUserDept userDept : sysUserDeptKSs) { | 
 |  |  | 
 |  |  |         } | 
 |  |  |         return sysUser; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public SysUser selectUserByUserNameAndDeptId(String userName) { | 
 |  |  |         String[] split = userName.split("&"); | 
 |  |  |         if (split[2].contains("null")) { | 
 |  |  |             split[2] = null; | 
 |  |  |         } | 
 |  |  |         SysUser sysUser = userMapper.selectUserByUserNameByCondition(split[0], split[1], split[2]); | 
 |  |  |         log.info("selectUserByUserNameAndDeptId的sysUser的值为:{}", sysUser); | 
 |  |  |         if (Objects.isNull(sysUser)) return sysUser; | 
 |  |  |         List<SysDept> sysDepts = null; | 
 |  |  |         if (StringUtils.isNotEmpty(split[0]) && split[0].equals("admin")) { | 
 |  |  |             SysDept dept = new SysDept(); | 
 |  |  |             dept.setOrgid(split[1]); | 
 |  |  |             sysDepts = sysDeptMapper.selectDeptList(dept); | 
 |  |  |         } else { | 
 |  |  |             sysDepts = sysUserDeptMapper.selectDeptListByUserId(sysUser.getUserId()); | 
 |  |  |         } | 
 |  |  |         List<Long> deptIds = new ArrayList<>(); | 
 |  |  |         for (SysDept sysDept : sysDepts) { | 
 |  |  |             deptIds.add(sysDept.getDeptId()); | 
 |  |  |         } | 
 |  |  |         SysUserDept sysUserDept = new SysUserDept(); | 
 |  |  |         sysUserDept.setUserId(sysUser.getUserId()); | 
 |  |  |         sysUserDept.setDeptType(sysUser.getSearchscope()); | 
 |  |  |         sysUserDept.setOrgid(split[1]); | 
 |  |  |         List<SysUserDept> sysUserDeptKSs = null; | 
 |  |  |         List<SysUserDept> sysUserDeptBQs = null; | 
 |  |  |         if (StringUtils.isNotEmpty(sysUser.getSearchscope()) && sysUser.getSearchscope().equals("0")) { | 
 |  |  |             if (StringUtils.isNotEmpty(split[0]) && split[0].equals("admin")) { | 
 |  |  |                 sysUserDept.setUserId(null); | 
 |  |  |             } | 
 |  |  |             sysUserDept.setDeptType("1"); | 
 |  |  |             sysUserDeptKSs = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); | 
 |  |  |             sysUserDept.setDeptType("2"); | 
 |  |  |             sysUserDeptBQs = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); | 
 |  |  |             //如果是admin,需要对sysUserDeptBQs,sysUserDeptBQs去重 | 
 |  |  |             if (StringUtils.isNotEmpty(split[0]) && split[0].equals("admin")) { | 
 |  |  |                 //如果是admin,只能去sys_dept去取数据 | 
 |  |  |                 SysDept dept = new SysDept(); | 
 |  |  |                 dept.setOrgid(split[1]); | 
 |  |  |                 dept.setDeptType("1"); | 
 |  |  |                 sysDepts = sysDeptMapper.selectDeptList(dept); | 
 |  |  |                 sysUserDeptKSs = DtoConversionUtils.sourceToTarget(sysDepts, SysUserDept.class); | 
 |  |  |  | 
 |  |  |                 dept.setDeptType("2"); | 
 |  |  |                 sysDepts = sysDeptMapper.selectDeptList(dept); | 
 |  |  |                 sysUserDeptBQs = DtoConversionUtils.sourceToTarget(sysDepts, SysUserDept.class); | 
 |  |  |  | 
 |  |  |                 List<SysUserDept> distinctUserDepts = new ArrayList<>(); | 
 |  |  |                 Set<String> uniqueDeptCodes = new HashSet<>(); | 
 |  |  |                 for (SysUserDept userDept : sysUserDeptKSs) { | 
 |  |  |                     String deptCode = userDept.getDeptCode(); | 
 |  |  |                     if (StringUtils.isNotEmpty(deptCode) && !uniqueDeptCodes.contains(deptCode)) { | 
 |  |  |                         distinctUserDepts.add(userDept); | 
 |  |  |                         uniqueDeptCodes.add(deptCode); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 List<SysUserDept> distinctUserBQs = new ArrayList<>(); | 
 |  |  |                 Set<String> uniqueBQCodes = new HashSet<>(); | 
 |  |  |                 for (SysUserDept userDept : sysUserDeptBQs) { | 
 |  |  |                     String deptCode = userDept.getDeptCode(); | 
 |  |  |                     if (StringUtils.isNotEmpty(deptCode) && !uniqueBQCodes.contains(deptCode)) { | 
 |  |  |                         distinctUserBQs.add(userDept); | 
 |  |  |                         uniqueBQCodes.add(deptCode); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 sysUserDeptKSs = distinctUserDepts; | 
 |  |  |                 sysUserDeptBQs = distinctUserBQs; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } else if (StringUtils.isNotEmpty(sysUser.getSearchscope()) && sysUser.getSearchscope().equals("1")) { | 
 |  |  |             sysUserDept.setDeptType("1"); | 
 |  |  |             sysUserDeptKSs = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); | 
 |  |  |         } else if (StringUtils.isNotEmpty(sysUser.getSearchscope()) && sysUser.getSearchscope().equals("2")) { | 
 |  |  |             sysUserDept.setDeptType("2"); | 
 |  |  |             sysUserDeptBQs = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         sysUser.setDepts(deptIds); | 
 |  |  |         if (!CollectionUtils.isEmpty(sysUserDeptBQs)) { | 
 |  |  |             List<Map<String, Object>> list = new ArrayList<>(); | 
 |  |  |             for (SysUserDept sud : sysUserDeptBQs) { | 
 |  |  |                 Map<String, Object> map = new HashMap<>(); | 
 |  |  |                 map.put("districtCode", ""); | 
 |  |  |                 if (StringUtils.isNotEmpty(sud.getDeptCode())) map.put("districtCode", sud.getDeptCode()); | 
 |  |  |                 else continue; | 
 |  |  |                 map.put("districtName", ""); | 
 |  |  |                 if (StringUtils.isNotEmpty(sud.getDeptName())) map.put("districtName", sud.getDeptName()); | 
 |  |  |                 list.add(map); | 
 |  |  |             } | 
 |  |  |             sysUser.setBelongWards(list); | 
 |  |  |         } | 
 |  |  |         if (!CollectionUtils.isEmpty(sysUserDeptKSs)) { | 
 |  |  |             List<Map<String, Object>> list = new ArrayList<>(); | 
 |  |  |             for (SysUserDept sud : sysUserDeptKSs) { | 
 |  |  |                 Map<String, Object> map = new HashMap<>(); | 
 |  |  |                 map.put("deptCode", ""); | 
 |  |  |                 if (StringUtils.isNotEmpty(sud.getDeptCode())) map.put("deptCode", sud.getDeptCode()); | 
 |  |  |                 else continue; | 
 |  |  |                 map.put("deptName", ""); | 
 |  |  |                 if (StringUtils.isNotEmpty(sud.getDeptName())) map.put("deptName", sud.getDeptName()); | 
 |  |  |                 list.add(map); | 
 |  |  |             } | 
 |  |  |             sysUser.setBelongDepts(list); | 
 |  |  |         } | 
 |  |  |         return sysUser; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 通过用户ID查询用户 | 
 |  |  | 
 |  |  |         // 新增用户信息 | 
 |  |  |         int rows = userMapper.insertUser(user); | 
 |  |  |         //新增用户与部门关联 | 
 |  |  |         if (!CollectionUtils.isEmpty(user.getDepts())) { | 
 |  |  |             for (Long deptId : user.getDepts()) { | 
 |  |  |                 SysUserDept sysUserDep = new SysUserDept(); | 
 |  |  |                 sysUserDep.setUserId(user.getUserId()); | 
 |  |  |                 sysUserDep.setDeptId(deptId); | 
 |  |  |                 sysUserDep.setCreateTime(new Date()); | 
 |  |  |                 sysUserDep.setUpdateTime(new Date()); | 
 |  |  |                 sysUserDep.setOrgid(user.getOrgid()); | 
 |  |  |                 sysUserDeptMapper.insertSysUserDept(sysUserDep); | 
 |  |  | //        if (!CollectionUtils.isEmpty(user.getDepts())) { | 
 |  |  | //            for (Long deptId : user.getDepts()) { | 
 |  |  | //                SysUserDept sysUserDep = new SysUserDept(); | 
 |  |  | //                sysUserDep.setUserId(user.getUserId()); | 
 |  |  | //                sysUserDep.setDeptId(deptId); | 
 |  |  | //                sysUserDep.setCreateTime(new Date()); | 
 |  |  | //                sysUserDep.setUpdateTime(new Date()); | 
 |  |  | //                sysUserDep.setOrgid(user.getOrgid()); | 
 |  |  | //                sysUserDeptMapper.insertSysUserDept(sysUserDep); | 
 |  |  | //            } | 
 |  |  | //        } | 
 |  |  |         if (!CollectionUtils.isEmpty(user.getDeptCodes())) { | 
 |  |  |             for (String deptCode : user.getDeptCodes()) { | 
 |  |  |                 SysDept sysDept = sysDeptMapper.selectDeptByCode(deptCode); | 
 |  |  |                 if (ObjectUtils.isEmpty(sysDept)) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 SysUserDept sysUserDept = new SysUserDept(); | 
 |  |  |                 sysUserDept.setUserId(user.getUserId()); | 
 |  |  |                 sysUserDept.setOrgid(user.getOrgid()); | 
 |  |  |                 sysUserDept.setDeptCode(deptCode); | 
 |  |  |                 sysUserDept.setDeptId(sysDept.getDeptId()); | 
 |  |  |                 List<SysUserDept> sysUserDepts = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); | 
 |  |  |                 sysUserDept.setDelFlag(0L); | 
 |  |  |                 sysUserDept.setDeptType("1"); | 
 |  |  |                 sysUserDept.setDeptName(sysDept.getDeptName()); | 
 |  |  |                 sysUserDept.setUpdateTime(new Date()); | 
 |  |  |                 if (!CollectionUtils.isEmpty(sysUserDepts)) { | 
 |  |  |                     sysUserDept.setId(sysUserDepts.get(0).getId()); | 
 |  |  |                     sysUserDeptMapper.updateSysUserDept(sysUserDept); | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 sysUserDept.setCreateTime(new Date()); | 
 |  |  |                 sysUserDeptMapper.insertSysUserDept(sysUserDept); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if (!CollectionUtils.isEmpty(user.getWardCodes())) { | 
 |  |  |             for (String wardCode : user.getWardCodes()) { | 
 |  |  |                 SysDept sysDept = sysDeptMapper.selectDeptByCode(wardCode); | 
 |  |  |                 if (ObjectUtils.isEmpty(sysDept)) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 SysUserDept sysUserDept = new SysUserDept(); | 
 |  |  |                 sysUserDept.setUserId(user.getUserId()); | 
 |  |  |                 sysUserDept.setDeptCode(wardCode); | 
 |  |  |                 sysUserDept.setDeptId(sysDept.getDeptId()); | 
 |  |  |                 sysUserDept.setOrgid(user.getOrgid()); | 
 |  |  |                 List<SysUserDept> sysUserDepts = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); | 
 |  |  |                 sysUserDept.setDelFlag(0L); | 
 |  |  |                 sysUserDept.setDeptType("2"); | 
 |  |  |                 sysUserDept.setOrgid(user.getOrgid()); | 
 |  |  |                 sysUserDept.setDeptName(sysDept.getDeptName()); | 
 |  |  |                 sysUserDept.setUpdateTime(new Date()); | 
 |  |  |                 if (!CollectionUtils.isEmpty(sysUserDepts)) { | 
 |  |  |                     sysUserDeptMapper.updateSysUserDept(sysUserDept); | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 sysUserDept.setCreateTime(new Date()); | 
 |  |  |                 sysUserDeptMapper.insertSysUserDept(sysUserDept); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         // 新增用户岗位关联 | 
 |  |  | 
 |  |  |         if (!CollectionUtils.isEmpty(user.getDeptCodes())) { | 
 |  |  |             for (String deptCode : user.getDeptCodes()) { | 
 |  |  |                 SysDept sysDept = sysDeptMapper.selectDeptByCode(deptCode); | 
 |  |  |                 if (ObjectUtils.isEmpty(sysDept)) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 SysUserDept sysUserDept = new SysUserDept(); | 
 |  |  |                 sysUserDept.setUserId(user.getUserId()); | 
 |  |  |                 sysUserDept.setOrgid(user.getOrgid()); | 
 |  |  |                 sysUserDept.setDeptCode(deptCode); | 
 |  |  |                 sysUserDept.setDeptId(sysDept.getDeptId()); | 
 |  |  |                 List<SysUserDept> sysUserDepts = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); | 
 |  |  |                 sysUserDept.setDelFlag(0L); | 
 |  |  |                 sysUserDept.setDeptType("1"); | 
 |  |  | 
 |  |  |         if (!CollectionUtils.isEmpty(user.getWardCodes())) { | 
 |  |  |             for (String wardCode : user.getWardCodes()) { | 
 |  |  |                 SysDept sysDept = sysDeptMapper.selectDeptByCode(wardCode); | 
 |  |  |  | 
 |  |  |                 if (ObjectUtils.isEmpty(sysDept)) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 SysUserDept sysUserDept = new SysUserDept(); | 
 |  |  |                 sysUserDept.setUserId(user.getUserId()); | 
 |  |  |                 sysUserDept.setDeptCode(wardCode); | 
 |  |  |                 sysUserDept.setDeptId(sysDept.getDeptId()); | 
 |  |  |                 sysUserDept.setOrgid(user.getOrgid()); | 
 |  |  |                 List<SysUserDept> sysUserDepts = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); | 
 |  |  |                 sysUserDept.setDelFlag(0L); | 
 |  |  |                 sysUserDept.setDeptType("2"); |