Commit 855e634dbee49370fe6054f0e1fd823c2a1f4dbb

Authored by yeqianyong
1 parent 778ddf58

楚江ERP-发货单批量导出模板更换

... ... @@ -34,6 +34,7 @@ import org.apache.commons.lang3.StringUtils;
34 34 import org.apache.poi.ss.usermodel.Sheet;
35 35 import org.apache.poi.ss.usermodel.Workbook;
36 36 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  37 +import org.springframework.data.redis.core.RedisTemplate;
37 38 import org.springframework.web.bind.annotation.DeleteMapping;
38 39 import com.lframework.starter.web.core.controller.DefaultBaseController;
39 40 import com.lframework.starter.web.core.annotations.security.HasPermission;
... ... @@ -47,11 +48,15 @@ import java.math.RoundingMode;
47 48 import java.nio.file.Files;
48 49 import java.nio.file.Path;
49 50 import java.nio.file.Paths;
  51 +import java.time.Duration;
  52 +import java.time.LocalDate;
  53 +import java.time.LocalDateTime;
50 54 import java.time.format.DateTimeFormatter;
51 55 import java.util.ArrayList;
52 56 import java.util.Comparator;
53 57 import java.util.List;
54 58 import java.util.Map;
  59 +import java.util.concurrent.TimeUnit;
55 60 import java.util.stream.Collectors;
56 61 import java.util.zip.ZipEntry;
57 62 import java.util.zip.ZipOutputStream;
... ... @@ -74,6 +79,8 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
74 79 private ShipmentsPlanDetailService shipmentsPlanDetailService;
75 80 @Resource
76 81 private SysUserService sysUserService;
  82 + @Resource
  83 + private RedisTemplate redisTemplate;
77 84
78 85
79 86 /**
... ... @@ -366,7 +373,7 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
366 373 }
367 374 String latex = LatexFormulaExcelExporterUtil.convertToLatex(formulaComponentList);
368 375 if (StringUtils.isNotBlank(latex)) {
369   - LatexFormulaExcelExporterUtil.insertLatexImageToCell(workbook, sheet, latex, startRow, 4, 1, 7);
  376 + LatexFormulaExcelExporterUtil.insertLatexImageToCell(workbook, sheet, latex, startRow, 2, 1, 7);
370 377 }
371 378 ExcelUtil.setCellValue(sheet, startRow, 9, detail.getQuantity());
372 379 if ("TYPE_2".equals(type)) {
... ... @@ -375,9 +382,11 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
375 382 ExcelUtil.setCellValue(sheet, startRow, 12, detail.getSalesPrice());
376 383 ExcelUtil.setCellValue(sheet, startRow, 13, detail.getOrderType());
377 384 ExcelUtil.setCellValue(sheet, startRow, 14, detail.getYieldBatchNo());
  385 + ExcelUtil.setCellValue(sheet, startRow, 15, " -- ");
378 386 } else {
379 387 ExcelUtil.setCellValue(sheet, startRow, 13, detail.getPackagingFee());
380 388 ExcelUtil.setCellValue(sheet, startRow, 15, detail.getOrderType());
  389 + ExcelUtil.setCellValue(sheet, startRow, 16, " -- ");
381 390 }
382 391 startRow++;
383 392 }
... ... @@ -386,12 +395,13 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
386 395 dataMap.put("createDate", dateFormatter.format(orderInfo.getCreateTime()));
387 396 SysUser user = sysUserService.findById(orderInfo.getCreateById());
388 397 dataMap.put("createBy", user.getName());
389   - dataMap.put("totalQuantity", totalQuantity.setScale(2, RoundingMode.HALF_UP));
390   - dataMap.put("totalActualQuantity", totalActualQuantity.setScale(2, RoundingMode.HALF_UP));
391   - dataMap.put("totalNum", totalNum.setScale(2, RoundingMode.HALF_UP));
392   - dataMap.put("totalPrice", totalPrice.setScale(2, RoundingMode.HALF_UP));
  398 + dataMap.put("totalQuantity", totalQuantity.doubleValue() > 0 ? totalQuantity.setScale(2, RoundingMode.HALF_UP) : null);
  399 + dataMap.put("totalActualQuantity", totalActualQuantity.doubleValue() > 0 ? totalActualQuantity.setScale(2, RoundingMode.HALF_UP) : null);
  400 + dataMap.put("totalNum", totalNum.doubleValue() > 0 ? totalNum.setScale(2, RoundingMode.HALF_UP) : null);
  401 + dataMap.put("totalPrice", totalPrice.doubleValue() > 0 ? totalPrice.setScale(2, RoundingMode.HALF_UP) : null);
393 402 // 流水号
394   - String serialNumber = "";
  403 + String serialNumber = createSerialNumber(null, "SHIPMENT_ORDER_SERIAL_NUMBER");
  404 + dataMap.put("serialNumber", serialNumber);
395 405 // 处理模板中的占位符
396 406 ExcelUtil.processTemplate(workbook, dataMap);
397 407 // 生成文件名
... ... @@ -490,4 +500,36 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
490 500 log.warn("清理临时文件失败", e);
491 501 }
492 502 }
  503 +
  504 +
  505 +
  506 + /**
  507 + * 生成当天流水号
  508 + *
  509 + * @return String
  510 + */
  511 + public String createSerialNumber(String pre, String key) {
  512 + // 1. 获取当前年月日(格式:yyyyMMdd)
  513 + String datePart = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
  514 + // 2. Redis自增序列
  515 + Long id = redisTemplate.opsForValue().increment(key, 1);
  516 + if (id != null && id == 1) {
  517 + // 计算到次日零点的秒数
  518 + LocalDateTime now = LocalDateTime.now();
  519 + LocalDateTime midnight = now.toLocalDate().plusDays(1).atStartOfDay();
  520 + long secondsUntilMidnight = Duration.between(now, midnight).getSeconds();
  521 +
  522 + redisTemplate.expire(key, secondsUntilMidnight, TimeUnit.SECONDS);
  523 + }
  524 + // 3. 补零到4位
  525 + String incrPart = String.format("%04d", id);
  526 + // 4. 拼接最终结果
  527 + String result = "";
  528 + if (StringUtils.isBlank(pre)) {
  529 + result = datePart + incrPart;
  530 + } else {
  531 + result = pre + datePart + incrPart;
  532 + }
  533 + return result;
  534 + }
493 535 }
... ...