新增文件

master
c1769 2 years ago
parent 4b71e11834
commit 8949af75a9

@ -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<String> deductionItems = new ArrayList<>(); // 扣分项
private FlowDeductionPoint next; // 下一节点
public FlowDeductionPoint next(FlowDeductionPoint next) {
this.setNext(next);
return next;
}
/**
*
*/
public int getDeductionScoreByFinishStep(Integer finishStep, List<OperateScores> 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<OperateScores> 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<Integer> 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;
}
}

@ -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<Products> list = productsService.queryAll();
if (list.isEmpty()) {
return;
}
Random random = new Random();
Date now = new Date();
List<Products> 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("货物售价随机变更完毕");
}
}
Loading…
Cancel
Save