lisai17@sina.com 2020-11-30 22:28:01 +08:00
parent c7c18bd88e
commit d7b7127f55
4 changed files with 147 additions and 38 deletions

View File

@ -593,22 +593,52 @@ public class OrderStatService {
* @param tm
* @return
*/
public List<Record> salestatCustomer(String tm) {
String sql = "select max(t.customer_id) id, t.customer_name name, count(*) as orderCount, sum(t.total_price) as totalPrice, sum(t.weight) as weight\n" +
" from (\n" +
" select ifnull(t.customer_id, t.customer_name) customer_id, t.customer_name, t.paid, t.total_price, t.weight\n" +
" from order_sale t\n" +
" where t.state = ? \n" +
" and t.create_time like ? \n" +
" union all\n" +
" select ifnull(t.customer_id, t.customer_name) customer_id, t.customer_name, t.paid, t.total_price, t.weight\n" +
" from order_temp t\n" +
" where t.state = ? \n" +
" and t.create_time like ? \n" +
" ) t\n" +
" group by t.customer_name";
public List<Record> salestatCustomer(String tm, Integer invoice_type) {
List<Record> dblist = Db.find(sql, OrderStateEnum.RECEIVED.getStateid(), tm + "%", OrderStateEnum.RECEIVED.getStateid(), tm + "%");
List<Record> dblist = null;
if (invoice_type != null) {
dblist = Db.find("select max(t.customer_id) id, t.customer_name name, count(*) as orderCount, sum(t.total_price) as totalPrice, sum(t.weight) as weight\n" +
" from (\n" +
" select ifnull(t.customer_id, t.customer_name) customer_id, t.customer_name, t.paid, t.total_price, t.weight\n" +
" from order_sale t\n" +
" where t.state = ? \n" +
" and t.invoice_type = ? \n" +
" and t.create_time like ? \n" +
" union all\n" +
" select ifnull(t.customer_id, t.customer_name) customer_id, t.customer_name, t.paid, t.total_price, t.weight\n" +
" from order_temp t\n" +
" where t.state = ? \n" +
" and t.invoice_type = ? \n" +
" and t.create_time like ? \n" +
" ) t\n" +
" group by t.customer_name",
OrderStateEnum.RECEIVED.getStateid(),
invoice_type,
tm + "%",
OrderStateEnum.RECEIVED.getStateid(),
invoice_type,
tm + "%"
);
} else {
dblist = Db.find("select max(t.customer_id) id, t.customer_name name, count(*) as orderCount, sum(t.total_price) as totalPrice, sum(t.weight) as weight\n" +
" from (\n" +
" select ifnull(t.customer_id, t.customer_name) customer_id, t.customer_name, t.paid, t.total_price, t.weight\n" +
" from order_sale t\n" +
" where t.state = ? \n" +
" and t.create_time like ? \n" +
" union all\n" +
" select ifnull(t.customer_id, t.customer_name) customer_id, t.customer_name, t.paid, t.total_price, t.weight\n" +
" from order_temp t\n" +
" where t.state = ? \n" +
" and t.create_time like ? \n" +
" ) t\n" +
" group by t.customer_name",
OrderStateEnum.RECEIVED.getStateid(),
tm + "%",
OrderStateEnum.RECEIVED.getStateid(),
tm + "%"
);
}
Record total = new Record();
total.set("id", 0);
@ -732,8 +762,8 @@ public class OrderStatService {
* @param tm
* @return
*/
public Workbook salestatCustomerExport(String tm, String title, String subtitle) {
List<Record> list = salestatCustomer(tm);
public Workbook salestatCustomerExport(String tm, String title, String subtitle, Integer invoice_type) {
List<Record> list = salestatCustomer(tm, invoice_type);
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet(title);
@ -789,7 +819,7 @@ public class OrderStatService {
}
public Workbook daysalestatCustomerExport(String tm) {
public Workbook daysalestatCustomerExport(String tm, Integer invoice_type) {
String title = "销售日统计";
@ -803,10 +833,10 @@ public class OrderStatService {
subtitle += title;
return salestatCustomerExport(tm, title, subtitle);
return salestatCustomerExport(tm, title, subtitle, invoice_type);
}
public Workbook monthsalestatCustomerExport(String tm) {
public Workbook monthsalestatCustomerExport(String tm, Integer invoice_type) {
String title = "销售月统计";
// 副标题 start
@ -819,7 +849,7 @@ public class OrderStatService {
subtitle += title;
return salestatCustomerExport(tm, title, subtitle);
return salestatCustomerExport(tm, title, subtitle, invoice_type);
}
/**

View File

@ -95,7 +95,7 @@ public class Config extends JFinalConfig {
public static DeviceThread deviceThread = new DeviceThread();
public static SocketIOService socketio = null;
private static boolean client_run = true;
public static final String CLINET_VERSION = "20201111";
public static final String CLINET_VERSION = "20201130";
public static String getRootPath() {
return PathKit.getWebRootPath()

View File

@ -1,25 +1,29 @@
package com.cowr.service.ssjygl.jobs;
import com.cowr.common.enums.OrderStateEnum;
import com.cowr.common.view.Result;
import com.cowr.model.Ordercluster;
import com.cowr.model.SyncTask;
import com.cowr.model.Sysuser;
import com.cowr.service.ssjygl.order.ordercluster.OrderclusterSyncService;
import com.cowr.service.ssjygl.synctask.SyncTaskService;
import com.cowr.ssjygl.order.ordercluster.OrderclusterService;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.util.*;
public class CheckUndonOrderclusterJob implements Job {
private static Log log = Log.getLog(CheckUndonOrderclusterJob.class);
@Override
public void execute(JobExecutionContext jobExecutionContext) {
/**
* ordercluster
*/
public void closeOrder() {
try {
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 0);
@ -88,4 +92,77 @@ public class CheckUndonOrderclusterJob implements Job {
log.error(e.getMessage(), e);
}
}
/**
* ordercluster
*/
public void forwardOrder() {
try {
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
List<Ordercluster> undonlist = Ordercluster.dao.find(
"select * from ordercluster t \n" +
" where t.state < ? \n" +
" and t.cutoff_time < ? ",
OrderStateEnum.RECEIVED.getStateid(), c.getTime());
if (undonlist != null && !undonlist.isEmpty()) {
log.debug("完成未执行完的订单 %d", undonlist.size());
for (Ordercluster ordercluster : undonlist) {
int ordercluster_id = ordercluster.getId();
BigDecimal over_weight = OrderclusterService.me.getOverWeight(ordercluster_id); // 按客户找集团订单已完成量
BigDecimal surplus_weight = ordercluster.getTotalWeight().subtract(over_weight); // 剩余未完成量
Sysuser user = new Sysuser();
user.setId(0);
user.setName("system");
Calendar cold = Calendar.getInstance();
cold.setTime(ordercluster.getCutoffTime());
cold.set(Calendar.DATE, 1);
Date cutoff_time = cold.getTime();
Result ret;
if (ordercluster.getCustomerId() != null) {
ret = OrderclusterSyncService.me.forwardCluster(ordercluster_id, surplus_weight, cutoff_time, user);
} else {
String trucks = Db.queryStr("select group_concat(t.truck_license) trucks from ordercluster_truck t\n" +
" where t.ordercluster_id = ?\n" +
" group by t.ordercluster_id", ordercluster_id);
ret = OrderclusterSyncService.me.forwardTemp(ordercluster_id, surplus_weight, cutoff_time, trucks, user);
}
if (ret.getCode() != Result.SUCCESS) {
log.error("自动转结失败。ordercluster_id:%s, err msg: %s", ordercluster_id, ret.getMsg());
}
try {
Thread.sleep(1000);
} catch (Exception ignored) {
}
}
log.debug("自动转结完成, %s");
} else {
log.debug("无未完成的订单");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
@Override
public void execute(JobExecutionContext jobExecutionContext) {
try {
forwardOrder();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}

View File

@ -142,11 +142,12 @@ public class OrderStatController extends BaseController {
@Before(DayValidator.class)
public void daystatCustomer() {
String tm = get("tm");
Integer invoice_type = getInt("invoice_type");
int export = getInt("export", 0);
if (export == 0) {
renderJson(Result.object(OrderStatService.me.salestatCustomer(tm)));
renderJson(Result.object(OrderStatService.me.salestatCustomer(tm, invoice_type)));
} else {
Workbook wb = OrderStatService.me.daysalestatCustomerExport(tm);
Workbook wb = OrderStatService.me.daysalestatCustomerExport(tm, invoice_type);
render(new ExcelRender(tm + "_销售日统计_" + System.currentTimeMillis() + ".xlsx", wb));
}
}
@ -156,13 +157,14 @@ public class OrderStatController extends BaseController {
*/
@Before(MonthValidator.class)
public void monthstatCustomer() {
String tm = get("tm");
int export = getInt("export", 0);
String tm = get("tm");
Integer invoice_type = getInt("invoice_type");
int export = getInt("export", 0);
if (export == 0) {
renderJson(Result.object(OrderStatService.me.salestatCustomer(tm)));
renderJson(Result.object(OrderStatService.me.salestatCustomer(tm, invoice_type)));
} else {
Workbook wb = OrderStatService.me.monthsalestatCustomerExport(tm);
Workbook wb = OrderStatService.me.monthsalestatCustomerExport(tm, invoice_type);
render(new ExcelRender(tm + "_销售月统计_" + System.currentTimeMillis() + ".xlsx", wb));
}
}
@ -366,8 +368,8 @@ public class OrderStatController extends BaseController {
@Before(StartAndEndIntervalValidator.class)
public void statRangeAllCustomer() {
String stm = get("stm");
String etm = get("etm");
String stm = get("stm");
String etm = get("etm");
int export = getInt("export", 0); // 是否导出为exce 0 不导出1 导出
if (export == 0) {
renderJson(Result.object(OrderStatService.me.yearStatByCustomer(stm, etm)));
@ -379,8 +381,8 @@ public class OrderStatController extends BaseController {
@Before(StartAndEndIntervalValidator.class)
public void statRangeAllSup() {
String stm = get("stm");
String etm = get("etm");
String stm = get("stm");
String etm = get("etm");
int export = getInt("export", 0); // 是否导出为exce 0 不导出1 导出
if (export == 0) {
renderJson(Result.object(OrderStatService.me.yearStatBySup(stm, etm)));