Revert "Revert "定时统计客户当前订单状态""

This reverts commit d05e9db96f.
master
YIN 2025-01-13 09:55:01 +08:00
parent d05e9db96f
commit 0efe7b0fc3
7 changed files with 319 additions and 95 deletions

View File

@ -1,6 +1,9 @@
package com.cpxt.web.task;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cpxt.biz.domain.BizCar;
import com.cpxt.biz.domain.BizCarState;
@ -21,6 +24,8 @@ import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Component("getLocationTask")
@ -28,11 +33,19 @@ public class GetLocationTask {
// 域名
private static final String ADDRESS = "http://api.e6yun.com/";
private static final String APP_KEY_JSON = "[{ 'APP_KEY':'FEB9F91D-BCD7-4DC2-97D1-CB599EEAF9D5','SECRET_KEY':'A8211E8F-9E95-4C80-9414-CD5E1F675FEF' }, " +
"{ 'APP_KEY':'ECB3CDEA-ACD1-4E62-840D-717DCFBEAE79','SECRET_KEY':'BE3544F5-C488-41E8-9DA5-0172BF767210' }]";
// 公钥
private static final String APP_KEY = "FEB9F91D-BCD7-4DC2-97D1-CB599EEAF9D5";
// 密钥
private static final String SECRET_KEY = "A8211E8F-9E95-4C80-9414-CD5E1F675FEF";
// 公钥
private static final String APP_KEY2 = "ECB3CDEA-ACD1-4E62-840D-717DCFBEAE79";
// 密钥
private static final String SECRET_KEY2 = "BE3544F5-C488-41E8-9DA5-0172BF767210";
/*添加代码 begin*/
private static GetLocationTask getLocationTask;
@ -54,8 +67,15 @@ public class GetLocationTask {
// 同步车辆定位数据
public void syncLocationData(){
JSONArray array = JSONUtil.parseArray(APP_KEY_JSON);
for (int i = 0; i < array.size(); i++) {
JSONObject apikey = array.getJSONObject(i);
String APPKEY = apikey.getStr("APP_KEY");
String APPSECRET = apikey.getStr("SECRET_KEY");
// 创建 E6SdkApi 以使用SDK API
E6SdkApi e6SdkApi = new E6SdkApi(ADDRESS, APP_KEY, SECRET_KEY);
E6SdkApi e6SdkApi = new E6SdkApi(ADDRESS, APPKEY, APPSECRET);
try {
// 通过 e6SdkApi 来使用API
GetVehicleInfoVO vehicleInfoVO = e6SdkApi.GetVehcileInfo("-1");
@ -64,10 +84,12 @@ public class GetLocationTask {
if (Helper.FInt(vehicleInfoVO.getCode())==1){
List<VehicleInfoResp> list = vehicleInfoVO.getData();
for (VehicleInfoResp info : list) {
String carNo = info.getVehicleNO();
String serialNo = info.getEquipCode();
BizCar dbcar = getLocationTask.carMapper.selectByCarNo(carNo);
BizCar dbcar = getLocationTask.carMapper.selectBySerialNo(serialNo);
if (dbcar!=null){
Long carId = dbcar.getId();
// String carNo = dbcar.getCarNo();
BizCarState newstate = new BizCarState();
newstate.setCarId(dbcar.getId());
@ -134,7 +156,7 @@ public class GetLocationTask {
newstate.setCommIds(info.getCommIds());
// 更新实时定位信息
BizCarState carState = getLocationTask.stateMapper.selectByCarNo(carNo);
BizCarState carState = getLocationTask.stateMapper.selectBizCarStateByCarId(carId);
if (carState!=null){
newstate.setId(carState.getId());
getLocationTask.stateMapper.updateById(newstate);
@ -159,6 +181,8 @@ public class GetLocationTask {
// 异常捕获
e.printStackTrace();
}
}
}
}

View File

@ -7,11 +7,13 @@ import com.cpxt.biz.domain.BizCustomerWarehouse;
import com.cpxt.biz.domain.BizOrder;
import com.cpxt.biz.domain.BizOrderTask;
import com.cpxt.biz.mapper.*;
import com.cpxt.common.utils.DateUtils;
import com.cpxt.common.utils.Helper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@ -57,6 +59,15 @@ public class OrderTask {
for (Long shopId : shopIds ) {
BizOrder order = new BizOrder();
order.setOrderSn(getNewOrderSn());
if (task.getOrderDateMode()==2){
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date tomorrow = calendar.getTime();
order.setOrderDate(tomorrow);
}else{
order.setOrderDate(new Date());
}
order.setCustomerId(task.getCustomerId());
order.setCustomerName(task.getCustomerName());

View File

@ -46,6 +46,21 @@ public class StatTask {
private StatCarMapper statCarMapper;
@Autowired
private StatDriverMapper statDriverMapper;
@Autowired
private BizOrderMapper orderMapper;
@Autowired
private BizCustomerMapper customerMapper;
@Autowired
private BizCustomerRouteMapper routeMapper;
@Autowired
private BizCustomerShopMapper shopMapper;
@Autowired
private BizCustomerStateMapper customerStateMapper;
@Autowired
private BizCustomerRouteStateMapper routeStateMapper;
@Autowired
private BizCustomerShopStateMapper shopStateMapper;
@PostConstruct
public void init(){
@ -56,6 +71,132 @@ public class StatTask {
statTask.driverMapper = this.driverMapper;
statTask.stateMapper = this.stateMapper;
statTask.trackMapper = this.trackMapper;
statTask.orderMapper = this.orderMapper;
statTask.customerMapper = this.customerMapper;
statTask.routeMapper = this.routeMapper;
statTask.shopMapper = this.shopMapper;
statTask.customerStateMapper = this.customerStateMapper;
statTask.routeStateMapper = this.routeStateMapper;
statTask.shopStateMapper = this.shopStateMapper;
}
public void statCustomerData(){
Date now = new Date();
// 统计各路线平均配送时间
List<Map> route_avgtime_list = statTask.routeStateMapper.selectAvgTimes();
for (Map item : route_avgtime_list) {
int routeId = Helper.FInt(item.get("route_id"));
int avgtimes = Helper.FInt(item.get("avgtimes"));
if (routeId>0) {
BizCustomerRouteState routeState = statTask.routeStateMapper.selectOneByRouteId(routeId);
if (routeState==null || routeState.getId()==0)
routeState = new BizCustomerRouteState();
routeState.setRouteId(routeId);
routeState.setAvgTimes(avgtimes);
if (Helper.FInt(routeState.getId())>0)
statTask.routeStateMapper.updateById(routeState);
else
statTask.routeStateMapper.insert(routeState);
}
}
// 统计各路线今日订单数据
List<Map> route_order_count_list = statTask.routeStateMapper.selectOrderCount();
for (Map item : route_order_count_list) {
int routeId = Helper.FInt(item.get("route_id"));
int order_count = Helper.FInt(item.get("order_count"));
int finish_count = Helper.FInt(item.get("finish_count"));
if (routeId>0) {
BizCustomerRouteState routeState = statTask.routeStateMapper.selectOneByRouteId(routeId);
if (routeState==null || routeState.getId()==0)
routeState = new BizCustomerRouteState();
routeState.setRouteId(routeId);
routeState.setTodayOrders(order_count);
routeState.setFinishOrders(finish_count);
if (Helper.FInt(routeState.getId())>0)
statTask.routeStateMapper.updateById(routeState);
else
statTask.routeStateMapper.insert(routeState);
}
}
// 统计各路线当前订单数据
List<Map> route_order_list = statTask.routeStateMapper.selectCurrentOrder();
for (Map item : route_order_list) {
int routeId = Helper.FInt(item.get("route_id"));
String orderSn = Helper.NStr(item.get("order_sn"));
int carId = Helper.FInt(item.get("car_id"));
int driverId = Helper.FInt(item.get("driver_id"));
int copilotId = Helper.FInt(item.get("copilot_id"));
if (routeId>0) {
BizCustomerRouteState routeState = statTask.routeStateMapper.selectOneByRouteId(routeId);
if (routeState==null || routeState.getId()==0)
routeState = new BizCustomerRouteState();
routeState.setRouteId(routeId);
routeState.setCurrentOrder(orderSn);
routeState.setCurrentCarId(carId);
routeState.setCurrentDriverId(driverId);
routeState.setCurrentCopilotId(copilotId);
if (Helper.FInt(routeState.getId())>0)
statTask.routeStateMapper.updateById(routeState);
else
statTask.routeStateMapper.insert(routeState);
}
}
// 统计各门店平均配送时间
List<Map> shop_avgtime_list = statTask.shopStateMapper.selectAvgTimes();
for (Map item : shop_avgtime_list) {
int shopId = Helper.FInt(item.get("shop_id"));
int avgtimes = Helper.FInt(item.get("avgtimes"));
if (shopId>0) {
BizCustomerShopState state = statTask.shopStateMapper.selectOneByShopId(shopId);
if (state==null || state.getId()==0)
state = new BizCustomerShopState();
state.setShopId(shopId);
state.setAvgTimes(avgtimes);
if (Helper.FInt(state.getId())>0)
statTask.shopStateMapper.updateById(state);
else
statTask.shopStateMapper.insert(state);
}
}
// 统计各门店平均配送时间
List<Map> shop_order_list = statTask.shopStateMapper.selectCurrentOrder();
for (Map item : shop_order_list) {
int shopId = Helper.FInt(item.get("shop_id"));
int avgtimes = Helper.FInt(item.get("avgtimes"));
if (shopId>0) {
BizCustomerShopState state = statTask.shopStateMapper.selectOneByShopId(shopId);
if (state==null || state.getId()==0)
state = new BizCustomerShopState();
state.setShopId(shopId);
state.setIsFinish(Helper.FInt(item.get("order_status"))==3?1:0);
state.setCurrentOrder(Helper.NStr(item.get("order_sn")));
state.setCurrentCarId(Helper.FInt(item.get("car_id")));
state.setCurrentDriverId(Helper.FInt(item.get("driver_id")));
state.setCurrentCopilotId(Helper.FInt(item.get("copilot_id")));
if (Helper.FInt(state.getId())>0)
statTask.shopStateMapper.updateById(state);
else
statTask.shopStateMapper.insert(state);
}
}
}
// 定时统计车辆使用情况

View File

@ -291,6 +291,11 @@ public class BizOrder
/** 备注 */
private String remark;
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "所属日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date orderDate;
// 下单开始时间
@TableField(exist = false)
private String beginTime;

View File

@ -29,6 +29,9 @@ public interface BizCarMapper extends BaseMapper<BizCar>
@Select("select * from biz_car where car_no = #{carNo}")
BizCar selectByCarNo(String carNo);
@Select("select * from biz_car where serial_no = #{serialNo}")
BizCar selectBySerialNo(String serialNo);
@Select("select * from ${tableName} where gps_time >= #{startTime} and gps_time <= #{endTime}")
List<Map> selectBizTrackList(@Param("tableName") String tableName,@Param("startTime") String startTime,@Param("endTime") String endTime);

View File

@ -3,6 +3,10 @@ package com.cpxt.biz.mapper;
import com.cpxt.biz.domain.BizCustomerRouteState;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
/**
* @author LuoJian
@ -13,6 +17,22 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BizCustomerRouteStateMapper extends BaseMapper<BizCustomerRouteState> {
@Select("select * from biz_customer_route_state where route_id = #{routeId}")
BizCustomerRouteState selectOneByRouteId(int routeId);
@Select("select route_id, ROUND(AVG(TIME_TO_SEC(TIMEDIFF(arrive_time, start_time ))),0) AS avgtimes from biz_order " +
" where order_status = 3 and start_time is not null and arrive_time is not null group by route_id")
List<Map> selectAvgTimes();
@Select("select route_id, count(id) order_count, sum(case when order_status = 3 then 1 else 0 end) finish_count " +
" from biz_order where order_date = curdate() group by route_id ")
List<Map> selectOrderCount();
@Select("select * from (select distinct order_sn,order_status, route_id,car_id, driver_id, copilot_id " +
" from biz_order where order_date = curdate() and (order_status = '1' or order_status = '2') " +
" order by create_time asc ) as t group by t.route_id ")
List<Map> selectCurrentOrder();
}

View File

@ -1,8 +1,13 @@
package com.cpxt.biz.mapper;
import com.cpxt.biz.domain.BizCustomerRouteState;
import com.cpxt.biz.domain.BizCustomerShopState;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
/**
* @author LuoJian
@ -13,6 +18,21 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BizCustomerShopStateMapper extends BaseMapper<BizCustomerShopState> {
@Select("select * from biz_customer_shop_state where shop_id = #{routeId}")
BizCustomerShopState selectOneByShopId(int shopId);
@Select("select shop_id, ROUND(AVG(TIME_TO_SEC(TIMEDIFF(arrive_time, start_time ))),0) AS avgtimes from biz_order " +
" where order_status = 3 and start_time is not null and arrive_time is not null group by shop_id")
List<Map> selectAvgTimes();
@Select("select shop_id, count(id) order_count, sum(case when order_status = 3 then 1 else 0 end) finish_count " +
" from biz_order where order_date = curdate() group by shop_id ")
List<Map> selectOrderCount();
@Select("select * from (select distinct order_sn,order_status, shop_id, car_id, driver_id, copilot_id " +
" from biz_order where order_date = curdate() and (order_status = '1' or order_status = '2') " +
" order by create_time asc ) as t group by t.shop_id ")
List<Map> selectCurrentOrder();
}