diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AfterSalesShippingDeviceMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AfterSalesShippingDeviceMapper.java index 253806fa..a8a7b048 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AfterSalesShippingDeviceMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/mapper/AfterSalesShippingDeviceMapper.java @@ -34,7 +34,12 @@ public interface AfterSalesShippingDeviceMapper * @param makeNo 关联生产订单号 * @return 选择设备信息 */ - public AfterSalesShippingDevice selectShippingDeviceByMakeNo(String makeNo); + public List selectShippingDeviceByMakeNo(String makeNo); + + + + + /** * 查询出货设备列表 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysSalesShippingInformController.java b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysSalesShippingInformController.java index 766d5287..e8a90202 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysSalesShippingInformController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysSalesShippingInformController.java @@ -138,6 +138,20 @@ public class SysSalesShippingInformController extends BaseController } + + /** + * 导出出货发票1模板 + * */ + @RequiresPermissions("system:salesShippingInform:exportShippingInvoiceOne") + @Log(title = "销售出货单", businessType = BusinessType.EXPORT) + @GetMapping("/exportShippingInvoiceOne/{outOrderCode}") + public void exportShippingInvoiceOne(@PathVariable("outOrderCode") String outOrderCode,HttpServletResponse response) { + + sysSalesShippingInformService.exportShippingInvoiceOne(outOrderCode, response); + } + + + /** * 导出出货单通知单模板 * */ diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/dto/ExportShippingInvoiceDto.java b/ruoyi-admin/src/main/java/com/ruoyi/system/dto/ExportShippingInvoiceDto.java new file mode 100644 index 00000000..eed8c878 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/dto/ExportShippingInvoiceDto.java @@ -0,0 +1,26 @@ +package com.ruoyi.system.dto; + +import lombok.Data; + +import java.math.BigDecimal; + +/** +* 出货发票导出模板类 +* */ + +@Data +public class ExportShippingInvoiceDto { + + private Integer index; + + private String materialName; + + private String makeNo; + + private Integer materialNum; + + private BigDecimal materialUsd; + + private BigDecimal materialUsdSum; + +} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesShippingInformService.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesShippingInformService.java index 20b00e61..ae03a86c 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesShippingInformService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysSalesShippingInformService.java @@ -139,4 +139,8 @@ public interface ISysSalesShippingInformService * */ void exportShippingInformOrder(String outOrderCode, HttpServletResponse response); + /** + * 导出出货发票1模板 + * */ + void exportShippingInvoiceOne(String outOrderCode, HttpServletResponse response); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java index 981987e2..27028be2 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesShippingInformServiceImpl.java @@ -22,6 +22,7 @@ import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.file.FileDownloadUtils; import com.ruoyi.system.domain.*; import com.ruoyi.system.dto.ExportShippingInformOrderDto; +import com.ruoyi.system.dto.ExportShippingInvoiceDto; import com.ruoyi.system.dto.ExportShippingOrderDto; import com.ruoyi.system.dto.ExportShippingPackingDto; import com.ruoyi.system.mapper.*; @@ -666,6 +667,88 @@ public class SysSalesShippingInformServiceImpl implements ISysSalesShippingInfor } } + + /** + * 导出出货单发票1模板 + * */ + @Override + public void exportShippingInvoiceOne(String outOrderCode, HttpServletResponse response) { + String fileName = "销售出货发票1.xlsx"; + FileDownloadUtils fileDownloadUtils = new FileDownloadUtils(); + try { + String fileRelativePath = fileDownloadUtils.getFileRelativePath(fileName); + if (StringUtils.isEmpty(outOrderCode)){ + log.warn("出货单号为空,请检查:{}", outOrderCode); + throw new RuntimeException("出货单号为空,请检查"); + } + + String realFileName = outOrderCode + "-" + fileName.substring(0, fileName.lastIndexOf(".")) + ".xlsx"; + + //设置响应头,指定文件和文件类型 + response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8")); + response.setContentType("application/octet-stream"); + + + SysSalesShippingInform sysSalesShippingInform = sysSalesShippingInformMapper.selectSysSalesShippingInformByCode(outOrderCode); + String salesOrderCode = sysSalesShippingInform.getSalesOrderCode(); + SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderBySaleNo(salesOrderCode); + + List sysSalesOrderChildren = salesOrderChildMapper.selectOrderChildListBySalesOrderCode(salesOrderCode); + + String makeNo = sysMakeOrder.getMakeNo(); + if (!StringUtils.isEmpty(makeNo)){ + List afterSalesShippingDevices = salesShippingDeviceMapper.selectShippingDeviceByMakeNo(makeNo); + } + + Map map = new HashMap<>(); + map.put("customerContact",sysSalesShippingInform.getCustomerContact()); + map.put("customerContactAddress",sysSalesShippingInform.getCustomerContactAddress()); + map.put("customerContactBillto",sysSalesShippingInform.getCustomerContactBillto()); + map.put("contactAddressBillto",sysSalesShippingInform.getContactAddressBillto()); + + + ArrayList exportShippingInvoiceDtos = new ArrayList<>(); + + AtomicInteger index = new AtomicInteger(1); + + for (SysSalesOrderChild sysSalesOrderChild : sysSalesOrderChildren) { + ExportShippingInvoiceDto exportShippingInvoiceDto = new ExportShippingInvoiceDto(); + exportShippingInvoiceDto.setIndex(index.getAndIncrement()); + exportShippingInvoiceDto.setMaterialName(sysSalesOrderChild.getMaterialName()); + exportShippingInvoiceDto.setMaterialNum(1); + + if (sysSalesOrderChild.getMaterialUsd() != null) { + exportShippingInvoiceDto.setMaterialUsd(new BigDecimal(sysSalesOrderChild.getMaterialUsd())); + } else { + // 如果 materialUsd 为 null,可以设置为默认值或者保持不变 + exportShippingInvoiceDto.setMaterialUsd(BigDecimal.ZERO); // 示例: 设置为0 + } + + if (sysSalesOrderChild.getMaterialUsdSum() != null) { + exportShippingInvoiceDto.setMaterialUsdSum(new BigDecimal(sysSalesOrderChild.getMaterialUsdSum())); + } else { + // 如果 materialUsdSum 为 null,可以设置为默认值或者保持不变 + exportShippingInvoiceDto.setMaterialUsdSum(BigDecimal.ZERO); // 示例: 设置为0 + } + exportShippingInvoiceDto.setMakeNo(makeNo); + // to do 缺少物料型号 + exportShippingInvoiceDtos.add(exportShippingInvoiceDto); + } + + + ExcelWriter workBook = EasyExcel.write(response.getOutputStream()).withTemplate(fileRelativePath).build(); + WriteSheet sheet = EasyExcel.writerSheet().build(); + FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build(); + workBook.fill(map, sheet); + workBook.fill(exportShippingInvoiceDtos, fillConfig, sheet); + workBook.finish(); + + + } catch (IOException e) { + throw new RuntimeException("文件处理失败",e); + } + } + /** * 导出出货通知单模板 * */ diff --git a/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml index 9ad1878c..9882c470 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml @@ -106,7 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"