Commit a438f777 by 丁伟峰

创建订单之前的容量查询,改用新的数据表和逻辑实现

1 parent df81069f
Showing with 219 additions and 152 deletions
package com.dituhui.pea.order.common;
import com.dituhui.pea.order.dao.MapBlockInfoDao;
import com.dituhui.pea.order.dao.SkillInfoDao;
import com.dituhui.pea.order.entity.MapBlockInfoEntity;
import com.dituhui.pea.order.entity.SkillInfoEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component
@Slf4j
public class CapacityUtils {
@Autowired
private SkillInfoDao skillInfoDao;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
public List<String> getTeamIdsByBlockIdsAndLayerIds(List<String> blockIds, List<String> layerIds) {
List<String> teamIds = mapBlockInfoDao.findByBlockIdInAndLayerIdIn(blockIds, layerIds).stream().map(MapBlockInfoEntity::getTeamId).collect(Collectors.toList());
log.info("根据输入信息返回对应的可能的工作队列表({}/{}) ===> {}", blockIds, layerIds, teamIds);
return teamIds;
}
public List<String> getLayers(String brand, String type, String skill) {
List<String> layers = new ArrayList<>();
SkillInfoEntity entity = skillInfoDao.getByBrandAndTypeAndSkill(brand, type, skill);
if (entity != null) {
layers.add(entity.getLayerId());
}
return layers;
}
}
......@@ -2,18 +2,39 @@ package com.dituhui.pea.order.common;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.Locale;
public class DateUtil {
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATETIME;
public class DateUtils {
public static String toWeekChinese(String date) {
LocalDate d = LocalDate.parse(date);
return DateUtil.toWeekChinese(d.getDayOfWeek().getValue());
return DateUtils.toWeekChinese(d.getDayOfWeek().getValue());
}
public static String toWeekChinese(int dayOfWeek) {
// TextStyle: SHORT 周一;LONG 星期一;NARROW 一
return DayOfWeek.of(dayOfWeek).getDisplayName(TextStyle.SHORT, Locale.CHINESE);
}
public static String formatDateTime(LocalDateTime d, String format){
return d.format(DateTimeFormatter.ofPattern(format));
}
public static String formatDateTime(LocalDateTime d){
return formatDateTime(d, PATTERN_DATETIME);
}
public static String formatDate(LocalDate d, String format){
return d.format(DateTimeFormatter.ofPattern(format));
}
public static String formatDate(LocalDate d){
return formatDate(d, PATTERN_DATE);
}
}
......@@ -22,7 +22,7 @@ import java.util.List;
import java.util.stream.Collectors;
@Component
public class EngineerUtil {
public class EngineerUtils {
@Autowired
private OrgTeamEngineerDao orgTeamEngineerDao;
......@@ -72,6 +72,7 @@ public class EngineerUtil {
private Specification<EngineerInfoEntity> buildSpecification(String keyword) {
// 动态查询
return new Specification<EngineerInfoEntity>() {
@Override
public Predicate toPredicate(Root<EngineerInfoEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
......
package com.dituhui.pea.order.common;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
@Component
@Slf4j
public class SaasUtils {
/**
* 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空
*/
public List<BlockInfo> queryBlocks(String location, String address) {
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例
log.info("===> queryBlocks({}, {})", location, address);
RestTemplate restTemplate = new RestTemplate();
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// 构建请求参数
String url;
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
params.add("ak", "284c57cbabad4755a9c657885a8df3e2");
if (StringUtils.isNotEmpty(location)) {
url = "https://pea-test.bshg.com.cn/v1/xyfendan";
String[] coordinates = location.split(",");
params.add("coordinate", String.format("{\"x\":%s, \"y\":%s}", coordinates[0], coordinates[1]));
} else {
url = "https://pea-test.bshg.com.cn/v2/fendan";
params.add("addresses", String.format("[{\"address\":\"%s\"}]", address));
}
params.add("need_district", "false");
params.add("need_layer", "true");
// params.add("related_point_fields", "");
params.add("area_fields", "名称,唯一编号,区块");
log.info("request params ==> {}", params);
// 构建请求实体
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
// 发送POST请求
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
// 获取响应结果
String responseBody = responseEntity.getBody();
log.info("after call saas ==> {}", responseEntity.getBody());
// 使用Jackson库解析JSON数据
ObjectMapper objectMapper = new ObjectMapper();
try {
List<BlockInfo> blocks = new ArrayList<>();
JsonNode responseJson = objectMapper.readTree(responseBody);
// 获取areaResults[0]的值
for (JsonNode r : responseJson.get("result").get(0).get("areaResults")) {
// 分单接口暂时无图层返回
blocks.add(new BlockInfo().setBlockId(r.get("field3").asText()).setBlockName(r.get("field1").asText()));
}
return blocks;
} catch (Exception e) {
return null;
}
}
public List<String> queryBlockIds(String location, String address) {
return queryBlocks(location, address).stream().map(BlockInfo::getBlockId).collect(Collectors.toList());
}
@lombok.Data
@Accessors(chain = true)
static class BlockInfo {
private String layer;
private String blockId;
private String blockName;
}
}
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dituhui.pea.order.controller;
import com.dituhui.pea.common.BusinessException;
......@@ -63,7 +47,7 @@ public class OrderCreateController {
public Result<?> capacityQuery(@Validated @RequestBody CapacityOrderQueryDTO.Request reqDTO) {
Result<?> res = null;
try {
res = capacityQueryService.getOneCapacityData(reqDTO);
res = capacityQueryService.queryMatchCapacityData(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
......
......@@ -3,7 +3,11 @@ package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.CapacityEngineerStatEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface CapacityEngineerStatDao extends JpaRepository<CapacityEngineerStatEntity, Integer> {
CapacityEngineerStatEntity getByEngineerCodeAndWorkday(String engineerCode, String workday);
CapacityEngineerStatEntity getByWorkdayAndEngineerCode(String workday, String engineerCode);
List<CapacityEngineerStatEntity> getByWorkdayAndEngineerCodeIn(String workday, List<String> engineerCodes);
}
package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.EngineerSkillEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface EngineerSkillDao extends JpaRepository<EngineerSkillEntity, Long> {
List<EngineerSkillEntity> findAllByBrandAndTypeAndSkillAndEngineerCodeIn(String brand, String type, String skill, List<String> engineerCodes);
}
......@@ -6,10 +6,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@Where(clause = "status = 1")
public interface MapBlockInfoDao extends JpaRepository<MapBlockInfoEntity, Integer> {
@Query("select s.teamId from MapBlockInfoEntity s where s.blockId = :blockId and s.layer = :layer")
String getTeamIdByBlockIdAndLayer(String blockId, String layer);
List<MapBlockInfoEntity> findByBlockIdInAndLayerIdIn(List<String> blockIds, List<String> layerIds);
}
......@@ -10,4 +10,5 @@ import java.util.List;
public interface SkillInfoDao extends JpaRepository<SkillInfoEntity, Long> {
List<SkillInfoEntity> findAll();
Page<SkillInfoEntity> findAll(Pageable pageable);
SkillInfoEntity getByBrandAndTypeAndSkill(String brand, String type, String skill);
}
package com.dituhui.pea.order.entity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@Entity
@Table(name="v_engineer_skill")
public class EngineerSkillEntity {
@Id
@GeneratedValue
private Long id;
private String engineerCode;
private String skillGroupCode;
private String brand;
private String type;
private String skill;
}
......@@ -2,9 +2,7 @@ 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.CapacityStatQueryDTO;
import com.fasterxml.jackson.core.JsonProcessingException;
public interface CapacityQueryService {
Result<?> getOneCapacityData(CapacityOrderQueryDTO.Request capacityQueryReqDTO);
Result<?> queryMatchCapacityData(CapacityOrderQueryDTO.Request capacityQueryReqDTO);
}
......@@ -6,9 +6,6 @@ import java.util.List;
public interface CommonService {
String getTeamIdByInput(String location, String address, String layer);
void addOrderEvent(String orderId, String subOrderId, String source, String operator, String event, String content, String memo);
List<LabelValueDTO> getSpecialParams(String catalog, String biztype);
......
......@@ -2,7 +2,7 @@ package com.dituhui.pea.order.service.impl;
import cn.hutool.core.util.IdUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.DateUtil;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.OrgGroupEntity;
......@@ -89,7 +89,7 @@ public class BusinessTeamServiceImpl implements BusinessTeamService {
List<String> days = Arrays.asList(workDays.split(","));
Collections.sort(days);
return days.stream().map(e -> {
return DateUtil.toWeekChinese(Integer.parseInt(e));
return DateUtils.toWeekChinese(Integer.parseInt(e));
}).collect(Collectors.toList());
}
......
......@@ -31,113 +31,11 @@ import java.util.stream.Collectors;
public class CommonServiceImpl implements CommonService {
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Autowired
private CapacityTeamStatDao capacityTeamStatDao;
@Autowired
private OrderEventDao orderEventDao;
@Autowired
private PubParamsDao pubParamsDao;
public String getTeamIdByInput(String location, String address, String layer) {
// todo 目前会随机兜底,后面将合理化
log.info("====== getTeamIdByInput ===");
String teamId = null;
List<LayerAndArea> layerAndAreas = getLayerAndAreas(location, address);
if (layerAndAreas == null || layerAndAreas.size() == 0) {
// 分单接口没有查到,本地随机处理一下
teamId = capacityTeamStatDao.getRandomTeamIdByLayer(layer);
log.info("分单接口没有查到,本地随机处理一下 ==> {}", teamId);
} else {
// 分单接口查到了areaId(blockId),查询map_block_info,从而限定groupId,然后再随机teamId,这样就相对真实一点
// 生成随机索引
int randomIndex = new Random().nextInt(layerAndAreas.size());
// 获取随机元素
LayerAndArea layerAndArea = layerAndAreas.get(randomIndex);
teamId = mapBlockInfoDao.getTeamIdByBlockIdAndLayer(layerAndArea.areaId, layer);
log.info("分单接口查询返回区块,layerAndArea=={}, teamId=={}", layerAndArea, teamId);
}
if (StringUtils.isEmpty(teamId)) {
teamId = capacityTeamStatDao.getRandomTeamId();
log.info("查询没有teamId,需要随机生成teamId=={}", teamId);
}
log.info("teamId ==> {}", teamId);
assert (StringUtils.isNotEmpty(teamId));
return teamId;
}
/**
* 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空
* 目前layer_info表中,area_data是保存位置围栏的json数据,后面可能会是对于其他图层的引用;
*
* @param location
* @return
*/
private List<LayerAndArea> getLayerAndAreas(String location, String address) {
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例
log.info("===> getLayerAndAreas({}, {})", location, address);
RestTemplate restTemplate = new RestTemplate();
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// 构建请求参数
String url;
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
params.add("ak", "284c57cbabad4755a9c657885a8df3e2");
if (StringUtils.isNotEmpty(location)) {
url = "https://pea-test.bshg.com.cn/v1/xyfendan";
String[] coordinates = location.split(",");
params.add("coordinate", String.format("{\"x\":%s, \"y\":%s}", coordinates[0], coordinates[1]));
} else {
url = "https://pea-test.bshg.com.cn/v2/fendan";
params.add("addresses", String.format("[{\"address\":\"%s\"}]", address));
}
params.add("need_district", "false");
params.add("need_layer", "true");
// params.add("related_point_fields", "");
params.add("area_fields", "名称,唯一编号,区块");
log.info("request params ==> {}", params);
// 构建请求实体
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
// 发送POST请求
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
// 获取响应结果
String responseBody = responseEntity.getBody();
log.info("after call saas ==> {}", responseEntity.getBody());
// 使用Jackson库解析JSON数据
ObjectMapper objectMapper = new ObjectMapper();
try {
List<LayerAndArea> results = new ArrayList<>();
JsonNode responseJson = objectMapper.readTree(responseBody);
// 获取areaResults[0]的值
for (JsonNode r : responseJson.get("result").get(0).get("areaResults")) {
// 分单接口暂时无图层返回
results.add(new LayerAndArea().setAreaId(r.get("field3").asText()).setAreaName(r.get("field1").asText()));
}
return results;
} catch (Exception e) {
return null;
}
}
@lombok.Data
@Accessors(chain = true)
private static class LayerAndArea {
private String layer;
private String areaId;
private String areaName;
}
public void addOrderEvent(String orderId, String subOrderId, String source, String operator, String event, String content, String memo) {
OrderEventEntity entity = new OrderEventEntity();
......
......@@ -2,8 +2,8 @@ package com.dituhui.pea.order.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.DateUtil;
import com.dituhui.pea.order.common.EngineerUtil;
import com.dituhui.pea.order.common.DateUtils;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.dao.CapacityEngineerCalendarDao;
import com.dituhui.pea.order.dao.OrgTeamDao;
import com.dituhui.pea.order.dao.OrgTeamEngineerDao;
......@@ -34,7 +34,7 @@ import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATETIME;
public class EngineerCalendarServiceImpl implements EngineerCalendarService {
@Autowired
private EngineerUtil engineerUtil;
private EngineerUtils engineerUtil;
@Autowired
private OrgTeamEngineerDao orgTeamEngineerDao;
......@@ -141,7 +141,7 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
EngineerCalendarDTO.Calendar calendar = new EngineerCalendarDTO.Calendar();
calendar.setDate(date);
int dayOfWeek = LocalDate.parse(date).getDayOfWeek().getValue();
calendar.setWeek(DateUtil.toWeekChinese(dayOfWeek));
calendar.setWeek(DateUtils.toWeekChinese(dayOfWeek));
EngineerCalendarDTO.Content content = new EngineerCalendarDTO.Content();
List<String> workdays = Arrays.asList(e.getWorkdays().split(","));
if (workdays.contains(String.valueOf(dayOfWeek))) {
......
package com.dituhui.pea.order.service.impl;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.EngineerUtil;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.dao.CapacityEngineerStatDao;
import com.dituhui.pea.order.dao.EngineerInfoDao;
import com.dituhui.pea.order.dao.OrderAppointmentDao;
......@@ -39,7 +39,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
private OrderRequestDao orderRequestDao;
@Autowired
private EngineerUtil engineerUtil;
private EngineerUtils engineerUtils;
@Override
public Result<?> getEngineersGanttList(EngineersGanttDTO.Request reqDTO) {
......@@ -85,7 +85,7 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
.setEngineerName(engineerInfo.getName())
.setGrade(engineerInfo.getGrade());
CapacityEngineerStatEntity capacityEngineerStat = capacityEngineerStatDao.getByEngineerCodeAndWorkday(engineerCode, reqDTO.getDate());
CapacityEngineerStatEntity capacityEngineerStat = capacityEngineerStatDao.getByWorkdayAndEngineerCode(reqDTO.getDate(), engineerCode);
if (capacityEngineerStat == null) {
log.warn("技术员当日的容量数据不存在,{}{}", engineerCode, reqDTO.getDate());
} else {
......@@ -108,39 +108,38 @@ public class EngineerGanttServiceImpl implements EngineerGanttService {
if (teamIds != null && teamIds.size() > 0) {
for (String teamId : teamIds) {
engineerCodes.addAll(
engineerUtil.getEngineersByLevel("team", teamId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
engineerUtils.getEngineersByLevel("team", teamId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
}
} else if (groupIds != null && groupIds.size() > 0) {
for (String groupId : groupIds) {
engineerCodes.addAll(
engineerUtil.getEngineersByLevel("group", groupId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
engineerUtils.getEngineersByLevel("group", groupId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
}
} else if (branchIds != null && branchIds.size() > 0) {
for (String branchId : branchIds) {
engineerCodes.addAll(
engineerUtil.getEngineersByLevel("branch", branchId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
engineerUtils.getEngineersByLevel("branch", branchId).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
}
} else {
engineerCodes.addAll(engineerUtil.getEngineersByLevel(levelType, levelValue).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
engineerCodes.addAll(engineerUtils.getEngineersByLevel(levelType, levelValue).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList()));
}
engineerCodes = new ArrayList<>(new HashSet<>(engineerCodes));
if (StringUtils.isBlank(key)) {
return engineerCodes;
} else {
// 最后,还需要根据key进行过滤(需要结合数据库表)
return engineerUtil.filterEngineersByKey(engineerCodes, key).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
return engineerUtils.filterEngineersByKey(engineerCodes, key).stream().map(EngineerInfoEntity::getEngineerCode).collect(Collectors.toList());
}
}
public Map<String, OrderRequestEntity> getOrdersByOrderIds(List<String> orderIds) {
List<OrderRequestEntity> orders = orderRequestDao.findAllByOrderIdIn(orderIds);
return orders.stream()
.collect(Collectors.toMap(OrderRequestEntity::getOrderId, order -> order));
return orders.stream().collect(Collectors.toMap(OrderRequestEntity::getOrderId, order -> order));
}
private List<?> getOrderTips(String orderId) {
log.info("==> getOrderTips: orderId[{}]", orderId);
// log.info("==> getOrderTips: orderId[{}]", orderId);
OrderRequestEntity order = orderRequestDao.getByOrderId(orderId);
if (order == null) {
log.error("对应的订单不存在!{}", orderId);
......
package com.dituhui.pea.order.service.impl;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.EngineerUtil;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.*;
......@@ -33,7 +33,7 @@ public class OrganizationServiceImpl implements OrganizationService {
private OrgTeamDao orgTeamDao;
@Autowired
private EngineerUtil engineerUtil;
private EngineerUtils engineerUtils;
@Override
public Result<?> getOrganizationTree(String levelType, String levelValue) {
......@@ -115,7 +115,7 @@ public class OrganizationServiceImpl implements OrganizationService {
@Override
public Result<?> getEngineersByLevel(String levelType, String levelValue) {
List<EngineerInfoEntity> engineers = engineerUtil.getEngineersByLevel(levelType, levelValue);
List<EngineerInfoEntity> engineers = engineerUtils.getEngineersByLevel(levelType, levelValue);
List<OrganizationEngineersDTO.Engineer> engineers1 = engineers.stream().map(entity -> {
return new OrganizationEngineersDTO.Engineer()
.setEngineerCode(entity.getEngineerCode())
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!