Преглед изворни кода

增加账单明细导出分项接口

nzf пре 3 година
родитељ
комит
e61390cc71

+ 15 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/warehouseBusiness/TWarehousebillsfeesController.java

@@ -12,6 +12,7 @@ import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.finance.excel.FleetExcel;
 import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees;
+import com.ruoyi.warehouseBusiness.excel.BillDetailsSubItem;
 import com.ruoyi.warehouseBusiness.excel.QueryMenu;
 import com.ruoyi.warehouseBusiness.service.ITWarehousebillsfeesService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -134,4 +135,18 @@ public class TWarehousebillsfeesController extends BaseController {
         ExcelUtil<QueryMenu> util = new ExcelUtil<>(QueryMenu.class);
         return util.exportExcel(list, "账单明细");
     }
+
+    /**
+     * 导出分项
+     */
+    @GetMapping("/exportBillSubItemDetails")
+    public AjaxResult exportBillSubItemDetails(TWarehousebillsfees tWarehousebillsfees){
+        if (tWarehousebillsfees.getfCorpid() == null) {
+            return AjaxResult.error("请选择客户名称");
+        } else {
+            BillDetailsSubItem billDetailsSubItem = new BillDetailsSubItem();
+            billDetailsSubItem.setfCorpid(tWarehousebillsfees.getfCorpid());
+            return tWarehousebillsfeesService.exportBillSubItemDetails(billDetailsSubItem);
+        }
+    }
 }

+ 23 - 13
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/excel/BillDetailsSubItem.java

@@ -1,7 +1,6 @@
 package com.ruoyi.warehouseBusiness.excel;
 
 import java.math.BigDecimal;
-import java.util.Date;
 
 /**
  * 账单明细分项实体
@@ -13,6 +12,9 @@ public class BillDetailsSubItem {
     // 作业类型
     private String twlfBusinesstype;
 
+    // 客户名称
+    private Long fCorpid;
+
     // 提单号
     private String fStatementno;
 
@@ -32,10 +34,10 @@ public class BillDetailsSubItem {
     private BigDecimal fVolumn;
 
     // 入库时间
-    private Date fOriginalbilldate;
+    private String fOriginalbilldate;
 
     // 出库时间
-    private Date fBsdate;
+    private String fBsdate;
 
     // 计费天数
     private int fBillingdays;
@@ -47,10 +49,10 @@ public class BillDetailsSubItem {
     private String createBy;
 
     // 计费时间
-    private Date fChargedate;
+    private String fChargedate;
 
     // 结费时间
-    private Date fStlamountdate;
+    private String fStlamountdate;
 
     // 仓库
     private int fWarehouseId;
@@ -74,6 +76,14 @@ public class BillDetailsSubItem {
         this.twlfBusinesstype = twlfBusinesstype;
     }
 
+    public Long getfCorpid() {
+        return fCorpid;
+    }
+
+    public void setfCorpid(Long fCorpid) {
+        this.fCorpid = fCorpid;
+    }
+
     public String getfStatementno() {
         return fStatementno;
     }
@@ -122,19 +132,19 @@ public class BillDetailsSubItem {
         this.fVolumn = fVolumn;
     }
 
-    public Date getfOriginalbilldate() {
+    public String getfOriginalbilldate() {
         return fOriginalbilldate;
     }
 
-    public void setfOriginalbilldate(Date fOriginalbilldate) {
+    public void setfOriginalbilldate(String fOriginalbilldate) {
         this.fOriginalbilldate = fOriginalbilldate;
     }
 
-    public Date getfBsdate() {
+    public String getfBsdate() {
         return fBsdate;
     }
 
-    public void setfBsdate(Date fBsdate) {
+    public void setfBsdate(String fBsdate) {
         this.fBsdate = fBsdate;
     }
 
@@ -162,19 +172,19 @@ public class BillDetailsSubItem {
         this.createBy = createBy;
     }
 
-    public Date getfChargedate() {
+    public String getfChargedate() {
         return fChargedate;
     }
 
-    public void setfChargedate(Date fChargedate) {
+    public void setfChargedate(String fChargedate) {
         this.fChargedate = fChargedate;
     }
 
-    public Date getfStlamountdate() {
+    public String getfStlamountdate() {
         return fStlamountdate;
     }
 
-    public void setfStlamountdate(Date fStlamountdate) {
+    public void setfStlamountdate(String fStlamountdate) {
         this.fStlamountdate = fStlamountdate;
     }
 

+ 108 - 15
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehousebillsfeesServiceImpl.java

@@ -2,6 +2,7 @@ package com.ruoyi.warehouseBusiness.service.impl;
 
 
 import com.ruoyi.basicData.mapper.TFeesMapper;
+import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
@@ -20,6 +21,7 @@ import org.apache.poi.ss.usermodel.VerticalAlignment;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.*;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -109,7 +111,8 @@ public class TWarehousebillsfeesServiceImpl implements ITWarehousebillsfeesServi
     }
 
     /**
-     *  查询报表
+     * 查询报表
+     *
      * @param tWarehousebillsfees
      * @return
      */
@@ -117,9 +120,9 @@ public class TWarehousebillsfeesServiceImpl implements ITWarehousebillsfeesServi
     public List<FleetExcel> selectFleetExcelList(TWarehousebillsfees tWarehousebillsfees) {
         List<FleetExcel> fleetExcelList = new ArrayList<>();
         // 开始月份
-        int  startMonth = 1;
+        int startMonth = 1;
         // 结束月份
-        int  endMonth = 1;
+        int endMonth = 1;
         if (StringUtils.isNotEmpty(tWarehousebillsfees.getfYears())) {
             // 年份
             List<String> month = tWarehousebillsfees.getfMonth();
@@ -151,7 +154,8 @@ public class TWarehousebillsfeesServiceImpl implements ITWarehousebillsfeesServi
     }
 
     /**
-     *  查询报表合计
+     * 查询报表合计
+     *
      * @param fleetExcelsList
      * @return
      */
@@ -212,22 +216,22 @@ public class TWarehousebillsfeesServiceImpl implements ITWarehousebillsfeesServi
         HSSFCellStyle cellStyle = getCellStyle(wb);
         // 创建标题,合并标题单元格
         // 行号
-        int ruwNum = 0;
+        int rowNum = 0;
         // 第一行
-        HSSFRow first = sheet.createRow(ruwNum++);
-        String[] left = {"序号","业务类型","作业类型","提单号","货名","客户","件数","重量","体积","入库时间","计算天数","货物堆存费"};
+        HSSFRow first = sheet.createRow(rowNum++);
+        String[] left = {"序号", "业务类型", "作业类型", "提单号", "货名", "客户", "件数", "重量", "体积", "入库时间", "计算天数", "货物堆存费"};
         List<String> middle = tFeesMapper.selectTFeesNameList();
-        String[] right = {"金额","计划员","计费时间","结费时间","仓库","备注"};
+        String[] right = {"金额", "计划员", "计费时间", "结费时间", "仓库", "备注"};
 
         List<String> all = new ArrayList<>();
-        Collections.addAll(all,left);
+        Collections.addAll(all, left);
         all.addAll(middle);
-        Collections.addAll(all,right);
+        Collections.addAll(all, right);
 
         int size = all.size();
-        for (int i = 0;i < size;i++){
+        for (int i = 0; i < size; i++) {
             HSSFCell tempCell = first.createCell(i);
-            if (i>11 && i<size-6){
+            if (i > 11 && i < size - 6) {
                 tempCell.setCellValue(all.get(i) + "单价");
             } else {
                 tempCell.setCellValue(all.get(i));
@@ -241,14 +245,103 @@ public class TWarehousebillsfeesServiceImpl implements ITWarehousebillsfeesServi
             return AjaxResult.error("无数据,导出Excel失败");
         }
 
-        for (BillDetailsSubItem billDetailsSubItem1 : list) {
+        int index = 1;
+        for (BillDetailsSubItem bd : list) {
+            HSSFRow tempRow = sheet.createRow(rowNum++);
+            // 循环单元格填入数据
+            for (int i = 0; i < size; i++) {
+                HSSFCell temCell = tempRow.createCell(i);
+                String cellValue = "";
+                if (i == 0) {
+                    cellValue = StringUtils.objToStr(index++);
+                } else if (i == 1) {
+                    // 业务类型
+                    cellValue = StringUtils.objToStr(bd.getfBusinesstype());
+                } else if (i == 2) {
+                    // 作业类型
+                    cellValue = StringUtils.objToStr(bd.getTwlfBusinesstype());
+                } else if (i == 3) {
+                    // 提单号
+                    cellValue = StringUtils.objToStr(bd.getfStatementno());
+                } else if (i == 4) {
+                    // 货名
+                    cellValue = StringUtils.objToStr(bd.getTgfName());
+                } else if (i == 5) {
+                    // 客户
+                    cellValue = StringUtils.objToStr(bd.getTcfName());
+                } else if (i == 6) {
+                    // 件数
+                    cellValue = StringUtils.objToStr(bd.getfQty());
+                } else if (i == 7) {
+                    // 重量
+                    cellValue = StringUtils.objToStr(bd.getfNetweight());
+                } else if (i == 8) {
+                    // 体积
+                    cellValue = StringUtils.objToStr(bd.getfVolumn());
+                } else if (i == 9) {
+                    // 入库时间
+                    cellValue = StringUtils.objToStr(bd.getfOriginalbilldate());
+                } else if (i == 10) {
+                    // 出库时间
+                    cellValue = StringUtils.objToStr(bd.getfBsdate());
+                } else if (i == 11) {
+                    // 计费天数
+                    cellValue = StringUtils.objToStr(bd.getfBillingdays());
+                } else if (i == size - 6) {
+                    // 金额
+                    cellValue = StringUtils.objToStr(bd.getfAmount());
+                } else if (i == size - 5) {
+                    // 计划员
+                    cellValue = StringUtils.objToStr(bd.getCreateBy());
+                } else if (i == size - 4) {
+                    // 计费时间
+                    cellValue = StringUtils.objToStr(bd.getfChargedate());
+                } else if (i == size - 3) {
+                    // 结费时间
+                    cellValue = StringUtils.objToStr(bd.getfStlamountdate());
+                } else if (i == size - 2) {
+                    // 仓库
+                    cellValue = StringUtils.objToStr(bd.getfWarehouseId());
+                } else if (i == size - 1) {
+                    // 备注
+                    cellValue = StringUtils.objToStr(bd.getRemark());
+                }
+                temCell.setCellValue(cellValue);
+                temCell.setCellStyle(cellStyle);
+            }
+        }
+
+        for (int i = 0; i < size; i++) {
+            sheet.autoSizeColumn(i);
+            sheet.setColumnWidth(i,sheet.getColumnWidth(i)*17/10);
+        }
+
+        // 导出 excel
+        String fileName = "账单明细导出分项.xls";
+        // 创建导出流
+        try {
+            OutputStream out = new FileOutputStream(getAbsoluteFile(fileName));
+            wb.write(out);
+            wb.close();
+            out.close();
+            return AjaxResult.success(fileName);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return AjaxResult.error("导出Excel失败");
+        }
+    }
 
+    private String getAbsoluteFile(String fileName) {
+        String downloadPath = RuoYiConfig.getDownloadPath() + fileName;
+        File desc = new File(downloadPath);
+        if (!desc.getParentFile().exists()) {
+            desc.getParentFile().mkdirs();
         }
-        return null;
+        return downloadPath;
     }
 
     // 获取 excel 表格的 cell 相关样式
-    public HSSFCellStyle getCellStyle(HSSFWorkbook wb){
+    public HSSFCellStyle getCellStyle(HSSFWorkbook wb) {
         HSSFCellStyle cellStyle = wb.createCellStyle();
         // 水平居中
         cellStyle.setAlignment(HorizontalAlignment.CENTER);

+ 5 - 4
ruoyi-warehouse/src/main/resources/mapper/warehouseBusiness/TWarehousebillsfeesMapper.xml

@@ -936,19 +936,20 @@
         select
             tw.f_business_type as fBusinesstype,
             twl.f_business_type as twlfBusinesstype,
+            tw.f_corpid as fCorpid,
             tw.f_statement_no as fStatementno,
             tg.f_name as tgfName,
             tc.f_name as tcfName,
             tw.f_qty as fQty,
             twb.f_netweight as fNetweight,
             twb.f_volumn as fVolumn,
-            twb.f_originalbilldate as fOriginalbilldate,
-            twb.f_bsdate as fBsdate,
+            DATE_FORMAT(twb.f_originalbilldate, '%Y-%m-%d') fOriginalbilldate,
+            DATE_FORMAT(twb.f_bsdate, '%Y-%m-%d') fBsdate,
             twb.f_billing_days as fBillingdays,
             tw.f_amount as fAmount,
             twb.create_by as createBy,
-            twb.f_chargedate as fChargedate,
-            tw.f_stlamount_date as fStlamountdate,
+            DATE_FORMAT(twb.f_chargedate, '%Y-%m-%d') fChargedate,
+            DATE_FORMAT(tw.f_stlamount_date, '%Y-%m-%d') fStlamountdate,
             tw.f_warehouseid as fWarehouseId,
             twb.remark as remark
         from t_warehousebillsfees tw