Commit 261a14d2 by huangjinxin

feat:分单接口初版

1 parent 42c1f55c
...@@ -21,7 +21,7 @@ import com.dituhui.pea.enums.StatusCodeEnum; ...@@ -21,7 +21,7 @@ import com.dituhui.pea.enums.StatusCodeEnum;
/** /**
* 响应返回实体类型 * 响应返回实体类型
* *
* @param <T> 返回业务实际类型泛型定义 * @param <T> 返回业务实际类型泛型定义
* @author TrevorLink * @author TrevorLink
*/ */
public class Result<T> { public class Result<T> {
...@@ -29,17 +29,17 @@ public class Result<T> { ...@@ -29,17 +29,17 @@ public class Result<T> {
/** /**
* 业务响应状态代码 * 业务响应状态代码
*/ */
private String code; private String code;
/** /**
* 业务响应状态描述 * 业务响应状态描述
*/ */
private String message; private String message;
/** /**
* 业务响应信息承载体 * 业务响应信息承载体
*/ */
private T result; private T result;
public static <T> Result<T> success(T result) { public static <T> Result<T> success(T result) {
return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), result); return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), result);
...@@ -74,6 +74,11 @@ public class Result<T> { ...@@ -74,6 +74,11 @@ public class Result<T> {
return new Result<>(resultEnum.getCode(), resultEnum.getDesc(), result); return new Result<>(resultEnum.getCode(), resultEnum.getDesc(), result);
} }
public static <T> Result<T> failed(StatusCodeEnum resultEnum) {
return new Result<>(resultEnum.getCode(), resultEnum.getDesc(), null);
}
public Result() { public Result() {
} }
......
...@@ -124,7 +124,11 @@ public enum StatusCodeEnum { ...@@ -124,7 +124,11 @@ public enum StatusCodeEnum {
USER_EMAIL_ERROR("020", "邮箱格式有误", false), USER_EMAIL_ERROR("020", "邮箱格式有误", false),
USER_ORG_NULL_ERROR("021", "组织结构异常或为空", false); USER_ORG_NULL_ERROR("021", "组织结构异常或为空", false),
FENDAN_TEAM_UNMATCHED("022", "分单接口没有匹配到工作队", false),
FENDAN_AREA_UNMATCHED("023", "分单接口没有查到配置区块", false);
/** /**
* 状态码 * 状态码
......
...@@ -24,4 +24,11 @@ public class FendanDTO { ...@@ -24,4 +24,11 @@ public class FendanDTO {
private Boolean needDistrict = false; private Boolean needDistrict = false;
/**
* 是否返回区划的边界点
*/
private Boolean needPoints = false;
} }
...@@ -82,7 +82,9 @@ public class SaasUtils { ...@@ -82,7 +82,9 @@ public class SaasUtils {
public List<BlockInfo> queryBlocksByXy(FendanDTO fendanDTO) { public List<BlockInfo> queryBlocksByXy(FendanDTO fendanDTO) {
long t = System.currentTimeMillis(); long t = System.currentTimeMillis();
log.info("===> queryBlocksByXySingleT({})", t); log.info("===> queryBlocksByXySingleT({})", t);
SaasWebResult webResult = saasRemoteService.single(ak, String.valueOf(t), fendanDTO); String webResultStr = saasRemoteService.single(ak, fendanDTO);
log.info("queryBlocksByXySingle返回结果: ===> {}", webResultStr);
SaasWebResult webResult = JSONObject.parseObject(webResultStr, SaasWebResult.class);
log.info("queryBlocksByXySingle返回结果: ===> {}", webResult.getResult()); log.info("queryBlocksByXySingle返回结果: ===> {}", webResult.getResult());
List<BlockInfo> blocks = new ArrayList<>(); List<BlockInfo> blocks = new ArrayList<>();
if (!webResult.getCode().equals("S001")) { if (!webResult.getCode().equals("S001")) {
......
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.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;
@RestController
@RequestMapping("/pea-order")
public class FendanController {
@Autowired
private FendanService fendanService;
@RequestMapping(value = "fendan", method = RequestMethod.POST)
public Result<?> fendan(@RequestBody OrderDTO.OrderCreateRequest request) {
return fendanService.fendan(request);
}
}
...@@ -2,11 +2,13 @@ package com.dituhui.pea.order.dao; ...@@ -2,11 +2,13 @@ package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.EngineerInfoEntity; import com.dituhui.pea.order.entity.EngineerInfoEntity;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
...@@ -34,4 +36,20 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ ...@@ -34,4 +36,20 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
static Specification<EngineerInfoEntity> engineerCodeIn(List<String> engineerCodes) { static Specification<EngineerInfoEntity> engineerCodeIn(List<String> engineerCodes) {
return (root, query, criteriaBuilder) -> root.get("engineerCode").in(engineerCodes); return (root, query, criteriaBuilder) -> root.get("engineerCode").in(engineerCodes);
} }
@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_code = :skillCode and ei.group_id in ( :teamIds ) " +
" order by mlc.priority ", nativeQuery = true)
List<EngineerInfoEntity> listBrandAndSkillCodeAndTeamIdIn(@Param("brand") String brand, @Param("productType") String productType,
@Param("skillCode") String skillCode, @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.group_id in ( :teamIds ) " +
" 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);
} }
...@@ -19,4 +19,6 @@ public interface MapBlockInfoDao extends JpaRepository<MapBlockInfoEntity, Integ ...@@ -19,4 +19,6 @@ public interface MapBlockInfoDao extends JpaRepository<MapBlockInfoEntity, Integ
List<MapBlockInfoEntity> findByLayerId(String layerId); List<MapBlockInfoEntity> findByLayerId(String layerId);
MapBlockInfoEntity findByTeamIdAndLayerId(String teamId, String layerId); MapBlockInfoEntity findByTeamIdAndLayerId(String teamId, String layerId);
List<MapBlockInfoEntity> findByBlockIdIn(List<String> blockIds);
} }
package com.dituhui.pea.order.dao; package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.OrgGroupEntity; import com.dituhui.pea.order.entity.OrgGroupEntity;
import org.apache.ibatis.annotations.Param;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository @Repository
@Where(clause = "status = 1") @Where(clause = "status = 1")
public interface OrgGroupDao extends JpaRepository<OrgGroupEntity, Integer> { public interface OrgGroupDao extends JpaRepository<OrgGroupEntity, Integer> {
List<OrgGroupEntity> findAllByBranchId(String branchId); List<OrgGroupEntity> findAllByBranchId(String branchId);
List<OrgGroupEntity> findAllByBranchIdIn(List<String> branchId); List<OrgGroupEntity> findAllByBranchIdIn(List<String> branchId);
List<OrgGroupEntity> findAllByClusterId(String clusterId); List<OrgGroupEntity> findAllByClusterId(String clusterId);
List<OrgGroupEntity> findAllByClusterIdIn(List<String> clusterId); List<OrgGroupEntity> findAllByClusterIdIn(List<String> clusterId);
List<OrgGroupEntity> findAllByGroupId(String groupId); List<OrgGroupEntity> findAllByGroupId(String groupId);
List<OrgGroupEntity> findAllByGroupIdIn(List<String> groupId); List<OrgGroupEntity> findAllByGroupIdIn(List<String> groupId);
OrgGroupEntity getByGroupId(String groupId); OrgGroupEntity getByGroupId(String groupId);
public List<OrgGroupEntity> findByGroupIdIn(List<String> ids); public List<OrgGroupEntity> findByGroupIdIn(List<String> ids);
@Query(value = "SELECT * from org_group og left join org_team ot on og.group_id = ot.group_id WHERE ot.team_id in (:teamIds) order by og.category ", nativeQuery = true)
List<OrgGroupEntity> findByTeamIdIn(@Param("teamIds") List<String> teamIds);
} }
...@@ -4,10 +4,7 @@ import com.dituhui.pea.common.SaasWebResult; ...@@ -4,10 +4,7 @@ import com.dituhui.pea.common.SaasWebResult;
import com.dituhui.pea.pojo.fendan.FenDanEsResult; import com.dituhui.pea.pojo.fendan.FenDanEsResult;
import com.dituhui.pea.pojo.fendan.FendanDTO; import com.dituhui.pea.pojo.fendan.FendanDTO;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(url = "${SaaS.url}", name = "saasService") @FeignClient(url = "${SaaS.url}", name = "saasService")
public interface ISaaSRemoteService { public interface ISaaSRemoteService {
...@@ -37,5 +34,7 @@ public interface ISaaSRemoteService { ...@@ -37,5 +34,7 @@ public interface ISaaSRemoteService {
@PostMapping("/saas/fendan/distribute/single") @PostMapping("/saas/fendan/distribute/single")
public SaasWebResult single(@RequestParam String ak, @RequestParam String t, @RequestBody FendanDTO fendanDTO); public String single(@RequestParam String ak, @RequestBody FendanDTO fendanDTO);
//@PostMapping("/saas/fendan/distribute/single")
//public SaasWebResult single(@RequestParam("ak") String ak, @RequestParam("t") String t, @RequestBody FendanDTO fendanDTO);
} }
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.OrgTeamInfo;
import com.dituhui.pea.pojo.fendan.FendanDTO;
import java.util.List;
public interface FendanService {
/**
* 分单接口
*
* @param request
* @return
*/
Result<List<OrgTeamInfo>> fendan(OrderDTO.OrderCreateRequest request);
}
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.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.service.FendanService;
import com.dituhui.pea.pojo.fendan.FendanDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
public class FendanServiceImpl implements FendanService {
@Autowired
private SaasUtils saasUtils;
@Autowired
private OrgTeamDao orgTeamDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Override
public Result<List<OrgTeamInfo>> fendan(OrderDTO.OrderCreateRequest request) {
List<OrgTeamInfo> orgTeamInfos = 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:匹配工作队
String peaBrand = fixBrand(request.getBrand());
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<EngineerInfoEntity> engineerInfoList = engineerInfoDao.listBrandAndSkillAndTeamIdIn(peaBrand, request.getProductType(), request.getServiceType(), teamIdList);
//4:单个工程师不需要进行派单优先级排序
List<OrgTeamEntity> teamList = orgTeamDao.findByTeamIdIn(teamIdList);
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());
OrgTeamInfo orgTeamInfo = BeanUtil.copyProperties(orgTeamEntity, OrgTeamInfo.class);
orgTeamInfo.setEngineerInfoList(engineerInfoList);
orgTeamInfos.add(orgTeamInfo);
return Result.success(orgTeamInfos);
}
//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());
OrgTeamInfo orgTeamInfo = BeanUtil.copyProperties(orgTeamEntity, OrgTeamInfo.class);
orgTeamInfo.setEngineerInfoList(Arrays.asList(engineerInfoEntity));
orgTeamInfos.add(orgTeamInfo);
}
return Result.success(orgTeamInfos);
}
//6:如果筛选出多个工程师则进行优先级排序
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;
}
OrgTeamInfo orgTeamInfo = BeanUtil.copyProperties(orgTeamEntity, OrgTeamInfo.class);
orgTeamInfo.setEngineerInfoList(Arrays.asList(engineerInfoList.get(i)));
orgTeamInfos.add(orgTeamInfo);
}
}
}
return Result.success(orgTeamInfos);
}
/**
* 筛选品牌
*
* @param brand
* @return
*/
private String fixBrand(String brand) {
if (!brand.equals("嘉格纳")) {
return "博世/西门子以及其他品牌";
} else {
return brand;
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!