Commit 62e07ea3 by 丁伟峰

Merge branch 'feat-dingwf-mvp616' into develop

2 parents 2dabf1ed 89e71502
......@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.*;
public class OrderCreateController {
@Autowired
private OrderCreateService orderService;
private OrderCreateService orderCreateService;
@Autowired
private CapacityQueryService capacityQueryService;
......@@ -41,7 +41,7 @@ public class OrderCreateController {
public Result<?> createOrder(@Validated @RequestBody OrderCreateReqDTO orderCreateReqDTO) {
Result<?> res = null;
try {
res = orderService.createOrder(orderCreateReqDTO);
res = orderCreateService.createOrder(orderCreateReqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
......@@ -52,7 +52,7 @@ public class OrderCreateController {
public Result<?> getParameter() {
Result<?> res = null;
try {
res = orderService.initParameter();
res = orderCreateService.initParameter();
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
......
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity;
import org.hibernate.annotations.Where;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
......@@ -17,4 +16,10 @@ public interface CapacityTeamStatDao extends JpaRepository<CapacityTeamStatEntit
@Query("select c from CapacityTeamStatEntity c where c.teamId = :teamId and c.workday between :beginDate and :endDate")
Page<?> findByTeamIdAndWorkdayBetween(String teamId, String beginDate, String endDate, Pageable pageable);
@Query(value = "SELECT team_id FROM capacity_team_stat where layer = :layer ORDER BY RAND() LIMIT 1", nativeQuery = true)
String getRandomTeamIdByLayer(String layer);
@Query(value = "SELECT team_id FROM capacity_team_stat ORDER BY RAND() LIMIT 1", nativeQuery = true)
String getRandomTeamId();
}
......@@ -11,5 +11,5 @@ import org.springframework.stereotype.Repository;
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);
String getTeamIdByBlockIdAndLayer(String blockId, String layer);
}
......@@ -12,6 +12,7 @@ import com.alibaba.cloud.integration.order.entity.OrgGroupEntity;
import com.alibaba.cloud.integration.order.service.CapacityQueryService;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -57,10 +58,26 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
/*
location ==> [layer_info] ==> team ==> (+skill) ==> [capacity_team_stat]
*/
String teamId;
String layer = productCategoryDao.getLayerByBrandAndTypeAndSkill(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill());
String teamId = getTeamByLayer(reqDTO.getLocation(), reqDTO.getAddress(), layer);
List<LayerAndArea> layerAndAreas = getLayerAndAreas(reqDTO.getLocation(), reqDTO.getAddress());
if (layerAndAreas == null || layerAndAreas.size() == 0) {
// 分单接口没有查到,本地随机处理一下
teamId = capacityTeamStatDao.getRandomTeamIdByLayer(layer);
} else {
// 生成随机索引
int randomIndex = new Random().nextInt(layerAndAreas.size());
// 获取随机元素
LayerAndArea layerAndArea = layerAndAreas.get(randomIndex);
teamId = mapBlockInfoDao.getTeamIdByBlockIdAndLayer(layerAndArea.areaId, layer);
}
if (teamId == null || teamId.isBlank()) {
teamId = capacityTeamStatDao.getRandomTeamId();
}
assert (teamId != null && !teamId.isBlank());
CapacityQueryOrderRespDTO capacityQueryRespDTO = new CapacityQueryOrderRespDTO();
capacityQueryRespDTO.setBeginDate(capacityQueryRespDTO.getBeginDate()).setEndDate(reqDTO.getEndDate());
capacityQueryRespDTO.setBeginDate(reqDTO.getBeginDate()).setEndDate(reqDTO.getEndDate());
capacityQueryRespDTO.setCalendar(getTimeRangeByTeamSkill(teamId, reqDTO.getSkill(), reqDTO.getBeginDate(), reqDTO.getEndDate()));
capacityQueryRespDTO.setRemark(String.format("%s-%s", teamId, layer));
return Result.success(capacityQueryRespDTO);
......@@ -107,8 +124,10 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
* @param location
* @return
*/
private String getTeamByLayer(String location, String address, String layer) {
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取
private List<LayerAndArea> getLayerAndAreas(String location, String address) {
// 根据坐标 查询分单接口,获得区块、图层列表 ===> 查询map_block_info表,根据优先级,确定 工作队;
// 根据工作队+图层,查询 capacity_team_stat,返回
// todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取图层、区块名称,对于我们的容量查询没有真正使用,目前采用随机返回方式
// 创建RestTemplate实例
RestTemplate restTemplate = new RestTemplate();
......@@ -144,13 +163,14 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
// 使用Jackson库解析JSON数据
ObjectMapper objectMapper = new ObjectMapper();
try {
List<LayerAndArea> results = new ArrayList<>();
JsonNode responseJson = objectMapper.readTree(responseBody);
// 获取areaResults[0]的值
JsonNode areaResult = responseJson.get("result").get(0).get("areaResults").get(0);
// 将areaResult转换为JSON字符串
// todo 分单接口其实也应该直接返回 图层
return mapBlockInfoDao.getTeamidByBlockidAndLayer(areaResult.get("field2").toString(), layer);
for (JsonNode r : responseJson.get("result").get(0).get("areaResults")) {
// 分单接口暂时无图层返回
results.add(new LayerAndArea().setAreaId(r.get("field2").asText()).setAreaName(r.get("field1").asText()));
}
return results;
} catch (Exception e) {
return null;
}
......@@ -221,4 +241,11 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
return String.format("周%s", weekday.getDisplayName(TextStyle.SHORT, Locale.CHINA));
}
@lombok.Data
@Accessors(chain = true)
private static class LayerAndArea {
private String layer;
private String areaId;
private String areaName;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!