|
@@ -0,0 +1,359 @@
|
|
|
+package com.jjt.order.utils;
|
|
|
+
|
|
|
+import com.jjt.calc.domain.TwinFormulaInfo;
|
|
|
+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.vo.BomVO;
|
|
|
+import com.jjt.order.vo.SkuVO;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xddf.usermodel.chart.*;
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTDLbls;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+
|
|
|
+/**
|
|
|
+ * OrderExportUtils$
|
|
|
+ *
|
|
|
+ * @author wukai
|
|
|
+ * @date 2025/2/12 02:27
|
|
|
+ */
|
|
|
+public class OrderExportUtil {
|
|
|
+ private CellStyle p2;
|
|
|
+ private CellStyle percentStyle;
|
|
|
+
|
|
|
+ public OrderExportUtil(XSSFWorkbook wb) {
|
|
|
+ CreationHelper creationHelper = wb.getCreationHelper();
|
|
|
+ this.percentStyle = wb.createCellStyle();
|
|
|
+ percentStyle.setDataFormat(creationHelper.createDataFormat().getFormat("0.00%"));
|
|
|
+ percentStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ this.p2 = wb.createCellStyle();
|
|
|
+ p2.setDataFormat(wb.createDataFormat().getFormat("0.00"));
|
|
|
+ p2.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 总览
|
|
|
+ *
|
|
|
+ * @param sheet sheet
|
|
|
+ * @param bomList 物料列表
|
|
|
+ */
|
|
|
+ public void sheet0(XSSFSheet sheet, List<BomVO> bomList) {
|
|
|
+ AtomicInteger num = new AtomicInteger(3);
|
|
|
+ BomVO bom = new BomVO();
|
|
|
+ bom.setOrders(0L);
|
|
|
+ bom.setXql(0d);
|
|
|
+ bom.setKcl(0f);
|
|
|
+ bom.setYcl(0d);
|
|
|
+ bom.setCz(0d);
|
|
|
+ bom.setCl(0d);
|
|
|
+ bomList.forEach(obj -> {
|
|
|
+ Row row = sheet.createRow(num.getAndIncrement());
|
|
|
+ Cell[] cells = new Cell[10];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ cells[0].setCellValue(obj.getBomCode());
|
|
|
+ cells[1].setCellValue(obj.getBomName());
|
|
|
+ cells[2].setCellValue(obj.getBomSpec());
|
|
|
+ cells[3].setCellValue(obj.getOrders());
|
|
|
+ cells[4].setCellValue(obj.getXql());
|
|
|
+ cells[5].setCellValue(obj.getKcl());
|
|
|
+ cells[7].setCellValue(obj.getYcl());
|
|
|
+ cells[8].setCellValue(obj.getCz());
|
|
|
+ cells[9].setCellValue(obj.getCl());
|
|
|
+ cells[9].setCellStyle(percentStyle);
|
|
|
+ bom.setOrders(bom.getOrders() + obj.getOrders());
|
|
|
+ bom.setXql(bom.getXql() + obj.getXql());
|
|
|
+ bom.setKcl(bom.getKcl() + obj.getKcl());
|
|
|
+ bom.setYcl(bom.getYcl() + obj.getYcl());
|
|
|
+ bom.setCz(bom.getCz() + obj.getCz());
|
|
|
+ bom.setCl(bom.getCl() + obj.getCl());
|
|
|
+ });
|
|
|
+ Row row = sheet.createRow(num.getAndIncrement());
|
|
|
+ Cell[] cells = new Cell[10];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ cells[0].setCellValue("合计");
|
|
|
+// cells[3].setCellValue(bom.getOrders());
|
|
|
+ cells[4].setCellValue(bom.getXql());
|
|
|
+ cells[5].setCellValue(bom.getKcl());
|
|
|
+ cells[7].setCellValue(bom.getYcl());
|
|
|
+ cells[8].setCellValue(bom.getCz());
|
|
|
+ for (int i = 4; i < 9; i++) {
|
|
|
+ cells[i].setCellStyle(p2);
|
|
|
+ }
|
|
|
+ cells[9].setCellValue(bom.getCl() / bomList.size());
|
|
|
+ cells[9].setCellStyle(percentStyle);
|
|
|
+ // 创建一个画布
|
|
|
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
|
|
+ // 前四个默认0,[0,4]:从0列4行开始;[7,20]:到7列20行结束
|
|
|
+ // 默认宽度(14-8)*12
|
|
|
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 11, 3, 17, 20);
|
|
|
+ // 创建一个chart对象
|
|
|
+ XSSFChart chart = drawing.createChart(anchor);
|
|
|
+ // 标题
|
|
|
+ chart.setTitleText("需求重量占比图");
|
|
|
+ // 标题是否覆盖图表
|
|
|
+ chart.setTitleOverlay(false);
|
|
|
+
|
|
|
+ // 图例位置
|
|
|
+ XDDFChartLegend legend = chart.getOrAddLegend();
|
|
|
+ legend.setPosition(LegendPosition.TOP_RIGHT);
|
|
|
+
|
|
|
+ XDDFCategoryDataSource countries = XDDFDataSourcesFactory.fromStringCellRange(sheet, new CellRangeAddress(3, num.get() - 2, 2, 2));
|
|
|
+ // 数据1,单元格范围位置[1, 0]到[1, 6]
|
|
|
+ XDDFNumericalDataSource<Double> area = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(3, num.get() - 2, 4, 4));
|
|
|
+// XDDFChartData data = chart.createData(ChartTypes.PIE3D, null, null);
|
|
|
+ XDDFChartData data = chart.createData(ChartTypes.PIE, null, null);
|
|
|
+ // 设置为可变颜色
|
|
|
+ data.setVaryColors(true);
|
|
|
+ // 图表加载数据
|
|
|
+ data.addSeries(countries, area);
|
|
|
+
|
|
|
+ // 绘制
|
|
|
+ chart.plot(data);
|
|
|
+ CTDLbls dLbls = chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).addNewDLbls();
|
|
|
+ dLbls.addNewShowVal().setVal(false);
|
|
|
+ dLbls.addNewShowLegendKey().setVal(false);
|
|
|
+ dLbls.addNewShowCatName().setVal(true);
|
|
|
+ // 类别名称
|
|
|
+ dLbls.addNewShowSerName().setVal(false);
|
|
|
+ dLbls.addNewShowPercent().setVal(true);
|
|
|
+ // 百分比
|
|
|
+ dLbls.addNewShowLeaderLines().setVal(true);
|
|
|
+ // 引导线
|
|
|
+ dLbls.setSeparator("\n");
|
|
|
+ // 分隔符为分行符
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 白坯布全量
|
|
|
+ *
|
|
|
+ * @param sheet sheet
|
|
|
+ * @param stocks 库存
|
|
|
+ */
|
|
|
+ public void sheet1(Sheet sheet, List<VmsStock> stocks) {
|
|
|
+ AtomicInteger num = new AtomicInteger(2);
|
|
|
+ stocks.forEach(stock -> {
|
|
|
+ Row row = sheet.createRow(num.getAndIncrement());
|
|
|
+ Cell[] cells = new Cell[6];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ cells[0].setCellValue(stock.getSku());
|
|
|
+ cells[1].setCellValue(stock.getDesc());
|
|
|
+ cells[2].setCellValue(stock.getNum());
|
|
|
+ cells[3].setCellValue(stock.getQty());
|
|
|
+ cells[3].setCellStyle(p2);
|
|
|
+// cells[4].setCellValue();
|
|
|
+// cells[5].setCellValue();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 白坯库存匹配
|
|
|
+ *
|
|
|
+ * @param sheet sheet
|
|
|
+ * @param skuList 库存
|
|
|
+ */
|
|
|
+ public void sheet2(Sheet sheet, List<SkuVO> skuList) {
|
|
|
+ AtomicInteger num = new AtomicInteger(3);
|
|
|
+ skuList.forEach(sku -> {
|
|
|
+ int sr = num.get();
|
|
|
+ Row row = sheet.createRow(num.getAndIncrement());
|
|
|
+ Cell[] cells = new Cell[18];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ cells[0].setCellValue(sku.getSku());
|
|
|
+ cells[1].setCellValue(sku.getDesc());
|
|
|
+ cells[2].setCellValue(sku.getNum());
|
|
|
+ cells[3].setCellValue(sku.getQty());
|
|
|
+ cells[4].setCellValue(sku.getXql());
|
|
|
+ cells[3].setCellStyle(p2);
|
|
|
+ cells[4].setCellStyle(p2);
|
|
|
+ cells[5].setCellValue(sku.getBomCode());
|
|
|
+ cells[6].setCellValue(sku.getBomName());
|
|
|
+ cells[7].setCellValue(sku.getBomSpec());
|
|
|
+ boolean out = false;
|
|
|
+ for (TwinOrder order : sku.getOrderList()) {
|
|
|
+ if (out) {
|
|
|
+ row = sheet.createRow(num.getAndIncrement());
|
|
|
+ cells = new Cell[18];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cells[8].setCellValue(DateUtils.parseDateToStr(order.getOrderDate()));
|
|
|
+ cells[9].setCellValue(order.getOrderCode());
|
|
|
+ cells[10].setCellValue(order.getCustomerCode());
|
|
|
+ cells[11].setCellValue(order.getCustomerName());
|
|
|
+ boolean in = false;
|
|
|
+ int ssr = num.get() - 1;
|
|
|
+ for (TwinOrderDetail detail : order.getTwinOrderDetailList()) {
|
|
|
+ if (in) {
|
|
|
+ row = sheet.createRow(num.getAndIncrement());
|
|
|
+ cells = new Cell[18];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cells[12].setCellValue(detail.getColor());
|
|
|
+ cells[13].setCellValue(detail.getPrice().doubleValue());
|
|
|
+ cells[14].setCellValue(detail.getTotalPrice().doubleValue());
|
|
|
+ cells[15].setCellValue(detail.getUnit());
|
|
|
+ cells[16].setCellValue(detail.getNum().doubleValue());
|
|
|
+ cells[17].setCellValue(detail.getWeight().doubleValue());
|
|
|
+ in = true;
|
|
|
+ }
|
|
|
+ out = true;
|
|
|
+ int eer = num.get() - 1;
|
|
|
+ for (int i = 8; i < 12; i++) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(ssr, eer, i, i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int er = num.get() - 1;
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(sr, er, i, i));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 经编机规格分布
|
|
|
+ *
|
|
|
+ * @param sheet sheet
|
|
|
+ * @param bomList 库存
|
|
|
+ */
|
|
|
+ public void sheet3(Sheet sheet, List<BomVO> bomList) {
|
|
|
+ AtomicInteger num = new AtomicInteger(3);
|
|
|
+ bomList.forEach(obj -> {
|
|
|
+ int sr = num.get();
|
|
|
+ Row row = sheet.createRow(num.getAndIncrement());
|
|
|
+ Cell[] cells = new Cell[18];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ cells[0].setCellValue(obj.getBomCode());
|
|
|
+ cells[1].setCellValue(obj.getBomName());
|
|
|
+ cells[2].setCellValue(obj.getBomSpec());
|
|
|
+ cells[3].setCellValue(obj.getXql());
|
|
|
+ cells[4].setCellValue(obj.getDeviceIds());
|
|
|
+ cells[5].setCellValue(obj.getLast());
|
|
|
+ cells[6].setCellValue(obj.getYcl());
|
|
|
+
|
|
|
+ boolean out = false;
|
|
|
+ for (TwinOrder order : obj.getOrderList()) {
|
|
|
+ if (out) {
|
|
|
+ row = sheet.createRow(num.getAndIncrement());
|
|
|
+ cells = new Cell[18];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Cell xql = cells[7];
|
|
|
+ cells[8].setCellValue(DateUtils.parseDateToStr(order.getOrderDate()));
|
|
|
+ cells[9].setCellValue(order.getOrderCode());
|
|
|
+ cells[10].setCellValue(order.getCustomerCode());
|
|
|
+ cells[11].setCellValue(order.getCustomerName());
|
|
|
+ boolean in = false;
|
|
|
+ int ssr = num.get() - 1;
|
|
|
+ BigDecimal ow = BigDecimal.ZERO;
|
|
|
+ for (TwinOrderDetail detail : order.getTwinOrderDetailList()) {
|
|
|
+ if (in) {
|
|
|
+ row = sheet.createRow(num.getAndIncrement());
|
|
|
+ cells = new Cell[18];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cells[12].setCellValue(detail.getColor());
|
|
|
+ cells[13].setCellValue(detail.getPrice().doubleValue());
|
|
|
+ cells[14].setCellValue(detail.getTotalPrice().doubleValue());
|
|
|
+ cells[15].setCellValue(detail.getUnit());
|
|
|
+ cells[16].setCellValue(detail.getNum().doubleValue());
|
|
|
+ cells[17].setCellValue(detail.getWeight().doubleValue());
|
|
|
+ ow = ow.add(detail.getWeight());
|
|
|
+ in = true;
|
|
|
+ }
|
|
|
+ xql.setCellValue(ow.doubleValue());
|
|
|
+ xql.setCellStyle(p2);
|
|
|
+ out = true;
|
|
|
+ int eer = num.get() - 1;
|
|
|
+ for (int i = 7; i < 12; i++) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(ssr, eer, i, i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int er = num.get() - 1;
|
|
|
+ for (int i = 0; i < 7; i++) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(sr, er, i, i));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 白坯布库存--全量
|
|
|
+ *
|
|
|
+ * @param sheet sheet
|
|
|
+ * @param infos 库存
|
|
|
+ */
|
|
|
+ public void sheet4(Sheet sheet, List<TwinFormulaInfo> infos) {
|
|
|
+ AtomicInteger num = new AtomicInteger(3);
|
|
|
+ infos.sort(Comparator.comparing(TwinFormulaInfo::getFd18).reversed().thenComparing(TwinFormulaInfo::getFd16).thenComparing(TwinFormulaInfo::getFd17).thenComparing(TwinFormulaInfo::getFd3));
|
|
|
+ infos.forEach(info -> {
|
|
|
+ Row row = sheet.createRow(num.getAndIncrement());
|
|
|
+ Cell[] cells = new Cell[35];
|
|
|
+ for (int i = 0; i < cells.length; i++) {
|
|
|
+ cells[i] = row.createCell(i);
|
|
|
+ }
|
|
|
+ cells[0].setCellValue(info.getFd18());
|
|
|
+ cells[1].setCellValue(info.getFd16());
|
|
|
+ cells[2].setCellValue(info.getFd17());
|
|
|
+ cells[3].setCellValue(info.getFd3());
|
|
|
+ cells[4].setCellValue(info.getFd15());
|
|
|
+ cells[5].setCellValue(info.getFd4());
|
|
|
+ cells[6].setCellValue(info.getFd5());
|
|
|
+ cells[7].setCellValue(info.getFd6());
|
|
|
+ cells[8].setCellValue(info.getFd2());
|
|
|
+ cells[9].setCellValue(info.getFd1());
|
|
|
+ cells[10].setCellValue(info.getFd13());
|
|
|
+ cells[11].setCellValue(info.getFd14());
|
|
|
+ cells[12].setCellValue(info.getFd24());
|
|
|
+ cells[13].setCellValue(info.getFd25());
|
|
|
+
|
|
|
+ cells[14].setCellValue(info.getCd10());
|
|
|
+ cells[15].setCellValue(info.getCd11());
|
|
|
+ cells[16].setCellValue(info.getCd12());
|
|
|
+ cells[17].setCellValue(info.getCd13());
|
|
|
+ cells[18].setCellValue(info.getCd14());
|
|
|
+ cells[19].setCellValue(info.getCd15());
|
|
|
+ cells[20].setCellValue(info.getCd16());
|
|
|
+ cells[21].setCellValue(info.getCd17());
|
|
|
+ cells[22].setCellValue(info.getCd18());
|
|
|
+ cells[23].setCellValue(info.getCd19());
|
|
|
+
|
|
|
+ cells[24].setCellValue(info.getFd19());
|
|
|
+ cells[25].setCellValue(info.getFd20());
|
|
|
+ cells[26].setCellValue(info.getFd21());
|
|
|
+ cells[27].setCellValue(info.getFd22());
|
|
|
+ cells[28].setCellValue(info.getFd23());
|
|
|
+
|
|
|
+ cells[29].setCellValue(info.getFd7());
|
|
|
+ cells[30].setCellValue(info.getFd8());
|
|
|
+ cells[31].setCellValue(info.getFd9());
|
|
|
+ cells[32].setCellValue(info.getFd10());
|
|
|
+ cells[33].setCellValue(info.getFd11());
|
|
|
+ cells[34].setCellValue(info.getFd12());
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|