|
|
@@ -0,0 +1,61 @@
|
|
|
+package com.dderp.business.service.flycat;
|
|
|
+
|
|
|
+import com.dderp.common.api.NoSqlKeysService;
|
|
|
+import com.dderp.common.api.flycat.OrderService;
|
|
|
+import com.dderp.common.base.BaseService;
|
|
|
+import com.dderp.common.datas.RedisKeys;
|
|
|
+import com.dySweetFishPlugin.redis.RedisService;
|
|
|
+import com.sweetfish.util.AnyValue;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+
|
|
|
+public class OrderServiceImpl extends BaseService implements OrderService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ RedisService redisService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ NoSqlKeysService keysService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void init(AnyValue config) {
|
|
|
+ super.init(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void destroy(AnyValue config) {
|
|
|
+ super.destroy(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void start(AnyValue config) {
|
|
|
+ super.start(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取订单流水号
|
|
|
+ * 每个门店每个订单平台每天的流水号,从1开始,零点归1
|
|
|
+ *
|
|
|
+ * @param idShop 门店id
|
|
|
+ * @param idPlatform 订单平台id
|
|
|
+ * @param supplierCode 分表
|
|
|
+ */
|
|
|
+ public long getOrderSequence(long idShop, long idPlatform, long supplierCode) {
|
|
|
+ String key = keysService.getRedisKey(RedisKeys.KEY_ORDER_SHOP_SEQUENCE, supplierCode, true) +
|
|
|
+ idShop + ":" + idPlatform;
|
|
|
+ long orderSequence = redisService.incr(key);
|
|
|
+ if (orderSequence == 1) {
|
|
|
+ //让redis自动过期,不要自己写线程清零
|
|
|
+ //如果是新的一天,设置键的过期时间为到自然日零点的剩余时间
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime tomorrowMidnight = LocalDateTime.of(now.toLocalDate().plusDays(1), LocalTime.MIDNIGHT);
|
|
|
+ Duration duration = Duration.between(now, tomorrowMidnight);
|
|
|
+
|
|
|
+ redisService.expire(key, (int) duration.getSeconds());
|
|
|
+ }
|
|
|
+ return orderSequence;
|
|
|
+ }
|
|
|
+}
|