feat:门店人员
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.dto.StoreDTO;
|
||||
import com.cool.store.entity.StoreDO;
|
||||
import com.cool.store.dto.store.StoreUserPositionDTO;
|
||||
import com.cool.store.response.MiniShopsResponse;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/5/13 9:56
|
||||
@@ -25,4 +23,6 @@ public interface StoreService {
|
||||
|
||||
PageInfo<MiniShopsResponse> getStoreListByMobile(String mobile,Integer pageNum,Integer pageSize,String storeName,String storeNum);
|
||||
|
||||
PageInfo<StoreUserPositionDTO> getStoreUser(Integer pageSize, Integer pageNum);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,29 +1,40 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.cool.store.dto.store.AuthStoreUserDTO;
|
||||
import com.cool.store.dao.EnterpriseUserDAO;
|
||||
import com.cool.store.dao.EnterpriseUserRoleDao;
|
||||
import com.cool.store.dao.StoreDao;
|
||||
import com.cool.store.dao.SysRoleDao;
|
||||
import com.cool.store.dto.StoreDTO;
|
||||
import com.cool.store.dto.store.StoreAreaDTO;
|
||||
import com.cool.store.dto.store.StoreUserDTO;
|
||||
import com.cool.store.dto.store.StoreUserPositionDTO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.entity.StoreDO;
|
||||
import com.cool.store.entity.SysRoleDO;
|
||||
import com.cool.store.entity.UserAuthMappingDO;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.enums.ExtendFieldTypeEnum;
|
||||
import com.cool.store.enums.*;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.mapper.RegionMapper;
|
||||
import com.cool.store.mapper.StoreMapper;
|
||||
import com.cool.store.mapper.SysRoleMapper;
|
||||
import com.cool.store.mapper.UserAuthMappingMapper;
|
||||
import com.cool.store.response.MiniShopsResponse;
|
||||
import com.cool.store.service.StoreService;
|
||||
import com.cool.store.service.UserAuthMappingService;
|
||||
import com.cool.store.utils.poi.constant.Constants;
|
||||
import com.cool.store.vo.SysRoleVO;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.Data;
|
||||
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.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -51,6 +62,12 @@ public class StoreServiceImpl implements StoreService {
|
||||
private UserAuthMappingService userAuthMappingService;
|
||||
@Resource
|
||||
private RegionMapper regionMapper;
|
||||
@Resource
|
||||
SysRoleMapper sysRoleMapper;
|
||||
@Resource
|
||||
StoreMapper storeMapper;
|
||||
@Resource
|
||||
UserAuthMappingMapper userAuthMappingMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<StoreDTO> getStoreExtendFieldInfo(Integer pageSize, Integer pageNum) {
|
||||
@@ -92,6 +109,192 @@ public class StoreServiceImpl implements StoreService {
|
||||
return new PageInfo<>(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<StoreUserPositionDTO> getStoreUser(Integer pageSize, Integer pageNum) {
|
||||
if (pageSize>=100){
|
||||
throw new ServiceException(ErrorCodeEnum.ERROR_MESSAGE,"单次最多获取100条门店数据");
|
||||
}
|
||||
PageHelper.startPage(pageNum,pageSize);
|
||||
List<StoreDO> list = storeDao.list();
|
||||
PageInfo info = new PageInfo<>(list);
|
||||
if (CollectionUtils.isEmpty(list)){
|
||||
return info;
|
||||
}
|
||||
List<StoreUserPositionDTO> result = new ArrayList<>();
|
||||
list.forEach(x->{
|
||||
StoreUserPositionDTO storeUserPositionDTO = new StoreUserPositionDTO();
|
||||
List<StoreUserDTO> storeUserPosition = this.getStoreUserPositionDTO(x.getStoreId());
|
||||
Map<String, List<StoreUserDTO>> storeUserDTOMap = ListUtils.emptyIfNull(storeUserPosition).stream().collect(Collectors.groupingBy(k -> k.getUserId()));
|
||||
storeUserPositionDTO.setStoreId(x.getStoreId());
|
||||
storeUserPositionDTO.setStoreName(x.getStoreName());
|
||||
storeUserPositionDTO.setShopCode(x.getStoreNum());
|
||||
List<StoreUserDTO> userList = Lists.newArrayList();
|
||||
for (String userId : storeUserDTOMap.keySet()) {
|
||||
List<StoreUserDTO> singleUserDTOList = storeUserDTOMap.get(userId);
|
||||
if(CollectionUtils.isEmpty(singleUserDTOList)){
|
||||
continue;
|
||||
}
|
||||
StoreUserDTO storeUserDTO = singleUserDTOList.get(0);
|
||||
List<String> positionNameList = ListUtils.emptyIfNull(singleUserDTOList)
|
||||
.stream().map(StoreUserDTO::getPositionName).collect(Collectors.toList());
|
||||
storeUserDTO.setPositionName(String.join(Constants.COMMA, positionNameList));
|
||||
userList.add(storeUserDTO);
|
||||
}
|
||||
storeUserPositionDTO.setUserList(userList);
|
||||
result.add(storeUserPositionDTO);
|
||||
});
|
||||
info.setList(result);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<StoreUserDTO> getStoreUserPositionDTO(String storeId){
|
||||
if (StrUtil.isBlank(storeId)) {
|
||||
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR.getCode(), "请选择门店后查询");
|
||||
}
|
||||
List<AuthStoreUserDTO> authStoreUserDTOList = this.authStoreUser(
|
||||
Collections.singletonList(storeId), "store_inside");
|
||||
|
||||
if (CollectionUtils.isEmpty(authStoreUserDTOList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> userIdList = ListUtils.emptyIfNull(authStoreUserDTOList)
|
||||
.stream()
|
||||
.map(AuthStoreUserDTO::getUserIdList)
|
||||
.flatMap(Collection::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(userIdList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<StoreUserDTO> result = sysRoleMapper.userAndPositionList( userIdList, null, "store_inside");
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<AuthStoreUserDTO> authStoreUser(List<String> storeIdList, String positionType) {
|
||||
List<AuthStoreUserDTO> result = new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(storeIdList)) {
|
||||
return result;
|
||||
}
|
||||
//将拥有管理员角色、角色属性为全企业数据的人查询出来
|
||||
List<SysRoleVO> roleUserByRoleId = sysRoleMapper.getRoleUserByRoleEnum(Role.MASTER.getRoleEnum(),positionType);
|
||||
List<SysRoleVO> roleUserByRoleAuth = sysRoleMapper.getRoleUserByRoleAuth(AuthRoleEnum.ALL.getCode(),positionType);
|
||||
//组合出拥有所有门店信息的人
|
||||
List<String> allStoreUserIdList = getAllStoreUserIdList(roleUserByRoleId, roleUserByRoleAuth);
|
||||
//查询出有门店权限配置的的人员
|
||||
// 1.将门店区域切分出门店所属于的区域ID
|
||||
// 2.将配置了区域的人 查询出来
|
||||
// 3.将配置了门店的人 查询出来
|
||||
List<StoreAreaDTO> storeAreaList = storeMapper.getStoreAreaList(storeIdList);
|
||||
if (CollectionUtils.isEmpty(storeAreaList)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<String> fullAreaIdList = ListUtils.emptyIfNull(storeAreaList)
|
||||
.stream()
|
||||
.map(StoreAreaDTO::getAreaIdList)
|
||||
.flatMap(Collection::stream)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
List<String> lastAreaIdList = ListUtils.emptyIfNull(storeAreaList)
|
||||
.stream()
|
||||
.map(StoreAreaDTO::getAreaId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//除不包含子区域的可视化范围的区域配置。
|
||||
List<UserAuthMappingDO> regionUserAuthMappingList = userAuthMappingMapper.listUserAuthMappingByAuth(
|
||||
UserAuthMappingTypeEnum.REGION.getCode(), fullAreaIdList, positionType, AuthRoleEnum.NOT_INCLUDE_SUBORDINATE.getCode());
|
||||
//不包含子区域的的直属连接门店的区域下的配置(会重复一些选择了上面数据)
|
||||
List<UserAuthMappingDO> notIncludeRegionUserAuthMappingList = userAuthMappingMapper.listUserAuthMappingByAuth(
|
||||
UserAuthMappingTypeEnum.REGION.getCode(), lastAreaIdList, positionType, null);
|
||||
//配置了门店的的配置
|
||||
List<UserAuthMappingDO> storeUserAuthMappingList = userAuthMappingMapper.listUserAuthMappingByMappingList(
|
||||
storeIdList, UserAuthMappingTypeEnum.STORE.getCode());
|
||||
return ListUtils.emptyIfNull(storeAreaList)
|
||||
.stream()
|
||||
.map(data -> mapAuthStoreUserDTO(regionUserAuthMappingList, allStoreUserIdList, storeUserAuthMappingList, notIncludeRegionUserAuthMappingList, data))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<String> getAllStoreUserIdList(List<SysRoleVO> roleUserByRoleId, List<SysRoleVO> roleUserByRoleAuth) {
|
||||
List<String> allUserIdList= new ArrayList<>();
|
||||
List<String> masterUserList = ListUtils.emptyIfNull(roleUserByRoleId).stream()
|
||||
.map(SysRoleVO::getEnterpriseDOs)
|
||||
.flatMap(Collection::stream)
|
||||
.map(EnterpriseUserDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
List<String> roleAllUserList = ListUtils.emptyIfNull(roleUserByRoleAuth).stream()
|
||||
.map(SysRoleVO::getEnterpriseDOs)
|
||||
.flatMap(Collection::stream)
|
||||
.map(EnterpriseUserDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(masterUserList)) {
|
||||
allUserIdList.addAll(masterUserList);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(roleAllUserList)) {
|
||||
allUserIdList.addAll(roleAllUserList);
|
||||
}
|
||||
return ListUtils.emptyIfNull(allUserIdList)
|
||||
.stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
private AuthStoreUserDTO mapAuthStoreUserDTO(
|
||||
List<UserAuthMappingDO> regionUserAuthMappingList,
|
||||
List<String> allStoreUserIdList,
|
||||
List<UserAuthMappingDO> storeUserAuthMappingList,
|
||||
List<UserAuthMappingDO> notIncludeRegionUserAuthMappingList,
|
||||
StoreAreaDTO data) {
|
||||
|
||||
//组装全部的人员信息
|
||||
List<String> authStoreIdList = new ArrayList<>();
|
||||
AuthStoreUserDTO authStoreUserDTO = new AuthStoreUserDTO();
|
||||
authStoreUserDTO.setStoreId(data.getStoreId());
|
||||
authStoreUserDTO.setStoreName(data.getStoreName());
|
||||
//组装拥有所有门店信息的人
|
||||
if (CollectionUtils.isNotEmpty(allStoreUserIdList)) {
|
||||
authStoreIdList.addAll(allStoreUserIdList);
|
||||
}
|
||||
//组装配置了区域权限的人(除了不包含子区域可视化范围)
|
||||
List<String> storeAreaIdList = data.getAreaIdList();
|
||||
List<String> regionUserIdList = ListUtils.emptyIfNull(regionUserAuthMappingList).stream()
|
||||
.filter(area -> storeAreaIdList.contains(area.getMappingId()))
|
||||
.map(UserAuthMappingDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(regionUserIdList)) {
|
||||
authStoreIdList.addAll(regionUserIdList);
|
||||
}
|
||||
//组装配置了区域权限的人(不包含子区域可视化范围)
|
||||
List<String> notIncludeRegionUserIdList = ListUtils.emptyIfNull(notIncludeRegionUserAuthMappingList).stream()
|
||||
.filter(area -> StringUtils.equals(data.getAreaId(), area.getMappingId()))
|
||||
.map(UserAuthMappingDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(notIncludeRegionUserIdList)) {
|
||||
authStoreIdList.addAll(notIncludeRegionUserIdList);
|
||||
}
|
||||
//组装配置了门店权限的人
|
||||
List<String> storeUserIdList = ListUtils.emptyIfNull(storeUserAuthMappingList).stream()
|
||||
.filter(store -> StringUtils.equals(store.getMappingId(), data.getStoreId()))
|
||||
.map(UserAuthMappingDO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(storeUserIdList)) {
|
||||
authStoreIdList.addAll(storeUserIdList);
|
||||
}
|
||||
|
||||
//去除重复数据
|
||||
List<String> distinctUserIdList = ListUtils.emptyIfNull(authStoreIdList).stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
authStoreUserDTO.setUserIdList(distinctUserIdList);
|
||||
return authStoreUserDTO;
|
||||
}
|
||||
|
||||
|
||||
public static List<StoreDTO> processStores(List<StoreDO> stores) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
Reference in New Issue
Block a user