demand: 账单导出:在客户账单管理模块中,当选择海运相关运单时,系统要支持上述模版导出,导出的账单表格要包含提单号、面单号、贵司编号(如没有填,输出为空)、起运港、目的港、箱量、件数、毛重、体积、费用名称、币种、金额
committer: heyu
This commit is contained in:
parent
a6f3454a48
commit
6a9780369c
@ -17,9 +17,11 @@ import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
@ -27,29 +29,26 @@ import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.alibaba.excel.util.MapUtils;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.metadata.WriteTable;
|
||||
import com.alibaba.excel.write.metadata.fill.FillConfig;
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.metadata.style.WriteFont;
|
||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.xdadan.erp.common.utils.DateUtils;
|
||||
import com.xdadan.erp.common.utils.DictUtils;
|
||||
import com.xdadan.erp.emis.domain.EmisExchangeRate;
|
||||
import com.xdadan.erp.emis.domain.EmisSettleSubBill;
|
||||
import com.xdadan.erp.emis.domain.EmisSettleSubBillFeeitem;
|
||||
import com.xdadan.erp.emis.domain.*;
|
||||
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||
import com.xdadan.erp.emis.domain.stat.BillPayStatInfo;
|
||||
import com.xdadan.erp.emis.domain.stat.OpenBillStatInfo;
|
||||
import com.xdadan.erp.emis.domain.vo.scan.ScanResult;
|
||||
import com.xdadan.erp.emis.service.EmisBaseService;
|
||||
import com.xdadan.erp.emis.service.IEmisExchangeRateService;
|
||||
import com.xdadan.erp.emis.service.IEmisSettleBillPayLogService;
|
||||
import com.xdadan.erp.emis.service.billexport.ExcelUtils;
|
||||
import com.xdadan.erp.emis.service.billexport.MapObjectUtil;
|
||||
import com.xdadan.erp.emis.mapper.EmisSettleSubBillFeeitemMapper;
|
||||
import com.xdadan.erp.emis.service.*;
|
||||
import com.xdadan.erp.emis.service.test.CustomCellWriteHandler;
|
||||
import com.xdadan.erp.emis.utils.WaybillHelper;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -67,9 +66,7 @@ import com.xdadan.erp.common.core.domain.AjaxResult;
|
||||
import com.xdadan.erp.common.core.page.TableDataInfo;
|
||||
import com.xdadan.erp.common.enums.BusinessType;
|
||||
import com.xdadan.erp.common.utils.poi.ExcelUtil;
|
||||
|
||||
import com.xdadan.erp.emis.domain.EmisSettleBill;
|
||||
import com.xdadan.erp.emis.service.IEmisSettleBillService;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
/**
|
||||
* 结算总账单Controller
|
||||
@ -511,6 +508,13 @@ public class EmisSettleBillController extends BaseController
|
||||
return AjaxResult.success("确认成功");
|
||||
}
|
||||
|
||||
@Log(title = "导出海运账单", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/exportSeaWayBill")
|
||||
public void exportSeaWayBill(HttpServletResponse response, EmisSettleBill emisSettleBill) {
|
||||
|
||||
emisSettleBillService.exportSeaWayBill(response, emisSettleBill);
|
||||
}
|
||||
|
||||
@Log(title = "导出账单", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/exportBill")
|
||||
public void exportBill(HttpServletResponse response, EmisSettleBill emisSettleBill)
|
||||
|
||||
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @Project: emis
|
||||
* @Title: EmisWaybill.java
|
||||
* @author linfso
|
||||
* @date 2024-04-11 05:48:01
|
||||
* @Copyright: ShangHai Duta 2022 All rights reserved.
|
||||
* @version v1.0
|
||||
* @Description: <p> 运单列表 实体类 </p>
|
||||
*/
|
||||
|
||||
package com.xdadan.erp.emis.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.xdadan.erp.common.annotation.audit.DataAuditField;
|
||||
import com.xdadan.erp.common.annotation.audit.DataAuditTable;
|
||||
import com.xdadan.erp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName EmisWaybillAndFeeitem
|
||||
* @Description 运单列表
|
||||
* @author heyu
|
||||
* @date 2025-04-03 11:48:01
|
||||
*/
|
||||
@Data
|
||||
@TableName("emis_waybill")
|
||||
@DataAuditTable(tableName = "emis_waybill",tableComment = "运单列表")
|
||||
public class EmisWaybillAndFeeitem extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String uuid;
|
||||
|
||||
@TableField
|
||||
@DataAuditField(fieldComment = "探路者面单号")
|
||||
private String billCode ;
|
||||
|
||||
@TableField
|
||||
@DataAuditField(fieldComment = "提单号(记录海运提单信息)")
|
||||
private String ladingBillCode ;
|
||||
|
||||
@TableField
|
||||
@DataAuditField(fieldComment = "贵司编号(记录相关业务的贵司编号)")
|
||||
private String companyCode ;
|
||||
|
||||
@TableField
|
||||
@DataAuditField(fieldComment = "起运港")
|
||||
private String departurePort ;
|
||||
|
||||
@TableField
|
||||
@DataAuditField(fieldComment = "目的港")
|
||||
private String destinationPort;
|
||||
|
||||
@TableField
|
||||
@DataAuditField(fieldComment = "箱量")
|
||||
private String boxQuantity;
|
||||
|
||||
@TableField
|
||||
@DataAuditField(fieldComment = "件数")
|
||||
private Integer parcelQty;
|
||||
|
||||
@TableField
|
||||
@DataAuditField(fieldComment = "毛重")
|
||||
private BigDecimal billWeight;
|
||||
|
||||
@TableField
|
||||
@DataAuditField(fieldComment = "体积")
|
||||
private BigDecimal totalVolume;
|
||||
|
||||
// 子账单费用明细信息
|
||||
@TableField(exist = false)
|
||||
private List<EmisSettleSubBillFeeitem> settleSubBillFeeitemList;
|
||||
}
|
||||
@ -13,6 +13,10 @@ package com.xdadan.erp.emis.mapper;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xdadan.erp.emis.domain.EmisSettleSubBillFeeitem;
|
||||
import com.xdadan.erp.emis.domain.EmisWaybill;
|
||||
import com.xdadan.erp.emis.domain.EmisWaybillAndFeeitem;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @ClassName EmisSettleSubBillFeeitemMapper
|
||||
* @Description <p> 子账单费用明细 Mapper 接口 </p>
|
||||
@ -80,4 +84,6 @@ public interface EmisSettleSubBillFeeitemMapper extends BaseMapper<EmisSettleSub
|
||||
|
||||
|
||||
public int deleteEmisSettleSubBillFeeitemByBillCode(String billCode);
|
||||
|
||||
List<EmisWaybillAndFeeitem> selectEmisWaybillListByBillCodeList(@Param("billCodeList") List<String> billCodeList);
|
||||
}
|
||||
|
||||
@ -17,6 +17,8 @@ import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||
import com.xdadan.erp.emis.domain.stat.BillPayStatInfo;
|
||||
import com.xdadan.erp.emis.domain.stat.OpenBillStatInfo;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @ClassName EmisSettleBillService
|
||||
* @Description 结算总账单
|
||||
@ -123,4 +125,6 @@ public interface IEmisSettleBillService extends IDataAuditService
|
||||
* @return
|
||||
*/
|
||||
public int reCalcSettleBillPayStatus(String settleBillNo);
|
||||
|
||||
void exportSeaWayBill(HttpServletResponse response, EmisSettleBill emisSettleBill);
|
||||
}
|
||||
|
||||
@ -0,0 +1,94 @@
|
||||
package com.xdadan.erp.emis.service.excelCellStrategy;
|
||||
|
||||
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.metadata.style.WriteFont;
|
||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
/**
|
||||
* @author heyu
|
||||
* @ClassName CellStyleStrategy.java
|
||||
* @Description CellStyleStrategy
|
||||
* @createTime 2025年04月09日
|
||||
*/
|
||||
public class CellStyleStrategy extends HorizontalCellStyleStrategy {
|
||||
|
||||
|
||||
private final WriteCellStyle headWriteCellStyle;
|
||||
|
||||
public CellStyleStrategy(WriteCellStyle headWriteCellStyle) {
|
||||
this.headWriteCellStyle = headWriteCellStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setHeadCellStyle(CellWriteHandlerContext context) {
|
||||
|
||||
context.getWriteSheetHolder().getSheet().setColumnWidth(0, (int) (15.88 * 256));
|
||||
context.getWriteSheetHolder().getSheet().setColumnWidth(1, (int) (20.5 * 256));
|
||||
context.getWriteSheetHolder().getSheet().setColumnWidth(2, (int) (10 * 256));
|
||||
context.getWriteSheetHolder().getSheet().setColumnWidth(3, (int) (12.5 * 256));
|
||||
context.getWriteSheetHolder().getSheet().setColumnWidth(4, (int) (18.75 * 256));
|
||||
// context.getWriteSheetHolder().getSheet().addMergedRegion(new CellRangeAddress(2,2,0,8));
|
||||
// context.getWriteSheetHolder().getSheet().addMergedRegion(new CellRangeAddress(2,2,9,11));
|
||||
// 根据行索引为不同级别的表头应用不同样式
|
||||
if (context.getRowIndex() == 0) {
|
||||
setRowStyle(context, (short) (27.75 * 20), (short) 14, IndexedColors.BLACK.getIndex(), false,IndexedColors.WHITE.getIndex());
|
||||
} else if (context.getRowIndex() > 0 && context.getRowIndex() < 3) {
|
||||
setRowStyle(context, (short) (27.75 * 20), (short) 12, IndexedColors.RED.getIndex(), true,IndexedColors.WHITE.getIndex());
|
||||
if (context.getCell().getStringCellValue().contains("出账日期")) {
|
||||
context.getRow().setHeight((short) (32 * 20));
|
||||
}
|
||||
} else if (context.getRow().getCell(0).getStringCellValue().contains("总计")) {
|
||||
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
|
||||
setRowStyle(context, (short) (23 * 20), (short) 8, IndexedColors.RED.getIndex(), true,IndexedColors.WHITE.getIndex());
|
||||
} else if (context.getRow().getCell(0).getStringCellValue().contains("小计")) {
|
||||
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
|
||||
setRowStyle(context, (short) (23 * 20), (short) 8, IndexedColors.BLACK.getIndex(), false,IndexedColors.WHITE.getIndex());
|
||||
} else {
|
||||
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
setRowStyle(context, (short) (23 * 20), (short) 10, IndexedColors.BLACK.getIndex(), true,IndexedColors.YELLOW.getIndex());
|
||||
// Workbook workbook = context.getWriteContext().getWorkbook();
|
||||
// CellStyle cellStyle = workbook.createCellStyle();
|
||||
// Font cellFont = workbook.createFont();
|
||||
// cellFont.setBold(false);
|
||||
// cellStyle.setFont(cellFont);
|
||||
// Cell cell = context.getCell();
|
||||
// if("贵司编号".equals(cell.getStringCellValue())){
|
||||
// cellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
|
||||
// cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
// cell.setCellStyle(cellStyle);
|
||||
// }else {
|
||||
// cellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
|
||||
// cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
// cell.setCellStyle(cellStyle);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
if (stopProcessing(context)) {
|
||||
return;
|
||||
}
|
||||
WriteCellData<?> cellData = context.getFirstCellData();
|
||||
WriteCellStyle.merge(this.headWriteCellStyle, cellData.getOrCreateStyle());
|
||||
}
|
||||
|
||||
protected void setContentCellStyle(CellWriteHandlerContext context) {
|
||||
context.getRow().setHeight((short) (23 * 20));
|
||||
}
|
||||
|
||||
private void setRowStyle(CellWriteHandlerContext context, short height, short fontSize, short fontColor, boolean isBold, short backgroundColor) {
|
||||
context.getRow().setHeight(height);
|
||||
// 背景色
|
||||
headWriteCellStyle.setFillForegroundColor(backgroundColor);
|
||||
// 创建字体实例
|
||||
WriteFont cellWriteFont = new WriteFont();
|
||||
// 设置字体大小
|
||||
cellWriteFont.setFontName("微软雅黑");
|
||||
cellWriteFont.setFontHeightInPoints(fontSize);
|
||||
cellWriteFont.setColor(fontColor);
|
||||
cellWriteFont.setBold(isBold);
|
||||
headWriteCellStyle.setWriteFont(cellWriteFont);
|
||||
}
|
||||
}
|
||||
@ -11,10 +11,22 @@
|
||||
package com.xdadan.erp.emis.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.xdadan.erp.common.core.domain.AjaxResult;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.metadata.WriteTable;
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.metadata.style.WriteFont;
|
||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.xdadan.erp.common.utils.DateUtils;
|
||||
import com.xdadan.erp.common.utils.StringUtils;
|
||||
import com.xdadan.erp.emis.domain.*;
|
||||
@ -25,15 +37,24 @@ import com.xdadan.erp.emis.domain.stat.BillPayStatInfo;
|
||||
import com.xdadan.erp.emis.domain.stat.OpenBillStatInfo;
|
||||
import com.xdadan.erp.emis.mapper.*;
|
||||
import com.xdadan.erp.emis.service.EmisBaseService;
|
||||
import com.xdadan.erp.emis.service.excelCellStrategy.CellStyleStrategy;
|
||||
import com.xdadan.erp.emis.service.test.CustomCellWriteHandler;
|
||||
import com.xdadan.erp.emis.utils.WaybillHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.xdadan.erp.emis.service.IEmisSettleBillService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 结算总账单Service业务层处理
|
||||
*
|
||||
@ -60,6 +81,12 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
|
||||
@Autowired
|
||||
private EmisSettlePayRelMapper emisSettlePayRelMapper;
|
||||
|
||||
@Autowired
|
||||
private EmisBaseService emisBaseService;
|
||||
|
||||
@Autowired
|
||||
private EmisSettleSubBillFeeitemMapper emisSettleSubBillFeeitemMapper;
|
||||
|
||||
/**
|
||||
* 获取稽核数据
|
||||
* @param id
|
||||
@ -807,6 +834,224 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportSeaWayBill(HttpServletResponse response, EmisSettleBill emisSettleBill) {
|
||||
try {
|
||||
log.info("cd exportSeaWayBill , emisSettleBill,{}", emisSettleBill);
|
||||
|
||||
Map<String, Object> textMap = new HashMap<>();
|
||||
|
||||
// 总账单
|
||||
EmisSettleBill bill = emisBaseService.getSettleBillBySettleBillNo(emisSettleBill.getSettleBillNo());
|
||||
|
||||
// 子账单
|
||||
List<EmisSettleSubBill> list = emisBaseService.selectSubBillListBySettleBillNo(emisSettleBill.getSettleBillNo());
|
||||
|
||||
// 运单号
|
||||
List<String> billCodeList = list.stream()
|
||||
.map(EmisSettleSubBill::getBillCode)
|
||||
.collect(Collectors.toList());
|
||||
if (org.springframework.util.CollectionUtils.isEmpty(list) || org.springframework.util.CollectionUtils.isEmpty(billCodeList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据运单号查询运单详情
|
||||
List<EmisWaybillAndFeeitem> emisWaybills = emisSettleSubBillFeeitemMapper.selectEmisWaybillListByBillCodeList(billCodeList);
|
||||
Map<String, EmisWaybillAndFeeitem> emisWaybillMap = emisWaybills.stream().collect(Collectors.toMap(EmisWaybillAndFeeitem::getBillCode, i -> i));
|
||||
if (MapUtil.isEmpty(emisWaybillMap) || org.springframework.util.CollectionUtils.isEmpty(emisWaybills)) {
|
||||
return;
|
||||
}
|
||||
log.info("select emisWaybills is success, emisWaybills,{}", emisWaybills);
|
||||
|
||||
// 运单费用条目
|
||||
List<EmisSettleSubBillFeeitem> emisWaybillFeeitemList = new ArrayList<>();
|
||||
emisWaybills.forEach(emisWaybill -> {
|
||||
if (Objects.nonNull(emisWaybill) && CollectionUtil.isNotEmpty(emisWaybill.getSettleSubBillFeeitemList())) {
|
||||
emisWaybillFeeitemList.addAll(emisWaybill.getSettleSubBillFeeitemList());
|
||||
}
|
||||
});
|
||||
calculateTotal(emisWaybillFeeitemList, textMap);
|
||||
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 filePath = "D:\\log\\stduent_01.xlsx";
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
|
||||
//内容的策略
|
||||
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
||||
contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
|
||||
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
WriteFont contentWriteFont = new WriteFont();
|
||||
contentWriteFont.setFontName("微软雅黑");
|
||||
contentWriteFont.setFontHeightInPoints((short) 8);
|
||||
contentWriteCellStyle.setWriteFont(contentWriteFont);
|
||||
|
||||
ExcelWriter excelWriter = EasyExcel.write(outputStream).excelType(ExcelTypeEnum.XLSX).build();
|
||||
List<List<String>> contentHeader = this.buildHeader();
|
||||
HorizontalCellStyleStrategy horizontalCellStyleStrategy =
|
||||
new HorizontalCellStyleStrategy(null, contentWriteCellStyle);
|
||||
// 构建大表头
|
||||
WriteSheet writeSheet1 = EasyExcel.writerSheet("sheet").needHead(Boolean.FALSE)
|
||||
.registerWriteHandler(horizontalCellStyleStrategy)
|
||||
.registerWriteHandler(new CellStyleStrategy(new WriteCellStyle())).build();
|
||||
List<List<String>> header1 = contentHeader.stream().map(item -> Collections.singletonList("探路供应链(上海)")).collect(Collectors.toList());
|
||||
WriteTable t1 = EasyExcel.writerTable(0).needHead(Boolean.TRUE).head(header1).build();
|
||||
excelWriter.write((Collection<?>) null, writeSheet1, t1);
|
||||
|
||||
List<List<String>> header2 = contentHeader.stream().map(item -> Collections.singletonList(year + "年" + month + "月海运费确认书")).collect(Collectors.toList());
|
||||
WriteTable t2 = EasyExcel.writerTable(1).needHead(Boolean.TRUE).head(header2).build();
|
||||
excelWriter.write((Collection<?>) null, writeSheet1, t2);
|
||||
|
||||
List<List<String>> header3 = contentHeader.stream().map(item -> Collections.singletonList("结算对象:探路供应链公司")).collect(Collectors.toList());
|
||||
header3.set(9, Collections.singletonList("出账日期:" + date));
|
||||
header3.set(10, Collections.singletonList("出账日期:" + date));
|
||||
header3.set(11, Collections.singletonList("出账日期:" + date));
|
||||
WriteTable t3 = EasyExcel.writerTable(2).needHead(Boolean.TRUE).head(header3).build();
|
||||
excelWriter.write((Collection<?>) null, writeSheet1, t3);
|
||||
|
||||
log.info("Building a large header is success");
|
||||
|
||||
List<String> excelKey = emisWaybillMap.keySet().stream().collect(Collectors.toList());
|
||||
int num = 3;
|
||||
for (int i = 0; i < excelKey.size(); i++) {
|
||||
List<List<String>> result = new ArrayList<>();
|
||||
Map<String, Object> subtotalMap = new HashMap<>();
|
||||
|
||||
EmisWaybillAndFeeitem emisWaybill = emisWaybillMap.get(excelKey.get(i));
|
||||
List<EmisSettleSubBillFeeitem> settleSubBillFeeitemList = emisWaybill.getSettleSubBillFeeitemList();
|
||||
calculateSubtotal(settleSubBillFeeitemList, subtotalMap);
|
||||
settleSubBillFeeitemList.forEach(item -> {
|
||||
result.add(Lists.newArrayList(emisWaybill.getLadingBillCode(), emisWaybill.getBillCode(), emisWaybill.getCompanyCode(), emisWaybill.getDeparturePort(),
|
||||
emisWaybill.getDestinationPort(), emisWaybill.getBoxQuantity(), String.valueOf(emisWaybill.getParcelQty()),
|
||||
emisWaybill.getBillWeight().stripTrailingZeros().toPlainString(),
|
||||
emisWaybill.getTotalVolume().stripTrailingZeros().toPlainString(),
|
||||
item.getFeeName(), item.getCurrency(), item.getBillFee().stripTrailingZeros().toPlainString()
|
||||
));
|
||||
});
|
||||
// 小表头
|
||||
WriteSheet sheet = EasyExcel.writerSheet("sheet")
|
||||
.needHead(Boolean.FALSE)
|
||||
.registerWriteHandler(new CustomCellWriteHandler()).build();
|
||||
WriteTable writeTable0 = EasyExcel.writerTable(num).head(contentHeader).build();
|
||||
excelWriter.write((Collection<?>) null, sheet, writeTable0);
|
||||
|
||||
// 行数据
|
||||
WriteTable writeTable1 = EasyExcel.writerTable(num + 1).needHead(Boolean.TRUE).head(contentHeader).build();
|
||||
excelWriter.write(result, writeSheet1, writeTable1);
|
||||
|
||||
log.info("Building the first row is success");
|
||||
|
||||
// 小计
|
||||
List<List<String>> nameHeader2 = contentHeader.stream().map(item -> Collections.singletonList("小计: USD金额:" + subtotalMap.get("usdSubtotal") + " CNY金额:" + subtotalMap.get("cnySubtotal"))).collect(Collectors.toList());
|
||||
WriteTable writeTable2 = EasyExcel.writerTable(num + 2).needHead(Boolean.TRUE).head(nameHeader2).build();
|
||||
excelWriter.write((Collection<?>) null, writeSheet1, writeTable2);
|
||||
num = num + 2;
|
||||
}
|
||||
// 总计
|
||||
List<List<String>> nameHeader3 = contentHeader.stream().map(item -> Collections.singletonList("总计: USD金额:" + textMap.get("usdTotal") + " CNY金额:" + textMap.get("cnyTotal"))).collect(Collectors.toList());
|
||||
WriteTable writeTable3 = EasyExcel.writerTable(num + 1).needHead(Boolean.TRUE).head(nameHeader3).build();
|
||||
excelWriter.write((Collection<?>) null, writeSheet1, writeTable3);
|
||||
|
||||
log.info("exportSeaWayBill is success");
|
||||
|
||||
// 设置响应头信息
|
||||
String fileName = bill.getSettleBillName() + "_海运账单.xlsx";
|
||||
response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()));
|
||||
response.setContentType("application/octet-stream");
|
||||
//关流
|
||||
excelWriter.finish();
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<List<String>> buildHeader() {
|
||||
List<List<String>> header = new ArrayList<>();
|
||||
header.add(Collections.singletonList("提单号"));
|
||||
header.add(Collections.singletonList("探路者面单号"));
|
||||
header.add(Collections.singletonList("贵司编号"));
|
||||
header.add(Collections.singletonList("起运港"));
|
||||
header.add(Collections.singletonList("目的港"));
|
||||
header.add(Collections.singletonList("箱量"));
|
||||
header.add(Collections.singletonList("件数"));
|
||||
header.add(Collections.singletonList("毛重"));
|
||||
header.add(Collections.singletonList("体积"));
|
||||
header.add(Collections.singletonList("费用名称"));
|
||||
header.add(Collections.singletonList("币种"));
|
||||
header.add(Collections.singletonList("金额"));
|
||||
return header;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void calculateTotal(List<EmisSettleSubBillFeeitem> emisWaybillFeeitemList, Map<String, Object> textMap) {
|
||||
Map<String, List<EmisSettleSubBillFeeitem>> emisWaybillFeeitemMap = emisWaybillFeeitemList.stream()
|
||||
.collect(Collectors.groupingBy(EmisSettleSubBillFeeitem::getCurrency));
|
||||
|
||||
if (MapUtil.isNotEmpty(emisWaybillFeeitemMap)) {
|
||||
Set<String> keySet = emisWaybillFeeitemMap.keySet();
|
||||
keySet.forEach(key -> {
|
||||
// 计算每种金额总计
|
||||
String count = emisWaybillFeeitemMap.get(key).stream()
|
||||
.map(EmisSettleSubBillFeeitem::getBillFee)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.stripTrailingZeros()
|
||||
.toPlainString();
|
||||
if (keySet.size() > 1) {
|
||||
countA(key, textMap, "usdTotal", count, "cnyTotal");
|
||||
} else {
|
||||
countB(key, textMap, "usdTotal", count, "cnyTotal");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void calculateSubtotal(List<EmisSettleSubBillFeeitem> emisWaybillFeeitemList, Map<String, Object> textMap) {
|
||||
Map<String, List<EmisSettleSubBillFeeitem>> emisWaybillFeeitemMap = emisWaybillFeeitemList.stream()
|
||||
.collect(Collectors.groupingBy(EmisSettleSubBillFeeitem::getCurrency));
|
||||
|
||||
if (MapUtil.isNotEmpty(emisWaybillFeeitemMap)) {
|
||||
Set<String> keySet = emisWaybillFeeitemMap.keySet();
|
||||
keySet.forEach(key -> {
|
||||
// 计算每种金额总计
|
||||
String count = emisWaybillFeeitemMap.get(key).stream()
|
||||
.map(EmisSettleSubBillFeeitem::getBillFee)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.stripTrailingZeros()
|
||||
.toPlainString();
|
||||
if (keySet.size() > 1) {
|
||||
countA(key, textMap, "usdSubtotal", count, "cnySubtotal");
|
||||
} else {
|
||||
countB(key, textMap, "usdSubtotal", count, "cnySubtotal");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void countA(String key, Map<String, Object> textMap, String usdSubtotal, String count, String cnySubtotal) {
|
||||
if ("USD".equals(key)) {
|
||||
textMap.put(usdSubtotal, count);
|
||||
} else {
|
||||
textMap.put(cnySubtotal, count);
|
||||
}
|
||||
}
|
||||
|
||||
private static void countB(String key, Map<String, Object> textMap, String usdSubtotal, String count, String cnySubtotal) {
|
||||
if ("USD".equals(key)) {
|
||||
textMap.put(usdSubtotal, count);
|
||||
textMap.put(cnySubtotal, "0");
|
||||
} else {
|
||||
textMap.put(cnySubtotal, count);
|
||||
textMap.put(usdSubtotal, "0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改结算总账单
|
||||
|
||||
@ -16,10 +16,50 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="orderNum" column="order_num" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="EmisWaybillAndFeeitemResult" type="com.xdadan.erp.emis.domain.EmisWaybillAndFeeitem">
|
||||
<!-- <id property="uuid" column="uuid"/>-->
|
||||
<result property="billCode" column="bill_code"/>
|
||||
<result property="ladingBillCode" column="lading_bill_code"/>
|
||||
<result property="companyCode" column="company_code"/>
|
||||
<result property="departurePort" column="departure_port"/>
|
||||
<result property="destinationPort" column="destination_port"/>
|
||||
<result property="boxQuantity" column="box_quantity"/>
|
||||
<result property="parcelQty" column="parcel_qty"/>
|
||||
<result property="billWeight" column="bill_weight"/>
|
||||
<result property="totalVolume" column="total_volume"/>
|
||||
<collection property="settleSubBillFeeitemList" javaType="java.util.List" resultMap="SettleSubBillFeeitemResult"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="SettleSubBillFeeitemResult" type="com.xdadan.erp.emis.domain.EmisSettleSubBillFeeitem">
|
||||
<result property="subBillNo" column="sub_bill_no"/>
|
||||
<result property="billCode" column="bill_code"/>
|
||||
<result property="feeCode" column="fee_code"/>
|
||||
<result property="feeName" column="fee_name"/>
|
||||
<result property="billFee" column="bill_fee"/>
|
||||
<result property="origFee" column="orig_fee"/>
|
||||
<result property="currency" column="currency"/>
|
||||
<result property="orderNum" column="order_num"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEmisSettleSubBillFeeitemVo">
|
||||
select id, sub_bill_no, bill_code, fee_code, fee_name, bill_fee, orig_fee, currency, order_num, del_flag, create_by, create_time, update_by, update_time, remark from emis_settle_sub_bill_feeitem
|
||||
</sql>
|
||||
|
||||
<sql id="selectEmisWaybillAndFeeitemVo">
|
||||
select a.bill_code,
|
||||
a.lading_bill_code,
|
||||
a.company_code,
|
||||
a.departure_port,
|
||||
a.destination_port,
|
||||
a.box_quantity,
|
||||
a.parcel_qty,
|
||||
a.bill_weight,
|
||||
a.total_volume,
|
||||
b.*
|
||||
from emis_waybill a
|
||||
left join emis_settle_sub_bill_feeitem b on a.bill_code = b.bill_code and b.del_flag = '0'
|
||||
</sql>
|
||||
|
||||
<select id="selectFeeitemListBySubBillNo" parameterType="String" resultMap="EmisSettleSubBillFeeitemResult">
|
||||
select id, sub_bill_no, bill_code, fee_code, fee_name, bill_fee, orig_fee, currency, order_num,remark
|
||||
from emis_settle_sub_bill_feeitem a
|
||||
@ -78,6 +118,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
from emis_settle_sub_bill_feeitem a
|
||||
where a.id = #{id}
|
||||
</select>
|
||||
|
||||
<!--根据运单号列表获取运单信息-->
|
||||
<select id="selectEmisWaybillListByBillCodeList" parameterType="list" resultMap="EmisWaybillAndFeeitemResult">
|
||||
<include refid="selectEmisWaybillAndFeeitemVo"/>
|
||||
<where>
|
||||
a.bill_code in
|
||||
<foreach collection="billCodeList" item="billCode" open="(" separator="," close=")">
|
||||
#{billCode}
|
||||
</foreach>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertEmisSettleSubBillFeeitem" parameterType="EmisSettleSubBillFeeitem" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into emis_settle_sub_bill_feeitem
|
||||
|
||||
Loading…
Reference in New Issue
Block a user