客户对账添加合计及提货统计

dev
wuwenxiong 2022-02-15 16:01:07 +08:00
parent e23125c6dd
commit c8b153a7b1
1 changed files with 162 additions and 35 deletions

View File

@ -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<Object> paraList = new ArrayList<>();
List<Record> 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;
}