Merge #67 into master from cc_20260320_openapi_modify
fix:获取门店信息开放接口返回门店运营顾问 * cc_20260320_openapi_modify: (1 commits squashed) - fix:获取门店信息开放接口返回门店运营顾问 Signed-off-by: 王非凡 <accounts_67eba0c5fee9c49c80c8e2b4@mail.teambition.com> Merged-by: 正新 <accounts_6964c7bcd2a2c377c5bbd01b@mail.teambition.com> CR-link: https://codeup.aliyun.com/692ea314dec569489f6f167c/hangzhou/java/custom_zxjp/change/67
This commit is contained in:
@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
@@ -80,4 +81,7 @@ public class StoreDTO {
|
||||
|
||||
@ApiModelProperty("招商经理手机号")
|
||||
private String investManagerMobile;
|
||||
|
||||
@ApiModelProperty("运营顾问列表")
|
||||
private List<UserSimpleDTO> operationsConsultant;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.cool.store.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户简单信息DTO
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2026/3/20
|
||||
*/
|
||||
@Data
|
||||
public class UserSimpleDTO {
|
||||
@ApiModelProperty("用户id")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("手机号")
|
||||
private String mobile;
|
||||
|
||||
private String storeId;
|
||||
|
||||
public UserSimpleDTO(String userId, String storeId) {
|
||||
this.userId = userId;
|
||||
this.storeId = storeId;
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,5 @@ public class OpenApiStoreRequest {
|
||||
|
||||
private Integer pageNum;
|
||||
|
||||
|
||||
private Boolean queryOperations;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface StoreService {
|
||||
* @param pageNum
|
||||
* @return
|
||||
*/
|
||||
PageInfo<StoreDTO> getStoreExtendFieldInfo(Integer pageSize,Integer pageNum);
|
||||
PageInfo<StoreDTO> getStoreExtendFieldInfo(Integer pageSize,Integer pageNum, Boolean queryOperations);
|
||||
|
||||
/**
|
||||
* 分页查询接入物联网的门店
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.UserSimpleDTO;
|
||||
import com.cool.store.dto.store.StoreAreaDTO;
|
||||
import com.cool.store.dto.store.StoreUserDTO;
|
||||
import com.cool.store.dto.store.StoreUserPositionDTO;
|
||||
@@ -79,9 +80,11 @@ public class StoreServiceImpl implements StoreService {
|
||||
EnterpriseUserGroupMappingMapper enterpriseUserGroupMappingMapper;
|
||||
@Resource
|
||||
StoreMasterSignerInfoDAO storeMasterSignerInfoDAO;
|
||||
@Resource
|
||||
EnterpriseUserRoleMapper enterpriseUserRoleMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<StoreDTO> getStoreExtendFieldInfo(Integer pageSize, Integer pageNum) {
|
||||
public PageInfo<StoreDTO> getStoreExtendFieldInfo(Integer pageSize, Integer pageNum, Boolean queryOperations) {
|
||||
if (pageSize>200){
|
||||
throw new ServiceException(ErrorCodeEnum.ERROR_MESSAGE,"单次最多获取200条门店数据");
|
||||
}
|
||||
@@ -105,7 +108,13 @@ public class StoreServiceImpl implements StoreService {
|
||||
List<RegionDO> regionList = regionMapper.getByIds(new ArrayList<>(regionIds));
|
||||
Map<Long, String> regionNameMap = regionList.stream().collect(Collectors.toMap(RegionDO::getId, RegionDO::getName));
|
||||
|
||||
List<StoreDTO> storeDTOS = processStores(list, regionNameMap,userNameMap);
|
||||
// 批量查询门店对应的运营顾问
|
||||
Map<String, List<UserSimpleDTO>> operationsConsultantMap = null;
|
||||
if (Boolean.TRUE.equals(queryOperations)) {
|
||||
operationsConsultantMap = getOperationsConsultantMap(list);
|
||||
}
|
||||
|
||||
List<StoreDTO> storeDTOS = processStores(list, regionNameMap, userNameMap, operationsConsultantMap);
|
||||
info.setList(storeDTOS);
|
||||
return info;
|
||||
}
|
||||
@@ -434,8 +443,90 @@ public class StoreServiceImpl implements StoreService {
|
||||
return authStoreUserDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量查询门店对应的运营顾问
|
||||
* 优化:拆分复杂SQL为多个简单查询,在内存中组装
|
||||
*
|
||||
* @param storeList 门店列表
|
||||
* @return 门店ID -> 运营顾问列表
|
||||
*/
|
||||
private Map<String, List<UserSimpleDTO>> getOperationsConsultantMap(List<StoreDO> storeList) {
|
||||
if (CollectionUtils.isEmpty(storeList)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
public static List<StoreDTO> processStores(List<StoreDO> stores,Map<Long, String> regionMap,Map<String, EnterpriseUserDO> userMap) {
|
||||
// 查询运营顾问角色的用户ID列表
|
||||
Long roleId = UserRoleEnum.SUPERVISION.getCode();
|
||||
List<String> consultantUserIds = enterpriseUserRoleMapper.selectUserIdsByRoleId(String.valueOf(roleId));
|
||||
if (CollectionUtils.isEmpty(consultantUserIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
// 查询这些用户的权限映射(门店/区域)
|
||||
List<UserAuthMappingDO> userAuthMappings = userAuthMappingMapper.listUserAuthMappingByUserIdList(consultantUserIds);
|
||||
if (CollectionUtils.isEmpty(userAuthMappings)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
// 构建用户权限映射(按用户ID分组)
|
||||
Map<String, List<UserAuthMappingDO>> userAuthMap = CollStreamUtil.groupByKey(userAuthMappings, UserAuthMappingDO::getUserId);
|
||||
|
||||
// 构建门店ID集合和门店regionPath映射,用于快速匹配
|
||||
Map<String, String> storeRegionPathMap = CollStreamUtil.toMap(storeList, StoreDO::getStoreId, s -> s.getRegionPath() == null ? "" : s.getRegionPath());
|
||||
|
||||
List<UserSimpleDTO> resultUserList = new ArrayList<>();
|
||||
for (String userId : consultantUserIds) {
|
||||
List<UserAuthMappingDO> authList = userAuthMap.get(userId);
|
||||
if (CollectionUtils.isEmpty(authList)) {
|
||||
continue;
|
||||
}
|
||||
// 遍历门店,匹配该用户有权限的门店
|
||||
for (Map.Entry<String, String> entry : storeRegionPathMap.entrySet()) {
|
||||
String storeId = entry.getKey();
|
||||
String regionPath = entry.getValue();
|
||||
boolean isMatch = false;
|
||||
for (UserAuthMappingDO auth : authList) {
|
||||
if ("store".equals(auth.getType()) && storeId.equals(auth.getMappingId())) {
|
||||
// 方式1: 用户配置了门店权限,直接匹配
|
||||
isMatch = true;
|
||||
break;
|
||||
} else if ("region".equals(auth.getType()) && StringUtils.isNotBlank(regionPath)) {
|
||||
// 方式2: 用户配置了区域权限,匹配 region_path
|
||||
String regionId = auth.getMappingId();
|
||||
if (regionPath.contains("/" + regionId + "/")) {
|
||||
isMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isMatch) {
|
||||
resultUserList.add(new UserSimpleDTO(userId, storeId));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(resultUserList)) {
|
||||
List<String> userIds = resultUserList.stream()
|
||||
.map(UserSimpleDTO::getUserId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
List<EnterpriseUserDO> userInfoList = enterpriseUserMapper.searchUserByUserIdsAndKeyword(userIds, null);
|
||||
Map<String, EnterpriseUserDO> userInfoMap = CollStreamUtil.toMap(userInfoList, EnterpriseUserDO::getUserId, u -> u);
|
||||
|
||||
return resultUserList.stream()
|
||||
.filter(v -> userInfoMap.containsKey(v.getUserId()))
|
||||
.peek(v -> {
|
||||
EnterpriseUserDO user = userInfoMap.get(v.getUserId());
|
||||
v.setMobile(user.getMobile());
|
||||
v.setName(user.getName());
|
||||
}).collect(Collectors.groupingBy(UserSimpleDTO::getStoreId));
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
|
||||
public static List<StoreDTO> processStores(List<StoreDO> stores, Map<Long, String> regionMap,
|
||||
Map<String, EnterpriseUserDO> userMap,
|
||||
Map<String, List<UserSimpleDTO>> operationsConsultantMap) {
|
||||
// 处理每个门店
|
||||
return stores.stream().map(store -> {
|
||||
StoreDTO dto = BeanUtil.toBean(store, StoreDTO.class);
|
||||
@@ -459,6 +550,10 @@ public class StoreServiceImpl implements StoreService {
|
||||
dto.setInvestManager(enterpriseUserDO.getUserId());
|
||||
dto.setInvestManagerMobile(enterpriseUserDO.getMobile());
|
||||
}
|
||||
// 设置运营顾问
|
||||
if (operationsConsultantMap != null) {
|
||||
dto.setOperationsConsultant(operationsConsultantMap.getOrDefault(store.getStoreId(), Collections.emptyList()));
|
||||
}
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class OpenApiController {
|
||||
@ApiOperation("获取门店信息")
|
||||
@PostMapping("/getStoreList")
|
||||
public ApiResponse<PageInfo<StoreDTO>> getStoreList(@RequestBody @Validated OpenApiStoreRequest dto) {
|
||||
return ApiResponse.success(storeService.getStoreExtendFieldInfo(dto.getPageSize(),dto.getPageNum()));
|
||||
return ApiResponse.success(storeService.getStoreExtendFieldInfo(dto.getPageSize(),dto.getPageNum(), dto.getQueryOperations()));
|
||||
}
|
||||
|
||||
@ApiOperation("获取接入物联网门店信息")
|
||||
|
||||
Reference in New Issue
Block a user