diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWarehouseInController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWarehouseInController.java index e72798cd7..8fc5379a9 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWarehouseInController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWarehouseInController.java @@ -11,13 +11,21 @@ package com.xdadan.erp.web.emis; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import cn.hutool.core.map.MapUtil; +import com.aliyun.tea.utils.IOUtils; import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter; +import com.xdadan.erp.emis.domain.WarehouseInExport; import com.xdadan.erp.emis.domain.exception.EmisBizError; +import com.xdadan.erp.emis.service.excelCellStrategy.ImageExcelHandler; import com.xdadan.erp.emis.utils.WaybillHelper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -201,4 +209,60 @@ public class EmisWarehouseInController extends EmisBaseController { return toAjax(emisWarehouseInService.deleteEmisWarehouseInByIds(ids)); } + + /** + * 导出进仓单详细信息 + */ + @PreAuthorize("@ss.hasPermi('emis:exportWarehouseInInfo:export')") + @Log(title = "导出进仓单详细信息", businessType = BusinessType.EXPORT) + @PostMapping("/exportWarehouseInInfo") + public void exportWarehouseInInfo(HttpServletResponse response, @RequestBody List inNos) { + try { + List list = emisWarehouseInService.selectWarehouseInExportData(inNos); + + // 转换为Object数组列表 + List dataList = list.stream() + .map(item -> new Object[] { + item.getInNo(), + item.getBillCode(), + item.getOrderSn(), + item.getEntryDate(), + item.getTotalParcelQty(), + item.getTotalWeight(), + item.getTotalVolume(), + item.getPrepareInExpress(), + item.getPrepareInBillCode(), + item.getGoodsName(), + item.getPrepareInSupplier(), + item.getImageUrls() + }) + .collect(Collectors.toList()); + + // 生成Excel文件 + byte[] excelBytes = ImageExcelHandler.generateExcel(dataList); + + String fileName = "进仓货物详细信息_" + UUID.randomUUID().toString() + ".xlsx"; + response.setHeader("Content-Disposition", + "attachment;filename*=utf-8''" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name())); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + + ServletOutputStream outputStream = response.getOutputStream(); + outputStream.write(excelBytes); + outputStream.flush(); + IOUtils.closeQuietly(outputStream); + + // 清理临时文件 + list.forEach(item -> { + if (item.getImageFiles() != null) { + item.getImageFiles().forEach(file -> { + if (file != null && file.exists()) { + file.delete(); + } + }); + } + }); + } catch (Exception e) { + throw new RuntimeException("导出进仓单数据失败:" + e.getMessage()); + } + } } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/WarehouseInExport.java b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/WarehouseInExport.java new file mode 100644 index 000000000..979ef0c95 --- /dev/null +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/WarehouseInExport.java @@ -0,0 +1,50 @@ +package com.xdadan.erp.emis.domain; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; +import com.alibaba.excel.annotation.ExcelIgnore; + +import java.io.File; +import java.util.List; + +@Data +public class WarehouseInExport { + @ExcelProperty("进仓单号") + private String inNo; + + @ExcelProperty("运单号") + private String billCode; + + @ExcelProperty("订单号") + private String orderSn; + + @ExcelProperty("进仓时间") + private String entryDate; + + @ExcelProperty("件数") + private Integer totalParcelQty; + + @ExcelProperty("重量") + private String totalWeight; + + @ExcelProperty("体积") + private String totalVolume; + + @ExcelProperty("快递公司") + private String prepareInExpress; + + @ExcelProperty("快递单号") + private String prepareInBillCode; + + @ExcelProperty("品名") + private String goodsName; + + @ExcelProperty("供应商") + private String prepareInSupplier; + + @ExcelProperty("图片") + private String imageUrls; + + @ExcelIgnore + private List imageFiles; +} \ No newline at end of file diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisWarehouseInMapper.java b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisWarehouseInMapper.java index 2c1abdcbb..4819b5c65 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisWarehouseInMapper.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisWarehouseInMapper.java @@ -31,6 +31,14 @@ public interface EmisWarehouseInMapper extends BaseMapper public EmisWarehouseIn selectEmisWarehouseInByInNo(String inNo); + /** + * 批量查询进仓单信息 + * + * @param inNos 进仓单号列表 + * @return 进仓单信息列表 + */ + List selectEmisWarehouseInByInNos(List inNos); + /** * 查询列表 * diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWarehouseInService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWarehouseInService.java index eec88ee2f..726fdc704 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWarehouseInService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWarehouseInService.java @@ -11,6 +11,7 @@ package com.xdadan.erp.emis.service; import java.util.List; import com.xdadan.erp.emis.domain.EmisWarehouseIn; +import com.xdadan.erp.emis.domain.WarehouseInExport; import com.xdadan.erp.emis.domain.exception.EmisBizError; /** @@ -71,4 +72,9 @@ public interface IEmisWarehouseInService * @return 结果 */ public int deleteEmisWarehouseInById(Long id); + + /** + * 根据进仓单号列表查询导出数据 + */ + List selectWarehouseInExportData(List inNos) throws EmisBizError; } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/excelCellStrategy/ImageExcelHandler.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/excelCellStrategy/ImageExcelHandler.java new file mode 100644 index 000000000..94dc4da98 --- /dev/null +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/excelCellStrategy/ImageExcelHandler.java @@ -0,0 +1,248 @@ +package com.xdadan.erp.emis.service.excelCellStrategy; + +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.RegionUtil; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.util.Units; +import org.apache.commons.io.IOUtils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.List; + +public class ImageExcelHandler { + private static final int IMAGE_COLUMN_START = 11; // 图片起始列 + private static final int ROW_HEIGHT = 80; // 行高(像素) + private static final int IMAGE_COLUMN_WIDTH = 15; // 每个图片列的宽度 + + public static byte[] generateExcel(List data) throws IOException { + try (Workbook workbook = new XSSFWorkbook()) { + Sheet sheet = workbook.createSheet("进仓货物信息"); + + // 创建样式 + CellStyle headerStyle = createHeaderStyle(workbook); + CellStyle dataStyle = createDataStyle(workbook); + CellStyle mergedHeaderStyle = createMergedHeaderStyle(workbook); // 新增合并单元格的样式 + + // 首先计算最大图片数量 + int maxImageCount = 1; + for (Object[] rowData : data) { + if (rowData[rowData.length - 1] != null) { + String[] imageUrls = rowData[rowData.length - 1].toString().split(","); + maxImageCount = Math.max(maxImageCount, imageUrls.length); + } + } + + // 设置列宽 + sheet.setColumnWidth(0, 15 * 256); // 进仓单号 + sheet.setColumnWidth(1, 15 * 256); // 运单号 + sheet.setColumnWidth(2, 15 * 256); // 订单号 + sheet.setColumnWidth(3, 20 * 256); // 进仓时间 + sheet.setColumnWidth(4, 10 * 256); // 件数 + sheet.setColumnWidth(5, 10 * 256); // 重量 + sheet.setColumnWidth(6, 10 * 256); // 体积 + sheet.setColumnWidth(7, 15 * 256); // 快递公司 + sheet.setColumnWidth(8, 15 * 256); // 快递单号 + sheet.setColumnWidth(9, 20 * 256); // 品名 + sheet.setColumnWidth(10, 15 * 256); // 供应商 + + // 设置所有图片列的宽度 + for (int i = 0; i < maxImageCount; i++) { + sheet.setColumnWidth(IMAGE_COLUMN_START + i, IMAGE_COLUMN_WIDTH * 256); + } + + // 创建标题行 + Row headerRow = sheet.createRow(0); + headerRow.setHeight((short) (30 * 20)); // 设置标题行高 + String[] headers = { "进仓单号", "运单号", "订单号", "进仓时间", "件数", "重量", "体积", "快递公司", "快递单号", "品名", "供应商", "图片" }; + + // 创建标题单元格 + for (int i = 0; i < headers.length; i++) { + Cell cell = headerRow.createCell(i); + cell.setCellValue(headers[i]); + if (i == IMAGE_COLUMN_START) { + cell.setCellStyle(mergedHeaderStyle); + } else { + cell.setCellStyle(headerStyle); + } + } + + // 创建数据行 + for (int i = 0; i < data.size(); i++) { + Object[] rowData = data.get(i); + Row row = sheet.createRow(i + 1); + row.setHeight((short) (ROW_HEIGHT * 20)); // 设置行高 + + // 填充数据 + for (int j = 0; j < rowData.length - 1; j++) { + Cell cell = row.createCell(j); + if (rowData[j] != null) { + cell.setCellValue(rowData[j].toString()); + } + cell.setCellStyle(dataStyle); + } + + // 为所有可能的图片列创建单元格(即使没有图片) + for (int j = 0; j < maxImageCount; j++) { + Cell imageCell = row.createCell(IMAGE_COLUMN_START + j); + imageCell.setCellStyle(dataStyle); + } + + // 处理图片 + if (rowData[rowData.length - 1] != null) { + String[] imageUrls = rowData[rowData.length - 1].toString().split(","); + Drawing drawing = sheet.createDrawingPatriarch(); + + for (int j = 0; j < imageUrls.length; j++) { + try { + String imageUrl = imageUrls[j].trim(); + if (imageUrl.isEmpty()) { + continue; + } + + URL url = new URL(imageUrl); + try (InputStream inputStream = url.openStream()) { + byte[] imageBytes = IOUtils.toByteArray(inputStream); + if (imageBytes.length == 0) { + System.err.println("Empty image data for URL: " + imageUrl); + continue; + } + + // 添加图片到工作簿 + int pictureIdx; + if (imageUrl.toLowerCase().endsWith(".png")) { + pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG); + } else { + pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG); + } + + // 计算当前图片的列 + int currentColumn = IMAGE_COLUMN_START + j; + + // 创建锚点,使用相对位置以实现居中 + ClientAnchor anchor = drawing.createAnchor( + Units.EMU_PER_PIXEL * 10, // dx1 - 左边距 + Units.EMU_PER_PIXEL * 5, // dy1 - 上边距 + -Units.EMU_PER_PIXEL * 10, // dx2 - 右边距 + -Units.EMU_PER_PIXEL * 5, // dy2 - 下边距 + currentColumn, // col1 + i + 1, // row1 + currentColumn + 1, // col2 + i + 2 // row2 + ); + + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE); + + // 创建图片并居中显示 + Picture picture = drawing.createPicture(anchor, pictureIdx); + picture.resize(0.99); // 调整图片大小以保持边距 + } + } catch (Exception e) { + System.err.println("Error processing image: " + e.getMessage()); + e.printStackTrace(); + } + } + } + } + + // 合并图片列的表头 + CellRangeAddress mergedRegion = new CellRangeAddress( + 0, // 起始行 + 0, // 结束行 + IMAGE_COLUMN_START, // 起始列 + IMAGE_COLUMN_START + maxImageCount - 1 // 结束列 + ); + sheet.addMergedRegion(mergedRegion); + + // 为合并后的单元格设置边框 + RegionUtil.setBorderTop(BorderStyle.MEDIUM, mergedRegion, sheet); + RegionUtil.setBorderBottom(BorderStyle.MEDIUM, mergedRegion, sheet); + RegionUtil.setBorderLeft(BorderStyle.MEDIUM, mergedRegion, sheet); + RegionUtil.setBorderRight(BorderStyle.MEDIUM, mergedRegion, sheet); + RegionUtil.setBottomBorderColor(IndexedColors.BLACK.getIndex(), mergedRegion, sheet); + RegionUtil.setTopBorderColor(IndexedColors.BLACK.getIndex(), mergedRegion, sheet); + RegionUtil.setLeftBorderColor(IndexedColors.BLACK.getIndex(), mergedRegion, sheet); + RegionUtil.setRightBorderColor(IndexedColors.BLACK.getIndex(), mergedRegion, sheet); + + // 写入到字节数组 + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + workbook.write(outputStream); + return outputStream.toByteArray(); + } + } + + private static CellStyle createMergedHeaderStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + // 设置背景色 + style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + // 设置边框 + style.setBorderTop(BorderStyle.MEDIUM); + style.setBorderBottom(BorderStyle.MEDIUM); + style.setBorderLeft(BorderStyle.MEDIUM); + style.setBorderRight(BorderStyle.MEDIUM); + // 设置边框颜色 + style.setTopBorderColor(IndexedColors.BLACK.getIndex()); + style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); + style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); + style.setRightBorderColor(IndexedColors.BLACK.getIndex()); + // 设置对齐方式 + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + // 设置字体 + Font font = workbook.createFont(); + font.setBold(true); + font.setFontHeightInPoints((short) 12); + style.setFont(font); + return style; + } + + private static CellStyle createHeaderStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + // 设置背景色 + style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + // 设置边框 + style.setBorderTop(BorderStyle.MEDIUM); + style.setBorderBottom(BorderStyle.MEDIUM); + style.setBorderLeft(BorderStyle.MEDIUM); + style.setBorderRight(BorderStyle.MEDIUM); + // 设置边框颜色 + style.setTopBorderColor(IndexedColors.BLACK.getIndex()); + style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); + style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); + style.setRightBorderColor(IndexedColors.BLACK.getIndex()); + // 设置对齐方式 + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + // 设置字体 + Font font = workbook.createFont(); + font.setBold(true); + font.setFontHeightInPoints((short) 12); + style.setFont(font); + return style; + } + + private static CellStyle createDataStyle(Workbook workbook) { + CellStyle style = workbook.createCellStyle(); + // 设置边框 + style.setBorderTop(BorderStyle.THIN); + style.setBorderBottom(BorderStyle.THIN); + style.setBorderLeft(BorderStyle.THIN); + style.setBorderRight(BorderStyle.THIN); + // 设置边框颜色 + style.setTopBorderColor(IndexedColors.BLACK.getIndex()); + style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); + style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); + style.setRightBorderColor(IndexedColors.BLACK.getIndex()); + // 设置对齐方式 + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + // 设置自动换行 + style.setWrapText(true); + return style; + } +} \ No newline at end of file diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java index f51068126..700e1e3ab 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java @@ -895,9 +895,9 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS log.info("get textMap is success, textMap,{}", textMap); // 出账日期 - String date = DateUtils.parseDateToStr("yyyy.M.dd", list.get(0).getBillDate()); - String year = DateUtils.parseDateToStr("yyyy", list.get(0).getBillDate()); - String month = DateUtils.parseDateToStr("M", list.get(0).getBillDate()); + String date = DateUtils.parseDateToStr("yyyy.M.dd", bill.getCreateTime()); + String year = DateUtils.parseDateToStr("yyyy", DateUtils.parseDate(bill.getBillMonth(),"yyyy-MM")); + String month = DateUtils.parseDateToStr("M", DateUtils.parseDate(bill.getBillMonth(),"yyyy-MM")); // String filePath = "D:\\log\\stduent_01.xlsx"; ServletOutputStream outputStream = response.getOutputStream(); diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWarehouseInServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWarehouseInServiceImpl.java index c5317fe2b..dc239de16 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWarehouseInServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWarehouseInServiceImpl.java @@ -8,23 +8,33 @@ * @Description:

进仓单 实体类

*/ -package com.xdadan.erp.emis.service.impl; + package com.xdadan.erp.emis.service.impl; -import java.math.BigDecimal; -import java.util.List; + import java.math.BigDecimal; + import java.util.ArrayList; + import java.util.List; + import java.util.stream.Collectors; + import java.io.InputStream; + import java.net.HttpURLConnection; + import java.net.URL; -import com.xdadan.erp.emis.domain.EmisWarehouseInBatch; -import com.xdadan.erp.emis.domain.EmisWaybill; -import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType; -import com.xdadan.erp.emis.domain.exception.EmisBizError; -import com.xdadan.erp.emis.mapper.EmisWarehouseInBatchMapper; -import com.xdadan.erp.emis.mapper.EmisWaybillMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import com.xdadan.erp.emis.domain.EmisWarehouseIn; -import com.xdadan.erp.emis.mapper.EmisWarehouseInMapper; -import com.xdadan.erp.emis.service.IEmisWarehouseInService; -import org.springframework.util.CollectionUtils; + import com.xdadan.erp.common.utils.DateUtils; + import lombok.extern.slf4j.Slf4j; + import org.apache.commons.io.IOUtils; + import java.io.File; + import org.apache.commons.io.FileUtils; + + import com.xdadan.erp.emis.domain.*; + import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType; + import com.xdadan.erp.emis.domain.exception.EmisBizError; + import com.xdadan.erp.emis.mapper.EmisWarehouseInBatchMapper; + import com.xdadan.erp.emis.mapper.EmisWaybillMapper; + import jodd.util.StringUtil; + import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.stereotype.Service; + import com.xdadan.erp.emis.mapper.EmisWarehouseInMapper; + import com.xdadan.erp.emis.service.IEmisWarehouseInService; + import org.springframework.util.CollectionUtils; /** * 进仓单Service业务层处理 @@ -33,6 +43,7 @@ import org.springframework.util.CollectionUtils; * @date 2024-05-22 00:20:31 */ @Service +@Slf4j public class EmisWarehouseInServiceImpl implements IEmisWarehouseInService { @Autowired @@ -185,4 +196,138 @@ public class EmisWarehouseInServiceImpl implements IEmisWarehouseInService return emisWarehouseInMapper.deleteEmisWarehouseInById(id); } + /** + * 下载图片到临时文件 + */ + private File downloadImage(String imageUrl) { + HttpURLConnection connection = null; + InputStream inputStream = null; + File tempFile = null; + + try { + // 创建临时文件 + String fileExt = imageUrl.substring(imageUrl.lastIndexOf(".")); + if (!fileExt.matches("\\.(jpg|jpeg|png|gif)$")) { + fileExt = ".jpg"; // 默认扩展名 + } + tempFile = File.createTempFile("warehouse_in_", fileExt); + tempFile.deleteOnExit(); // 程序退出时删除临时文件 + + // 下载图片 + URL url = new URL(imageUrl); + connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + + if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { + inputStream = connection.getInputStream(); + FileUtils.copyInputStreamToFile(inputStream, tempFile); + return tempFile; + } + } catch (Exception e) { + log.error("下载图片失败: {}", imageUrl, e); + if (tempFile != null && tempFile.exists()) { + tempFile.delete(); + } + } finally { + IOUtils.closeQuietly(inputStream); + if (connection != null) { + connection.disconnect(); + } + } + return null; + } + + @Override + public List selectWarehouseInExportData(List inNos) { + log.info("开始导出进仓单数据,进仓单号:{}", inNos); + + if (CollectionUtils.isEmpty(inNos)) { + log.warn("进仓单号列表为空"); + return new ArrayList<>(); + } + + // 批量查询所有进仓单数据 + List warehouseInList = emisWarehouseInMapper.selectEmisWarehouseInByInNos(inNos); + + if (CollectionUtils.isEmpty(warehouseInList)) { + log.warn("未查询到进仓单数据,进仓单号:{}", inNos); + return new ArrayList<>(); + } + + log.info("查询到{}条进仓单数据", warehouseInList.size()); + + List exportList = new ArrayList<>(); + + warehouseInList.forEach(warehouseIn -> { + if (warehouseIn.getStockInBatchList() != null) { + warehouseIn.getStockInBatchList().forEach(batch -> { + try { + WarehouseInExport exportDTO = new WarehouseInExport(); + // 进仓单号 + exportDTO.setInNo(warehouseIn.getInNo()); + // 运单号 + exportDTO.setBillCode(warehouseIn.getBillCode()); + // 订单号 + exportDTO.setOrderSn(warehouseIn.getOrderSn()); + // 进仓时间 + exportDTO.setEntryDate(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",batch.getEntryDate())); + + // 件数 + exportDTO.setTotalParcelQty(batch.getTotalParcelQty()); + // 重量 + exportDTO.setTotalWeight(batch.getTotalWeight().stripTrailingZeros().toPlainString()); + // 体积 + exportDTO.setTotalVolume(batch.getTotalVolume().stripTrailingZeros().toPlainString()); + // 快递公司 + exportDTO.setPrepareInExpress(batch.getPrepareInExpress()); + // 快递单号 + exportDTO.setPrepareInBillCode(batch.getPrepareInBillCode()); + // 品名 + String goodsName = batch.getCargoList().stream() + .map(EmisWarehouseInDtl::getGoodsName) + .distinct() + .filter(i -> StringUtil.isNotEmpty(i)) + .collect(Collectors.joining(",")); + if (StringUtil.isNotEmpty(goodsName)) { + exportDTO.setGoodsName(goodsName); + } + // 供应商 + exportDTO.setPrepareInSupplier(batch.getPrepareInSupplier()); + + // 处理图片 - 处理所有图片 + if (StringUtil.isNotEmpty(batch.getPicUrl())) { + String[] urls = batch.getPicUrl().split(","); + List imageFiles = new ArrayList<>(); + StringBuilder imageUrlsBuilder = new StringBuilder(); + for (String url : urls) { + File imageFile = downloadImage(url.trim()); + if (imageFile != null) { + imageFiles.add(imageFile); + if (imageUrlsBuilder.length() > 0) { + imageUrlsBuilder.append(","); + } + imageUrlsBuilder.append(url.trim()); + } + } + if (!imageFiles.isEmpty()) { + exportDTO.setImageFiles(imageFiles); + exportDTO.setImageUrls(imageUrlsBuilder.toString()); + } + } + + exportList.add(exportDTO); + } catch (Exception e) { + log.error("处理进仓单数据失败,进仓单号:{},批次信息:{}", warehouseIn.getInNo(), batch, e); + } + }); + } + }); + + log.info("数据处理完成,共处理{}条数据", exportList.size()); + return exportList; + } + + } diff --git a/emis-biz/src/main/resources/mapper/EmisWarehouseInMapper.xml b/emis-biz/src/main/resources/mapper/EmisWarehouseInMapper.xml index cf30b1352..cc97d7233 100644 --- a/emis-biz/src/main/resources/mapper/EmisWarehouseInMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisWarehouseInMapper.xml @@ -33,7 +33,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -260,6 +291,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where a.in_no = #{inNo} limit 1 + + + insert into emis_warehouse_in