cloudroam
2024-10-25 3819ff43fe6e89adf97cf2504e9d7da1a2ac40f2
src/main/java/com/mzl/flower/schedule/ScheduleService.java
@@ -1,28 +1,37 @@
package com.mzl.flower.schedule;
import com.aliyuncs.exceptions.ClientException;
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.BaseService;
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.service.wallet.WalletBillRecordService;
import com.mzl.flower.thread.FlowerCategoryPriceThread;
import com.mzl.flower.utils.SmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
@@ -37,13 +46,13 @@
    private PartnerMapper partnerMapper;
    @Autowired
    private FlowerService flowerService;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private UserPaymentV3Service paymentV3Service;
    @Autowired
    private UserPaymentSybService paymentSybService;
    @Autowired
    private OrderService orderService;
@@ -66,23 +75,26 @@
    @Autowired
    private CouponRecordService couponRecordService;
    @Scheduled(cron = "1 0/20 * * * ?")
    @Autowired
    private MemberGrowthRecordMapper memberGrowthRecordMapper;
    @Autowired
    private CouponTemplateService2 couponTemplateService2;
    @Autowired
    private FlowerCategoryPriceThread thread;
    @Autowired
    private BaseService baseService;
    @Autowired
    private WalletBillRecordService walletBillRecordService;
    @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"));
    }
@@ -118,10 +130,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);
@@ -179,6 +192,8 @@
                try {
                    paymentV3Service.checkTransferStatus(t);
                    settlementService.updateSettlementStatus(t.getId());
                    //2024-10-24更新钱包提现信息
                    walletBillRecordService.updateTransferStatus(t.getId());
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
@@ -204,7 +219,12 @@
        if(!CollectionUtils.isEmpty(orderList)){
            orderList.forEach(o->{
                try {
                    growthValueDealService.deductionGrowthValue(o);
                    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());
@@ -230,4 +250,49 @@
    }
    @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"));
    }
    @Scheduled(cron = "0 15 17 * * ?")
    @Profile("prod")
    public void DealSendMessageInfoBySupplier() {
        log.info("供应商下单供货提示开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 设置开始时间为前一天的17点以后
        LocalDateTime startDateTime = LocalDateTime.of(currentDate.minusDays(1), LocalTime.of(17, 0));
        // 设置结束时间为当前日期的17点
        LocalDateTime endDateTime = LocalDateTime.of(currentDate, LocalTime.of(17, 0));
        System.out.println("开始时间: " + startDateTime);
        System.out.println("结束时间: " + endDateTime);
        List<String> sends = orderMapper.getWaitSendMessageInfoBySupplier("COLLECTION", startDateTime, endDateTime);
        if(CollectionUtils.isNotEmpty(sends)) {
            sends.forEach(s -> {
                try {
                    SmsUtil.sendSms(s, "SMS_474905508", null);
                } catch (ClientException e) {
                    log.error("发送短信失败,手机号:" + s, e);
                }
            });
        }
        log.info("供应商下单供货提示结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
    }
}