砂站运输量统计
parent
66835a2f93
commit
451b90aae1
|
|
@ -21,7 +21,7 @@ public class Const {
|
|||
public static final long SUP_OFFLINE_TIME = 5 * 60 * 1000L; // 砂站离线时间限制,单位 毫秒
|
||||
|
||||
public static final String TEMP_CODE_AGGR_STAT = "SMS_205434464"; // 累计销售汇总
|
||||
public static final String TEMP_CODE_AGGR_STAT_2 = "SMS_212486582"; // 累计销售汇总-实际营收
|
||||
public static final String TEMP_CODE_AGGR_STAT_2 = "SMS_213772873"; // 累计销售汇总-实际营收
|
||||
public static final String TEMP_CODE_DAY_STAT = "SMS_205430436"; // 日销售汇总
|
||||
public static final String TEMP_CODE_CUSTOMER_DAY_STAT = "SMS_208985081"; // 客户日销售汇总
|
||||
public static final String TEMP_CODE_PEIE = "SMS_203673037"; // 配额分配通知
|
||||
|
|
@ -39,7 +39,7 @@ public class Const {
|
|||
SMS_TEMP_MAP.put(TEMP_CODE_DEPOSIT_SUCCESS, "${time}${customer_name}在${vendor}的预存${amount}元,合计余额${surplus}元。");
|
||||
SMS_TEMP_MAP.put(TEMP_CODE_DEPOSIT_FAIL, "${time}${customer_name}在${vendor}预存的${amount}元审核未通过,若有疑问请及时联系结算中心。");
|
||||
SMS_TEMP_MAP.put(TEMP_CODE_AGGR_STAT, "截至${time1}累计销售黄砂${aggr_weight}吨,共计${aggr_price}元,运输${aggr_cnt}辆次。账户累计${aggr_total_price}元,其中预付费客户总余额${customer_total_surplus}元。${time2}当日销售黄砂${total_weight}吨,共计${total_price}元,运输${total_cnt}辆次。");
|
||||
SMS_TEMP_MAP.put(TEMP_CODE_AGGR_STAT_2, "截至${time1}累计销售黄砂${aggr_weight}吨,共计${aggr_price}元,运输${aggr_cnt}辆次;其中2020年充值客户销售${customer_weight}吨,共${customer_price}元,2021年新增客户销售${revenue_weight}吨,共${revenue}元。账户累计${aggr_total_price}元,其中预付费客户总余额${customer_total_surplus}元。${time2}当日销售黄砂${total_weight}吨,共计${total_price}元,运输${total_cnt}辆次。");
|
||||
SMS_TEMP_MAP.put(TEMP_CODE_AGGR_STAT_2, "截至${time1}累计销售黄砂${aggr_weight}吨,共计${aggr_price}元,运输${aggr_cnt}辆次;其中2020年充值客户销售${customer_weight}吨,共${customer_price}元,2021年新增客户销售${revenue_weight}吨,共${revenue}元。${time2}当日销售黄砂${total_weight}吨,共计${total_price}元,运输${total_cnt}辆次。");
|
||||
SMS_TEMP_MAP.put(TEMP_CODE_SURPLUS_WARN, "截至${time}${customer_name}在${vendor}的预存账户余额为${surplus}元。请及时关注。");
|
||||
SMS_TEMP_MAP.put(TEMP_CODE_REFUND_SUCCESS, "${time}${customer_name}在${vendor}的退款${amount}元,合计余额${surplus}元。");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import com.cowr.common.Const;
|
|||
import com.cowr.common.base.BaseService;
|
||||
import com.cowr.common.enums.OrderStateEnum;
|
||||
import com.cowr.common.enums.UserTypeEnum;
|
||||
import com.cowr.common.utils.DateTimeUtil;
|
||||
import com.cowr.common.view.PageParam;
|
||||
import com.cowr.common.view.Result;
|
||||
import com.cowr.model.Ordercluster;
|
||||
|
|
@ -21,7 +20,10 @@ import com.jfinal.plugin.activerecord.Page;
|
|||
import com.jfinal.plugin.activerecord.Record;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Generated by COWR Fri Apr 17 16:59:39 CST 2020
|
||||
|
|
@ -637,7 +639,7 @@ public class OrderclusterService extends BaseService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取集团订单剩余成量
|
||||
* 获取单个集团订单剩余成量
|
||||
*
|
||||
* @param ordercluster_id
|
||||
* @return
|
||||
|
|
@ -694,4 +696,84 @@ public class OrderclusterService extends BaseService {
|
|||
|
||||
return out == null ? new BigDecimal(0) : out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 按客户查询未完成的配额量
|
||||
*
|
||||
* @param customer_id
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getOverTotalPriceByCustomer(int customer_id) {
|
||||
String sql = "select sum(a.total_price) total_price from ( \n" +
|
||||
" select t.ordercluster_id, sum(t.weight) weight, sum(t.total_price) total_price from order_sale t \n" +
|
||||
" left join ordercluster o on o.id = t.ordercluster_id\n" +
|
||||
" where t.state = ? \n" +
|
||||
" and o.state < ? \n" +
|
||||
" and o.customer_id = ? \n" +
|
||||
" group by t.ordercluster_id \n" +
|
||||
" \n" +
|
||||
" union \n" +
|
||||
" select t.ordercluster_id, sum(t.weight) weight, sum(t.total_price) total_price from order_temp t \n" +
|
||||
" left join ordercluster o on o.id = t.ordercluster_id\n" +
|
||||
" where t.state = ? \n" +
|
||||
" and o.state < ? \n" +
|
||||
" and o.customer_id = ? \n" +
|
||||
" group by t.ordercluster_id \n" +
|
||||
") a \n" +
|
||||
"group by a.ordercluster_id ";
|
||||
|
||||
BigDecimal out = Db.queryBigDecimal(
|
||||
sql,
|
||||
OrderStateEnum.RECEIVED.getStateid(), OrderStateEnum.RECEIVED.getStateid(), customer_id,
|
||||
OrderStateEnum.RECEIVED.getStateid(), OrderStateEnum.RECEIVED.getStateid(), customer_id
|
||||
);
|
||||
|
||||
return out == null ? new BigDecimal(0) : out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户未完成的配额中,未执行完成的总金额
|
||||
*
|
||||
* @param customer_id
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal undoPrice(int customer_id) {
|
||||
String sql = "select(\n" +
|
||||
" select sum(t.`total_weight` * t.`unit_price`) `total_price`\n" +
|
||||
" from `ordercluster` t\n" +
|
||||
" where t.`customer_id`= ?\n" +
|
||||
" and t.state < ? ) - (\n" +
|
||||
" select sum(t.`weight` * t.`unit_price`) total_price\n" +
|
||||
" from order_temp t\n" +
|
||||
" where exists(\n" +
|
||||
" select 1 from `ordercluster` o\n" +
|
||||
" where o.`customer_id`= ?\n" +
|
||||
" and o.id= t.`ordercluster_id`\n" +
|
||||
" and o.`state`< ?" +
|
||||
" )\n" +
|
||||
" and t.`customer_id`= ?\n" +
|
||||
" and t.`state`= ?)";
|
||||
|
||||
BigDecimal out = Db.queryBigDecimal(
|
||||
sql,
|
||||
customer_id,
|
||||
OrderStateEnum.RECEIVED.getStateid(),
|
||||
customer_id,
|
||||
OrderStateEnum.RECEIVED.getStateid(),
|
||||
customer_id,
|
||||
OrderStateEnum.RECEIVED.getStateid()
|
||||
);
|
||||
|
||||
return out == null ? new BigDecimal("0") : out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户未完成订单id
|
||||
*/
|
||||
public List<Record> getUncompletedOrdersFromUsers(Integer customer_id){
|
||||
String sql = "select t.id from ordercluster t join supermarket s on s.id = t.supermarket_id \n " +
|
||||
" where t.customer_id is not null and state<5 and customer_id=?";
|
||||
return Db.find(sql,customer_id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ import com.cowr.common.Const;
|
|||
import com.cowr.common.base.BaseService;
|
||||
import com.cowr.common.view.PageParam;
|
||||
import com.cowr.model.Customer;
|
||||
import com.cowr.model.PrepayCustomer;
|
||||
import com.cowr.model.PrepayDetail;
|
||||
import com.cowr.model.RefundDetail;
|
||||
import com.cowr.ssjygl.prepay.prepaycustomer.PrepayCustomerService;
|
||||
import com.jfinal.kit.StrKit;
|
||||
import com.jfinal.log.Log;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
|
|
@ -92,7 +94,7 @@ public class RefundDetailService extends BaseService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取账户可用余额
|
||||
* 根据账户ID和账户金额,获取账户可用余额
|
||||
* @param customer_id 客户ID
|
||||
* @param surplus 账户余额
|
||||
* @return
|
||||
|
|
@ -106,5 +108,16 @@ public class RefundDetailService extends BaseService {
|
|||
return surplus.subtract(amount);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取账户的可用余额
|
||||
* @param customer_id 客户ID
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getCustomerAccountBalance(Integer customer_id){
|
||||
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer_id);
|
||||
if(prepayCustomer==null){
|
||||
return new BigDecimal("-1");
|
||||
}
|
||||
return getAvailableBalance(customer_id,prepayCustomer.getSurplus());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ 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.hssf.usermodel.HSSFCellStyle;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
|
@ -1837,4 +1838,401 @@ public class OrderStatService {
|
|||
|
||||
return wb;
|
||||
}
|
||||
|
||||
public Workbook trafficStatisticsOfEachSandStationExport(String stm, String etm){
|
||||
List<Record> list=trafficStatisticsOfEachSandStation(stm, etm);
|
||||
Workbook wb = new XSSFWorkbook();
|
||||
|
||||
Sheet sheet = wb.createSheet(stm + " ~ " + etm + "各砂站运输量统计表");
|
||||
|
||||
sheet.setColumnWidth(1,40*256);
|
||||
for(int i=2;i<28;i++){
|
||||
sheet.setColumnWidth(i,15*256);
|
||||
}
|
||||
|
||||
// 表头 start
|
||||
Row row = sheet.createRow(0);
|
||||
sheet.addMergedRegion(new CellRangeAddress(0,1,0,0));
|
||||
sheet.addMergedRegion(new CellRangeAddress(0,1,1,1));
|
||||
sheet.addMergedRegion(new CellRangeAddress(0,1,2,2));
|
||||
sheet.addMergedRegion(new CellRangeAddress(0,1,3,3));
|
||||
int num = 4;
|
||||
for(int i=0;i<12;i++){
|
||||
sheet.addMergedRegion(new CellRangeAddress(0,0,num,num+1));
|
||||
num=num+2;
|
||||
}
|
||||
// 通用单元格格式
|
||||
Font font = wb.createFont();
|
||||
CellStyle cellStyle = wb.createCellStyle();
|
||||
// font.setFontHeight((short) (10 * 20));
|
||||
// font.setFontName("宋体");
|
||||
cellStyle.setBorderBottom(BorderStyle.THIN);
|
||||
cellStyle.setBorderLeft(BorderStyle.THIN);
|
||||
cellStyle.setBorderTop(BorderStyle.THIN);
|
||||
cellStyle.setBorderRight(BorderStyle.THIN);
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
|
||||
cellStyle.setFont(font);
|
||||
|
||||
num = 0;
|
||||
row.createCell(0).setCellValue("序号");
|
||||
row.createCell(1).setCellValue("客户名称");
|
||||
row.createCell(2).setCellValue("总销售量(吨)");
|
||||
row.createCell(3).setCellValue("总销售额(元)");
|
||||
row.createCell(4).setCellValue("竹瓦");
|
||||
row.createCell(6).setCellValue("竹瓦水厂");
|
||||
row.createCell(8).setCellValue("竹瓦合计");
|
||||
row.createCell(10).setCellValue("团陂");
|
||||
row.createCell(12).setCellValue("城隍");
|
||||
row.createCell(14).setCellValue("石畈");
|
||||
row.createCell(16).setCellValue("融嘉");
|
||||
row.createCell(17).setCellValue("水利站");
|
||||
row.createCell(20).setCellValue("融嘉合计");
|
||||
row.createCell(22).setCellValue("盐港");
|
||||
row.createCell(24).setCellValue("永安");
|
||||
row.createCell(26).setCellValue("盐港合计");
|
||||
|
||||
row = sheet.createRow(1);
|
||||
num = 4;
|
||||
for(int i=0;i<12;i++){
|
||||
row.createCell(num++).setCellValue("总销售量(吨)");
|
||||
row.createCell(num++).setCellValue("总销售额(元)");
|
||||
}
|
||||
int datalen = list.size();
|
||||
for (int i = 0; i < datalen; i++) {
|
||||
Record sales = list.get(i);
|
||||
row = sheet.createRow(i + 2);
|
||||
num = 0;
|
||||
row.createCell(num++).setCellValue(i+1);
|
||||
row.createCell(num++).setCellValue(sales.getStr("customer_name"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "weight"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "total_price"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "zw_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "zw_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "zwsc_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "zwsc_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "zwhj_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "zwhj_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "tp_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "tp_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "sc_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "sc_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "sb_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "sb_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "jr_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "jr_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "sl_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "sl_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "jrhj_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "jrhj_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "yg_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "yg_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "ya_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "ya_xse"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "yghj_xsl"));
|
||||
row.createCell(num++).setCellValue(DataUtil.getDefaultByRecord(sales, "yghj_xse"));
|
||||
}
|
||||
|
||||
for (int r = 0; r < datalen + 2; r++) {
|
||||
row = sheet.getRow(r);
|
||||
if (row == null) {
|
||||
row = sheet.createRow(r);
|
||||
}
|
||||
for (int c = 0; c < 28; c++) {
|
||||
Cell cell = row.getCell(c);
|
||||
|
||||
if (cell == null) {
|
||||
cell = row.createCell(c);
|
||||
}
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
}
|
||||
return wb;
|
||||
}
|
||||
|
||||
/**
|
||||
* 各砂站运输量统计表
|
||||
*/
|
||||
public List<Record> trafficStatisticsOfEachSandStation( String stm, String etm){
|
||||
List<Record> dataList = new ArrayList<>();
|
||||
//零散用户统计
|
||||
Record scattered=scatteredUsersAreNotClassified(stm,etm);
|
||||
if(scattered.getBigDecimal("weight").compareTo(new BigDecimal("0"))>0||scattered.getBigDecimal("total_price").compareTo(new BigDecimal("0"))>0){
|
||||
Record scatteredSandStation=scatteredUsersClassificationStatistics(stm,etm);
|
||||
scattered.setColumns(scatteredSandStation);
|
||||
dataList.add(scattered);
|
||||
}
|
||||
//固定用户统计
|
||||
List<Record> recordList = fixedUserUnclassified(stm,etm);
|
||||
if(recordList!=null&&!recordList.isEmpty()){
|
||||
for (Record record : recordList) {
|
||||
if(record.getBigDecimal("weight").compareTo(new BigDecimal("0"))>0||record.getBigDecimal("total_price").compareTo(new BigDecimal("0"))>0){
|
||||
Integer customer_id=record.getInt("customer_id");
|
||||
Record sandStation=fixedUserClassificationStatistics(stm, etm,customer_id);
|
||||
record.setColumns(sandStation);
|
||||
}
|
||||
}
|
||||
}
|
||||
dataList.addAll(recordList);
|
||||
return dataList;
|
||||
}
|
||||
/**
|
||||
* 零散用户
|
||||
*/
|
||||
/**
|
||||
* 固定用户不分类统计:统计各个固定用户在所有砂站的销量和销售额
|
||||
*/
|
||||
public List<Record> fixedUserUnclassified(String stm, String etm){
|
||||
String sql="SELECT\n" +
|
||||
"a.customer_name,\n" +
|
||||
" a.customer_id,\n" +
|
||||
"ifnull(sum( a.weight ),0) weight,\n" +
|
||||
"ifnull(sum( a.total_price ),0) total_price\n" +
|
||||
"FROM\n" +
|
||||
"(\n" +
|
||||
"SELECT\n" +
|
||||
"t.customer_id,\n" +
|
||||
"t.customer_name,\n" +
|
||||
"t.weight,\n" +
|
||||
"t.total_price,\n" +
|
||||
"t.product_id,\n" +
|
||||
"t.product_name \n" +
|
||||
"FROM\n" +
|
||||
"order_sale t \n" +
|
||||
"WHERE\n" +
|
||||
"t.state = 5 \n" +
|
||||
"AND t.create_time >=? \n" +
|
||||
"AND t.create_time <=? \n" +
|
||||
"AND t.isprepaid = 1 UNION\n" +
|
||||
"SELECT\n" +
|
||||
"t.customer_id,\n" +
|
||||
"t.customer_name,\n" +
|
||||
"t.weight,\n" +
|
||||
"t.total_price,\n" +
|
||||
"t.product_id,\n" +
|
||||
"t.product_name \n" +
|
||||
"FROM\n" +
|
||||
"order_temp t \n" +
|
||||
"WHERE\n" +
|
||||
"t.state = 5 \n" +
|
||||
"AND t.create_time >=? \n" +
|
||||
"AND t.create_time <=? \n" +
|
||||
"AND t.isprepaid = 1 \n" +
|
||||
") a\n" +
|
||||
" JOIN customer c ON c.id = a.customer_id \n" +
|
||||
"GROUP BY\n" +
|
||||
"a.customer_id,a.customer_name";
|
||||
List<Record> recordList = Db.find(sql, stm, etm, stm, etm);
|
||||
return recordList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 固定用户分类统计:统计各个固定用户在不同砂站的销量以及销售额
|
||||
* @return
|
||||
*/
|
||||
public Record fixedUserClassificationStatistics(String stm, String etm,Integer customer_id){
|
||||
String sql="SELECT\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 1 THEN g.weight END ), 0.00 ) zw_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 1 THEN g.total_price END ), 0.00 ) zw_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 2 THEN g.weight END ), 0.00 ) tp_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 2 THEN g.total_price END ), 0.00 ) tp_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 3 THEN g.weight END ), 0.00 ) sc_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 3 THEN g.total_price END ), 0.00 ) sc_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 4 THEN g.weight END ), 0.00 ) sb_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 4 THEN g.total_price END ), 0.00 ) sb_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 5 THEN g.weight END ), 0.00 ) jr_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 5 THEN g.total_price END ), 0.00 ) jr_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 6 THEN g.weight END ), 0.00 ) yg_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 6 THEN g.total_price END ), 0.00 ) yg_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 7 THEN g.weight END ), 0.00 ) zwsc_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 7 THEN g.total_price END ), 0.00 ) zwsc_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 8 THEN g.weight END ), 0.00 ) ya_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 8 THEN g.total_price END ), 0.00 ) ya_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 9 THEN g.weight END ), 0.00 ) sl_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 9 THEN g.total_price END ), 0.00 ) sl_xse \n" +
|
||||
"FROM\n" +
|
||||
"(\n" +
|
||||
"SELECT\n" +
|
||||
"m.id,\n" +
|
||||
"n.customer_id,\n" +
|
||||
"IFNULL( n.weight, 0.00 ) weight,\n" +
|
||||
"IFNULL( n.total_price, 0.00 ) total_price \n" +
|
||||
"FROM\n" +
|
||||
"( SELECT id, NAME FROM supermarket ) m\n" +
|
||||
"JOIN (\n" +
|
||||
"SELECT\n" +
|
||||
"a.id,\n" +
|
||||
"sum( a.weight ) weight,\n" +
|
||||
"sum( a.total_price ) total_price,\n" +
|
||||
"a.customer_id \n" +
|
||||
"FROM\n" +
|
||||
"(\n" +
|
||||
"SELECT\n" +
|
||||
"t.supermarket_id AS id,\n" +
|
||||
"t.customer_id,\n" +
|
||||
"t.customer_name,\n" +
|
||||
"t.weight,\n" +
|
||||
"t.total_price,\n" +
|
||||
"t.product_id,\n" +
|
||||
"t.product_name \n" +
|
||||
"FROM\n" +
|
||||
"order_sale t \n" +
|
||||
"WHERE\n" +
|
||||
"t.state = 5 \n" +
|
||||
"AND t.create_time >=? \n" +
|
||||
"AND t.create_time <=? \n" +
|
||||
"AND t.isprepaid = 1 UNION\n" +
|
||||
"SELECT\n" +
|
||||
"t.supermarket_id AS id,\n" +
|
||||
"t.customer_id,\n" +
|
||||
"t.customer_name,\n" +
|
||||
"t.weight,\n" +
|
||||
"t.total_price,\n" +
|
||||
"t.product_id,\n" +
|
||||
"t.product_name \n" +
|
||||
"FROM\n" +
|
||||
"order_temp t \n" +
|
||||
"WHERE\n" +
|
||||
"t.state = 5 \n" +
|
||||
"AND t.create_time >=? \n" +
|
||||
"AND t.create_time <=? \n" +
|
||||
"AND t.isprepaid = 1 \n" +
|
||||
") a\n" +
|
||||
"JOIN customer c ON c.id = a.customer_id \n" +
|
||||
"WHERE\n" +
|
||||
"a.customer_id = ? \n" +
|
||||
"GROUP BY\n" +
|
||||
"a.id \n" +
|
||||
") n ON m.id = n.id \n" +
|
||||
") g \n" +
|
||||
"GROUP BY\n" +
|
||||
"g.customer_id";
|
||||
Record record = Db.findFirst(sql, stm,etm, stm,etm, customer_id);
|
||||
return total(record);
|
||||
}
|
||||
/**
|
||||
* 零散用户不分类统计:统计所有零散用户在所有砂站的销量和销售额
|
||||
*/
|
||||
public Record scatteredUsersAreNotClassified(String stm, String etm){
|
||||
String sql="SELECT '零散用户' customer_name, 0 customer_id,\n" +
|
||||
"ifnull(sum( a.weight ),0) weight,\n" +
|
||||
"ifnull(sum( a.total_price ),0) total_price\n" +
|
||||
"FROM\n" +
|
||||
"(\n" +
|
||||
"SELECT\n" +
|
||||
"t.weight,\n" +
|
||||
"t.total_price,\n" +
|
||||
"t.product_id\n" +
|
||||
"FROM\n" +
|
||||
"order_sale t \n" +
|
||||
"WHERE\n" +
|
||||
"t.state = 5 \n" +
|
||||
"AND t.create_time >=?\n" +
|
||||
"AND t.create_time <=?\n" +
|
||||
"AND t.isprepaid = 0 UNION\n" +
|
||||
"SELECT\n" +
|
||||
"t.weight,\n" +
|
||||
"t.total_price,\n" +
|
||||
"t.product_id\n" +
|
||||
"FROM\n" +
|
||||
"order_temp t \n" +
|
||||
"WHERE\n" +
|
||||
"t.state = 5 \n" +
|
||||
"AND t.create_time >=?\n" +
|
||||
"AND t.create_time <=?\n" +
|
||||
"AND t.isprepaid = 0 \n" +
|
||||
") a";
|
||||
Record record = Db.findFirst(sql, stm, etm, stm, etm);
|
||||
return record;
|
||||
}
|
||||
|
||||
/**
|
||||
* 零散用户分类统计:统计所有零散用户在各个沙场的销量和销售额
|
||||
* @param stm
|
||||
* @param etm
|
||||
* @return
|
||||
*/
|
||||
public Record scatteredUsersClassificationStatistics(String stm, String etm){
|
||||
String sql="select \n" +
|
||||
"ifnull( sum( CASE g.id WHEN 1 THEN IFNULL( g.weight, 0 ) END ), 0 ) zw_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 1 THEN IFNULL( g.total_price, 0 ) END ), 0 ) zw_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 2 THEN IFNULL( g.weight, 0 ) END ), 0 ) tp_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 2 THEN IFNULL( g.total_price, 0 ) END ), 0 ) tp_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 3 THEN IFNULL( g.weight, 0 ) END ), 0 ) sc_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 3 THEN IFNULL( g.total_price, 0 ) END ), 0 ) sc_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 4 THEN IFNULL( g.weight, 0 ) END ), 0 ) sb_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 4 THEN IFNULL( g.total_price, 0 ) END ), 0 ) sb_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 5 THEN IFNULL( g.weight, 0 ) END ), 0 ) jr_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 5 THEN IFNULL( g.total_price, 0 ) END ), 0 ) jr_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 6 THEN IFNULL( g.weight, 0 ) END ), 0 ) yg_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 6 THEN IFNULL( g.total_price, 0 ) END ), 0 ) yg_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 7 THEN IFNULL( g.weight, 0 ) END ), 0 ) zwsc_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 7 THEN IFNULL( g.total_price, 0 ) END ), 0 ) zwsc_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 8 THEN IFNULL( g.weight, 0 ) END ), 0 ) ya_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 8 THEN IFNULL( g.total_price, 0 ) END ), 0 ) ya_xse,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 9 THEN IFNULL( g.weight, 0 ) END ), 0 ) sl_xsl,\n" +
|
||||
"ifnull( sum( CASE g.id WHEN 9 THEN IFNULL( g.total_price, 0 ) END ), 0 ) sl_xse \n" +
|
||||
" from (\n" +
|
||||
"select m.id,n.weight,n.total_price from \n" +
|
||||
"( SELECT id, NAME FROM supermarket ) m join \n" +
|
||||
"(\n" +
|
||||
"SELECT\n" +
|
||||
"t.supermarket_id AS id,\n" +
|
||||
"t.customer_id,\n" +
|
||||
"t.customer_name,\n" +
|
||||
"t.weight,\n" +
|
||||
"t.total_price,\n" +
|
||||
"t.product_id,\n" +
|
||||
"t.product_name \n" +
|
||||
"FROM\n" +
|
||||
"order_sale t \n" +
|
||||
"WHERE\n" +
|
||||
"t.state = 5 \n" +
|
||||
"AND t.create_time >=?\n" +
|
||||
"AND t.create_time <=?\n" +
|
||||
"AND t.isprepaid = 0 UNION\n" +
|
||||
"SELECT\n" +
|
||||
"t.supermarket_id AS id,\n" +
|
||||
"t.customer_id,\n" +
|
||||
"t.customer_name,\n" +
|
||||
"t.weight,\n" +
|
||||
"t.total_price,\n" +
|
||||
"t.product_id,\n" +
|
||||
"t.product_name \n" +
|
||||
"FROM\n" +
|
||||
"order_temp t \n" +
|
||||
"WHERE\n" +
|
||||
"t.state = 5 \n" +
|
||||
"AND t.create_time >=?\n" +
|
||||
"AND t.create_time <=?\n" +
|
||||
"AND t.isprepaid = 0 ) n on m.id=n.id\n" +
|
||||
") g";
|
||||
Record record = Db.findFirst(sql, stm,etm, stm,etm);
|
||||
return total(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合计
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
public Record total(Record record){
|
||||
//竹瓦合计
|
||||
BigDecimal zwhj_xsl=new BigDecimal(record.getStr("zw_xsl")).add(new BigDecimal(record.getStr("zwsc_xsl")));
|
||||
BigDecimal zwhj_xse=new BigDecimal(record.getStr("zw_xse")).add(new BigDecimal(record.getStr("zwsc_xse")));
|
||||
record.set("zwhj_xsl",zwhj_xsl);
|
||||
record.set("zwhj_xse",zwhj_xse);
|
||||
//融嘉合计
|
||||
BigDecimal jrhj_xsl=new BigDecimal(record.getStr("jr_xsl")).add(new BigDecimal(record.getStr("sl_xsl")));
|
||||
BigDecimal jrhj_xse=new BigDecimal(record.getStr("jr_xse")).add(new BigDecimal(record.getStr("sl_xse")));
|
||||
record.set("jrhj_xsl",jrhj_xsl);
|
||||
record.set("jrhj_xse",jrhj_xse);
|
||||
//盐港合计
|
||||
BigDecimal yghj_xsl=new BigDecimal(record.getStr("yg_xsl")).add(new BigDecimal(record.getStr("ya_xsl")));
|
||||
BigDecimal yghj_xse=new BigDecimal(record.getStr("yg_xse")).add(new BigDecimal(record.getStr("ya_xse")));
|
||||
record.set("yghj_xsl",yghj_xsl);
|
||||
record.set("yghj_xse",yghj_xse);
|
||||
return record;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue