Showing
3 changed files
with
48 additions
and
6 deletions
| @@ -34,6 +34,7 @@ import org.apache.commons.lang3.StringUtils; | @@ -34,6 +34,7 @@ import org.apache.commons.lang3.StringUtils; | ||
| 34 | import org.apache.poi.ss.usermodel.Sheet; | 34 | import org.apache.poi.ss.usermodel.Sheet; |
| 35 | import org.apache.poi.ss.usermodel.Workbook; | 35 | import org.apache.poi.ss.usermodel.Workbook; |
| 36 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | 36 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| 37 | +import org.springframework.data.redis.core.RedisTemplate; | ||
| 37 | import org.springframework.web.bind.annotation.DeleteMapping; | 38 | import org.springframework.web.bind.annotation.DeleteMapping; |
| 38 | import com.lframework.starter.web.core.controller.DefaultBaseController; | 39 | import com.lframework.starter.web.core.controller.DefaultBaseController; |
| 39 | import com.lframework.starter.web.core.annotations.security.HasPermission; | 40 | import com.lframework.starter.web.core.annotations.security.HasPermission; |
| @@ -47,11 +48,15 @@ import java.math.RoundingMode; | @@ -47,11 +48,15 @@ import java.math.RoundingMode; | ||
| 47 | import java.nio.file.Files; | 48 | import java.nio.file.Files; |
| 48 | import java.nio.file.Path; | 49 | import java.nio.file.Path; |
| 49 | import java.nio.file.Paths; | 50 | import java.nio.file.Paths; |
| 51 | +import java.time.Duration; | ||
| 52 | +import java.time.LocalDate; | ||
| 53 | +import java.time.LocalDateTime; | ||
| 50 | import java.time.format.DateTimeFormatter; | 54 | import java.time.format.DateTimeFormatter; |
| 51 | import java.util.ArrayList; | 55 | import java.util.ArrayList; |
| 52 | import java.util.Comparator; | 56 | import java.util.Comparator; |
| 53 | import java.util.List; | 57 | import java.util.List; |
| 54 | import java.util.Map; | 58 | import java.util.Map; |
| 59 | +import java.util.concurrent.TimeUnit; | ||
| 55 | import java.util.stream.Collectors; | 60 | import java.util.stream.Collectors; |
| 56 | import java.util.zip.ZipEntry; | 61 | import java.util.zip.ZipEntry; |
| 57 | import java.util.zip.ZipOutputStream; | 62 | import java.util.zip.ZipOutputStream; |
| @@ -74,6 +79,8 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | @@ -74,6 +79,8 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | ||
| 74 | private ShipmentsPlanDetailService shipmentsPlanDetailService; | 79 | private ShipmentsPlanDetailService shipmentsPlanDetailService; |
| 75 | @Resource | 80 | @Resource |
| 76 | private SysUserService sysUserService; | 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,7 +373,7 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | ||
| 366 | } | 373 | } |
| 367 | String latex = LatexFormulaExcelExporterUtil.convertToLatex(formulaComponentList); | 374 | String latex = LatexFormulaExcelExporterUtil.convertToLatex(formulaComponentList); |
| 368 | if (StringUtils.isNotBlank(latex)) { | 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 | ExcelUtil.setCellValue(sheet, startRow, 9, detail.getQuantity()); | 378 | ExcelUtil.setCellValue(sheet, startRow, 9, detail.getQuantity()); |
| 372 | if ("TYPE_2".equals(type)) { | 379 | if ("TYPE_2".equals(type)) { |
| @@ -375,9 +382,11 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | @@ -375,9 +382,11 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | ||
| 375 | ExcelUtil.setCellValue(sheet, startRow, 12, detail.getSalesPrice()); | 382 | ExcelUtil.setCellValue(sheet, startRow, 12, detail.getSalesPrice()); |
| 376 | ExcelUtil.setCellValue(sheet, startRow, 13, detail.getOrderType()); | 383 | ExcelUtil.setCellValue(sheet, startRow, 13, detail.getOrderType()); |
| 377 | ExcelUtil.setCellValue(sheet, startRow, 14, detail.getYieldBatchNo()); | 384 | ExcelUtil.setCellValue(sheet, startRow, 14, detail.getYieldBatchNo()); |
| 385 | + ExcelUtil.setCellValue(sheet, startRow, 15, " -- "); | ||
| 378 | } else { | 386 | } else { |
| 379 | ExcelUtil.setCellValue(sheet, startRow, 13, detail.getPackagingFee()); | 387 | ExcelUtil.setCellValue(sheet, startRow, 13, detail.getPackagingFee()); |
| 380 | ExcelUtil.setCellValue(sheet, startRow, 15, detail.getOrderType()); | 388 | ExcelUtil.setCellValue(sheet, startRow, 15, detail.getOrderType()); |
| 389 | + ExcelUtil.setCellValue(sheet, startRow, 16, " -- "); | ||
| 381 | } | 390 | } |
| 382 | startRow++; | 391 | startRow++; |
| 383 | } | 392 | } |
| @@ -386,12 +395,13 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | @@ -386,12 +395,13 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | ||
| 386 | dataMap.put("createDate", dateFormatter.format(orderInfo.getCreateTime())); | 395 | dataMap.put("createDate", dateFormatter.format(orderInfo.getCreateTime())); |
| 387 | SysUser user = sysUserService.findById(orderInfo.getCreateById()); | 396 | SysUser user = sysUserService.findById(orderInfo.getCreateById()); |
| 388 | dataMap.put("createBy", user.getName()); | 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 | ExcelUtil.processTemplate(workbook, dataMap); | 406 | ExcelUtil.processTemplate(workbook, dataMap); |
| 397 | // 生成文件名 | 407 | // 生成文件名 |
| @@ -490,4 +500,36 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | @@ -490,4 +500,36 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | ||
| 490 | log.warn("清理临时文件失败", e); | 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 | } |
No preview for this file type
No preview for this file type