|
@@ -3,11 +3,12 @@ package com.jjt.inventory.controller;
|
|
|
import com.jjt.common.core.controller.BaseController;
|
|
|
import com.jjt.common.core.domain.R;
|
|
|
import com.jjt.common.core.redis.RedisCache;
|
|
|
+import com.jjt.common.utils.DateUtils;
|
|
|
+import com.jjt.inventory.domain.TwinCalcDayBp;
|
|
|
+import com.jjt.inventory.domain.TwinCalcDayPt;
|
|
|
import com.jjt.inventory.domain.TwinCalcHourBp;
|
|
|
import com.jjt.inventory.domain.TwinCalcHourPt;
|
|
|
-import com.jjt.inventory.service.IInventoryService;
|
|
|
-import com.jjt.inventory.service.ITwinCalcHourBpService;
|
|
|
-import com.jjt.inventory.service.ITwinCalcHourPtService;
|
|
|
+import com.jjt.inventory.service.*;
|
|
|
import com.jjt.inventory.vo.BpVO;
|
|
|
import com.jjt.inventory.vo.PtVO;
|
|
|
import com.jjt.inventory.vo.TopVO;
|
|
@@ -23,10 +24,8 @@ import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.IntFunction;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -44,9 +43,13 @@ public class InventoryController extends BaseController {
|
|
|
@Resource
|
|
|
private MssqlService mssqlService;
|
|
|
@Resource
|
|
|
- private ITwinCalcHourBpService bpService;
|
|
|
+ private ITwinCalcHourBpService hourBpService;
|
|
|
@Resource
|
|
|
- private ITwinCalcHourPtService ptService;
|
|
|
+ private ITwinCalcHourPtService hourPtService;
|
|
|
+ @Resource
|
|
|
+ private ITwinCalcDayPtService dayPtService;
|
|
|
+ @Resource
|
|
|
+ private ITwinCalcDayBpService dayBpService;
|
|
|
|
|
|
|
|
|
@ApiOperation("盘头库库存分析")
|
|
@@ -55,42 +58,34 @@ public class InventoryController extends BaseController {
|
|
|
@ResponseBody
|
|
|
public R<PtVO> pt() {
|
|
|
PtVO ptVO = new PtVO();
|
|
|
+ //当前库统计
|
|
|
String sql = "SELECT TOP 10 SKU,SKU_DESCRC,LOT01 FROM V_WMS_STOCK WHERE WAREHOUSE_ID='WH03-盘头仓库' AND UOM='个' AND LOT01 IS NOT NULL AND LOT01!='' ORDER BY LOT01";
|
|
|
List<TopVO> tops = topProcess(sql);
|
|
|
ptVO.setTops(tops);
|
|
|
-
|
|
|
- // 模拟30天的使用情况数据
|
|
|
- for (int day = 0; day < 30; day++) {
|
|
|
- PtVO.Usage usage = new PtVO.Usage();
|
|
|
- usage.setMax(1500 + day * 10);
|
|
|
- // 每天最大使用量增加10
|
|
|
- usage.setRate(BigDecimal.valueOf(0.7 + day * 0.005).setScale(2, RoundingMode.HALF_UP));
|
|
|
- // 使用率每天递增0.5%
|
|
|
- usage.setDate(LocalDate.now().minusDays(29 - day));
|
|
|
- // 从30天前到今天
|
|
|
-
|
|
|
- int yarnCount = 3 + (int) (Math.random() * 8);
|
|
|
- // 随机3-10个纱种
|
|
|
- int totalNum = 0;
|
|
|
- for (int i = 1; i <= yarnCount; i++) {
|
|
|
- PtVO.YarnTypeDetail detail = new PtVO.YarnTypeDetail();
|
|
|
- detail.setName("纱种" + i);
|
|
|
- detail.setNum(50 + (int) (Math.random() * 100));
|
|
|
- // 随机50-150的数量
|
|
|
- totalNum += detail.getNum();
|
|
|
- usage.getDetails().add(detail);
|
|
|
- }
|
|
|
- // 计算比例
|
|
|
- for (PtVO.YarnTypeDetail detail : usage.getDetails()) {
|
|
|
- BigDecimal ratio = new BigDecimal(detail.getNum()).divide(new BigDecimal(totalNum), 2, RoundingMode.HALF_UP);
|
|
|
- detail.setRatio(ratio);
|
|
|
- }
|
|
|
- ptVO.getUsages().add(usage);
|
|
|
- }
|
|
|
-
|
|
|
+ //30天统计
|
|
|
+ List<TwinCalcDayPt> calcDayList = dayPtService.selectStartDate(LocalDateTime.now().minusHours(7).minusDays(30).toLocalDate());
|
|
|
+ calcDayList = calcDayList.stream().sorted(Comparator.comparing(TwinCalcDayPt::getTime)).collect(Collectors.toList());
|
|
|
+ calcDayList.stream()
|
|
|
+ .map(day -> {
|
|
|
+ PtVO.Usage usage = new PtVO.Usage();
|
|
|
+ usage.setMax(day.getMaxNum());
|
|
|
+ usage.setRate(day.getRate());
|
|
|
+ usage.setDate(DateUtils.toLocalDate(day.getTime()));
|
|
|
+ Integer hour = Integer.parseInt(day.getData());
|
|
|
+ List<TwinCalcHourPt> hourPtList = hourPtService.selectTwinCalcHourPtByHour(day.getTime(), hour);
|
|
|
+ hourPtList.stream().filter(item -> item.getNum() > 0).sorted(Comparator.comparing(TwinCalcHourPt::getNum).reversed()).forEach(hourPt -> {
|
|
|
+ PtVO.YarnTypeDetail detail = new PtVO.YarnTypeDetail();
|
|
|
+ detail.setName(hourPt.getName());
|
|
|
+ detail.setNum(hourPt.getNum());
|
|
|
+ BigDecimal ratio = new BigDecimal(hourPt.getNum()).divide(new BigDecimal(day.getMaxNum()), 4, RoundingMode.HALF_UP);
|
|
|
+ detail.setRatio(ratio);
|
|
|
+ usage.getDetails().add(detail);
|
|
|
+ });
|
|
|
+ return usage;
|
|
|
+ }).forEach(ptVO.getUsages()::add);
|
|
|
+ //当日统计
|
|
|
Map<String, PtVO.Stock> stats = new HashMap<>(16);
|
|
|
- List<TwinCalcHourPt> hourPtList = ptService.selectTwinCalcHourPtByDay(LocalDateTime.now().minusHours(7).toLocalDate());
|
|
|
-
|
|
|
+ List<TwinCalcHourPt> hourPtList = hourPtService.selectTwinCalcHourPtByDay(LocalDateTime.now().minusHours(7).toLocalDate());
|
|
|
hourPtList.forEach(pt -> {
|
|
|
PtVO.Stock stock = stats.computeIfAbsent(pt.getName(), k -> new PtVO.Stock());
|
|
|
stock.setName(pt.getName());
|
|
@@ -114,70 +109,229 @@ public class InventoryController extends BaseController {
|
|
|
@ResponseBody
|
|
|
public R<BpVO> bp() {
|
|
|
BpVO bpVO = new BpVO();
|
|
|
+ //当前库统计
|
|
|
String sql = "SELECT TOP 10 SKU,SKU_DESCRC,LOT01 FROM V_WMS_STOCK WHERE WAREHOUSE_ID='WH04-白坯仓库' AND UOM='KG' AND LOT01 IS NOT NULL AND LOT01!='' ORDER BY LOT01";
|
|
|
List<TopVO> tops = topProcess(sql);
|
|
|
bpVO.setTops(tops);
|
|
|
+ //30天统计
|
|
|
+ List<TwinCalcDayBp> calcDayList = dayBpService.selectStartDate(LocalDateTime.now().minusHours(7).minusDays(30).toLocalDate());
|
|
|
+ calcDayList.stream().sorted(Comparator.comparing(TwinCalcDayBp::getTime)).forEach(day -> {
|
|
|
+ Integer rollMaxHour = Integer.parseInt(day.getRollData().split(",")[0]);
|
|
|
+ Integer rollMinHour = Integer.parseInt(day.getRollData().split(",")[1]);
|
|
|
+ Integer meterMaxHour = Integer.parseInt(day.getMeterData().split(",")[0]);
|
|
|
+ Integer meterMinHour = Integer.parseInt(day.getMeterData().split(",")[1]);
|
|
|
+ Integer weightMaxHour = Integer.parseInt(day.getWeightData().split(",")[0]);
|
|
|
+ Integer weightMinHour = Integer.parseInt(day.getWeightData().split(",")[1]);
|
|
|
+ int[] hours = Arrays.stream(new int[]{rollMaxHour, rollMinHour, meterMaxHour, meterMinHour, weightMaxHour, weightMinHour}).distinct().toArray();
|
|
|
+ Map<Integer, List<TwinCalcHourBp>> hourMap = hourBpService.selectTwinCalcHourBpByHours(day.getTime(), hours);
|
|
|
+ IntFunction<BpVO.YarnTypeDetail> createDetail = mick -> {
|
|
|
+ BpVO.YarnTypeDetail detail = new BpVO.YarnTypeDetail();
|
|
|
+ detail.setName("米克重(" + mick + ")");
|
|
|
+ return detail;
|
|
|
+ };
|
|
|
|
|
|
- // 模拟近一月库存情况 - 卷数、米数、重量三种类型
|
|
|
- for (int i = 0; i < 30; i++) {
|
|
|
// 米数库存
|
|
|
BpVO.MonthStock meterStock = new BpVO.MonthStock();
|
|
|
- meterStock.setMax(800 + (int) (Math.random() * 400));
|
|
|
- // 800-1200米
|
|
|
- meterStock.setMin(300 + (int) (Math.random() * 300));
|
|
|
- // 300-600米
|
|
|
- meterStock.setAvg(new BigDecimal((meterStock.getMax() + meterStock.getMin()) / 2.0).setScale(2, RoundingMode.HALF_UP));
|
|
|
- meterStock.setDate(LocalDate.now().minusDays(29 - i));
|
|
|
+ meterStock.setMax(day.getMeterMax());
|
|
|
+ meterStock.setMin(day.getMeterMin());
|
|
|
+ meterStock.setAvg(day.getMeterAvg());
|
|
|
+ meterStock.setDate(DateUtils.toLocalDate(day.getTime()));
|
|
|
+
|
|
|
+ hourMap.get(meterMaxHour).stream()
|
|
|
+ .filter(item -> item.getMeterNum() > 0)
|
|
|
+ .sorted(Comparator.comparing(TwinCalcHourBp::getMeterNum).reversed())
|
|
|
+ .collect(Collectors.groupingBy(TwinCalcHourBp::getMick))
|
|
|
+ .forEach((mick, list) -> {
|
|
|
+ int meterNum = list.stream().mapToInt(TwinCalcHourBp::getMeterNum).sum();
|
|
|
+ BpVO.YarnTypeDetail detail = createDetail.apply(mick);
|
|
|
+ detail.setNum(meterNum);
|
|
|
+ detail.setRatio(new BigDecimal(meterNum).divide(new BigDecimal(day.getMeterMax()), 4, RoundingMode.HALF_UP));
|
|
|
+ meterStock.getDetails().add(detail);
|
|
|
+ });
|
|
|
+
|
|
|
+ hourMap.get(meterMinHour).stream()
|
|
|
+ .filter(item -> item.getMeterNum() > 0)
|
|
|
+ .collect(Collectors.groupingBy(TwinCalcHourBp::getMick))
|
|
|
+ .forEach((mick, list) -> {
|
|
|
+ int meterNum = list.stream().mapToInt(TwinCalcHourBp::getMeterNum).sum();
|
|
|
+ BpVO.YarnTypeDetail detail = createDetail.apply(mick);
|
|
|
+ detail.setNum(meterNum);
|
|
|
+ detail.setRatio(new BigDecimal(meterNum).divide(new BigDecimal(day.getMeterMin()), 4, RoundingMode.HALF_UP));
|
|
|
+ meterStock.getMinDetails().add(detail);
|
|
|
+ });
|
|
|
+ meterStock.getDetails().sort(Comparator.comparing(BpVO.YarnTypeDetail::getNum).reversed());
|
|
|
+ meterStock.getMinDetails().sort(Comparator.comparing(BpVO.YarnTypeDetail::getNum).reversed());
|
|
|
bpVO.getMeterMonthStocks().add(meterStock);
|
|
|
|
|
|
// 重量库存
|
|
|
BpVO.MonthStock weightStock = new BpVO.MonthStock();
|
|
|
- weightStock.setMax(500 + (int) (Math.random() * 300));
|
|
|
- // 500-800公斤
|
|
|
- weightStock.setMin(200 + (int) (Math.random() * 200));
|
|
|
- // 200-400公斤
|
|
|
- weightStock.setAvg(new BigDecimal((weightStock.getMax() + weightStock.getMin()) / 2.0).setScale(2, RoundingMode.HALF_UP));
|
|
|
- weightStock.setDate(LocalDate.now().minusDays(29 - i));
|
|
|
+ weightStock.setMax(day.getWeightMax());
|
|
|
+ weightStock.setMin(day.getWeightMin());
|
|
|
+ weightStock.setAvg(day.getWeightAvg());
|
|
|
+ weightStock.setDate(DateUtils.toLocalDate(day.getTime()));
|
|
|
+ hourMap.get(weightMaxHour).stream()
|
|
|
+ .filter(item -> item.getWeightNum() > 0)
|
|
|
+ .collect(Collectors.groupingBy(TwinCalcHourBp::getMick))
|
|
|
+ .forEach((mick, list) -> {
|
|
|
+ int weightNum = list.stream().mapToInt(TwinCalcHourBp::getWeightNum).sum();
|
|
|
+ BpVO.YarnTypeDetail detail = createDetail.apply(mick);
|
|
|
+ detail.setNum(weightNum);
|
|
|
+ detail.setRatio(new BigDecimal(weightNum).divide(new BigDecimal(day.getWeightMax()), 4, RoundingMode.HALF_UP));
|
|
|
+ weightStock.getDetails().add(detail);
|
|
|
+ });
|
|
|
+
|
|
|
+ hourMap.get(weightMinHour).stream()
|
|
|
+ .filter(item -> item.getWeightNum() > 0)
|
|
|
+ .collect(Collectors.groupingBy(TwinCalcHourBp::getMick))
|
|
|
+ .forEach((mick, list) -> {
|
|
|
+ int weightNum = list.stream().mapToInt(TwinCalcHourBp::getWeightNum).sum();
|
|
|
+ BpVO.YarnTypeDetail detail = createDetail.apply(mick);
|
|
|
+ detail.setNum(weightNum);
|
|
|
+ detail.setRatio(new BigDecimal(weightNum).divide(new BigDecimal(day.getWeightMin()), 4, RoundingMode.HALF_UP));
|
|
|
+ weightStock.getMinDetails().add(detail);
|
|
|
+ });
|
|
|
+ weightStock.getDetails().sort(Comparator.comparing(BpVO.YarnTypeDetail::getNum).reversed());
|
|
|
+ weightStock.getMinDetails().sort(Comparator.comparing(BpVO.YarnTypeDetail::getNum).reversed());
|
|
|
bpVO.getWeightMonthStocks().add(weightStock);
|
|
|
|
|
|
// 卷数库存
|
|
|
BpVO.MonthStock rollStock = new BpVO.MonthStock();
|
|
|
- rollStock.setMax(150 + (int) (Math.random() * 100));
|
|
|
- // 150-250卷
|
|
|
- rollStock.setMin(50 + (int) (Math.random() * 80));
|
|
|
- // 50-130卷
|
|
|
- rollStock.setAvg(new BigDecimal((rollStock.getMax() + rollStock.getMin()) / 2.0).setScale(2, RoundingMode.HALF_UP));
|
|
|
- rollStock.setDate(LocalDate.now().minusDays(29 - i));
|
|
|
+ rollStock.setMax(day.getRollMax());
|
|
|
+ rollStock.setMin(day.getRollMin());
|
|
|
+ rollStock.setAvg(day.getRollAvg());
|
|
|
+ rollStock.setDate(DateUtils.toLocalDate(day.getTime()));
|
|
|
+
|
|
|
+ hourMap.get(rollMaxHour).stream()
|
|
|
+ .filter(item -> item.getRollNum() > 0)
|
|
|
+ .sorted(Comparator.comparing(TwinCalcHourBp::getRollNum).reversed())
|
|
|
+ .collect(Collectors.groupingBy(TwinCalcHourBp::getMick))
|
|
|
+ .forEach((mick, list) -> {
|
|
|
+ int rollNum = list.stream().mapToInt(TwinCalcHourBp::getRollNum).sum();
|
|
|
+ BpVO.YarnTypeDetail detail = createDetail.apply(mick);
|
|
|
+ detail.setNum(rollNum);
|
|
|
+ detail.setRatio(new BigDecimal(rollNum).divide(new BigDecimal(day.getRollMax()), 4, RoundingMode.HALF_UP));
|
|
|
+ rollStock.getDetails().add(detail);
|
|
|
+ });
|
|
|
+ hourMap.get(rollMinHour).stream()
|
|
|
+ .filter(item -> item.getRollNum() > 0)
|
|
|
+ .sorted(Comparator.comparing(TwinCalcHourBp::getRollNum).reversed())
|
|
|
+ .collect(Collectors.groupingBy(TwinCalcHourBp::getMick))
|
|
|
+ .forEach((mick, list) -> {
|
|
|
+ int rollNum = list.stream().mapToInt(TwinCalcHourBp::getRollNum).sum();
|
|
|
+ BpVO.YarnTypeDetail detail = createDetail.apply(mick);
|
|
|
+ detail.setNum(rollNum);
|
|
|
+ detail.setRatio(new BigDecimal(rollNum).divide(new BigDecimal(day.getRollMin()), 4, RoundingMode.HALF_UP));
|
|
|
+ rollStock.getMinDetails().add(detail);
|
|
|
+ });
|
|
|
+ rollStock.getDetails().sort(Comparator.comparing(BpVO.YarnTypeDetail::getNum).reversed());
|
|
|
+ rollStock.getMinDetails().sort(Comparator.comparing(BpVO.YarnTypeDetail::getNum).reversed());
|
|
|
bpVO.getRollMonthStocks().add(rollStock);
|
|
|
- for (BpVO.MonthStock stock : new BpVO.MonthStock[]{meterStock, weightStock, rollStock}) {
|
|
|
- int totalNum = 0;
|
|
|
- int yarnCount = 3 + (int) (Math.random() * 8);
|
|
|
- // 随机3-10个纱种
|
|
|
- List<BpVO.YarnTypeDetail> details = new java.util.ArrayList<>();
|
|
|
|
|
|
- // 先设置数量并计算总数
|
|
|
- for (int j = 1; j <= yarnCount; j++) {
|
|
|
- BpVO.YarnTypeDetail detail = new BpVO.YarnTypeDetail();
|
|
|
- detail.setName("纱种" + j);
|
|
|
- detail.setNum(50 + (int) (Math.random() * 100));
|
|
|
- // 随机50-150的数量
|
|
|
- totalNum += detail.getNum();
|
|
|
- details.add(detail);
|
|
|
- }
|
|
|
|
|
|
- // 根据数量计算比例
|
|
|
- for (BpVO.YarnTypeDetail detail : details) {
|
|
|
- BigDecimal ratio = new BigDecimal(detail.getNum()).divide(new BigDecimal(totalNum), 2, RoundingMode.HALF_UP);
|
|
|
- detail.setRatio(ratio);
|
|
|
- stock.getDetails().add(detail);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Map<String, BpVO.Stock[]> stats = new HashMap<>(16);
|
|
|
- List<TwinCalcHourBp> hourBpList = bpService.selectTwinCalcHourPtByDay(LocalDateTime.now().minusHours(7).toLocalDate());
|
|
|
+// for (BpVO.MonthStock stock : new BpVO.MonthStock[]{meterStock, weightStock, rollStock}) {
|
|
|
+// int totalNum = 0;
|
|
|
+// int yarnCount = 3 + (int) (Math.random() * 8);
|
|
|
+// // 随机3-10个纱种
|
|
|
+// List<BpVO.YarnTypeDetail> details = new java.util.ArrayList<>();
|
|
|
+//
|
|
|
+// // 先设置数量并计算总数
|
|
|
+// for (int j = 1; j <= yarnCount; j++) {
|
|
|
+// BpVO.YarnTypeDetail detail = new BpVO.YarnTypeDetail();
|
|
|
+// detail.setName("纱种" + j);
|
|
|
+// detail.setNum(50 + (int) (Math.random() * 100));
|
|
|
+// // 随机50-150的数量
|
|
|
+// totalNum += detail.getNum();
|
|
|
+// details.add(detail);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 根据数量计算比例
|
|
|
+// for (BpVO.YarnTypeDetail detail : details) {
|
|
|
+// BigDecimal ratio = new BigDecimal(detail.getNum()).divide(new BigDecimal(totalNum), 2, RoundingMode.HALF_UP);
|
|
|
+// detail.setRatio(ratio);
|
|
|
+// stock.getDetails().add(detail);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ });
|
|
|
+// calcDayList.stream()
|
|
|
+// .map(day -> {
|
|
|
+// BpVO.MonthStock monthStock = new BpVO.MonthStock();
|
|
|
+// monthStock.set
|
|
|
+// usage.setMax(day.getMaxNum());
|
|
|
+// usage.setRate(day.getRate());
|
|
|
+// usage.setDate(DateUtils.toLocalDate(day.getTime()));
|
|
|
+// Integer hour = Integer.parseInt(day.getData());
|
|
|
+// List<TwinCalcHourPt> hourPtList = hourPtService.selectTwinCalcHourPtByHour(day.getTime(), hour);
|
|
|
+// hourPtList.stream().filter(item -> item.getNum() > 0).sorted(Comparator.comparing(TwinCalcHourPt::getNum).reversed()).forEach(hourPt -> {
|
|
|
+// PtVO.YarnTypeDetail detail = new PtVO.YarnTypeDetail();
|
|
|
+// detail.setName(hourPt.getName());
|
|
|
+// detail.setNum(hourPt.getNum());
|
|
|
+// BigDecimal ratio = new BigDecimal(hourPt.getNum()).divide(new BigDecimal(day.getMaxNum()), 4, RoundingMode.HALF_UP);
|
|
|
+// detail.setRatio(ratio);
|
|
|
+// usage.getDetails().add(detail);
|
|
|
+// });
|
|
|
+// return monthStock;
|
|
|
+// }).forEach(bpVO.getRollMonthStocks()::add);
|
|
|
+ // 模拟近一月库存情况 - 卷数、米数、重量三种类型
|
|
|
+// for (int i = 0; i < 30; i++) {
|
|
|
+// // 米数库存
|
|
|
+// BpVO.MonthStock meterStock = new BpVO.MonthStock();
|
|
|
+// meterStock.setMax(800 + (int) (Math.random() * 400));
|
|
|
+// // 800-1200米
|
|
|
+// meterStock.setMin(300 + (int) (Math.random() * 300));
|
|
|
+// // 300-600米
|
|
|
+// meterStock.setAvg(new BigDecimal((meterStock.getMax() + meterStock.getMin()) / 2.0).setScale(2, RoundingMode.HALF_UP));
|
|
|
+// meterStock.setDate(LocalDate.now().minusDays(29 - i));
|
|
|
+// bpVO.getMeterMonthStocks().add(meterStock);
|
|
|
+//
|
|
|
+// // 重量库存
|
|
|
+// BpVO.MonthStock weightStock = new BpVO.MonthStock();
|
|
|
+// weightStock.setMax(500 + (int) (Math.random() * 300));
|
|
|
+// // 500-800公斤
|
|
|
+// weightStock.setMin(200 + (int) (Math.random() * 200));
|
|
|
+// // 200-400公斤
|
|
|
+// weightStock.setAvg(new BigDecimal((weightStock.getMax() + weightStock.getMin()) / 2.0).setScale(2, RoundingMode.HALF_UP));
|
|
|
+// weightStock.setDate(LocalDate.now().minusDays(29 - i));
|
|
|
+// bpVO.getWeightMonthStocks().add(weightStock);
|
|
|
+//
|
|
|
+// // 卷数库存
|
|
|
+// BpVO.MonthStock rollStock = new BpVO.MonthStock();
|
|
|
+// rollStock.setMax(150 + (int) (Math.random() * 100));
|
|
|
+// // 150-250卷
|
|
|
+// rollStock.setMin(50 + (int) (Math.random() * 80));
|
|
|
+// // 50-130卷
|
|
|
+// rollStock.setAvg(new BigDecimal((rollStock.getMax() + rollStock.getMin()) / 2.0).setScale(2, RoundingMode.HALF_UP));
|
|
|
+// rollStock.setDate(LocalDate.now().minusDays(29 - i));
|
|
|
+// bpVO.getRollMonthStocks().add(rollStock);
|
|
|
+// for (BpVO.MonthStock stock : new BpVO.MonthStock[]{meterStock, weightStock, rollStock}) {
|
|
|
+// int totalNum = 0;
|
|
|
+// int yarnCount = 3 + (int) (Math.random() * 8);
|
|
|
+// // 随机3-10个纱种
|
|
|
+// List<BpVO.YarnTypeDetail> details = new java.util.ArrayList<>();
|
|
|
+//
|
|
|
+// // 先设置数量并计算总数
|
|
|
+// for (int j = 1; j <= yarnCount; j++) {
|
|
|
+// BpVO.YarnTypeDetail detail = new BpVO.YarnTypeDetail();
|
|
|
+// detail.setName("纱种" + j);
|
|
|
+// detail.setNum(50 + (int) (Math.random() * 100));
|
|
|
+// // 随机50-150的数量
|
|
|
+// totalNum += detail.getNum();
|
|
|
+// details.add(detail);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 根据数量计算比例
|
|
|
+// for (BpVO.YarnTypeDetail detail : details) {
|
|
|
+// BigDecimal ratio = new BigDecimal(detail.getNum()).divide(new BigDecimal(totalNum), 2, RoundingMode.HALF_UP);
|
|
|
+// detail.setRatio(ratio);
|
|
|
+// stock.getDetails().add(detail);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
+ //当日统计,按米克重统计
|
|
|
+ Map<Integer, BpVO.Stock[]> stats = new HashMap<>(16);
|
|
|
+ List<TwinCalcHourBp> hourBpList = hourBpService.selectTwinCalcHourPtByDay(LocalDateTime.now().minusHours(7).toLocalDate());
|
|
|
hourBpList.forEach(bp -> {
|
|
|
- BpVO.Stock[] stock = stats.computeIfAbsent(bp.getName(), k -> {
|
|
|
+ BpVO.Stock[] stock = stats.computeIfAbsent(bp.getMick(), k -> {
|
|
|
BpVO.Stock[] newStock = new BpVO.Stock[3];
|
|
|
newStock[0] = new BpVO.Stock(); // 卷数
|
|
|
newStock[1] = new BpVO.Stock(); // 米数
|
|
@@ -185,15 +339,15 @@ public class InventoryController extends BaseController {
|
|
|
return newStock;
|
|
|
});
|
|
|
// 处理卷数统计
|
|
|
- processStock(stock[0], bp.getName(), bp.getRollIn(), bp.getRollOut(), bp.getRollNum());
|
|
|
+ processStock(stock[0], bp.getMick(), bp.getRollIn(), bp.getRollOut(), bp.getRollNum());
|
|
|
// 处理米数统计
|
|
|
- processStock(stock[1], bp.getName(), bp.getMeterIn(), bp.getMeterOut(), bp.getMeterNum());
|
|
|
+ processStock(stock[1], bp.getMick(), bp.getMeterIn(), bp.getMeterOut(), bp.getMeterNum());
|
|
|
// 处理重量统计
|
|
|
- processStock(stock[2], bp.getName(), bp.getWeightIn(), bp.getWeightOut(), bp.getWeightNum());
|
|
|
+ processStock(stock[2], bp.getMick(), bp.getWeightIn(), bp.getWeightOut(), bp.getWeightNum());
|
|
|
});
|
|
|
|
|
|
long hours = hourBpList.stream().map(TwinCalcHourBp::getHour).distinct().count();
|
|
|
-
|
|
|
+
|
|
|
// 使用流式处理优化计算和分类
|
|
|
List<BpVO.Stock> rollStocks = new ArrayList<>();
|
|
|
List<BpVO.Stock> meterStocks = new ArrayList<>();
|
|
@@ -203,11 +357,15 @@ public class InventoryController extends BaseController {
|
|
|
stockArray[0].calcAvg((int) hours);
|
|
|
stockArray[1].calcAvg((int) hours);
|
|
|
stockArray[2].calcAvg((int) hours);
|
|
|
-
|
|
|
+
|
|
|
rollStocks.add(stockArray[0]);
|
|
|
meterStocks.add(stockArray[1]);
|
|
|
weightStocks.add(stockArray[2]);
|
|
|
});
|
|
|
+
|
|
|
+ rollStocks.sort(Comparator.comparing(BpVO.Stock::getMick).reversed());
|
|
|
+ meterStocks.sort(Comparator.comparing(BpVO.Stock::getMick).reversed());
|
|
|
+ weightStocks.sort(Comparator.comparing(BpVO.Stock::getMick).reversed());
|
|
|
bpVO.setRollStocks(rollStocks);
|
|
|
bpVO.setMeterStocks(meterStocks);
|
|
|
bpVO.setWeightStocks(weightStocks);
|
|
@@ -238,13 +396,14 @@ public class InventoryController extends BaseController {
|
|
|
* 处理库存数据
|
|
|
*
|
|
|
* @param stock 库存数据
|
|
|
- * @param name 名称
|
|
|
+ * @param mick 米克重
|
|
|
* @param in 入库数量
|
|
|
* @param out 出库数量
|
|
|
* @param num 数量
|
|
|
*/
|
|
|
- private void processStock(BpVO.Stock stock, String name, Integer in, Integer out, Integer num) {
|
|
|
- stock.setName(name);
|
|
|
+ private void processStock(BpVO.Stock stock, Integer mick, Integer in, Integer out, Integer num) {
|
|
|
+ stock.setName("米克重(" + mick + ")");
|
|
|
+ stock.setMick(mick);
|
|
|
stock.addIn(in);
|
|
|
stock.addOut(out);
|
|
|
stock.updateMax(num);
|