|  |  |  | 
|---|
|  |  |  | package com.mzl.flower.schedule; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.mzl.flower.constant.Constants; | 
|---|
|  |  |  | import com.mzl.flower.dto.response.point.ExpiredPointDTO; | 
|---|
|  |  |  | import com.mzl.flower.entity.flower.FlowerCategory; | 
|---|
|  |  |  | import com.mzl.flower.entity.partner.Partner; | 
|---|
|  |  |  | import com.mzl.flower.entity.point.CustomerPoint; | 
|---|
|  |  |  | import com.mzl.flower.entity.point.CustomerPointDetail; | 
|---|
|  |  |  | import com.mzl.flower.mapper.point.CustomerPointDetailMapper; | 
|---|
|  |  |  | import com.mzl.flower.mapper.point.CustomerPointMapper; | 
|---|
|  |  |  | import com.mzl.flower.mapper.point.PointGoodsRecordMapper; | 
|---|
|  |  |  | import com.mzl.flower.utils.DateUtils; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang3.time.DateFormatUtils; | 
|---|
|  |  |  | import org.springframework.format.annotation.DateTimeFormat; | 
|---|
|  |  |  | import org.springframework.scheduling.annotation.Scheduled; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.time.LocalDate; | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | import java.time.temporal.ChronoUnit; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final CustomerPointDetailMapper customerPointDetailMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public PointScheduleService(CustomerPointMapper customerPointMapper, CustomerPointDetailMapper customerPointDetailMapper) { | 
|---|
|  |  |  | private final PointGoodsRecordMapper pointGoodsRecordMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public PointScheduleService(CustomerPointMapper customerPointMapper, CustomerPointDetailMapper customerPointDetailMapper, PointGoodsRecordMapper pointGoodsRecordMapper) { | 
|---|
|  |  |  | this.customerPointMapper = customerPointMapper; | 
|---|
|  |  |  | this.customerPointDetailMapper = customerPointDetailMapper; | 
|---|
|  |  |  | this.pointGoodsRecordMapper = pointGoodsRecordMapper; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 定时计算用户过期积分 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Scheduled(cron = "0 10 1 * * ?") | 
|---|
|  |  |  | @Scheduled(cron = "0 10 0 * * ?") | 
|---|
|  |  |  | public void calculatingExpiredPoint() { | 
|---|
|  |  |  | log.info("过期积分计算开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); | 
|---|
|  |  |  | LocalDate now = LocalDate.now().minusDays(1);//前一天 | 
|---|
|  |  |  | 
|---|
|  |  |  | customerPointDetail.setPoint(expiredPoint); | 
|---|
|  |  |  | customerPointDetail.setRecordDate(lastYear); | 
|---|
|  |  |  | customerPointDetail.create("sys"); | 
|---|
|  |  |  | customerPointDetail.setRemarks(DateUtils.toString(now,"yyyy-MM-dd")+"过期积分结算"); | 
|---|
|  |  |  | customerPointDetail.setRemarks(DateUtils.toString(now,"yyyy-MM-dd")+"过期积分结算,过期积分"+expiredPoint); | 
|---|
|  |  |  | customerPointDetailMapper.insert(customerPointDetail); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新用户积分记录 | 
|---|
|  |  |  | 
|---|
|  |  |  | if(customerPoint == null ){ | 
|---|
|  |  |  | log.error("用户积分记录不存在,userId={},customerId={}",pointDTO.getUserId(),pointDTO.getCustomerId()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | customerPoint.setExpiredPoint(expiredPoint); | 
|---|
|  |  |  | Integer expiredPointTotal = customerPoint.getExpiredPoint()==null?0:customerPoint.getExpiredPoint(); | 
|---|
|  |  |  | customerPoint.setExpiredPoint(expiredPoint+expiredPointTotal); | 
|---|
|  |  |  | customerPointMapper.updateById(customerPoint); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 积分兑换券过期 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Scheduled(cron = "0 46 11 * * ?") | 
|---|
|  |  |  | public void expiredPointGoodsRecord() { | 
|---|
|  |  |  | log.info("积分兑换券过期计算开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); | 
|---|
|  |  |  | pointGoodsRecordMapper.updateExpiredPointGoodsRecord(); | 
|---|
|  |  |  | log.info("积分兑换券过期计算开始:" + DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|