diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/job/BasicdataPriceJob.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/job/BasicdataPriceJob.java index 45dc87391..9ddddb040 100644 --- a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/job/BasicdataPriceJob.java +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/job/BasicdataPriceJob.java @@ -2,6 +2,7 @@ package com.logpm.basicdata.job; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.basicdata.entity.BasicdataPriceEntity; @@ -15,9 +16,13 @@ import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; /** * @author zhaoqiaobo @@ -70,5 +75,46 @@ public class BasicdataPriceJob { return ReturnT.SUCCESS; } + /** + * 定时维护价格的生效状态 + * 每天凌晨定时维护一次 + * + * @param param + * @return + * @throws Exception + */ + @XxlJob("changePriceEffectiveStatus") + public ReturnT changePriceEffectiveStatus(String param) throws Exception { + // 未生效转生效的价格 + Set effectiveSet = new HashSet<>(); + List list = priceService.list(Wrappers.lambdaQuery().in(BasicdataPriceEntity::getEffectiveStatus, -1, 0)); + if (CollUtil.isNotEmpty(list)) { + List collect = list.stream().filter(item -> item.getEffectiveStatus() == -1 && StrUtil.equals(DateUtil.formatDate(item.getEffectiveTime()), DateUtil.formatDate(DateUtil.beginOfDay(new Date())))).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect)) { + Set updateSet = new HashSet<>(); + for (BasicdataPriceEntity basicdataPriceEntity : collect) { + effectiveSet.add(Convert.toStr(basicdataPriceEntity.getClientId()) + Convert.toStr(basicdataPriceEntity.getBrandId())); + updateSet.add(basicdataPriceEntity.getId()); + } + if (CollUtil.isNotEmpty(updateSet)) { + priceService.update(Wrappers.lambdaUpdate().set(BasicdataPriceEntity::getEffectiveStatus, 0).in(BasicdataPriceEntity::getId, updateSet)); + } + List collect1 = list.stream().filter(item -> item.getEffectiveStatus() == 0).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect1)) { + Set updateSet1 = new HashSet<>(); + for (BasicdataPriceEntity basicdataPriceEntity : collect1) { + if(CollUtil.contains(effectiveSet,Convert.toStr(basicdataPriceEntity.getClientId()) + Convert.toStr(basicdataPriceEntity.getBrandId()))){ + updateSet1.add(basicdataPriceEntity.getId()); + } + } + if(CollUtil.isNotEmpty(updateSet1)){ + priceService.update(Wrappers.lambdaUpdate().set(BasicdataPriceEntity::getEffectiveStatus, 1).in(BasicdataPriceEntity::getId, updateSet1)); + } + } + } + } + return ReturnT.SUCCESS; + } + }