2020-09-18 17:10:33 +08:00
package com.cowr.ssjygl.overall ;
2020-11-04 14:22:06 +08:00
import com.cowr.common.Const ;
2020-09-18 17:10:33 +08:00
import com.cowr.common.enums.OrderStateEnum ;
import com.cowr.common.utils.DateTimeUtil ;
2020-11-05 10:45:53 +08:00
import com.cowr.model.Supermarket ;
2020-09-18 17:10:33 +08:00
import com.jfinal.plugin.activerecord.Db ;
import com.jfinal.plugin.activerecord.Record ;
2020-11-02 10:02:58 +08:00
import java.math.BigDecimal ;
2024-07-29 11:38:17 +08:00
import java.time.LocalDate ;
2020-11-05 10:45:53 +08:00
import java.util.* ;
2020-09-18 17:10:33 +08:00
public class OverallService {
2021-09-24 00:28:20 +08:00
public static OverallService me = new OverallService ( ) ;
2020-09-18 17:10:33 +08:00
2020-09-18 17:42:20 +08:00
/ *
/ overall / stat ? token =
{
"code" : 200 ,
"data" : {
"ordercluster" : {
"before_month_total_weight" : 446.00 , // 前月配额重量
"before_day_total_weight" : 693.00 , // 前日配额重量
"month_total_weight" : 7930.00 , // 当月配额重量
"day_total_weight" : 160.00 , // 当日配额重量
2020-09-24 19:57:38 +08:00
"total_weight" : 8376.00 , // 总配额重量
"month_truck_cnt" : 49 , // 当月分配车次
"day_truck_cnt" : 0 , // 当日分配车次
"truck_cnt" : 53 , // 总分配车次
"before_month_truck_cnt" : 4 , // 前月分配车次
"before_daytruck__cnt" : 0 // 前日分配撤职
2020-09-18 17:42:20 +08:00
] ,
"by_supermarket" : [
{
"supermarket_id" : 1 ,
"supermarket_name" : "竹瓦" ,
"supermarket_name2" : "竹瓦" ,
2020-10-11 22:50:32 +08:00
"total_price" : 43826.40 , // 砂站总销售额
"weight" : 486.96 , // 砂站总销售重量
"truck_cnt" : 18 , // 砂站总运输车次
"month_total_price" : 43826.40 , // 当月砂站总销售额
"month_weight" : 486.96 , // 当月砂站销售重量
"month_truck_cnt" : 18 , // 当月砂站运输车次
"day_total_price" : 0.00 , // 当日砂站销售总额
"day_weight" : 0.00 , // 当日砂站销售重量
"day_truck_cnt" : 0 // 当日砂站运输车次
"before_month_total_price" : 0.00 , // 前月砂站总销售额
"before_month_weight" : 0.00 , // 前月砂站总销售重量
"before_month_truck_cnt" : 0 , // 前月砂站运输车次
"before_day_total_price" : 1796.40 , // 前日砂站销售总额
"before_day_weight" : 19.96 , // 前日砂站销售重量
"before_day_truck_cnt" : 2 , // 前日砂站运输车次
"day_quota_total_price" : 253.00 , // 当日砂站配额重量
2020-09-18 17:42:20 +08:00
} ,
] ,
"by_customer" : [
{
"total_price" : 41310.00 ,
"month_total_price" : 41310.00 ,
"before_day_truck_cnt" : 0 ,
"month_truck_cnt" : 14 ,
"truck_cnt" : 14 ,
"day_total_price" : 0.00 ,
"weight" : 459.00 ,
"before_day_total_price" : 0.00 ,
"month_weight" : 459.00 ,
"before_month_total_price" : 0.00 ,
"before_month_weight" : 0.00 ,
"day_weight" : 0.00 ,
"before_month_truck_cnt" : 0 ,
"customer_name" : "零散客户" ,
"before_day_weight" : 0.00 ,
"day_truck_cnt" : 0
} ,
{
"total_price" : 3330.00 ,
"month_total_price" : 3330.00 ,
"before_day_truck_cnt" : 0 ,
"month_truck_cnt" : 1 ,
"truck_cnt" : 1 ,
"day_total_price" : 0.00 ,
"weight" : 37.00 ,
"before_day_total_price" : 0.00 ,
"month_weight" : 37.00 ,
"before_month_total_price" : 0.00 ,
"before_month_weight" : 0.00 ,
"day_weight" : 0.00 ,
"before_month_truck_cnt" : 0 ,
"customer_name" : "中铁十六局集团有限公司黄黄高铁项目部(一标)" ,
"customer_id" : 8 ,
"before_day_weight" : 0.00 ,
"day_truck_cnt" : 0
} ,
{
"total_price" : 3690.00 ,
"month_total_price" : 3690.00 ,
"before_day_truck_cnt" : 0 ,
"month_truck_cnt" : 3 ,
"truck_cnt" : 3 ,
"day_total_price" : 0.00 ,
"weight" : 41.00 ,
"before_day_total_price" : 0.00 ,
"month_weight" : 41.00 ,
"before_month_total_price" : 0.00 ,
"before_month_weight" : 0.00 ,
"day_weight" : 0.00 ,
"before_month_truck_cnt" : 0 ,
"customer_name" : "湖北碁润商砼有限公司" ,
"customer_id" : 12 ,
"before_day_weight" : 0.00 ,
"day_truck_cnt" : 0
}
]
}
}
2020-09-24 19:57:38 +08:00
select count ( t . sn ) cnt , sum ( t . weight ) weight , sum ( t . total_price ) total_price , date_format ( t . create_time , ' % Y - % m - % d ' ) date from order_temp t
where t . state = 5
group by date
2024-07-29 11:38:17 +08:00
首 页 数 据 统 计
2020-09-18 17:42:20 +08:00
* /
2023-12-04 16:51:03 +08:00
public Record stat ( Integer supermarket_id ) {
2021-07-28 15:05:49 +08:00
Record out = new Record ( ) ;
Date now = new Date ( ) ;
Calendar c = Calendar . getInstance ( ) ;
2020-09-18 17:10:33 +08:00
c . setTime ( now ) ;
2021-07-28 15:05:49 +08:00
c . set ( Calendar . HOUR_OF_DAY , 0 ) ;
c . set ( Calendar . MINUTE , 0 ) ;
c . set ( Calendar . SECOND , 0 ) ;
c . set ( Calendar . MILLISECOND , 0 ) ;
Date day = c . getTime ( ) ; // 当日
2020-09-18 17:10:33 +08:00
2021-09-17 09:40:03 +08:00
c . set ( Calendar . DAY_OF_MONTH , 1 ) ;
2021-07-28 15:05:49 +08:00
Date month = c . getTime ( ) ; // 当月
2021-09-24 10:44:40 +08:00
c . set ( Calendar . MONTH , 0 ) ;
2021-07-28 15:05:49 +08:00
Date year = c . getTime ( ) ; // 当年
2024-07-29 11:38:17 +08:00
int year_total_price = 0 ;
if ( 2024 = = LocalDate . now ( ) . getYear ( ) ) {
// 久联认款1000万中出站销售金额
year_total_price = 1000 * 10000 ;
}
2025-02-27 13:16:45 +08:00
c . setTime ( now ) ;
c . add ( Calendar . DAY_OF_MONTH , - 1 ) ;
String nowmonttm = DateTimeUtil . sd . get ( ) . format ( now ) ; // 当月
String nowdaytm = DateTimeUtil . sdf . get ( ) . format ( now ) ; // 当日
String predaytm = DateTimeUtil . sdf . get ( ) . format ( c . getTime ( ) ) ; // 前一日
c . add ( Calendar . DAY_OF_MONTH , 1 ) ;
c . add ( Calendar . MONTH , - 1 ) ;
String premonthtm = DateTimeUtil . sd . get ( ) . format ( c . getTime ( ) ) ; // 前一月
// 参数
List < Object > params2 = new ArrayList < > ( ) ;
String sql_by_customer = "\n" +
" select\n" +
" t.customer_id,\n" +
" ifnull(max(case when t.customer_id is null then null else t.customer_name end), '零散客户') customer_name,\n" +
" sum(t.weight) weight,\n" +
" sum(t.total_price) total_price,\n" +
" count(*) truck_cnt,\n" +
" \n" +
" ifnull(sum(case when t.create_time like '" + nowmonttm + "%' then t.weight end), 0) month_weight,\n" +
" ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.weight end), 0) day_weight,\n" +
" \n" +
" ifnull(sum(case when t.create_time like '" + nowmonttm + "%' then t.total_price end), 0) month_total_price,\n" +
" ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.total_price end), 0) day_total_price,\n" +
" \n" +
" count(case when t.create_time like '" + nowmonttm + "%' then t.sn end) month_truck_cnt,\n" +
" count(case when t.create_time like '" + nowdaytm + "%' then t.sn end) day_truck_cnt,\n" +
" \n" +
" ifnull(sum(case when t.create_time like '" + premonthtm + "%' then t.weight end), 0) before_month_weight,\n" +
" ifnull(sum(case when t.create_time like '" + predaytm + "%' then t.weight end), 0) before_day_weight,\n" +
" \n" +
" ifnull(sum(case when t.create_time like '" + premonthtm + "%' then t.total_price end), 0) before_month_total_price,\n" +
" ifnull(sum(case when t.create_time like '" + predaytm + "%' then t.total_price end), 0) before_day_total_price,\n" +
" \n" +
" count(case when t.create_time like '" + premonthtm + "%' then t.sn end) before_month_truck_cnt,\n" +
" count(case when t.create_time like '" + predaytm + "%' then t.sn end) before_day_truck_cnt\n" +
" from order_temp t\n" +
" where t.state = ?\n" ;
String sql_by_supermarket = " select \n" +
" s.id supermarket_id,\n" +
" s.name supermarket_name,\n" +
" ifnull(s.name2,s.name) supermarket_name2,\n" +
" ifnull(a.total_price, 0) total_price,\n" +
" ifnull(a.month_total_price, 0) month_total_price,\n" +
" ifnull(a.before_day_truck_cnt, 0) before_day_truck_cnt,\n" +
" ifnull(a.month_truck_cnt, 0) month_truck_cnt,\n" +
" ifnull(a.truck_cnt, 0) truck_cnt,\n" +
" ifnull(a.day_total_price, 0) day_total_price,\n" +
" ifnull(a.weight, 0) weight,\n" +
" ifnull(a.before_day_total_price, 0) before_day_total_price,\n" +
" ifnull(a.month_weight, 0) month_weight,\n" +
" ifnull(a.before_month_total_price, 0) before_month_total_price,\n" +
" ifnull(a.before_month_weight, 0) before_month_weight,\n" +
" ifnull(a.day_weight, 0) day_weight,\n" +
" ifnull(a.before_month_truck_cnt, 0) before_month_truck_cnt,\n" +
" ifnull(a.before_day_weight, 0) before_day_weight,\n" +
" ifnull(a.day_truck_cnt, 0) day_truck_cnt" +
" from supermarket s\n" +
" left join (\n" +
" select\n" +
" t.supermarket_id,\n" +
" sum(t.weight) weight,\n" +
" sum(t.total_price) total_price,\n" +
" count(*) truck_cnt,\n" +
" \n" +
" ifnull(sum(case when t.create_time like '" + nowmonttm + "%' then t.weight end), 0) month_weight,\n" +
" ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.weight end), 0) day_weight,\n" +
" \n" +
" ifnull(sum(case when t.create_time like '" + nowmonttm + "%' then t.total_price end), 0) month_total_price,\n" +
" ifnull(sum(case when t.create_time like '" + nowdaytm + "%' then t.total_price end), 0) day_total_price,\n" +
" \n" +
" count(case when t.create_time like '" + nowmonttm + "%' then t.sn end) month_truck_cnt,\n" +
" count(case when t.create_time like '" + nowdaytm + "%' then t.sn end) day_truck_cnt,\n" +
" \n" +
" ifnull(sum(case when t.create_time like '" + premonthtm + "%' then t.weight end), 0) before_month_weight,\n" +
" ifnull(sum(case when t.create_time like '" + predaytm + "%' then t.weight end), 0) before_day_weight,\n" +
" \n" +
" ifnull(sum(case when t.create_time like '" + premonthtm + "%' then t.total_price end), 0) before_month_total_price,\n" +
" ifnull(sum(case when t.create_time like '" + predaytm + "%' then t.total_price end), 0) before_day_total_price,\n" +
" \n" +
" count(case when t.create_time like '" + premonthtm + "%' then t.sn end) before_month_truck_cnt,\n" +
" count(case when t.create_time like '" + predaytm + "%' then t.sn end) before_day_truck_cnt\n" +
" from order_temp t\n" +
" where t.state = ?\n" ;
2022-02-15 10:55:06 +08:00
String sql_ordercluster = "select \n" +
" ifnull(sum(g.total_weight), 0) total_weight,\n" +
" ifnull(sum(g.total_price), 0) total_price,\n" +
" ifnull(sum(g.truck_cnt), 0) truck_cnt,\n" +
2022-01-24 11:37:54 +08:00
" ifnull(sum(g.year_total_weight), 0) year_total_weight,\n" +
2024-07-29 11:38:17 +08:00
" ifnull(sum(g.year_total_price), 0) + " + year_total_price + " year_total_price,\n" +
2022-01-24 11:37:54 +08:00
" ifnull(sum(g.year_truck_cnt), 0) year_truck_cnt,\n" +
" ifnull(sum(g.month_total_weight), 0) month_total_weight,\n" +
" ifnull(sum(g.month_total_price), 0) month_total_price,\n" +
2022-02-15 10:55:06 +08:00
" ifnull(sum(g.month_truck_cnt), 0) month_truck_cnt,\n" +
" ifnull(sum(g.day_total_weight), 0) day_total_weight,\n" +
" ifnull(sum(g.day_total_price), 0) day_total_price,\n" +
" ifnull(sum(g.day_truck_cnt), 0) day_truck_cnt\n" +
2022-01-24 11:37:54 +08:00
" from \n" +
" (\n" +
" select \n" +
2022-02-15 10:55:06 +08:00
" ifnull(sum(t.weight), 0) total_weight,\n" +
2024-08-20 15:27:52 +08:00
" ifnull( sum( CASE WHEN t.sale_type = 0 THEN t.total_price END ), 0 ) total_price,\n" +
2023-12-08 17:18:53 +08:00
" ifnull(sum(t.count), 0) truck_cnt,\n" +
2024-01-11 10:07:58 +08:00
" ifnull(sum(case when t.date >= ? then t.weight end ), 0) year_total_weight,\n" +
2024-07-29 11:38:17 +08:00
" ifnull(sum(case when t.date >= ? and t.sale_type = 0 then t.total_price end ), 0) year_total_price,\n" +
2024-01-11 09:46:14 +08:00
" ifnull(sum(case when t.date >= ? then t.count else 0 end ), 0) year_truck_cnt,\n" +
2023-12-04 16:51:03 +08:00
" ifnull(sum(case when t.date >= ? then t.weight end ), 0) month_total_weight,\n" +
2024-07-29 11:38:17 +08:00
" ifnull(sum(case when t.date >= ? and t.sale_type = 0 then t.total_price end ), 0) month_total_price,\n" +
2023-12-04 16:51:03 +08:00
" ifnull(sum(case when t.date >= ? then t.count else 0 end ), 0) month_truck_cnt,\n" +
" ifnull(sum(case when t.date >= ? then t.weight end ), 0) day_total_weight,\n" +
2024-07-29 11:38:17 +08:00
" ifnull(sum(case when t.date >= ? and t.sale_type = 0 then t.total_price end ), 0) day_total_price,\n" +
2023-12-04 16:51:03 +08:00
" ifnull(sum(case when t.date >= ? then t.count else 0 end ), 0) day_truck_cnt\n" +
" from order_end t\n" +
2025-03-14 16:51:02 +08:00
" where t.sale_type != 2\n" +
2023-12-04 16:51:03 +08:00
" UNION\n" +
2022-01-24 11:37:54 +08:00
" select \n" +
2022-02-15 10:55:06 +08:00
" 0 total_weight,\n" +
" ifnull(sum(p.presell_amount), 0) total_price,\n" +
" 0 truck_cnt,\n" +
2022-01-24 11:37:54 +08:00
" 0 year_total_weight,\n" +
2024-01-22 09:21:58 +08:00
" 0 year_total_price,\n" +
2022-01-24 11:37:54 +08:00
" 0 year_truck_cnt,\n" +
" 0 month_total_weight,\n" +
2024-01-22 09:21:58 +08:00
" 0 month_total_price,\n" +
2022-02-15 10:55:06 +08:00
" 0 month_truck_cnt,\n" +
" 0 day_total_weight,\n" +
2024-01-22 09:21:58 +08:00
" 0 day_total_price,\n" +
2022-02-15 10:55:06 +08:00
" 0 day_truck_cnt\n" +
2022-01-24 11:37:54 +08:00
" from presell_order p\n" +
" where p.del = 0\n" +
" ) g" ;
2025-02-27 13:16:45 +08:00
List < Record > by_supermarket_list ;
if ( supermarket_id ! = null ) {
sql_ordercluster + = " and t.supermarket_id = ? " ;
sql_by_customer + = " and t.supermarket_id = ? " ;
params2 . add ( supermarket_id ) ;
by_supermarket_list = Db . find ( sql_by_supermarket +
" and t.supermarket_id = ? " +
" group by t.supermarket_id\n" +
" ) a on a.supermarket_id = s.id \n" +
" where s.id = ? " +
2025-03-14 15:54:10 +08:00
"AND s.type = 0" +
2025-02-27 13:16:45 +08:00
"" , OrderStateEnum . RECEIVED . getStateid ( ) , supermarket_id , supermarket_id ) ;
} else {
by_supermarket_list = Db . find ( sql_by_supermarket +
" group by t.supermarket_id\n" +
" ) a on a.supermarket_id = s.id" +
2025-03-14 15:54:10 +08:00
" where s.type = 0" +
2025-02-27 13:16:45 +08:00
"" , OrderStateEnum . RECEIVED . getStateid ( ) ) ;
}
// out.set("by_customer", Db.find(sql_by_customer + " group by t.customer_id", params2.toArray()));
out . set ( "by_supermarket" , by_supermarket_list ) ;
Record ocout = Db . findFirst ( sql_ordercluster , year , year , year , month , month , month , day , day , day ) ;
2022-02-15 10:55:06 +08:00
out . set ( "ordercluster" , ocout ) ;
2020-09-18 17:10:33 +08:00
return out ;
}
2020-10-11 22:50:32 +08:00
/ * *
* 近 31 日 总 销 售 列 表
2020-10-18 00:39:17 +08:00
*
2020-10-11 22:50:32 +08:00
* @return
* /
2020-11-06 11:02:09 +08:00
public Collection < Record > lastStat ( ) {
2020-10-11 22:50:32 +08:00
Date now = new Date ( ) ;
Calendar c = Calendar . getInstance ( ) ;
c . setTime ( now ) ;
c . add ( Calendar . DAY_OF_MONTH , - 31 ) ;
c . set ( Calendar . HOUR_OF_DAY , 0 ) ;
c . set ( Calendar . MINUTE , 0 ) ;
c . set ( Calendar . SECOND , 0 ) ;
c . set ( Calendar . MILLISECOND , 0 ) ;
2020-11-06 11:02:09 +08:00
String tm = DateTimeUtil . sdfhms . get ( ) . format ( c . getTime ( ) ) ;
Map < String , Record > map = new HashMap < > ( ) ;
2020-10-11 22:50:32 +08:00
2020-11-06 11:02:09 +08:00
for ( int i = 0 ; i < 31 ; i + + ) {
c . add ( Calendar . DAY_OF_MONTH , 1 ) ;
String t = DateTimeUtil . sdf . get ( ) . format ( c . getTime ( ) ) ;
map . put ( t ,
new Record ( )
. set ( "date" , t )
. set ( "cnt" , 0 )
. set ( "weight" , 0 )
. set ( "total_price" , 0 )
) ;
}
List < Record > list = Db . find ( "\n" +
"select count(t.sn) cnt, sum(t.weight) weight, sum(t.total_price) total_price, date_format(t.create_time, '%Y-%m-%d') date \n" +
" from order_temp t\n" +
" where t.state = ?\n" +
" and t.create_time > ?\n" +
2025-03-14 16:51:02 +08:00
" and t.sale_type != 2 \n" +
2020-11-06 11:02:09 +08:00
" group by date" ,
2020-10-11 22:50:32 +08:00
OrderStateEnum . RECEIVED . getStateid ( ) ,
2020-11-06 11:02:09 +08:00
tm ) ;
for ( Record record : list ) {
String t = record . get ( "date" ) ;
map . put ( t , record ) ;
}
List < Record > outlist = new ArrayList < > ( ) ;
outlist . addAll ( map . values ( ) ) ;
outlist . sort ( new Comparator < Record > ( ) {
@Override
public int compare ( Record o1 , Record o2 ) {
String t1 = o1 . get ( "date" ) ;
String t2 = o2 . get ( "date" ) ;
try {
if ( DateTimeUtil . sdf . get ( ) . parse ( t1 ) . after ( DateTimeUtil . sdf . get ( ) . parse ( t2 ) ) ) {
return 1 ;
} else {
return - 1 ;
}
} catch ( Exception ignored ) {
}
return 0 ;
}
} ) ;
return outlist ;
2020-10-11 22:50:32 +08:00
}
/ * *
* 近 31 日 砂 站 总 销 售 列 表
2020-10-18 00:39:17 +08:00
*
2020-10-11 22:50:32 +08:00
* @return
* /
public List < Record > lastSupermarketStat ( int supermarket_id ) {
Date now = new Date ( ) ;
Calendar c = Calendar . getInstance ( ) ;
c . setTime ( now ) ;
c . add ( Calendar . DAY_OF_MONTH , - 31 ) ;
c . set ( Calendar . HOUR_OF_DAY , 0 ) ;
c . set ( Calendar . MINUTE , 0 ) ;
c . set ( Calendar . SECOND , 0 ) ;
c . set ( Calendar . MILLISECOND , 0 ) ;
return Db . find ( "\n" +
"select count(t.sn) cnt, sum(t.weight) weight, sum(t.total_price) total_price, date_format(t.create_time, '%Y-%m-%d') date from order_temp t\n" +
"where t.state = ?\n" +
"and t.supermarket_id = ?\n" +
"and t.create_time >= ?\n" +
"group by date" ,
OrderStateEnum . RECEIVED . getStateid ( ) ,
supermarket_id ,
DateTimeUtil . sdfhms . get ( ) . format ( c . getTime ( ) ) ) ;
}
/ * *
* 近 31 日 客 户 总 销 售 列 表
2020-10-18 00:39:17 +08:00
*
2020-10-11 22:50:32 +08:00
* @return
* /
public List < Record > lastCustomerStat ( int customer_id ) {
Date now = new Date ( ) ;
Calendar c = Calendar . getInstance ( ) ;
c . setTime ( now ) ;
c . add ( Calendar . DAY_OF_MONTH , - 31 ) ;
c . set ( Calendar . HOUR_OF_DAY , 0 ) ;
c . set ( Calendar . MINUTE , 0 ) ;
c . set ( Calendar . SECOND , 0 ) ;
c . set ( Calendar . MILLISECOND , 0 ) ;
return Db . find ( "\n" +
"select count(t.sn) cnt, sum(t.weight) weight, sum(t.total_price) total_price, date_format(t.create_time, '%Y-%m-%d') date from order_temp t\n" +
"where t.state = ?\n" +
"and t.customer_id = ?\n" +
"and t.create_time >= ?\n" +
"group by date" ,
OrderStateEnum . RECEIVED . getStateid ( ) ,
customer_id ,
DateTimeUtil . sdfhms . get ( ) . format ( c . getTime ( ) ) ) ;
}
/ * *
* 近 31 日 散 户 总 销 售 列 表
2020-10-18 00:39:17 +08:00
*
2020-10-11 22:50:32 +08:00
* @return
* /
public List < Record > lastTempStat ( ) {
Date now = new Date ( ) ;
Calendar c = Calendar . getInstance ( ) ;
c . setTime ( now ) ;
c . add ( Calendar . DAY_OF_MONTH , - 31 ) ;
c . set ( Calendar . HOUR_OF_DAY , 0 ) ;
c . set ( Calendar . MINUTE , 0 ) ;
c . set ( Calendar . SECOND , 0 ) ;
c . set ( Calendar . MILLISECOND , 0 ) ;
return Db . find ( "\n" +
"select count(t.sn) cnt, sum(t.weight) weight, sum(t.total_price) total_price, date_format(t.create_time, '%Y-%m-%d') date from order_temp t\n" +
"where t.state = ?\n" +
"and t.customer_id is null \n" +
"and t.create_time >= ?\n" +
"group by date" ,
OrderStateEnum . RECEIVED . getStateid ( ) ,
DateTimeUtil . sdfhms . get ( ) . format ( c . getTime ( ) ) ) ;
}
2020-11-03 14:27:22 +08:00
2021-07-28 15:05:49 +08:00
/ * *
2025-03-17 14:10:28 +08:00
* 最 后 30 天 销 售 记 录
2021-07-28 15:05:49 +08:00
*
* @param supermarket_id
* @return
* /
2020-11-03 14:27:22 +08:00
public List < Record > lastOrder ( Integer supermarket_id ) {
if ( supermarket_id ! = null ) {
2020-11-04 14:22:06 +08:00
return Db . find ( "select t.sn, t.customer_id, t.customer_name, t.truck_license, t.weight, t.total_price, t.create_time, t.supermarket_id, s.name supermarket_name \n" +
" from order_temp t\n" +
2020-11-03 14:27:22 +08:00
" left join supermarket s on s.id = t.supermarket_id\n" +
2025-03-17 14:10:28 +08:00
" where t.state = 5 and t.sale_type != 2 \n" +
2020-11-03 14:27:22 +08:00
" and t.supermarket_id = ? \n" +
2023-12-04 16:51:03 +08:00
" AND t.CREATE_TIME >= CURDATE() - INTERVAL 30 DAY\n" +
" AND t.CREATE_TIME < CURDATE()" +
2020-11-03 14:27:22 +08:00
" order by t.create_time desc \n" +
" limit 30" , supermarket_id ) ;
} else {
2020-11-04 14:22:06 +08:00
return Db . find ( "select t.sn, t.customer_id, t.customer_name, t.truck_license, t.weight, t.total_price, t.create_time, t.supermarket_id, s.name supermarket_name\n" +
" , s.lgtd origin_lgtd, s.lttd origin_lttd\n" +
" , ifnull(c.lgtd, " + Const . DEFAULT_LGTD + ") dest_lgtd, ifnull(c.lttd, " + Const . DEFAULT_LTTD + ") dest_lttd\n" +
" from order_temp t\n" +
2020-11-03 14:27:22 +08:00
" left join supermarket s on s.id = t.supermarket_id\n" +
2020-11-04 14:22:06 +08:00
" left join (\n" +
" select t.* from customer_receiver t\n" +
" left join (\n" +
" select t.customer_id, min(t.id) id from customer_receiver t group by t.customer_id\n" +
" ) a on a.id = t.id\n" +
" where a.id is not null\n" +
" ) c on c.customer_id = t.customer_id\n" +
2025-03-17 14:10:28 +08:00
" where t.state = 5 and t.sale_type != 2 \n" +
2023-12-04 16:51:03 +08:00
" AND t.CREATE_TIME >= CURDATE() - INTERVAL 30 DAY\n" +
" AND t.CREATE_TIME < CURDATE()" +
2020-11-03 14:27:22 +08:00
" order by t.create_time desc \n" +
" limit 30" ) ;
}
}
2020-11-04 14:22:06 +08:00
2020-11-04 15:34:26 +08:00
/ *
[
{
"day_quota_cnt" : 1 , // 今日有配额的客户数量
"day_weight" : 0.20 , // 今日完成重量
"name" : "固定客户" ,
"cnt" : 25 , // 固定客户总数
"day_total_price" : 18.00 , // 今日完成的销售额
"id" : 1 , // id == 1 是固定客户
"day_quota_weight" : 100.00 , // 今日配额重量
"day_cnt" : 1 // 今日运输车次
} ,
{
"day_quota_cnt" : 2 , // 今日有配额的客户数量
"day_weight" : 0.10 , // 今日完成重量
"name" : "零散客户" ,
"cnt" : 51 , // 零散客户总数
"day_total_price" : 9.00 , // 今日完成的销售额
"id" : 2 , // id == 2 零散客户
"day_quota_weight" : 26.00 , // 今日配额重量
"day_cnt" : 1 // 今日运输车次
}
]
* /
2020-11-04 14:22:06 +08:00
public List < Record > customerQuota ( ) {
Date now = new Date ( ) ;
String nowdaytm = DateTimeUtil . sdf . get ( ) . format ( now ) ; // 当日
List < Record > outlist = new ArrayList < > ( ) ;
2020-11-06 10:14:11 +08:00
Record c1 = new Record ( )
. set ( "id" , 1 )
. set ( "name" , "固定客户" )
. set ( "cnt" , Db . queryInt ( "select count(*) cnt from customer" ) )
. set ( "day_quota_cnt" , 0 )
. set ( "day_quota_weight" , 0 )
. set ( "day_cnt" , 0 )
. set ( "day_weight" , 0 )
. set ( "day_total_price" , 0 ) ;
Record c2 = new Record ( )
. set ( "id" , 2 )
. set ( "name" , "零散客户" )
. set ( "cnt" , Db . queryInt ( "select count(distinct customer_name) cnt from ordercluster where customer_id is null" ) )
. set ( "day_quota_cnt" , 0 )
. set ( "day_quota_weight" , 0 )
. set ( "day_cnt" , 0 )
. set ( "day_weight" , 0 )
. set ( "day_total_price" , 0 ) ;
2020-11-04 14:22:06 +08:00
outlist . add ( c1 ) ;
outlist . add ( c2 ) ;
2020-11-09 21:30:26 +08:00
List < Record > data1 = Db . find ( "select case when t.customer_id is null then 2 else 1 end cid, count(t.id) day_quota_cnt, sum(t.total_weight) day_quota_weight \n" +
" from ordercluster t\n" +
" where t.state <= 5\n" +
2020-11-04 14:22:06 +08:00
" and t.cutoff_time like ?\n" +
" group by cid" , nowdaytm + "%" ) ;
2020-11-09 21:30:26 +08:00
List < Record > data2 = Db . find ( "select case when t.customer_id is null then 2 else 1 end cid, count(t.sn) day_cnt, sum(t.weight) day_weight, sum(total_price) day_total_price \n" +
" from order_temp t\n" +
2020-11-04 14:22:06 +08:00
" where t.state = 5\n" +
2023-09-25 14:55:42 +08:00
// " and t.product_id != 4\n" +
2020-11-04 14:22:06 +08:00
" and t.create_time like ?\n" +
" group by cid" , nowdaytm + "%" ) ;
for ( Record record : data1 ) {
int cid = record . getInt ( "cid" ) ;
if ( cid = = 1 ) {
c1 . set ( "day_quota_cnt" , record . get ( "day_quota_cnt" ) ) ;
c1 . set ( "day_quota_weight" , record . get ( "day_quota_weight" ) ) ;
} else if ( cid = = 2 ) {
c2 . set ( "day_quota_cnt" , record . get ( "day_quota_cnt" ) ) ;
c2 . set ( "day_quota_weight" , record . get ( "day_quota_weight" ) ) ;
}
}
for ( Record record : data2 ) {
int cid = record . getInt ( "cid" ) ;
if ( cid = = 1 ) {
c1 . set ( "day_cnt" , record . get ( "day_cnt" ) ) ;
c1 . set ( "day_weight" , record . get ( "day_weight" ) ) ;
c1 . set ( "day_total_price" , record . get ( "day_total_price" ) ) ;
} else if ( cid = = 2 ) {
c2 . set ( "day_cnt" , record . get ( "day_cnt" ) ) ;
c2 . set ( "day_weight" , record . get ( "day_weight" ) ) ;
c2 . set ( "day_total_price" , record . get ( "day_total_price" ) ) ;
}
}
return outlist ;
}
2020-11-04 15:34:26 +08:00
2020-11-05 10:45:53 +08:00
public List < Record > customerQuotaStat ( ) {
2020-11-04 15:34:26 +08:00
Date now = new Date ( ) ;
String nowdaytm = DateTimeUtil . sdf . get ( ) . format ( now ) ; // 当日
return Db . find ( "select\n" +
" t.* \n" +
" , s.lgtd origin_lgtd, s.lttd origin_lttd\n" +
" , ifnull(c.lgtd, " + Const . DEFAULT_LGTD + ") dest_lgtd, ifnull(c.lttd, " + Const . DEFAULT_LTTD + ") dest_lttd\n" +
2020-11-04 15:44:40 +08:00
" , ifnull(o.cnt, 0) over_cnt\n" +
2020-11-04 15:34:26 +08:00
" , ifnull(o.total_weight, 0) over_weight\n" +
" , ifnull(o.total_price, 0) over_total_price\n" +
" from ordercluster t\n" +
" left join supermarket s on s.id = t.supermarket_id\n" +
" left join (\n" +
" select t.* from customer_receiver t\n" +
" left join (\n" +
" select t.customer_id, min(t.id) id from customer_receiver t group by t.customer_id\n" +
" ) a on a.id = t.id\n" +
" where a.id is not null\n" +
" ) c on c.customer_id = t.customer_id\n" +
" left join (\n" +
2020-11-04 15:44:40 +08:00
" select t.ordercluster_id, count(t.sn) cnt, sum(t.weight) total_weight, sum(t.total_price) total_price from order_temp t\n" +
2020-11-04 15:34:26 +08:00
" where t.state = 5\n" +
" and t.create_time like ?\n" +
" group by t.ordercluster_id\n" +
" ) o on o.ordercluster_id = t.id\n" +
2020-11-09 21:30:26 +08:00
" where t.state <= 5\n" +
2020-11-04 15:34:26 +08:00
" and t.cutoff_time like ? " , nowdaytm + "%" , nowdaytm + "%" ) ;
}
2020-11-05 10:45:53 +08:00
/ * *
* 超 市 环 比
*
* @return
* /
public Record supermarketQoQ ( ) {
Date now = new Date ( ) ;
Calendar c = Calendar . getInstance ( ) ;
c . setTime ( now ) ;
c . add ( Calendar . DAY_OF_YEAR , - 1 ) ;
c . set ( Calendar . HOUR_OF_DAY , 0 ) ;
c . set ( Calendar . MINUTE , 0 ) ;
c . set ( Calendar . SECOND , 0 ) ;
c . set ( Calendar . MILLISECOND , 0 ) ;
String start = DateTimeUtil . sdf . get ( ) . format ( c . getTime ( ) ) ;
c . add ( Calendar . DAY_OF_YEAR , - 8 ) ;
String end = DateTimeUtil . sdf . get ( ) . format ( c . getTime ( ) ) ;
String [ ] ds = new String [ ] { start , end } ;
2025-03-14 15:54:10 +08:00
List < Supermarket > ss = Supermarket . dao . find ( "select * from supermarket where type = 0" ) ;
2025-02-27 13:16:45 +08:00
// List<Supermarket> ss = Supermarket.dao.find("select * from supermarket where del = 0 AND type = 0");
2020-11-05 10:45:53 +08:00
List < Record > list = Db . find ( "select date_format(t.create_time, '%Y-%m-%d') date, count(t.sn) total_cnt, sum(t.weight) total_weight, sum(t.total_price) total_price, t.supermarket_id id\n" +
" from order_temp t\n" +
" where t.create_time like ?\n" +
" or t.create_time like ?\n" +
" group by t.supermarket_id, date" , start + "%" , end + "%" ) ;
Map < String , Record > map = new HashMap < > ( ) ;
for ( Record record : list ) {
String date = record . getStr ( "date" ) ;
String sid = record . getStr ( "id" ) ;
map . put ( date + "_" + sid , record ) ;
}
for ( Supermarket supermarket : ss ) {
for ( String t : ds ) {
String key = t + "_" + supermarket . getId ( ) ;
if ( ! map . containsKey ( key ) ) {
Record newobj = new Record ( )
. set ( "id" , supermarket . getId ( ) )
. set ( "name" , supermarket . getName ( ) )
. set ( "date" , t )
. set ( "total_cnt" , 0 )
. set ( "total_weight" , 0 )
. set ( "total_price" , 0 ) ;
list . add ( newobj ) ;
map . put ( key , newobj ) ;
} else {
map . get ( key ) . set ( "name" , supermarket . getName ( ) ) ;
}
}
}
Record out = new Record ( ) ;
List < Record > slist = new ArrayList < > ( ) ;
for ( Supermarket supermarket : ss ) {
String skey = ds [ 0 ] + "_" + supermarket . getId ( ) ;
String ekey = ds [ 1 ] + "_" + supermarket . getId ( ) ;
Record sval = map . get ( skey ) ;
Record eval = map . get ( ekey ) ;
BigDecimal s_total_cnt = sval . getBigDecimal ( "total_cnt" ) ;
BigDecimal e_total_cnt = eval . getBigDecimal ( "total_cnt" ) ;
BigDecimal s_total_weight = sval . getBigDecimal ( "total_weight" ) ;
BigDecimal e_total_weight = eval . getBigDecimal ( "total_weight" ) ;
BigDecimal s_total_price = sval . getBigDecimal ( "total_price" ) ;
BigDecimal e_total_price = eval . getBigDecimal ( "total_price" ) ;
slist . add (
new Record ( )
. set ( "id" , supermarket . getId ( ) )
. set ( "name" , supermarket . getName ( ) )
. set ( "total_cnt_ratio" , e_total_cnt . doubleValue ( ) = = 0 ? 0 : s_total_cnt . subtract ( e_total_cnt ) . divide ( e_total_cnt , 4 , BigDecimal . ROUND_HALF_UP ) )
. set ( "total_weight_ratio" , e_total_weight . doubleValue ( ) = = 0 ? 0 : s_total_weight . subtract ( e_total_weight ) . divide ( e_total_weight , 4 , BigDecimal . ROUND_HALF_UP ) )
. set ( "total_price_ratio" , e_total_price . doubleValue ( ) = = 0 ? 0 : s_total_price . subtract ( e_total_price ) . divide ( e_total_price , 4 , BigDecimal . ROUND_HALF_UP ) )
) ;
}
out . set ( "list" , slist ) ;
out . set ( "date" , ds ) ;
return out ;
}
2020-09-18 17:10:33 +08:00
}