|
@@ -9,11 +9,13 @@ import com.jjt.common.core.controller.BaseController;
|
|
|
import com.jjt.common.core.redis.RedisCache;
|
|
|
import com.jjt.common.utils.DateUtils;
|
|
|
import com.jjt.order.domain.TwinOrder;
|
|
|
+import com.jjt.order.domain.TwinOrderDetail;
|
|
|
import com.jjt.order.domain.VmsStock;
|
|
|
import com.jjt.order.service.ITwinOrderService;
|
|
|
import com.jjt.order.utils.OrderExportUtil;
|
|
|
import com.jjt.order.utils.OrderGsmExportUtil;
|
|
|
-import com.jjt.utils.MssqlUtil;
|
|
|
+import com.jjt.order.vo.BomVO;
|
|
|
+import com.jjt.utils.MssqlService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -23,9 +25,11 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.zip.ZipEntry;
|
|
@@ -34,7 +38,7 @@ import java.util.zip.ZipOutputStream;
|
|
|
/**
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
-@Api("数据接口")
|
|
|
+@Api("订单数据接口")
|
|
|
@RestController
|
|
|
@Slf4j
|
|
|
@RequestMapping()
|
|
@@ -47,6 +51,8 @@ public class OrderApiController extends BaseController {
|
|
|
private ITwinFormulaInfoService formulaInfoService;
|
|
|
@Resource
|
|
|
private ITwinCalcDayService dayService;
|
|
|
+ @Resource
|
|
|
+ private MssqlService mssqlService;
|
|
|
|
|
|
@ApiOperation("查看当前库存")
|
|
|
@GetMapping("/api/stock")
|
|
@@ -59,7 +65,7 @@ public class OrderApiController extends BaseController {
|
|
|
@ApiOperation("导出白坯预测")
|
|
|
@RequestMapping("/api/export/order")
|
|
|
@CrossOrigin(origins = "*")
|
|
|
- public void orderExport(String start, String end, HttpServletResponse response) {
|
|
|
+ public void orderExport(@RequestParam String start, @RequestParam String end, @RequestParam Integer days, HttpServletResponse response) {
|
|
|
//查询订单
|
|
|
List<TwinOrder> orderList = orderService.selectTwinOrderListByDate(start, end);
|
|
|
//按订单ID分组
|
|
@@ -73,7 +79,7 @@ public class OrderApiController extends BaseController {
|
|
|
List<TwinCalcDay> dayList = dayService.selectTwinCalcDayListByTime(sd, sd);
|
|
|
//按设备ID分组
|
|
|
Map<Long, TwinCalcDay> dayMap = dayList.stream().collect(Collectors.toMap(TwinCalcDay::getDeviceId, o -> o));
|
|
|
- List<VmsStock> stocks = MssqlUtil.vmsStock();
|
|
|
+ List<VmsStock> stocks = mssqlService.vmsStock();
|
|
|
try (OutputStream outputStream = new BufferedOutputStream(response.getOutputStream()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipOutputStream zipOut = new ZipOutputStream(bos);) {
|
|
|
// 创建临时输出流
|
|
|
response.reset();
|
|
@@ -83,8 +89,8 @@ public class OrderApiController extends BaseController {
|
|
|
|
|
|
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("tpl/order.xlsx"); XSSFWorkbook wb = new XSSFWorkbook(inputStream);) {
|
|
|
OrderExportUtil oe = new OrderExportUtil();
|
|
|
- String title = "白坯布靶向生产测算-10天(" + start + " 至 " + end + ")\n按重量匹配";
|
|
|
- oe.process(wb, title, orderList, infos, orderMap, dayMap, stocks);
|
|
|
+ String title = "白坯布靶向生产测算-"+days+"天(" + start + " 至 " + end + ")\n按重量匹配";
|
|
|
+ oe.process(wb, title, orderList, infos, orderMap, dayMap, stocks,days);
|
|
|
// 将第一个工作簿写入 ZIP
|
|
|
ZipEntry entry = new ZipEntry("按重量匹配.xlsx");
|
|
|
zipOut.putNextEntry(entry);
|
|
@@ -97,8 +103,8 @@ public class OrderApiController extends BaseController {
|
|
|
|
|
|
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("tpl/order-gsm.xlsx"); XSSFWorkbook wb = new XSSFWorkbook(inputStream);) {
|
|
|
OrderGsmExportUtil oe = new OrderGsmExportUtil();
|
|
|
- String title = "白坯布靶向生产测算-10天(" + start + " 至 " + end + ")\n按平方米克重匹配";
|
|
|
- oe.process(wb, title, orderList, infos, orderMap, dayMap, stocks);
|
|
|
+ String title = "白坯布靶向生产测算-"+days+"天(" + start + " 至 " + end + ")\n按平方米克重匹配";
|
|
|
+ oe.process(wb, title, orderList, infos, orderMap, dayMap, stocks,days);
|
|
|
// 将第二个工作簿写入 ZIP
|
|
|
ZipEntry entry = new ZipEntry("按平方米克重匹配.xlsx");
|
|
|
zipOut.putNextEntry(entry);
|
|
@@ -117,101 +123,94 @@ public class OrderApiController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 先按重量匹配,再匹配长或者宽大于规格的长宽
|
|
|
- *
|
|
|
- * @param spec 规格
|
|
|
- * @param stocks 库存
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- private VmsStock matchStock(String spec, List<VmsStock> stocks) {
|
|
|
- //按重量分组
|
|
|
- Map<Integer, List<VmsStock>> stockMap = stocks.stream().collect(Collectors.groupingBy(VmsStock::getWeight, LinkedHashMap::new, Collectors.toList()));
|
|
|
- if (spec != null) {
|
|
|
- String[] tmp = spec.split("\\*");
|
|
|
- if (tmp.length == 3) {
|
|
|
- //长
|
|
|
- float length = Float.parseFloat(tmp[0]);
|
|
|
- //宽
|
|
|
- float width = Float.parseFloat(tmp[1]);
|
|
|
- //重量,单位kg,需要转换成克
|
|
|
- int weight = (int) (Float.parseFloat(tmp[2]) * 1000);
|
|
|
- List<VmsStock> tempList = stockMap.get(weight);
|
|
|
- if (tempList != null) {
|
|
|
- for (VmsStock stock : tempList) {
|
|
|
- if (length > stock.getLength() || width > stock.getLength()) {
|
|
|
- return stock;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
+ @ApiOperation("查询最近一个月有订单的时间")
|
|
|
+ @GetMapping("/api/order/date")
|
|
|
+ @CrossOrigin(origins = "*")
|
|
|
+ @ResponseBody
|
|
|
+ public List<LocalDate> orderDate() {
|
|
|
+ LocalDate end = LocalDate.now();
|
|
|
+ LocalDate start = end.minusMonths(1);
|
|
|
+ List<TwinOrder> orderList = orderService.selectTwinOrderListByDate(start.toString(), end.toString());
|
|
|
+ List<LocalDate> result = orderList.stream()
|
|
|
+ .map(order -> order.getOrderDate().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDate())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 匹配库存,新匹配方式,以幅宽和平方米克重来匹配
|
|
|
- * 订单中计算得到毛毯平方米克重要求,根据长宽规格,先以产品长度匹配白胚库中的幅宽规格。
|
|
|
- * 如没有或不足,以宽匹配,但此时要做标注,以准备网框的工艺切换。
|
|
|
- * 白胚库的规格,只以平方米克重和幅宽为规格单位。
|
|
|
- *
|
|
|
- * @param spec 规格
|
|
|
- * @param stocks 库存
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- private VmsStock matchStockGsm(String spec, List<VmsStock> stocks) {
|
|
|
- //按重量分组
|
|
|
-// Map<Integer, List<VmsStock>> stockMap = stocks.stream().collect(Collectors.groupingBy(VmsStock::getWeight, LinkedHashMap::new, Collectors.toList()));
|
|
|
-// if (spec != null) {
|
|
|
-// String[] tmp = spec.split("\\*");
|
|
|
-// if (tmp.length == 3) {
|
|
|
-// float length = Float.parseFloat(tmp[0]);
|
|
|
-// float width = Float.parseFloat(tmp[1]);
|
|
|
-// int weight = (int) (Float.parseFloat(tmp[2]) * 1000);
|
|
|
-// List<VmsStock> tempList = stockMap.get(weight);
|
|
|
-// if (tempList != null) {
|
|
|
-// for (VmsStock stock : tempList) {
|
|
|
-// if (length > stock.getLength() || width > stock.getLength()) {
|
|
|
-// return stock;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
+ @ApiOperation("按照时间查询订单")
|
|
|
+ @GetMapping("/api/order/query")
|
|
|
+ @CrossOrigin(origins = "*")
|
|
|
+ @ResponseBody
|
|
|
+ public List<TwinOrder> query(@RequestParam String start, @RequestParam String end, @RequestParam Integer days) {
|
|
|
+ List<TwinOrder> orderList = orderService.selectTwinOrderListByDate(start, end);
|
|
|
|
|
|
- /**
|
|
|
- * 匹配产线
|
|
|
- *
|
|
|
- * @param spec 规格
|
|
|
- * @param list 产线
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- private List<TwinFormulaInfo> matchFormula(String spec, List<TwinFormulaInfo> list) {
|
|
|
- List<TwinFormulaInfo> result = new ArrayList<>();
|
|
|
- //按重量分组
|
|
|
- Map<Float, List<TwinFormulaInfo>> formulaMap = list.stream().collect(Collectors.groupingBy(TwinFormulaInfo::getFd18, LinkedHashMap::new, Collectors.toList()));
|
|
|
- if (spec != null) {
|
|
|
- String[] tmp = spec.split("\\*");
|
|
|
- if (tmp.length == 3) {
|
|
|
- Float length = Float.parseFloat(tmp[0]);
|
|
|
- Float width = Float.parseFloat(tmp[1]);
|
|
|
- Float weight = Float.parseFloat(tmp[2]);
|
|
|
- List<TwinFormulaInfo> infos = formulaMap.get(weight);
|
|
|
- if (infos != null) {
|
|
|
- for (TwinFormulaInfo info : infos) {
|
|
|
- if (length.equals(info.getFd16()) && width.equals(info.getFd17()) ||
|
|
|
- length.equals(info.getFd17()) && width.equals(info.getFd16())) {
|
|
|
- result.add(info);
|
|
|
- }
|
|
|
+ //白柸布库存
|
|
|
+ List<VmsStock> stocks = mssqlService.vmsStock();
|
|
|
+ //当前产量处理
|
|
|
+ List<TwinFormulaInfo> infos = formulaInfoService.selectTwinFormulaInfoList(new TwinFormulaInfo());
|
|
|
+ LocalDateTime ldt = LocalDateTime.now();
|
|
|
+ Date sd = DateUtils.toDate(LocalDateTime.now().minusHours(7).toLocalDate().minusDays(1));
|
|
|
+ List<TwinCalcDay> dayList = dayService.selectTwinCalcDayListByTime(sd, sd);
|
|
|
+ //按设备ID分组
|
|
|
+ Map<Long, TwinCalcDay> dayMap = dayList.stream().collect(Collectors.toMap(TwinCalcDay::getDeviceId, o -> o));
|
|
|
+
|
|
|
+ for (TwinOrder twinOrder : orderList) {
|
|
|
+ List<BomVO> bomVOList = new ArrayList<>();
|
|
|
+ //过滤掉规格为空的,并按规格分组
|
|
|
+ Map<String, List<TwinOrderDetail>> allMap = twinOrder.getTwinOrderDetailList().stream().filter(tod -> tod.getBomSpec() != null).collect(Collectors.groupingBy(TwinOrderDetail::getBomSpec, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ OrderExportUtil oe = new OrderExportUtil();
|
|
|
+ for (String spec : allMap.keySet()) {
|
|
|
+ List<TwinOrderDetail> todList = allMap.get(spec);
|
|
|
+ //匹配白坯布库存
|
|
|
+ Float kc = 0f;
|
|
|
+ VmsStock stock = oe.matchStock(spec, stocks);
|
|
|
+ if (stock != null) {
|
|
|
+ kc = stock.getQty();
|
|
|
+ }
|
|
|
+ //匹配生产设备
|
|
|
+ List<TwinFormulaInfo> matchFormula = oe.matchFormula(spec, infos);
|
|
|
+ BigDecimal cl = BigDecimal.ZERO;
|
|
|
+ for (TwinFormulaInfo match : matchFormula) {
|
|
|
+ TwinCalcDay day = dayMap.get(match.getDeviceId());
|
|
|
+ if (day != null) {
|
|
|
+ cl = cl.add(day.getWeight());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ cl = cl.multiply(BigDecimal.valueOf(1000));
|
|
|
+ double totalWeight = todList.stream().mapToDouble(o -> o.getWeight().doubleValue()).sum();
|
|
|
+ TwinOrderDetail tod = todList.get(0);
|
|
|
+
|
|
|
+ BomVO bom = new BomVO();
|
|
|
+ bom.setLast(cl.doubleValue());
|
|
|
+ bom.setBomCode(tod.getBomCode());
|
|
|
+ bom.setBomName(tod.getBomName());
|
|
|
+ bom.setBomSpec(spec);
|
|
|
+ bom.setXql(totalWeight);
|
|
|
+ bom.setKcl(kc);
|
|
|
+ double ycl = cl.multiply(BigDecimal.valueOf(days)).doubleValue();
|
|
|
+ double cz = totalWeight - kc - ycl;
|
|
|
+ bom.setYcl(ycl);
|
|
|
+ bom.setCz(cz);
|
|
|
+ bomVOList.add(bom);
|
|
|
}
|
|
|
+ twinOrder.setBomList(bomVOList);
|
|
|
+ twinOrder.setTwinOrderDetailList(null);
|
|
|
}
|
|
|
- return result;
|
|
|
+ return orderList;
|
|
|
}
|
|
|
+
|
|
|
+// @ApiOperation("按订单号查询预测信息")
|
|
|
+// @GetMapping("/api/order/detail")
|
|
|
+// @CrossOrigin(origins = "*")
|
|
|
+// @ResponseBody
|
|
|
+// public List<TwinOrder> detail(@RequestParam List<String> code) {
|
|
|
+//// List<TwinOrder> orderList = orderService.selectTwinOrderListByDate(date, date);
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
}
|