Merge pull request 'demand: tms-运单管理-寄件运单查询-新增导出出口清单接口' (#280) from aike into master

Reviewed-on: http://git.xdadan.loc/tanex/emis-service/pulls/280
This commit is contained in:
heyu 2025-12-26 15:37:04 +08:00
commit df3fde06db
2 changed files with 387 additions and 0 deletions

View File

@ -40,6 +40,7 @@ import com.xdadan.erp.emis.service.*;
import com.xdadan.erp.emis.service.print.IXddTplPrint;
import com.xdadan.erp.emis.service.print.cpcl.CvtTplToCpcl;
import com.xdadan.erp.emis.service.print.tanex.TanexTplPrintImpl;
import com.xdadan.erp.emis.service.excelCellStrategy.EmisWaybillCustomExportUtil;
import com.xdadan.erp.emis.utils.GZipUtils;
import com.xdadan.erp.emis.utils.PrintUtils;
import com.xdadan.erp.emis.utils.WaybillHelper;
@ -427,6 +428,46 @@ public class EmisWaybillController extends EmisBaseController
}
}
/**
* 导出出口清单
* @param response
* @param emisWaybill
*/
@Log(title = "导出出口清单", businessType = BusinessType.EXPORT)
@PreAuthorize("@ss.hasPermi('emis:emisWaybill:exportExportList')")
@RequestMapping("/exportExportList")
public void exportExportList(HttpServletResponse response, EmisWaybill emisWaybill) {
try {
// 设置通用权限查询参数
setPrivParams(emisWaybill);
List<EmisWaybill> list = null;
// 如果单号不为空,则去除其他参数
if(!StringUtils.isEmpty(emisWaybill.getBillCode())){
emisWaybill.setBillCode(WaybillHelper.formatQueryValue(emisWaybill.getBillCode()));
String[] billCodeSortList = emisWaybill.getBillCode().split(",");
if(billCodeSortList.length>1){
emisWaybill.getParams().put("billCodeSortList",Arrays.asList(billCodeSortList));
}
list = emisWaybillService.selectEmisWaybillList(emisWaybill);
}else{
// 设置通用权限查询参数
list = emisWaybillService.selectEmisWaybillList(emisWaybill);
}
if (list == null || list.isEmpty()) {
list = new ArrayList<>();
}
// 导出Excel
String fileName = "出口清单_" + System.currentTimeMillis();
EmisWaybillCustomExportUtil.exportCustomExcel(response, list, fileName);
} catch (Exception ex) {
log.error("导出出口清单失败", ex);
ex.printStackTrace();
}
}
@Log(title = "运单实时下单", businessType = BusinessType.INSERT)
@PostMapping(value = "/realSubmitOrder")
public AjaxResult realSubmitOrder(@Validated @RequestBody WaybillOrder waybillOrder, Integer isModify)

View File

@ -0,0 +1,346 @@
package com.xdadan.erp.emis.service.excelCellStrategy;
import com.xdadan.erp.emis.domain.EmisWaybill;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
/**
* 出口清单导出Excel工具类
*
* @author heyu
* @date 2025-12-26
*/
public class EmisWaybillCustomExportUtil {
private static final String[] HEADERS = {
"出口分运单号", "整单件数", "报关类型", "收件人", "英文收件人", "收件人国/区",
"收件人城市", "收件人地址", "英文收件人地址", "收件人电话", "发件人", "发件人证件类型",
"发件人证件号码", "发件人城市", "发件人地址", "发件人电话", "贸易国别", "监管方式",
"成交方式", "包装种类", "是否含木质包装", "是否旧物", "是否低温运输", "运费",
"运费币制", "保费", "保费币制", "杂费", "杂费币制"
};
private static final int[] COLUMN_WIDTHS = {
20, 12, 15, 20, 15, 15,
15, 40, 30, 15, 20, 15,
20, 15, 40, 15, 15, 15,
15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15
};
/**
* 导出出口清单Excel
*
* @param response HTTP响应
* @param dataList 数据列表
* @param sheetName 工作表名称(同时也是文件名,格式:出口清单_时间戳)
*/
public static void exportCustomExcel(HttpServletResponse response, List<EmisWaybill> dataList,
String sheetName) {
try {
// 创建工作簿
SXSSFWorkbook workbook = new SXSSFWorkbook(100);
Sheet sheet = workbook.createSheet(sheetName);
// 创建样式
CellStyle headerStyle = createHeaderStyle(workbook);
CellStyle dataStyle = createDataStyle(workbook);
CellStyle numberStyle = createNumberStyle(workbook);
// 创建表头
createHeader(sheet, headerStyle);
// 填充数据
int rowIndex = 1;
for (EmisWaybill waybill : dataList) {
Row row = sheet.createRow(rowIndex++);
row.setHeightInPoints(20);
// 出口分运单号 (billCode)
createCell(row, 0, waybill.getBillCode() != null ? waybill.getBillCode() : "", dataStyle);
// 整单件数 (parcelQty)
if (waybill.getParcelQty() != null) {
createCell(row, 1, waybill.getParcelQty(), numberStyle);
} else {
createCell(row, 1, "", dataStyle);
}
// 报关收件人 (空)
createCell(row, 2, "", dataStyle);
// 收件人 (receiveName)
createCell(row, 3, waybill.getReceiveName() != null ? waybill.getReceiveName() : "", dataStyle);
// 英文收件人 (空)
createCell(row, 4, "", dataStyle);
// 收件人国/区 (空)
createCell(row, 5, "", dataStyle);
// 收件人城市 (空)
createCell(row, 6, "", dataStyle);
// 收件人地址 (收货省+收货市+收货地址)
String receiveFullAddress = buildAddress(
waybill.getReceiveProvinceName(),
waybill.getReceiveCityName(),
waybill.getReceiveAddress()
);
createCell(row, 7, receiveFullAddress, dataStyle);
// 英文收件人地址 (空)
createCell(row, 8, "", dataStyle);
// 收件人电话 (receiveMobile)
createCell(row, 9, waybill.getReceiveMobile() != null ? waybill.getReceiveMobile() : "", dataStyle);
// 发件人 (sendName)
createCell(row, 10, waybill.getSendName() != null ? waybill.getSendName() : "", dataStyle);
// 发件人证件类型 (空)
createCell(row, 11, "", dataStyle);
// 发件人证件号码 (空)
createCell(row, 12, "", dataStyle);
// 发件人城市 (sendCityName)
createCell(row, 13, waybill.getSendCityName() != null ? waybill.getSendCityName() : "", dataStyle);
// 发件人地址 (寄件省+寄件市+寄件地址)
String sendFullAddress = buildAddress(
waybill.getSendProvinceName(),
waybill.getSendCityName(),
waybill.getSendAddress()
);
createCell(row, 14, sendFullAddress, dataStyle);
// 发件人电话 (sendMobile)
createCell(row, 15, waybill.getSendMobile() != null ? waybill.getSendMobile() : "", dataStyle);
// 贸易国别 (空)
createCell(row, 16, "", dataStyle);
// 监管方式 (空)
createCell(row, 17, "", dataStyle);
// 成交方式 (空)
createCell(row, 18, "", dataStyle);
// 包装种类 (空)
createCell(row, 19, "", dataStyle);
// 是否含木质包装 (空)
createCell(row, 20, "", dataStyle);
// 是否旧物 (空)
createCell(row, 21, "", dataStyle);
// 是否低温运输 (空)
createCell(row, 22, "", dataStyle);
// 运费 (空)
createCell(row, 23, "", dataStyle);
// 运费币制 (空)
createCell(row, 24, "", dataStyle);
// 保费 (空)
createCell(row, 25, "", dataStyle);
// 保费币制 (空)
createCell(row, 26, "", dataStyle);
// 杂费 (空)
createCell(row, 27, "", dataStyle);
// 杂费币制 (空)
createCell(row, 28, "", dataStyle);
}
// 设置列宽
setColumnWidths(sheet);
// 输出文件
outputFile(response, workbook, sheetName);
} catch (Exception e) {
throw new RuntimeException("导出Excel失败:" + e.getMessage(), e);
}
}
/**
* 创建表头样式
*/
private static CellStyle createHeaderStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
// 设置字体
Font font = workbook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 12);
font.setBold(true);
style.setFont(font);
// 设置背景色(浅绿色)
style.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// 设置边框
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
// 设置对齐方式
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/**
* 创建数据样式
*/
private static CellStyle createDataStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
// 设置字体
Font font = workbook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 11);
style.setFont(font);
// 设置边框
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
// 设置对齐方式
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setWrapText(true); // 自动换行
return style;
}
/**
* 创建数字样式
*/
private static CellStyle createNumberStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
// 设置字体
Font font = workbook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 11);
style.setFont(font);
// 设置边框
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
// 设置对齐方式
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
/**
* 构建完整地址(省·市·地址)
*/
private static String buildAddress(String province, String city, String address) {
StringBuilder sb = new StringBuilder();
if (province != null && !province.trim().isEmpty()) {
sb.append(province);
}
if (city != null && !city.trim().isEmpty()) {
if (sb.length() > 0) {
sb.append("·");
}
sb.append(city);
}
if (address != null && !address.trim().isEmpty()) {
if (sb.length() > 0) {
sb.append("·");
}
sb.append(address);
}
return sb.toString();
}
/**
* 创建表头
*/
private static void createHeader(Sheet sheet, CellStyle headerStyle) {
Row headerRow = sheet.createRow(0);
headerRow.setHeightInPoints(25);
for (int i = 0; i < HEADERS.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(HEADERS[i]);
cell.setCellStyle(headerStyle);
}
}
/**
* 创建单元格
*/
private static void createCell(Row row, int columnIndex, String value, CellStyle style) {
Cell cell = row.createCell(columnIndex);
cell.setCellValue(value != null ? value : "");
cell.setCellStyle(style);
}
/**
* 创建数字单元格
*/
private static void createCell(Row row, int columnIndex, Integer value, CellStyle style) {
Cell cell = row.createCell(columnIndex);
if (value != null) {
cell.setCellValue(value);
} else {
cell.setCellValue("");
}
cell.setCellStyle(style);
}
/**
* 设置列宽
*/
private static void setColumnWidths(Sheet sheet) {
for (int i = 0; i < COLUMN_WIDTHS.length; i++) {
sheet.setColumnWidth(i, COLUMN_WIDTHS[i] * 256);
}
}
/**
* 输出文件
*/
private static void outputFile(HttpServletResponse response, Workbook workbook, String sheetName)
throws IOException {
// 设置响应头
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode(sheetName + ".xlsx", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
// 输出文件
try (OutputStream outputStream = response.getOutputStream()) {
workbook.write(outputStream);
workbook.close();
}
}
}