package jnpf.permission.service.impl; import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.github.pagehelper.page.PageMethod; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Lists; import jnpf.base.Pagination; import jnpf.base.UserInfo; import jnpf.base.entity.DictionaryDataEntity; import jnpf.base.entity.SuperBaseEntity; import jnpf.base.service.DictionaryDataService; import jnpf.base.service.SuperServiceImpl; import jnpf.base.service.SysconfigService; import jnpf.base.vo.DownloadVO; import jnpf.config.ConfigValueUtil; import jnpf.constant.*; import jnpf.database.source.DbBase; import jnpf.database.util.DataSourceUtil; import jnpf.database.util.TenantDataSourceUtil; import jnpf.emnus.SysParamEnum; import jnpf.entity.FileParameter; import jnpf.exception.DataException; import jnpf.message.util.OnlineUserModel; import jnpf.message.util.OnlineUserProvider; import jnpf.model.BaseSystemInfo; import jnpf.model.SystemParamModel; import jnpf.model.tenant.TenantVO; import jnpf.permission.entity.*; import jnpf.permission.mapper.UserMapper; import jnpf.permission.model.organize.OrganizeSelectorVO; import jnpf.permission.model.rolerelaiton.RoleRelationPage; import jnpf.permission.model.user.UserIdListVo; import jnpf.permission.model.user.UserRelationIds; import jnpf.permission.model.user.mod.UserConditionModel; import jnpf.permission.model.user.mod.UserImportModel; import jnpf.permission.model.user.page.PageUser; import jnpf.permission.model.user.page.PaginationUser; import jnpf.permission.model.user.page.UserPagination; import jnpf.permission.model.user.vo.*; import jnpf.permission.service.*; import jnpf.util.*; import jnpf.util.context.RequestContext; import lombok.Cleanup; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Workbook; import org.dromara.x.file.storage.core.FileInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import org.springframework.web.multipart.MultipartFile; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; import static jnpf.util.Constants.ADMIN_KEY; /** * 用户信息 * * @author JNPF开发平台组 * @version V3.1.0 * @copyright 引迈信息技术有限公司 * @date 2019年9月26日 上午9:18 */ @Service public class UserServiceImpl extends SuperServiceImpl implements UserService { @Autowired private UserRelationService userRelationService; @Autowired private RedisUtil redisUtil; @Autowired private OrganizeService organizeService; @Autowired private PositionService positionService; @Autowired private RoleService roleService; @Autowired private CacheKeyUtil cacheKeyUtil; @Autowired private DataSourceUtil dataSourceUtil; @Autowired private ConfigValueUtil configValueUtil; @Autowired private DictionaryDataService dictionaryDataService; @Autowired private RoleRelationService roleRelationService; @Autowired private UserMapper userMapper; @Autowired private SysconfigService sysconfigApi; @Autowired private OrganizeAdministratorService organizeAdministratorService; @Autowired private UserOldPasswordService userOldPasswordService; @Autowired private GroupService groupService; @Autowired private PermissionGroupService permissionGroupService; @Autowired private UserService userService; @Autowired private SocialsUserService socialsUserService; @Override public List getList(UserPagination pagination) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().ne(UserEntity::getAccount, ADMIN_KEY); boolean filterLastTime = false; //关键字(账户、姓名、手机) if (!StringUtil.isEmpty(pagination.getKeyword())) { filterLastTime = true; queryWrapper.lambda().and( t -> t.like(UserEntity::getAccount, pagination.getKeyword()) .or().like(UserEntity::getRealName, pagination.getKeyword()) .or().like(UserEntity::getMobilePhone, pagination.getKeyword()) ); } if (pagination.getEnabledMark() != null) { queryWrapper.lambda().eq(UserEntity::getEnabledMark, pagination.getEnabledMark()); } if (StringUtil.isNotEmpty(pagination.getGender())) { queryWrapper.lambda().eq(UserEntity::getGender, pagination.getGender()); } //有分组id过滤 if (StringUtil.isNotEmpty(pagination.getGroupId())) { List listUser = userRelationService.getListByObjectId(pagination.getGroupId(), PermissionConst.GROUP); List users = listUser.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()); if (CollectionUtil.isEmpty(users)) { return pagination.setData(Collections.EMPTY_LIST, 0); } List> lists = Lists.partition(users, 1000); queryWrapper.lambda().and(t -> { for (List userItem : lists) { t.in(UserEntity::getId, userItem).or(); } }); } //有岗位id if (StringUtil.isNotEmpty(pagination.getPositionId())) { List listUser = userRelationService.getListByObjectId(pagination.getPositionId(), PermissionConst.POSITION); List users = listUser.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()); if (CollectionUtil.isEmpty(users)) { return pagination.setData(Collections.EMPTY_LIST, 0); } List> lists = Lists.partition(users, 1000); queryWrapper.lambda().and(t -> { for (List userItem : lists) { t.in(UserEntity::getId, userItem).or(); } }); } else if (StringUtil.isNotEmpty(pagination.getOrganizeId())) { //有组织id List orgIds = new ArrayList<>(); orgIds.add(pagination.getOrganizeId()); if (Objects.equals(pagination.getShowSubOrganize(), 1)) { List allChild = organizeService.getAllChild(pagination.getOrganizeId()); orgIds.addAll(allChild.stream().map(OrganizeEntity::getId).collect(Collectors.toList())); } List listPost = positionService.getListByOrgIds(orgIds); List listPostId = listPost.stream().map(PositionEntity::getId).collect(Collectors.toList()); List listUser = userRelationService.getListByObjectIdAll(listPostId); List users = listUser.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()); if (CollectionUtil.isEmpty(users)) { return pagination.setData(Collections.EMPTY_LIST, 0); } List> lists = Lists.partition(users, 1000); queryWrapper.lambda().and(t -> { for (List userItem : lists) { t.in(UserEntity::getId, userItem).or(); } }); } //有角色id if (StringUtil.isNotEmpty(pagination.getRoleId())) { List listUser = roleRelationService.getListByRoleId(pagination.getRoleId(), PermissionConst.USER); List users = listUser.stream().map(RoleRelationEntity::getObjectId).collect(Collectors.toList()); if (CollectionUtil.isEmpty(users)) { return pagination.setData(Collections.EMPTY_LIST, 0); } List> lists = Lists.partition(users, 1000); queryWrapper.lambda().and(t -> { for (List userItem : lists) { t.in(UserEntity::getId, userItem).or(); } }); } long count = this.count(queryWrapper); queryWrapper.lambda().select(UserEntity::getId); queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); if (filterLastTime) { queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime); } if (Objects.equals(pagination.getDataType(), 1)) { return this.list(queryWrapper); } Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize(), count, false); page.setOptimizeCountSql(false); IPage iPage = this.page(page, queryWrapper); if (!iPage.getRecords().isEmpty()) { List ids = iPage.getRecords().stream().map(m -> m.getId()).collect(Collectors.toList()); queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(UserEntity::getId, ids); queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); if (filterLastTime) { queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime); } iPage.setRecords(this.list(queryWrapper)); } return pagination.setData(iPage.getRecords(), iPage.getTotal()); } @Override public List getList(boolean filterEnabledMark) { QueryWrapper queryWrapper = new QueryWrapper<>(); if (filterEnabledMark) { queryWrapper.lambda().eq(UserEntity::getEnabledMark, 1); } queryWrapper.lambda().ne(UserEntity::getAccount, ADMIN_KEY); queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); return this.list(queryWrapper); } @Override public List getUserNameList(List idList) { if (idList.size() > 0) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getEnabledMark).in(UserEntity::getId, idList); return this.list(queryWrapper); } return new ArrayList<>(); } @Override public List getUserNameList(Set idList) { if (idList.size() > 0) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount).in(UserEntity::getId, idList); return this.list(queryWrapper); } return new ArrayList<>(); } @Override public Map getUserMap() { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount); Map userMap = new HashMap<>(); this.list(queryWrapper).stream().forEach(user -> userMap.put(user.getId(), user.getRealName() + "/" + user.getAccount())); return userMap; } @Override public Map getUserNameAndIdMap() { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount); Map userMap = new HashMap<>(); this.list(queryWrapper).stream().forEach(user -> userMap.put(user.getRealName() + "/" + user.getAccount(), user.getId())); return userMap; } @Override public Map getUserNameAndIdMap(boolean enabledMark) { QueryWrapper queryWrapper = new QueryWrapper<>(); if (enabledMark) { queryWrapper.lambda().eq(UserEntity::getEnabledMark, 1); } queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount); Map userMap = new HashMap<>(); this.list(queryWrapper).stream().forEach(user -> userMap.put(user.getRealName() + "/" + user.getAccount(), user.getId())); return userMap; } @Override public UserEntity getByRealName(String realName) { UserEntity userEntity = new UserEntity(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(UserEntity::getRealName, realName); queryWrapper.lambda().select(UserEntity::getId); List list = this.list(queryWrapper); if (list.size() > 0) { userEntity = list.get(0); } return userEntity; } @Override public UserEntity getByRealName(String realName, String account) { UserEntity userEntity = new UserEntity(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(UserEntity::getRealName, realName); queryWrapper.lambda().eq(UserEntity::getAccount, account); queryWrapper.lambda().select(UserEntity::getId); List list = this.list(queryWrapper); if (list.size() > 0) { userEntity = list.get(0); } return userEntity; } @Override public List getAdminList() { QueryWrapper query = new QueryWrapper<>(); query.lambda().eq(UserEntity::getIsAdministrator, 1); query.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); return list(query); } @Override public List getList(PaginationUser pagination, String organizeId, Boolean flag, Boolean filter, Integer enabledMark, String gender) { // 定义变量判断是否需要使用修改时间倒序 boolean filterLastTime = false; String userId = UserProvider.getUser().getUserId(); QueryWrapper queryWrapper = new QueryWrapper<>(); if (flag) { queryWrapper.lambda().ne(UserEntity::getId, userId); } if (filter) { queryWrapper.lambda().ne(UserEntity::getAccount, ADMIN_KEY); } //组织机构 if (!StringUtil.isEmpty(organizeId)) { List orgIdList = organizeService.getUnderOrganizationss(organizeId); orgIdList.add(organizeId); PageHelper.startPage((int) pagination.getCurrentPage(), (int) pagination.getPageSize(), false); //组织数量很多时解析SQL很慢, COUNT不解析SQL不去除ORDERBY PageMethod.getLocalPage().keepOrderBy(true); // 用户id List query = new ArrayList<>(16); String dbSchema = null; // 判断是否为多租户 if (configValueUtil.isMultiTenancy() && DbBase.DM.equalsIgnoreCase(dataSourceUtil.getDbType())) { dbSchema = dataSourceUtil.getDbSchema(); } String keyword = null; if (StringUtil.isNotEmpty(pagination.getKeyword())) { keyword = "%" + pagination.getKeyword() + "%" ; } query = userMapper.query(orgIdList, keyword, dbSchema, enabledMark, gender); Long count = this.baseMapper.count(orgIdList, keyword, dbSchema, enabledMark, gender); PageInfo pageInfo = new PageInfo(query); // 赋值分页参数 pagination.setTotal(count); pagination.setCurrentPage(pageInfo.getPageNum()); pagination.setPageSize(pageInfo.getPageSize()); if (pageInfo.getList().size() > 0) { // 存放返回结果 QueryWrapper queryWrapper1 = new QueryWrapper<>(); List> lists = Lists.partition(query, 1000); queryWrapper1.lambda().and(t -> { for (List id : lists) { t.or().in(UserEntity::getId, id); } }); queryWrapper1.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); List entityList = getBaseMapper().selectList(queryWrapper1); return entityList; } else { return new ArrayList<>(); } } if (!UserProvider.getUser().getIsAdministrator()) { // 通过权限转树 List listss = organizeAdministratorService.getOrganizeAdministratorEntity(UserProvider.getUser().getUserId()); Set orgIds = new HashSet<>(16); // 判断自己是哪些组织的管理员 listss.stream().forEach(t -> { if (t != null) { if (t.getThisLayerSelect() != null && t.getThisLayerSelect() == 1) { orgIds.add(t.getOrganizeId()); } if (t.getSubLayerSelect() != null && t.getSubLayerSelect() == 1) { List underOrganizations = organizeService.getUnderOrganizations(t.getOrganizeId(), false); orgIds.addAll(underOrganizations); } } }); List list1 = new ArrayList<>(orgIds); // 得到所有有权限的组织 List organizeName = new ArrayList<>(organizeService.getOrganizeName(list1, null, false, null).values()); // 用户关系表得到所有的人 List collect = organizeName.stream().map(OrganizeEntity::getId).collect(Collectors.toList()); List listByObjectIdAll = userRelationService.getListByOrgId(collect); List collect1 = listByObjectIdAll.stream().map(UserRelationEntity::getUserId).distinct().collect(Collectors.toList()); return getUserNames(collect1, pagination, false, ObjectUtil.equal(enabledMark, 1)); } //关键字(账户、姓名、手机) if (!StringUtil.isEmpty(pagination.getKeyword())) { filterLastTime = true; queryWrapper.lambda().and( t -> t.like(UserEntity::getAccount, pagination.getKeyword()) .or().like(UserEntity::getRealName, pagination.getKeyword()) .or().like(UserEntity::getMobilePhone, pagination.getKeyword()) ); } if (enabledMark != null) { queryWrapper.lambda().eq(UserEntity::getEnabledMark, enabledMark); } if (StringUtil.isNotEmpty(gender)) { queryWrapper.lambda().eq(UserEntity::getGender, gender); } //不分页 if (Objects.equals(pagination.getDataType(), 1)) { queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); if (filterLastTime) { queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime); } return this.list(queryWrapper); } //分页 //排序 long count = this.count(queryWrapper); queryWrapper.lambda().select(UserEntity::getId); queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); if (filterLastTime) { queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime); } Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize(), count, false); page.setOptimizeCountSql(false); IPage iPage = this.page(page, queryWrapper); if (!iPage.getRecords().isEmpty()) { List ids = iPage.getRecords().stream().map(m -> m.getId()).collect(Collectors.toList()); queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(UserEntity::getId, ids); queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); if (filterLastTime) { queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime); } iPage.setRecords(this.list(queryWrapper)); } return pagination.setData(iPage.getRecords(), iPage.getTotal()); } @Override public List getList(PageUser pagination, Boolean filterCurrentUser) { // 定义变量判断是否需要使用修改时间倒序 boolean filterLastTime = false; QueryWrapper queryWrapper = new QueryWrapper<>(); if (filterCurrentUser) { String userId = UserProvider.getUser().getUserId(); queryWrapper.lambda().ne(UserEntity::getId, userId); } queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0); //关键字(账户、姓名、手机) if (!StringUtil.isEmpty(pagination.getKeyword())) { filterLastTime = true; queryWrapper.lambda().and( t -> t.like(UserEntity::getAccount, pagination.getKeyword()) .or().like(UserEntity::getRealName, pagination.getKeyword()) .or().like(UserEntity::getMobilePhone, pagination.getKeyword()) ); } if (CollectionUtil.isNotEmpty(pagination.getIdList())) { List> partition = Lists.partition(pagination.getIdList(), 1000); queryWrapper.lambda().and(t -> { for (List list : partition) { t.in(UserEntity::getId, list).or(); } }); } //排序 queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); if (filterLastTime) { queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime); } Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize()); IPage iPage = this.page(page, queryWrapper); return pagination.setData(iPage.getRecords(), iPage.getTotal()); } @Override public List getUserPage(Pagination pagination) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0); if (StringUtil.isNotEmpty(pagination.getKeyword())) { //通过关键字查询 queryWrapper.lambda().and( t -> t.like(UserEntity::getAccount, pagination.getKeyword()) .or().like(UserEntity::getRealName, pagination.getKeyword()) .or().like(UserEntity::getMobilePhone, pagination.getKeyword()) ); } queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0); queryWrapper.lambda().select(UserEntity::getId, UserEntity::getAccount, UserEntity::getRealName, UserEntity::getGender, UserEntity::getEnabledMark); Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize()); IPage iPage = this.page(page, queryWrapper); return iPage.getRecords(); } @Override public List getListByOrganizeId(String organizeId, String keyword) { List userIds = userRelationService.getListByObjectId(organizeId, PermissionConst.ORGANIZE).stream() .map(UserRelationEntity::getUserId).collect(Collectors.toList()); if (userIds.size() > 0) { QueryWrapper query = new QueryWrapper<>(); if (userIds.size() > 0) { query.lambda().in(UserEntity::getId, userIds); } // 通过关键字查询 if (StringUtil.isNotEmpty(keyword)) { query.lambda().and( t -> t.like(UserEntity::getAccount, keyword) .or().like(UserEntity::getRealName, keyword) ); } // 只查询正常的用户 query.lambda().ne(UserEntity::getEnabledMark, 0); query.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); return this.list(query); } return new ArrayList<>(0); } @Override public List getListByManagerId(String managerId, String keyword) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(UserEntity::getManagerId, managerId); // 通过关键字查询 if (StringUtil.isNotEmpty(keyword)) { queryWrapper.lambda().and( t -> t.like(UserEntity::getAccount, keyword) .or().like(UserEntity::getRealName, keyword) ); } // 只查询正常的用户 queryWrapper.lambda().eq(UserEntity::getEnabledMark, 1); queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); return this.list(queryWrapper); } @Override public UserEntity getInfo(String id) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(UserEntity::getId, String.valueOf(id)); return this.getOne(queryWrapper); } @Override public UserEntity getUserByAccount(String account) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(UserEntity::getAccount, account); return this.getOne(queryWrapper); } @Override public UserEntity getUserByMobile(String mobile) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(UserEntity::getMobilePhone, mobile); List list = this.list(queryWrapper); return CollectionUtil.isNotEmpty(list) ? list.get(0) : null; } @Override public Boolean setAdminListByIds(List adminIds) { // 将所有的管理员取消 QueryWrapper query = new QueryWrapper<>(); query.lambda().eq(UserEntity::getIsAdministrator, 1); // admin不允许移除管理员 query.lambda().ne(UserEntity::getAccount, ADMIN_KEY); List list1 = this.list(query); for (UserEntity entity : list1) { entity.setIsAdministrator(0); this.updateById(entity); } // 重新赋值管理员 List list = new ArrayList<>(); adminIds.stream().forEach(adminId -> { UserEntity userEntity = new UserEntity(); userEntity.setId(adminId); userEntity.setIsAdministrator(1); // admin无需添加 if (!ADMIN_KEY.equals(userEntity.getAccount())) { list.add(userEntity); } }); List adminList = list1.stream().map(UserEntity::getId).collect(Collectors.toList()); adminList.removeAll(list.stream().map(UserEntity::getId).collect(Collectors.toList())); delCurUser(MsgCode.PS010.get(), adminList); updateStand(adminList, 1); return this.updateBatchById(list); } @Override public boolean isExistByAccount(String account) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(UserEntity::getAccount, account); List list = this.list(queryWrapper); if (CollectionUtil.isNotEmpty(list)) { return true; } return false; } @Override @DSTransactional public Boolean create(UserEntity entity) throws Exception { beforeCheck(); if (StringUtil.isNotEmpty(entity.getGroupId()) && entity.getGroupId().contains(",")) { entity.setGroupId(null); } //添加用户 初始化 String userId = RandomUtil.uuId(); if (StringUtil.isNotEmpty(entity.getId())) { userId = entity.getId(); } BaseSystemInfo sysInfo = sysconfigApi.getSysInfo(); entity.setPassword(Md5Util.getStringMd5(sysInfo.getNewUserDefaultPassword())); entity.setId(userId); if (StringUtil.isEmpty(entity.getAccount())) { throw new DataException(MsgCode.PS007.get()); } if (StringUtil.isEmpty(entity.getRealName())) { throw new DataException(MsgCode.PS008.get()); } //获取头像 String oldHeadIcon = entity.getHeadIcon(); if (StringUtil.isEmpty(oldHeadIcon)) { entity.setHeadIcon("001.png"); } else { //获取头像 String[] headIcon = oldHeadIcon.split("/"); if (headIcon.length > 0) { entity.setHeadIcon(headIcon[headIcon.length - 1]); } } entity.setSecretkey(RandomUtil.uuId()); entity.setPassword(Md5Util.getStringMd5(entity.getPassword().toLowerCase() + entity.getSecretkey().toLowerCase())); entity.setIsAdministrator(0); entity.setCreatorUserId(UserProvider.getUser().getUserId()); String groupId = entity.getGroupId(); if (StringUtil.isNotEmpty(groupId)) { UserRelationEntity groupRelation = new UserRelationEntity(); groupRelation.setId(RandomUtil.uuId()); groupRelation.setObjectType(PermissionConst.GROUP); groupRelation.setObjectId(groupId); groupRelation.setUserId(entity.getId()); groupRelation.setCreatorTime(entity.getCreatorTime()); groupRelation.setCreatorUserId(entity.getCreatorUserId()); userRelationService.save(groupRelation); } //添加岗位关系 if (StringUtil.isNotEmpty(entity.getPositionId())) { String[] split = entity.getPositionId().split(","); for (String s : split) { UserRelationEntity posRelation = new UserRelationEntity(); posRelation.setId(RandomUtil.uuId()); posRelation.setObjectType(PermissionConst.POSITION); posRelation.setObjectId(s); posRelation.setUserId(entity.getId()); posRelation.setCreatorTime(entity.getCreatorTime()); posRelation.setCreatorUserId(entity.getCreatorUserId()); userRelationService.save(posRelation); } } //添加组织关系 if (StringUtil.isNotEmpty(entity.getOrganizeId())) { String[] split = entity.getOrganizeId().split(","); for (String s : split) { UserRelationEntity posRelation = new UserRelationEntity(); posRelation.setId(RandomUtil.uuId()); posRelation.setObjectType(PermissionConst.ORGANIZE); posRelation.setObjectId(s); posRelation.setUserId(entity.getId()); posRelation.setCreatorTime(entity.getCreatorTime()); posRelation.setCreatorUserId(entity.getCreatorUserId()); userRelationService.save(posRelation); } } //添加角色关系 if (StringUtil.isNotEmpty(entity.getRoleId())) { String[] split = entity.getRoleId().split(","); for (String s : split) { RoleRelationEntity posRelation = new RoleRelationEntity(); posRelation.setId(RandomUtil.uuId()); posRelation.setObjectType(PermissionConst.USER); posRelation.setObjectId(entity.getId()); posRelation.setRoleId(s); posRelation.setCreatorTime(entity.getCreatorTime()); posRelation.setCreatorUserId(entity.getCreatorUserId()); roleRelationService.save(posRelation); } } else { //创建没有角色的时候,默认使用者 RoleEntity byEnCode = roleService.getByEnCode(PermissionConst.USER_CODE); RoleRelationEntity posRelation = new RoleRelationEntity(); posRelation.setId(RandomUtil.uuId()); posRelation.setObjectType(PermissionConst.USER); posRelation.setObjectId(entity.getId()); posRelation.setRoleId(byEnCode.getId()); posRelation.setCreatorTime(entity.getCreatorTime()); posRelation.setCreatorUserId(entity.getCreatorUserId()); roleRelationService.save(posRelation); } //写入时清空 entity.setGroupId(""); entity.setPositionId(""); entity.setOrganizeId(""); entity.setRoleId(""); entity.setQuickQuery(PinYinUtil.getFirstSpell(entity.getRealName())); //清理获取所有用户的redis缓存 redisUtil.remove(cacheKeyUtil.getAllUser()); this.save(entity); return true; } /** * 验证是否还有额度 */ @Override public void beforeCheck() { String tenantId = UserProvider.getUser().getTenantId(); // 开启多租住的 if (StringUtil.isNotEmpty(tenantId)) { TenantVO cacheTenantInfo = TenantDataSourceUtil.getCacheTenantInfo(tenantId); long count = this.count(); if (cacheTenantInfo.getAccountNum() != 0 && cacheTenantInfo.getAccountNum() < count) { throw new DataException(MsgCode.PS009.get()); } } } @Override @DSTransactional public Boolean update(String userId, UserEntity entity) throws Exception { //更新用户 entity.setId(userId); if (StringUtil.isEmpty(entity.getAccount())) { throw new DataException(MsgCode.PS007.get()); } if (StringUtil.isEmpty(entity.getRealName())) { throw new DataException(MsgCode.PS008.get()); } //获取头像 String oldHeadIcon = entity.getHeadIcon(); if (StringUtil.isEmpty(oldHeadIcon)) { entity.setHeadIcon("001.png"); } entity.setLastModifyTime(DateUtil.getNowDate()); entity.setLastModifyUserId(UserProvider.getUser().getUserId()); //获取头像 String[] headIcon = entity.getHeadIcon().split("/"); if (headIcon.length > 0) { entity.setHeadIcon(headIcon[headIcon.length - 1]); } entity.setQuickQuery(PinYinUtil.getFirstSpell(entity.getRealName())); //清理获取所有用户的redis缓存 redisUtil.remove(cacheKeyUtil.getAllUser()); if (StringUtil.isNotEmpty(entity.getGroupId()) && entity.getGroupId().contains(",")) { entity.setGroupId(null); } this.updateById(entity); return true; } @Override @DSTransactional public void delete(UserEntity entity) { this.removeById(entity.getId()); //删除用户关联 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(UserRelationEntity::getUserId, entity.getId()); userRelationService.remove(queryWrapper); //删除用户关联角色 QueryWrapper roleRelationQuery = new QueryWrapper<>(); roleRelationQuery.lambda().eq(RoleRelationEntity::getObjectId, entity.getId()); roleRelationService.remove(roleRelationQuery); //删除用户绑定关系 QueryWrapper socialsUserEntityQueryWrapper = new QueryWrapper<>(); socialsUserEntityQueryWrapper.lambda().eq(SocialsUserEntity::getUserId, entity.getId()); socialsUserService.remove(socialsUserEntityQueryWrapper); } @Override @DSTransactional public void batchDelete(List userIdList) { if (userIdList == null || userIdList.isEmpty()) { return; } this.removeBatchByIds(userIdList); //删除用户关联 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(UserRelationEntity::getUserId, userIdList); userRelationService.remove(queryWrapper); //删除用户关联角色 QueryWrapper roleRelationQuery = new QueryWrapper<>(); roleRelationQuery.lambda().in(RoleRelationEntity::getObjectId, userIdList); roleRelationService.remove(roleRelationQuery); } @Override public void updatePassword(UserEntity entity) { entity.setSecretkey(RandomUtil.uuId()); entity.setPassword(Md5Util.getStringMd5(entity.getPassword().toLowerCase() + entity.getSecretkey().toLowerCase())); entity.setChangePasswordDate(DateUtil.getNowDate()); this.updateById(entity); //加入到旧密码记录表 UserOldPasswordEntity userOldPasswordEntity = new UserOldPasswordEntity(); userOldPasswordEntity.setOldPassword(entity.getPassword()); userOldPasswordEntity.setSecretkey(entity.getSecretkey()); userOldPasswordEntity.setUserId(entity.getId()); userOldPasswordEntity.setAccount(entity.getAccount()); userOldPasswordService.create(userOldPasswordEntity); } @Override public List getUserName(List id) { return getUserName(id, false); } /** * 查询用户名称 * * @param id 主键值 * @return */ @Override public List getUserName(List id, boolean filterEnabledMark) { List list = new ArrayList<>(); // 达梦数据库无法null值入参 id.removeAll(Collections.singleton(null)); if (id.size() > 0) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(UserEntity::getId, id); if (filterEnabledMark) { queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0); } list = this.list(queryWrapper); } return list; } @Override public List getListByUserIds(List id) { List list = new ArrayList<>(); // 达梦数据库无法null值入参 id.removeAll(Collections.singleton(null)); if (id.size() > 0) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(UserEntity::getId, id); list = this.list(queryWrapper); } return list; } @Override public List getUserList(List id) { List list = new ArrayList<>(); // 达梦数据库无法null值入参 id.removeAll(Collections.singleton(null)); if (id.size() > 0) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(UserEntity::getId, id); queryWrapper.lambda().eq(UserEntity::getEnabledMark, 1); list = this.list(queryWrapper); } return list; } @Override public UserEntity getUserEntity(String account) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(UserEntity::getAccount, account); return this.baseMapper.selectOne(queryWrapper); } @Override public List getListId() { return this.baseMapper.getListId(); } @Override public void update(UserEntity entity, String type) { UpdateWrapper wrapper = new UpdateWrapper<>(); if ("Position".equals(type)) { wrapper.lambda().set(UserEntity::getPositionId, entity.getPositionId()); } else { wrapper.lambda().set(UserEntity::getRoleId, entity.getRoleId()); } wrapper.lambda().eq(UserEntity::getId, entity.getId()); this.update(wrapper); } @Override public void updateLastTime(UserEntity entity, String type) { UpdateWrapper wrapper = new UpdateWrapper<>(); if ("Position".equals(type)) { wrapper.lambda().set(UserEntity::getPositionId, entity.getPositionId()); } else { wrapper.lambda().set(UserEntity::getRoleId, entity.getRoleId()); } wrapper.lambda().set(UserEntity::getLastModifyTime, new Date()); wrapper.lambda().set(UserEntity::getLastModifyUserId, entity.getLastModifyUserId()); wrapper.lambda().eq(UserEntity::getId, entity.getId()); this.update(wrapper); } @Override public boolean isSubordinate(String id, String managerId) { int num = 0; return recursionSubordinates(id, managerId, num); } @Override public DownloadVO exportExcel(String dataType, String selectKey, PaginationUser pagination) { List entityList = new ArrayList<>(); if ("0".equals(dataType)) { entityList = getList(pagination, pagination.getOrganizeId(), false, true, null, null); } else if ("1".equals(dataType)) { entityList = getList(false); } List modeList = new ArrayList<>(); Map orgMaps = null; // 长度超过300代表是全部数据 if (entityList.size() > 300) { orgMaps = organizeService.getOrgMaps(null, true, null); } // 得到民族集合 List dataServiceList = dictionaryDataService.getListByTypeDataCode("Nation"); Map dataServiceMap = dataServiceList.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName)); // 得到证件类型 List dataServiceList1 = dictionaryDataService.getListByTypeDataCode("certificateType"); Map dataServiceMap1 = dataServiceList1.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName)); // 得到文化程度 List dataServiceList2 = dictionaryDataService.getListByTypeDataCode("Education"); Map dataServiceMap2 = dataServiceList2.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName)); // 得到职级 List dataServiceList3 = dictionaryDataService.getListByTypeDataCode("Rank"); Map dataServiceMap3 = dataServiceList3.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName)); // 得到性别 List dataServiceList4 = dictionaryDataService.getListByTypeDataCode("sex"); Map dataServiceMap4 = dataServiceList4.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName)); for (UserEntity entity : entityList) { UserExportVO model = new UserExportVO(); model.setAccount(entity.getAccount()); model.setRealName(entity.getRealName()); // 组织 // 定义多组织集合 StringJoiner stringJoiner = new StringJoiner(";"); // 获取该用户的所有组织关系 List allOrgRelationByUserId = userRelationService.getAllOrgRelationByUserId(entity.getId()); Map orgIdNameMaps = organizeService.getInfoList(); for (UserRelationEntity userRelationEntity : allOrgRelationByUserId) { String id = userRelationEntity.getObjectId(); OrganizeEntity organize = null; // 得到该组织信息 if (orgMaps != null) { organize = orgMaps.get(id); } else { organize = organizeService.getInfo(id); } // 得到父级id树 if (organize != null && ObjectUtil.equal(organize.getEnabledMark(), 1) && StringUtil.isNotEmpty(organize.getOrganizeIdTree())) { stringJoiner.add(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organize.getOrganizeIdTree(), "/")); } } model.setOrganizeId(stringJoiner.toString()); // 主管 UserEntity info = getInfo(entity.getManagerId()); if (Objects.nonNull(info) && StringUtil.isNotEmpty(info.getRealName()) && StringUtil.isNotEmpty(info.getAccount())) { model.setManagerId(info.getRealName() + "/" + info.getAccount()); } // 岗位 List listByObjectType = userRelationService.getListByObjectType(entity.getId(), PermissionConst.POSITION); StringBuffer positionName = new StringBuffer(); for (UserRelationEntity userRelationEntity : listByObjectType) { if (StringUtil.isNotEmpty(userRelationEntity.getObjectId())) { PositionEntity positionEntity = positionService.getInfo(userRelationEntity.getObjectId()); if (Objects.nonNull(positionEntity) && ObjectUtil.equal(positionEntity.getEnabledMark(), 1)) { positionName.append("," + positionEntity.getFullName() + "/" + positionEntity.getEnCode()); } } } // 判断岗位是否需要导出 if (positionName.length() > 0) { model.setPositionId(positionName.toString().replaceFirst(",", "")); } // 角色 List listByObjectType1 = userRelationService.getListByObjectType(entity.getId(), PermissionConst.ROLE); StringBuffer roleName = new StringBuffer(); for (UserRelationEntity userRelationEntity : listByObjectType1) { if (StringUtil.isNotEmpty(userRelationEntity.getObjectId())) { RoleEntity roleEntity = roleService.getInfo(userRelationEntity.getObjectId()); if (Objects.nonNull(roleEntity) && ObjectUtil.equal(roleEntity.getEnabledMark(), 1)) { roleName.append("," + roleEntity.getFullName()); } } } if (roleName.length() > 0) { model.setRoleId(roleName.toString().replaceFirst(",", "")); } model.setDescription(entity.getDescription()); // 性别 if (dataServiceMap4.containsKey(entity.getGender())) { model.setGender(dataServiceMap4.get(entity.getGender())); } // 民族 if (dataServiceMap.containsKey(entity.getNation())) { model.setNation(dataServiceMap.get(entity.getNation())); } model.setNativePlace(entity.getNativePlace()); // 证件类型 if (dataServiceMap1.containsKey(entity.getCertificatesType())) { model.setCertificatesType(dataServiceMap1.get(entity.getCertificatesType())); } model.setCertificatesNumber(entity.getCertificatesNumber()); // 文化程度 if (dataServiceMap2.containsKey(entity.getEducation())) { model.setEducation(dataServiceMap2.get(entity.getEducation())); } // 生日 SimpleDateFormat sf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (entity.getBirthday() != null) { String birthday = sf1.format(entity.getBirthday()); model.setBirthday(birthday); } model.setTelePhone(entity.getTelePhone()); model.setLandline(entity.getLandline()); model.setMobilePhone(entity.getMobilePhone()); model.setEmail(entity.getEmail()); model.setUrgentContacts(entity.getUrgentContacts()); model.setUrgentTelePhone(entity.getUrgentTelePhone()); model.setPostalAddress(entity.getPostalAddress()); model.setSortCode(entity.getSortCode() == null ? 0 : entity.getSortCode()); // 设置状态 if (entity.getEnabledMark() == null) { model.setEnabledMark("禁用"); } else { if (entity.getEnabledMark() == 2) { model.setEnabledMark("锁定"); } else if (entity.getEnabledMark() == 1) { model.setEnabledMark("正常"); } else { model.setEnabledMark("禁用"); } } // 入职时间 if (entity.getEntryDate() != null) { String entryDate = sf1.format(entity.getEntryDate()); model.setEntryDate(entryDate); } // 职级 if (dataServiceMap3.containsKey(entity.getRanks())) { model.setRanks(dataServiceMap3.get(entity.getRanks())); } modeList.add(model); } return exportUtil(selectKey, "用户信息", modeList, 0); } private DownloadVO exportUtil(String selectKey, String explain, List modeList, int type) { List list = JsonUtil.listToJsonField(JsonUtil.getJsonToList(modeList, UserExportVO.class)); if (type == 1) { list = JsonUtil.listToJsonField(JsonUtil.getJsonToList(modeList, UserExportExceptionVO.class)); } List entitys = new ArrayList<>(); String[] splitData = selectKey.split(","); if (splitData.length > 0) { for (int i = 0; i < splitData.length; i++) { if (splitData[i].equals("account")) { entitys.add(new ExcelExportEntity("账号", "account")); } if (splitData[i].equals("realName")) { entitys.add(new ExcelExportEntity("姓名", "realName")); } if (splitData[i].equals("gender")) { entitys.add(new ExcelExportEntity("性别", "gender")); } if (splitData[i].equals("email")) { entitys.add(new ExcelExportEntity("电子邮箱", "email")); } if (splitData[i].equals("organizeId")) { entitys.add(new ExcelExportEntity("所属组织", "organizeId")); } if (splitData[i].equals("managerId")) { entitys.add(new ExcelExportEntity("直属主管", "managerId")); } if (splitData[i].equals("positionId")) { entitys.add(new ExcelExportEntity("岗位", "positionId")); } if (splitData[i].equals("ranks")) { entitys.add(new ExcelExportEntity("职级", "ranks")); } if (splitData[i].equals("roleId")) { entitys.add(new ExcelExportEntity("角色", "roleId")); } if (splitData[i].equals("sortCode")) { entitys.add(new ExcelExportEntity("排序", "sortCode")); } if (splitData[i].equals("enabledMark")) { entitys.add(new ExcelExportEntity("状态", "enabledMark")); } if (splitData[i].equals("description")) { entitys.add(new ExcelExportEntity("说明", "description", 25)); } if (splitData[i].equals("nation")) { entitys.add(new ExcelExportEntity("民族", "nation")); } if (splitData[i].equals("nativePlace")) { entitys.add(new ExcelExportEntity("籍贯", "nativePlace")); } if (splitData[i].equals("entryDate")) { entitys.add(new ExcelExportEntity("入职时间", "entryDate")); } if (splitData[i].equals("certificatesType")) { entitys.add(new ExcelExportEntity("证件类型", "certificatesType")); } if (splitData[i].equals("certificatesNumber")) { entitys.add(new ExcelExportEntity("证件号码", "certificatesNumber")); } if (splitData[i].equals("education")) { entitys.add(new ExcelExportEntity("文化程度", "education")); } if (splitData[i].equals("birthday")) { entitys.add(new ExcelExportEntity("出生年月", "birthday")); } if (splitData[i].equals("telePhone")) { entitys.add(new ExcelExportEntity("办公电话", "telePhone")); } if (splitData[i].equals("landline")) { entitys.add(new ExcelExportEntity("办公座机", "landline")); } if (splitData[i].equals("mobilePhone")) { entitys.add(new ExcelExportEntity("手机号码", "mobilePhone")); } if (splitData[i].equals("urgentContacts")) { entitys.add(new ExcelExportEntity("紧急联系", "urgentContacts")); } if (splitData[i].equals("urgentTelePhone")) { entitys.add(new ExcelExportEntity("紧急电话", "urgentTelePhone")); } if (splitData[i].equals("postalAddress")) { entitys.add(new ExcelExportEntity("通讯地址", "postalAddress", 25)); } if (splitData[i].equals("errorsInfo")) { entitys.add(new ExcelExportEntity("异常原因", "errorsInfo", 50)); } } } ExportParams exportParams = new ExportParams(null, "用户信息"); exportParams.setType(ExcelType.XSSF); DownloadVO vo = DownloadVO.builder().build(); try { @Cleanup Workbook workbook = new HSSFWorkbook(); if (entitys.size() > 0) { workbook = ExcelExportUtil.exportExcel(exportParams, entitys, list); } String name = explain + DateUtil.dateFormatByPattern(new Date(), "yyyyMMddHHmmss") + ".xlsx" ; MultipartFile multipartFile = ExcelUtil.workbookToCommonsMultipartFile(workbook, name); FileInfo fileInfo = FileUploadUtils.uploadFile(new FileParameter(FileTypeConstant.TEMPORARY, name), multipartFile); vo.setName(fileInfo.getFilename()); vo.setUrl(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + "Temporary") + "&name=" + name); } catch (Exception e) { log.error("用户信息导出Excel错误:" + e.getMessage()); } return vo; } @Override public Map importPreview(List personList) { List> dataRow = new ArrayList<>(); List> columns = new ArrayList<>(); for (int i = 0; i < personList.size(); i++) { Map dataRowMap = new HashMap<>(); UserExportVO model = personList.get(i); dataRowMap.put("account", model.getAccount()); dataRowMap.put("realName", model.getRealName()); dataRowMap.put("organizeId", model.getOrganizeId()); dataRowMap.put("managerId", model.getManagerId()); dataRowMap.put("positionId", model.getPositionId()); dataRowMap.put("roleId", model.getRoleId()); dataRowMap.put("description", model.getDescription()); dataRowMap.put("gender", model.getGender()); dataRowMap.put("nation", model.getNation()); dataRowMap.put("nativePlace", model.getNativePlace()); dataRowMap.put("certificatesType", model.getCertificatesType()); dataRowMap.put("certificatesNumber", model.getCertificatesNumber()); dataRowMap.put("education", model.getEducation()); dataRowMap.put("birthday", model.getBirthday()); dataRowMap.put("telePhone", model.getTelePhone()); dataRowMap.put("landline", model.getLandline()); dataRowMap.put("mobilePhone", model.getMobilePhone()); dataRowMap.put("email", model.getEmail()); dataRowMap.put("urgentContacts", model.getUrgentContacts()); dataRowMap.put("urgentTelePhone", model.getUrgentTelePhone()); dataRowMap.put("postalAddress", model.getPostalAddress()); dataRowMap.put("sortCode", model.getSortCode()); dataRowMap.put("enabledMark", model.getEnabledMark()); dataRowMap.put("entryDate", model.getEntryDate()); dataRowMap.put("ranks", model.getRanks()); dataRow.add(dataRowMap); } for (int i = 1; i <= personList.size(); i++) { Map columnsMap = new HashMap<>(); columnsMap.put("AllowDBNull", true); columnsMap.put("AutoIncrement", false); columnsMap.put("AutoIncrementSeed", 0); columnsMap.put("AutoIncrementStep", 1); columnsMap.put("Caption", this.getColumns(i)); columnsMap.put("ColumnMapping", 1); columnsMap.put("ColumnName", this.getColumns(i)); columnsMap.put("Container", null); columnsMap.put("DataType", "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); columnsMap.put("DateTimeMode", 3); columnsMap.put("DefaultValue", null); columnsMap.put("DesignMode", false); columnsMap.put("Expression", ""); columnsMap.put("ExtendedProperties", ""); columnsMap.put("MaxLength", -1); columnsMap.put("Namespace", ""); columnsMap.put("Ordinal", 0); columnsMap.put("Prefix", ""); columnsMap.put("ReadOnly", false); columnsMap.put("Site", null); columnsMap.put("Table", personList); columnsMap.put("Unique", false); columns.add(columnsMap); } Map map = new HashMap<>(); map.put("dataRow", dataRow); map.put("columns", columns); return map; } @Override public UserImportVO importData(List dataList) { // List importModels = new ArrayList<>(16); List exceptionList = new ArrayList<>(16); // 得到民族集合 List dataServiceList = dictionaryDataService.getListByTypeDataCode("Nation"); BiMap dataServiceMap = HashBiMap.create(dataServiceList.stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName))); // 得到证件类型 List dataServiceList1 = dictionaryDataService.getListByTypeDataCode("certificateType"); BiMap dataServiceMap1 = HashBiMap.create(dataServiceList1.stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName))); // 得到文化程度 List dataServiceList2 = dictionaryDataService.getListByTypeDataCode("Education"); BiMap dataServiceMap2 = HashBiMap.create(dataServiceList2.stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName))); // 得到职级 List dataServiceList3 = dictionaryDataService.getListByTypeDataCode("Rank"); BiMap dataServiceMap3 = HashBiMap.create(dataServiceList3.stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName))); // 得到性别 List dataServiceList4 = dictionaryDataService.getListByTypeDataCode("sex"); BiMap dataServiceMap4 = HashBiMap.create(dataServiceList4.stream().collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName))); // // 去除重复的account // Map collect = dataList.stream().filter(t -> StringUtil.isNotBlank(t.getAccount())).collect(Collectors.groupingBy(t -> t.getAccount(), Collectors.counting())); // List collect1 = collect.entrySet().stream().filter(entry -> entry.getValue() > 1).map(entry -> entry.getKey()).collect(Collectors.toList()); // for (String account : collect1) { // List collect2 = dataList.stream().filter(t -> account.equals(t.getAccount())).collect(Collectors.toList()); // dataList.removeAll(collect2); // exceptionList.addAll(collect2); // } // Map userExportVOMap = dataList.stream().collect(Collectors.toMap(UserExportVO::getAccount, Function.identity())); //记录成功了几条 int sum = 0; //记录第几条失败 int num = 0; for (UserExportVO exportVO : dataList) { UserImportModel model = new UserImportModel(); UserExportExceptionVO exceptionVO = JsonUtil.getJsonToBean(exportVO, UserExportExceptionVO.class); StringJoiner exceptionMsg = new StringJoiner(";"); // 处理账号 if (StringUtil.isNotEmpty(exportVO.getAccount())) { UserEntity userByAccount = getUserByAccount(exportVO.getAccount()); if (Objects.nonNull(userByAccount)) { // 账号重复 exceptionMsg.add("账号已存在"); } String regex = "^[a-z0-9A-Z\u4e00-\u9fa5]+$" ; if (!exportVO.getAccount().matches(regex)) { // 账号重复 exceptionMsg.add("账户值不能含有特殊符号"); } model.setAccount(exportVO.getAccount()); } else { // 账号为空 exceptionMsg.add("账号不能为空"); } // 处理姓名 if (StringUtil.isEmpty(exportVO.getRealName())) { // 姓名为空 exceptionMsg.add("姓名不能为空"); } model.setRealName(exportVO.getRealName()); // 处理组织id String organizeId = exportVO.getOrganizeId(); if (StringUtil.isEmpty(organizeId)) { // 判断如果所属组织为空,则为错误数据 exceptionMsg.add("所属组织不能为空"); } else { StringJoiner orgName = new StringJoiner("、"); // 处理多级组织 String[] organizeIds = organizeId.split(";"); // 储存字段 StringJoiner orgIds = new StringJoiner(","); // 处理单个组织 for (String id : organizeIds) { String[] split = id.split("/"); // 定义一个标志,当前部门如果不存在则存到错误集合中 if (split.length > 0) { for (int i = 0; i < split.length; i++) { String orgId = split[i]; OrganizeEntity organizeEntity = organizeService.getInfoByFullName(orgId); if (organizeEntity != null) { if (i == split.length - 1) { orgIds.add(organizeEntity.getId()); } } else { orgName.add(id); break; } } } } if (orgName.length() > 0) { exceptionMsg.add("找不到该所属组织(" + orgName.toString() + ")"); } else { model.setOrganizeId(orgIds.toString()); } } // 处理性别 if (StringUtil.isEmpty(exportVO.getGender())) { // 性别为必填项,不给默认为错误,不给默认值 exceptionMsg.add("性别不能为空"); } else { if (dataServiceMap4.containsValue(exportVO.getGender())) { model.setGender(dataServiceMap4.inverse().get(exportVO.getGender())); } else { exceptionMsg.add("找不到该性别"); } } // 处理主管id String managerId = exportVO.getManagerId(); if (StringUtil.isNotEmpty(managerId)) { String[] split1 = managerId.split("/"); if (split1.length > 0) { String account = split1[split1.length - 1]; UserEntity entity = getUserByAccount(account); if (Objects.nonNull(entity) && StringUtil.isNotEmpty(entity.getAccount())) { model.setManagerId(entity.getId()); } } } String tmpOrganizeId = StringUtil.isEmpty(model.getOrganizeId()) ? "" : model.getOrganizeId(); // 处理岗位id String positionId = exportVO.getPositionId(); if (StringUtil.isNotEmpty(positionId)) { StringBuilder positionIdBuffer = new StringBuilder(); String[] positionIds = positionId.split(","); for (String id : positionIds) { // 岗位名称+编码 String[] positionName = id.split("/"); // 无编码无名称代表是无用数据,不予保存 if (positionName.length > 1) { // 通过名称和编码获取岗位信息 List positionEntityList = positionService.getListByFullName(positionName[0], positionName[1]); if (positionEntityList != null && positionEntityList.size() > 0) { PositionEntity positionEntity = positionEntityList.get(0); String[] split = tmpOrganizeId.split(","); boolean flag = false; for (String orgId : split) { List list = positionService.getListByOrganizeId(Collections.singletonList(orgId), false); if (list.stream().anyMatch(t -> t.getId().equals(positionEntity.getId()))) { flag = true; break; } } if (flag) { positionIdBuffer.append("," + positionEntity.getId()); } } } } model.setPositionId(positionIdBuffer.toString().replaceFirst(",", "")); } model.setDescription(exportVO.getDescription()); // 处理民族 if (StringUtil.isNotEmpty(exportVO.getNation())) { if (dataServiceMap.containsValue(exportVO.getNation())) { model.setNation(dataServiceMap.inverse().get(exportVO.getNation())); } } model.setNativePlace(exportVO.getNativePlace()); // 处理证件类型 if (StringUtil.isNotEmpty(exportVO.getCertificatesType())) { if (dataServiceMap1.containsValue(exportVO.getCertificatesType())) { model.setCertificatesType(dataServiceMap1.inverse().get(exportVO.getCertificatesType())); } } model.setCertificatesNumber(exportVO.getCertificatesNumber()); // 处理文化程度 if (StringUtil.isNotEmpty(exportVO.getEducation())) { if (dataServiceMap2.containsValue(exportVO.getEducation())) { model.setEducation(dataServiceMap2.inverse().get(exportVO.getEducation())); } } // 处理生日 if (StringUtil.isNotEmpty(exportVO.getBirthday())) { Date date = DateUtil.stringToDate(exportVO.getBirthday()); model.setBirthday(date); } model.setTelePhone(exportVO.getTelePhone()); model.setMobilePhone(exportVO.getMobilePhone()); model.setLandline(exportVO.getLandline()); model.setEmail(exportVO.getEmail()); model.setUrgentContacts(exportVO.getUrgentContacts()); model.setUrgentTelePhone(exportVO.getUrgentTelePhone()); model.setPostalAddress(exportVO.getPostalAddress()); model.setSortCode(exportVO.getSortCode() == null ? 0 : exportVO.getSortCode()); // 入职时间 if (StringUtil.isNotEmpty(exportVO.getEntryDate())) { Date date = DateUtil.stringToDate(exportVO.getEntryDate()); model.setEntryDate(date); } // 设置状态 if ("锁定".equals(exportVO.getEnabledMark())) { model.setEnabledMark(2); } else if ("正常".equals(exportVO.getEnabledMark())) { model.setEnabledMark(1); } else { model.setEnabledMark(0); } // 处理证件类型 if (StringUtil.isNotEmpty(exportVO.getRanks())) { if (dataServiceMap3.containsValue(exportVO.getRanks())) { model.setRanks(dataServiceMap3.inverse().get(exportVO.getRanks())); } } if (exceptionMsg.length() > 0) { exceptionVO.setErrorsInfo(exceptionMsg.toString()); exceptionList.add(exceptionVO); continue; } UserEntity entitys = JsonUtil.getJsonToBean(model, UserEntity.class); entitys.setHeadIcon("001.png"); try { create(entitys); sum++; } catch (Exception e) { if (e instanceof DataException) { exceptionVO.setErrorsInfo(e.getMessage()); } else { exceptionVO.setErrorsInfo("数据有误"); } exceptionList.add(exceptionVO); log.error("导入第" + (num + 1) + "条数据失败"); } } UserImportVO vo = new UserImportVO(); vo.setSnum(sum); if (exceptionList.size() > 0) { vo.setResultType(1); vo.setFailResult(exceptionList); vo.setFnum(exceptionList.size()); return vo; } else { vo.setResultType(0); return vo; } } @Override public void getOrganizeIdTree(String organizeId, StringBuffer organizeParentIdList) { OrganizeEntity entity = organizeService.getInfo(organizeId); if (Objects.nonNull(entity) && StringUtil.isNotEmpty(entity.getParentId())) { // 记录id organizeParentIdList.append(organizeId + ","); getOrganizeIdTree(entity.getParentId(), organizeParentIdList); } } @Override public DownloadVO exportExceptionData(List dataList) { DownloadVO vo = exportUtil("account,realName,gender,email,organizeId,managerId,positionId,roleId,sortCode,enabledMark,description,nation," + "nativePlace,entryDate,certificatesType,certificatesNumber,education,birthday,telePhone,landline,mobilePhone,urgentContacts," + "urgentTelePhone,postalAddress,ranks,errorsInfo" , "错误报告", dataList, 1); return vo; } @Override public List getUserName(List id, Pagination pagination) { List list = new ArrayList<>(); id.removeAll(Collections.singleton(null)); if (id.size() > 0) { QueryWrapper queryWrapper = new QueryWrapper<>(); if (!StringUtil.isEmpty(pagination.getKeyword())) { queryWrapper.lambda().and( t -> t.like(UserEntity::getRealName, pagination.getKeyword()) .or().like(UserEntity::getAccount, pagination.getKeyword()) ); } queryWrapper.lambda().in(UserEntity::getId, id); queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0); queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount, UserEntity::getGender, UserEntity::getHeadIcon, UserEntity::getMobilePhone); Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize()); IPage iPage = this.page(page, queryWrapper); return pagination.setData(iPage.getRecords(), iPage.getTotal()); } return pagination.setData(list, list.size()); } @Override public List getUserNames(List id, PaginationUser pagination, Boolean flag, Boolean enabledMark) { List list = new ArrayList<>(); id.removeAll(Collections.singleton(null)); if (id.size() > 0) { QueryWrapper queryWrapper = new QueryWrapper<>(); if (!StringUtil.isEmpty(pagination.getKeyword())) { queryWrapper.lambda().and( t -> t.like(UserEntity::getRealName, pagination.getKeyword()) .or().like(UserEntity::getAccount, pagination.getKeyword()) .or().like(UserEntity::getMobilePhone, pagination.getKeyword()) ); } List> lists = Lists.partition(id, 1000); queryWrapper.lambda().and(t -> { for (List userId : lists) { t.or().in(UserEntity::getId, userId); } }); if (flag) { queryWrapper.lambda().ne(UserEntity::getId, UserProvider.getUser().getUserId()); } if (enabledMark) { queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0); } if (StringUtil.isNotEmpty(pagination.getGender())) { queryWrapper.lambda().eq(UserEntity::getGender, pagination.getGender()); } queryWrapper.lambda().orderByDesc(UserEntity::getCreatorTime); // queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount, // UserEntity::getGender, UserEntity::getMobilePhone); if (ObjectUtil.isEmpty(pagination) || Objects.equals(pagination.getDataType(), 1)) { return this.list(queryWrapper); } Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize()); IPage iPage = this.page(page, queryWrapper); return pagination.setData(iPage.getRecords(), iPage.getTotal()); } return ObjectUtil.isEmpty(pagination) ? new ArrayList<>() : pagination.setData(list, list.size()); } @Override public List getListByRoleId(String roleId) { List list = new ArrayList<>(); // 根据roleId获取,用户与组织的关联对象集合 userRelationService.getListByRoleId(roleId).forEach(u -> { list.add(this.getInfo(u.getUserId())); }); return list; } @Override public List getListByRoleIds(List roleIds) { QueryWrapper query = new QueryWrapper<>(); query.lambda().eq(UserRelationEntity::getObjectType, "role").in(UserRelationEntity::getObjectId, roleIds); List list = userRelationService.list(query); if (CollectionUtil.isNotEmpty(list)) { List userIds = list.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()); return listByIds(userIds); } return new ArrayList<>(); } @Override public List getFullNameByIds(List ids) { List list = new ArrayList<>(); if (ids != null) { ids.forEach(selectedId -> { if (StringUtil.isNotEmpty(selectedId)) { String[] split = selectedId.split("--"); // 截取type后获取详情 if (split.length > 1) { String type = split[1]; if (PermissionConst.COMPANY.equalsIgnoreCase(type) || PermissionConst.DEPARTMENT.equalsIgnoreCase(type)) { OrganizeEntity organizeEntity = organizeService.getInfo(split[0]); if (organizeEntity != null) { list.add(organizeEntity.getFullName()); } } else if (PermissionConst.ROLE.equalsIgnoreCase(type)) { RoleEntity roleEntity = roleService.getInfo(split[0]); if (roleEntity != null) { list.add(roleEntity.getFullName()); } } else if (PermissionConst.POSITION.equalsIgnoreCase(type)) { PositionEntity positionEntity = positionService.getInfo(split[0]); if (positionEntity != null) { list.add(positionEntity.getFullName()); } } else if (PermissionConst.GROUP.equalsIgnoreCase(type)) { GroupEntity groupEntity = groupService.getInfo(split[0]); if (groupEntity != null) { list.add(groupEntity.getFullName()); } } else if ("user".equalsIgnoreCase(type)) { UserEntity userEntity = this.getInfo(split[0]); if (userEntity != null) { list.add(userEntity.getRealName()); } } } else { UserEntity userEntity = this.getInfo(split[0]); if (userEntity != null) { list.add(userEntity.getRealName()); } } } }); } return list; } @Override public List selectedByIds(List ids) { List list = new ArrayList<>(); List organizeEntityList = organizeService.list(); Map allOrgsTreeName = organizeService.getAllOrgsTreeName(); List organizeSelectorList = JsonUtil.getJsonToList(organizeEntityList, OrganizeSelectorVO.class); for (OrganizeSelectorVO item : organizeSelectorList) { if (PermissionConst.DEPARTMENT.equals(item.getCategory())) { item.setIcon(PermissionConst.DEPARTMENT_ICON); } else { item.setIcon(PermissionConst.COMPANY_ICON); } item.setFullName(item.getOrgNameTree()); if (StringUtil.isNotEmpty(item.getParentId()) && Objects.nonNull(allOrgsTreeName.get(item.getParentId()))) { item.setParentName(allOrgsTreeName.get(item.getParentId()).toString()); } String[] orgs = item.getOrganizeIdTree().split(","); item.setOrganizeIds(Arrays.asList(orgs)); } if (ids != null) { Map orgIdNameMaps = organizeService.getInfoList(); ids.forEach(selectedId -> { if (StringUtil.isNotEmpty(selectedId)) { // 判断是否为系统参数 if (JnpfConst.SYSTEM_PARAM.containsKey(selectedId)) { UserIdListVo vo = new UserIdListVo(); vo.setId(selectedId); vo.setFullName(JnpfConst.SYSTEM_PARAM.get(selectedId)); } //组织 String[] split = selectedId.split("--"); // 截取type后获取详情 if (split.length > 1) { String type = split[1]; if (PermissionConst.COMPANY.equalsIgnoreCase(type) || PermissionConst.DEPARTMENT.equalsIgnoreCase(type)) { OrganizeEntity organizeEntity = organizeService.getInfo(split[0]); if (organizeEntity != null) { BaseInfoVo vo = JsonUtil.getJsonToBean(organizeEntity, BaseInfoVo.class); if ("department".equals(organizeEntity.getCategory())) { vo.setIcon(PermissionConst.DEPARTMENT_ICON); } else if ("company".equals(organizeEntity.getCategory())) { vo.setIcon(PermissionConst.COMPANY_ICON); } vo.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/")); vo.setOrganizeIds(organizeService.getOrgIdTree(organizeEntity)); vo.setType(organizeEntity.getCategory()); list.add(vo); } } else if (PermissionConst.ROLE.equalsIgnoreCase(type)) { RoleEntity roleEntity = roleService.getInfo(split[0]); if (roleEntity != null) { BaseInfoVo vo = JsonUtil.getJsonToBean(roleEntity, BaseInfoVo.class); List relationListByRoleId = roleRelationService.getListByRoleId(vo.getId(), null); StringJoiner orgName = new StringJoiner(","); relationListByRoleId.forEach(item -> { orgName.add(item.getObjectId()); }); vo.setId(selectedId); vo.setOrganize(orgName.toString()); vo.setType(SysParamEnum.ROLE.getCode()); vo.setIcon(PermissionConst.ROLE_ICON); vo.setOrgNameTree(vo.getFullName()); list.add(vo); } } else if (SysParamEnum.POS.getCode().equalsIgnoreCase(type) || SysParamEnum.SUBPOS.getCode().equalsIgnoreCase(type) || SysParamEnum.PROGENYPOS.getCode().equalsIgnoreCase(type)) { PositionEntity positionEntity = positionService.getInfo(split[0]); if (positionEntity != null) { BaseInfoVo vo = JsonUtil.getJsonToBean(positionEntity, BaseInfoVo.class); vo.setId(selectedId); OrganizeEntity info = organizeService.getInfo(positionEntity.getOrganizeId()); String orgName = "" ; if (info != null) { vo.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, info.getOrganizeIdTree(), "/")); orgName = vo.getOrganize(); } vo.setType(SysParamEnum.get(type).getCode()); vo.setIcon(PermissionConst.POSITION_ICON); vo.setOrgNameTree(orgName + "/" + positionEntity.getFullName() + SysParamEnum.get(type).getSuffix()); list.add(vo); } } else if (SysParamEnum.GROUP.getCode().equalsIgnoreCase(type)) { GroupEntity groupEntity = groupService.getInfo(split[0]); if (groupEntity != null) { BaseInfoVo vo = JsonUtil.getJsonToBean(groupEntity, BaseInfoVo.class); vo.setIcon(PermissionConst.GROUP_ICON); vo.setId(selectedId); vo.setType(SysParamEnum.GROUP.getCode()); vo.setOrgNameTree(groupEntity.getFullName() + SysParamEnum.get(type).getSuffix()); list.add(vo); } } else if (SysParamEnum.USER.getCode().equalsIgnoreCase(type)) { UserEntity userEntity = this.getInfo(split[0]); if (userEntity != null) { BaseInfoVo vo = JsonUtil.getJsonToBean(userEntity, BaseInfoVo.class); List listByObjectType = userRelationService.getListByObjectType(userEntity.getId(), PermissionConst.ORGANIZE); StringJoiner orgName = new StringJoiner(","); listByObjectType.forEach(userRelationEntity -> { OrganizeEntity info = organizeService.getInfo(userRelationEntity.getObjectId()); if (info != null) { String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, info.getOrganizeIdTree(), "/"); orgName.add(fullNameByOrgIdTree); } }); vo.setId(selectedId); vo.setOrganize(orgName.toString()); vo.setType(SysParamEnum.USER.getCode()); vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon())); vo.setFullName(vo.getRealName() + "/" + vo.getAccount()); vo.setOrgNameTree(vo.getFullName()); list.add(vo); } } else { BaseInfoVo vo = new BaseInfoVo(); List collect = organizeSelectorList.stream() .filter(it -> split[0].equals(it.getId())) .collect(Collectors.toList()); if (!collect.isEmpty()) { vo = BeanUtil.copyProperties(collect.get(0), BaseInfoVo.class); String id = split[0]; SysParamEnum sysParamEnum = SysParamEnum.get(type); String suffix = sysParamEnum != null ? sysParamEnum.getSuffix() : "" ; vo.setId(selectedId); vo.setOrgNameTree(allOrgsTreeName.get(id) + suffix); } vo.setId(selectedId); vo.setFullName(SysParamEnum.get(split[1]).getName()); vo.setRealName(orgIdNameMaps.get(split[0]) + "\\" + vo.getFullName()); vo.setType(split[1]); list.add(vo); } } else { UserEntity userEntity = this.getInfo(split[0]); if (userEntity != null) { extracted(userEntity, orgIdNameMaps, list, userEntity.getRealName() + "/" + userEntity.getAccount()); } if (selectedId.equals("@userId")) { UserInfo user = UserProvider.getUser(); userEntity = this.getInfo(user.getUserId()); userEntity.setId("@userId"); String userName = "当前用户" ; extracted(userEntity, orgIdNameMaps, list, userName); } } } }); } return list; } private void extracted(UserEntity userEntity, Map orgIdNameMaps, List list, String userName) { BaseInfoVo vo = JsonUtil.getJsonToBean(userEntity, BaseInfoVo.class); List listByObjectType = userRelationService.getListByObjectType(userEntity.getId(), PermissionConst.ORGANIZE); StringJoiner orgName = new StringJoiner(","); listByObjectType.forEach(userRelationEntity -> { OrganizeEntity info = organizeService.getInfo(userRelationEntity.getObjectId()); if (info != null) { String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, info.getOrganizeIdTree(), "/"); orgName.add(fullNameByOrgIdTree); } }); vo.setOrganize(orgName.toString()); vo.setType("user"); vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon())); vo.setFullName(vo.getRealName() + "/" + vo.getAccount()); vo.setOrgNameTree(userName); list.add(vo); } @Override public Boolean delCurRoleUser(String message, List objectIdAll) { List list = permissionGroupService.list(objectIdAll).stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList()); List member = list.stream().filter(t -> StringUtil.isNotEmpty(t.getPermissionMember())).map(PermissionGroupEntity::getPermissionMember).collect(Collectors.toList()); List userIdList = new ArrayList<>(); if (list.stream().filter(t -> Objects.equals(t.getType(), 0)).count() > 0) { userIdList.addAll(getUserMap().keySet()); } else { // 判断角色下面的人 userIdList.addAll(this.getUserIdList(member)); } delCurUser(message, userIdList); return true; } @Override public List getList(List orgIdList, String keyword) { // 得到用户关系表 List listByObjectId = userRelationService.getListByOrgId(orgIdList); if (listByObjectId.isEmpty()) { return new ArrayList<>(); } QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(UserEntity::getId, listByObjectId.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList())).and( t -> t.like(UserEntity::getRealName, keyword) .or().like(UserEntity::getAccount, keyword) ); return this.list(queryWrapper); } @Override public List getListBySyn(List orgIdList, String keyword) { // 得到用户关系表 List listByObjectId = userRelationService.getListByOrgId(orgIdList); //根据userId分类 Map> collect = listByObjectId.stream().collect(Collectors.groupingBy(UserRelationEntity::getUserId)); if (listByObjectId.isEmpty()) { return new ArrayList<>(); } QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(UserEntity::getId, listByObjectId.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList())).and( t -> t.like(UserEntity::getRealName, keyword) .or().like(UserEntity::getAccount, keyword) ); List list = this.list(queryWrapper); ArrayList userEntities = new ArrayList<>(); for (UserEntity userEntity : list) { List userRelationEntities = collect.get(userEntity.getId()); for (UserRelationEntity userRelationEntity : userRelationEntities) { UserEntity entity = BeanUtil.copyProperties(userEntity, UserEntity.class); entity.setOrganizeId(userRelationEntity.getObjectId()); userEntities.add(entity); } } return userEntities; } @Override public List getUserIdList(List idList) { Set userIds = new LinkedHashSet<>(); idList.forEach(selectedId -> { if (StringUtil.isNotEmpty(selectedId)) { if (selectedId.equals("@userId")) { userIds.add(UserProvider.getUser().getUserId()); return; } String[] split = selectedId.split("--"); if (Arrays.stream(split).count() == 1) { UserEntity info = userService.getInfo(selectedId); if (BeanUtil.isNotEmpty(info)) { userIds.add(info.getId()); } return; } if (selectedId.substring(selectedId.length() - 3).equalsIgnoreCase(SysParamEnum.ORG.getCode())) { ArrayList strings = new ArrayList<>(); if (selectedId.contains(SysParamEnum.SUBORG.getCode())) { List listByParentId = organizeService.getListByParentId(split[0]); if (listByParentId != null) { strings.addAll(listByParentId.stream().map(OrganizeEntity::getId).collect(Collectors.toList())); } } if (selectedId.contains(SysParamEnum.PROGENYORG.getCode())) { List grandSonList = organizeService.getAllChild(split[0]); if (grandSonList != null) { strings.addAll(grandSonList.stream().map(OrganizeEntity::getId).collect(Collectors.toList())); } } strings.add(split[0]); List listByOrgIds = positionService.getListByOrgIds(strings.stream() .filter(Objects::nonNull).collect(Collectors.toList())); List positionIds = listByOrgIds.stream().map(PositionEntity::getId).collect(Collectors.toList()); List listByObjectIdAll = userRelationService.getListByObjectIdAll(positionIds); userIds.addAll(listByObjectIdAll.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList())); } else if (selectedId.substring(selectedId.length() - 3).equalsIgnoreCase(SysParamEnum.POS.getCode())) { ArrayList strings = new ArrayList<>(); strings.add(split[0]); PositionEntity info = positionService.getInfo(split[0]); if (info != null && selectedId.contains(SysParamEnum.SUBPOS.getCode())) { List byParentId = positionService.getByParentId(info.getId()); if (null != byParentId && !byParentId.isEmpty()) { strings.addAll(byParentId.stream().map(PositionEntity::getId).collect(Collectors.toList())); } } if (info != null && selectedId.contains(SysParamEnum.PROGENYPOS.getCode())) { List grandSonList = positionService.getAllChild(info.getId()); if (null != grandSonList) { strings.addAll(grandSonList.stream().map(PositionEntity::getId).collect(Collectors.toList())); } } List collect = userRelationService.getListByObjectIdAll(strings) .stream() .map(UserRelationEntity::getUserId) .collect(Collectors.toList()); userIds.addAll(collect); } else if (selectedId.contains(SysParamEnum.GROUP.getCode())) { List collect = userRelationService.getListByObjectId(split[0]) .stream() .map(UserRelationEntity::getUserId) .collect(Collectors.toList()); userIds.addAll(collect); } else if (selectedId.contains(SysParamEnum.ROLE.getCode())) { List collect = roleRelationService.getListByRoleId(split[0], PermissionConst.USER) .stream() .map(RoleRelationEntity::getObjectId) .collect(Collectors.toList()); userIds.addAll(collect); } else if (selectedId.contains(SysParamEnum.USER.getCode())) { UserEntity info = userService.getInfo(split[0]); if (BeanUtil.isNotEmpty(info)) { userIds.add(info.getId()); } } } }); return new ArrayList<>(userIds); } @Override public List getObjList(List userIds, PaginationUser pagination) { // 得到所有的用户id关系 Map orgIdNameMaps = organizeService.getInfoList(); List userEntityList = getUserIdListByOrganize(userIds, pagination); if (userEntityList.isEmpty()) { return Collections.emptyList(); } List jsonToList = JsonUtil.getJsonToList(userEntityList, UserIdListVo.class); jsonToList.forEach(userIdListVo -> { List listByObjectType = userRelationService.getListByObjectType(userIdListVo.getId(), PermissionConst.ORGANIZE); StringJoiner orgName = new StringJoiner(","); listByObjectType.forEach(userRelationEntity -> { OrganizeEntity info = organizeService.getInfo(userRelationEntity.getObjectId()); if (info != null) { String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, info.getOrganizeIdTree(), "/"); orgName.add(fullNameByOrgIdTree); } }); userIdListVo.setOrganize(orgName.toString()); userIdListVo.setType(SysParamEnum.USER.getCode()); userIdListVo.setFullName(userIdListVo.getRealName() + "/" + userIdListVo.getAccount()); userIdListVo.setHeadIcon(UploaderUtil.uploaderImg(userIdListVo.getHeadIcon())); }); return JsonUtil.getJsonToList(jsonToList, BaseInfoVo.class); } private List getUserIdListByOrganize(List userIds, PaginationUser pagination) { List userObjectIds = getUserIdList(userIds); if (userObjectIds.isEmpty()) { return Collections.emptyList(); } LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.ne(UserEntity::getAccount, ADMIN_KEY); wrapper.ne(UserEntity::getEnabledMark, 0); //idList范围过滤 if (userObjectIds.size() > 1000) { List> lists = Lists.partition(userObjectIds, 1000); wrapper.and(t -> { for (List item : lists) { t.in(UserEntity::getId, item).or(); } }); } else { wrapper.in(UserEntity::getId, userObjectIds); } //关键字 if (StringUtil.isNotEmpty(pagination.getKeyword())) { wrapper.and( t -> t.like(UserEntity::getRealName, pagination.getKeyword()) .or().like(UserEntity::getAccount, pagination.getKeyword()) .or().like(UserEntity::getMobilePhone, pagination.getKeyword()) ); } Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize()); IPage iPage = userService.page(page, wrapper); return pagination.setData(iPage.getRecords(), iPage.getTotal()); } @Override public List getListByAuthorize(String organizeId, jnpf.base.Page page) { List jsonToList = new ArrayList<>(16); List collect0 = organizeAdministratorService.getListByAuthorize().stream().map(OrganizeEntity::getId).collect(Collectors.toList()); // 有权限的组织 Map orgMaps = organizeService.getOrganizeName(collect0, null, true, null); Map orgIdNameMaps = organizeService.getInfoList(); List dataServiceList4 = dictionaryDataService.getListByTypeDataCode("sex"); Map dataServiceMap4 = dataServiceList4.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName)); //判断是否搜索关键字 if (StringUtil.isNotEmpty(page.getKeyword())) { //通过关键字查询 List list = getList(new ArrayList<>(orgMaps.keySet()), page.getKeyword()); //遍历用户给要返回的值插入值 for (UserEntity entity : list) { UserByRoleVO vo = new UserByRoleVO(); vo.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon())); vo.setId(entity.getId()); vo.setFullName(entity.getRealName() + "/" + entity.getAccount()); vo.setEnabledMark(entity.getEnabledMark()); vo.setIsLeaf(true); vo.setHasChildren(false); vo.setIcon(PermissionConst.USER_ICON); vo.setType("user"); vo.setGender(dataServiceMap4.get(entity.getGender())); List listByUserId = userRelationService.getListByUserId(entity.getId()).stream().filter(t -> t != null && PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList()); StringBuilder stringBuilder = new StringBuilder(); listByUserId.forEach(t -> { OrganizeEntity organizeEntity = orgMaps.get(t.getObjectId()); if (organizeEntity != null) { String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/"); if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) { stringBuilder.append("," + fullNameByOrgIdTree); } } }); if (stringBuilder.length() > 0) { vo.setOrganize(stringBuilder.toString().replaceFirst(",", "")); } jsonToList.add(vo); } return jsonToList; } //获取所有组织 List collect = new ArrayList<>(orgMaps.values()); //判断时候传入组织id //如果传入组织id,则取出对应的子集 if (!"0".equals(organizeId)) { //通过组织查询部门及人员 OrganizeEntity organizeEntity = orgMaps.get(organizeId); if (organizeEntity != null) { // 取出子组织 List collect1 = collect.stream().filter(t -> !t.getId().equals(organizeEntity.getId()) && t.getOrganizeIdTree().contains(organizeEntity.getId())).collect(Collectors.toList()); // 判断组织关系中是否有子部门id List organizeEntities = new ArrayList<>(); for (OrganizeEntity entity : collect1) { OrganizeEntity organizeEntity1 = orgMaps.get(entity.getId()); if (organizeEntity1 != null) { organizeEntities.add(organizeEntity1); } } // 得到子集的子集 List collect2 = collect.stream().filter(t -> t.getOrganizeIdTree().contains(organizeId)).collect(Collectors.toList()); // 移除掉上级不是同一个的 List collect3 = new ArrayList<>(); collect2.forEach(t -> { organizeEntities.forEach(oe -> { if (!oe.getId().equals(t.getId()) && t.getOrganizeIdTree().contains(oe.getId())) { collect3.add(t); } }); }); organizeEntities.removeAll(collect3); //取出组织下的人员 List entityList = getListByOrganizeId(organizeId, null); for (UserEntity entity : entityList) { UserByRoleVO vo = new UserByRoleVO(); vo.setId(entity.getId()); vo.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon())); vo.setFullName(entity.getRealName() + "/" + entity.getAccount()); vo.setEnabledMark(entity.getEnabledMark()); vo.setIsLeaf(true); vo.setHasChildren(false); vo.setIcon(PermissionConst.USER_ICON); vo.setType("user"); vo.setGender(dataServiceMap4.get(entity.getGender())); List listByUserId = userRelationService.getListByUserId(entity.getId()).stream().filter(t -> t != null && PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList()); StringJoiner stringJoiner = new StringJoiner(","); listByUserId.forEach(t -> { OrganizeEntity organizeEntity1 = orgMaps.get(t.getObjectId()); if (organizeEntity1 != null) { String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity1.getOrganizeIdTree(), "/"); if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) { stringJoiner.add(fullNameByOrgIdTree); } } }); vo.setOrganize(stringJoiner.toString()); jsonToList.add(vo); } for (OrganizeEntity entitys : organizeEntities) { UserByRoleVO vo = new UserByRoleVO(); vo.setId(entitys.getId()); vo.setType(entitys.getCategory()); vo.setFullName(entitys.getFullName()); if ("department".equals(entitys.getCategory())) { vo.setIcon(PermissionConst.DEPARTMENT_ICON); } else { vo.setIcon(PermissionConst.COMPANY_ICON); } vo.setHasChildren(true); vo.setIsLeaf(false); vo.setEnabledMark(entitys.getEnabledMark()); if (StringUtil.isNotEmpty(entitys.getOrganizeIdTree())) { String[] split = entitys.getOrganizeIdTree().split(organizeEntity.getId()); if (split.length > 1) { vo.setFullName(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, split[1], "/")); } } jsonToList.add(vo); } } return jsonToList; } List list = new ArrayList<>(16); for (OrganizeEntity organizeEntity : collect) { if (organizeEntity != null && organizeEntity.getEnabledMark() == 1) { UserByRoleVO userByRoleVO = new UserByRoleVO(); userByRoleVO.setId(organizeEntity.getId()); userByRoleVO.setType(organizeEntity.getCategory()); if ("department".equals(organizeEntity.getCategory())) { userByRoleVO.setIcon(PermissionConst.DEPARTMENT_ICON); } else { userByRoleVO.setIcon(PermissionConst.COMPANY_ICON); } userByRoleVO.setHasChildren(true); userByRoleVO.setIsLeaf(false); userByRoleVO.setEnabledMark(organizeEntity.getEnabledMark()); // 处理断层 if (StringUtil.isNotEmpty(organizeEntity.getOrganizeIdTree())) { List list1 = new ArrayList<>(); String[] split = organizeEntity.getOrganizeIdTree().split(","); list1 = Arrays.asList(split); Collections.reverse(list1); for (String orgId : list1) { OrganizeEntity organizeEntity1 = orgMaps.get(orgId); if (organizeEntity1 != null && !organizeEntity1.getId().equals(organizeEntity.getId())) { // 记录id list.add(organizeEntity.getId()); break; } } } if (!list.contains(organizeEntity.getId())) { jsonToList.add(userByRoleVO); } } } jsonToList.forEach(t -> { OrganizeEntity entity = orgMaps.get(t.getId()); if (entity != null) { t.setFullName(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, entity.getOrganizeIdTree(), "/")); } t.setParentId(entity.getParentId()); }); return jsonToList; } private String getColumns(Integer key) { Map map = new HashMap<>(); map.put(1, "账号"); map.put(2, "姓名"); map.put(3, "性别"); map.put(4, "手机"); map.put(5, "说明"); map.put(6, "状态"); map.put(7, "排序"); map.put(8, "是否管理员"); map.put(9, "锁定标志"); map.put(10, "添加时间"); map.put(11, "部门"); return map.get(key); } /** * 判断上级是否直属主管的值是否为我的下属 * * @param id * @param managerId * @param num */ private boolean recursionSubordinates(String id, String managerId, int num) { UserEntity entity = getInfo(managerId); num++; if (entity != null && entity.getId().equals(id)) { return true; } if (num < 10) { if (entity != null) { return recursionSubordinates(id, entity.getManagerId(), num); } return false; } else { return false; } } /** * 查询给定的条件是否有默认当前登录者的默认用户值 * * @param userConditionModel * @return */ @Override public String getDefaultCurrentValueUserId(UserConditionModel userConditionModel) { UserInfo userInfo = UserProvider.getUser(); int currentFinded = 0; if (userConditionModel.getUserIds() != null && !userConditionModel.getUserIds().isEmpty() && userConditionModel.getUserIds().contains(userInfo.getUserId())) { currentFinded = 1; } if (currentFinded == 0 && userConditionModel.getDepartIds() != null && !userConditionModel.getDepartIds().isEmpty()) { List orgList = organizeService.getOrgEntityList(userConditionModel.getDepartIds(), true); List orgLIdList = orgList.stream().map(OrganizeEntity::getId).collect(Collectors.toList()); if (orgLIdList != null && !orgLIdList.isEmpty()) { List userIds = userRelationService.getListByObjectIdAll(orgLIdList).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()); if (userIds != null && !userIds.isEmpty() && userIds.contains(userInfo.getUserId())) { currentFinded = 1; } } } if (currentFinded == 0 && userConditionModel.getRoleIds() != null && !userConditionModel.getRoleIds().isEmpty()) { List roleList = roleService.getListByIds(userConditionModel.getRoleIds(), null, false); List roleIdList = roleList.stream().filter(t -> t.getEnabledMark() == 1).map(RoleEntity::getId).collect(Collectors.toList()); if (roleIdList != null && !roleIdList.isEmpty()) { List userIds = userRelationService.getListByObjectIdAll(roleIdList).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()); if (userIds != null && !userIds.isEmpty() && userIds.contains(userInfo.getUserId())) { currentFinded = 1; } } } if (currentFinded == 0 && userConditionModel.getPositionIds() != null && !userConditionModel.getPositionIds().isEmpty()) { List positionList = positionService.getPosList(userConditionModel.getPositionIds()); List positionIdList = positionList.stream().filter(t -> t.getEnabledMark() == 1).map(PositionEntity::getId).collect(Collectors.toList()); if (positionIdList != null && !positionIdList.isEmpty()) { List userIds = userRelationService.getListByObjectIdAll(positionIdList).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()); if (userIds != null && !userIds.isEmpty() && userIds.contains(userInfo.getUserId())) { currentFinded = 1; } } } if (currentFinded == 0 && userConditionModel.getGroupIds() != null && !userConditionModel.getGroupIds().isEmpty()) { List groupList = groupService.getListByIds(userConditionModel.getGroupIds()); List groupIdList = groupList.stream().map(GroupEntity::getId).collect(Collectors.toList()); if (groupIdList != null && !groupIdList.isEmpty()) { List userIds = userRelationService.getListByObjectIdAll(groupIdList).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()); if (userIds != null && !userIds.isEmpty() && userIds.contains(userInfo.getUserId())) { currentFinded = 1; } } } return (currentFinded == 1) ? userInfo.getUserId() : "" ; } @Override public List getUserAccount(List ids) { List list = new ArrayList<>(); if (!ids.isEmpty()) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(UserEntity::getAccount, ids); list = this.list(queryWrapper); } return list; } @Override public void updateStand(List ids, int standing) { List userName = getUserName(new ArrayList<>(ids), false); for (UserEntity user : userName) { String positionId = user.getPositionId(); String organizeId = user.getOrganizeId(); String id = user.getId(); UpdateWrapper wrapper = new UpdateWrapper<>(); wrapper.lambda().eq(UserEntity::getId, id); wrapper.lambda().set(UserEntity::getOrganizeId, organizeId); wrapper.lambda().set(UserEntity::getPositionId, positionId); update(wrapper); } if (!ids.isEmpty()) { UpdateWrapper pcWrapper = new UpdateWrapper<>(); pcWrapper.lambda().in(UserEntity::getId, ids); pcWrapper.lambda().eq(UserEntity::getStanding, standing); pcWrapper.lambda().set(UserEntity::getStanding, 3); update(pcWrapper); UpdateWrapper appWrapper = new UpdateWrapper<>(); appWrapper.lambda().in(UserEntity::getId, ids); appWrapper.lambda().eq(UserEntity::getAppStanding, standing); appWrapper.lambda().set(UserEntity::getAppStanding, 3); update(appWrapper); } } @Override public Boolean delCurUser(String message, List userIds) { if (userIds.isEmpty()) { return true; } //用户不强制下线,websokit推送刷新即可 List users = new ArrayList<>(); List onlineUserList = OnlineUserProvider.getOnlineUserList(); for (OnlineUserModel onlineUserModel : onlineUserList) { String userId = onlineUserModel.getUserId(); if (userIds.contains(userId)) { users.add(onlineUserModel); } } if (!ObjectUtils.isEmpty(users)) { for (OnlineUserModel user : users) { JSONObject obj = new JSONObject(); obj.put("method", "refresh"); obj.put("msg", StringUtil.isEmpty(message) ? MsgCode.PS010.get() : message); if (user != null) { OnlineUserProvider.sendMessage(user, obj); } } } return true; } @Override public void majorStandFreshUser() { UserInfo userInfo = UserProvider.getUser(); List onlineUserList = OnlineUserProvider.getOnlineUserList(); for (OnlineUserModel onlineUserModel : onlineUserList) { String userId = onlineUserModel.getUserId(); //当前用户,同平台的其他客户端需要强制刷新 if (userInfo.getUserId().equals(userId) && Objects.equals(!RequestContext.isOrignPc(), onlineUserModel.getIsMobileDevice())) { JSONObject obj = new JSONObject(); obj.put("method", "refresh"); obj.put("msg", MsgCode.PS010.get()); OnlineUserProvider.sendMessage(onlineUserModel, obj); } } } @Override public Boolean logoutUser(String message, List userIds) { if (userIds.isEmpty()) { return true; } //用户不强制下线 List users = new ArrayList<>(); List onlineUserList = OnlineUserProvider.getOnlineUserList(); for (OnlineUserModel onlineUserModel : onlineUserList) { String userId = onlineUserModel.getUserId(); if (userIds.contains(userId) && !Objects.equals(UserProvider.getUser().getToken(), onlineUserModel.getToken())) { users.add(onlineUserModel); } } if (!ObjectUtils.isEmpty(users)) { for (OnlineUserModel user : users) { JSONObject obj = new JSONObject(); obj.put("method", "logout"); obj.put("msg", StringUtil.isEmpty(message) ? MsgCode.PS011.get() : message); if (user != null) { OnlineUserProvider.sendMessage(user, obj); } //先移除对象, 并推送下线信息, 避免网络原因导致就用户未断开 新用户连不上WebSocket OnlineUserProvider.removeModel(user); //通知所有在线,有用户离线 //功能已删除 // for (OnlineUserModel item : OnlineUserProvider.getOnlineUserList().stream().filter(t -> !Objects.equals(user.getUserId(), t.getUserId()) && Objects.equals(user.getTenantId(), t.getTenantId())).collect(Collectors.toList())) { // if (!item.getUserId().equals(user.getUserId())) { // JSONObject objs = new JSONObject(); // objs.put("method", "Offline"); // //推送给前端 // OnlineUserProvider.sendMessage(item, objs); // } // } UserProvider.logoutByToken(user.getToken()); } } return true; } @Override public List getPageByIds(RoleRelationPage pagination) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().select(UserEntity::getId, UserEntity::getAccount, UserEntity::getRealName, UserEntity::getGender, UserEntity::getMobilePhone, UserEntity::getEnabledMark); boolean flag = false; //关键字(账户、姓名、手机) if (!StringUtil.isEmpty(pagination.getKeyword())) { flag = true; queryWrapper.lambda().and( t -> t.like(UserEntity::getAccount, pagination.getKeyword()) .or().like(UserEntity::getRealName, pagination.getKeyword()) .or().like(UserEntity::getMobilePhone, pagination.getKeyword()) ); } List> lists = Lists.partition(pagination.getIdList(), 1000); queryWrapper.lambda().and(t -> { for (List item : lists) { t.in(UserEntity::getId, item).or(); } }); queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime); if (flag) { queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime); return this.list(queryWrapper); } Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize()); IPage iPage = this.page(page, queryWrapper); return pagination.setData(iPage.getRecords(), iPage.getTotal()); } @Override public UserRelationIds getUserObjectIdList(String userId) { List listUser = userRelationService.getListByObjectType(userId, null); List group = listUser.stream().filter(t -> PermissionConst.GROUP.equals(t.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList()); List organize = listUser.stream().filter(t -> PermissionConst.ORGANIZE.equals(t.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList()); List position = listUser.stream().filter(t -> PermissionConst.POSITION.equals(t.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList()); List rogAndPos = listUser.stream().filter(t -> PermissionConst.ORGANIZE.equals(t.getObjectType()) || PermissionConst.POSITION.equals(t.getObjectType())) .map(UserRelationEntity::getObjectId).collect(Collectors.toList()); rogAndPos.add(userId); List role = roleRelationService.getListByObjectId(rogAndPos, null).stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList()); UserRelationIds userRelationIds = UserRelationIds.builder() .group(group) .organize(organize) .position(position) .role(role) .build(); return userRelationIds; } @Override public Map getSystemFieldValue(SystemParamModel model) { Map mapList = new HashMap<>(); List needList = model.getList(); UserInfo userInfo = UserProvider.getUser(); String userId = userInfo.getUserId(); List organizeIds = userInfo.getOrganizeIds(); List positionIds = userInfo.getPositionIds(); for (String key : needList) { List dataValue = new ArrayList<>(); String values = "" ; switch (key) { case DataInterfaceVarConst.CURRENTTIME: values = String.valueOf(DateUtil.stringToDate(DateUtil.getNow()).getTime()); break; case DataInterfaceVarConst.USER: values = userId; break; case DataInterfaceVarConst.ORG: values = JsonUtil.getObjectToString(organizeIds); break; case DataInterfaceVarConst.POSITIONID: values = JsonUtil.getObjectToString(positionIds); break; case DataInterfaceVarConst.USERANDSUB: dataValue.add(userId); if (!positionIds.isEmpty()) { dataValue.addAll(userRelationService.getUserAndSub(positionIds, null).stream() .map(SuperBaseEntity.SuperIBaseEntity::getId).collect(Collectors.toList())); } values = JsonUtil.getObjectToString(dataValue); break; case DataInterfaceVarConst.USERANDPROGENY: dataValue.add(userId); if (!positionIds.isEmpty()) { dataValue.addAll(userRelationService.getUserProgeny(positionIds, null).stream() .map(SuperBaseEntity.SuperIBaseEntity::getId).collect(Collectors.toList())); } values = JsonUtil.getObjectToString(dataValue); break; case DataInterfaceVarConst.ORGANDSUB: if (!organizeIds.isEmpty()) { List listByParentIds = organizeService.getListByParentIds(organizeIds); dataValue.addAll(organizeIds); dataValue.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList())); } values = JsonUtil.getObjectToString(dataValue); break; case DataInterfaceVarConst.ORGANIZEANDPROGENY: if (!organizeIds.isEmpty()) { List allChild = organizeService.getProgeny(organizeIds, null); dataValue.addAll(allChild.stream().map(OrganizeEntity::getId).collect(Collectors.toList())); } values = JsonUtil.getObjectToString(dataValue); break; case DataInterfaceVarConst.POSITIONANDSUB: if (!positionIds.isEmpty()) { List listByParentIds = positionService.getListByParentIds(positionIds); dataValue.addAll(positionIds); dataValue.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList())); } values = JsonUtil.getObjectToString(dataValue); break; case DataInterfaceVarConst.POSITIONANDPROGENY: if (!positionIds.isEmpty()) { List allChild = positionService.getProgeny(positionIds, null); dataValue.addAll(allChild.stream().map(PositionEntity::getId).collect(Collectors.toList())); } values = JsonUtil.getObjectToString(dataValue); break; default: break; } mapList.put(key, values); } return mapList; } }