cloudroam
2024-09-03 e32fe26a1945fb44100d06b7049ccce865b11d4a
src/main/java/com/mzl/flower/schedule/ScheduleService.java
@@ -11,12 +11,14 @@
import com.mzl.flower.mapper.payment.OrderMapper;
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;
@@ -56,6 +58,9 @@
    @Autowired
    private OrderItemSettlementService orderItemSettlementService;
    @Autowired
    private GrowthValueDealService growthValueDealService;
    @Scheduled(cron = "1 0/20 * * * ?")
    public void calculateAvePrice() {
@@ -185,4 +190,24 @@
        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 {
                    growthValueDealService.deductionGrowthValue(o);
                } catch (Exception e) {
                    // 记录错误信息,例如将错误信息写入日志
                    log.info("处理订单 " + o.getId() + " 时出错: " + e.getMessage());
                }
            });
        }
        log.info("成长值扣除结束:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
    }
}