Explorar el Código

定时发放优惠券模块

xdd hace 1 mes
padre
commit
f8fd32e939

+ 1 - 1
fs-admin/src/main/java/com/fs/qw/config/SocketConfig.java

@@ -5,7 +5,7 @@ import org.springframework.context.annotation.Configuration;
 
 @Configuration
 public class SocketConfig {
-    @Value("${socket.url}")
+//    @Value("${socket.url}")
     private String socketUrl;
 
     public String getSocketUrl() {

+ 10 - 8
fs-service-system/src/main/java/com/fs/store/domain/FsCouponSchedule.java

@@ -1,5 +1,6 @@
 package com.fs.store.domain;
 
+import java.time.LocalDateTime;
 import java.util.Date;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fs.common.annotation.Excel;
@@ -57,12 +58,12 @@ public class FsCouponSchedule extends BaseEntity
     /** 下单时间 */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "下单时间", width = 30, dateFormat = "yyyy-MM-dd")
-    private Date orderTime;
+    private LocalDateTime orderTime;
 
     /** 执行时间 */
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    @Excel(name = "执行时间", width = 30, dateFormat = "yyyy-MM-dd")
-    private Date executeTime;
+//    @JsonFormat(pattern = "yyyy-MM-dd")
+//    @Excel(name = "执行时间", width = 30, dateFormat = "yyyy-MM-dd")
+//    private Date executeTime;
 
     /** 优惠券ID */
     @Excel(name = "优惠券ID")
@@ -80,12 +81,13 @@ public class FsCouponSchedule extends BaseEntity
     /** 预计发送时间 */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "预计发送时间", width = 30, dateFormat = "yyyy-MM-dd")
-    private Date sendTime;
+    private LocalDateTime sendTime;
+
 
     /** 实际发送时间 */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "实际发送时间", width = 30, dateFormat = "yyyy-MM-dd")
-    private Date actualSendTime;
+    private LocalDateTime actualSendTime;
 
     /** 错误信息 */
     @Excel(name = "错误信息")
@@ -97,12 +99,12 @@ public class FsCouponSchedule extends BaseEntity
 
     /** 最大重试次数 */
     @Excel(name = "最大重试次数")
-    private Long maxRetries;
+    private Long maxRetries = 3L;
 
     /** 下次重试时间 */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "下次重试时间", width = 30, dateFormat = "yyyy-MM-dd")
-    private Date nextRetryTime;
+    private LocalDateTime nextRetryTime;
 
     /** 订单来源 */
     @Excel(name = "订单来源")

+ 5 - 0
fs-service-system/src/main/java/com/fs/store/mapper/FsCouponScheduleMapper.java

@@ -61,4 +61,9 @@ public interface FsCouponScheduleMapper
      * @return 结果
      */
     public int deleteFsCouponScheduleByIds(Long[] ids);
+
+    /**
+     * 查询待发送优惠券
+     */
+    List<FsCouponSchedule> selectPendingCouponList();
 }

+ 5 - 0
fs-service-system/src/main/java/com/fs/store/service/IFsCouponScheduleService.java

@@ -60,4 +60,9 @@ public interface IFsCouponScheduleService
      * @return 结果
      */
     public int deleteFsCouponScheduleById(Long id);
+
+    /**
+     * 发放优惠券
+     */
+    void issueCoupon();
 }

+ 17 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/FsCouponScheduleServiceImpl.java

@@ -1,6 +1,8 @@
 package com.fs.store.service.impl;
 
 import java.util.List;
+
+import cn.hutool.core.util.ObjectUtil;
 import com.fs.common.utils.DateUtils;
 import com.fs.store.domain.FsCouponSchedule;
 import com.fs.store.mapper.FsCouponScheduleMapper;
@@ -54,6 +56,13 @@ public class FsCouponScheduleServiceImpl implements IFsCouponScheduleService
     public int insertFsCouponSchedule(FsCouponSchedule fsCouponSchedule)
     {
         fsCouponSchedule.setCreateTime(DateUtils.getNowDate());
+        // 如果上次发送时间为空,那么预计发送时间等于=下单时间+1月
+        if(ObjectUtil.isNull(fsCouponSchedule.getActualSendTime())){
+            fsCouponSchedule.setSendTime(fsCouponSchedule.getOrderTime().plusMonths(1L));
+        } else {
+            // 否则等于上次发送时间+1月
+            fsCouponSchedule.setSendTime(fsCouponSchedule.getActualSendTime().plusMonths(1L));
+        }
         return fsCouponScheduleMapper.insertFsCouponSchedule(fsCouponSchedule);
     }
 
@@ -93,4 +102,12 @@ public class FsCouponScheduleServiceImpl implements IFsCouponScheduleService
     {
         return fsCouponScheduleMapper.deleteFsCouponScheduleById(id);
     }
+
+    /**
+     * 发放优惠券
+     */
+    @Override
+    public void issueCoupon() {
+        fsCouponScheduleMapper.selectPendingCouponList();
+    }
 }

+ 10 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java

@@ -178,6 +178,8 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
     @Autowired
     HuiFuService huiFuService;
 
+    @Autowired
+    private IFsCouponScheduleService fsCouponScheduleService;
     /**
      * 查询订单
      *
@@ -1381,6 +1383,14 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
             storeOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
             storeOrder.setPayTime(new Date());
             fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
+
+
+            // 如果是套餐类型的
+//            if(ObjectUtil.equal(storeOrder.getIsPackage(),1)) {
+//                FsCouponSchedule fsCouponSchedule = new FsCouponSchedule();
+//
+//                fsCouponScheduleService.insertFsCouponSchedule()
+//            }
             //非处方直接提交OMS
             try {
                 if(order.getIsPrescribe().equals(0)){

+ 5 - 5
fs-service-system/src/main/resources/mapper/store/FsCouponScheduleMapper.xml

@@ -17,7 +17,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="updateTime"    column="update_time"    />
         <result property="updateBy"    column="update_by"    />
         <result property="orderTime"    column="order_time"    />
-        <result property="executeTime"    column="execute_time"    />
         <result property="couponId"    column="coupon_id"    />
         <result property="couponBatchId"    column="coupon_batch_id"    />
         <result property="sendTime"    column="send_time"    />
@@ -44,7 +43,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="count != null "> and count = #{count}</if>
             <if test="status != null "> and status = #{status}</if>
             <if test="orderTime != null "> and order_time = #{orderTime}</if>
-            <if test="executeTime != null "> and execute_time = #{executeTime}</if>
             <if test="couponId != null "> and coupon_id = #{couponId}</if>
             <if test="couponBatchId != null "> and coupon_batch_id = #{couponBatchId}</if>
             <if test="sendTime != null "> and send_time = #{sendTime}</if>
@@ -62,6 +60,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where id = #{id}
     </select>
 
+    <select id="selectPendingCouponList" resultType="com.fs.store.domain.FsCouponSchedule">
+        <include refid="selectFsCouponScheduleVo"/>
+        where status in (0,-1) and retry_count &lt; 3 and count &lt; month
+    </select>
+
     <insert id="insertFsCouponSchedule" parameterType="FsCouponSchedule" useGeneratedKeys="true" keyProperty="id">
         insert into fs_coupon_schedule
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -76,7 +79,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateTime != null">update_time,</if>
             <if test="updateBy != null">update_by,</if>
             <if test="orderTime != null">order_time,</if>
-            <if test="executeTime != null">execute_time,</if>
             <if test="couponId != null">coupon_id,</if>
             <if test="couponBatchId != null">coupon_batch_id,</if>
             <if test="sendTime != null">send_time,</if>
@@ -100,7 +102,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateTime != null">#{updateTime},</if>
             <if test="updateBy != null">#{updateBy},</if>
             <if test="orderTime != null">#{orderTime},</if>
-            <if test="executeTime != null">#{executeTime},</if>
             <if test="couponId != null">#{couponId},</if>
             <if test="couponBatchId != null">#{couponBatchId},</if>
             <if test="sendTime != null">#{sendTime},</if>
@@ -128,7 +129,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>
             <if test="orderTime != null">order_time = #{orderTime},</if>
-            <if test="executeTime != null">execute_time = #{executeTime},</if>
             <if test="couponId != null">coupon_id = #{couponId},</if>
             <if test="couponBatchId != null">coupon_batch_id = #{couponBatchId},</if>
             <if test="sendTime != null">send_time = #{sendTime},</if>