添加异常数据检查、添加客户对账统计
parent
5a750ec7ae
commit
cc88a428ec
|
|
@ -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<Record> checkAccount(String tm, Integer customer_id) {
|
||||||
|
String querytm = tm + " 23:59:59";
|
||||||
|
String sql = null;
|
||||||
|
|
||||||
|
if (customer_id != null) {
|
||||||
|
List<Object> 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<Record> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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.invalidverify.InvoiceInvalidVerifyController;
|
||||||
import com.cowr.service.ssjygl.invoice.log.InvoiceLogController;
|
import com.cowr.service.ssjygl.invoice.log.InvoiceLogController;
|
||||||
import com.cowr.service.ssjygl.invoice.receive.InvoiceReceiveController;
|
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.jobs.StatSmsJob;
|
||||||
import com.cowr.service.ssjygl.netty.NettyServer;
|
import com.cowr.service.ssjygl.netty.NettyServer;
|
||||||
import com.cowr.service.ssjygl.order.invalidverify.OrderInvalidVerifyController;
|
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.sandfarm.SandfarmController;
|
||||||
import com.cowr.service.ssjygl.sms.log.SmsLogController;
|
import com.cowr.service.ssjygl.sms.log.SmsLogController;
|
||||||
import com.cowr.service.ssjygl.sms.noticecontact.SmsNoticeContactController;
|
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.SupermarketController;
|
||||||
import com.cowr.service.ssjygl.supermarket.SupermarketSyncService;
|
import com.cowr.service.ssjygl.supermarket.SupermarketSyncService;
|
||||||
import com.cowr.service.ssjygl.supermarket.customerdistance.SupermarketCustomerDistanceController;
|
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/transfer", OrderTransferStatController.class);
|
||||||
me.add("/stat/purchase", OrderPurchaseStatController.class);
|
me.add("/stat/purchase", OrderPurchaseStatController.class);
|
||||||
me.add("/stat/invoiceuse", InvoiceUseController.class);
|
me.add("/stat/invoiceuse", InvoiceUseController.class);
|
||||||
|
me.add("/stat/customer", CustomerStatController.class);
|
||||||
|
|
||||||
// -- 发票管理
|
// -- 发票管理
|
||||||
me.add("/invoice/log", InvoiceLogController.class);
|
me.add("/invoice/log", InvoiceLogController.class);
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,3 +18,8 @@ cleanossbakfile.enable=true
|
||||||
statsms.job=com.cowr.service.ssjygl.jobs.StatSmsJob
|
statsms.job=com.cowr.service.ssjygl.jobs.StatSmsJob
|
||||||
statsms.cron= 0 0 8 * * ?
|
statsms.cron= 0 0 8 * * ?
|
||||||
statsms.enable=true
|
statsms.enable=true
|
||||||
|
|
||||||
|
# 检查异常数据
|
||||||
|
checkexceptiondata.job=com.cowr.service.ssjygl.jobs.CheckExceptionDataJob
|
||||||
|
checkexceptiondata.cron= 0 3 * * * ?
|
||||||
|
checkexceptiondata.enable=true
|
||||||
Loading…
Reference in New Issue