diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java index b1e9094..53858d6 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java @@ -593,22 +593,52 @@ public class OrderStatService { * @param tm * @return */ - public List 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 salestatCustomer(String tm, Integer invoice_type) { - List dblist = Db.find(sql, OrderStateEnum.RECEIVED.getStateid(), tm + "%", OrderStateEnum.RECEIVED.getStateid(), tm + "%"); + List 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 list = salestatCustomer(tm); + public Workbook salestatCustomerExport(String tm, String title, String subtitle, Integer invoice_type) { + List 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); } /** diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java index f4d2187..68486ff 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java @@ -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() diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/CheckUndonOrderclusterJob.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/CheckUndonOrderclusterJob.java index 08f94dc..c840cf5 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/CheckUndonOrderclusterJob.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/CheckUndonOrderclusterJob.java @@ -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 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); + } + } } diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/stat/sale/OrderStatController.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/stat/sale/OrderStatController.java index e7695e7..b13cdba 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/stat/sale/OrderStatController.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/stat/sale/OrderStatController.java @@ -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)));