From c8b153a7b1b77ec388f5574163185652b39b7290 Mon Sep 17 00:00:00 2001 From: wuwenxiong <646448316@qq.com> Date: Tue, 15 Feb 2022 16:01:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=AF=B9=E8=B4=A6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=90=88=E8=AE=A1=E5=8F=8A=E6=8F=90=E8=B4=A7=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stat/customer/CustomerStatService.java | 197 ++++++++++++++---- 1 file changed, 162 insertions(+), 35 deletions(-) diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/customer/CustomerStatService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/customer/CustomerStatService.java index d461e0a..fe9a191 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/customer/CustomerStatService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/customer/CustomerStatService.java @@ -1,13 +1,11 @@ package com.cowr.ssjygl.stat.customer; import com.cowr.common.utils.DataUtil; -import com.cowr.common.view.ReportExcelStyle; import com.jfinal.log.Log; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Record; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.util.ArrayList; @@ -30,38 +28,47 @@ public class CustomerStatService { String tempSql; String customerSql = ""; List paraList = new ArrayList<>(); + List ret; if (customer_id != null) { customerSql = " and t.customer_id = ? \n"; } - tempSql = " select t.customer_id, sum(t.total_price) total_price, sum(t.weight) total_weight, count(t.sn) total_cnt\n" + + tempSql = " select t.customer_id,\n" + + " sum(ifnull((case when t.sale_type = 0 THEN t.total_price END), 0)) sh_total_price,\n" + + " sum(ifnull((case when t.sale_type = 0 THEN t.weight END), 0)) sh_total_weight,\n" + + " sum(ifnull((case when t.sale_type = 0 THEN 1 END), 0)) sh_total_cnt,\n" + + " sum(ifnull((case when t.sale_type = 1 THEN t.total_price END), 0)) yh_total_price,\n" + + " sum(ifnull((case when t.sale_type = 1 THEN t.weight END), 0)) yh_total_weight,\n" + + " sum(ifnull((case when t.sale_type = 1 THEN 1 END), 0)) yh_total_cnt \n" + " from order_temp t\n" + " where t.customer_id is not null\n" + " and t.create_time <= ? \n" + " and t.state = 5\n" + - " and t.sale_type = 0\n" + customerSql + " group by t.customer_id\n"; sql = "select \n" + " t.customer_id id,\n" + " c.`name`,\n" + - " t.surplus,\n" + - " a.total_price,\n" + - " a.total_weight,\n" + - " a.total_cnt,\n" + - " b.amount,\n" + - " b.refund_amount,\n" + + " ifnull(a.sh_total_price, 0) sh_total_price,\n" + + " ifnull(a.yh_total_price,0) yh_total_price,\n" + + " ifnull(a.sh_total_weight,0) sh_total_weight,\n" + + " ifnull(a.yh_total_weight,0) yh_total_weight,\n" + + " ifnull(a.sh_total_cnt,0) sh_total_cnt,\n" + + " ifnull(a.yh_total_cnt,0) yh_total_cnt,\n" + + " ifnull(b.amount,0) amount,\n" + + " ifnull(b.refund_amount,0) refund_amount,\n" + " ifnull(p.presell_amount,0) presell_amount,\n" + - " b.amount - ifnull(a.total_price,0) - b.refund_amount - ifnull(p.presell_amount,0) then_surplus" + + " ifnull(p.presell_amount,0) - ifnull(a.yh_total_price,0) yh_surplus,\n" + + " ifnull(b.amount,0) - ifnull(a.sh_total_price,0) - ifnull(b.refund_amount,0) - ifnull(p.presell_amount,0) then_surplus" + " from prepay_customer t\n" + " left join customer c on c.id= t.customer_id\n" + - " left join (\n" + tempSql + " ) a on a.customer_id = t.customer_id\n" + + " left join (\n" + tempSql + " ) a on a.customer_id = t.customer_id\n" + " left join(\n" + " select a.customer_id, a.amount, ifnull(b.amount, 0) refund_amount\n" + " from(\n" + - " select t.customer_id, sum(t.amount) amount\n" + + " select t.customer_id, sum(t.amount) amount\n" + " from prepay_detail t\n" + " where t.state= 2\n" + " and t.verify_time <= ?\n" + @@ -92,7 +99,7 @@ public class CustomerStatService { String _sql = " select g.* from (\n" + sql + "\n) g where g.id = ?"; - return Db.find(_sql, paraList.toArray()); + ret = Db.find(_sql, paraList.toArray()); } else { paraList.add(querytm); paraList.add(querytm); @@ -105,8 +112,73 @@ public class CustomerStatService { sql += " order by t.customer_id"; - return Db.find(sql, paraList.toArray()); + ret = Db.find(sql, paraList.toArray()); } + + if (ret.size() > 0) { + int hj_sh_total_cnt = 0; + double hj_sh_total_weight = 0.0; + double hj_sh_total_price = 0.0; + + int hj_yh_total_cnt = 0; + double hj_yh_total_weight = 0.0; + double hj_yh_total_price = 0.0; + + double hj_total_amount = 0.0; + double hj_refund_amount = 0.0; + double hj_presell_amount = 0.0; + double hj_yh_surplus = 0.0; + double hj_then_surplus = 0.0; + + for (Record r : ret) { + int sh_total_cnt = r.getInt("sh_total_cnt") == null ? 0 : r.getInt("sh_total_cnt"); + double sh_total_weight = r.getDouble("sh_total_weight") == null ? 0.0 : r.getDouble("sh_total_weight"); + double sh_total_price = r.getDouble("sh_total_price") == null ? 0.0 : r.getDouble("sh_total_price"); + + int yh_total_cnt = r.getInt("yh_total_cnt") == null ? 0 : r.getInt("yh_total_cnt"); + double yh_total_weight = r.getDouble("yh_total_weight") == null ? 0.0 : r.getDouble("yh_total_weight"); + double yh_total_price = r.getDouble("yh_total_price") == null ? 0.0 : r.getDouble("yh_total_price"); + + double total_amount = r.getDouble("amount") == null ? 0.0 : r.getDouble("amount"); + double refund_amount = r.getDouble("refund_amount") == null ? 0.0 : r.getDouble("refund_amount"); + double presell_amount = r.getDouble("presell_amount") == null ? 0.0 : r.getDouble("presell_amount"); + double yh_surplus = r.getDouble("yh_surplus") == null ? 0.0 : r.getDouble("yh_surplus"); + double then_surplus = r.getDouble("then_surplus") == null ? 0.0 : r.getDouble("then_surplus"); + + hj_sh_total_cnt += sh_total_cnt; + hj_sh_total_weight += sh_total_weight; + hj_sh_total_price += sh_total_price; + + hj_yh_total_cnt += yh_total_cnt; + hj_yh_total_weight += yh_total_weight; + hj_yh_total_price += yh_total_price; + + hj_total_amount += total_amount; + hj_refund_amount += refund_amount; + hj_presell_amount += presell_amount; + hj_yh_surplus += yh_surplus; + hj_then_surplus += then_surplus; + } + + Record hj = new Record(); + hj.set("id", 99999); + hj.set("name", "合计"); + hj.set("sh_total_cnt", hj_sh_total_cnt); + hj.set("sh_total_weight", hj_sh_total_weight); + hj.set("sh_total_price", hj_sh_total_price); + hj.set("yh_total_cnt", hj_yh_total_cnt); + hj.set("yh_total_weight", hj_yh_total_weight); + hj.set("yh_total_price", hj_yh_total_price); + hj.set("amount", hj_total_amount); + hj.set("refund_amount", hj_refund_amount); + hj.set("presell_amount", hj_presell_amount); + hj.set("yh_surplus", hj_yh_surplus); + hj.set("then_surplus", hj_then_surplus); + + ret.add(hj); + } + + return ret; } public Workbook checkAccountExport(String tm, Integer customer_id, Integer customer_type_id) { @@ -118,37 +190,92 @@ public class CustomerStatService { // 表头 start Row row = sheet.createRow(0); int a = 0; - int end_col = 9; row.createCell(a++).setCellValue("序号"); - row.createCell(a++).setCellValue("客户"); - row.createCell(a++).setCellValue("余额"); - row.createCell(a++).setCellValue("预售金额"); - row.createCell(a++).setCellValue("累计充值"); - row.createCell(a++).setCellValue("累计退款"); - row.createCell(a++).setCellValue("累计消费金额(元)"); - row.createCell(a++).setCellValue("累计运输重量(吨)"); - row.createCell(a++).setCellValue("累计运输车次"); - // 表头 end + row.createCell(a++).setCellValue("客户名称"); + row.createCell(a++).setCellValue("销售"); + a += 2; + row.createCell(a++).setCellValue("预售提货"); + a += 2; + row.createCell(a++).setCellValue("付费金额(元)"); + row.createCell(a++).setCellValue("退费金额(元)"); + row.createCell(a++).setCellValue("预售金额(元)"); + row.createCell(a++).setCellValue("预售余额(元)"); + row.createCell(a++).setCellValue("账户余额(元)"); + + Row row2 = sheet.createRow(1); + int a2 = 2; + + row2.createCell(a2++).setCellValue("运输次数"); + row2.createCell(a2++).setCellValue("重量(吨)"); + row2.createCell(a2++).setCellValue("总价(元)"); + row2.createCell(a2++).setCellValue("运输次数"); + row2.createCell(a2++).setCellValue("重量(吨)"); + row2.createCell(a2++).setCellValue("总价(元)"); + + sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1)); + sheet.addMergedRegion(new CellRangeAddress(0, 0, 2, 4)); + sheet.addMergedRegion(new CellRangeAddress(0, 0, 5, 7)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 8, 8)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 9, 9)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 10, 10)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 11, 11)); + sheet.addMergedRegion(new CellRangeAddress(0, 1, 12, 12)); int datalen = list.size(); - + int colcnt = a; + int rowcnt = 2; for (int i = 0; i < datalen; i++) { Record record = list.get(i); - row = sheet.createRow(i + 1); + row = sheet.createRow(rowcnt++); a = 0; row.createCell(a++).setCellValue(i + 1); row.createCell(a++).setCellValue(record.getStr("name")); - row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "then_surplus")); - row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "presell_amount")); + row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "sh_total_cnt")); + row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "sh_total_weight")); + row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "sh_total_price")); + row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_total_cnt")); + row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_total_weight")); + row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_total_price")); row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "amount")); row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "refund_amount")); - row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "total_price")); - row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "total_weight")); - row.createCell(a++).setCellValue(record.getStr("total_cnt")); + row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "presell_amount")); + row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "yh_surplus")); + row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "then_surplus")); } - ReportExcelStyle.setCommonCellStyle(wb, sheet, datalen - 1, end_col); + // 通用单元格格式 + Font font = wb.createFont(); + CellStyle cellStyle = wb.createCellStyle(); + cellStyle.setBorderBottom(BorderStyle.THIN); + cellStyle.setBorderLeft(BorderStyle.THIN); + cellStyle.setBorderTop(BorderStyle.THIN); + cellStyle.setBorderRight(BorderStyle.THIN); + cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中 + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中 + cellStyle.setFont(font); + + for (int r = 0; r < rowcnt; r++) { + row = sheet.getRow(r); + if (row == null) { + row = sheet.createRow(r); + } + for (int c = 0; c < colcnt; c++) { + Cell cell = row.getCell(c); + + if (cell == null) { + cell = row.createCell(c); + } + cell.setCellStyle(cellStyle); + } + } + + for (int i = 1; i < 40; i++) { + sheet.setColumnWidth(i, 15 * 256); + } + + sheet.setColumnWidth(1, 40 * 256); return wb; }