package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
|
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
|
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
|
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
|
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsSpreadService;
|
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
|
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
|
import com.stylefeng.guns.modular.specialTrain.server.impl.OrderPrivateCarServiceImpl;
|
import com.stylefeng.guns.modular.system.dao.*;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.*;
|
import com.stylefeng.guns.modular.system.util.GoogleMap.DistancematrixVo;
|
import com.stylefeng.guns.modular.system.util.GoogleMap.FleetEngineUtil;
|
import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil;
|
import com.stylefeng.guns.modular.system.util.quartz.QuartzUtil;
|
import com.stylefeng.guns.modular.system.util.quartz.jobs.OrderTimeOutJob;
|
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
|
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
|
import org.apache.shiro.util.StringUtils;
|
import org.quartz.JobDataMap;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Isolation;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
|
@Service
|
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
public class ReassignServiceImpl extends ServiceImpl<ReassignMapper, Reassign> implements IReassignService {
|
|
@Resource
|
private ReassignMapper reassignMapper;
|
|
@Resource
|
private SensitiveWordsMapper sensitiveWordsMapper;
|
|
@Autowired
|
private IOrderService orderService;
|
|
@Autowired
|
private IDriverService driverService;
|
|
@Autowired
|
private ITransactionDetailsService transactionDetailsService;
|
|
@Autowired
|
private IPaymentRecordService paymentRecordService;
|
|
@Autowired
|
private PayMoneyUtil payMoneyUtil;
|
|
/*@Autowired
|
private ICBCPayUtil icbcPayUtil;*/
|
|
@Autowired
|
private IOrderTaxiService orderTaxiService;
|
|
@Autowired
|
private IIncomeService incomeService;
|
|
@Autowired
|
private ISystemNoticeService systemNoticeService;
|
|
@Autowired
|
private IOrderPrivateCarService orderPrivateCarService;
|
|
@Autowired
|
private ICompanyCityService companyCityService;
|
|
@Autowired
|
private IPushOrderService pushOrderService;
|
|
@Autowired
|
private PushUtil pushUtil;
|
|
@Autowired
|
private IOrderCrossCityService orderCrossCityService;
|
|
@Autowired
|
private JGPushUtil jgPushUtil;
|
|
@Resource
|
private DispatchMapper dispatchMapper;
|
|
@Autowired
|
private IOrderLogisticsService orderLogisticsService;
|
|
@Value("${callbackPath}")
|
private String callbackPath;
|
|
@Resource
|
private RedisUtil redisUtil;
|
|
@Resource
|
private ICarService carService;
|
|
@Resource
|
private ISysOvertimeService sysOvertimeService;
|
|
@Resource
|
private ICancleOrderService cancleOrderService;
|
|
@Resource
|
private UserInfoMapper userInfoMapper;
|
|
@Resource
|
private FleetEngineUtil fleetEngineUtil;
|
|
@Resource
|
private CarModelMapper carModelMapper;
|
|
|
|
/**
|
* 提交改派申请
|
* @param uid 申请司机id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil saveData(Reassign reassign, Integer uid, Integer type, Integer language) throws Exception {
|
String content = reassign.getRemark();
|
if(ToolUtil.isNotEmpty(content)){
|
List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
|
for(SensitiveWords s : sensitiveWords){
|
content = content.replaceAll(s.getContent(), "***");
|
}
|
}
|
reassign.setRemark(content);
|
ResultUtil resultUtil = ResultUtil.success();
|
Driver driver = driverService.selectById(uid);
|
Reassign query = reassignMapper.query(uid, null, reassign.getOrderId(), reassign.getOrderType(), 1);
|
if(null != query){
|
reassignMapper.deleteById(query.getId());
|
}
|
query = reassignMapper.query(uid, null, reassign.getOrderId(), reassign.getOrderType(), 2);
|
if(null != query){
|
return ResultUtil.error(language == 1 ? "您提交的申请正在处理中" : language == 2 ? "Your application is being processed." : "Votre demande est en cours de traitement.");
|
}
|
|
//获取支付金额
|
reassign.setOriginalDriverId(uid);
|
reassign.setOriginalCarId(driver.getCarId());
|
reassign.setInsertTime(new Date());
|
reassign.setState(2);
|
this.insert(reassign);
|
|
//修改改派通知状态
|
switch (reassign.getOrderType()){
|
case 1:
|
OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(reassign.getOrderId());
|
orderPrivateCar.setOldState(orderPrivateCar.getState());
|
orderPrivateCar.setState(11);
|
orderPrivateCar.setReassignNotice(2);
|
orderPrivateCarService.updateById(orderPrivateCar);
|
break;
|
case 2:
|
OrderTaxi orderTaxi = orderTaxiService.selectById(reassign.getOrderId());
|
orderTaxi.setOldState(orderTaxi.getState());
|
orderTaxi.setState(11);
|
orderTaxi.setReassignNotice(2);
|
orderTaxiService.updateById(orderTaxi);
|
break;
|
case 4:
|
OrderLogistics orderLogistics = orderLogisticsService.selectById(reassign.getOrderId());
|
orderLogistics.setOldState(orderLogistics.getState());
|
orderLogistics.setState(11);
|
orderLogistics.setReassignNotice(2);
|
orderLogisticsService.updateById(orderLogistics);
|
break;
|
case 5:
|
OrderLogistics orderLogistics1 = orderLogisticsService.selectById(reassign.getOrderId());
|
orderLogistics1.setOldState(orderLogistics1.getState());
|
orderLogistics1.setState(11);
|
orderLogistics1.setReassignNotice(2);
|
orderLogisticsService.updateById(orderLogistics1);
|
break;
|
}
|
systemNoticeService.addSystemNotice(2, language == 1 ? "您的改派申请已成功提交,我们会尽快为你处理!" : language == 2 ?
|
"Your request for reassignment was submitted, we shall handle it for you as soon as possible." :
|
"Votre demande de réaffectation a été soumise. Nous la traiterons pour vous dans les plus brefs délais.", uid);
|
|
//开始自动完成改派
|
switch (reassign.getOrderType()){
|
case 1:
|
OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(reassign.getOrderId());
|
Company company = companyCityService.query1(String.valueOf(orderPrivateCar.getStartLon()), String.valueOf(orderPrivateCar.getStartLat()));//获取起点所属分公司
|
PushOrder pushOrder = pushOrderService.querys(1, 1, company.getId()).get(0);
|
//获取空闲司机
|
List<Driver> list = driverService.queryIdleDriver(1, orderPrivateCar.getServerCarModelId(), orderPrivateCar.getStartLon(), orderPrivateCar.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机
|
System.err.println("【" + orderPrivateCar.getId() + "】空闲司机:" + JSON.toJSONString(list));
|
if(list.size() > 0){
|
String text = "";
|
Driver driver1 = list.get(0);
|
reassign.setState(3);
|
reassign.setNowDriverId(driver1.getId());
|
reassign.setNowCarId(driver1.getCarId());
|
reassign.setCompleteTime(new Date());
|
this.updateById(reassign);
|
|
|
Integer language1 = driver1.getLanguage();
|
switch (language1){
|
case 1:
|
text = "收到新的打车订单,从" + orderPrivateCar.getStartAddress() + "出发,全程约" + orderPrivateCar.getEstimatedMileage() + "公里";
|
break;
|
case 2:
|
text = "Received a new ride order, starting from " + orderPrivateCar.getStartAddress() + ", the whole journey is about " + orderPrivateCar.getEstimatedMileage() + "kilometre";
|
break;
|
case 3:
|
text = "J'ai reçu une nouvelle commande de course, à partir de " + orderPrivateCar.getStartAddress() + ", le trajet complet est d’environ " + orderPrivateCar.getEstimatedMileage() + "kilométrage";
|
break;
|
|
}
|
String audioUrl = "";
|
String fileName = "pushOrder" + orderPrivateCar.getDriverId() + UUIDUtil.getRandomCode(5) + ".mp3";
|
try {
|
audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, fileName);
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
//定时任务删除语音文件
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
Process process = null;
|
try {
|
process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/" + fileName);
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
if (process != null) {
|
process.destroy();
|
}
|
}
|
}, 30000);
|
|
orderPrivateCar.setDriverId(driver1.getId());
|
orderPrivateCar.setCarId(driver1.getCarId());
|
orderPrivateCar.setCompanyId(driver1.getFranchiseeId() != null && driver1.getFranchiseeId() != 0 ? driver1.getFranchiseeId() : (
|
driver1.getCompanyId() != null && driver1.getCompanyId() != 0 ? driver1.getCompanyId() : 1));
|
orderPrivateCar.setSnatchOrderTime(new Date());
|
orderPrivateCar.setState(orderPrivateCar.getOldState());
|
orderPrivateCar.setOldState(null);
|
if(!StringUtils.hasLength(orderPrivateCar.getTripId())){
|
orderPrivateCar.setTripId(UUIDUtil.getRandomCode());
|
}
|
|
if(orderPrivateCar.getOrderType() == 1){
|
String value = redisUtil.getValue("DRIVER" + driver1.getId());
|
if(ToolUtil.isNotEmpty(value)) {
|
String[] split = value.split(",");
|
DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]));
|
//超时时间
|
long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000);
|
orderPrivateCar.setEstimateArriveTime(new Date(timeOut));
|
orderPrivateCar.setEstimateArriveMileage(distancematrix.getDistance());
|
}
|
}
|
orderPrivateCarService.updateAllColumnById(orderPrivateCar);
|
driver1.setState(3);
|
driverService.updateById(driver1);
|
|
driver.setState(2);
|
driverService.updateById(driver);
|
|
//删除定时任务
|
QuartzUtil.deleteQuartzTask("1_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
|
QuartzUtil.deleteQuartzTask("2_1_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
|
QuartzUtil.deleteQuartzTask("2_2_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
|
QuartzUtil.deleteQuartzTask("3_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
|
|
/**
|
* 超时用户取消不收费的提醒
|
* 预约单:行程时间 + 配置不收费的时间 > 当前时间 (只弹一次)
|
* 即时单:预估到达预约点时间 + 配置不收费的时间 > 当前时间 (只弹一次)
|
*
|
* 超时用户取消订单后需要弹给司机提醒弹框,超时时间 = 当前时间 - 行程时间 - 配置不收费的时间
|
*
|
* 定时提醒弹框
|
* 司机只要开始超时且还未到达预约点,则需要定时提醒
|
*
|
* 预约单需要提前xx分钟提醒司机需要接乘客,过后每隔xx分钟提醒一次。超时后停止提醒
|
*/
|
|
//添加定时任务(普通任务)
|
SysOvertime reminderRules = sysOvertimeService.selectOne(new EntityWrapper<SysOvertime>().eq("companyId", driver1.getCompanyId()));
|
if(null != reminderRules){
|
CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", driver1.getCompanyId()));
|
Integer driverTimeout = JSON.parseObject(cancleOrder.getContent()).getInteger("driverTimeout");
|
|
//即时单
|
if(orderPrivateCar.getOrderType() == 1){
|
//超时时间
|
long timeOut = orderPrivateCar.getEstimateArriveTime().getTime() + (driverTimeout * 60 * 1000);
|
//乘客取消不收费提醒
|
JobDataMap jobDataMap = new JobDataMap();
|
jobDataMap.put("driverId", driver1.getId());
|
jobDataMap.put("timeOutType", 1);
|
jobDataMap.put("orderId", orderPrivateCar.getId());
|
jobDataMap.put("orderType", 1);
|
jobDataMap.put("language", language1);
|
jobDataMap.put("timeOut", timeOut);
|
jobDataMap.put("driverTimeout", driverTimeout);
|
jobDataMap.put("describe", language1 == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language1 == 2 ? "Reminder You are overdue for " + driverTimeout + " minutes The subscriber could cancel the order for free Confirm" : "Rappel Vous êtes en retard de " + driverTimeout + " minutes L’abonné peut annuler la commande gratuitement Confirmer");
|
QuartzUtil.addSimpleQuartzTask(
|
new OrderTimeOutJob().buildQuartzJob("1_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap)
|
, new Date(timeOut), timeOut, 0);
|
|
//超时循环提醒
|
jobDataMap = new JobDataMap();
|
jobDataMap.put("driverId", driver1.getId());
|
jobDataMap.put("timeOutType", 3);
|
jobDataMap.put("orderId", orderPrivateCar.getId());
|
jobDataMap.put("orderType", 1);
|
jobDataMap.put("language", language1);
|
jobDataMap.put("timeOut", orderPrivateCar.getEstimateArriveTime().getTime());
|
jobDataMap.put("driverTimeout", 0);
|
jobDataMap.put("describe", "");
|
QuartzUtil.addSimpleQuartzTask(
|
new OrderTimeOutJob().buildQuartzJob("3_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap)
|
, orderPrivateCar.getEstimateArriveTime(), reminderRules.getCar() * 60000, -1);
|
}else{
|
//超时时间
|
long timeOut = orderPrivateCar.getTravelTime().getTime() + (driverTimeout * 60000);
|
//乘客取消不收费提醒
|
JobDataMap jobDataMap = new JobDataMap();
|
jobDataMap.put("driverId", driver1.getId());
|
jobDataMap.put("timeOutType", 1);
|
jobDataMap.put("orderId", orderPrivateCar.getId());
|
jobDataMap.put("orderType", 1);
|
jobDataMap.put("language", language1);
|
jobDataMap.put("timeOut", timeOut);
|
jobDataMap.put("driverTimeout", driverTimeout);
|
jobDataMap.put("describe", language1 == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language1 == 2 ? "Reminder You are overdue for " + driverTimeout + " minutes The subscriber could cancel the order for free Confirm" : "Rappel Vous êtes en retard de " + driverTimeout + " minutes L’abonné peut annuler la commande gratuitement Confirmer");
|
QuartzUtil.addSimpleQuartzTask(
|
new OrderTimeOutJob().buildQuartzJob("1_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap)
|
, new Date(timeOut), timeOut, 0);
|
|
|
UserInfo userInfo = userInfoMapper.selectById(orderPrivateCar.getUserId());
|
|
//预约单出发首次提醒
|
long travelTime = orderPrivateCar.getTravelTime().getTime() - reminderRules.getReserveTime() * 60000;
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
jobDataMap = new JobDataMap();
|
jobDataMap.put("driverId", driver1.getId());
|
jobDataMap.put("timeOutType", 2);
|
jobDataMap.put("orderId", orderPrivateCar.getId());
|
jobDataMap.put("orderType", 1);
|
jobDataMap.put("language", language1);
|
jobDataMap.put("timeOut", timeOut);
|
jobDataMap.put("driverTimeout", 0);
|
jobDataMap.put("describe", language1 == 1 ? "您将于" + sdf.format(orderPrivateCar.getTravelTime()) + "去接" + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + ",请准时!" :
|
language1 == 2 ? "You are going to pick up " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " at " + sdf.format(orderPrivateCar.getTravelTime()) + ", please be on time. " :
|
"Vous allez chercher " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " à " + sdf.format(orderPrivateCar.getTravelTime()) + ", s’il vous plaît soyez à l’heure.");
|
QuartzUtil.addSimpleQuartzTask(
|
new OrderTimeOutJob().buildQuartzJob("2_1_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap)
|
, new Date(travelTime), travelTime, 0);
|
|
//预约单出发循环提醒
|
jobDataMap = new JobDataMap();
|
jobDataMap.put("driverId", driver1.getId());
|
jobDataMap.put("timeOutType", 2);
|
jobDataMap.put("orderId", orderPrivateCar.getId());
|
jobDataMap.put("orderType", 1);
|
jobDataMap.put("language", language1);
|
jobDataMap.put("timeOut", orderPrivateCar.getTravelTime().getTime());
|
jobDataMap.put("driverTimeout", 0);
|
jobDataMap.put("describe", language1 == 1 ? "您将于" + sdf.format(orderPrivateCar.getTravelTime()) + "去接" + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + ",请准时!" :
|
language1 == 2 ? "You are going to pick up " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " at " + sdf.format(orderPrivateCar.getTravelTime()) + ", please be on time. " :
|
"Vous allez chercher " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " à " + sdf.format(orderPrivateCar.getTravelTime()) + ", s’il vous plaît soyez à l’heure.");
|
QuartzUtil.addSimpleQuartzTask(
|
new OrderTimeOutJob().buildQuartzJob("2_2_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap)
|
, new Date(travelTime + reminderRules.getReserveNext() * 60000), reminderRules.getReserveNext() * 60000, -1);
|
|
//超时循环提醒
|
jobDataMap = new JobDataMap();
|
jobDataMap.put("driverId", driver1.getId());
|
jobDataMap.put("timeOutType", 3);
|
jobDataMap.put("orderId", orderPrivateCar.getId());
|
jobDataMap.put("orderType", 1);
|
jobDataMap.put("language", language1);
|
jobDataMap.put("timeOut", orderPrivateCar.getTravelTime().getTime());
|
jobDataMap.put("driverTimeout", 0);
|
jobDataMap.put("describe", "");
|
QuartzUtil.addSimpleQuartzTask(
|
new OrderTimeOutJob().buildQuartzJob("3_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap)
|
, orderPrivateCar.getTravelTime(), reminderRules.getCar() * 60000, -1);
|
}
|
}
|
|
new Thread(()->{
|
try {
|
Car car = carService.selectById(orderPrivateCar.getCarId());
|
if(!StringUtils.hasLength(car.getVehicleId())){
|
car.setVehicleId(UUIDUtil.getRandomCode());
|
carService.updateById(car);
|
}
|
String trip = fleetEngineUtil.getTrip(orderPrivateCar.getTripId());
|
if(ToolUtil.isEmpty(trip)){
|
String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId());
|
if(ToolUtil.isEmpty(vehicles)){
|
CarModel carModel = carModelMapper.selectById(car.getCarModelId());
|
fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
|
}
|
fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderPrivateCar.getTripId(),
|
orderPrivateCar.getStartLat().toString(), orderPrivateCar.getStartLon().toString(), orderPrivateCar.getEndLat().toString(), orderPrivateCar.getEndLon().toString());
|
}
|
//开始修改行程数据
|
fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderPrivateCar.getTripId(), null, null, null, null);
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}).start();
|
|
//推送相关代码------------------start----------------
|
String finalAudioUrl = audioUrl;
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderReassign(orderPrivateCar.getUserId(), 1, orderPrivateCar.getId(), 1, "");
|
pushUtil.pushOrderReassign(orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, finalAudioUrl);
|
}
|
}).start();
|
|
|
systemNoticeService.addSystemNotice(2, language1 == 1 ? "您已成功抢得打车订单,请及时联系客户!" :
|
language1 == 2 ? "You have grabbed the ride order, please contact the client timely."
|
: "Vous avez saisi la commande de course, veuillez contacter le client en temps opportun.", orderPrivateCar.getDriverId());
|
systemNoticeService.addSystemNotice(1, language1 == 1 ? "您的订单已指派给" + driver1.getFirstName() + "师傅,请保持电话畅通!" :
|
language1 == 2 ? "Your order has been assigned to the driver- " + driver1.getFirstName() + ", please keep your line on."
|
: "Votre commande a été attribuée au chauffeur- " + driver1.getFirstName() + ", S'il vous plaît, restez en ligne.", orderPrivateCar.getUserId());
|
|
}
|
break;
|
case 4:
|
OrderLogistics orderLogistics = orderLogisticsService.selectById(reassign.getOrderId());
|
Company company1 = companyCityService.query1(String.valueOf(orderLogistics.getStartLon()), String.valueOf(orderLogistics.getStartLat()));//获取起点所属分公司
|
PushOrder pushOrder1 = pushOrderService.querys(1, 1, company1.getId()).get(0);
|
//获取空闲司机
|
List<Driver> list1 = driverService.queryIdleDriver(orderLogistics.getType(), orderLogistics.getServerCarModelId(), orderLogistics.getStartLon(), orderLogistics.getStartLat(), pushOrder1.getPushDistance(), null);//所有附近空闲司机
|
System.err.println("【" + orderLogistics.getId() + "】空闲司机:" + JSON.toJSONString(list1));
|
if(list1.size() > 0){
|
Driver driver1 = list1.get(0);
|
reassign.setState(3);
|
reassign.setNowDriverId(driver1.getId());
|
reassign.setNowCarId(driver1.getCarId());
|
reassign.setCompleteTime(new Date());
|
this.updateById(reassign);
|
|
String text = "";
|
Integer language1 = driver1.getLanguage();
|
switch (language1){
|
case 1:
|
text = "收到新的包裹订单,从" + orderLogistics.getStartAddress() + "出发,全程约" + orderLogistics.getEstimatedMileage() + "公里";
|
break;
|
case 2:
|
text = "Received a new delivery order, starting from " + orderLogistics.getStartAddress() + ", the whole journey is about " + orderLogistics.getEstimatedMileage() + "kilometre";
|
break;
|
case 3:
|
text = "J'ai reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage() + "kilométrage";
|
break;
|
|
}
|
String audioUrl = "";
|
String fileName = "pushOrder" + driver1.getId() + UUIDUtil.getRandomCode(5) + ".mp3";
|
try {
|
audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, fileName);
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
//定时任务删除语音文件
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
Process process = null;
|
try {
|
process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/" + fileName);
|
} catch (IOException e) {
|
throw new RuntimeException(e);
|
}
|
if (process != null) {
|
process.destroy();
|
}
|
}
|
}, 30000);
|
|
|
orderLogistics.setDriverId(driver1.getId());
|
orderLogistics.setCarId(driver1.getCarId());
|
orderLogistics.setCompanyId(driver1.getFranchiseeId() != null && driver1.getFranchiseeId() != 0 ? driver1.getFranchiseeId() : (
|
driver1.getCompanyId() != null && driver1.getCompanyId() != 0 ? driver1.getCompanyId() : 1));
|
orderLogistics.setState(orderLogistics.getOldState());
|
orderLogistics.setOldState(null);
|
orderLogistics.setSnatchOrderTime(new Date());
|
if(!StringUtils.hasLength(orderLogistics.getTripId())){
|
orderLogistics.setTripId(UUIDUtil.getRandomCode());
|
}
|
String value = redisUtil.getValue("DRIVER" + driver1.getId());
|
if(ToolUtil.isNotEmpty(value)) {
|
String[] split = value.split(",");
|
DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderLogistics.getStartLat(), orderLogistics.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]));
|
//超时时间
|
long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000);
|
orderLogistics.setEstimateArriveTime(new Date(timeOut));
|
orderLogistics.setEstimateArriveMileage(distancematrix.getDistance());
|
}
|
orderLogisticsService.updateAllColumnById(orderLogistics);
|
//修改司机为服务中
|
driver1.setState(3);
|
driverService.updateById(driver1);
|
|
driver.setState(2);
|
driverService.updateById(driver);
|
|
//删除定时任务
|
QuartzUtil.deleteQuartzTask("1_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
|
QuartzUtil.deleteQuartzTask("2_1_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
|
QuartzUtil.deleteQuartzTask("2_2_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
|
QuartzUtil.deleteQuartzTask("3_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
|
|
/**
|
* 超时用户取消不收费的提醒
|
* 即时单:预估到达预约点时间 + 配置不收费的时间 > 当前时间 (只弹一次)
|
*
|
* 超时用户取消订单后需要弹给司机提醒弹框,超时时间 = 当前时间 - 行程时间 - 配置不收费的时间
|
*
|
* 定时提醒弹框
|
* 司机只要开始超时且还未到达预约点,则需要定时提醒
|
*/
|
|
//添加定时任务(普通任务)
|
SysOvertime reminderRules = sysOvertimeService.selectOne(new EntityWrapper<SysOvertime>().eq("companyId", driver1.getCompanyId()));
|
if(null != reminderRules){
|
CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", driver1.getCompanyId()));
|
Integer driverTimeout = JSON.parseObject(cancleOrder.getContent()).getInteger("driverTimeout");
|
//超时时间
|
long timeOut = orderLogistics.getEstimateArriveTime().getTime() + (driverTimeout * 60 * 1000);
|
//乘客取消不收费提醒
|
JobDataMap jobDataMap = new JobDataMap();
|
jobDataMap.put("driverId", driver1.getId());
|
jobDataMap.put("timeOutType", 1);
|
jobDataMap.put("orderId", orderLogistics.getId());
|
jobDataMap.put("orderType", 4);
|
jobDataMap.put("language", language1);
|
jobDataMap.put("timeOut", timeOut);
|
jobDataMap.put("driverTimeout", driverTimeout);
|
jobDataMap.put("describe", language1 == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language1 == 2 ? "Reminder You are overdue for " + driverTimeout + " minutes The subscriber could cancel the order for free Confirm" : "Rappel Vous êtes en retard de " + driverTimeout + " minutes L’abonné peut annuler la commande gratuitement Confirmer");
|
QuartzUtil.addSimpleQuartzTask(
|
new OrderTimeOutJob().buildQuartzJob("1_" + orderLogistics.getId() + "_4", "ORDER_TIME_OUT", jobDataMap)
|
, new Date(timeOut), timeOut, 0);
|
|
//超时循环提醒
|
jobDataMap = new JobDataMap();
|
jobDataMap.put("driverId", driver1.getId());
|
jobDataMap.put("timeOutType", 3);
|
jobDataMap.put("orderId", orderLogistics.getId());
|
jobDataMap.put("orderType", 4);
|
jobDataMap.put("language", language1);
|
jobDataMap.put("timeOut", orderLogistics.getEstimateArriveTime().getTime());
|
jobDataMap.put("driverTimeout", driverTimeout);
|
jobDataMap.put("describe", "");
|
QuartzUtil.addSimpleQuartzTask(
|
new OrderTimeOutJob().buildQuartzJob("3_" + orderLogistics.getId() + "_4", "ORDER_TIME_OUT", jobDataMap)
|
, orderLogistics.getEstimateArriveTime(), reminderRules.getCar() * 60000, -1);
|
}
|
|
new Thread(()->{
|
try {
|
Car car = carService.selectById(orderLogistics.getCarId());
|
if(!StringUtils.hasLength(car.getVehicleId())){
|
car.setVehicleId(UUIDUtil.getRandomCode());
|
carService.updateById(car);
|
}
|
String trip = fleetEngineUtil.getTrip(orderLogistics.getTripId());
|
if(ToolUtil.isEmpty(trip)){
|
String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId());
|
if(ToolUtil.isEmpty(vehicles)){
|
CarModel carModel = carModelMapper.selectById(car.getCarModelId());
|
fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
|
}
|
fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderLogistics.getTripId(),
|
orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
|
}else{
|
//开始修改行程数据
|
fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null);
|
}
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}).start();
|
|
//推送相关代码------------------start----------------
|
String finalAudioUrl = audioUrl;
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderReassign(orderLogistics.getUserId(), 1, orderLogistics.getId(), 4, "");
|
pushUtil.pushOrderReassign(orderLogistics.getDriverId(), 2, orderLogistics.getId(), 4, finalAudioUrl);
|
}
|
}).start();
|
|
systemNoticeService.addSystemNotice(2, language1 == 1 ? "您已成功抢得包裹订单,请及时联系客户!" :
|
language1 == 2 ? "You have grabbed the delivery order, please contact the client timely."
|
: "Vous avez saisi la commande du livraison. Veuillez contacter le client en temps opportun.", orderLogistics.getDriverId());
|
systemNoticeService.addSystemNotice(1, language1 == 1 ? "您的订单已指派给" + driver1.getFirstName() + "师傅,请保持电话畅通!" :
|
language1 == 2 ? "Your order has been assigned to the driver- " + driver1.getFirstName() + ", please keep your line on."
|
: "Votre commande a été attribuée au chauffeur- " + driver1.getFirstName() + ", S'il vous plaît, restez en ligne.", orderLogistics.getUserId());
|
|
}
|
break;
|
}
|
return resultUtil;
|
}
|
|
|
|
|
/**
|
* 提交改派申请(跨城专用)
|
* @param uid 申请司机id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil saveData_(Reassign reassign, String orderIds, Integer uid, Integer type, Integer language) throws Exception {
|
type = null == type ? 2 : type;//现目前微信只支持小程序支付
|
String content = reassign.getRemark();
|
if(ToolUtil.isNotEmpty(content)){
|
List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
|
for(SensitiveWords s : sensitiveWords){
|
content = content.replaceAll(s.getContent(), "***");
|
}
|
}
|
reassign.setRemark(content);
|
ResultUtil resultUtil = ResultUtil.success();
|
Driver driver = driverService.selectById(uid);
|
// TODO: 2020/11/12 司机端不控制重复提交(如果重复提交且未支付,直接将之前的数据删除)
|
// Reassign query = reassignMapper.query(uid, null, null, null, 1);
|
// if(null != query){
|
// return ResultUtil.error("有未完成支付的改派申请");
|
// }
|
String[] split = orderIds.split(",");//获取支付金额
|
Double aDouble = orderService.queryReassignMoney(Integer.valueOf(split[0]), 3);
|
Double totalMoney = aDouble * split.length;
|
String ids = "";
|
for(String id : split){
|
Reassign query = reassignMapper.query(uid, null, Integer.valueOf(id), 3, 1);
|
if(null != query){
|
// return ResultUtil.error("不能重复提交申请");
|
reassignMapper.deleteById(query.getId());
|
}
|
query = reassignMapper.query(uid, null, Integer.valueOf(id), 3, 2);
|
if(null != query){
|
return ResultUtil.error(language == 1 ? "您提交的申请正在处理中" : language == 2 ? "Your application is being processed." : "Votre demande est en cours de traitement.");
|
}
|
|
reassign.setMoney(aDouble);
|
reassign.setOrderId(Integer.valueOf(id));
|
reassign.setOrderType(3);
|
reassign.setOriginalDriverId(uid);
|
reassign.setOriginalCarId(driver.getCarId());
|
reassign.setInsertTime(new Date());
|
reassign.setState(1);
|
this.insert(reassign);
|
ids += reassign.getId() + ",";
|
}
|
ids = ids.substring(0, ids.length() - 1);
|
systemNoticeService.addSystemNotice(2, language == 1 ? "您的改派申请已成功提交,我们会尽快为你处理!" : language == 2 ?
|
"Your request for reassignment was submitted, we shall handle it for you as soon as possible." :
|
"Votre demande de réaffectation a été soumise. Nous la traiterons pour vous dans les plus brefs délais.", uid);
|
|
//开始支付
|
if(null != reassign.getPayType()){
|
if(reassign.getPayType() == 1){//微信支付
|
String[] split1 = ids.split(",");
|
resultUtil = payMoneyUtil.weixinpay("改派订单",ids+"",ids + "_3",totalMoney+"","/base/wxReassign","APP");
|
//Map<String, String> map = icbcPayUtil.placeAnOrder(ids + "_3", 9, 5, uid.toString(), "改派订单", totalMoney, callbackPath + "/base/wxReassign", "", type, driver.getAppletsOpenId());
|
if(resultUtil.getCode()==200){
|
for(String id : split1){
|
paymentRecordService.saveData(1, null, null, Integer.valueOf(id), 3, 1, aDouble, null, 1);//添加预支付数据
|
}
|
resultUtil = resultUtil;
|
}else{
|
resultUtil = ResultUtil.error(language == 1 ? "获取支付信息失败" : language == 2 ? "Failed to obtain payment information" : "Impossible d’obtenir les informations de paiement", "");
|
}
|
}
|
if(reassign.getPayType() == 2){//支付宝
|
String[] split1 = ids.split(",");
|
resultUtil = payMoneyUtil.alipay("改派订单","v",ids + "_3",totalMoney+"","/base/aliReassign");
|
//Map<String, String> map = icbcPayUtil.placeAnOrder(ids + "_3", 10, 5, uid.toString(), "改派订单", totalMoney, callbackPath + "/base/aliReassign", "", 2, "");
|
if(resultUtil.getCode()==200){
|
for(String id : split1){
|
paymentRecordService.saveData(1, null, null, Integer.valueOf(id), 3, 2, aDouble, null, 1);//添加预支付数据
|
}
|
resultUtil = resultUtil;
|
}else{
|
resultUtil = ResultUtil.error(language == 1 ? "获取支付信息失败" : language == 2 ? "Failed to obtain payment information" : "Impossible d’obtenir les informations de paiement", "");
|
}
|
}
|
if(reassign.getPayType() == 3){//余额
|
for(String id : split){
|
Reassign query = reassignMapper.query(uid, null, Integer.valueOf(id), 3, 1);
|
query.setState(2);
|
query.setPayTime(new Date());
|
reassignMapper.updateById(query);
|
//添加交易明细
|
transactionDetailsService.saveData(uid, language == 1 ? "司机改派支付" : language == 2 ? "The driver was reassigned to pay" : "Paiement de réaffectation du conducteur", aDouble, 2, 1, 2, 3, Integer.valueOf(id));
|
}
|
Double balance = driver.getBalance();
|
if(null == balance || balance < totalMoney){
|
throw new SystemException(language == 1 ? "账户余额不足" : language == 2 ? "Insufficient balance" : "Solde insuffisant");
|
}
|
driver.setBalance(new BigDecimal(balance).subtract(new BigDecimal(totalMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
driverService.updateById(driver);
|
|
|
//修改改派通知状态
|
for(String id : split){
|
OrderCrossCity orderCrossCity = orderCrossCityService.selectById(id);
|
orderCrossCity.setOldState(orderCrossCity.getState());
|
orderCrossCity.setState(11);
|
orderCrossCity.setReassignNotice(2);
|
orderCrossCityService.updateById(orderCrossCity);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderCrossCity.getCompanyId(), 4, orderCrossCity.getId(), 3, reassign.getMoney());
|
}
|
systemNoticeService.addSystemNotice(2, language == 1 ? "您已使用余额成功支付改派申请费用!" : language == 2 ?
|
"You have paid for reassignment with the balance." : "Vous avez payé la réaffectation avec le solde.", uid);
|
//开始推送调度单
|
Map<String, String> map = new HashMap<>();
|
map.put("orderId", reassign.getOrderId().toString());
|
map.put("orderType", reassign.getOrderType().toString());
|
List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1);
|
for(Dispatch dispatch : dispatches){
|
jgPushUtil.push(2,"有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId());
|
}
|
}
|
}
|
return resultUtil;
|
}
|
|
|
|
|
/**
|
* 获取列表数据
|
* @param uid
|
* @param pageNum
|
* @param size
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryList(Integer language, Integer uid, Integer pageNum, Integer size) throws Exception {
|
pageNum = (pageNum - 1) * size;
|
List<Map<String, Object>> list = reassignMapper.queryList(uid, pageNum, size);
|
for (Map<String, Object> map : list) {
|
if(null != map.get("day")){
|
String day = map.get("day").toString();
|
map.put("day", DateUtil.conversionFormat(language, day));
|
}
|
}
|
return list;
|
}
|
|
|
/**
|
* 改派支付完成后的操作
|
* @param id 改派单id
|
* @param order_id 工行支付订单
|
* @param type 1=微信,2=支付宝
|
* @throws Exception
|
*/
|
@Override
|
public void payReassign(String id, String order_id, Integer type) throws Exception {
|
String[] s = id.split("_");
|
if(Integer.valueOf(s[1]) == 3){//跨城订单
|
String[] split = s[0].split(",");
|
List<Reassign> reassigns = this.selectBatchIds(Arrays.asList(split));
|
Driver driver = driverService.selectById(reassigns.get(0).getOriginalDriverId());
|
for(String key : split){
|
PaymentRecord query = paymentRecordService.query(1, null, null, Integer.valueOf(key), 3, type, 1);
|
if(null != query){
|
//添加交易明细
|
transactionDetailsService.saveData(reassigns.get(0).getOriginalDriverId(), "司机改派支付", reassigns.get(0).getMoney(), 2, 1, 2, 3, Integer.valueOf(key));
|
for(Reassign reassign : reassigns){
|
reassign.setState(2);
|
reassign.setPayOrder(order_id);
|
reassign.setPayTime(new Date());
|
this.updateById(reassign);
|
//开始推送调度单
|
Map<String, String> map = new HashMap<>();
|
map.put("orderId", reassign.getOrderId().toString());
|
map.put("orderType", reassign.getOrderType().toString());
|
List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1);
|
for(Dispatch dispatch : dispatches){
|
jgPushUtil.push(2,"有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId());
|
}
|
}
|
query.setState(2);
|
query.setCode(order_id);
|
paymentRecordService.updateById(query);
|
|
//修改改派通知状态
|
for(Reassign reassign : reassigns){
|
OrderCrossCity orderCrossCity1 = orderCrossCityService.selectById(reassign.getOrderId());
|
orderCrossCity1.setOldState(orderCrossCity1.getState());
|
orderCrossCity1.setState(11);
|
orderCrossCity1.setReassignNotice(2);
|
orderCrossCityService.updateById(orderCrossCity1);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderCrossCity1.getCompanyId(), 4, orderCrossCity1.getId(), 3, reassign.getMoney());
|
}
|
systemNoticeService.addSystemNotice(2, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功支付改派申请费用!", reassigns.get(0).getOriginalDriverId());
|
|
}else{
|
System.err.println("预支付数据异常(orderId = " + id + ")");
|
}
|
}
|
|
|
}else{//其他订单
|
Reassign reassign = this.selectById(s[0]);
|
Driver driver = driverService.selectById(reassign.getOriginalDriverId());
|
PaymentRecord query = paymentRecordService.query(1, null, null, reassign.getOrderId(), reassign.getOrderType(), type, 1);
|
if(null != query){
|
//添加交易明细
|
transactionDetailsService.saveData(reassign.getOriginalDriverId(), "司机改派支付", reassign.getMoney(), 2, 1, 2, reassign.getOrderType(), reassign.getOrderId());
|
reassign.setState(2);
|
reassign.setPayOrder(order_id);
|
reassign.setPayTime(new Date());
|
this.updateById(reassign);
|
|
query.setState(2);
|
query.setCode(order_id);
|
paymentRecordService.updateById(query);
|
|
//修改改派通知状态
|
switch (reassign.getOrderType()){
|
case 1:
|
OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(reassign.getOrderId());
|
orderPrivateCar.setOldState(orderPrivateCar.getState());
|
orderPrivateCar.setState(11);
|
orderPrivateCar.setReassignNotice(2);
|
orderPrivateCarService.updateById(orderPrivateCar);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderPrivateCar.getCompanyId(), 4, orderPrivateCar.getId(), 1, reassign.getMoney());
|
break;
|
case 2:
|
OrderTaxi orderTaxi = orderTaxiService.selectById(reassign.getOrderId());
|
orderTaxi.setOldState(orderTaxi.getState());
|
orderTaxi.setState(11);
|
orderTaxi.setReassignNotice(2);
|
orderTaxiService.updateById(orderTaxi);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderTaxi.getCompanyId(), 4, orderTaxi.getId(), 2, reassign.getMoney());
|
break;
|
case 4:
|
OrderLogistics orderLogistics = orderLogisticsService.selectById(reassign.getOrderId());
|
orderLogistics.setOldState(orderLogistics.getState());
|
orderLogistics.setState(11);
|
orderLogistics.setReassignNotice(2);
|
orderLogisticsService.updateById(orderLogistics);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderLogistics.getCompanyId(), 4, orderLogistics.getId(), 4, reassign.getMoney());
|
break;
|
case 5:
|
OrderLogistics orderLogistics1 = orderLogisticsService.selectById(reassign.getOrderId());
|
orderLogistics1.setOldState(orderLogistics1.getState());
|
orderLogistics1.setState(11);
|
orderLogistics1.setReassignNotice(2);
|
orderLogisticsService.updateById(orderLogistics1);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderLogistics1.getCompanyId(), 4, orderLogistics1.getId(), 5, reassign.getMoney());
|
break;
|
}
|
systemNoticeService.addSystemNotice(2, "您已使用" + (type == 1 ? "微信" : "支付宝") + "成功支付改派申请费用!", reassign.getOriginalDriverId());
|
//开始推送调度单
|
Map<String, String> map = new HashMap<>();
|
map.put("orderId", reassign.getOrderId().toString());
|
map.put("orderType", reassign.getOrderType().toString());
|
List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1);
|
for(Dispatch dispatch : dispatches){
|
jgPushUtil.push(2,"有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId());
|
}
|
}else{
|
System.err.println("预支付数据异常(orderId = " + id + ")");
|
}
|
}
|
|
|
}
|
}
|