From 34a5c00c80235213fca81689636c79fbad47a5fe Mon Sep 17 00:00:00 2001
From: gongzuming <gongzuming>
Date: 星期五, 11 十月 2024 09:24:26 +0800
Subject: [PATCH] 支付优化

---
 src/main/java/com/mzl/flower/schedule/ScheduleService.java |  122 +++++++++++++++++++++++++++++++++-------
 1 files changed, 100 insertions(+), 22 deletions(-)

diff --git a/src/main/java/com/mzl/flower/schedule/ScheduleService.java b/src/main/java/com/mzl/flower/schedule/ScheduleService.java
index c45f66b..1cf50e6 100644
--- a/src/main/java/com/mzl/flower/schedule/ScheduleService.java
+++ b/src/main/java/com/mzl/flower/schedule/ScheduleService.java
@@ -2,21 +2,27 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.mzl.flower.constant.Constants;
+import com.mzl.flower.dto.response.member.MemberGrowthRecordVO;
 import com.mzl.flower.entity.flower.FlowerCategory;
 import com.mzl.flower.entity.partner.Partner;
 import com.mzl.flower.entity.payment.Order;
 import com.mzl.flower.entity.payment.Transfer;
 import com.mzl.flower.mapper.flower.FlowerCategoryMapper;
+import com.mzl.flower.mapper.member.MemberGrowthRecordMapper;
 import com.mzl.flower.mapper.partner.PartnerMapper;
 import com.mzl.flower.mapper.payment.OrderMapper;
+import com.mzl.flower.service.coupon.CouponRecordService;
+import com.mzl.flower.service.coupon.CouponTemplateService2;
 import com.mzl.flower.service.flower.FlowerCategoryService;
-import com.mzl.flower.service.flower.FlowerService;
+import com.mzl.flower.service.menber.impl.GrowthValueDealService;
 import com.mzl.flower.service.payment.*;
+import com.mzl.flower.thread.FlowerCategoryPriceThread;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.time.DateFormatUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -34,13 +40,13 @@
     private PartnerMapper partnerMapper;
 
     @Autowired
-    private FlowerService flowerService;
-
-    @Autowired
     private OrderMapper orderMapper;
 
     @Autowired
     private UserPaymentV3Service paymentV3Service;
+
+    @Autowired
+    private UserPaymentSybService paymentSybService;
 
     @Autowired
     private OrderService orderService;
@@ -57,23 +63,25 @@
     @Autowired
     private OrderItemSettlementService orderItemSettlementService;
 
-    @Scheduled(cron = "1 0/20 * * * ?")
+    @Autowired
+    private GrowthValueDealService growthValueDealService;
+
+    @Autowired
+    private CouponRecordService couponRecordService;
+
+    @Autowired
+    private MemberGrowthRecordMapper memberGrowthRecordMapper;
+
+    @Autowired
+    private CouponTemplateService2 couponTemplateService2;
+
+    @Autowired
+    private FlowerCategoryPriceThread thread;
+
+    @Scheduled(cron = "1 1 0/2 * * ?")
     public void calculateAvePrice() {
         log.info("均价计算开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
-        List<FlowerCategory> cLs = categoryMapper.selectList(new QueryWrapper<FlowerCategory>()
-                .isNotNull("parent_id"));
-        if(cLs != null && cLs.size() > 0){
-            List<Partner> ls = partnerMapper.selectList(new QueryWrapper<Partner>().eq("status", "P"));
-            for(FlowerCategory c : cLs){
-                flowerService.calculateCategoryDaily(c.getId(), null);
-
-                if(ls != null && ls.size() > 0){
-                    for(Partner p : ls){
-                        flowerService.calculateCategoryDaily(c.getId(), p.getId());
-                    }
-                }
-            }
-        }
+        thread.run();
         log.info("均价计算结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
     }
 
@@ -109,10 +117,11 @@
                 try {
                     LocalDateTime createdTime = o.getCreateTime().plusMinutes(5);
                     if (createdTime.isBefore(LocalDateTime.now())) {
-                        boolean f = paymentV3Service.checkOrderStatus(o.getId());
+                        /*boolean f = paymentV3Service.checkOrderStatus(o.getId());
                         if(!f){
                             paymentV3Service.cancelOrder(o.getId());
-                        }
+                        }*/
+                        paymentSybService.cancelOrder(o.getId());
                     }
                 } catch (Exception e) {
                     log.error(e.getMessage(), e);
@@ -133,7 +142,12 @@
     @Scheduled(cron = "1 20 0/1 * * ?")
     public void autoReceive() {
         log.info("自动收货开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
-        orderService.autoReceive();
+        List<Order> ls = orderService.autoReceive();
+        if(ls != null && ls.size() > 0){
+            for(Order o : ls){
+                orderService.processAfterReceive(o);
+            }
+        }
         log.info("自动收货结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
     }
 
@@ -164,6 +178,7 @@
             for(Transfer t : ls){
                 try {
                     paymentV3Service.checkTransferStatus(t);
+                    settlementService.updateSettlementStatus(t.getId());
                 } catch (Exception e) {
                     log.error(e.getMessage(), e);
                 }
@@ -179,4 +194,67 @@
         billService.generateBill(date.plusDays(-1));
         log.info("账单结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
     }
+
+    //成长值降级定时任务
+    @Scheduled(cron = "0 0 5 * * ?")
+    public void deductGrowthValue() {
+        log.info("成长值扣除开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+        //获取当前员工
+        List<Order> orderList = orderMapper.getOrderInfoByReceiveTime();
+        if(!CollectionUtils.isEmpty(orderList)){
+            orderList.forEach(o->{
+                try {
+                    LocalDateTime now = LocalDateTime.now();
+                    LocalDate nowDate = now.toLocalDate();
+                    List<MemberGrowthRecordVO> memberGrowthRecordVOS = memberGrowthRecordMapper.selectDowngradingByUserId(o.getCreateBy(), nowDate);
+                    if (CollectionUtils.isEmpty(memberGrowthRecordVOS)) {
+                        growthValueDealService.deductionGrowthValue(o);
+                    }
+                } catch (Exception e) {
+                    // 记录错误信息,例如将错误信息写入日志
+                    log.info("处理订单 " + o.getId() + " 时出错: " + e.getMessage());
+                }
+            });
+        }
+        log.info("成长值扣除结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+    }
+
+
+    @Scheduled(cron = "0 30 0 1 * ?")
+    public void grantVipCouponRecordList() {
+        log.info("会员优惠券开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+        couponRecordService.grantVipCouponRecordList();
+        log.info("会员优惠券结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+    }
+
+    @Scheduled(cron = "0 30 0 1 * ?")
+    public void expiredCouponRecordLastMon() {
+        log.info("会员优惠券开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+        couponRecordService.expiredCouponRecordLastMon();
+        log.info("会员优惠券结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+    }
+
+
+    @Scheduled(cron = "0 0/5 * * * ?")
+    public void expireActivityCouponTemplateAll() {
+        log.info("优惠券模版过期下架开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+
+        // 下架有所的过期的优惠券
+        couponTemplateService2.expireActivityCouponTemplateAll();
+
+        log.info("优惠券模版过期下架开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+    }
+
+    @Scheduled(cron = "0 0/5 * * * ?")
+    public void expireCouponRecordAll() {
+        log.info("优惠券记录过期开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+
+        // 下架有所的过期的优惠券
+        couponRecordService.expireCouponRecordAll();
+
+        log.info("优惠券记录过期开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+    }
+
+
+
 }

--
Gitblit v1.9.3