diff --git a/web/src/main/java/com/ibeetl/jlw/flow/operatescores/entity/FlowDeductionPoint.java b/web/src/main/java/com/ibeetl/jlw/flow/operatescores/entity/FlowDeductionPoint.java new file mode 100644 index 0000000..4184e17 --- /dev/null +++ b/web/src/main/java/com/ibeetl/jlw/flow/operatescores/entity/FlowDeductionPoint.java @@ -0,0 +1,84 @@ +package com.ibeetl.jlw.flow.operatescores.entity; + +import com.ibeetl.jlw.flow.operatescores.service.OperateScoresService; +import lombok.Data; + +import java.util.*; + +/** + * 流程扣分点 + */ +@Data +public class FlowDeductionPoint { + + private int maxScore; + private Integer step; // 流程步骤 + private Integer flowId; // 流程ID + private String desc; // 描述 + private List deductionItems = new ArrayList<>(); // 扣分项 + private FlowDeductionPoint next; // 下一节点 + + public FlowDeductionPoint next(FlowDeductionPoint next) { + this.setNext(next); + return next; + } + + /** + * 根据未完成的流程进度扣分 + */ + public int getDeductionScoreByFinishStep(Integer finishStep, List deductionScores) { + FlowDeductionPoint node = this; + while (node.getStep() <= finishStep) { + if (node.getNext() == null) { + return 0; // 流程节点全部完成 不扣分 + } + node = node.getNext(); + } + // 扣分 = 当前节点所有分数 + 之后节点所有分数 - 当前节点已扣分数 + return node.maxScore + node.getAfterScores() - node.currentDeductionScores(deductionScores); + } + + /** + * 获取当前流程节点以及之后节点的总分数 + */ + public int getAfterScores() { + if (this.getNext() == null) { + return 0; + } + return this.getNext().maxScore + this.getNext().getAfterScores(); + } + + + /** + * 返回当前节点已经扣过的分数,用于防止重复扣分 + */ + public int currentDeductionScores(List deductionScores) { + int totalScore = 0; + for (OperateScores ds : deductionScores) { + if (this.deductionItems.contains(ds.getType())) { + totalScore += ds.getScore() == null ? 0 : ds.getScore(); + } + } + return Math.min(totalScore, this.maxScore); + } + + public static FlowDeductionPoint generate(String prefix, Integer flowId, Integer step, int maxScore, + int start, int end, List excludes) { + final FlowDeductionPoint fdp = new FlowDeductionPoint(); + fdp.setFlowId(flowId); // 存货质押 + fdp.setDesc(prefix); + fdp.setStep(step); + fdp.setMaxScore(maxScore); + + for (int i = start; i <= end; i++) { + if (excludes != null && excludes.contains(i)) { + continue; + } + String key = prefix + i; + fdp.deductionItems.add(key); + } + return fdp; + } + + +} diff --git a/web/src/main/java/com/ibeetl/jlw/task/ProductSellPriceTask.java b/web/src/main/java/com/ibeetl/jlw/task/ProductSellPriceTask.java new file mode 100644 index 0000000..06dcf64 --- /dev/null +++ b/web/src/main/java/com/ibeetl/jlw/task/ProductSellPriceTask.java @@ -0,0 +1,55 @@ +package com.ibeetl.jlw.task; + +import com.ibeetl.jlw.entity.Products; +import com.ibeetl.jlw.service.ProductsService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Random; + +/** + * 商品货物价格变化 + */ +@Component +@Slf4j +public class ProductSellPriceTask { + + @Autowired + private ProductsService productsService; + + @Scheduled(cron = "0 0 3 * * ?") + public void updateSellPrice() { + List list = productsService.queryAll(); + if (list.isEmpty()) { + return; + } + Random random = new Random(); + Date now = new Date(); + List updateList = new ArrayList<>(list.size()); + // 售价按照正负10%随机波动,且售价不能超出成本价正负50%范围 + for (Products p : list) { + double r = random.nextDouble() * 0.2 + 0.9; // 正负10%随机波动 + BigDecimal newPrice = p.getSellPrice().multiply(BigDecimal.valueOf(r)); + BigDecimal min = p.getCostPrice().multiply(BigDecimal.valueOf(0.5)); + BigDecimal max = p.getCostPrice().multiply(BigDecimal.valueOf(1.5)); + if (newPrice.compareTo(min) < 0 || newPrice.compareTo(max) > 0) { + newPrice = p.getCostPrice().multiply(BigDecimal.valueOf(1.1)); + } + final Products up = new Products(); + up.setId(p.getId()); + up.setSellPrice(newPrice); + up.setUpdatedAt(now); + updateList.add(up); + } + productsService.updateBatchTemplate(updateList); + log.info("货物售价随机变更完毕"); + } + + +}