gongzuming
2024-09-19 a768dc3daa04d35fedfbe75c0a59b9b2545b85c4
src/main/java/com/mzl/flower/schedule/ScheduleService.java
@@ -2,22 +2,26 @@
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.flower.FlowerCategoryService;
import com.mzl.flower.service.flower.FlowerService;
import com.mzl.flower.service.menber.impl.GrowthValueDealService;
import com.mzl.flower.service.payment.*;
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;
@@ -59,9 +63,15 @@
    private OrderItemSettlementService orderItemSettlementService;
    @Autowired
    private GrowthValueDealService growthValueDealService;
    @Autowired
    private CouponRecordService couponRecordService;
    @Scheduled(cron = "1 0/20 * * * ?")
    @Autowired
    private MemberGrowthRecordMapper memberGrowthRecordMapper;
    @Scheduled(cron = "1 0/30 * * * ?")
    public void calculateAvePrice() {
        log.info("均价计算开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
        List<FlowerCategory> cLs = categoryMapper.selectList(new QueryWrapper<FlowerCategory>()
@@ -190,6 +200,31 @@
        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"));
@@ -198,10 +233,11 @@
    }
    @Scheduled(cron = "0 30 0 1 * ?")
    public void expiredVipCouponRecordList() {
        log.info("会员优惠券过期开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
        couponRecordService.expiredCouponRecordByListCurMonth();
        log.info("会员优惠券过期结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
    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"));
    }
}