diff --git a/ssjygl-xsct-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java b/ssjygl-xsct-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java index 0aca3fc..a41faa7 100644 --- a/ssjygl-xsct-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java +++ b/ssjygl-xsct-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java @@ -739,7 +739,8 @@ public class OrderStatService { // " and t.create_time like ? \n" + " and t.create_time between ? and ? \n" + saleParams + - " and t.invoice_type = ? \n"; + " and t.invoice_type = ? \n" + + " and t.sale_type != 2 \n"; if (customer_id != null) { sql += " and c.id = ? \n"; paraList.add(customer_id); @@ -765,7 +766,8 @@ public class OrderStatService { // " and t.create_time like ? \n" + " and t.create_time between ? and ? \n" + saleParams + - " and t.invoice_type = ? \n"; + " and t.invoice_type = ? \n"+ + " and t.sale_type != 2 \n"; if (customer_id != null) { sql += " and c.id = ? \n"; paraList.add(customer_id); @@ -789,6 +791,7 @@ public class OrderStatService { " from order_temp t\n" + " left join customer c on c.id = t.customer_id \n" + " where t.state = ? \n" + + " and t.sale_type != 2 \n" + // " and t.create_time like ? \n" + " and t.create_time between ? and ? \n" + saleParams; @@ -813,6 +816,7 @@ public class OrderStatService { " from order_temp t\n" + " left join customer c on c.id = t.customer_id \n" + " where t.state = ? \n" + + " and t.sale_type != 2 \n" + // " and t.create_time like ? \n" + " and t.create_time between ? and ? \n" + saleParams; @@ -3929,7 +3933,8 @@ public class OrderStatService { titleMap.put("weight", "销量(吨)"); titleMap.put("total_price", "金额(元)"); List> listMap = new ArrayList<>(); - List list = statYearBySup(tm, 2); +// List list = statYearBySup(tm, 2); + List list = statYearBySup1(tm); for (Record r : list) { Map map = r.getColumns(); listMap.add(map); @@ -4514,6 +4519,160 @@ public class OrderStatService { return type == 1 ? retChildren : retList; } + + /** + * [{ + * name: '竹瓦', key: '1' + * children: [ + * {name: '实售', key: '1_sh' , + * children: [ + * {name: '黄砂', key: '1_sh_1', order_num: 45, weight: 171.11, total_price: 14855.9}, + * {name: '鹅卵石', key: '1_sh_2', order_num: 3, weight: 36, total_price: 2376}, + * {name: '机制砂', key: '1_sh_3', order_num: 0, weight: 0, total_price: 0} + * ] + * }, + * {name: '预售', key: '1_yh' , + * children: [ + * {name: '-', key: '1_yh_1', order_num: '-', weight: '-', total_price: 380}] + * } + * ] + * } + * ] + * 砂站年统计 + * + * @param tm + * @return + */ + public List statYearBySup1(String tm) { + // 砂站 + List sups = Db.find("SELECT\n" + + " t.id,\n" + + " t.`name`\n" + + "FROM\n" + + " supermarket t\n" + + "WHERE\n" + + "t.type = 0 " + ); + + List shParamsList = new ArrayList<>(); + List yhParamsList = new ArrayList<>(); + String shParams = ""; + String yhParams = ""; + if (!StrKit.isBlank(tm)) { + shParams += " and t.date between ? and ? \n"; + yhParams += " and t.date between ? and ? \n"; + addTm(tm, shParamsList); + addTm(tm, yhParamsList); + } + + List retList = new ArrayList<>(); + + // 实售 + List shList = Db.find(getSaleSql(shParams,0), shParamsList.toArray()); + // 预售 + List yhList = Db.find(getSaleSql(yhParams,1), yhParamsList.toArray()); + + // 实售总 + List stList = Db.find(getTotalSaleSql(shParams,0), shParamsList.toArray()); + // 预售总 + List ytList = Db.find(getTotalSaleSql(yhParams,1), yhParamsList.toArray()); + + //所有总 + List totalList = Db.find("select sum(t.count) as order_num, sum(t.total_price) as total_price, sum(t.weight) as weight\n" + + " from order_end t where t.sale_type != 2" + shParams, yhParamsList.toArray()); + // 实售处理 + if (shList != null && !shList.isEmpty()) { + for (Record s : shList) { + s.set("key", s.getInt("id") + "_sh_"+s.getInt("product_id")); + s.set("item_name", "实售"); + } + retList.addAll(shList); + } + + // 预售处理 + if (yhList != null && !yhList.isEmpty()) { + for (Record s : yhList) { + s.set("key", s.getInt("id") + "_yh_"+s.getInt("product_id")); + s.set("item_name", "预售"); + } + retList.addAll(yhList); + } + + // 实售总处理 + if (stList != null && !stList.isEmpty()) { + for (Record s : stList) { + s.set("key", "hj_sh_" + s.getInt("product_id")); + s.set("item_name", "实售"); + s.set("name","合计"); + } + retList.addAll(stList); + } + + // 预售总处理 + if (ytList != null && !ytList.isEmpty()) { + for (Record s : ytList) { + s.set("key", "hj_yh_" + s.getInt("product_id")); + s.set("item_name", "预售"); + s.set("name","合计"); + } + retList.addAll(ytList); + } + + // 所有总处理 + if (totalList != null && !totalList.isEmpty()) { + for (Record s : totalList) { + s.set("key", "total"); + s.set("product_name","-"); + s.set("item_name", "-"); + s.set("name","总合计"); + } + retList.addAll(totalList); + } + + + return retList; + } + + private String getSaleSql(String params,Integer saleType){ + return "select s.id, s.name, p.id product_id, p.`name` product_name, ifnull(a.orderCount, 0) as order_num, ifnull(a.totalPrice, 0) as total_price, ifnull(a.weight, 0) as weight\n" + + " from " + +// "supermarket_product t\n" + +// " left join \n" + + " (select t.id, t.product_id" + + ", sum(t.count) as orderCount" + + ", sum(t.total_price) as totalPrice, sum(t.weight) as weight\n" + + " from (\n" + + " select t.supermarket_id as id, t.total_price, t.weight, t.product_id" + + ", t.count\n" + + " from order_end t \n" + + " where t.sale_type = " + saleType + " \n" + + params + + " ) t\n" + + " group by t.id, t.product_id\n" + + " ) a " + +// "on a.id = t.supermarket_id and a.product_id = t.product_id\n" + + " left join supermarket s on s.id = a.id\n" + + " left join product p on p.id = a.product_id order BY s.id, p.id ASC"; + } + + private String getTotalSaleSql(String params,Integer saleType){ + return "select p.id product_id, p.`name` product_name, ifnull(a.orderCount, 0) as order_num, ifnull(a.totalPrice, 0) as total_price, ifnull(a.weight, 0) as weight\n" + + " from (\n" + + " select t.product_id" + + ", sum(t.count) as orderCount" + + ", sum(t.total_price) as totalPrice, sum(t.weight) as weight\n" + + " from (\n" + + " select t.supermarket_id as id, t.total_price, t.weight, t.product_id" + + ", t.count\n" + + " from order_end t \n" + + " where t.sale_type = " + saleType + " \n" + + params + + " ) t\n" + + " group by t.product_id\n" + + " ) a \n" + + " left join product p on p.id = a.product_id order BY p.id ASC"; + } + public List statYearBySupLocal(String tm, int type) { // 砂站 List sups = Db.find("SELECT\n" + diff --git a/ssjygl-xsct-service/src/main/java/com/cowr/service/ssjygl/customer/contractsignedlog/CustomerContractSignedLogService.java b/ssjygl-xsct-service/src/main/java/com/cowr/service/ssjygl/customer/contractsignedlog/CustomerContractSignedLogService.java index 1853503..36b5cf2 100644 --- a/ssjygl-xsct-service/src/main/java/com/cowr/service/ssjygl/customer/contractsignedlog/CustomerContractSignedLogService.java +++ b/ssjygl-xsct-service/src/main/java/com/cowr/service/ssjygl/customer/contractsignedlog/CustomerContractSignedLogService.java @@ -152,17 +152,35 @@ public class CustomerContractSignedLogService extends BaseService { } public Result getByUserId(CustomerContractSignedLog model) { - CustomerContractSignedLog signedLog = CustomerContractSignedLog.dao.findFirst("select * from customer_contract_signed_log where user_id = ?", model.getId()); - if (signedLog == null) { + String selectsql = "select t.*, " + + " s1.name company_name,s1.attachment company_attachment, s2.name client_name , s2.attachment client_attachment "; + String fromsql = "from customer_contract_signed_log t" + + " left join customer_contract_signed s1 on t.company_signed_id = s1.id " + + " left join customer_contract_signed s2 on t.client_signed_id = s2.id " + + "where t.user_id = " + model.getId(); + Record record = Db.findFirst(selectsql + fromsql); + if (record == null) { return Result.failed(false, ""); } String htmlstr = ""; - CustomerContractTemplate template = CustomerContractTemplate.dao.findById(signedLog.getContractId()); + CustomerContractTemplate template = CustomerContractTemplate.dao.findById(record.getInt("contract_id")); if (template != null) { htmlstr = template.getHtmlstr(); } - Record ret = signedLog.toRecord(); - ret.set("htmlstr", htmlstr); - return Result.object(ret); + record.set("htmlstr", htmlstr); + return Result.object(record); + +// CustomerContractSignedLog signedLog = CustomerContractSignedLog.dao.findFirst("select * from customer_contract_signed_log where user_id = ?", model.getId()); +// if (signedLog == null) { +// return Result.failed(false, ""); +// } +// String htmlstr = ""; +// CustomerContractTemplate template = CustomerContractTemplate.dao.findById(signedLog.getContractId()); +// if (template != null) { +// htmlstr = template.getHtmlstr(); +// } +// Record ret = signedLog.toRecord(); +// ret.set("htmlstr", htmlstr); +// return Result.object(ret); } } diff --git a/ssjygl-xsct-service/src/main/java/com/cowr/service/ssjygl/stat/sale/OrderStatController.java b/ssjygl-xsct-service/src/main/java/com/cowr/service/ssjygl/stat/sale/OrderStatController.java index 86de9a5..d4f30a7 100644 --- a/ssjygl-xsct-service/src/main/java/com/cowr/service/ssjygl/stat/sale/OrderStatController.java +++ b/ssjygl-xsct-service/src/main/java/com/cowr/service/ssjygl/stat/sale/OrderStatController.java @@ -454,6 +454,22 @@ public class OrderStatController extends BaseController { } } + /** + * 按砂站年统计(新版) + */ + @Clear(AuthInterceptor.class) + public void statYearBySup1() { + String tm = get("tm"); + int export = getInt("export", 0); // 是否导出为exce 0 不导出,1 导出 + Boolean stat_product = getBoolean("stat_product", false); + if (export == 0) { + renderJson(Result.object(OrderStatService.me.statYearBySup1(tm))); + } else { + Workbook wb = OrderStatService.me.yearsalestatExportBySup(tm); + render(new ExcelRender("按砂站总销售汇总表_" + System.currentTimeMillis() + ".xlsx", wb)); + } + } + /** * 按取土场年统计 */