统计修改

dev
wany 2025-03-14 13:34:39 +08:00
parent ee4c7aa68f
commit 0338161792
3 changed files with 202 additions and 9 deletions

View File

@ -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<Map<String, Object>> listMap = new ArrayList<>();
List<Record> list = statYearBySup(tm, 2);
// List<Record> list = statYearBySup(tm, 2);
List<Record> list = statYearBySup1(tm);
for (Record r : list) {
Map<String, Object> 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<Record> statYearBySup1(String tm) {
// 砂站
List<Record> sups = Db.find("SELECT\n" +
" t.id,\n" +
" t.`name`\n" +
"FROM\n" +
" supermarket t\n"
+ "WHERE\n" +
"t.type = 0 "
);
List<Object> shParamsList = new ArrayList<>();
List<Object> 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<Record> retList = new ArrayList<>();
// 实售
List<Record> shList = Db.find(getSaleSql(shParams,0), shParamsList.toArray());
// 预售
List<Record> yhList = Db.find(getSaleSql(yhParams,1), yhParamsList.toArray());
// 实售总
List<Record> stList = Db.find(getTotalSaleSql(shParams,0), shParamsList.toArray());
// 预售总
List<Record> ytList = Db.find(getTotalSaleSql(yhParams,1), yhParamsList.toArray());
//所有总
List<Record> 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<Record> statYearBySupLocal(String tm, int type) {
// 砂站
List<Record> sups = Db.find("SELECT\n" +

View File

@ -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);
}
}

View File

@ -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));
}
}
/**
*
*/