Commit 38b0ddab by 刘鑫

feat(容量): 容量计算逻辑

1 parent 3829dfac
......@@ -12,6 +12,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Set;
@Repository
public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integer>, JpaSpecificationExecutor<EngineerInfoEntity> {
......@@ -37,13 +38,30 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
return (root, query, criteriaBuilder) -> root.get("engineerCode").in(engineerCodes);
}
/**
* 根据技能、产品、产品类型 分站ID获取分站下用户对应技能的技术员
*
* @param brand 产品
* @param productType 产品类型
* @param skill 技能
* @param groupId 分站ID
* @return 工程师信息
*/
@Query(value = "SELECT ei.* FROM skill_info si LEFT JOIN skill_group sg ON sg.skill_group_code =si.skill_group_code "
+ " LEFT JOIN engineer_skill_group esg ON sg.skill_group_code = esg.skill_group_code "
+ " LEFT JOIN engineer_info ei ON esg.engineer_code = ei.engineer_code "
+ " WHERE si.brand = :brand AND si.type= :productType AND si.skill = :skill "
+ " AND group_id = :groupId ", nativeQuery = true)
Set<EngineerInfoEntity> listByBrandAndTypeAndSkillAndGroupId(@Param("brand") String brand, @Param("productType") String productType,
@Param("skill") String skill, @Param("groupId") String groupId);
@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);
@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 " +
......@@ -51,7 +69,7 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
" 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);
@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 " +
......@@ -59,5 +77,5 @@ public interface EngineerInfoDao extends JpaRepository<EngineerInfoEntity, Integ
" 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);
@Param("skill") String skill, @Param("engineerCodes") List<String> engineerCodes);
}
package com.dituhui.pea.order.entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Date;
@Data
@Entity
@Table(name="engineer_info")
@Table(name = "engineer_info")
@EqualsAndHashCode
public class EngineerInfoEntity {
/**
* 工程师id
......@@ -112,5 +113,6 @@ public class EngineerInfoEntity {
*/
private LocalDateTime updateTime = LocalDateTime.now();
public EngineerInfoEntity() {}
public EngineerInfoEntity() {
}
}
......@@ -2,7 +2,23 @@ package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.CapacityOrderQueryDTO;
import com.dituhui.pea.order.dto.param.CapacityQueryDTO;
import com.dituhui.pea.order.dto.param.Location;
import java.time.LocalDate;
import java.util.List;
public interface CapacityQueryService {
Result<?> queryMatchCapacityData(CapacityOrderQueryDTO.Request capacityQueryReqDTO);
/**
* 对外创单可用容量查询
*
* @param services 服务技能信息, 包含品牌, 产品类型, 服务技能
* @param location 需要查询容量的地址
* @param beginDate 开始日期
* @param endDate 结束日期
* @return 满足对应技能工作队的容量(三种类型与工作队绑定)
*/
Result<?> matchCapacityData(List<CapacityQueryDTO.Service> services, Location location, LocalDate beginDate, LocalDate endDate);
}
package com.dituhui.pea.order.service.impl;
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.DateUtils;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.common.SaasUtils;
import com.dituhui.pea.order.dao.CapacityEngineerStatDao;
import com.dituhui.pea.order.dao.EngineerSkillDao;
import com.dituhui.pea.order.dao.OrgTeamDao;
import com.dituhui.pea.order.dao.SkillInfoDao;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.CapacityOrderQueryDTO;
import com.dituhui.pea.order.dto.param.CapacityQueryDTO;
import com.dituhui.pea.order.dto.param.Location;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.feign.ISaaSRemoteService;
import com.dituhui.pea.order.service.CapacityQueryService;
import com.dituhui.pea.pojo.fendan.FendanDTO;
import com.google.common.collect.Sets;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -23,6 +26,7 @@ import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -47,6 +51,63 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
@Autowired
ISaaSRemoteService saasRemoteService;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Override
public Result<?> matchCapacityData(List<CapacityQueryDTO.Service> services, Location location, LocalDate beginDate, LocalDate endDate) {
//TODO 转换品牌、产品类型、 技能代码为对应汉字
//1:根据经纬度分单获取面
FendanDTO fendanDTO = new FendanDTO();
final String addressLongLat = location.getLongitude() + "," + location.getLatitude();
fendanDTO.setXy(addressLongLat);
List<SaasUtils.BlockInfo> blockInfoList = saasUtils.queryBlocksByXy(fendanDTO);
if (blockInfoList.isEmpty()) {
return Result.failed(StatusCodeEnum.FENDAN_AREA_UNMATCHED);
}
//2:根据查询出区划匹配分站信息
List<String> blockIds = blockInfoList.stream().map(SaasUtils.BlockInfo::getBlockId).distinct().collect(Collectors.toList());
// List<MapBlockInfoEntity> mapBlockInfoEntities = mapBlockInfoDao.findByBlockIdIn(blockIds);
List<MapBlockInfoEntity> mapBlockInfoEntities = new ArrayList<>();
if (CollectionUtils.isEmpty(mapBlockInfoEntities)) {
return Result.failed(StatusCodeEnum.FENDAN_TEAM_UNMATCHED);
}
//分站、网点ID
List<String> groupIdList = mapBlockInfoEntities.stream().map(MapBlockInfoEntity::getGroupId).distinct()
.collect(Collectors.toList());
final String groupId = groupIdList.get(0);
//3. 查询分站下拥有对应技能的工程师(排重) todo 技能码转换为对应的技能汉字
List<CapacityQueryDTO.Service> convertServices = services;
List<SkillInfoEntity> querySkillGroup = new ArrayList<>();
Set<EngineerInfoEntity> allFulfillEngineer = Sets.newConcurrentHashSet();
for (CapacityQueryDTO.Service service : convertServices) {
Set<EngineerInfoEntity> engineerInfoEntities = engineerInfoDao.listByBrandAndTypeAndSkillAndGroupId(service.getBrand(),
service.getProductType(), service.getServiceType(), groupId);
//查询对应的技能信息
SkillInfoEntity skillInfo = skillInfoDao.getByBrandAndTypeAndSkill(service.getBrand(),
service.getProductType(), service.getServiceType());
querySkillGroup.add(skillInfo);
allFulfillEngineer.addAll(engineerInfoEntities);
}
log.info("[matchCapacityData]【符合技能要求的工程师总数为:{} 个】", allFulfillEngineer.size());
//TODO 计算所有查询技能的所需耗时 (querySkillGroup)
//TODO 查询单个工程师日期范围内的技能容量信息 后加和汇总
return null;
}
//TODO 计算单个工程师 单日 多技能容量
private void reckonEngineerDaySkillsVolume(LocalDate date, EngineerInfoEntity engineerInfo) {
//TODO
}
@Override
public Result<?> queryMatchCapacityData(CapacityOrderQueryDTO.Request reqDTO) {
// 单条容量查询
......@@ -63,7 +124,7 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
}
if (blockIds.isEmpty()) {
log.error("分单接口没有查到对应的结果");
return Result.failed(String.format("分单接口(address:%s)(location:%s) 没有查到配置区块", reqDTO.getAddress(), reqDTO.getLocation()));
return Result.failed(String.format("分单接口(address:%s)(location:%s) 没有查到配置区块", reqDTO.getAddress(), reqDTO.getLocation()));
}
List<String> teamIds = capacityUtils.getTeamIdsByBlockIdsAndLayerIds(blockIds, layerIds);
if (teamIds == null || teamIds.isEmpty()) {
......@@ -180,8 +241,8 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
return calendar;
}
private String fixBrand(String brand){
if (!brand.equals("嘉格纳")){
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!