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