Commit 9b415000 by 丁伟峰

改善了order_request的id字段(改用了snowflake)

1 parent 43cccd29
...@@ -92,6 +92,11 @@ ...@@ -92,6 +92,11 @@
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.5</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -36,20 +36,24 @@ public class CommonService { ...@@ -36,20 +36,24 @@ public class CommonService {
public String getTeamIdByInput(String location, String address, String layer) { public String getTeamIdByInput(String location, String address, String layer) {
// todo 目前会随机兜底,后面将合理化 // todo 目前会随机兜底,后面将合理化
log.info("====== getTeamIdByInput ===");
String teamId = null; String teamId = null;
List<LayerAndArea> layerAndAreas = getLayerAndAreas(location, address); List<LayerAndArea> layerAndAreas = getLayerAndAreas(location, address);
if (layerAndAreas == null || layerAndAreas.size() == 0) { if (layerAndAreas == null || layerAndAreas.size() == 0) {
// 分单接口没有查到,本地随机处理一下 // 分单接口没有查到,本地随机处理一下
teamId = capacityTeamStatDao.getRandomTeamIdByLayer(layer); teamId = capacityTeamStatDao.getRandomTeamIdByLayer(layer);
} else { } else {
// 分单接口查到了areaId(blockId),查询map_block_info,从而限定groupId,然后再随机teamId,这样就相对真实一点
// 生成随机索引 // 生成随机索引
int randomIndex = new Random().nextInt(layerAndAreas.size()); int randomIndex = new Random().nextInt(layerAndAreas.size());
// 获取随机元素 // 获取随机元素
LayerAndArea layerAndArea = layerAndAreas.get(randomIndex); LayerAndArea layerAndArea = layerAndAreas.get(randomIndex);
teamId = mapBlockInfoDao.getTeamIdByBlockIdAndLayer(layerAndArea.areaId, layer); teamId = mapBlockInfoDao.getTeamIdByBlockIdAndLayer(layerAndArea.areaId, layer);
log.info("layerAndArea=={}, teamId=={}", layerAndArea, teamId);
} }
if (StringUtils.isEmpty(teamId)) { if (StringUtils.isEmpty(teamId)) {
teamId = capacityTeamStatDao.getRandomTeamId(); teamId = capacityTeamStatDao.getRandomTeamId();
log.info("查询没有teamId,需要随机生成teamId=={}", teamId);
} }
log.info("teamId ==> {}", teamId); log.info("teamId ==> {}", teamId);
assert (StringUtils.isNotEmpty(teamId)); assert (StringUtils.isNotEmpty(teamId));
...@@ -125,7 +129,7 @@ public class CommonService { ...@@ -125,7 +129,7 @@ public class CommonService {
private String areaName; private String areaName;
} }
public void addOrderChange(String orderId, String subOrderId, String source, String operator, String content, String memo){ public void addOrderChange(String orderId, String subOrderId, String source, String operator, String content, String memo) {
OrderChangeEntity entity = new OrderChangeEntity(); OrderChangeEntity entity = new OrderChangeEntity();
entity.setOrderId(orderId).setSuborderId(subOrderId).setSource(source).setOperator(operator).setContent(content).setMemo(memo); entity.setOrderId(orderId).setSuborderId(subOrderId).setSource(source).setOperator(operator).setContent(content).setMemo(memo);
entity.setCreateTime(new Date()).setUpdateTime(new Date()); entity.setCreateTime(new Date()).setUpdateTime(new Date());
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.dituhui.pea.order.service.impl; package com.dituhui.pea.order.service.impl;
import cn.hutool.core.util.IdUtil;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dao.OrderRequestDao; import com.dituhui.pea.order.dao.OrderRequestDao;
import com.dituhui.pea.order.dao.OrgTeamDao; import com.dituhui.pea.order.dao.OrgTeamDao;
...@@ -85,7 +86,7 @@ public class OrderCreateServiceImpl implements OrderCreateService { ...@@ -85,7 +86,7 @@ public class OrderCreateServiceImpl implements OrderCreateService {
public Result<?> createOrder(OrderCreateReqDTO req) { public Result<?> createOrder(OrderCreateReqDTO req) {
log.info("[createOrder] current XID: {}", RootContext.getXID()); log.info("[createOrder] current XID: {}", RootContext.getXID());
OrderRequestEntity entity = new OrderRequestEntity(); OrderRequestEntity entity = new OrderRequestEntity();
entity.setId(UUID.randomUUID().toString().replace("-", "")); entity.setId(IdUtil.getSnowflake().nextIdStr());
String orderId = req.getOrderId(); String orderId = req.getOrderId();
if (StringUtils.isEmpty(orderId)) { if (StringUtils.isEmpty(orderId)) {
orderId = UUID.randomUUID().toString().replace("-", ""); orderId = UUID.randomUUID().toString().replace("-", "");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!