|
@@ -2,10 +2,14 @@ package com.jjt.biz.service.impl;
|
|
|
|
|
|
import com.jjt.biz.service.IApiAllService;
|
|
|
import com.jjt.biz.vo.*;
|
|
|
+import com.jjt.calc.domain.TwinCalcDay;
|
|
|
+import com.jjt.calc.service.ITwinCalcDayService;
|
|
|
import com.jjt.common.constant.CacheConstants;
|
|
|
import com.jjt.common.core.redis.RedisCache;
|
|
|
import com.jjt.common.utils.DateUtils;
|
|
|
+import com.jjt.ws.domain.TwinRzCalcMonth;
|
|
|
import com.jjt.ws.domain.TwinWorkshopCalc;
|
|
|
+import com.jjt.ws.service.ITwinRzCalcMonthService;
|
|
|
import com.jjt.ws.service.ITwinWorkshopCalcService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -15,6 +19,8 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -31,6 +37,10 @@ public class ApiAllServiceImpl implements IApiAllService {
|
|
|
private RedisCache redisCache;
|
|
|
@Resource
|
|
|
private ITwinWorkshopCalcService wsCalcService;
|
|
|
+ @Resource
|
|
|
+ private ITwinRzCalcMonthService rzCalcMonthService;
|
|
|
+ @Resource
|
|
|
+ private ITwinCalcDayService calcDayService;
|
|
|
|
|
|
/**
|
|
|
* 获取当前库存数据
|
|
@@ -49,10 +59,85 @@ public class ApiAllServiceImpl implements IApiAllService {
|
|
|
*/
|
|
|
@Override
|
|
|
public AvgMonthVO avgMonth() {
|
|
|
+ LocalDateTime ldt = LocalDateTime.now();
|
|
|
+ YearMonth targetMonth = YearMonth.from(ldt);
|
|
|
+ if (ldt.getDayOfMonth() < 2 || ldt.getDayOfMonth() == 2 && ldt.getHour() < 8) {
|
|
|
+ //2号8点之前 取上一个月
|
|
|
+ targetMonth = targetMonth.minusMonths(1);
|
|
|
+ }
|
|
|
+ String month = targetMonth.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
+ Map<String, Object> params = new HashMap<>(16);
|
|
|
+ params.put("month", month);
|
|
|
+
|
|
|
+ BigDecimal costTotal = BigDecimal.ZERO;
|
|
|
+ BigDecimal costJb = BigDecimal.ZERO;
|
|
|
+ BigDecimal yieldJb = BigDecimal.ZERO;
|
|
|
+ BigDecimal jdl = BigDecimal.ZERO;
|
|
|
+ BigDecimal costRz = BigDecimal.ZERO;
|
|
|
+ BigDecimal yieldRz = BigDecimal.ZERO;
|
|
|
+
|
|
|
AvgMonthVO vo = new AvgMonthVO();
|
|
|
- vo.mock();
|
|
|
- redisCache.setCacheObject(CacheConstants.AVG_MONTH, vo);
|
|
|
- return redisCache.getCacheObject(CacheConstants.AVG_MONTH);
|
|
|
+ TwinWorkshopCalc twinWorkshopCalc = new TwinWorkshopCalc();
|
|
|
+ twinWorkshopCalc.setParams(params);
|
|
|
+ List<TwinWorkshopCalc> wsList = wsCalcService.selectTwinWorkshopCalcList(twinWorkshopCalc);
|
|
|
+ Map<Date, List<TwinWorkshopCalc>> wsMap = wsList.stream().collect(Collectors.groupingBy(TwinWorkshopCalc::getDataDate));
|
|
|
+ for (Date d : wsMap.keySet()) {
|
|
|
+ List<TwinWorkshopCalc> list = wsMap.get(d);
|
|
|
+ for (TwinWorkshopCalc ws : list) {
|
|
|
+ if ("WS02-D".equals(ws.getWsCode())) {
|
|
|
+ //经编费用
|
|
|
+ costJb = costJb.add(ws.getTotalPrice());
|
|
|
+ }
|
|
|
+ costTotal = costTotal.add(ws.getTotalPrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ costTotal = costTotal.divide(BigDecimal.valueOf(wsMap.size()), 2, RoundingMode.HALF_UP);
|
|
|
+ //这里是算的经编总费用
|
|
|
+ costJb = costJb.divide(BigDecimal.valueOf(wsMap.size()), 1, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ List<TwinCalcDay> dayList = calcDayService.selectTwinCalcDayListByMonth(month);
|
|
|
+ Map<Date, List<TwinCalcDay>> dayMap = dayList.stream().collect(Collectors.groupingBy(TwinCalcDay::getTime));
|
|
|
+ for (Date d : dayMap.keySet()) {
|
|
|
+ List<TwinCalcDay> list = dayMap.get(d);
|
|
|
+ // 计算 length 总和
|
|
|
+ BigDecimal totalLength = list.stream()
|
|
|
+ .map(TwinCalcDay::getLength)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ yieldJb = yieldJb.add(totalLength);
|
|
|
+ // 计算 jdl 总和
|
|
|
+ BigDecimal totalJdl = list.stream()
|
|
|
+ .map(TwinCalcDay::getEfficiency)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal avgJdl = totalJdl.multiply(BigDecimal.valueOf(100)).divide(BigDecimal.valueOf(list.size()), 4, RoundingMode.HALF_UP);
|
|
|
+ jdl = jdl.add(avgJdl);
|
|
|
+ }
|
|
|
+
|
|
|
+ yieldJb = yieldJb.divide(BigDecimal.valueOf(dayMap.size()), 0, RoundingMode.HALF_UP);
|
|
|
+ jdl = jdl.divide(BigDecimal.valueOf(dayMap.size()), 2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+
|
|
|
+ TwinRzCalcMonth twinRzCalcMonth = new TwinRzCalcMonth();
|
|
|
+ twinRzCalcMonth.setParams(params);
|
|
|
+ List<TwinRzCalcMonth> rzList = rzCalcMonthService.selectTwinRzCalcMonthList(twinRzCalcMonth);
|
|
|
+ for (TwinRzCalcMonth calcMonth : rzList) {
|
|
|
+ costRz = costRz.add(calcMonth.getLengthPrice());
|
|
|
+ yieldRz = yieldRz.add(calcMonth.getLength());
|
|
|
+ }
|
|
|
+
|
|
|
+ costRz = costRz.divide(BigDecimal.valueOf(rzList.size()), 2, RoundingMode.HALF_UP);
|
|
|
+ yieldRz = yieldRz.divide(BigDecimal.valueOf(rzList.size()), 0, RoundingMode.HALF_UP);
|
|
|
+ //这里算平均每米费用
|
|
|
+ costJb = costJb.divide(yieldJb, 2, RoundingMode.HALF_UP);
|
|
|
+ vo.setCostRz(costRz);
|
|
|
+ vo.setYieldRz(yieldRz);
|
|
|
+ vo.setCostTotal(costTotal);
|
|
|
+ vo.setCostJb(costJb);
|
|
|
+ vo.setYieldJb(yieldJb);
|
|
|
+ vo.setJdl(jdl);
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -91,15 +176,25 @@ public class ApiAllServiceImpl implements IApiAllService {
|
|
|
public List<ProdTradeVO> prodTrade() {
|
|
|
List<ProdTradeVO> list = new ArrayList<>();
|
|
|
IndexData id = redisCache.getCacheObject(CacheConstants.INDEX_CALC);
|
|
|
+ YrTwinVO yrTwinVO = redisCache.getCacheObject(CacheConstants.RZ_MOCK);
|
|
|
+ List<YrProdTradeVO> yrProdTradeVOS = yrTwinVO.getProdTrade();
|
|
|
+ Map<String, YrProdTradeVO> yrMap = yrProdTradeVOS.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ YrProdTradeVO::getTips,
|
|
|
+ vo -> vo,
|
|
|
+ (existing, replacement) -> existing
|
|
|
+ ));
|
|
|
List<WeekData> weekDataList = id.getWeekData();
|
|
|
for (WeekData wd : weekDataList) {
|
|
|
ProdTradeVO vo = new ProdTradeVO();
|
|
|
- vo.mock();
|
|
|
vo.setJbLength(wd.getLength());
|
|
|
vo.setJbWeight(wd.getWeight());
|
|
|
LocalDate localDate = LocalDate.parse(wd.getTime());
|
|
|
vo.setDate(week(localDate));
|
|
|
vo.setTips(localDate.toString());
|
|
|
+ YrProdTradeVO yr = yrMap.get(wd.getTime());
|
|
|
+ vo.setRzLength(yr.getLine().get(0).getLength());
|
|
|
+ vo.setRzWeight(yr.getLine().get(0).getWeight());
|
|
|
list.add(vo);
|
|
|
}
|
|
|
|
|
@@ -255,6 +350,7 @@ public class ApiAllServiceImpl implements IApiAllService {
|
|
|
CurrYieldVO currYieldVO = currYield();
|
|
|
CurrYieldVO.RZ rz = currYieldVO.getRz();
|
|
|
rz.setYield(rzVO.getStatus().getLength());
|
|
|
+ rz.setYieldMax(BigDecimal.valueOf(200000));
|
|
|
vo.setCurrYield(currYieldVO);
|
|
|
vo.setProdTrade(prodTrade());
|
|
|
vo.setEnergyTrade(energyTrade());
|