修改订单编号生成逻辑
This commit is contained in:
parent
69f87d4385
commit
eac128abdd
@ -2,23 +2,39 @@ package com.rootcloud.common.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class OrderNumberUtils {
|
||||
|
||||
private static int callCount = 0;
|
||||
private static String lastDate = "";
|
||||
|
||||
public static String generateOrderNumber() {
|
||||
String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
if (!currentDate.equals(lastDate)) {
|
||||
callCount = 0;
|
||||
lastDate = currentDate;
|
||||
}
|
||||
|
||||
callCount++;
|
||||
|
||||
return currentDate + String.format("%03d", callCount);
|
||||
public String generateOrderNumber() {
|
||||
/* 由于之前人员将订单seq数据存储在内存中,服务重启后seq失效清零,导致后续订单从0开始,编码重复,现存入redis中
|
||||
* 逻辑修改为:每次自然天增加后,重置seq为0,且将seq,自然天等数据存入redis
|
||||
* */
|
||||
int callCount = (int) (redisTemplate.opsForValue().get("orderSeq") == null ? 0 :
|
||||
redisTemplate.opsForValue().get("orderSeq"));
|
||||
// 当前日期
|
||||
String currentDate =
|
||||
new SimpleDateFormat("yyyyMMdd").format(new Date());
|
||||
// 上次日期
|
||||
String lastDate =
|
||||
(String) (redisTemplate.opsForValue().get("orderLastDate") == null ? currentDate :
|
||||
redisTemplate.opsForValue().get("orderLastDate"));
|
||||
redisTemplate.opsForValue().set("orderLastDate", currentDate);
|
||||
if (!currentDate.equals(lastDate)) {
|
||||
callCount = 0;
|
||||
redisTemplate.opsForValue().set("orderLastDate", currentDate);
|
||||
}
|
||||
callCount++;
|
||||
redisTemplate.opsForValue().set("orderSeq", callCount);
|
||||
return currentDate + String.format("%03d", callCount);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1058,7 +1058,7 @@ public class OrderServiceImpl extends ServiceImpl<NxOrderMapper, NxOrderEntity>
|
||||
order.setOrderServicetypeCode(ServicePlanEnums.MessageType.TRANSFORMATION.getCode());
|
||||
order.setOrderServicetypeName(ServicePlanEnums.MessageType.TRANSFORMATION.getDesc());
|
||||
}
|
||||
orderNum.append(OrderNumberUtils.generateOrderNumber());
|
||||
orderNum.append(orderNumberUtils.generateOrderNumber());
|
||||
order.setOrderOrdernumber(orderNum.toString());
|
||||
order.setOrderSource("app");
|
||||
order.setOrderDevicecode(deviceDataVo.getSblbSbbm());
|
||||
@ -1245,7 +1245,7 @@ public class OrderServiceImpl extends ServiceImpl<NxOrderMapper, NxOrderEntity>
|
||||
order.setOrderServicetypeCode(ServicePlanEnums.MessageType.INSPECTION.getCode());
|
||||
order.setOrderServicetypeName(ServicePlanEnums.MessageType.INSPECTION.getDesc());
|
||||
}
|
||||
orderNum.append(OrderNumberUtils.generateOrderNumber());
|
||||
orderNum.append(orderNumberUtils.generateOrderNumber());
|
||||
order.setOrderOrdernumber(orderNum.toString());
|
||||
order.setOrderSource("app");
|
||||
order.setOrderDevicecode(deviceDataVo.getSblbSbbm());
|
||||
@ -1369,6 +1369,8 @@ public class OrderServiceImpl extends ServiceImpl<NxOrderMapper, NxOrderEntity>
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
@Resource
|
||||
OrderNumberUtils orderNumberUtils;
|
||||
@Override
|
||||
public JsonResult<Object> createOrder3(OrderParam param) throws Exception {
|
||||
String deviceIds = param.getDeviceIds();
|
||||
@ -1442,7 +1444,7 @@ public class OrderServiceImpl extends ServiceImpl<NxOrderMapper, NxOrderEntity>
|
||||
order.setOrderServicetypeCode(ServicePlanEnums.MessageType.INSPECTION.getCode());
|
||||
order.setOrderServicetypeName(ServicePlanEnums.MessageType.INSPECTION.getDesc());
|
||||
}
|
||||
orderNum.append(OrderNumberUtils.generateOrderNumber());
|
||||
orderNum.append(orderNumberUtils.generateOrderNumber());
|
||||
order.setOrderOrdernumber(orderNum.toString());
|
||||
order.setOrderSource("app");
|
||||
order.setOrderDevicecode(deviceDataVo.getSblbSbbm());
|
||||
|
@ -1359,6 +1359,8 @@ public class ServicePlanServiceImpl extends ServiceImpl<ServicePlanDao, ServiceP
|
||||
}
|
||||
|
||||
|
||||
@Resource
|
||||
private OrderNumberUtils orderNumberUtils;
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void generateOrder(ServicePlanEntity servicePlan, int triggerType, String thatDay, boolean tempTime) throws Exception {
|
||||
@ -1416,7 +1418,7 @@ public class ServicePlanServiceImpl extends ServiceImpl<ServicePlanDao, ServiceP
|
||||
NxOrderEntity order = new NxOrderEntity();
|
||||
String orderId = JEUuidUtil.uuid();
|
||||
order.setNxOrderId(orderId);
|
||||
String orderNumber = "B" + OrderNumberUtils.generateOrderNumber();
|
||||
String orderNumber = "B" + orderNumberUtils.generateOrderNumber();
|
||||
order.setOrderOrdernumber(orderNumber);
|
||||
order.setOrderSource("app");
|
||||
order.setOrderDevicecode(nxDeviceEntity.getSblbSbbm());
|
||||
|
@ -15,7 +15,7 @@ spring:
|
||||
# url: jdbc:mysql://10.70.40.48:3306/jepaas?useUnicode=true&characterEncoding=utf8&useSSL=false
|
||||
username: root
|
||||
password: 123456
|
||||
url: jdbc:mysql://127.0.0.1:3306/jepaas0830?useUnicode=true&characterEncoding=utf8&useSSL=false
|
||||
url: jdbc:mysql://192.168.31.204:3306/jepaas?useUnicode=true&characterEncoding=utf8&useSSL=false
|
||||
|
||||
hikari:
|
||||
pool-name: DatebookHikariCP
|
||||
@ -44,10 +44,10 @@ spring:
|
||||
mapper-locations: classpath:/mapper/*.xml
|
||||
redis:
|
||||
# host: 10.70.25.113
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
host: 8.141.87.245
|
||||
port: 9004
|
||||
# password: GypassBDN^1024
|
||||
password: 123456
|
||||
password: redis_1234
|
||||
timeout: 2000
|
||||
database: 1
|
||||
lettuce:
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.rootcloud;
|
||||
|
||||
import com.rootcloud.common.util.OrderNumberUtils;
|
||||
import com.rootcloud.controller.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -40,6 +41,8 @@ public class NxgxApplicationTests {
|
||||
private DeviceHistorySituationController deviceHistorySituationController;
|
||||
@Autowired
|
||||
private WorkStatusMonitorController workStatusMonitorController;
|
||||
@Autowired
|
||||
private OrderNumberUtils utils;
|
||||
|
||||
@Before() //这个方法在每个方法执行之前都会执行一遍
|
||||
public void setup() {
|
||||
@ -52,7 +55,9 @@ public class NxgxApplicationTests {
|
||||
|
||||
@org.junit.Test
|
||||
public void getAllCategoryTest() throws Exception {
|
||||
workStatusMonitorController.queryWorkStatus("CWnS7aGB5cfxZLXO3wv","0");
|
||||
String s = utils.generateOrderNumber();
|
||||
System.out.println(s);
|
||||
// workStatusMonitorController.queryWorkStatus("CWnS7aGB5cfxZLXO3wv","0");
|
||||
/* DevicePropertyValueParam devicePropertyValueParam = new DevicePropertyValueParam();
|
||||
devicePropertyValueParam.setDeviceId("19w5OHDnldK");
|
||||
List<String> propertyIds = new ArrayList<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user