update
This commit is contained in:
@@ -8,8 +8,6 @@ import com.aliyun.openservices.ons.api.bean.Subscription;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.enums.RocketMqGroupEnum;
|
||||
import com.cool.store.mq.RocketMqConfig;
|
||||
import com.cool.store.mq.consumer.listener.EnterpriseInitListener;
|
||||
import com.cool.store.mq.consumer.listener.EnterpriseScriptListener;
|
||||
import com.cool.store.mq.consumer.listener.TestListener;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -31,10 +29,6 @@ public class ConsumerClient {
|
||||
@Resource
|
||||
private RocketMqConfig rocketMqConfig;
|
||||
@Resource
|
||||
private EnterpriseInitListener enterpriseInitListener;
|
||||
@Resource
|
||||
private EnterpriseScriptListener enterpriseScriptListener;
|
||||
@Resource
|
||||
private TestListener testListener;
|
||||
|
||||
/**
|
||||
@@ -88,36 +82,4 @@ public class ConsumerClient {
|
||||
return consumerBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 企业开通
|
||||
*/
|
||||
@Bean(initMethod = "start", destroyMethod = "shutdown")
|
||||
public ConsumerBean enterpriseOpenBean() {
|
||||
RocketMqGroupEnum groupEnum = RocketMqGroupEnum.ENTERPRISE_OPEN_DATA_SYNC;
|
||||
ConsumerBean consumerBean = new ConsumerBean();
|
||||
//配置文件
|
||||
Properties properties = getCommonProperties(groupEnum);
|
||||
consumerBean.setProperties(properties);
|
||||
Map<Subscription, MessageListener> commonSubscriptionTable = getCommonSubscriptionTable(groupEnum, testListener);
|
||||
//订阅多个topic如上面设置
|
||||
consumerBean.setSubscriptionTable(commonSubscriptionTable);
|
||||
return consumerBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 企业库脚本开通
|
||||
*/
|
||||
@Bean(initMethod = "start", destroyMethod = "shutdown")
|
||||
public ConsumerBean enterpriseScriptBean() {
|
||||
RocketMqGroupEnum groupEnum = RocketMqGroupEnum.ENTERPRISE_OPEN_ENTERPRISE_RUN_SCRIPT;
|
||||
ConsumerBean consumerBean = new ConsumerBean();
|
||||
//配置文件
|
||||
Properties properties = getCommonProperties(groupEnum);
|
||||
consumerBean.setProperties(properties);
|
||||
Map<Subscription, MessageListener> commonSubscriptionTable = getCommonSubscriptionTable(groupEnum, enterpriseScriptListener);
|
||||
//订阅多个topic如上面设置
|
||||
consumerBean.setSubscriptionTable(commonSubscriptionTable);
|
||||
return consumerBean;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.cool.store.mq.consumer.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.openservices.ons.api.Action;
|
||||
import com.aliyun.openservices.ons.api.ConsumeContext;
|
||||
import com.aliyun.openservices.ons.api.Message;
|
||||
import com.aliyun.openservices.ons.api.MessageListener;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.dto.enterprise.EnterpriseInitDTO;
|
||||
import com.cool.store.enums.AppTypeEnum;
|
||||
import com.cool.store.enums.EnterpriseStatusEnum;
|
||||
import com.cool.store.service.EnterpriseInitService;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 企业开通初始化
|
||||
*
|
||||
* @author chenyupeng
|
||||
* @since 2022/1/26
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EnterpriseInitListener implements MessageListener {
|
||||
@Resource
|
||||
private EnterpriseInitService enterpriseInitService;
|
||||
@Autowired
|
||||
private RedisUtilPool redisUtilPool;
|
||||
|
||||
@Override
|
||||
public Action consume(Message message, ConsumeContext consumeContext) {
|
||||
if(message.getReconsumeTimes() + 1 >= Integer.parseInt(CommonConstants.MaxReconsumeTimes)){
|
||||
//超过最大消费次数
|
||||
return Action.CommitMessage;
|
||||
}
|
||||
String text = new String(message.getBody());
|
||||
if(StringUtils.isBlank(text)){
|
||||
return Action.CommitMessage;
|
||||
}
|
||||
String lockKey = "EnterpriseInitDataSync:" + message.getMsgID();
|
||||
EnterpriseInitDTO enterpriseInitDTO = JSONObject.parseObject(text, EnterpriseInitDTO.class);
|
||||
log.info("EnterpriseInitListener messageId:{},try times:{}, receive data :{}", message.getMsgID(), message.getReconsumeTimes(), JSONObject.toJSONString(enterpriseInitDTO));
|
||||
boolean lock = redisUtilPool.setNxExpire(lockKey, message.getMsgID(), CommonConstants.ENTERPRISE_OPEN_LOCK_TIMES);
|
||||
if (lock) {
|
||||
try {
|
||||
String appType = enterpriseInitDTO.getAppType();
|
||||
String enterpriseStatusKey = MessageFormat.format(CommonConstants.ENTERPRISE_OPEN_STATUS_KEY, enterpriseInitDTO.getCorpId(), enterpriseInitDTO.getAppType());
|
||||
enterpriseInitService.enterpriseInit(enterpriseInitDTO.getCorpId(), AppTypeEnum.getAppType(enterpriseInitDTO.getAppType()),
|
||||
enterpriseInitDTO.getEid(), enterpriseInitDTO.getDbName(), enterpriseInitDTO.getUserId());
|
||||
enterpriseInitService.sendOpenSucceededMsg(enterpriseInitDTO.getCorpId(), enterpriseInitDTO.getAppType(), Arrays.asList(enterpriseInitDTO.getUserId()));
|
||||
//更新企业开通缓存状态
|
||||
redisUtilPool.setString(enterpriseStatusKey, String.valueOf(EnterpriseStatusEnum.NORMAL.getCode()), CommonConstants.ONE_DAY_SECONDS);
|
||||
return Action.CommitMessage;
|
||||
} catch (Exception e) {
|
||||
log.error("has exception", e);
|
||||
} finally {
|
||||
redisUtilPool.delKey(lockKey);
|
||||
}
|
||||
}
|
||||
return Action.CommitMessage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.cool.store.mq.consumer.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.aliyun.openservices.ons.api.Action;
|
||||
import com.aliyun.openservices.ons.api.ConsumeContext;
|
||||
import com.aliyun.openservices.ons.api.Message;
|
||||
import com.aliyun.openservices.ons.api.MessageListener;
|
||||
import com.cool.store.dto.enterprise.EnterpriseOpenMsg;
|
||||
import com.cool.store.enums.RocketMqTagEnum;
|
||||
import com.cool.store.service.EnterpriseInitService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 执行企业端脚本消息监听
|
||||
* @author :xugangkun
|
||||
* @date :2022/2/11 15:32
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EnterpriseScriptListener implements MessageListener {
|
||||
|
||||
@Resource
|
||||
private EnterpriseInitService enterpriseInitService;
|
||||
|
||||
@Override
|
||||
public Action consume(Message message, ConsumeContext consumeContext) {
|
||||
String text = new String(message.getBody());
|
||||
log.info("EnterpriseScriptListener messageId:{}, msg:{}", message.getMsgID(), text);
|
||||
if(StringUtils.isBlank(text)){
|
||||
return Action.CommitMessage;
|
||||
}
|
||||
switch (RocketMqTagEnum.getByTag(message.getTag())){
|
||||
case ENTERPRISE_OPEN_ENTERPRISE_RUN_SCRIPT:
|
||||
log.info("run Enterprise Script start");
|
||||
EnterpriseOpenMsg msg = null;
|
||||
try {
|
||||
msg = JSON.parseObject(text, EnterpriseOpenMsg.class);
|
||||
} catch (Exception e) {
|
||||
log.error("invalid auth msg={}", text);
|
||||
}
|
||||
enterpriseInitService.runEnterpriseScript(msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Action.CommitMessage;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.dto.auth.AuthRegionStoreDTO;
|
||||
import com.cool.store.dto.auth.AuthRegionStoreUserDTO;
|
||||
import com.cool.store.dto.auth.AuthStoreCountDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* describe:可视化权限服务
|
||||
*
|
||||
* @author zhouyiping
|
||||
* @date 2020/10/14
|
||||
*/
|
||||
public interface AuthVisualService {
|
||||
|
||||
/**
|
||||
* do
|
||||
* 查询权限区域/门店(配置区域使用)
|
||||
* @param eid
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<AuthRegionStoreUserDTO> authRegionStore(String eid, String userId);
|
||||
|
||||
|
||||
/**
|
||||
* do
|
||||
* 查询权限区域/门店(配置区域使用)
|
||||
* @param eid
|
||||
* @param userIdList
|
||||
* @return
|
||||
*/
|
||||
List<AuthRegionStoreDTO> authRegionStoreByUserList(String eid, List<String> userIdList);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* do
|
||||
* 获取人员拥有的门店总数
|
||||
* @param eid
|
||||
* @param userId
|
||||
* @param isReturnList 是否返回门店列表
|
||||
* @return
|
||||
*/
|
||||
List<AuthStoreCountDTO> authStoreCount(String eid, List<String> userId, Boolean isReturnList);
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
public interface EnterpriseConfigService {
|
||||
|
||||
EnterpriseConfigDO selectByEnterpriseId(String enterpriseId);
|
||||
EnterpriseConfigDO selectByEnterpriseId();
|
||||
|
||||
/**
|
||||
* 根据dbName获取dbServer
|
||||
|
||||
@@ -13,12 +13,5 @@ import java.util.List;
|
||||
*/
|
||||
public interface EnterpriseInitService {
|
||||
|
||||
void runEnterpriseScript(EnterpriseOpenMsg msg);
|
||||
|
||||
|
||||
void enterpriseInit(String cropId, AppTypeEnum appType, String eid, String dbName, String openUserId);
|
||||
|
||||
void sendOpenSucceededMsg(String corpId, String appType, List<String> userList);
|
||||
|
||||
void sync(String eid, String userName, String userId, Long regionId);
|
||||
void sync(String userName, String userId, Long regionId);
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.context.CurrentUser;
|
||||
import com.cool.store.dto.enterprise.EnterpriseUserDTO;
|
||||
import com.cool.store.dto.usergroup.UserGroupAddRequest;
|
||||
import com.cool.store.dto.usergroup.UserGroupDTO;
|
||||
import com.cool.store.vo.buser.EnterpriseUserPageVO;
|
||||
import com.cool.store.vo.usergroup.UserGroupVO;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author wxp
|
||||
* @Date 2022/12/29 11:18
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface EnterpriseUserGroupService {
|
||||
|
||||
/**
|
||||
* 增加用户分组
|
||||
* @param enterpriseId
|
||||
* @param userGroupAddRequest
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
Boolean saveOrUpdateUserGroup(String enterpriseId, UserGroupAddRequest userGroupAddRequest, CurrentUser user);
|
||||
|
||||
Boolean updateUserGroup(String enterpriseId,Long userGroupId,List<String> userIdList);
|
||||
|
||||
void batchDeleteGroup(String enterpriseId, String groupId, List<String> userIdList);
|
||||
|
||||
/**
|
||||
* 获取用户分组列表
|
||||
* @param enterpriseId
|
||||
* @param groupName 分组名,模糊查询用
|
||||
* @return
|
||||
*/
|
||||
List<UserGroupVO> listUserGroup(String enterpriseId, String groupName, CurrentUser user);
|
||||
|
||||
UserGroupVO getGroupInfo(String enterpriseId, String groupId, CurrentUser user);
|
||||
|
||||
PageInfo<EnterpriseUserPageVO> listUserByGroupId(String enterpriseId, String groupId, String userName, Integer pageNum, Integer pageSize, CurrentUser currentUser);
|
||||
|
||||
void updateUserGroup(String enterpriseId, List<String> groupIdList, String userId, CurrentUser currentUser);
|
||||
|
||||
Boolean configUser(String enterpriseId, UserGroupAddRequest userGroupAddRequest, CurrentUser user);
|
||||
|
||||
Map<String, List<UserGroupDTO>> getUserGroupMap(String enterpriseId, List<String> userIdList);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.dto.buser.SubordinateUserRangeDTO;
|
||||
import com.cool.store.dto.enterprise.EnterpriseUserDTO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.request.EnterpriseUserRequest;
|
||||
import com.cool.store.vo.buser.EnterpriseUserPageVO;
|
||||
@@ -17,15 +15,13 @@ import java.util.Map;
|
||||
*/
|
||||
public interface EnterpriseUserService {
|
||||
|
||||
void updateUserRegionPathList(String enterpriseId, List<String> userIds);
|
||||
void updateUserRegionPathList(List<String> userIds);
|
||||
|
||||
List<EnterpriseUserPageVO> listUser(String enterpriseId, String userName, String deptId,
|
||||
List<EnterpriseUserPageVO> listUser(String userName, String deptId,
|
||||
String orderBy, String orderRule,
|
||||
Long roleId, Integer userStatus, Integer pageNum, Integer pageSize, String jobNumber, String regionId, Boolean hasPage);
|
||||
|
||||
List<String> initUserRole(String enterpriseId, List<EnterpriseUserPageVO> enterpriseUserList);
|
||||
|
||||
Map<String, SubordinateUserRangeDTO> fillUserSubordinateNames(String enterpriseId, List<String> userIdList);
|
||||
List<String> initUserRole(List<EnterpriseUserPageVO> enterpriseUserList);
|
||||
|
||||
/**
|
||||
* 获取人员所属部门
|
||||
@@ -33,7 +29,7 @@ public interface EnterpriseUserService {
|
||||
* @param userIdList
|
||||
* @return
|
||||
*/
|
||||
Map<String, String> getUserRegion(String enterpriseId, List<String> userIdList);
|
||||
Map<String, String> getUserRegion(List<String> userIdList);
|
||||
|
||||
/**
|
||||
* 更新用户的部门全路径
|
||||
@@ -42,6 +38,6 @@ public interface EnterpriseUserService {
|
||||
*/
|
||||
void updateUserDeptPath(EnterpriseUserRequest user, Map<String, String> deptIdMap);
|
||||
|
||||
EnterpriseUserDO selectByUserIdIgnoreActive(String enterpriseId, String userId);
|
||||
EnterpriseUserDO selectByUserIdIgnoreActive(String userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -12,10 +12,8 @@ import java.util.List;
|
||||
*/
|
||||
public interface RegionService {
|
||||
|
||||
void saveRegionAndStore(String eid, RegionDO regionDO, String userId);
|
||||
void saveRegionAndStore(RegionDO regionDO, String userId);
|
||||
|
||||
void removeRegions(String eid, List<Long> regionIds);
|
||||
|
||||
void deleteByStoreIds(String enterpriseId, List<String> storeIds, String userId);
|
||||
void removeRegions(List<Long> regionIds);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SubordinateMappingService {
|
||||
|
||||
|
||||
/**
|
||||
* 判断用户是否管辖全部用户
|
||||
* @param enterpriseId
|
||||
* @param currentUserId
|
||||
* @return
|
||||
*/
|
||||
Boolean checkHaveAllSubordinateUser(String enterpriseId, String currentUserId);
|
||||
|
||||
/**
|
||||
* 获取管辖用户
|
||||
* @param enterpriseId
|
||||
* @param currentUserId
|
||||
* @return
|
||||
*/
|
||||
List<String> getSubordinateUserIdList(String enterpriseId, String currentUserId,Boolean addCurrentFlag);
|
||||
|
||||
/**
|
||||
* 保留管辖用户
|
||||
* @param enterpriseId
|
||||
* @param currentUserId
|
||||
* @param userIdList
|
||||
* @return
|
||||
*/
|
||||
List<String> retainSubordinateUserIdList(String enterpriseId, String currentUserId, List<String> userIdList,Boolean addCurrentFlag);
|
||||
|
||||
}
|
||||
@@ -1,365 +0,0 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.cool.store.dao.*;
|
||||
import com.cool.store.dto.auth.AuthRegionStoreDTO;
|
||||
import com.cool.store.dto.auth.AuthRegionStoreUserDTO;
|
||||
import com.cool.store.dto.auth.AuthStoreCountDTO;
|
||||
import com.cool.store.dto.buser.UserRoleDTO;
|
||||
import com.cool.store.dto.store.StoreAreaDTO;
|
||||
import com.cool.store.entity.RegionDO;
|
||||
import com.cool.store.entity.StoreDO;
|
||||
import com.cool.store.entity.UserAuthMappingDO;
|
||||
import com.cool.store.enums.*;
|
||||
import com.cool.store.service.AuthVisualService;
|
||||
import com.cool.store.utils.CommonNodeUtils;
|
||||
import com.cool.store.utils.RedisConstantUtil;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* describe:
|
||||
*
|
||||
* @author zhouyiping
|
||||
* @date 2020/10/14
|
||||
*/
|
||||
@Service
|
||||
public class AuthVisualServiceImpl implements AuthVisualService {
|
||||
|
||||
@Resource
|
||||
private UserAuthMappingDAO userAuthMappingDAO;
|
||||
@Resource
|
||||
private RegionDAO regionDAO;
|
||||
@Autowired
|
||||
private RedisUtilPool redisUtilPool;
|
||||
@Autowired
|
||||
private EnterpriseUserRoleDAO enterpriseUserRoleDAO;
|
||||
@Resource
|
||||
private UserRegionMappingDAO userRegionMappingDAO;
|
||||
@Resource
|
||||
private RedisConstantUtil redisConstantUtil;
|
||||
@Resource
|
||||
private StoreDAO storeDAO;
|
||||
|
||||
|
||||
@Override
|
||||
public List<AuthRegionStoreUserDTO> authRegionStore(String eid, String userId) {
|
||||
|
||||
List<UserAuthMappingDO> userAuthMappingList = userAuthMappingDAO.listUserAuthMappingByUserId(eid, userId);
|
||||
return getAuthRegionStoreUserDTO(eid, userAuthMappingList);
|
||||
}
|
||||
|
||||
public List<AuthRegionStoreUserDTO> getAuthRegionStoreUserDTO(String eid, List<UserAuthMappingDO> userAuthMappingList) {
|
||||
List<AuthRegionStoreUserDTO> authRegionStoreDTOList = new ArrayList<>();
|
||||
Pair<List<String>, List<String>> listListTwoResultTuple = splitUserAuthMapping(userAuthMappingList);
|
||||
List<String> storeIdList = listListTwoResultTuple.getKey();
|
||||
List<String> regionIdList = listListTwoResultTuple.getValue();
|
||||
//将组织架构权限中的区域转换
|
||||
if (CollectionUtils.isNotEmpty(regionIdList)) {
|
||||
List<RegionDO> regionByRegionIds = regionDAO.getRegionByRegionIds(eid, regionIdList);
|
||||
List<AuthRegionStoreUserDTO> regionAuthRegionStoreList = ListUtils.emptyIfNull(regionByRegionIds).stream()
|
||||
.map(data -> mapAuthRegionStoreByRegion(data.getName(), data.getRegionId(), false, data.getStoreId()))
|
||||
.collect(Collectors.toList());
|
||||
List<String> regionStoreIdList = ListUtils.emptyIfNull(regionByRegionIds).stream()
|
||||
.filter(e -> StringUtils.isNotBlank(e.getStoreId()) && RegionTypeEnum.STORE.getType().equals(e.getRegionType()))
|
||||
.map(RegionDO::getStoreId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(regionAuthRegionStoreList)) {
|
||||
authRegionStoreDTOList.addAll(regionAuthRegionStoreList);
|
||||
}
|
||||
// 是否需要展示区域对应门店权限数据
|
||||
if (storeIdList != null && CollectionUtils.isNotEmpty(regionStoreIdList)
|
||||
&& StringUtils.isNotBlank(redisUtilPool.getString(redisConstantUtil.getShowStoreAuthKey()))) {
|
||||
storeIdList.addAll(regionStoreIdList);
|
||||
}
|
||||
}
|
||||
//将组织架构权限中的门店转换
|
||||
if (CollectionUtils.isNotEmpty(storeIdList) && StringUtils.isNotBlank(redisUtilPool.getString(redisConstantUtil.getShowStoreAuthKey()))) {
|
||||
List<StoreDO> storeListByStoreIds = storeDAO.getStoreListByStoreIds(eid, storeIdList);
|
||||
List<AuthRegionStoreUserDTO> storeAuthRegionStoreList = ListUtils.emptyIfNull(storeListByStoreIds).stream()
|
||||
.map(data -> mapAuthRegionStoreByRegion(data.getStoreName(), data.getStoreId(), true, data.getStoreId()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(storeAuthRegionStoreList)) {
|
||||
authRegionStoreDTOList.addAll(storeAuthRegionStoreList);
|
||||
}
|
||||
}
|
||||
return authRegionStoreDTOList;
|
||||
}
|
||||
|
||||
public Pair<List<String>, List<String>> splitUserAuthMapping(List<UserAuthMappingDO> userAuthMappingList) {
|
||||
|
||||
List<UserAuthMappingDO> store = new ArrayList<>();
|
||||
List<UserAuthMappingDO> region = new ArrayList<>();
|
||||
ListUtils.emptyIfNull(userAuthMappingList)
|
||||
.forEach(data -> {
|
||||
if (data.getType().equals(UserAuthMappingTypeEnum.STORE.getCode())) {
|
||||
store.add(data);
|
||||
} else {
|
||||
region.add(data);
|
||||
}
|
||||
});
|
||||
List<String> storeIdList = ListUtils.emptyIfNull(store).stream()
|
||||
.map(UserAuthMappingDO::getMappingId).distinct().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
List<String> regionIdList = ListUtils.emptyIfNull(region).stream()
|
||||
.map(UserAuthMappingDO::getMappingId).distinct().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
return new Pair(storeIdList, regionIdList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AuthRegionStoreDTO> authRegionStoreByUserList(String eid, List<String> userIdList) {
|
||||
|
||||
List<UserAuthMappingDO> userAuthMappingList = userAuthMappingDAO.listUserAuthMappingByUserIds(eid, userIdList);
|
||||
List<AuthRegionStoreUserDTO> authRegionStoreUserDTO = getAuthRegionStoreUserDTO(eid, userAuthMappingList);
|
||||
Map<String, AuthRegionStoreUserDTO> regionStoreUserMap = ListUtils.emptyIfNull(authRegionStoreUserDTO)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(AuthRegionStoreUserDTO::getId, data -> data, (a, b) -> a));
|
||||
Map<String, List<UserAuthMappingDO>> userAuthGroup = ListUtils.emptyIfNull(userAuthMappingList)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(UserAuthMappingDO::getUserId));
|
||||
return userIdList.stream()
|
||||
.map(data -> mapAuthRegionStoreDTO(regionStoreUserMap, userAuthGroup, data))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AuthStoreCountDTO> authStoreCount(String eid, List<String> userIdList, Boolean isReturnList) {
|
||||
/**
|
||||
* 1.查询出所有关于用户的权限门店
|
||||
* 1.权限区域角色权限
|
||||
* 2.权限门店
|
||||
* 2.分组聚合
|
||||
* 3.去重统计门店数
|
||||
*/
|
||||
//用户配置的区域权限
|
||||
List<UserAuthMappingDO> userAuthMappingDOList = userAuthMappingDAO.listUserAuthMappingByUserIds(eid, userIdList);
|
||||
|
||||
List<String> allAuthRegionList = ListUtils.emptyIfNull(userAuthMappingDOList)
|
||||
.stream()
|
||||
.filter(data -> StringUtils.equals(UserAuthMappingTypeEnum.REGION.getCode(), data.getType()))
|
||||
.map(UserAuthMappingDO::getMappingId)
|
||||
.distinct()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<StoreAreaDTO> storeAreaDTOS = storeDAO.listStoreByRegionIdList(eid, allAuthRegionList);
|
||||
Map<String, List<String>> storeAreaMap = ListUtils.emptyIfNull(storeAreaDTOS)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(StoreAreaDTO::getAreaId,
|
||||
Collectors.mapping(StoreAreaDTO::getStoreId, Collectors.toList())));
|
||||
Map<String, List<UserAuthMappingDO>> authMappingMap = ListUtils.emptyIfNull(userAuthMappingDOList)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(UserAuthMappingDO::getUserId));
|
||||
//用户角色可视化范围
|
||||
List<UserRoleDTO> userRoleList = enterpriseUserRoleDAO.getUserAndRolesByUserId(eid, userIdList);
|
||||
//取优先级最大角色去查询权限
|
||||
//todo role
|
||||
Map<String, UserRoleDTO> userRoleMap = ListUtils.emptyIfNull(userRoleList)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(UserRoleDTO::getUserId, data -> data, (a, b) -> {
|
||||
if (a.getPriority() == null || b.getPriority() == null) {
|
||||
return a;
|
||||
}
|
||||
return a.getPriority() > b.getPriority() ? b : a;
|
||||
}));
|
||||
List<UserRoleDTO> minUserRoleList = new ArrayList<UserRoleDTO>(userRoleMap.values());
|
||||
List<String> allStoreList = storeDAO.getAllStoreList(eid, isReturnList);
|
||||
Integer allStoreCount = storeDAO.getStoreCount(eid);
|
||||
|
||||
//子区域计算
|
||||
List<Long> all = null;
|
||||
Map<Long, List<Long>> regionParentGroupMap = null;
|
||||
Map<String, String> regionIdStoreIdMap = null;
|
||||
if (CollectionUtils.isNotEmpty(allAuthRegionList)) {
|
||||
List<RegionDO> allRegion = regionDAO.getAllRegion(eid);
|
||||
ListUtils.emptyIfNull(allRegion).forEach(this::initRoot);
|
||||
all = ListUtils.emptyIfNull(allRegion)
|
||||
.stream()
|
||||
.map(RegionDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
regionParentGroupMap = ListUtils.emptyIfNull(allRegion)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(data -> Long.valueOf(data.getParentId()),
|
||||
Collectors.mapping(RegionDO::getId, Collectors.toList())));
|
||||
|
||||
List<Long> storeRegionIdList = allAuthRegionList.stream()
|
||||
.map(e -> Long.valueOf(e)).collect(Collectors.toList());
|
||||
List<RegionDO> storeRegionList = regionDAO.listStoreRegionByIds(eid, storeRegionIdList);
|
||||
regionIdStoreIdMap = ListUtils.emptyIfNull(storeRegionList).stream()
|
||||
.filter(e -> StringUtils.isNotBlank(e.getStoreId()) && !e.getDeleted() && RegionTypeEnum.STORE.getType().equals(e.getRegionType()))
|
||||
.collect(Collectors.toMap(data->String.valueOf(data.getId()), RegionDO::getStoreId, (a, b) -> a));
|
||||
}
|
||||
|
||||
List<Long> finalAll = all;
|
||||
Map<Long, List<Long>> finalRegionParentGroupMap = regionParentGroupMap;
|
||||
Map<String, String> finalRegionIdStoreIdMap = regionIdStoreIdMap;
|
||||
return ListUtils.emptyIfNull(minUserRoleList).stream()
|
||||
.map(data -> mapAuStoreCountDTO(data, authMappingMap, storeAreaMap, allStoreList, allStoreCount, finalAll, finalRegionParentGroupMap, finalRegionIdStoreIdMap))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private AuthRegionStoreDTO mapAuthRegionStoreDTO(Map<String, AuthRegionStoreUserDTO> regionStoreUserMap, Map<String, List<UserAuthMappingDO>> userAuthGroup, String data) {
|
||||
if (MapUtils.isNotEmpty(userAuthGroup) && CollectionUtils.isNotEmpty(userAuthGroup.get(data)) && MapUtils.isNotEmpty(regionStoreUserMap)) {
|
||||
List<AuthRegionStoreUserDTO> authRegionStoreUserDTOList = ListUtils.emptyIfNull(userAuthGroup.get(data))
|
||||
.stream()
|
||||
.map(userAuthMappingDO -> regionStoreUserMap.get(userAuthMappingDO.getMappingId()))
|
||||
.distinct()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
AuthRegionStoreDTO authRegionStoreDTO = new AuthRegionStoreDTO();
|
||||
authRegionStoreDTO.setUserId(data);
|
||||
authRegionStoreDTO.setAuthRegionStoreUserList(authRegionStoreUserDTOList);
|
||||
return authRegionStoreDTO;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void initRoot(RegionDO regionDO) {
|
||||
if (regionDO.getParentId() == null) {
|
||||
regionDO.setParentId("0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取区域下的门店(不包含子节点)
|
||||
* @param storeIdList
|
||||
* @param areaStoreList
|
||||
* @return
|
||||
*/
|
||||
private List<String> authStoreId(List<String> storeIdList,
|
||||
List<String> areaStoreList) {
|
||||
|
||||
List<String> allStoreIdList = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(storeIdList)) {
|
||||
allStoreIdList.addAll(storeIdList);
|
||||
}
|
||||
//聚合区域下的门店信息
|
||||
|
||||
if (CollectionUtils.isNotEmpty(areaStoreList)) {
|
||||
allStoreIdList.addAll(areaStoreList);
|
||||
}
|
||||
|
||||
|
||||
//去除重复的StoreId
|
||||
return ListUtils.emptyIfNull(allStoreIdList).stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private AuthStoreCountDTO mapAuStoreCountDTO(UserRoleDTO userRoleDTO,
|
||||
Map<String, List<UserAuthMappingDO>> authMappingMap,
|
||||
Map<String, List<String>> storeAreaMap,
|
||||
List<String> invalidStores,
|
||||
Integer allStoreCount,
|
||||
List<Long> all,
|
||||
Map<Long, List<Long>> regionParentGroupMap, Map<String, String> regionIdStoreIdMap) {
|
||||
AuthStoreCountDTO authStoreCountDTO = new AuthStoreCountDTO();
|
||||
if (userRoleDTO == null || userRoleDTO.getRoleAuth() == null) {
|
||||
return authStoreCountDTO;
|
||||
}
|
||||
String userId = userRoleDTO.getUserId();
|
||||
authStoreCountDTO.setUserId(userId);
|
||||
//全企业数据或者管理员 直接返回企业下所有的门店总数
|
||||
if (StringUtils.equals(userRoleDTO.getRoleEnum(), (RoleEnum.MASTER.getRoleEnum()))) {
|
||||
authStoreCountDTO.setStoreList(invalidStores);
|
||||
authStoreCountDTO.setStoreCount(allStoreCount);
|
||||
return authStoreCountDTO;
|
||||
}
|
||||
List<String> storeIdList = new ArrayList<>();
|
||||
List<String> regionIdList = new ArrayList<>();
|
||||
List<String> areaStoreList;
|
||||
|
||||
if (MapUtils.isNotEmpty(authMappingMap)) {
|
||||
List<UserAuthMappingDO> userAuthMappingDOList = authMappingMap.get(userId);
|
||||
Pair<List<String>, List<String>> listListTwoResultTuple = splitUserAuthMapping(userAuthMappingDOList);
|
||||
storeIdList = listListTwoResultTuple.getKey();
|
||||
regionIdList = listListTwoResultTuple.getValue();
|
||||
if(CollectionUtils.isNotEmpty(regionIdList) && regionIdStoreIdMap != null){
|
||||
List<String> finalStoreIdList = storeIdList;
|
||||
regionIdList.forEach(regionId -> {
|
||||
String regionStoreId = regionIdStoreIdMap.get(regionId);
|
||||
if (StringUtils.isNotBlank(regionStoreId)) {
|
||||
finalStoreIdList.add(regionStoreId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
switch (AuthRoleEnum.getByCode(userRoleDTO.getRoleAuth())) {
|
||||
case ALL:
|
||||
authStoreCountDTO.setStoreList(invalidStores);
|
||||
authStoreCountDTO.setStoreCount(allStoreCount);
|
||||
break;
|
||||
case INCLUDE_SUBORDINATE:
|
||||
|
||||
areaStoreList = ListUtils.emptyIfNull(regionIdList)
|
||||
.stream()
|
||||
.map(data -> CommonNodeUtils.getAllChildListContainSelf(0L,
|
||||
Long.valueOf(data), all, regionParentGroupMap))
|
||||
.flatMap(Collection::stream)
|
||||
.map(data -> data.toString())
|
||||
.map(data -> {
|
||||
if (MapUtils.isNotEmpty(storeAreaMap)) {
|
||||
return storeAreaMap.get(data);
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
List<String> includeSubordinateStoreIdList = authStoreId(storeIdList, areaStoreList);
|
||||
if (CollectionUtils.isNotEmpty(includeSubordinateStoreIdList)) {
|
||||
authStoreCountDTO.setStoreList(includeSubordinateStoreIdList);
|
||||
authStoreCountDTO.setStoreCount(ListUtils.emptyIfNull(includeSubordinateStoreIdList).size());
|
||||
|
||||
}
|
||||
break;
|
||||
case PERSONAL:
|
||||
areaStoreList = ListUtils.emptyIfNull(regionIdList)
|
||||
.stream()
|
||||
.map(data -> CommonNodeUtils.getAllChildListContainSelf(0L,
|
||||
Long.valueOf(data), all, regionParentGroupMap))
|
||||
.flatMap(Collection::stream)
|
||||
.map(data -> data.toString())
|
||||
.map(data -> {
|
||||
if (MapUtils.isNotEmpty(storeAreaMap)) {
|
||||
return storeAreaMap.get(data);
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
List<String> personalStoreIdList = authStoreId(storeIdList, areaStoreList);
|
||||
if (CollectionUtils.isNotEmpty(personalStoreIdList)) {
|
||||
authStoreCountDTO.setStoreList(personalStoreIdList);
|
||||
authStoreCountDTO.setStoreCount(ListUtils.emptyIfNull(personalStoreIdList).size());
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return authStoreCountDTO;
|
||||
}
|
||||
|
||||
private AuthRegionStoreUserDTO mapAuthRegionStoreByRegion(String name, String regionId, boolean b, String storeId) {
|
||||
AuthRegionStoreUserDTO authRegionStoreDTO = new AuthRegionStoreUserDTO();
|
||||
authRegionStoreDTO.setName(name);
|
||||
authRegionStoreDTO.setId(regionId);
|
||||
authRegionStoreDTO.setStoreFlag(b);
|
||||
authRegionStoreDTO.setStoreId(storeId);
|
||||
return authRegionStoreDTO;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,9 @@ public class EnterpriseConfigServiceImpl implements EnterpriseConfigService {
|
||||
private EnterpriseConfigDAO enterpriseConfigDAO;
|
||||
|
||||
@Override
|
||||
public EnterpriseConfigDO selectByEnterpriseId(String enterpriseId) {
|
||||
return enterpriseConfigDAO.selectByEnterpriseId(enterpriseId);
|
||||
public EnterpriseConfigDO selectByEnterpriseId() {
|
||||
//return enterpriseConfigDAO.selectByEnterpriseId(enterpriseId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,16 +72,8 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
@Resource
|
||||
private RedisConstantUtil redisConstantUtil;
|
||||
@Resource
|
||||
private StoreDAO storeDAO;
|
||||
@Resource
|
||||
private RedisUtilPool redisUtilPool;
|
||||
@Resource
|
||||
private UserAuthMappingDAO userAuthMappingDAO;
|
||||
@Resource
|
||||
private EnterpriseUserDepartmentDAO enterpriseUserDepartmentDAO;
|
||||
@Resource
|
||||
private SubordinateMappingDAO subordinateMappingDAO;
|
||||
@Resource
|
||||
private EnterpriseDAO enterpriseDAO;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@@ -89,105 +81,36 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
private RegionService regionService;
|
||||
|
||||
@Override
|
||||
public void runEnterpriseScript(EnterpriseOpenMsg msg) {
|
||||
runEnterpriseScriptAndInitAuthUser(msg);
|
||||
//抛出开始数据同步消息
|
||||
EnterpriseInitDTO enterpriseInitDTO = new EnterpriseInitDTO();
|
||||
enterpriseInitDTO.setEid(msg.getEid());
|
||||
enterpriseInitDTO.setAppType(msg.getAppType());
|
||||
enterpriseInitDTO.setCorpId(msg.getCorpId());
|
||||
enterpriseInitDTO.setDbName(msg.getDbName());
|
||||
enterpriseInitDTO.setUserId(msg.getAuthUserId());
|
||||
log.info("send msg to enterprise_open_data_sync, eid:{}, appType:{}, corpId:{}, dbName:{}", msg.getEid(), msg.getAppType(), msg.getCorpId(), msg.getDbName(), msg.getAuthUserId());
|
||||
simpleMessageService.send(JSONObject.toJSONString(enterpriseInitDTO), RocketMqTagEnum.ENTERPRISE_OPEN_DATA_SYNC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterpriseInit(String corpId, AppTypeEnum appTypeEnum, String eid, String dbName, String openUserId) {
|
||||
try {
|
||||
String appType = appTypeEnum.getValue();
|
||||
//优先处理ai用户 保证能够超登
|
||||
List<EnterpriseUserRequest> authUsers = new ArrayList<>();
|
||||
List<String> adminUserList = isvHttpRequest.getAdminUserList(corpId, appType);
|
||||
//添加ai用户
|
||||
authUsers.add(getAIUser());
|
||||
authUsers.addAll(getAdminList(adminUserList));
|
||||
DataSourceHelper.changeToSpecificDataSource(dbName);
|
||||
//获取开通授权信息
|
||||
AuthInfoDTO authInfo = isvHttpRequest.getAuthInfo(corpId, appType);
|
||||
//记录此次处理的用户的id,
|
||||
Set<String> handlerUserIds = new HashSet<>();
|
||||
//处理ai用户
|
||||
dealUsers(authUsers, eid, corpId, dbName, new HashMap<>(), null, authInfo, handlerUserIds);
|
||||
//初始化部门
|
||||
List<SysDepartmentDTO> sysDepartmentDTOS = initDept(corpId, eid, appType, dbName);
|
||||
if(CollectionUtils.isEmpty(sysDepartmentDTOS)){
|
||||
//构建跟部门
|
||||
SysDepartmentDTO root = new SysDepartmentDTO();
|
||||
root.setId(CommonConstants.ROOT_DEPT_ID_STR);
|
||||
root.setName(authInfo.getAuthCorpInfo().getCorpName());
|
||||
sysDepartmentDTOS.add(root);
|
||||
}
|
||||
//初始化根区域
|
||||
initRootRegion(sysDepartmentDTOS, eid, dbName);
|
||||
//初始化用户
|
||||
initUser(sysDepartmentDTOS,corpId,eid,appType,dbName, adminUserList, authInfo, handlerUserIds);
|
||||
} catch (Exception e) {
|
||||
log.error("enterpriseInit enterpriseInit error,corpId:{},appType:{}", corpId, appTypeEnum.getValue(), e);
|
||||
throw new ServiceException(ErrorCodeEnum.FEISHU_SERVICE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void sendOpenSucceededMsg(String corpId, String appType, List<String> userList) {
|
||||
if(CollectionUtils.isEmpty(userList)){
|
||||
return;
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("userList", userList);
|
||||
jsonObject.put("appType", appType);
|
||||
jsonObject.put("corpId", corpId);
|
||||
simpleMessageService.send(jsonObject.toJSONString(), RocketMqTagEnum.OPEN_SUCCEEDED_MSG_QUEUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync(String eid, String userName, String userId, Long regionId) {
|
||||
public void sync(String userName, String userId, Long regionId) {
|
||||
DataSourceHelper.reset();
|
||||
EnterpriseConfigDO enterpriseConfigDO = enterpriseConfigDAO.selectByEnterpriseId(eid);
|
||||
EnterpriseConfigDO enterpriseConfigDO = enterpriseConfigDAO.selectByEnterpriseId();
|
||||
try {
|
||||
DataSourceHelper.changeToSpecificDataSource(enterpriseConfigDO.getDbName());
|
||||
newSyncFsDept(eid, regionId);
|
||||
newSyncFsDept(regionId);
|
||||
//如果没有开通钉钉同步,需要先同步部门,人员同步根据部门同步
|
||||
syncSpecifyNodeUser(eid,regionId, true);
|
||||
syncSpecifyNodeUser(regionId, true);
|
||||
}catch (Exception e){
|
||||
//无论是否失败,删除节点同步信息锁
|
||||
redisUtilPool.delKey(redisConstantUtil.getSyncLockKey(eid));
|
||||
//任务无论完成失败,都删除区域和门店缓存
|
||||
String regionKey = redisConstantUtil.getSyncRegionKey(eid);
|
||||
String storeKey = redisConstantUtil.getSyncStoreKey(eid);
|
||||
redisUtilPool.delKey(regionKey);
|
||||
redisUtilPool.delKey(storeKey);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void syncSpecifyNodeUser(String eid,Long regionId, Boolean isSyncRoleAndAuth) {
|
||||
log.info("开始同步用户eid:{}", eid);
|
||||
public void syncSpecifyNodeUser(Long regionId, Boolean isSyncRoleAndAuth) {
|
||||
log.info("开始同步用户eid:{}");
|
||||
//前置准备:获得企业配置信息、数据库名等
|
||||
DataSourceHelper.reset();
|
||||
EnterpriseConfigDO config = enterpriseConfigDAO.selectByEnterpriseId(eid);
|
||||
EnterpriseConfigDO config = enterpriseConfigDAO.selectByEnterpriseId();
|
||||
String corpId = config.getDingCorpId();
|
||||
String dbName = config.getDbName();
|
||||
//这次同步的用户id
|
||||
Set<String> dingUserIdList = new HashSet<>();
|
||||
//切换企业库
|
||||
DataSourceHelper.changeToSpecificDataSource(dbName);
|
||||
RegionDO regionDO = regionDAO.getByRegionId(eid, regionId);
|
||||
RegionDO regionDO = regionDAO.getByRegionId(regionId);
|
||||
|
||||
List<SyncTreeNode> deptList = new ArrayList<>();
|
||||
//遍历部门列表以及对应的用户列表 regionDO为null的时候遍历所有的用户
|
||||
if (regionId==null||regionDO==null){
|
||||
deptList = sysDepartmentDAO.getSyncDeptTreeList(eid);
|
||||
deptList = sysDepartmentDAO.getSyncDeptTreeList();
|
||||
}else {
|
||||
//查询指定部门的子部门(包括当前部门)
|
||||
String synDingDeptId = regionDO.getSynDingDeptId();
|
||||
@@ -211,7 +134,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
|
||||
List<String> deptIds = deptList.stream().map(SyncTreeNode::getId).collect(Collectors.toList());
|
||||
for (String deptId : deptIds) {
|
||||
syncFsDeptUser(corpId, eid, dbName, dingUserIdList, deptId, config.getAppType());
|
||||
syncFsDeptUser(corpId, dbName, dingUserIdList, deptId, config.getAppType());
|
||||
}
|
||||
log.info("dingUserIdList:{}",JSONObject.toJSONString(dingUserIdList));
|
||||
|
||||
@@ -220,9 +143,9 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
//删除门店库中和钉钉对应的用户、剩下的为待删除用户
|
||||
List<String> coolUserIdList = new ArrayList<>();
|
||||
if (regionId!=null){
|
||||
coolUserIdList = enterpriseUserDAO.selectSpecifyNodeUserIds(eid, regionDO.getSynDingDeptId());
|
||||
coolUserIdList = enterpriseUserDAO.selectSpecifyNodeUserIds(regionDO.getSynDingDeptId());
|
||||
}else {
|
||||
coolUserIdList = enterpriseUserDAO.selectAllUserId(eid);
|
||||
coolUserIdList = enterpriseUserDAO.selectAllUserId();
|
||||
}
|
||||
List<String> finalCoolUserIdList = coolUserIdList;
|
||||
dingUserIdList.forEach(dingUserId -> {
|
||||
@@ -231,63 +154,47 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
}
|
||||
});
|
||||
|
||||
List<String> mainAdminIds = enterpriseUserDAO.getMainAdminUserIds(eid);
|
||||
List<String> mainAdminIds = enterpriseUserDAO.getMainAdminUserIds();
|
||||
//如果是节点同步,不执行人员删除操作
|
||||
if(regionId!=null){
|
||||
log.info("节点用户同步完成eid:{},regionId={}", eid,regionId);
|
||||
log.info("节点用户同步完成eid:{},regionId={}",regionId);
|
||||
return;
|
||||
}
|
||||
for (String coolUserId : coolUserIdList) {
|
||||
try {
|
||||
//不能删除AI用户和主管理员
|
||||
if (!CommonConstants.AI_USER_ID.equals(coolUserId) && !mainAdminIds.contains(coolUserId)) {
|
||||
syncDeleteUser(eid, coolUserId, dbName);
|
||||
syncDeleteUser(coolUserId, dbName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("fullSyncUser corpId={}", e, corpId);
|
||||
}
|
||||
}
|
||||
log.info("同步用户完成eid:{}", eid);
|
||||
log.info("同步用户完成eid:{}");
|
||||
}
|
||||
|
||||
public void syncDeleteUser(String eid, String userId, String dbName) {
|
||||
public void syncDeleteUser(String userId, String dbName) {
|
||||
//删除企业库对应的映射关系
|
||||
DataSourceHelper.changeToSpecificDataSource(dbName);
|
||||
// 1.更新用户信息
|
||||
EnterpriseUserDO enterpriseUser = enterpriseUserDAO.getUserInfoById(eid, userId);
|
||||
EnterpriseUserDO enterpriseUser = enterpriseUserDAO.getUserInfoById(userId);
|
||||
if (enterpriseUser != null) {
|
||||
enterpriseUser.setActive(false);
|
||||
enterpriseUserDAO.updateEnterpriseUser(eid, enterpriseUser);
|
||||
enterpriseUserDAO.updateEnterpriseUser(enterpriseUser);
|
||||
}
|
||||
// 2.删除用户角色映射关系
|
||||
//获得用户在cool中的角色列表
|
||||
List<Long> userRoleIds = enterpriseUserRoleDAO.selectIdsByUserId(eid, userId);
|
||||
// 3.删除该用户的部门信息
|
||||
List<Integer> userDepartmentIds = enterpriseUserDepartmentDAO.getIdsByUserId(eid, userId);
|
||||
List<Long> userRoleIds = enterpriseUserRoleDAO.selectIdsByUserId(userId);
|
||||
//删除用户和区域的关联关系
|
||||
userRegionMappingDAO.deletedByUserIds(eid, Arrays.asList(userId));
|
||||
//删除用户的下属
|
||||
subordinateMappingDAO.deletedByUserIds(eid, Arrays.asList(userId));
|
||||
// 4.删除该用户的可见范围映射信息
|
||||
List<Long> userAuthIds = userAuthMappingDAO.selectIdsByUserId(eid, userId);
|
||||
userRegionMappingDAO.deletedByUserIds(Arrays.asList(userId));
|
||||
if (userRoleIds != null) {
|
||||
Lists.partition(userRoleIds, CommonConstants.DEAL_RECORD_MAX_SIZE).forEach(deleteUserRoleIds -> {
|
||||
enterpriseUserRoleDAO.deleteBatchByPrimaryKey(eid, deleteUserRoleIds);
|
||||
});
|
||||
}
|
||||
if (userDepartmentIds != null) {
|
||||
Lists.partition(userDepartmentIds, CommonConstants.DEAL_RECORD_MAX_SIZE).forEach(userDeptDeleteList -> {
|
||||
enterpriseUserDepartmentDAO.deleteByIdList(eid, userDeptDeleteList);
|
||||
});
|
||||
}
|
||||
if (userAuthIds != null) {
|
||||
Lists.partition(userAuthIds, CommonConstants.DEAL_RECORD_MAX_SIZE).forEach(deleteUserAuths -> {
|
||||
userAuthMappingDAO.deleteAuthMappingByIds(eid, deleteUserAuths);
|
||||
enterpriseUserRoleDAO.deleteBatchByPrimaryKey(deleteUserRoleIds);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void syncFsDeptUser(String corpId, String eid, String dbName, Set<String> dingUserIdList, String deptId, String appType){
|
||||
private void syncFsDeptUser(String corpId, String dbName, Set<String> dingUserIdList, String deptId, String appType){
|
||||
List<EnterpriseUserRequest> deptUsers =isvHttpRequest.getDeptUsers(corpId, deptId, appType);
|
||||
log.info("获取飞书部门下用户的部门id {} ,返回用户详情列表 {} ", deptId, JSONObject.toJSONString(deptUsers));
|
||||
if (CollectionUtils.isEmpty(deptUsers)){
|
||||
@@ -298,7 +205,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
dingUserIdList.add(deptUser.getEnterpriseUserDO().getUserId());
|
||||
try {
|
||||
String userId = deptUser.getEnterpriseUserDO().getUserId();
|
||||
syncFsUser(corpId, userId, eid, dbName, appType);
|
||||
syncFsUser(corpId, userId, dbName, appType);
|
||||
} catch (Exception e) {
|
||||
log.error("syncFsDeptUser,当前用户同步失败 {} ", deptUser.getEnterpriseUserDO().getUserId(), e);
|
||||
}
|
||||
@@ -306,10 +213,10 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
}
|
||||
}
|
||||
|
||||
public void syncFsUser(String corpId, String userId, String eid, String dbName, String appType) {
|
||||
public void syncFsUser(String corpId, String userId, String dbName, String appType) {
|
||||
//获得企业微信用户详情
|
||||
DataSourceHelper.changeToSpecificDataSource(dbName);
|
||||
Long employeeRoleId = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.EMPLOYEE.getRoleEnum());
|
||||
Long employeeRoleId = sysRoleDAO.getRoleIdByRoleEnum(RoleEnum.EMPLOYEE.getRoleEnum());
|
||||
DataSourceHelper.reset();
|
||||
EnterpriseUserRequest fsEnterpriseUser = getFsUserDetail(corpId, userId, String.valueOf(employeeRoleId), appType);
|
||||
|
||||
@@ -330,9 +237,9 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
//先处理企业库
|
||||
DataSourceHelper.changeToSpecificDataSource(dbName);
|
||||
//设置用户部门全路劲
|
||||
Pair<Set<String>, Map<String, String>> tuple = getAllDeptInfo(eid);
|
||||
Pair<Set<String>, Map<String, String>> tuple = getAllDeptInfo();
|
||||
enterpriseUserService.updateUserDeptPath(fsEnterpriseUser, tuple.getValue());
|
||||
EnterpriseUserDO coolEnterpriseUser = enterpriseUserService.selectByUserIdIgnoreActive(eid, userId);
|
||||
EnterpriseUserDO coolEnterpriseUser = enterpriseUserService.selectByUserIdIgnoreActive(userId);
|
||||
log.info("数智门店企业用户信息 {} ", JSONObject.toJSONString(coolEnterpriseUser));
|
||||
if (coolEnterpriseUser != null) {
|
||||
//设置下级是否变动
|
||||
@@ -342,10 +249,10 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
fsEnterpriseUser.getEnterpriseUserDO().setUserStatus(coolEnterpriseUser.getUserStatus());
|
||||
}
|
||||
}
|
||||
syncEntUser(fsEnterpriseUser, eid, appType);
|
||||
syncEntUser(fsEnterpriseUser, appType);
|
||||
}
|
||||
|
||||
public EnterpriseUserRequest getFsUserDetail(String corpId, String userId, String employeeRoleId, String appType) {
|
||||
public EnterpriseUserRequest getFsUserDetail(String corpId, String userId, String employeeRole, String appType) {
|
||||
EnterpriseUserDTO enterpriseUserDTO = null;
|
||||
try {
|
||||
enterpriseUserDTO = isvHttpRequest.getUserDetailByUserId(corpId, userId, appType);
|
||||
@@ -375,7 +282,6 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
enterpriseUser.setCreateTime(new Date());
|
||||
enterpriseUser.setUnionid(enterpriseUserDTO.getUnionid());
|
||||
enterpriseUser.setIsAdmin(false);
|
||||
enterpriseUser.setRoles(employeeRoleId);
|
||||
enterpriseUser.setRemark(enterpriseUserDTO.getUserId());
|
||||
enterpriseUser.setUserId(enterpriseUserDTO.getUserId());
|
||||
enterpriseUser.setName(enterpriseUserDTO.getName());
|
||||
@@ -386,14 +292,14 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
}
|
||||
|
||||
|
||||
public Pair<Set<String>, Map<String, String>> getAllDeptInfo(String eid) {
|
||||
List<SysDepartmentDO> allDeptList = sysDepartmentDAO.selectAllDepts(eid);
|
||||
public Pair<Set<String>, Map<String, String>> getAllDeptInfo() {
|
||||
List<SysDepartmentDO> allDeptList = sysDepartmentDAO.selectAllDepts();
|
||||
Set<String> deptIdSet = allDeptList.stream().map(SysDepartmentDO::getId).collect(Collectors.toSet());
|
||||
Map<String, String> deptIdMap = allDeptList.stream().filter(d -> d.getParentId() != null).collect(Collectors.toMap(SysDepartmentDO::getId, SysDepartmentDO::getParentId));
|
||||
return new Pair<>(deptIdSet, deptIdMap);
|
||||
}
|
||||
|
||||
public void syncEntUser(EnterpriseUserRequest request, String eid, String appType) {
|
||||
public void syncEntUser(EnterpriseUserRequest request, String appType) {
|
||||
EnterpriseUserDO enterpriseUser = request.getEnterpriseUserDO();
|
||||
if (Objects.isNull(enterpriseUser)) {
|
||||
return;
|
||||
@@ -403,28 +309,25 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
//TODO 一.插入或者更新用户信息
|
||||
if (enterpriseUser.getId() == null) {
|
||||
enterpriseUser.setId(UUIDUtils.get32UUID());
|
||||
enterpriseUserDAO.insertEnterpriseUser(eid, enterpriseUser);
|
||||
enterpriseUserDAO.insertEnterpriseUser(enterpriseUser);
|
||||
} else {
|
||||
enterpriseUserDAO.updateEnterpriseUser(eid, enterpriseUser);
|
||||
enterpriseUserDAO.updateEnterpriseUser(enterpriseUser);
|
||||
}
|
||||
//TODO 二.更新该用户的部门信息
|
||||
//ding部门id列表
|
||||
List<String> fsDeptIds = request.getDepartmentLists();
|
||||
//该用户在cool中的部门列表,该部门id为cool的id。
|
||||
syncUserDepartment(eid, userId, fsDeptIds);
|
||||
//同步用户的部门权限
|
||||
List<String> manageDeptIds = JSONObject.parseArray(request.getEnterpriseUserDO().getIsLeaderInDepts(), String.class);
|
||||
syncUserDepartmentAuth(eid, userId, manageDeptIds);
|
||||
//同步用户和区域的关系
|
||||
syncUserRegionMapping(eid, userId, ListUtils.emptyIfNull(fsDeptIds).stream().map(a -> String.valueOf(a)).collect(Collectors.toList()));
|
||||
syncUserRegionMapping(userId, ListUtils.emptyIfNull(fsDeptIds).stream().map(a -> String.valueOf(a)).collect(Collectors.toList()));
|
||||
//补全该用户的user_region_ids
|
||||
enterpriseUserService.updateUserRegionPathList(eid, Arrays.asList(userId));
|
||||
enterpriseUserService.updateUserRegionPathList(Arrays.asList(userId));
|
||||
//如果用户是企微管理员,同步为门店的管理员
|
||||
if (enterpriseUser.getIsAdmin()) {
|
||||
EnterpriseUserRole masterRole = enterpriseUserRoleDAO.selectByUserIdAndRoleId(eid, enterpriseUser.getUserId(), RoleEnum.MASTER.getId());
|
||||
EnterpriseUserRole masterRole = enterpriseUserRoleDAO.selectByUserIdAndRoleId(enterpriseUser.getUserId(), RoleEnum.MASTER.getId());
|
||||
if (masterRole == null) {
|
||||
Long roleIdByRoleEnum = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.MASTER.getRoleEnum());
|
||||
enterpriseUserRoleDAO.save(eid, new EnterpriseUserRole(roleIdByRoleEnum.toString(), userId));
|
||||
Long roleIdByRoleEnum = sysRoleDAO.getRoleIdByRoleEnum(RoleEnum.MASTER.getRoleEnum());
|
||||
enterpriseUserRoleDAO.save(new EnterpriseUserRole(roleIdByRoleEnum.toString(), userId));
|
||||
}
|
||||
}
|
||||
//TODO 三更新该用户的角色信息:新增或者删除
|
||||
@@ -439,50 +342,20 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
leaderInDept = Arrays.stream(leaderDeptStr.split(",")).map(String::valueOf).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
//自建私服直接去字段
|
||||
if(AppTypeEnum.isWxSelfAndPrivateType(appType) && CollectionUtils.isNotEmpty(request.getLeaderInDepts())){
|
||||
leaderInDept = request.getLeaderInDepts();
|
||||
}
|
||||
|
||||
if (fsDeptIds.size() != leaderInDept.size()) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < fsDeptIds.size(); i++) {
|
||||
leaderMap.put(fsDeptIds.get(i), CommonConstants.ONE_STR.equals(leaderInDept.get(i)));
|
||||
}
|
||||
syncUserAuth(userId, eid, fsDeptIds, enterpriseUser.getPosition(), leaderMap, appType);
|
||||
}
|
||||
|
||||
public void syncUserAuth(String userId, String eid, List<String> deptIds, String position, Map<String, Boolean> leaderMap, String appType) {
|
||||
List<UserAuthMappingDO> dingUserAuthList = getSyncAuthMappingList(leaderMap, position, userId, eid, deptIds, appType);
|
||||
//用户在cool中已有的可视范围映射关系
|
||||
List<UserAuthMappingDO> coolUserAuthList = userAuthMappingDAO.listUserAuthMappingByUserId(eid, userId);
|
||||
Map<String, UserAuthMappingDO> userAuthMap = ListUtils.emptyIfNull(coolUserAuthList)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(UserAuthMappingDO::getMappingId, data -> data, (a, b) -> a));
|
||||
for (UserAuthMappingDO userAuth : dingUserAuthList) {
|
||||
UserAuthMappingDO auth = userAuthMap == null ? null : userAuthMap.get(userAuth.getMappingId());
|
||||
if (auth == null) {
|
||||
userAuthMappingDAO.insertUserAuthMapping(eid, userAuth);
|
||||
} else {
|
||||
coolUserAuthList.remove(auth);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(coolUserAuthList)) {
|
||||
List<Long> deleteAuthIds = coolUserAuthList.stream()
|
||||
.filter(data -> "sync".equals(data.getSource()) )
|
||||
.map(UserAuthMappingDO::getId).collect(Collectors.toList());
|
||||
if(CollectionUtils.isNotEmpty(deleteAuthIds)){
|
||||
userAuthMappingDAO.deleteAuthMappingByIds(eid, deleteAuthIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<UserAuthMappingDO> getSyncAuthMappingList(Map<String, Boolean> map
|
||||
, String position, String userId, String eid, List<String> deptIds, String appType) {
|
||||
, String position, String userId, List<String> deptIds, String appType) {
|
||||
//该用户相关区域 3-25现在用户可视权限不涉及门店,只需要考虑区域,而且区域信息表中会冗余门店的信息,根据区域类型判断是否是门店
|
||||
List<RegionDO> regions = regionDAO.getRegionByDingDeptIds(eid, deptIds);
|
||||
// List<StoreDO> stores = storeMapper.getStoreByDingDeptIds(eid, dingDeptIds); 获得所有的门店类型 2021-5-6 区域表修改,不在冗余门店类型的区域
|
||||
List<RegionDO> regions = regionDAO.getRegionByDingDeptIds(deptIds);
|
||||
// List<StoreDO> stores = storeMapper.getStoreByDingDeptIds(dingDeptIds); 获得所有的门店类型 2021-5-6 区域表修改,不在冗余门店类型的区域
|
||||
//添加人员权限映射表,即用户可见范围
|
||||
List<UserAuthMappingDO> userAuthMappingDOList = new ArrayList<>();
|
||||
//判断是否是自定义区域权限
|
||||
@@ -503,14 +376,14 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
return userAuthMappingDOList;
|
||||
}
|
||||
|
||||
public void syncUserRegionMapping(String eid, String userId, List<String> deptIds) {
|
||||
public void syncUserRegionMapping(String userId, List<String> deptIds) {
|
||||
//现在已经存在的用户和区域的映射关系
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(eid, Arrays.asList(userId));
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(Arrays.asList(userId));
|
||||
Map<String, UserRegionMappingDO> userRegionMap = ListUtils.emptyIfNull(userRegionMappingDOS)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(UserRegionMappingDO::getRegionId, data -> data, (a, b) -> a));
|
||||
//db查询区域表的数据,找到映射的区域
|
||||
List<Long> regionIds = regionDAO.getRegionIdsBySynDingDeptIds(eid, deptIds);
|
||||
List<Long> regionIds = regionDAO.getRegionIdsBySynDingDeptIds(deptIds);
|
||||
if (CollectionUtils.isEmpty(regionIds)) {
|
||||
//没有任何映射的区域放在未分组下
|
||||
regionIds.add(CommonConstants.UNGROUPED_DEPT_ID);
|
||||
@@ -530,7 +403,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
userRegionMappings.add(userRegion);
|
||||
}
|
||||
if (userRegionMappings.size() > CommonConstants.DEAL_RECORD_MAX_SIZE) {
|
||||
userRegionMappingDAO.batchInsertRegionMapping(eid, userRegionMappings);
|
||||
userRegionMappingDAO.batchInsertRegionMapping(userRegionMappings);
|
||||
userRegionMappings.clear();
|
||||
}
|
||||
}
|
||||
@@ -538,7 +411,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
//批量新增
|
||||
if (CollectionUtils.isNotEmpty(userRegionMappings)) {
|
||||
Lists.partition(userRegionMappings, CommonConstants.DEAL_RECORD_MAX_SIZE).forEach(p -> {
|
||||
userRegionMappingDAO.batchInsertRegionMapping(eid, p);
|
||||
userRegionMappingDAO.batchInsertRegionMapping(p);
|
||||
});
|
||||
}
|
||||
//删除用户移除的区域关系
|
||||
@@ -546,81 +419,18 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
List<Integer> deleteUserRegions = userRegionMappingDOS.stream()
|
||||
.map(UserRegionMappingDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
userRegionMappingDAO.deletedByIds(eid, deleteUserRegions);
|
||||
userRegionMappingDAO.deletedByIds(deleteUserRegions);
|
||||
}
|
||||
}
|
||||
|
||||
public void syncUserDepartmentAuth(String eid, String userId, List<String> deptIds) {
|
||||
if (CollectionUtils.isEmpty(deptIds)) {
|
||||
return;
|
||||
}
|
||||
//该用户在cool中的部门列表,该部门id为cool的id。
|
||||
List<EnterpriseUserDepartmentDO> userDepartmentsAuth = enterpriseUserDepartmentDAO.selectUserDeptAuthByUserId(eid, userId);
|
||||
Map<String, EnterpriseUserDepartmentDO> userDeptAuthMap = ListUtils.emptyIfNull(userDepartmentsAuth)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(EnterpriseUserDepartmentDO::getDepartmentId, data -> data, (a, b) -> a));
|
||||
List<EnterpriseUserDepartmentDO> enterpriseUserDepartmentDOS = new ArrayList<>();
|
||||
for (String deptId : deptIds) {
|
||||
EnterpriseUserDepartmentDO userDepartmentDO = userDeptAuthMap.get(deptId);
|
||||
if (Objects.nonNull(userDepartmentDO)) {
|
||||
userDepartmentsAuth.remove(userDepartmentDO);
|
||||
} else {
|
||||
//换成批量新增
|
||||
EnterpriseUserDepartmentDO departmentDO = new EnterpriseUserDepartmentDO(userId, deptId, Boolean.TRUE);
|
||||
enterpriseUserDepartmentDOS.add(departmentDO);
|
||||
}
|
||||
}
|
||||
batchInsertOrDelUserDepartment(enterpriseUserDepartmentDOS, eid, userDepartmentsAuth);
|
||||
}
|
||||
|
||||
public void syncUserDepartment(String eid, String userId, List<String> deptIds) {
|
||||
if (CollectionUtils.isEmpty(deptIds)) {
|
||||
return;
|
||||
}
|
||||
//该用户在cool中的部门列表,该部门id为cool的id。
|
||||
List<EnterpriseUserDepartmentDO> userDepartments = enterpriseUserDepartmentDAO.selectUserDeptByUserId(eid, userId);
|
||||
Map<String, EnterpriseUserDepartmentDO> userDeptMap = ListUtils.emptyIfNull(userDepartments)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(EnterpriseUserDepartmentDO::getDepartmentId, data -> data, (a, b) -> a));
|
||||
List<EnterpriseUserDepartmentDO> dos = new ArrayList<>();
|
||||
deptIds.forEach(deptId -> {
|
||||
EnterpriseUserDepartmentDO userDepartmentDO = userDeptMap.get(deptId);
|
||||
if (Objects.nonNull(userDepartmentDO)) {
|
||||
userDepartments.remove(userDepartmentDO);
|
||||
} else {
|
||||
//换成批量新增
|
||||
EnterpriseUserDepartmentDO departmentDO = new EnterpriseUserDepartmentDO(userId, deptId, Boolean.FALSE);
|
||||
dos.add(departmentDO);
|
||||
}
|
||||
});
|
||||
//批量新增
|
||||
batchInsertOrDelUserDepartment(dos, eid, userDepartments);
|
||||
}
|
||||
|
||||
private void batchInsertOrDelUserDepartment(List<EnterpriseUserDepartmentDO> enterpriseUserDepartmentDOS, String eid,
|
||||
List<EnterpriseUserDepartmentDO> userDepartmentsAuth) {
|
||||
//批量新增
|
||||
if (CollectionUtils.isNotEmpty(enterpriseUserDepartmentDOS)) {
|
||||
Lists.partition(enterpriseUserDepartmentDOS, CommonConstants.DEAL_RECORD_MAX_SIZE).forEach(p -> {
|
||||
enterpriseUserDepartmentDAO.batchInsert(eid, p);
|
||||
});
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(userDepartmentsAuth)) {
|
||||
List<Integer> deleteUserDeptIds = userDepartmentsAuth.stream()
|
||||
.map(EnterpriseUserDepartmentDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
enterpriseUserDepartmentDAO.deleteByIdList(eid, deleteUserDeptIds);
|
||||
}
|
||||
}
|
||||
|
||||
public void newSyncFsDept(String eid, Long regionId){
|
||||
public void newSyncFsDept(Long regionId){
|
||||
DataSourceHelper.reset();
|
||||
EnterpriseConfigDO config = enterpriseConfigDAO.selectByEnterpriseId(eid);
|
||||
EnterpriseDO enterpriseDO = enterpriseDAO.getEnterpriseById(eid);
|
||||
Set<String> deleteDeptIds = syncDept(config.getDingCorpId(), config.getAppType(), eid, config.getDbName());
|
||||
EnterpriseConfigDO config = enterpriseConfigDAO.selectByEnterpriseId();
|
||||
EnterpriseDO enterpriseDO = enterpriseDAO.getEnterpriseById();
|
||||
Set<String> deleteDeptIds = syncDept(config.getDingCorpId(), config.getAppType(), config.getDbName());
|
||||
if (CollectionUtils.isNotEmpty(deleteDeptIds)) {
|
||||
//删除不存在的数据
|
||||
sysDepartmentDAO.deleteByNotInIds(eid, new ArrayList<>(deleteDeptIds));
|
||||
sysDepartmentDAO.deleteByNotInIds(new ArrayList<>(deleteDeptIds));
|
||||
}
|
||||
//先获得这次同步的数据范围 regionId 不为null 指定部门ID
|
||||
List<String> deptIds = new ArrayList<>();
|
||||
@@ -628,7 +438,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
RegionDO regionDO =null;
|
||||
if (regionId!=null){
|
||||
DataSourceHelper.changeToSpecificDataSource(config.getDbName());
|
||||
regionDO = regionDAO.getByRegionId(eid, regionId);
|
||||
regionDO = regionDAO.getByRegionId(regionId);
|
||||
deptIds.add(regionDO.getSynDingDeptId());
|
||||
unitId = regionDO.getSynDingDeptId();
|
||||
}
|
||||
@@ -671,10 +481,10 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
}
|
||||
List<RegionDTO> deptRegionList = transDeptToRegion(departmentList, config.getAppType());
|
||||
regionList.addAll(deptRegionList);
|
||||
newSyncOrgAll(eid,regionId, unitId, regionList);
|
||||
newSyncOrgAll(regionId, unitId, regionList);
|
||||
}
|
||||
|
||||
public void newSyncOrgAll(String eid,Long regionId ,String unitId, List<RegionDTO> resultList) {
|
||||
public void newSyncOrgAll(Long regionId ,String unitId, List<RegionDTO> resultList) {
|
||||
if(CollectionUtils.isEmpty(resultList)){
|
||||
return;
|
||||
}
|
||||
@@ -682,12 +492,10 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
resultList = resultList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
|
||||
new TreeSet<>(Comparator.comparing(RegionDTO::getSynDingDeptId))), ArrayList::new));
|
||||
DataSourceHelper.reset();
|
||||
EnterpriseConfigDO enterpriseConfigDO = enterpriseConfigDAO.selectByEnterpriseId(eid);
|
||||
EnterpriseConfigDO enterpriseConfigDO = enterpriseConfigDAO.selectByEnterpriseId();
|
||||
DataSourceHelper.changeToSpecificDataSource(enterpriseConfigDO.getDbName());
|
||||
|
||||
String userId = "";
|
||||
String regionKey = redisConstantUtil.getSyncRegionKey(eid);
|
||||
String storeKey = redisConstantUtil.getSyncStoreKey(eid);
|
||||
|
||||
Map<String, RegionDTO> mapResult = resultList.stream().collect(Collectors.toMap(RegionDTO::getSynDingDeptId, org -> org));
|
||||
//取的是跟节点或者指定节点
|
||||
@@ -717,7 +525,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
root.setId(regionId);
|
||||
}
|
||||
//构建数据
|
||||
RegionDO rootRegion = prepareRegionRoot(eid, userId, root);
|
||||
RegionDO rootRegion = prepareRegionRoot(userId, root);
|
||||
if(rootRegion == null){
|
||||
return;
|
||||
}
|
||||
@@ -726,10 +534,10 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
|
||||
//节点同步的时候,需要将该节点个regionPath拿到,之后的数据都是基于该regionPath
|
||||
if (regionId!=null){
|
||||
RegionDO regionDO = regionDAO.getByRegionId(eid, regionId);
|
||||
RegionDO regionDO = regionDAO.getByRegionId(regionId);
|
||||
rootRegion.setRegionPath(regionDO.getRegionPath());
|
||||
}
|
||||
List<RegionSyncDTO> regionList = regionDAO.getSpecifiedRegionIdAndDeptId(eid,regionId);
|
||||
List<RegionSyncDTO> regionList = regionDAO.getSpecifiedRegionIdAndDeptId(regionId);
|
||||
List<Long> regionSelfList = new ArrayList<>();
|
||||
Map<String, Object> regionMap = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(regionList)) {
|
||||
@@ -739,16 +547,10 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
|
||||
regionMap = regionList.stream().filter((RegionSyncDTO s) -> StringUtils.isNotBlank(s.getSynDingDeptId())&&s.getId()!=null).collect(Collectors.toMap(RegionSyncDTO::getSynDingDeptId, RegionSyncDTO::getId));
|
||||
}
|
||||
List<RegionSyncDTO> storeDOList = storeDAO.getSpecifiedStoreIdsAndDeptId(eid,regionId);
|
||||
List<String> removeStoreList = new ArrayList<>();
|
||||
Map<String, Object> storeMap = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(storeDOList)) {
|
||||
removeStoreList = storeDOList.stream()
|
||||
.filter((RegionSyncDTO s) -> StringUtils.isBlank(s.getSynDingDeptId()))
|
||||
.map(e -> String.valueOf(e.getId())).collect(Collectors.toList());
|
||||
storeMap = storeDOList.stream().filter((RegionSyncDTO s) ->
|
||||
StringUtils.isNotBlank(s.getSynDingDeptId())&&s.getId()!=null).collect(Collectors.toMap(RegionSyncDTO::getSynDingDeptId, RegionSyncDTO::getId));
|
||||
}
|
||||
String storeKey = "hsay_store";
|
||||
String regionKey = "hsay_region";
|
||||
//有效期一天 完成任务删除
|
||||
redisUtil.putAll(storeKey, storeMap, 1L, TimeUnit.DAYS);
|
||||
//有效期一天
|
||||
@@ -833,7 +635,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
log.info("regionUpdateList:int");
|
||||
for(RegionDO regionDO : regionUpdateList){
|
||||
//批量插入或更新
|
||||
regionService.saveRegionAndStore(eid, regionDO, userId);
|
||||
regionService.saveRegionAndStore(regionDO, userId);
|
||||
}
|
||||
queue.addAll(regionUpdateList);
|
||||
}
|
||||
@@ -843,10 +645,10 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
try {
|
||||
for(RegionDO regionDO : regionInsertList){
|
||||
//批量插入或更新
|
||||
regionService.saveRegionAndStore(eid, regionDO, userId);
|
||||
regionService.saveRegionAndStore(regionDO, userId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("保存部门异常 eid :{} deptId :{} deptName :{}", eid, deptInfo.getId(), deptInfo.getName());
|
||||
log.error("保存部门异常 eid :{} deptId :{} deptName :{}", deptInfo.getId(), deptInfo.getName());
|
||||
log.error("保存部门异常细节",e);
|
||||
if (e instanceof DuplicateKeyException) {
|
||||
throw new ServiceException(deptInfo.getName() + "[" + deptInfo.getId() + "] 下级部门和其他同步部门有上下级关系");
|
||||
@@ -871,11 +673,11 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
}
|
||||
//移除删除的钉钉区域
|
||||
if (CollectionUtils.isNotEmpty(regionIdList)) {
|
||||
regionService.removeRegions(eid, regionIdList);
|
||||
regionService.removeRegions(regionIdList);
|
||||
}
|
||||
//移除自有的区域
|
||||
if (CollectionUtils.isNotEmpty(regionSelfList)) {
|
||||
Lists.partition(regionSelfList, CommonConstants.DEAL_RECORD_MAX_SIZE).forEach(idList -> regionService.removeRegions(eid, idList));
|
||||
Lists.partition(regionSelfList, CommonConstants.DEAL_RECORD_MAX_SIZE).forEach(idList -> regionService.removeRegions(idList));
|
||||
}
|
||||
Map<String, Object> leftStoreMap = redisUtil.entries(storeKey);
|
||||
if (!leftStoreMap.isEmpty()) {
|
||||
@@ -883,23 +685,14 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
removeStoreList.add(entry.getValue().toString());
|
||||
}
|
||||
}
|
||||
//移除无用门店
|
||||
if (CollectionUtils.isNotEmpty(removeStoreList)) {
|
||||
List<String> storeIds = storeDAO.getStoreIdByIdList(eid, removeStoreList);
|
||||
if(CollectionUtils.isNotEmpty(storeIds)){
|
||||
Lists.partition(storeIds, CommonConstants.DEAL_RECORD_MAX_SIZE).forEach(idList -> regionService.deleteByStoreIds(eid, idList, userId));
|
||||
}
|
||||
}
|
||||
//发消息计算门店数量
|
||||
//simpleMessageService.send(JSONObject.toJSONString(new RegionStoreNumRecursionMsgDTO(eid, Long.valueOf(SyncConfig.ROOT_DEPT_ID))), RocketMqTagEnum.CAL_REGION_STORE_NUM);
|
||||
}
|
||||
|
||||
private RegionDO prepareRegionRoot(String eid, String userId, RegionDTO deptRoot) {
|
||||
private RegionDO prepareRegionRoot(String userId, RegionDTO deptRoot) {
|
||||
|
||||
RegionNode regionDelete = regionDAO.getRegionById(eid, CommonConstants.DELETE_DEPT_ID);
|
||||
RegionNode regionDelete = regionDAO.getRegionById(CommonConstants.DELETE_DEPT_ID);
|
||||
|
||||
if (regionDelete == null) {
|
||||
regionDAO.insertRegion(eid, RegionDO.builder().name("删除区域")
|
||||
regionDAO.insertRegion(RegionDO.builder().name("删除区域")
|
||||
.createName(userId)
|
||||
.createTime(System.currentTimeMillis())
|
||||
.id(Long.valueOf(CommonConstants.DELETE_DEPT_ID))
|
||||
@@ -924,12 +717,12 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
rootDO.setId(Long.valueOf(CommonConstants.ROOT_DEPT_ID_STR));
|
||||
rootDO.setParentId("0");
|
||||
}
|
||||
regionDAO.insertOrUpdate(rootDO, eid);
|
||||
regionDAO.insertOrUpdate(rootDO);
|
||||
return rootDO;
|
||||
}
|
||||
|
||||
|
||||
public Set<String> syncDept(String corpId, String appType, String enterpriseId, String dbName) {
|
||||
public Set<String> syncDept(String corpId, String appType, String dbName) {
|
||||
List<SysDepartmentDO> sysDepartments = getFsDepartmentsV1(corpId, appType);
|
||||
Set<String> idSet = new HashSet<>();
|
||||
log.info("{} get depts size={}", corpId, sysDepartments.size());
|
||||
@@ -938,7 +731,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
//分开批量插入
|
||||
if (CollectionUtils.isNotEmpty(sysDepartments)) {
|
||||
Lists.partition(sysDepartments, CommonConstants.DEAL_RECORD_MAX_SIZE).forEach(p -> {
|
||||
sysDepartmentDAO.batchInsertOrUpdate(enterpriseId, p);
|
||||
sysDepartmentDAO.batchInsertOrUpdate(p);
|
||||
});
|
||||
}
|
||||
return idSet;
|
||||
@@ -1081,38 +874,38 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
}
|
||||
}
|
||||
|
||||
public void dealUsers(List<EnterpriseUserRequest> users, String eid, String corpId, String dbName,
|
||||
public void dealUsers(List<EnterpriseUserRequest> users, String corpId, String dbName,
|
||||
Map<String, String> deptIdMap, Long unclassifiedRegionId, AuthInfoDTO authInfo, Set<String> handlerUserIds) {
|
||||
|
||||
DataSourceHelper.changeToSpecificDataSource(dbName);
|
||||
try {
|
||||
insertUserRelatedInfo(users, eid, dbName, authInfo, handlerUserIds);
|
||||
insertUserRelatedInfo(users, dbName, authInfo, handlerUserIds);
|
||||
//处理用户和区域的关系
|
||||
handlerUserRegionMapping(eid, users, unclassifiedRegionId);
|
||||
handlerUserRegionMapping(users, unclassifiedRegionId);
|
||||
} catch (Exception e) {
|
||||
log.error("dealUsers insertUserRelatedInfo error, corpId={}", corpId, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertUserRelatedInfo(List<EnterpriseUserRequest> deptUsers, String eid, String dbName, AuthInfoDTO authInfo, Set<String> handlerUserIds) {
|
||||
public void insertUserRelatedInfo(List<EnterpriseUserRequest> deptUsers, String dbName, AuthInfoDTO authInfo, Set<String> handlerUserIds) {
|
||||
|
||||
if (CollectionUtils.isEmpty(deptUsers)) {
|
||||
log.info("insertUserRelatedInfo deptUsers is empty,eid:{}",eid);
|
||||
log.info("insertUserRelatedInfo deptUsers is empty,eid:{}");
|
||||
return;
|
||||
}
|
||||
log.info("insertUserRelatedInfo-{}, deptUsersSize:{}",eid, deptUsers.size());
|
||||
log.info("insertUserRelatedInfo-{}, deptUsersSize:{}",deptUsers.size());
|
||||
DataSourceHelper.reset();
|
||||
//提取enterpriseUserDO
|
||||
List<EnterpriseUserDO> collect = ListUtils.emptyIfNull(deptUsers).stream()
|
||||
.map(EnterpriseUserRequest::getEnterpriseUserDO)
|
||||
.collect(Collectors.toList());
|
||||
DataSourceHelper.changeToSpecificDataSource(dbName);
|
||||
enterpriseUserDAO.batchInsertOrUpdate(eid, collect);
|
||||
enterpriseUserDAO.batchInsertOrUpdate(collect);
|
||||
// 同步用户与角色的关系
|
||||
Long masterRoleId = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.MASTER.getRoleEnum());
|
||||
Long employeeRoleId = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.EMPLOYEE.getRoleEnum());
|
||||
Long subMaster = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.SUB_MASTER.getRoleEnum());
|
||||
Long shopOwner = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.SHOPOWNER.getRoleEnum());
|
||||
Long masterRoleId = sysRoleDAO.getRoleIdByRoleEnum(RoleEnum.MASTER.getRoleEnum());
|
||||
Long employeeRoleId = sysRoleDAO.getRoleIdByRoleEnum(RoleEnum.EMPLOYEE.getRoleEnum());
|
||||
Long subMaster = sysRoleDAO.getRoleIdByRoleEnum(RoleEnum.SUB_MASTER.getRoleEnum());
|
||||
Long shopOwner = sysRoleDAO.getRoleIdByRoleEnum(RoleEnum.SHOPOWNER.getRoleEnum());
|
||||
List<EnterpriseUserRole> userRoles = new ArrayList<>();
|
||||
collect.forEach(f -> {
|
||||
if (Objects.nonNull(f)) {
|
||||
@@ -1134,16 +927,16 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
}
|
||||
});
|
||||
if (CollectionUtils.isNotEmpty(userRoles)) {
|
||||
enterpriseUserRoleDAO.insertBatchUserRole(eid, userRoles);
|
||||
enterpriseUserRoleDAO.insertBatchUserRole(userRoles);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理用户和区域的关系
|
||||
* @param eid
|
||||
* @param
|
||||
* @param enterpriseUserRequests
|
||||
*/
|
||||
public void handlerUserRegionMapping(String eid, List<EnterpriseUserRequest> enterpriseUserRequests, Long unclassifiedRegionId) {
|
||||
public void handlerUserRegionMapping(List<EnterpriseUserRequest> enterpriseUserRequests, Long unclassifiedRegionId) {
|
||||
//用户区域映射关系
|
||||
List<UserRegionMappingDO> userRegionMappings = new ArrayList<>();
|
||||
List<String> userIds = new ArrayList<>();
|
||||
@@ -1162,7 +955,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
regionIds.add(unclassifiedRegionId);
|
||||
} else {
|
||||
//db查询区域表的数据,找到映射的区域
|
||||
List<Long> regionIdsBySynDingDeptIds = regionDAO.getRegionIdsBySynDingDeptIds(eid, deptIds.stream().map(a -> a).collect(Collectors.toList()));
|
||||
List<Long> regionIdsBySynDingDeptIds = regionDAO.getRegionIdsBySynDingDeptIds(deptIds.stream().map(a -> a).collect(Collectors.toList()));
|
||||
if (CollectionUtils.isNotEmpty(regionIdsBySynDingDeptIds)) {
|
||||
regionIds.addAll(regionIdsBySynDingDeptIds);
|
||||
} else {
|
||||
@@ -1183,7 +976,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
//移除不在授权范围内的部门的主管部门
|
||||
List<String> leaderDeptIds = user.getLeaderInDepts();
|
||||
if (CollectionUtils.isNotEmpty(leaderDeptIds)) {
|
||||
List<Long> regionIdsBySynDingDeptIds = regionDAO.getRegionIdsBySynDingDeptIds(eid, leaderDeptIds.stream().map(a->a).collect(Collectors.toList()));
|
||||
List<Long> regionIdsBySynDingDeptIds = regionDAO.getRegionIdsBySynDingDeptIds(leaderDeptIds.stream().map(a->a).collect(Collectors.toList()));
|
||||
if (CollectionUtils.isNotEmpty(regionIdsBySynDingDeptIds)) {
|
||||
regionIds.addAll(regionIdsBySynDingDeptIds);
|
||||
}
|
||||
@@ -1195,10 +988,10 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
if (userRegionMappings.size() > CommonConstants.DEAL_RECORD_MAX_SIZE) {
|
||||
//先删除 后新增
|
||||
//用户和区域的映射关系
|
||||
userRegionMappingDAO.deletedByUserIds(eid, userIds);
|
||||
userRegionMappingDAO.batchInsertRegionMapping(eid, userRegionMappings);
|
||||
userRegionMappingDAO.deletedByUserIds(userIds);
|
||||
userRegionMappingDAO.batchInsertRegionMapping(userRegionMappings);
|
||||
//调用订正用户表字段user_region_ids
|
||||
enterpriseUserService.updateUserRegionPathList(eid, userIds);
|
||||
enterpriseUserService.updateUserRegionPathList(userIds);
|
||||
userRegionMappings.clear();
|
||||
userIds.clear();
|
||||
}
|
||||
@@ -1206,10 +999,10 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
if (CollectionUtils.isNotEmpty(userRegionMappings)) {
|
||||
//先删除 后新增
|
||||
//用户和区域的映射关系
|
||||
userRegionMappingDAO.deletedByUserIds(eid, userIds);
|
||||
userRegionMappingDAO.batchInsertRegionMapping(eid, userRegionMappings);
|
||||
userRegionMappingDAO.deletedByUserIds(userIds);
|
||||
userRegionMappingDAO.batchInsertRegionMapping(userRegionMappings);
|
||||
//调用订正用户表字段user_region_ids
|
||||
enterpriseUserService.updateUserRegionPathList(eid, userIds);
|
||||
enterpriseUserService.updateUserRegionPathList(userIds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1220,7 +1013,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
return userRegionMappingDO;
|
||||
}
|
||||
|
||||
public void initRootRegion(List<SysDepartmentDTO> sysDepartmentDTOS, String eid, String dbName) {
|
||||
public void initRootRegion(List<SysDepartmentDTO> sysDepartmentDTOS, String dbName) {
|
||||
|
||||
try {
|
||||
Optional<SysDepartmentDTO> first = sysDepartmentDTOS.stream()
|
||||
@@ -1239,19 +1032,19 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
regionDO.setUnclassifiedFlag(CommonConstants.ZERO);
|
||||
regionDO.setRegionPath(null);
|
||||
regionDO.setStoreNum(CommonConstants.ONE);
|
||||
regionDAO.insertRegion(eid, regionDO);
|
||||
regionDAO.insertRegion(regionDO);
|
||||
//同步部门为区域节点
|
||||
initRegionByDepartment(eid, CommonConstants.ROOT_DEPT_ID_STR);
|
||||
initRegionByDepartment(CommonConstants.ROOT_DEPT_ID_STR);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("enterpriseInit initRootRegion error,eid:{}", eid, e);
|
||||
log.error("enterpriseInit initRootRegion error,eid:{}", e);
|
||||
throw new ServiceException(ErrorCodeEnum.FEISHU_SERVICE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public void initRegionByDepartment(String eid, String deptId) {
|
||||
public void initRegionByDepartment(String deptId) {
|
||||
//首次获取 获取根部门下一级的所有数据
|
||||
List<QueryDeptChildDTO> queryDeptChildDTOS = sysDepartmentDAO.getDeptChildListByParentId(eid, deptId);
|
||||
List<QueryDeptChildDTO> queryDeptChildDTOS = sysDepartmentDAO.getDeptChildListByParentId(deptId);
|
||||
if (CollectionUtils.isEmpty(queryDeptChildDTOS)) {
|
||||
return;
|
||||
}
|
||||
@@ -1275,25 +1068,25 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
syncDingDeptIds.add(String.valueOf(deptChildDTO.getId()));
|
||||
if (regionDOS.size() > CommonConstants.DEAL_RECORD_MAX_SIZE) {
|
||||
//批量插入或更新
|
||||
regionDAO.batchInsertRegions(regionDOS, eid);
|
||||
regionDAO.batchInsertRegions(regionDOS);
|
||||
regionDOS.clear();
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(regionDOS)) {
|
||||
//批量插入或更新
|
||||
regionDAO.batchInsertRegions(regionDOS, eid);
|
||||
regionDAO.batchInsertRegions(regionDOS);
|
||||
}
|
||||
//递归调用,接着获取下一层级的数据进行处理
|
||||
//获取region的id和部门id映射关系
|
||||
Map<String, Long> regionIdMap = regionDAO.getRegionSynDeptIdAndIdMapping(eid, syncDingDeptIds);
|
||||
handlerSubRegions(eid, queryDeptChildDTOS, regionIdMap);
|
||||
Map<String, Long> regionIdMap = regionDAO.getRegionSynDeptIdAndIdMapping(syncDingDeptIds);
|
||||
handlerSubRegions(queryDeptChildDTOS, regionIdMap);
|
||||
}
|
||||
|
||||
public void initUser(List<SysDepartmentDTO> sysDepartmentDTOS, String corpId, String eid, String appType, String dbName,
|
||||
public void initUser(List<SysDepartmentDTO> sysDepartmentDTOS, String corpId, String appType, String dbName,
|
||||
List<String> adminList, AuthInfoDTO authInfo, Set<String> handlerUserIds) {
|
||||
try {
|
||||
//先查询是否存在未分组区域
|
||||
RegionDO unclassifiedRegionDO = regionDAO.getUnclassifiedRegionDO(eid);
|
||||
RegionDO unclassifiedRegionDO = regionDAO.getUnclassifiedRegionDO();
|
||||
//获取通讯录授权范围
|
||||
AuthScopeDTO authScope = isvHttpRequest.getAuthScope(corpId, appType);
|
||||
List<EnterpriseUserDTO> enterpriseUserDTOS = null;
|
||||
@@ -1327,7 +1120,7 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
authUsers.add(tempRequest);
|
||||
}
|
||||
}
|
||||
dealUsers(authUsers,eid,corpId,dbName, deptIdMap, unclassifiedRegionDO.getId(), authInfo, handlerUserIds);
|
||||
dealUsers(authUsers,corpId,dbName, deptIdMap, unclassifiedRegionDO.getId(), authInfo, handlerUserIds);
|
||||
List<EnterpriseUserRequest> deptUsers;
|
||||
if (CollectionUtils.isNotEmpty(sysDepartmentDTOS)) {
|
||||
|
||||
@@ -1344,24 +1137,24 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
|
||||
if (CollectionUtils.isNotEmpty(deptUsers)) {
|
||||
log.info("enterpriseInit initUser deptUsersInfo, corpId={}, deptId={}, userSize={}", corpId, sysDepartmentDTO.getId(), deptUsers.size());
|
||||
dealUsers(deptUsers, eid, corpId, dbName, deptIdMap, unclassifiedRegionDO.getId(), authInfo, handlerUserIds);
|
||||
dealUsers(deptUsers, corpId, dbName, deptIdMap, unclassifiedRegionDO.getId(), authInfo, handlerUserIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("enterpriseInit initUser error,eid:{},appType:{}", eid, appType, e);
|
||||
log.error("enterpriseInit initUser error,eid:{},appType:{}", appType, e);
|
||||
throw new ServiceException(ErrorCodeEnum.FEISHU_SERVICE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public void handlerSubRegions(String eid, List<QueryDeptChildDTO> depts, Map<String, Long> regionIdMap) {
|
||||
public void handlerSubRegions(List<QueryDeptChildDTO> depts, Map<String, Long> regionIdMap) {
|
||||
List<RegionDO> regionDOS = new ArrayList<>();
|
||||
//暂存一层级的数据
|
||||
List<QueryDeptChildDTO> results = new ArrayList<>();
|
||||
List<String> syncDingDeptIds = new ArrayList<>();
|
||||
for (QueryDeptChildDTO dept : depts) {
|
||||
//获取该层级的子节点处理
|
||||
List<QueryDeptChildDTO> childDTOS = sysDepartmentDAO.getDeptChildListByParentId(eid, String.valueOf(dept.getId()));
|
||||
List<QueryDeptChildDTO> childDTOS = sysDepartmentDAO.getDeptChildListByParentId(String.valueOf(dept.getId()));
|
||||
for (QueryDeptChildDTO deptChildDTO : childDTOS) {
|
||||
//设置上级区域的path,方便后续的追溯
|
||||
deptChildDTO.setPath(dept.getPath() + regionIdMap.get(deptChildDTO.getParentId()) + "/");
|
||||
@@ -1385,26 +1178,26 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
}
|
||||
if (regionDOS.size() > CommonConstants.DEAL_RECORD_MAX_SIZE) {
|
||||
//批量插入或更新
|
||||
regionDAO.batchInsertRegions(regionDOS, eid);
|
||||
regionDAO.batchInsertRegions(regionDOS);
|
||||
regionDOS.clear();
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(regionDOS)) {
|
||||
//批量插入或更新
|
||||
regionDAO.batchInsertRegions(regionDOS, eid);
|
||||
regionDAO.batchInsertRegions(regionDOS);
|
||||
}
|
||||
//递归调用
|
||||
if (CollectionUtils.isNotEmpty(results)) {
|
||||
//一次用完即清理
|
||||
regionIdMap.clear();
|
||||
//添加这一层的region的id和部门id映射关系
|
||||
regionIdMap.putAll(regionDAO.getRegionSynDeptIdAndIdMapping(eid, syncDingDeptIds));
|
||||
handlerSubRegions(eid, results, regionIdMap);
|
||||
regionIdMap.putAll(regionDAO.getRegionSynDeptIdAndIdMapping(syncDingDeptIds));
|
||||
handlerSubRegions(results, regionIdMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<SysDepartmentDTO> initDept(String corpId, String eid, String appType, String dbName) {
|
||||
public List<SysDepartmentDTO> initDept(String corpId, String appType, String dbName) {
|
||||
List<SysDepartmentDTO> departments = null;
|
||||
try {
|
||||
//获取所有部门
|
||||
@@ -1417,14 +1210,14 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
for (SysDepartmentDTO department : departments) {
|
||||
sysDepartmentDOS.add(convertSysDepartmentDTO2SysDepartmentDO(department, appType));
|
||||
if(sysDepartmentDOS.size() > CommonConstants.DEAL_RECORD_MAX_SIZE){
|
||||
sysDepartmentDAO.batchInsertOrUpdate(eid, sysDepartmentDOS);
|
||||
sysDepartmentDAO.batchInsertOrUpdate(sysDepartmentDOS);
|
||||
sysDepartmentDOS.clear();
|
||||
}
|
||||
}
|
||||
|
||||
DataSourceHelper.changeToSpecificDataSource(dbName);
|
||||
if(CollectionUtils.isNotEmpty(sysDepartmentDOS)){
|
||||
sysDepartmentDAO.batchInsertOrUpdate(eid, sysDepartmentDOS);
|
||||
sysDepartmentDAO.batchInsertOrUpdate(sysDepartmentDOS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("enterpriseInit initDept error,corpId:{},appType:{}", corpId, appType, e);
|
||||
@@ -1452,15 +1245,15 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
log.info("初始化开通用户");
|
||||
if (StringUtils.isNotBlank(msg.getAuthUserId())) {
|
||||
//初始化开通用户
|
||||
initAuthUser(msg.getEid(), msg.getCorpId(), msg.getAppType(), msg.getAuthUserId(), userId, msg.getDbName());
|
||||
initAuthUser(msg.getCorpId(), msg.getAppType(), msg.getAuthUserId(), userId, msg.getDbName());
|
||||
}
|
||||
}
|
||||
|
||||
public void initAuthUser(String eid, String corpId, String appType, String authUserId, String userId, String dbName) {
|
||||
public void initAuthUser(String corpId, String appType, String authUserId, String userId, String dbName) {
|
||||
List<EnterpriseUserRole> userRoles = new ArrayList<>();
|
||||
Long roleIdByRoleEnum = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.MASTER.getRoleEnum());
|
||||
Long shopOwner = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.SHOPOWNER.getRoleEnum());
|
||||
Long subMaster = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.SUB_MASTER.getRoleEnum());
|
||||
Long roleIdByRoleEnum = sysRoleDAO.getRoleIdByRoleEnum(RoleEnum.MASTER.getRoleEnum());
|
||||
Long shopOwner = sysRoleDAO.getRoleIdByRoleEnum(RoleEnum.SHOPOWNER.getRoleEnum());
|
||||
Long subMaster = sysRoleDAO.getRoleIdByRoleEnum(RoleEnum.SUB_MASTER.getRoleEnum());
|
||||
//钉钉或者企业走用户,app开通不需要
|
||||
EnterpriseUserDTO userDTO = null;
|
||||
try {
|
||||
@@ -1471,11 +1264,11 @@ public class EnterpriseInitServiceImpl implements EnterpriseInitService {
|
||||
EnterpriseUserDO userDO = EnterpriseUserDTO.transUserDtoToDo(userDTO);
|
||||
userDO.setMainAdmin(true);
|
||||
userDO.setIsAdmin(true);
|
||||
enterpriseUserDAO.batchInsertOrUpdate(eid, Collections.singletonList(userDO));
|
||||
enterpriseUserDAO.batchInsertOrUpdate(Collections.singletonList(userDO));
|
||||
userRoles.add(new EnterpriseUserRole(roleIdByRoleEnum.toString(), userId));
|
||||
userRoles.add(new EnterpriseUserRole(shopOwner.toString(), userId));
|
||||
userRoles.add(new EnterpriseUserRole(subMaster.toString(), userId));
|
||||
enterpriseUserRoleDAO.insertBatchUserRole(eid, userRoles);
|
||||
enterpriseUserRoleDAO.insertBatchUserRole(userRoles);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,389 +0,0 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.context.CurrentUser;
|
||||
import com.cool.store.dao.EnterpriseUserDAO;
|
||||
import com.cool.store.dao.EnterpriseUserGroupDAO;
|
||||
import com.cool.store.dao.EnterpriseUserGroupMappingDAO;
|
||||
import com.cool.store.dao.EnterpriseUserRoleDAO;
|
||||
import com.cool.store.dto.auth.AuthRegionStoreDTO;
|
||||
import com.cool.store.dto.buser.SubordinateUserRangeDTO;
|
||||
import com.cool.store.dto.usergroup.UserGroupAddRequest;
|
||||
import com.cool.store.dto.usergroup.UserGroupDTO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.entity.EnterpriseUserGroupDO;
|
||||
import com.cool.store.entity.EnterpriseUserGroupMappingDO;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.service.AuthVisualService;
|
||||
import com.cool.store.service.EnterpriseUserGroupService;
|
||||
import com.cool.store.service.EnterpriseUserService;
|
||||
import com.cool.store.service.SubordinateMappingService;
|
||||
import com.cool.store.utils.UUIDUtils;
|
||||
import com.cool.store.vo.buser.EnterpriseUserPageVO;
|
||||
import com.cool.store.vo.usergroup.UserGroupVO;
|
||||
import com.cool.store.vo.usergroup.UserSimpleDTO;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @Author wxp
|
||||
* @Date 2022/12/29 11:18
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EnterpriseUserGroupServiceImpl implements EnterpriseUserGroupService {
|
||||
|
||||
@Resource
|
||||
private EnterpriseUserGroupDAO enterpriseUserGroupDAO;
|
||||
@Resource
|
||||
private EnterpriseUserGroupMappingDAO enterpriseUserGroupMappingDAO;
|
||||
@Autowired
|
||||
public EnterpriseUserService enterpriseUserService;
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
@Resource
|
||||
private AuthVisualService visualService;
|
||||
@Resource
|
||||
private SubordinateMappingService subordinateMappingService;
|
||||
@Resource
|
||||
private EnterpriseUserRoleDAO enterpriseUserRoleDAO;
|
||||
|
||||
@Override
|
||||
public Boolean saveOrUpdateUserGroup(String enterpriseId, UserGroupAddRequest userGroupAddRequest, CurrentUser currentUser) {
|
||||
int count = enterpriseUserGroupDAO.countByGroupName(enterpriseId, userGroupAddRequest.getGroupName(), userGroupAddRequest.getGroupId());
|
||||
if (count > 0) {
|
||||
throw new ServiceException(ErrorCodeEnum.USER_GROUP_NAME_EXIST);
|
||||
}
|
||||
EnterpriseUserGroupDO userGroupDO = translateToUserGroupDO(userGroupAddRequest, currentUser);
|
||||
if(StringUtils.isBlank(userGroupAddRequest.getGroupId())){
|
||||
enterpriseUserGroupDAO.insertSelective(userGroupDO, enterpriseId);
|
||||
}else {
|
||||
enterpriseUserGroupDAO.updateByGroupId(userGroupDO, enterpriseId);
|
||||
}
|
||||
List<String> userIdList = userGroupAddRequest.getUserIdList();
|
||||
if(CollectionUtils.isEmpty(userIdList)){
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
enterpriseUserGroupMappingDAO.deleteUserGroupMappingByGroupId(enterpriseId, userGroupDO.getGroupId());
|
||||
List<EnterpriseUserGroupMappingDO> userGroupMappingDOList = new ArrayList<>();
|
||||
for (String userId: userIdList) {
|
||||
EnterpriseUserGroupMappingDO userGroupMappingDO = new EnterpriseUserGroupMappingDO();
|
||||
userGroupMappingDO.setUserId(userId);
|
||||
userGroupMappingDO.setGroupId(userGroupDO.getGroupId());
|
||||
userGroupMappingDO.setCreateUserId(currentUser.getUserId());
|
||||
userGroupMappingDO.setUpdateUserId(currentUser.getUserId());
|
||||
userGroupMappingDOList.add(userGroupMappingDO);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(userGroupMappingDOList)) {
|
||||
enterpriseUserGroupMappingDAO.batchInsertOrUpdateUserGroupMapping(enterpriseId, userGroupMappingDOList);
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateUserGroup(String enterpriseId, Long userGroupId, List<String> userIdList){
|
||||
enterpriseUserGroupMappingDAO.deleteUserGroupMappingByGroupId(enterpriseId, String.valueOf(userGroupId));
|
||||
List<EnterpriseUserGroupMappingDO> userGroupMappingDOList = new ArrayList<>();
|
||||
for (String userId: userIdList) {
|
||||
EnterpriseUserGroupMappingDO userGroupMappingDO = new EnterpriseUserGroupMappingDO();
|
||||
userGroupMappingDO.setUserId(userId);
|
||||
userGroupMappingDO.setGroupId(String.valueOf(userGroupId));
|
||||
userGroupMappingDO.setCreateUserId("");
|
||||
userGroupMappingDO.setUpdateUserId("");
|
||||
userGroupMappingDOList.add(userGroupMappingDO);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(userGroupMappingDOList)) {
|
||||
enterpriseUserGroupMappingDAO.batchInsertOrUpdateUserGroupMapping(enterpriseId, userGroupMappingDOList);
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDeleteGroup(String enterpriseId, String groupId, List<String> userIdList) {
|
||||
enterpriseUserGroupMappingDAO.deleteMappingByGroupIdList(enterpriseId, groupId, userIdList);
|
||||
if(CollectionUtils.isEmpty(userIdList)){
|
||||
enterpriseUserGroupDAO.deleteByGroupIdList(enterpriseId, Collections.singletonList(groupId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserGroupVO> listUserGroup(String enterpriseId, String groupName, CurrentUser user) {
|
||||
List<EnterpriseUserGroupDO> userGroupDOList = enterpriseUserGroupDAO.listUserGroup(enterpriseId,groupName);
|
||||
List<UserGroupVO> resultList = new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(userGroupDOList)) {
|
||||
return resultList;
|
||||
}
|
||||
List<String> groupIdList = userGroupDOList.stream().map(EnterpriseUserGroupDO::getGroupId).collect(Collectors.toList());
|
||||
Set<String> userIdSet = userGroupDOList.stream()
|
||||
.flatMap(c->Stream.of(c.getCreateUserId(),c.getUpdateUserId()))
|
||||
.collect(Collectors.toSet());
|
||||
List<EnterpriseUserDO> userDOList = enterpriseUserDAO.selectUsersByUserIds(enterpriseId, new ArrayList<>(userIdSet));
|
||||
Map<String, EnterpriseUserDO> userMap = userDOList.stream().collect(Collectors.toMap(EnterpriseUserDO::getUserId, Function.identity()));
|
||||
List<EnterpriseUserGroupMappingDO> userGroupMappingDOList = enterpriseUserGroupMappingDAO.listByGroupIdList(enterpriseId, groupIdList);
|
||||
Map<String, List<EnterpriseUserGroupMappingDO>> userGroupMappingMap = userGroupMappingDOList.stream()
|
||||
.collect(Collectors.groupingBy(EnterpriseUserGroupMappingDO::getGroupId));
|
||||
for (EnterpriseUserGroupDO enterpriseUserGroupDO : userGroupDOList) {
|
||||
UserGroupVO userGroupVO = new UserGroupVO();
|
||||
userGroupVO.setCreateUserId(enterpriseUserGroupDO.getCreateUserId());
|
||||
userGroupVO.setGroupId(enterpriseUserGroupDO.getGroupId());
|
||||
userGroupVO.setGroupName(enterpriseUserGroupDO.getGroupName());
|
||||
userGroupVO.setCreateTime(enterpriseUserGroupDO.getCreateTime());
|
||||
userGroupVO.setUpdateTime(enterpriseUserGroupDO.getUpdateTime());
|
||||
EnterpriseUserDO createUser = userMap.get(enterpriseUserGroupDO.getCreateUserId());
|
||||
if (createUser != null) {
|
||||
userGroupVO.setCreateUserName(createUser.getName());
|
||||
}
|
||||
EnterpriseUserDO updateUser = userMap.get(enterpriseUserGroupDO.getUpdateUserId());
|
||||
if (updateUser != null) {
|
||||
userGroupVO.setUpdateUserName(updateUser.getName());
|
||||
}
|
||||
if(!CollectionUtils.isEmpty(userGroupMappingMap.get(enterpriseUserGroupDO.getGroupId()))){
|
||||
userGroupVO.setUserCount(userGroupMappingMap.get(enterpriseUserGroupDO.getGroupId()).size());
|
||||
}
|
||||
userGroupVO.setEditFlag(checkUserEditFlag(enterpriseId, enterpriseUserGroupDO, user.getUserId()));
|
||||
resultList.add(userGroupVO);
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserGroupVO getGroupInfo(String enterpriseId, String groupId, CurrentUser user) {
|
||||
EnterpriseUserGroupDO userGroupDO = enterpriseUserGroupDAO.getByGroupId(enterpriseId, groupId);
|
||||
if (userGroupDO == null) {
|
||||
throw new ServiceException(ErrorCodeEnum.USER_GROUP_NOT_EXIST);
|
||||
}
|
||||
UserGroupVO userGroupVO = new UserGroupVO();
|
||||
BeanUtils.copyProperties(userGroupDO, userGroupVO);
|
||||
fillUserGroupVO(enterpriseId, userGroupDO, userGroupVO);
|
||||
userGroupVO.setEditFlag(checkUserEditFlag(enterpriseId, userGroupDO, user.getUserId()));
|
||||
return userGroupVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<EnterpriseUserPageVO> listUserByGroupId(String enterpriseId, String groupId, String userName, Integer pageNum, Integer pageSize, CurrentUser currentUser) {
|
||||
PageHelper.startPage(pageNum,pageSize);
|
||||
List<EnterpriseUserDO> enterpriseUserList = enterpriseUserDAO.listUserByGroupId(enterpriseId, groupId, userName, null);
|
||||
PageInfo pageInfo = new PageInfo<>();
|
||||
if (CollectionUtils.isEmpty(enterpriseUserList)) {
|
||||
return pageInfo;
|
||||
}
|
||||
List<EnterpriseUserPageVO> resultList = new ArrayList<>();
|
||||
resultList = EnterpriseUserPageVO.transUserDOToVO(enterpriseUserList);
|
||||
pageInfo = new PageInfo<>(resultList);
|
||||
//填充角色信息如果存在角色信息
|
||||
List<String> userIdList = enterpriseUserService.initUserRole(enterpriseId, resultList);
|
||||
List<AuthRegionStoreDTO> authRegionStoreDTOList = visualService.authRegionStoreByUserList(enterpriseId, userIdList);
|
||||
Map<String, AuthRegionStoreDTO> authRegionStoreMap = ListUtils.emptyIfNull(authRegionStoreDTOList)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(AuthRegionStoreDTO::getUserId, data -> data, (a, b) -> a));
|
||||
Map<String, SubordinateUserRangeDTO> subordinateUserRangeMap = enterpriseUserService.fillUserSubordinateNames(enterpriseId, userIdList);
|
||||
Map<String, String> userRegionMap = enterpriseUserService.getUserRegion(enterpriseId, userIdList);
|
||||
|
||||
Boolean haveAllSubordinateUser = subordinateMappingService.checkHaveAllSubordinateUser(enterpriseId, currentUser.getUserId());
|
||||
List<String> userSubordinateList = Lists.newArrayList();
|
||||
if(!haveAllSubordinateUser){
|
||||
userSubordinateList = subordinateMappingService.getSubordinateUserIdList(enterpriseId, currentUser.getUserId(),Boolean.TRUE);
|
||||
}
|
||||
List<String> finalUserSubordinateList = userSubordinateList;
|
||||
resultList.stream()
|
||||
.forEach(data->{
|
||||
if(MapUtils.isNotEmpty(authRegionStoreMap)&&authRegionStoreMap.get(data.getUserId())!=null){
|
||||
AuthRegionStoreDTO authRegionStoreDTO = authRegionStoreMap.get(data.getUserId());
|
||||
data.setAuthRegionStoreList(authRegionStoreDTO.getAuthRegionStoreUserList());
|
||||
}
|
||||
// 填充下属用户
|
||||
if (subordinateUserRangeMap.get(data.getUserId()) != null){
|
||||
data.setSubordinateUserRange(subordinateUserRangeMap.get(data.getUserId()).getSubordinateUserRange());
|
||||
data.setSourceList(subordinateUserRangeMap.get(data.getUserId()).getSourceList());
|
||||
data.setMySubordinates(subordinateUserRangeMap.get(data.getUserId()).getMySubordinates());
|
||||
}
|
||||
data.setDepartment(userRegionMap.get(data.getUserId()));
|
||||
if(haveAllSubordinateUser){
|
||||
data.setSelectFlag(true);
|
||||
}else {
|
||||
data.setSelectFlag(finalUserSubordinateList.contains(data.getUserId()));
|
||||
}
|
||||
});
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserGroup(String enterpriseId, List<String> groupIdList, String userId, CurrentUser currentUser) {
|
||||
if(CollectionUtils.isEmpty(groupIdList)){
|
||||
return;
|
||||
}
|
||||
enterpriseUserGroupMappingDAO.deleteMappingByUserIdList(enterpriseId, Collections.singletonList(userId));
|
||||
List<EnterpriseUserGroupMappingDO> userGroupMappingDOList = new ArrayList<>();
|
||||
for (String groupId: groupIdList) {
|
||||
EnterpriseUserGroupMappingDO userGroupMappingDO = new EnterpriseUserGroupMappingDO();
|
||||
userGroupMappingDO.setUserId(userId);
|
||||
userGroupMappingDO.setGroupId(groupId);
|
||||
userGroupMappingDO.setCreateUserId(currentUser.getUserId());
|
||||
userGroupMappingDO.setUpdateUserId(currentUser.getUserId());
|
||||
userGroupMappingDOList.add(userGroupMappingDO);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(userGroupMappingDOList)) {
|
||||
enterpriseUserGroupMappingDAO.batchInsertOrUpdateUserGroupMapping(enterpriseId, userGroupMappingDOList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean configUser(String enterpriseId, UserGroupAddRequest userGroupAddRequest, CurrentUser currentUser) {
|
||||
EnterpriseUserGroupDO userGroupDO = enterpriseUserGroupDAO.getByGroupId(enterpriseId, userGroupAddRequest.getGroupId());
|
||||
if (userGroupDO == null) {
|
||||
throw new ServiceException(ErrorCodeEnum.USER_GROUP_NOT_EXIST);
|
||||
}
|
||||
List<String> userIdList = userGroupAddRequest.getUserIdList();
|
||||
if(CollectionUtils.isEmpty(userIdList)){
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
List<EnterpriseUserGroupMappingDO> userGroupMappingDOList = new ArrayList<>();
|
||||
for (String userId: userIdList) {
|
||||
EnterpriseUserGroupMappingDO userGroupMappingDO = new EnterpriseUserGroupMappingDO();
|
||||
userGroupMappingDO.setUserId(userId);
|
||||
userGroupMappingDO.setGroupId(userGroupDO.getGroupId());
|
||||
userGroupMappingDO.setCreateUserId(currentUser.getUserId());
|
||||
userGroupMappingDO.setUpdateUserId(currentUser.getUserId());
|
||||
userGroupMappingDOList.add(userGroupMappingDO);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(userGroupMappingDOList)) {
|
||||
enterpriseUserGroupMappingDAO.batchInsertOrUpdateUserGroupMapping(enterpriseId, userGroupMappingDOList);
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<UserGroupDTO>> getUserGroupMap(String enterpriseId, List<String> userIdList) {
|
||||
Map<String, List<UserGroupDTO>> resultMap = Maps.newHashMap();
|
||||
if(CollectionUtils.isEmpty(userIdList)){
|
||||
return resultMap;
|
||||
}
|
||||
List<EnterpriseUserGroupMappingDO> enterpriseUserGroupMappingDOList = enterpriseUserGroupMappingDAO.listByUserIdList(enterpriseId, userIdList);
|
||||
List<String> allGroupIdList = ListUtils.emptyIfNull(enterpriseUserGroupMappingDOList)
|
||||
.stream().map(EnterpriseUserGroupMappingDO::getGroupId)
|
||||
.collect(Collectors.toList());
|
||||
List<EnterpriseUserGroupDO> userGroupDOList = enterpriseUserGroupDAO.listByGroupIdList(enterpriseId, allGroupIdList);
|
||||
//封装 userId-userGroup map,以表示一个用户对应几个分组
|
||||
Map<String, Set<String>> userGroupMap = ListUtils.emptyIfNull(enterpriseUserGroupMappingDOList)
|
||||
.stream().collect(Collectors.groupingBy(EnterpriseUserGroupMappingDO::getUserId,
|
||||
Collectors.mapping(EnterpriseUserGroupMappingDO::getGroupId, Collectors.toSet())));
|
||||
//获得分组id -分组名称的map
|
||||
Map<String, String> groupNameMap = ListUtils.emptyIfNull(userGroupDOList)
|
||||
.stream()
|
||||
.filter(data -> StringUtils.isNotBlank(data.getGroupName()))
|
||||
.collect(Collectors.toMap(EnterpriseUserGroupDO::getGroupId, EnterpriseUserGroupDO::getGroupName, (a, b) -> a));
|
||||
userIdList.forEach(userId -> {
|
||||
Set<String> groupIdList = userGroupMap.get(userId);
|
||||
if (CollectionUtils.isNotEmpty(groupIdList)) {
|
||||
List<UserGroupDTO> userGroupDTOList = resultMap.get(userId);
|
||||
if (CollectionUtils.isEmpty(userGroupDTOList)) {
|
||||
userGroupDTOList = Lists.newArrayList();
|
||||
resultMap.put(userId, userGroupDTOList);
|
||||
}
|
||||
for (String groupId: groupIdList) {
|
||||
UserGroupDTO userGroupDTO = new UserGroupDTO();
|
||||
userGroupDTO.setGroupId(groupId);
|
||||
userGroupDTO.setGroupName(groupNameMap.get(groupId));
|
||||
userGroupDTOList.add(userGroupDTO);
|
||||
}
|
||||
}
|
||||
});
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private void fillUserGroupVO(String enterpriseId, EnterpriseUserGroupDO userGroupDO, UserGroupVO userGroupVO) {
|
||||
List<EnterpriseUserGroupMappingDO> userGroupMappingDOList = enterpriseUserGroupMappingDAO.listByGroupIdList(enterpriseId, Collections.singletonList(userGroupDO.getGroupId()));
|
||||
if (CollectionUtils.isNotEmpty(userGroupMappingDOList)){
|
||||
List<String> configUserIdList = userGroupMappingDOList.stream().map(EnterpriseUserGroupMappingDO::getUserId).collect(Collectors.toList());
|
||||
List<EnterpriseUserDO> enterpriseUserDOList = enterpriseUserDAO.selectUsersByUserIds(enterpriseId, configUserIdList);
|
||||
List<UserSimpleDTO> configUserList = ListUtils.emptyIfNull(enterpriseUserDOList).stream()
|
||||
.map(this::translateToUserSimpleDTO)
|
||||
.collect(Collectors.toList());
|
||||
userGroupVO.setConfigUserList(configUserList);
|
||||
}
|
||||
if(StringUtils.isNotBlank(userGroupDO.getCommonEditUserids())){
|
||||
List<String> commonEditUserIdList = StrUtil.splitTrim(userGroupDO.getCommonEditUserids(), ",");
|
||||
List<EnterpriseUserDO> enterpriseUserDOList = enterpriseUserDAO.selectUsersByUserIds(enterpriseId, commonEditUserIdList);
|
||||
List<UserSimpleDTO> commonEditUserList = ListUtils.emptyIfNull(enterpriseUserDOList).stream()
|
||||
.map(this::translateToUserSimpleDTO)
|
||||
.collect(Collectors.toList());
|
||||
userGroupVO.setCommonEditUserList(commonEditUserList);
|
||||
}
|
||||
|
||||
List<String> userIdList = Lists.newArrayList();
|
||||
userIdList.add(userGroupDO.getCreateUserId());
|
||||
userIdList.add(userGroupDO.getUpdateUserId());
|
||||
List<EnterpriseUserDO> userDOList = enterpriseUserDAO.selectUsersByUserIds(enterpriseId, userIdList);
|
||||
Map<String, EnterpriseUserDO> userMap = userDOList.stream().collect(Collectors.toMap(EnterpriseUserDO::getUserId, Function.identity()));
|
||||
EnterpriseUserDO createUser = userMap.get(userGroupDO.getCreateUserId());
|
||||
if (createUser != null) {
|
||||
userGroupVO.setCreateUserName(createUser.getName());
|
||||
}
|
||||
EnterpriseUserDO updateUser = userMap.get(userGroupDO.getUpdateUserId());
|
||||
if (updateUser != null) {
|
||||
userGroupVO.setUpdateUserName(updateUser.getName());
|
||||
}
|
||||
if (CommonConstants.SYSTEM_USER_ID.equals(userGroupDO.getCreateUserId())) {
|
||||
userGroupVO.setCreateUserName(CommonConstants.SYSTEM_USER_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private UserSimpleDTO translateToUserSimpleDTO(EnterpriseUserDO enterpriseUserDO) {
|
||||
UserSimpleDTO userSimpleDTO = new UserSimpleDTO();
|
||||
userSimpleDTO.setUserId(enterpriseUserDO.getUserId());
|
||||
userSimpleDTO.setUserName(enterpriseUserDO.getName());
|
||||
return userSimpleDTO;
|
||||
}
|
||||
|
||||
public EnterpriseUserGroupDO translateToUserGroupDO(UserGroupAddRequest request, CurrentUser user) {
|
||||
EnterpriseUserGroupDO userGroupDO = new EnterpriseUserGroupDO();
|
||||
String groupId = StringUtils.isNotBlank(request.getGroupId()) ? request.getGroupId() : UUIDUtils.get32UUID();
|
||||
userGroupDO.setGroupId(groupId);
|
||||
userGroupDO.setGroupName(request.getGroupName());
|
||||
if(CollectionUtils.isNotEmpty(request.getCommonEditUserIdList())){
|
||||
userGroupDO.setCommonEditUserids(CommonConstants.COMMA + StringUtils.join(request.getCommonEditUserIdList(), CommonConstants.COMMA) + CommonConstants.COMMA);
|
||||
}else {
|
||||
userGroupDO.setCommonEditUserids("");
|
||||
}
|
||||
if(StringUtils.isNotBlank(request.getGroupId())){
|
||||
userGroupDO.setUpdateTime(new Date());
|
||||
userGroupDO.setUpdateUserId(user.getUserId());
|
||||
}else {
|
||||
userGroupDO.setCreateTime(new Date());
|
||||
userGroupDO.setCreateUserId(user.getUserId());
|
||||
}
|
||||
return userGroupDO;
|
||||
}
|
||||
|
||||
|
||||
// 校验用户是否有编辑权限
|
||||
public Boolean checkUserEditFlag(String eid, EnterpriseUserGroupDO enterpriseUserGroupDO, String userId){
|
||||
// 是否管理员
|
||||
boolean isAdmin = enterpriseUserRoleDAO.checkIsAdmin(eid, userId);
|
||||
if(isAdmin || userId.equals(enterpriseUserGroupDO.getCreateUserId()) || (StringUtils.isNotBlank(enterpriseUserGroupDO.getCommonEditUserids()) && enterpriseUserGroupDO.getCommonEditUserids().contains(userId))){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,19 +4,9 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.context.CurrentUser;
|
||||
import com.cool.store.dao.*;
|
||||
import com.cool.store.dto.auth.AuthRegionStoreDTO;
|
||||
import com.cool.store.dto.auth.AuthStoreCountDTO;
|
||||
import com.cool.store.dto.buser.MySubordinatesDTO;
|
||||
import com.cool.store.dto.buser.SubordinateUserRangeDTO;
|
||||
import com.cool.store.dto.buser.UserRoleDTO;
|
||||
import com.cool.store.dto.region.RegionPathDTO;
|
||||
import com.cool.store.dto.usergroup.UserGroupDTO;
|
||||
import com.cool.store.entity.*;
|
||||
import com.cool.store.enums.SubordinateSourceEnum;
|
||||
import com.cool.store.enums.UserSelectRangeEnum;
|
||||
import com.cool.store.request.EnterpriseUserRequest;
|
||||
import com.cool.store.service.AuthVisualService;
|
||||
import com.cool.store.service.EnterpriseUserGroupService;
|
||||
import com.cool.store.service.EnterpriseUserService;
|
||||
import com.cool.store.vo.buser.EnterpriseUserPageVO;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
@@ -51,27 +41,21 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
@Resource
|
||||
private AuthVisualService authVisualService;
|
||||
@Resource
|
||||
private EnterpriseUserRoleDAO enterpriseUserRoleDAO;
|
||||
@Resource
|
||||
private EnterpriseUserGroupService enterpriseUserGroupService;
|
||||
@Resource
|
||||
private SubordinateMappingDAO subordinateMappingDAO;
|
||||
|
||||
@Override
|
||||
public void updateUserRegionPathList(String enterpriseId, List<String> userIds) {
|
||||
public void updateUserRegionPathList(List<String> userIds) {
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
//查询该人员的最新部门情况 同步到enterpriseUser 表usereginIds表中
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(enterpriseId, userIds);
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(userIds);
|
||||
Map<String, List<UserRegionMappingDO>> userRegionMappingMap = ListUtils.emptyIfNull(userRegionMappingDOS)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(UserRegionMappingDO::getUserId));
|
||||
List<String> regionIds = userRegionMappingDOS.stream()
|
||||
.map(UserRegionMappingDO::getRegionId).distinct().collect(Collectors.toList());
|
||||
List<RegionDO> regionDOS = regionDAO.getRegionByRegionIds(enterpriseId, regionIds);
|
||||
List<RegionDO> regionDOS = regionDAO.getRegionByRegionIds(regionIds);
|
||||
Map<String, RegionDO> regionMap = regionDOS.stream()
|
||||
.collect(Collectors.toMap(RegionDO::getRegionId, data -> data));
|
||||
|
||||
@@ -89,9 +73,9 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
if (CollectionUtils.isEmpty(userRegionMappingList)){
|
||||
log.info("getUserRegionPathListStr exception 该人员没有任何部门");
|
||||
//查询未分组
|
||||
RegionDO unclassifiedRegionDO = regionDAO.getUnclassifiedRegionDO(enterpriseId);
|
||||
RegionDO unclassifiedRegionDO = regionDAO.getUnclassifiedRegionDO();
|
||||
//将人添加到未分组中
|
||||
addUserRegionMappingDO(enterpriseId,userId,unclassifiedRegionDO.getRegionId(),new CurrentUser());
|
||||
addUserRegionMappingDO(userId,unclassifiedRegionDO.getRegionId(),new CurrentUser());
|
||||
regionDOList.add(unclassifiedRegionDO);
|
||||
}
|
||||
|
||||
@@ -111,11 +95,11 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
}
|
||||
enterpriseUserList.add(enterpriseUserDO);
|
||||
}
|
||||
enterpriseUserDAO.batchUpdateDiffUserDiffRegionIds(enterpriseId, enterpriseUserList);
|
||||
enterpriseUserDAO.batchUpdateDiffUserDiffRegionIds(enterpriseUserList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnterpriseUserPageVO> listUser(String enterpriseId, String userName, String deptId,
|
||||
public List<EnterpriseUserPageVO> listUser(String userName, String deptId,
|
||||
String orderBy, String orderRule,
|
||||
Long roleId, Integer userStatus, Integer pageNum, Integer pageSize, String jobNumber, String regionId, Boolean hasPage) {
|
||||
if (hasPage){
|
||||
@@ -124,9 +108,9 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
List<EnterpriseUserDO> enterpriseUserList = new ArrayList<>();
|
||||
//企微用户 用户名在数据表中加密,需要再次请求企业端接口根据名称去筛选数据
|
||||
if(roleId!=null){
|
||||
enterpriseUserList = enterpriseUserDAO.fuzzyUsersByDepartment(enterpriseId, deptId, roleId, orderBy, orderRule, userName, jobNumber, userStatus, null,regionId);
|
||||
enterpriseUserList = enterpriseUserDAO.fuzzyUsersByDepartment(deptId, roleId, orderBy, orderRule, userName, jobNumber, userStatus, null,regionId);
|
||||
}else {
|
||||
enterpriseUserList= enterpriseUserDAO.fuzzyUsersByNotRole(enterpriseId, deptId, orderBy, orderRule, userName, jobNumber, userStatus, null,regionId);
|
||||
enterpriseUserList= enterpriseUserDAO.fuzzyUsersByNotRole(deptId, orderBy, orderRule, userName, jobNumber, userStatus, null,regionId);
|
||||
}
|
||||
List<EnterpriseUserPageVO> resultList = new ArrayList<>();
|
||||
if(CollectionUtils.isEmpty(enterpriseUserList)){
|
||||
@@ -134,15 +118,15 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
}
|
||||
resultList = EnterpriseUserPageVO.transUserDOToVO(enterpriseUserList);
|
||||
//填充角色信息如果存在角色信息
|
||||
List<String> userIdList = initUserRole(enterpriseId, resultList);
|
||||
List<String> userIdList = initUserRole(resultList);
|
||||
//根据人员查询该人员所在部门集合
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(enterpriseId, userIdList);
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(userIdList);
|
||||
//regionids 集合
|
||||
List<String> regionIds = ListUtils.emptyIfNull(userRegionMappingDOS).stream().map(UserRegionMappingDO::getRegionId).distinct().collect(Collectors.toList());
|
||||
|
||||
List<RegionDO> regionDOs = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(regionIds)){
|
||||
regionDOs = regionDAO.getRegionByRegionIds(enterpriseId, regionIds);
|
||||
regionDOs = regionDAO.getRegionByRegionIds(regionIds);
|
||||
}
|
||||
//部门map KV key-部门id value-部门名称
|
||||
Map<String, String> regionMap = ListUtils.emptyIfNull(regionDOs)
|
||||
@@ -155,33 +139,8 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
.collect(Collectors.groupingBy(UserRegionMappingDO::getUserId,
|
||||
Collectors.mapping(UserRegionMappingDO::getRegionId, Collectors.toSet())));
|
||||
|
||||
//填充门店总数以及权限区域列表
|
||||
List<AuthRegionStoreDTO> authRegionStoreDTOList = authVisualService.authRegionStoreByUserList(enterpriseId, userIdList);
|
||||
List<AuthStoreCountDTO> authStoreCountDTOS = authVisualService.authStoreCount(enterpriseId, userIdList, false);
|
||||
Map<String, AuthStoreCountDTO> storeCountMap = ListUtils.emptyIfNull(authStoreCountDTOS)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(AuthStoreCountDTO::getUserId, data -> data, (a, b) -> a));
|
||||
Map<String, AuthRegionStoreDTO> authRegionStoreMap = ListUtils.emptyIfNull(authRegionStoreDTOList)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(AuthRegionStoreDTO::getUserId, data -> data, (a, b) -> a));
|
||||
|
||||
Map<String, List<UserGroupDTO>> userGroupMap = enterpriseUserGroupService.getUserGroupMap(enterpriseId, userIdList);
|
||||
Map<String, SubordinateUserRangeDTO> subordinateUserRangeMap = fillUserSubordinateNames(enterpriseId, userIdList);
|
||||
|
||||
resultList.stream()
|
||||
.forEach(data->{
|
||||
if(MapUtils.isNotEmpty(authRegionStoreMap)&&authRegionStoreMap.get(data.getUserId())!=null){
|
||||
AuthRegionStoreDTO authRegionStoreDTO = authRegionStoreMap.get(data.getUserId());
|
||||
data.setAuthRegionStoreList(authRegionStoreDTO.getAuthRegionStoreUserList());
|
||||
}
|
||||
if(MapUtils.isNotEmpty(storeCountMap)&&storeCountMap.get(data.getUserId())!=null){
|
||||
AuthStoreCountDTO authStoreCountDTO = storeCountMap.get(data.getUserId());
|
||||
if(authStoreCountDTO.getStoreCount()!=null){
|
||||
data.setStoreCount(authStoreCountDTO.getStoreCount());
|
||||
}else {
|
||||
data.setStoreCount(0);
|
||||
}
|
||||
}
|
||||
if(MapUtils.isNotEmpty(userRegionMap)&&MapUtils.isNotEmpty(regionMap)) {
|
||||
Set<String> regions = userRegionMap.get(data.getUserId());
|
||||
String deptNames = SetUtils.emptyIfNull(regions)
|
||||
@@ -191,14 +150,6 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
.collect(Collectors.joining(CommonConstants.COMMA));
|
||||
data.setDepartment(deptNames);
|
||||
}
|
||||
//填充用户分组
|
||||
data.setUserGroupList(userGroupMap.get(data.getUserId()));
|
||||
// 填充下属用户
|
||||
if (subordinateUserRangeMap.get(data.getUserId()) != null){
|
||||
data.setSubordinateUserRange(subordinateUserRangeMap.get(data.getUserId()).getSubordinateUserRange());
|
||||
data.setSourceList(subordinateUserRangeMap.get(data.getUserId()).getSourceList());
|
||||
data.setMySubordinates(subordinateUserRangeMap.get(data.getUserId()).getMySubordinates());
|
||||
}
|
||||
});
|
||||
// 添加至常用联系人
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
@@ -208,7 +159,7 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
private void addUserRegionMappingDO(String enterpriseId,String userId,String regionId,CurrentUser currentUser){
|
||||
private void addUserRegionMappingDO(String userId,String regionId,CurrentUser currentUser){
|
||||
UserRegionMappingDO userRegionMappingDO = new UserRegionMappingDO();
|
||||
userRegionMappingDO.setUserId(userId);
|
||||
userRegionMappingDO.setRegionId(regionId);
|
||||
@@ -217,88 +168,18 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
userRegionMappingDO.setCreateTime(System.currentTimeMillis());
|
||||
userRegionMappingDO.setUpdateTime(System.currentTimeMillis());
|
||||
//将用户添加到未分组
|
||||
userRegionMappingDAO.batchInsertRegionMapping(enterpriseId, Arrays.asList(userRegionMappingDO));
|
||||
userRegionMappingDAO.batchInsertRegionMapping(Arrays.asList(userRegionMappingDO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, SubordinateUserRangeDTO> fillUserSubordinateNames(String enterpriseId, List<String> userIdList) {
|
||||
Map<String, SubordinateUserRangeDTO> subordinateUserRangeMap = Maps.newHashMap();
|
||||
if (CollectionUtils.isNotEmpty(userIdList)) {
|
||||
//查询该用户的下属
|
||||
List<SubordinateMappingDO> subordinateMappingDOS = subordinateMappingDAO.selectByUserIds(enterpriseId, userIdList);
|
||||
|
||||
List<EnterpriseUserDO> enterpriseUserDOS = enterpriseUserDAO.selectUsersByUserIds(enterpriseId, userIdList);
|
||||
Map<String, String> subordinateRangeMap = ListUtils.emptyIfNull(enterpriseUserDOS).stream().collect(Collectors.toMap(EnterpriseUserDO::getUserId, EnterpriseUserDO::getSubordinateRange));
|
||||
|
||||
List<SubordinateMappingDO> defineSelectMappingLit = subordinateMappingDOS.stream().filter(x -> SubordinateSourceEnum.SELECT.getCode().equals(x.getSource())).collect(Collectors.toList());
|
||||
Map<String, List<SubordinateMappingDO>> defineSelectMappingMap = ListUtils.emptyIfNull(defineSelectMappingLit).stream()
|
||||
.collect(Collectors.groupingBy(SubordinateMappingDO::getUserId));
|
||||
userIdList.forEach(userId -> {
|
||||
SubordinateUserRangeDTO subordinateUserRangeDTO = new SubordinateUserRangeDTO();
|
||||
subordinateUserRangeMap.put(userId, subordinateUserRangeDTO);
|
||||
String subordinateUserRange = subordinateRangeMap.get(userId);
|
||||
if (StringUtils.isNotBlank(subordinateUserRange)) {
|
||||
subordinateUserRangeDTO.setSubordinateUserRange(subordinateUserRange);
|
||||
if (UserSelectRangeEnum.DEFINE.getCode().equals(subordinateUserRange)) {
|
||||
List<SubordinateMappingDO> myDefineSelectMappingLit = defineSelectMappingMap.get(userId);
|
||||
List<String> regionIds = ListUtils.emptyIfNull(myDefineSelectMappingLit).stream().filter(x -> StringUtils.isNotBlank(x.getRegionId()))
|
||||
.map(SubordinateMappingDO::getRegionId).collect(Collectors.toList());
|
||||
Map<String, String> regionMap = new HashMap<>();
|
||||
List<RegionPathDTO> regionPathByList = regionDAO.getRegionPathByList(enterpriseId, regionIds);
|
||||
regionMap = regionPathByList.stream().collect(Collectors.toMap(RegionPathDTO::getRegionId, RegionPathDTO::getRegionName));
|
||||
|
||||
List<String> personalIds = ListUtils.emptyIfNull(myDefineSelectMappingLit).stream().filter(x -> StringUtils.isNotBlank(x.getPersonalId()))
|
||||
.map(SubordinateMappingDO::getPersonalId).collect(Collectors.toList());
|
||||
|
||||
List<EnterpriseUserDO> personalList = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(personalIds)) {
|
||||
personalList = enterpriseUserDAO.selectUsersByUserIds(enterpriseId, personalIds);
|
||||
}
|
||||
Map<String, String> personalMap = personalList.stream().collect(Collectors.toMap(EnterpriseUserDO::getUserId, EnterpriseUserDO::getName));
|
||||
|
||||
List<MySubordinatesDTO> nodeTypeList = new ArrayList<>();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(myDefineSelectMappingLit)) {
|
||||
for (SubordinateMappingDO item : myDefineSelectMappingLit) {
|
||||
MySubordinatesDTO nodeTypeDTO = new MySubordinatesDTO();
|
||||
if (StringUtils.isNotBlank(item.getRegionId())) {
|
||||
String regionName = regionMap.get(item.getRegionId());
|
||||
nodeTypeDTO.setNodeType("region");
|
||||
nodeTypeDTO.setRegionName(regionName);
|
||||
nodeTypeDTO.setRegionId(item.getRegionId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(item.getPersonalId())) {
|
||||
String personalName = personalMap.get(item.getPersonalId());
|
||||
nodeTypeDTO.setNodeType("personal");
|
||||
nodeTypeDTO.setPersonalName(personalName);
|
||||
nodeTypeDTO.setPersonalId(item.getPersonalId());
|
||||
}
|
||||
nodeTypeList.add(nodeTypeDTO);
|
||||
}
|
||||
}
|
||||
List<String> sourceList = subordinateMappingDOS.stream().filter(x -> StringUtils.isNotBlank(x.getSource()))
|
||||
.map(SubordinateMappingDO::getSource).distinct().collect(Collectors.toList());
|
||||
subordinateUserRangeDTO.setSourceList(sourceList);
|
||||
if (CollectionUtils.isEmpty(sourceList)) {
|
||||
subordinateUserRangeDTO.setSourceList(Collections.singletonList(SubordinateSourceEnum.AUTO.getCode()));
|
||||
}
|
||||
subordinateUserRangeDTO.setMySubordinates(nodeTypeList);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return subordinateUserRangeMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> initUserRole(String enterpriseId, List<EnterpriseUserPageVO> enterpriseUserList) {
|
||||
public List<String> initUserRole(List<EnterpriseUserPageVO> enterpriseUserList) {
|
||||
List<String> userIdList = ListUtils.emptyIfNull(enterpriseUserList)
|
||||
.stream()
|
||||
.map(EnterpriseUserPageVO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if(CollectionUtils.isNotEmpty(userIdList)){
|
||||
List<UserRoleDTO> userRoleDTOS = enterpriseUserRoleDAO.getUserAndRolesByUserId(enterpriseId, userIdList);
|
||||
List<UserRoleDTO> userRoleDTOS = enterpriseUserRoleDAO.getUserAndRolesByUserId(userIdList);
|
||||
//封装 userId-userRole map,以表示一个用户对应几个角色
|
||||
Map<String, List<Long>> userRoleDtoMap = new HashMap<>();
|
||||
userRoleDTOS.forEach(roleDto -> {
|
||||
@@ -332,17 +213,17 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getUserRegion(String enterpriseId, List<String> userIdList) {
|
||||
public Map<String, String> getUserRegion(List<String> userIdList) {
|
||||
Map<String, String> resultMap = Maps.newHashMap();
|
||||
//根据人员查询该人员所在部门集合
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(enterpriseId, userIdList);
|
||||
List<UserRegionMappingDO> userRegionMappingDOS = userRegionMappingDAO.listUserRegionMappingByUserId(userIdList);
|
||||
//regionids 集合
|
||||
List<String> regionIds = ListUtils.emptyIfNull(userRegionMappingDOS).stream()
|
||||
.map(UserRegionMappingDO::getRegionId).distinct().collect(Collectors.toList());
|
||||
|
||||
List<RegionDO> regionDOs = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(regionIds)){
|
||||
regionDOs = regionDAO.getRegionByRegionIds(enterpriseId, regionIds);
|
||||
regionDOs = regionDAO.getRegionByRegionIds(regionIds);
|
||||
}
|
||||
//部门map KV key-部门id value-部门名称
|
||||
Map<String, String> regionMap = ListUtils.emptyIfNull(regionDOs)
|
||||
@@ -395,7 +276,7 @@ public class EnterpriseUserServiceImpl implements EnterpriseUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnterpriseUserDO selectByUserIdIgnoreActive(String enterpriseId, String userId) {
|
||||
return enterpriseUserDAO.selectByUserIdIgnoreActive(enterpriseId, userId);
|
||||
public EnterpriseUserDO selectByUserIdIgnoreActive(String userId) {
|
||||
return enterpriseUserDAO.selectByUserIdIgnoreActive(userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class LoginServiceImpl implements LoginService {
|
||||
if (enterpriseConfig == null) {
|
||||
throw new ServiceException(ErrorCodeEnum.ENTERPRISE_INIT);
|
||||
}
|
||||
EnterpriseDO enterprise = enterpriseDAO.getEnterpriseById(enterpriseConfig.getEnterpriseId());
|
||||
EnterpriseDO enterprise = enterpriseDAO.getEnterpriseById();
|
||||
if (enterprise == null || enterprise.getStatus() == CommonConstants.ZERO) {
|
||||
throw new ServiceException(ErrorCodeEnum.ENTERPRISE_INIT);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class LoginServiceImpl implements LoginService {
|
||||
// 切到企业库
|
||||
DataSourceContext.setDataSourceType(dbName);
|
||||
// 查企业用户
|
||||
EnterpriseUserDO enterpriseUser = enterpriseUserDAO.getUserInfoById(enterprise.getId(), userId);
|
||||
EnterpriseUserDO enterpriseUser = enterpriseUserDAO.getUserInfoById(userId);
|
||||
if(enterpriseUser == null){
|
||||
throw new ServiceException(ErrorCodeEnum.NOT_AUTH);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class LoginServiceImpl implements LoginService {
|
||||
if (enterprise.getStatus() == CommonConstants.HUNDRED && !StringUtils.equals(enterpriseUser.getUserId(), "a100000001")) {
|
||||
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR.getCode(), "企业被冻结");
|
||||
}
|
||||
SysRoleDO sysRole = sysRoleDAO.getHighestPrioritySysRoleDoByUserId(enterprise.getId(), userId);
|
||||
SysRoleDO sysRole = sysRoleDAO.getHighestPrioritySysRoleDoByUserId(userId);
|
||||
if(Objects.isNull(sysRole)){
|
||||
log.info("当前用户没角色:{}", userId);
|
||||
throw new ServiceException(ErrorCodeEnum.NOT_AUTH);
|
||||
@@ -120,7 +120,7 @@ public class LoginServiceImpl implements LoginService {
|
||||
redisUtilPool.setString(currentUser.getUserId(), token);
|
||||
redisUtilPool.setString(CommonConstants.REFRESH_TOKEN_KEY+":"+refreshToken,JSON.toJSONString(refreshUser), CommonConstants.REFRESH_TOKEN_EXPIRE);
|
||||
jsonObject.put("refresh_token",refreshToken);
|
||||
loginRecordDAO.addLoginRecord(currentUser.getEnterpriseId(),currentUser.getUserId());
|
||||
loginRecordDAO.addLoginRecord(currentUser.getUserId());
|
||||
log.info("[" + enterpriseUser.getName() + "; action_token:"+ token + "; userId:" + currentUser.getUserId() +"]登入系统成功");
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@@ -1,36 +1,18 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.dao.RegionDAO;
|
||||
import com.cool.store.dao.StoreDAO;
|
||||
import com.cool.store.dao.UserAuthMappingDAO;
|
||||
import com.cool.store.dto.region.RegionStoreNumMsgDTO;
|
||||
import com.cool.store.entity.RegionDO;
|
||||
import com.cool.store.entity.StoreDO;
|
||||
import com.cool.store.enums.RegionTypeEnum;
|
||||
import com.cool.store.enums.RocketMqTagEnum;
|
||||
import com.cool.store.enums.StoreIsDeleteEnum;
|
||||
import com.cool.store.enums.UserAuthMappingTypeEnum;
|
||||
import com.cool.store.mq.producer.SimpleMessageService;
|
||||
import com.cool.store.service.RegionService;
|
||||
import com.cool.store.utils.RedisConstantUtil;
|
||||
import com.cool.store.utils.RedisUtil;
|
||||
import com.cool.store.utils.UUIDUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
@@ -46,106 +28,38 @@ public class RegionServiceImpl implements RegionService {
|
||||
@Resource
|
||||
private RedisConstantUtil redisConstantUtil;
|
||||
@Resource
|
||||
private StoreDAO storeDAO;
|
||||
@Resource
|
||||
private RegionDAO regionDAO;
|
||||
@Resource
|
||||
private UserAuthMappingDAO userAuthMappingDAO;
|
||||
@Resource
|
||||
private SimpleMessageService simpleMessageService;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void saveRegionAndStore(String eid, RegionDO regionDO, String userId) {
|
||||
String storeKey = redisConstantUtil.getSyncStoreKey(eid);
|
||||
public void saveRegionAndStore(RegionDO regionDO, String userId) {
|
||||
String storeId = null;
|
||||
if(regionDO.getStoreRange()){
|
||||
StoreDO storeDO = storeDAO.getStoreBySynId(eid, regionDO.getSynDingDeptId());
|
||||
if(storeDO != null && StringUtils.isNotBlank(storeDO.getStoreId())){
|
||||
storeId = storeDO.getStoreId();
|
||||
}else {
|
||||
storeId = UUIDUtils.get32UUID();
|
||||
}
|
||||
storeId = UUIDUtils.get32UUID();
|
||||
}
|
||||
regionDO.setStoreId(storeId);
|
||||
regionDO.setRegionType(RegionTypeEnum.PATH.getType());
|
||||
RegionDO oldRegion = regionDAO.getBySynDingDeptId(eid, regionDO.getSynDingDeptId());
|
||||
RegionDO oldRegion = regionDAO.getBySynDingDeptId(regionDO.getSynDingDeptId());
|
||||
boolean isAdd = oldRegion == null;
|
||||
if (isAdd) {
|
||||
if(regionDO.getStoreRange()){
|
||||
regionDO.setStoreId(storeId);
|
||||
regionDO.setRegionType(RegionTypeEnum.STORE.getType());
|
||||
}
|
||||
regionDAO.ignoreInsert(eid, regionDO);
|
||||
regionDAO.ignoreInsert(regionDO);
|
||||
} else {
|
||||
if(regionDO.getStoreRange()){
|
||||
regionDO.setRegionType(RegionTypeEnum.STORE.getType());
|
||||
}
|
||||
regionDAO.updateSyncRegion(eid, regionDO);
|
||||
}
|
||||
if (regionDO.getStoreRange()) {
|
||||
StoreDO store = new StoreDO();
|
||||
store.setStoreName(regionDO.getName());
|
||||
store.setRegionPath(regionDO.getFullRegionPath());
|
||||
store.setIsDelete(StoreIsDeleteEnum.EFFECTIVE.getValue());
|
||||
store.setRegionId(Long.valueOf(regionDO.getParentId()));
|
||||
store.setSource("sync");
|
||||
store.setStoreAddress(regionDO.getAddress());
|
||||
store.setLocationAddress(regionDO.getAddress());
|
||||
store.setStoreNum(regionDO.getStoreCode());
|
||||
store.setLatitude(regionDO.getLatitude());
|
||||
store.setLongitude(regionDO.getLongitude());
|
||||
store.setStoreId(storeId);
|
||||
String id = redisUtil.hashGetString(storeKey, regionDO.getSynDingDeptId());
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
store.setId(Long.valueOf(id));
|
||||
//删除对应的已有redis key缓存
|
||||
redisUtil.delete(storeKey, regionDO.getSynDingDeptId());
|
||||
store.setUpdateName(userId);
|
||||
store.setUpdateTime(System.currentTimeMillis());
|
||||
storeDAO.updateStore(eid, store);
|
||||
} else {
|
||||
store.setIsLock("not_locked");
|
||||
store.setStoreStatus("open");
|
||||
store.setSynDingDeptId(regionDO.getSynDingDeptId());
|
||||
store.setCreateName(userId);
|
||||
store.setCreateTime(System.currentTimeMillis());
|
||||
storeDAO.insertStore(eid, store);
|
||||
}
|
||||
regionDAO.updateSyncRegion(regionDO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRegions(String eid, List<Long> regionIds) {
|
||||
regionDAO.removeRegion(eid, regionIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByStoreIds(String enterpriseId, List<String> storeIds, String userId) {
|
||||
//获取门店基本信息
|
||||
List<StoreDO> storeList = storeDAO.getStoreListByStoreIds(enterpriseId, storeIds);
|
||||
if (CollectionUtils.isEmpty(storeList)) {
|
||||
return;
|
||||
}
|
||||
// 删除门店绑定的权限
|
||||
userAuthMappingDAO.deleteAuthMappingByIdAndType(enterpriseId, storeIds, UserAuthMappingTypeEnum.STORE.getCode());
|
||||
// 删除门店本身
|
||||
storeDAO.deleteStoreByStoreIds(enterpriseId, storeIds, userId, Calendar.getInstance().getTimeInMillis());
|
||||
//更新区域内的门店数量
|
||||
List<Long> regionIdList = ListUtils.emptyIfNull(storeList)
|
||||
.stream()
|
||||
.map(StoreDO::getRegionId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(regionIdList)) {
|
||||
List<RegionDO> regionDOList = regionDAO.listStoreRegionByIds(enterpriseId, regionIdList);
|
||||
List<Long> updateRegionIdList = ListUtils.emptyIfNull(regionDOList)
|
||||
.stream()
|
||||
.map(data -> StrUtil.splitTrim(data.getFullRegionPath(), "/"))
|
||||
.flatMap(Collection::stream)
|
||||
.map(Long::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
simpleMessageService.send(JSONObject.toJSONString(new RegionStoreNumMsgDTO(enterpriseId, updateRegionIdList)), RocketMqTagEnum.REGION_STORE_NUM_UPDATE);
|
||||
}
|
||||
public void removeRegions(List<Long> regionIds) {
|
||||
regionDAO.removeRegion(regionIds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.dao.EnterpriseUserDAO;
|
||||
import com.cool.store.dao.EnterpriseUserRoleDAO;
|
||||
import com.cool.store.dao.SubordinateMappingDAO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.entity.SubordinateMappingDO;
|
||||
import com.cool.store.entity.UserAuthMappingDO;
|
||||
import com.cool.store.enums.SubordinateSourceEnum;
|
||||
import com.cool.store.enums.UserSelectRangeEnum;
|
||||
import com.cool.store.mapper.EnterpriseUserMapper;
|
||||
import com.cool.store.mapper.UserAuthMappingMapper;
|
||||
import com.cool.store.service.EnterpriseUserService;
|
||||
import com.cool.store.service.SubordinateMappingService;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author wxp
|
||||
* @Date 2023/1/6 11:18
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SubordinateMappingServiceImpl implements SubordinateMappingService {
|
||||
|
||||
@Resource
|
||||
private SubordinateMappingDAO subordinateMappingDAO;
|
||||
@Autowired
|
||||
private EnterpriseUserService enterpriseUserService;
|
||||
@Resource
|
||||
private EnterpriseUserMapper enterpriseUserMapper;
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
@Resource
|
||||
private EnterpriseUserRoleDAO enterpriseUserRoleDAO;
|
||||
@Resource
|
||||
private UserAuthMappingMapper userAuthMappingMapper;
|
||||
|
||||
/**
|
||||
* 判断用户是否管辖全部用户
|
||||
* @param enterpriseId
|
||||
* @param currentUserId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean checkHaveAllSubordinateUser(String enterpriseId, String currentUserId) {
|
||||
if(CommonConstants.SYSTEM_USER_ID.equals(currentUserId)){
|
||||
return true;
|
||||
}
|
||||
// 判断是否是管理员
|
||||
boolean isAdmin = enterpriseUserRoleDAO.checkIsAdmin(enterpriseId, currentUserId);
|
||||
EnterpriseUserDO user = enterpriseUserDAO.getUserInfoById(enterpriseId, currentUserId);
|
||||
//失效人员没有权限
|
||||
if(user == null){
|
||||
return false;
|
||||
}
|
||||
if(isAdmin || UserSelectRangeEnum.ALL.getCode().equals(user.getSubordinateRange())){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管辖用户
|
||||
* @param enterpriseId
|
||||
* @param currentUserId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSubordinateUserIdList(String enterpriseId, String currentUserId,Boolean addCurrentFlag) {
|
||||
|
||||
List<String> allUserIdList = Lists.newArrayList();
|
||||
if (addCurrentFlag){
|
||||
allUserIdList.add(currentUserId);
|
||||
}
|
||||
EnterpriseUserDO user = enterpriseUserDAO.getUserInfoById(enterpriseId, currentUserId);
|
||||
// 查询管辖用户
|
||||
List<SubordinateMappingDO> subordinateMappingList = subordinateMappingDAO.selectByUserIds(enterpriseId, Collections.singletonList(currentUserId));
|
||||
// 如果用户关联用户配置是自定义,但是没有具体数据,默认关联区域门店区域权限下的人
|
||||
if(user != null && UserSelectRangeEnum.DEFINE.getCode().equals(user.getSubordinateRange()) && CollectionUtils.isEmpty(subordinateMappingList)){
|
||||
subordinateMappingList = Lists.newArrayList();
|
||||
SubordinateMappingDO subordinateMappingDO = fillDefaultAutoSubordinate(currentUserId, UserSelectRangeEnum.DEFINE.getCode(), SubordinateSourceEnum.AUTO.getCode());
|
||||
subordinateMappingList.add(subordinateMappingDO);
|
||||
subordinateMappingDAO.batchInsertSubordinateMapping(enterpriseId, subordinateMappingList);
|
||||
}
|
||||
|
||||
List<String> sourceList = ListUtils.emptyIfNull(subordinateMappingList).stream().filter(x -> StringUtils.isNotBlank(x.getSource()))
|
||||
.map(SubordinateMappingDO::getSource).distinct().collect(Collectors.toList());
|
||||
|
||||
//自动关联单独查询 过滤自动关联
|
||||
subordinateMappingList = ListUtils.emptyIfNull(subordinateMappingList).stream().filter(o -> !SubordinateSourceEnum.AUTO.getCode().equals(o.getSource())).collect(Collectors.toList());
|
||||
|
||||
List<String> regionIds = ListUtils.emptyIfNull(subordinateMappingList).stream().filter(x -> StringUtils.isNotBlank(x.getRegionId()))
|
||||
.map(SubordinateMappingDO::getRegionId).collect(Collectors.toList());
|
||||
List<String> personalIds = ListUtils.emptyIfNull(subordinateMappingList).stream().filter(x -> StringUtils.isNotBlank(x.getPersonalId()))
|
||||
.map(SubordinateMappingDO::getPersonalId).collect(Collectors.toList());
|
||||
if(CollectionUtils.isNotEmpty(personalIds)) {
|
||||
allUserIdList.addAll(personalIds);
|
||||
}
|
||||
|
||||
if(CollectionUtils.isNotEmpty(sourceList) && sourceList.contains(SubordinateSourceEnum.AUTO.getCode())) {
|
||||
List<UserAuthMappingDO> userAuthList = userAuthMappingMapper.listUserAuthMappingByUserId(enterpriseId, currentUserId);
|
||||
List<String> authRegionIdList = ListUtils.emptyIfNull(userAuthList)
|
||||
.stream().map(UserAuthMappingDO::getMappingId)
|
||||
.collect(Collectors.toList());
|
||||
regionIds.addAll(authRegionIdList);
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(regionIds)) {
|
||||
List<EnterpriseUserDO> enterpriseUserDOList = enterpriseUserMapper.listByRegionIdList(enterpriseId, regionIds);
|
||||
if (CollectionUtils.isNotEmpty(enterpriseUserDOList)) {
|
||||
List<String> enterpriseUserIds = enterpriseUserDOList.stream()
|
||||
.map(EnterpriseUserDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
allUserIdList.addAll(enterpriseUserIds);
|
||||
}
|
||||
}
|
||||
allUserIdList = allUserIdList.stream().distinct().collect(Collectors.toList());
|
||||
return allUserIdList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保留管辖用户 userId管辖用户范围
|
||||
* @param enterpriseId
|
||||
* @param currentUserId
|
||||
* @param userIdList
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> retainSubordinateUserIdList(String enterpriseId, String currentUserId, List<String> userIdList,Boolean addCurrentFlag) {
|
||||
Boolean flag = this.checkHaveAllSubordinateUser(enterpriseId, currentUserId);
|
||||
if(flag){
|
||||
return userIdList;
|
||||
}
|
||||
List<String> subordinateUserIdList = getSubordinateUserIdList(enterpriseId, currentUserId,addCurrentFlag);
|
||||
userIdList.retainAll(subordinateUserIdList);
|
||||
return userIdList;
|
||||
}
|
||||
|
||||
|
||||
private SubordinateMappingDO fillDefaultAutoSubordinate(String userId, String userRange, String source) {
|
||||
SubordinateMappingDO subordinateMappingDO = new SubordinateMappingDO();
|
||||
subordinateMappingDO.setUserId(userId);
|
||||
subordinateMappingDO.setRegionId(CommonConstants.ZERO_STR);
|
||||
subordinateMappingDO.setCreateId(CommonConstants.SYSTEM_USER_ID);
|
||||
subordinateMappingDO.setUpdateId(CommonConstants.SYSTEM_USER_ID);
|
||||
subordinateMappingDO.setType(CommonConstants.ZERO);
|
||||
subordinateMappingDO.setUserRange(userRange);
|
||||
subordinateMappingDO.setSource(source);
|
||||
return subordinateMappingDO;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user