From cc88a428ec29d03456451f301df424e7d53b801c Mon Sep 17 00:00:00 2001 From: "lisai17@sina.com" Date: Sun, 15 Nov 2020 00:03:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=A3=80=E6=9F=A5=E3=80=81=E6=B7=BB=E5=8A=A0=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E5=AF=B9=E8=B4=A6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stat/customer/CustomerStatService.java | 174 ++++++++++++++++++ .../ssjygl/jobs/CheckExceptionDataJob.java | 46 +++++ .../com/cowr/service/ssjygl/main/Config.java | 3 + .../stat/customer/CustomerStatController.java | 28 +++ .../src/main/resources/job.properties | 7 +- 5 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/customer/CustomerStatService.java create mode 100644 ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/CheckExceptionDataJob.java create mode 100644 ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/stat/customer/CustomerStatController.java 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 new file mode 100644 index 0000000..b20b951 --- /dev/null +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/customer/CustomerStatService.java @@ -0,0 +1,174 @@ +package com.cowr.ssjygl.stat.customer; + +import com.cowr.common.utils.DataUtil; +import com.cowr.common.view.ReportExcelStyle; +import com.jfinal.kit.StrKit; +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.xssf.usermodel.XSSFWorkbook; + +import java.util.ArrayList; +import java.util.List; + +public class CustomerStatService { + private static Log log = Log.getLog(CustomerStatService.class); + public static CustomerStatService me = new CustomerStatService(); + + /** + * 检查每日账户余额 + * + * @param tm + * @param customer_id + * @return + */ + public List checkAccount(String tm, Integer customer_id) { + String querytm = tm + " 23:59:59"; + String sql = null; + + if (customer_id != null) { + List paraList = new ArrayList<>(); + paraList.add(querytm); + paraList.add(customer_id); + paraList.add(querytm); + paraList.add(customer_id); + paraList.add(querytm); + paraList.add(customer_id); + paraList.add(customer_id); + + sql = "select 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" + + " b.amount - a.total_price - b.refund_amount then_surplus\n" + + " from prepay_customer t\n" + + " left join customer c on c.id= t.customer_id\n" + + " left join(\n" + + " select t.customer_id, sum(t.total_price) total_price, sum(t.weight) total_weight, count(t.sn) 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.customer_id = ? \n" + + " group by t.customer_id\n" + + " ) 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" + + " from prepay_detail t\n" + + " where t.state= 2\n" + + " and t.verify_time <= ?\n" + + " and t.customer_id = ? \n" + + " group by t.customer_id\n" + + " ) a\n" + + " left join(\n" + + " select t.customer_id, sum(t.amount) amount from refund_detail t\n" + + " left join (\n" + + " select max(t.change_time) confirm_time, t.refund_detail_id from refund_detail_state_history t where t.state = 3\n" + + " ) a on t.id = a.refund_detail_id\n" + + " where t.state = 3\n" + + " and a.confirm_time <= ?\n" + + " and t.customer_id = ? \n" + + " group by t.customer_id\n" + + " ) b on b.customer_id= a.customer_id\n" + + " ) b on b.customer_id= t.customer_id\n" + + " where t.customer_id = ? \n" + + " order by t.customer_id"; + + return Db.find(sql, paraList.toArray()); + } else { + sql = "select 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" + + " b.amount - a.total_price - b.refund_amount then_surplus\n" + + " from prepay_customer t\n" + + " left join customer c on c.id= t.customer_id\n" + + " left join(\n" + + " select t.customer_id, sum(t.total_price) total_price, sum(t.weight) total_weight, count(t.sn) 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" + + " group by t.customer_id\n" + + " ) 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" + + " from prepay_detail t\n" + + " where t.state= 2\n" + + " and t.verify_time <= ?\n" + + " group by t.customer_id\n" + + " ) a\n" + + " left join(\n" + + " select t.customer_id, sum(t.amount) amount from refund_detail t\n" + + " left join (\n" + + " select max(t.change_time) confirm_time, t.refund_detail_id from refund_detail_state_history t where t.state = 3\n" + + " ) a on t.id = a.refund_detail_id\n" + + " where t.state = 3\n" + + " and a.confirm_time <= ?\n" + + " group by t.customer_id\n" + + " ) b on b.customer_id= a.customer_id\n" + + " ) b on b.customer_id= t.customer_id\n" + + " order by t.customer_id"; + + return Db.find(sql, querytm, querytm, querytm); + } + } + + public Workbook checkAccountExport(String tm, Integer customer_id) { + List list = checkAccount(tm, customer_id); + + Workbook wb = new XSSFWorkbook(); + Sheet sheet = wb.createSheet(tm + " 客户对账表"); + + // 表头 start + Row row = sheet.createRow(0); + int a = 0; + 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 + + int datalen = list.size(); + int end_col = 8; + + for (int i = 0; i < datalen; i++) { + Record record = list.get(i); + row = sheet.createRow(i + 1); + 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, "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")); + } + + ReportExcelStyle.setCommonCellStyle(wb, sheet, datalen, end_col); + + return wb; + } + +} diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/CheckExceptionDataJob.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/CheckExceptionDataJob.java new file mode 100644 index 0000000..e3a63bb --- /dev/null +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/CheckExceptionDataJob.java @@ -0,0 +1,46 @@ +package com.cowr.service.ssjygl.jobs; + +import com.cowr.service.ssjygl.main.Config; +import com.jfinal.kit.HttpKit; +import com.jfinal.log.Log; +import com.jfinal.plugin.activerecord.Db; +import org.quartz.Job; +import org.quartz.JobExecutionContext; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +public class CheckExceptionDataJob implements Job { + private static Log log = Log.getLog(CheckExceptionDataJob.class); + + public void execute() { + int cnt = Db.queryInt("select count(t.sn) cnt from order_temp t\n" + + " left join transport p on t.sn = p.order_sn\n" + + " where p.id is null"); + + if (cnt > 0) { + String content = "浠水砂石系统有 " + cnt + " 条异常数据。"; + + log.debug(content); + + try { + HttpKit.get("http://owrsvr.cloudowr.cn/pubapi/weixin/sendTextMssage?touser=lisai&content=" + URLEncoder.encode(content, "utf-8")); + } catch (UnsupportedEncodingException e) { + log.error(e.getMessage(), e); + } + } + } + + @Override + public void execute(JobExecutionContext jobExecutionContext) { + try { + if (Config.isDev()) { + return; + } + + execute(); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + } +} diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/main/Config.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/main/Config.java index 7713b30..c10d79e 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/main/Config.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/main/Config.java @@ -16,6 +16,7 @@ import com.cowr.service.ssjygl.driver.DriverController; import com.cowr.service.ssjygl.invoice.invalidverify.InvoiceInvalidVerifyController; import com.cowr.service.ssjygl.invoice.log.InvoiceLogController; import com.cowr.service.ssjygl.invoice.receive.InvoiceReceiveController; +import com.cowr.service.ssjygl.jobs.CheckExceptionDataJob; import com.cowr.service.ssjygl.jobs.StatSmsJob; import com.cowr.service.ssjygl.netty.NettyServer; import com.cowr.service.ssjygl.order.invalidverify.OrderInvalidVerifyController; @@ -34,6 +35,7 @@ import com.cowr.service.ssjygl.purchase.PurchaseController; import com.cowr.service.ssjygl.sandfarm.SandfarmController; import com.cowr.service.ssjygl.sms.log.SmsLogController; import com.cowr.service.ssjygl.sms.noticecontact.SmsNoticeContactController; +import com.cowr.service.ssjygl.stat.customer.CustomerStatController; import com.cowr.service.ssjygl.supermarket.SupermarketController; import com.cowr.service.ssjygl.supermarket.SupermarketSyncService; import com.cowr.service.ssjygl.supermarket.customerdistance.SupermarketCustomerDistanceController; @@ -199,6 +201,7 @@ public class Config extends JFinalConfig { me.add("/stat/transfer", OrderTransferStatController.class); me.add("/stat/purchase", OrderPurchaseStatController.class); me.add("/stat/invoiceuse", InvoiceUseController.class); + me.add("/stat/customer", CustomerStatController.class); // -- 发票管理 me.add("/invoice/log", InvoiceLogController.class); diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/stat/customer/CustomerStatController.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/stat/customer/CustomerStatController.java new file mode 100644 index 0000000..6f6b8f1 --- /dev/null +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/stat/customer/CustomerStatController.java @@ -0,0 +1,28 @@ +package com.cowr.service.ssjygl.stat.customer; + +import com.cowr.common.validator.DayValidator; +import com.cowr.common.view.ExcelRender; +import com.cowr.common.view.Result; +import com.cowr.ssjygl.stat.customer.CustomerStatService; +import com.jfinal.aop.Before; +import com.jfinal.core.Controller; +import org.apache.poi.ss.usermodel.Workbook; + +public class CustomerStatController extends Controller { + + @Before(DayValidator.class) + public void checkAccount() { + String tm = get("tm"); + Integer customer_id = getInt("customer_id"); + + int export = getInt("export", 0); // 是否导出为exce 0 不导出,1 导出 + + if (export == 0) { + renderJson(Result.object(CustomerStatService.me.checkAccount(tm, customer_id))); + } else { + Workbook wb = CustomerStatService.me.checkAccountExport(tm, customer_id); + + render(new ExcelRender(tm + "_客户对账表_" + System.currentTimeMillis() + ".xlsx", wb)); + } + } +} diff --git a/ssjygl-xsx-service/src/main/resources/job.properties b/ssjygl-xsx-service/src/main/resources/job.properties index caca938..79d0e80 100644 --- a/ssjygl-xsx-service/src/main/resources/job.properties +++ b/ssjygl-xsx-service/src/main/resources/job.properties @@ -17,4 +17,9 @@ cleanossbakfile.enable=true # 每天 8 点统计发送前一天各销售情况,包含了客户信息汇总(发给客户)和总的汇总(发给公司) statsms.job=com.cowr.service.ssjygl.jobs.StatSmsJob statsms.cron= 0 0 8 * * ? -statsms.enable=true \ No newline at end of file +statsms.enable=true + +# 检查异常数据 +checkexceptiondata.job=com.cowr.service.ssjygl.jobs.CheckExceptionDataJob +checkexceptiondata.cron= 0 3 * * * ? +checkexceptiondata.enable=true \ No newline at end of file