Browse Source

汽运结算报表导出

huangfuli 1 năm trước cách đây
mục cha
commit
f71e705be3

+ 51 - 41
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/TranSettlementReportServiceImpl.java

@@ -47,6 +47,8 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.net.URLDecoder;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
@@ -833,6 +835,12 @@ public class TranSettlementReportServiceImpl extends ServiceImpl<TranSettlementR
         return "ok";
     }
 
+    /**
+     * 导出
+     * @param tranSettlementReport
+     * @param response
+     * @throws Exception
+     */
     @Override
     public void export(TranSettlementReport tranSettlementReport, HttpServletResponse response) throws Exception {
 
@@ -1076,7 +1084,7 @@ public class TranSettlementReportServiceImpl extends ServiceImpl<TranSettlementR
         sheet.setColumnWidth(20, 12 * 256 + 184);
         sheet.setColumnWidth(21, 12 * 256 + 184);
         sheet.setColumnWidth(22, 12 * 256 + 184);
-        sheet.setColumnWidth(23, 12 * 256 + 184);
+        sheet.setColumnWidth(23, "付款日期".getBytes().length*2*256);
         sheet.setColumnWidth(24, 1 * 256 + 184);
 
         // 创建单元格对象
@@ -1166,6 +1174,11 @@ public class TranSettlementReportServiceImpl extends ServiceImpl<TranSettlementR
         Float amountNotPayableTotal = 0f;//未付合计
         Float alreadyInvoiceTotal = 0f;//已开发票合计
 
+        DecimalFormat decimalFormat=new DecimalFormat("0.00");
+        contextstyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
+        contextstyle1.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
+
+
         for (int i = 0; i < tranSettlementReport.getTranSettlementReportList().size(); i++) {
             TranSettlementReport tranSettlementReport1 = tranSettlementReport.getTranSettlementReportList().get(i);
             transportDamageTotal = transportDamageTotal + (tranSettlementReport1.getTransportDamage()!=null?tranSettlementReport1.getTransportDamage():0d);
@@ -1202,55 +1215,55 @@ public class TranSettlementReportServiceImpl extends ServiceImpl<TranSettlementR
         cell = rowp.createCell(4);
         cell.setCellStyle(styleDetail);
         cell = rowp.createCell(5);
-        cell.setCellValue(loadingWeightTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(loadingWeightTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(6);
-        cell.setCellValue(unloadingWeightTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(unloadingWeightTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(7);
-        cell.setCellValue(transportDamageTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(transportDamageTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(8);
-        cell.setCellValue(lossWeightTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(lossWeightTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(9);
-        cell.setCellValue(actualLossTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(actualLossTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(10);
-        cell.setCellValue(transportPriceTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(transportPriceTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(11);
-        cell.setCellValue(settlementPriceTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(settlementPriceTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(12);
-        cell.setCellValue(settlementWeightTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(settlementWeightTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(13);
-        cell.setCellValue(cargoDamageTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(cargoDamageTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(14);
-        cell.setCellValue(unloadingWeightTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(unloadingWeightTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(15);
-        cell.setCellValue(serviceChargeTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(serviceChargeTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(16);
-        cell.setCellValue(amountActuallyPaidTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(amountActuallyPaidTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(17);
-        cell.setCellValue(taxPointTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(taxPointTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(18);
-        cell.setCellValue(totalPayableTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(totalPayableTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(19);
-        cell.setCellValue(amountEdPayableTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(amountEdPayableTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(20);
-        cell.setCellValue(amountNotPayableTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(amountNotPayableTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(21);
-        cell.setCellValue(alreadyInvoiceTotal);
+        cell.setCellValue(Double.parseDouble(decimalFormat.format(alreadyInvoiceTotal)));
         cell.setCellStyle(contextstyle1);
         cell = rowp.createCell(22);
         cell.setCellStyle(styleDetail);
@@ -1331,7 +1344,6 @@ public class TranSettlementReportServiceImpl extends ServiceImpl<TranSettlementR
         cell.setCellStyle(styleDetail);
         rownum++;
 
-        DecimalFormat decimalFormat=new DecimalFormat(".00");
 
         // 详情信息
         if (org.apache.commons.collections.CollectionUtils.isNotEmpty(tranSettlementReport.getTranSettlementReportList())) {
@@ -1352,65 +1364,63 @@ public class TranSettlementReportServiceImpl extends ServiceImpl<TranSettlementR
                 cell = rowx.createCell(4);
                 cell.setCellValue(editString(tranSettlementReport1.getCarNo()));
                 cell.setCellStyle(styleDetail);
+                DecimalFormat df = new DecimalFormat("0.00");
+                df.setRoundingMode(RoundingMode.HALF_UP);
                 cell = rowx.createCell(5);
-                cell.setCellValue(editFloat(tranSettlementReport1.getLoadingWeight()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(Double.valueOf(tranSettlementReport1.getLoadingWeight() != null ? tranSettlementReport1.getLoadingWeight(): 0)))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(6);
-                cell.setCellValue(editFloat(tranSettlementReport1.getUnloadingWeight()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(Double.valueOf(tranSettlementReport1.getUnloadingWeight() != null ? tranSettlementReport1.getUnloadingWeight(): 0)))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(7);
-                cell.setCellValue(editDouble(tranSettlementReport1.getTransportDamage()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getTransportDamage() != null ? tranSettlementReport1.getTransportDamage(): 0))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(8);
-                cell.setCellValue(editFloat(tranSettlementReport1.getLossWeight()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(Double.valueOf(tranSettlementReport1.getLossWeight() != null ? tranSettlementReport1.getLossWeight(): 0)))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(9);
-                cell.setCellValue(editDouble(tranSettlementReport1.getActualLoss()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getActualLoss() != null ? tranSettlementReport1.getActualLoss(): 0))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(10);
-                cell.setCellValue(editFloat(tranSettlementReport1.getTransportPrice()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(Double.valueOf(tranSettlementReport1.getTransportPrice() != null ? tranSettlementReport1.getTransportPrice(): 0)))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(11);
-                cell.setCellValue(editDouble(tranSettlementReport1.getSettlementPrice()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getSettlementPrice() != null ? tranSettlementReport1.getSettlementPrice(): 0))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(12);
-                cell.setCellValue(editFloat(tranSettlementReport1.getSettlementWeight()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(Double.valueOf(tranSettlementReport1.getSettlementWeight() != null ? tranSettlementReport1.getSettlementWeight(): 0)))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(13);
-                cell.setCellValue(editDouble(tranSettlementReport1.getCargoDamage()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getCargoDamage() != null ? tranSettlementReport1.getCargoDamage(): 0))));
                 cell.setCellStyle(contextstyle);
-                HSSFDataFormat df = wb.createDataFormat(); // 此处设置数据格式
-                contextstyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
-                HSSFDataFormat df1 = wb.createDataFormat(); // 此处设置数据格式
-                contextstyle1.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
                 cell = rowx.createCell(14);
                 if(tranSettlementReport1.getDeductionAmount()!=null){
-                    cell.setCellValue(editDouble(tranSettlementReport1.getDeductionAmount()));
+                    cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getDeductionAmount() != null ? tranSettlementReport1.getDeductionAmount(): 0))));
                 }
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(15);
-                cell.setCellValue(editDouble(tranSettlementReport1.getServiceCharge()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getServiceCharge() != null ? tranSettlementReport1.getServiceCharge(): 0))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(16);
-                cell.setCellValue(editDouble(tranSettlementReport1.getAmountActuallyPaid()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getAmountActuallyPaid() != null ? tranSettlementReport1.getAmountActuallyPaid(): 0))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(17);
-                cell.setCellValue(editDouble(tranSettlementReport1.getTaxPoint()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getTaxPoint() != null ? tranSettlementReport1.getTaxPoint(): 0))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(18);
-                cell.setCellValue(editDouble(tranSettlementReport1.getTotalPayable()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getTotalPayable() != null ? tranSettlementReport1.getTotalPayable(): 0))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(19);
-                cell.setCellValue(editFloat(tranSettlementReport1.getAmountEdPayable()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(Double.valueOf(tranSettlementReport1.getAmountEdPayable() != null ? tranSettlementReport1.getAmountEdPayable(): 0)))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(20);
-                cell.setCellValue(editFloat(tranSettlementReport1.getAmountNotPayable()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(Double.valueOf(tranSettlementReport1.getAmountNotPayable() != null ? tranSettlementReport1.getAmountNotPayable(): 0)))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(21);
-                cell.setCellValue(editFloat(tranSettlementReport1.getAlreadyInvoice()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(Double.valueOf(tranSettlementReport1.getAlreadyInvoice() != null ? tranSettlementReport1.getAlreadyInvoice(): 0)))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(22);
-                cell.setCellValue(editDouble(tranSettlementReport1.getGrainPrice()));
+                cell.setCellValue(editDouble(Double.parseDouble(df.format(tranSettlementReport1.getGrainPrice() != null ? tranSettlementReport1.getGrainPrice(): 0))));
                 cell.setCellStyle(contextstyle);
                 cell = rowx.createCell(23);
                 String date1 = addDateOneDay(tranSettlementReport1.getPaymentDate() != null ? tranSettlementReport1.getPaymentDate() : new Date());