Commit 49e54b1d by huangjinxin

fix:分单接口优化

feat:分单到分部,小队
1 parent 261a14d2
......@@ -128,7 +128,9 @@ public enum StatusCodeEnum {
FENDAN_TEAM_UNMATCHED("022", "分单接口没有匹配到工作队", false),
FENDAN_AREA_UNMATCHED("023", "分单接口没有查到配置区块", false);
FENDAN_AREA_UNMATCHED("023", "分单接口没有查到配置区块", false),
FENDAN_ENGINEER_UNMATCHED("023", "分单接口没有查到配置工程师", false);
/**
* 状态码
......
......@@ -2,14 +2,17 @@ package com.dituhui.pea.order.controller;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.param.OrderDTO;
import com.dituhui.pea.order.dto.param.OrgGroupInfo;
import com.dituhui.pea.order.dto.param.OrgTeamInfo;
import com.dituhui.pea.order.service.FendanService;
import com.dituhui.pea.pojo.fendan.FendanDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/pea-order")
public class FendanController {
......@@ -18,7 +21,12 @@ public class FendanController {
private FendanService fendanService;
@RequestMapping(value = "fendan", method = RequestMethod.POST)
public Result<?> fendan(@RequestBody OrderDTO.OrderCreateRequest request) {
public Result<List<OrgTeamInfo>> fendan(@RequestBody OrderDTO.OrderCreateRequest request) {
return fendanService.fendan(request);
}
@RequestMapping(value = "fendanToGroup", method = RequestMethod.POST)
public Result<List<OrgGroupInfo>> fendanToGroup(@RequestBody OrderDTO.OrderCreateRequest request) {
return fendanService.fendanToGroup(request);
}
}
......@@ -52,4 +52,12 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
" order by mlc.priority ", nativeQuery = true)
List<EngineerInfoEntity> listBrandAndSkillAndTeamIdIn(@Param("brand") String brand, @Param("productType") String productType,
@Param("skill") String skill, @Param("teamIds") List<String> teamIds);
@Query(value = "SELECT ei.* from engineer_info ei left join engineer_skill_group esg on ei.engineer_code = esg.engineer_code " +
"left join skill_info si on si.skill_group_code = esg.skill_group_code left join map_layer_customize mlc on mlc.layer_id = si.layer_id " +
" WHERE si.brand = :brand and si.`type` = :productType and si.skill = :skill and ei.engineer_code in ( :engineerCodes ) " +
" order by mlc.priority ", nativeQuery = true)
List<EngineerInfoEntity> listBrandAndSkillAndEngineerCodes(@Param("brand") String brand, @Param("productType") String productType,
@Param("skill") String skill, @Param("engineerCodes") List<String> engineerCodes);
}
package com.dituhui.pea.order.dto.param;
import lombok.Data;
import java.util.List;
@Data
public class OrgGroupInfo {
/**
* id
*/
private Integer id;
/**
* 小组id
*/
private String groupId;
/**
* 小组名称
*/
private String groupName;
/**
* 归属大区
*/
private String clusterId;
/**
* 归属分部
*/
private String branchId;
/**
* 办公地址
*/
private String address;
/**
* 办公地址经度
*/
private String x;
/**
* 办公地址纬度
*/
private String y;
/**
* 小组所在城市code
*/
private String cityCode;
/**
* 类型(1分站,2外围,3小组,4网点,5自保点)
*/
private Integer kind;
/**
* 类型(1自有,2加盟)
*/
private Integer category;
/**
* 默认配件仓
*/
private String warehouseId;
/**
* 备注
*/
private String memo;
public OrgGroupInfo() {
}
private List<OrgTeamInfo> teamInfos;
}
......@@ -31,10 +31,6 @@ public class OrgTeamInfo {
private String memo;
private LocalDateTime createTime;
private LocalDateTime updateTime;
private String workOn;
private String workOff;
......
......@@ -2,8 +2,8 @@ package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.param.OrderDTO;
import com.dituhui.pea.order.dto.param.OrgGroupInfo;
import com.dituhui.pea.order.dto.param.OrgTeamInfo;
import com.dituhui.pea.pojo.fendan.FendanDTO;
import java.util.List;
......@@ -16,4 +16,12 @@ public interface FendanService {
* @return
*/
Result<List<OrgTeamInfo>> fendan(OrderDTO.OrderCreateRequest request);
/**
* 分单到分部,分部包含工作队
*
* @param request
* @return
*/
Result<List<OrgGroupInfo>> fendanToGroup(OrderDTO.OrderCreateRequest request);
}
......@@ -3,15 +3,12 @@ package com.dituhui.pea.order.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.order.common.CapacityUtils;
import com.dituhui.pea.order.common.SaasUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.param.OrderDTO;
import com.dituhui.pea.order.dto.param.OrgGroupInfo;
import com.dituhui.pea.order.dto.param.OrgTeamInfo;
import com.dituhui.pea.order.entity.EngineerInfoEntity;
import com.dituhui.pea.order.entity.MapBlockInfoEntity;
import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.entity.OrgTeamEntity;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.service.FendanService;
import com.dituhui.pea.pojo.fendan.FendanDTO;
import lombok.extern.slf4j.Slf4j;
......@@ -36,6 +33,8 @@ public class FendanServiceImpl implements FendanService {
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrgTeamEngineerDao orgTeamEngineerDao;
@Override
public Result<List<OrgTeamInfo>> fendan(OrderDTO.OrderCreateRequest request) {
......@@ -48,7 +47,7 @@ public class FendanServiceImpl implements FendanService {
return Result.failed(StatusCodeEnum.FENDAN_AREA_UNMATCHED);
}
//2:匹配工作队
//2:根据查询出区划匹配工作队
String peaBrand = fixBrand(request.getBrand());
List<String> blockIds = blockInfos.stream().map(SaasUtils.BlockInfo::getBlockId).distinct().collect(Collectors.toList());
List<MapBlockInfoEntity> mapBlockInfoEntities = mapBlockInfoDao.findByBlockIdIn(blockIds);
......@@ -58,25 +57,41 @@ public class FendanServiceImpl implements FendanService {
//3:根据服务类型,技能组等信息匹配工程师
List<String> teamIdList = mapBlockInfoEntities.stream().map(MapBlockInfoEntity::getTeamId).distinct().collect(Collectors.toList());
List<EngineerInfoEntity> engineerInfoList = engineerInfoDao.listBrandAndSkillAndTeamIdIn(peaBrand, request.getProductType(), request.getServiceType(), teamIdList);
List<OrgTeamEngineerEntity> teamEngineer = orgTeamEngineerDao.findAllByTeamIdIn(teamIdList);
if (CollectionUtils.isEmpty(teamEngineer)) {
return Result.failed(StatusCodeEnum.FENDAN_ENGINEER_UNMATCHED);
}
//4:根据工作队和关联关系匹配工程师
List<String> engineerCodes = teamEngineer.stream().map(OrgTeamEngineerEntity::getEngineerCode).distinct().collect(Collectors.toList());
List<EngineerInfoEntity> engineerInfoList = engineerInfoDao.listBrandAndSkillAndEngineerCodes(peaBrand, request.getProductType(), request.getServiceType(), engineerCodes);
if (CollectionUtils.isEmpty(engineerInfoList)) {
return Result.failed(StatusCodeEnum.FENDAN_ENGINEER_UNMATCHED);
}
//4:单个工程师不需要进行派单优先级排序
//5:单个工程师或团队直接返回
for (EngineerInfoEntity engineerInfoEntity : engineerInfoList) {
engineerInfoEntity.setCreateTime(null);
engineerInfoEntity.setUpdateTime(null);
}
List<OrgTeamEntity> teamList = orgTeamDao.findByTeamIdIn(teamIdList);
Map<String, String> engineerInfoCodeTeamMap = teamEngineer.stream().collect(Collectors.toMap(OrgTeamEngineerEntity::getEngineerCode, OrgTeamEngineerEntity::getTeamId));
Map<String, OrgTeamEntity> teamMap = teamList.stream().collect(Collectors.toMap(OrgTeamEntity::getTeamId, e -> e));
if (engineerInfoList.size() == 1 || teamList.size() == 1) {
OrgTeamEntity orgTeamEntity = engineerInfoList.size() != 1 ? teamList.get(0) : teamMap.get(engineerInfoList.get(0).getGroupId());
OrgTeamEntity orgTeamEntity = engineerInfoList.size() != 1 ? teamList.get(0) :
teamMap.get(engineerInfoCodeTeamMap.get(engineerInfoList.get(0).getEngineerCode()));
OrgTeamInfo orgTeamInfo = BeanUtil.copyProperties(orgTeamEntity, OrgTeamInfo.class);
orgTeamInfo.setEngineerInfoList(engineerInfoList);
orgTeamInfos.add(orgTeamInfo);
return Result.success(orgTeamInfos);
}
//5:单个工作队或工程师直接返回
//5:所有分站/网点只有同一优先级直接返回
List<OrgGroupEntity> orgGroupList = orgGroupDao.findByTeamIdIn(teamIdList);
Set<Integer> categorySet = orgGroupList.stream().map(e -> e.getCategory()).collect(Collectors.toSet());
if (categorySet.size() == 1) {
for (EngineerInfoEntity engineerInfoEntity : engineerInfoList) {
OrgTeamEntity orgTeamEntity = teamMap.get(engineerInfoEntity.getGroupId());
OrgTeamEntity orgTeamEntity = teamMap.get(engineerInfoCodeTeamMap.get(engineerInfoEntity.getEngineerCode()));
OrgTeamInfo orgTeamInfo = BeanUtil.copyProperties(orgTeamEntity, OrgTeamInfo.class);
orgTeamInfo.setEngineerInfoList(Arrays.asList(engineerInfoEntity));
orgTeamInfos.add(orgTeamInfo);
......@@ -84,26 +99,57 @@ public class FendanServiceImpl implements FendanService {
return Result.success(orgTeamInfos);
}
//6:如果筛选出多个工程师则进行优先级排序
//6:如果筛选出多个分站/网点,多级派单顺序的话进行优先级排序
Map<String, List<OrgTeamEngineerEntity>> orgTeamEngineerInfoCodeMap = teamEngineer.stream().collect(Collectors.groupingBy(OrgTeamEngineerEntity::getTeamId));
Map<String, List<OrgTeamEntity>> orgTeamMap = teamList.stream().collect(Collectors.groupingBy(OrgTeamEntity::getGroupId));
for (OrgGroupEntity orgGroup : orgGroupList) {
if (!orgTeamMap.containsKey(orgGroup.getGroupId())) {
continue;
}
for (OrgTeamEntity orgTeamEntity : orgTeamMap.get(orgGroup.getGroupId())) {
for (int i = 0; i < engineerInfoList.size(); i++) {
if (!orgTeamEntity.getTeamId().equals(engineerInfoList.get(i).getGroupId())) {
continue;
for (OrgTeamEngineerEntity orgTeamEngineerEntity : orgTeamEngineerInfoCodeMap.get(orgTeamEntity)) {
for (int i = 0; i < engineerInfoList.size(); i++) {
if (!orgTeamEngineerEntity.getEngineerCode().equals(engineerInfoList.get(i).getEngineerCode())) {
continue;
}
OrgTeamInfo orgTeamInfo = BeanUtil.copyProperties(orgTeamEntity, OrgTeamInfo.class);
orgTeamInfo.setEngineerInfoList(Arrays.asList(engineerInfoList.get(i)));
orgTeamInfos.add(orgTeamInfo);
}
OrgTeamInfo orgTeamInfo = BeanUtil.copyProperties(orgTeamEntity, OrgTeamInfo.class);
orgTeamInfo.setEngineerInfoList(Arrays.asList(engineerInfoList.get(i)));
orgTeamInfos.add(orgTeamInfo);
}
}
}
return Result.success(orgTeamInfos);
}
@Override
public Result<List<OrgGroupInfo>> fendanToGroup(OrderDTO.OrderCreateRequest request) {
List<OrgGroupInfo> orgGroupTeamInfos = new ArrayList<>();
//1:根据经纬度分单获取面
FendanDTO fendanDTO = new FendanDTO();
fendanDTO.setXy(request.getLocation().getLongitude() + "," + request.getLocation().getLatitude());
List<SaasUtils.BlockInfo> blockInfos = saasUtils.queryBlocksByXy(fendanDTO);
if (blockInfos.isEmpty()) {
return Result.failed(StatusCodeEnum.FENDAN_AREA_UNMATCHED);
}
//2:匹配工作队
List<String> blockIds = blockInfos.stream().map(SaasUtils.BlockInfo::getBlockId).distinct().collect(Collectors.toList());
List<MapBlockInfoEntity> mapBlockInfoEntities = mapBlockInfoDao.findByBlockIdIn(blockIds);
if (CollectionUtils.isEmpty(mapBlockInfoEntities)) {
return Result.failed(StatusCodeEnum.FENDAN_TEAM_UNMATCHED);
}
//3:匹配分部
List<String> teamIdList = mapBlockInfoEntities.stream().map(MapBlockInfoEntity::getTeamId).distinct().collect(Collectors.toList());
List<OrgTeamEntity> teamList = orgTeamDao.findByTeamIdIn(teamIdList);
List<OrgGroupEntity> orgGroupList = orgGroupDao.findByTeamIdIn(teamIdList);
for (OrgGroupEntity orgGroupEntity : orgGroupList) {
OrgGroupInfo orgGroup = BeanUtil.copyProperties(orgGroupEntity, OrgGroupInfo.class);
List<OrgTeamInfo> orgTeamInfoList = teamList.stream().filter(e -> e.getGroupId().equals(orgGroup.getGroupId())).map(e -> BeanUtil.copyProperties(e, OrgTeamInfo.class)).collect(Collectors.toList());
orgGroup.setTeamInfos(orgTeamInfoList);
orgGroupTeamInfos.add(orgGroup);
}
return Result.success(orgGroupTeamInfos);
}
/**
* 筛选品牌
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!