package com.ruoyi.quartz.task;
|
|
import com.ruoyi.common.utils.HttpUtil;
|
import com.ruoyi.system.domain.*;
|
import com.ruoyi.system.service.IAOrderStatusService;
|
import com.ruoyi.system.service.IDispatchOrdService;
|
import com.ruoyi.system.service.ISysClientAppService;
|
import com.ruoyi.system.service.ITbOrdersService;
|
import com.ruoyi.system.service.impl.SysUserServiceImpl;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import com.ruoyi.common.utils.StringUtils;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 定时任务调度测试
|
*
|
* @author ruoyi
|
*/
|
@Component("ryTask")
|
public class RyTask
|
{
|
private static final Logger log = LoggerFactory.getLogger(RyTask.class);
|
@Autowired
|
private IAOrderStatusService orderStatusService;
|
|
@Autowired
|
private ITbOrdersService tbOrdersService;
|
|
@Autowired
|
private IDispatchOrdService dispatchOrdService;
|
|
@Autowired
|
private ISysClientAppService sysClientAppService;
|
|
public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
|
{
|
System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
|
}
|
|
public void ryParams(String params)
|
{
|
System.out.println("执行有参方法:" + params);
|
}
|
|
public void ryNoParams()
|
{
|
System.out.println("执行无参方法");
|
}
|
|
/**
|
* 回调推送状态
|
*/
|
public void ryOrderStatus() {
|
try {
|
List<AOrderStatus> orderStatusList = orderStatusService.selectAOrderStatusList();
|
if (orderStatusList.size() < 0) {
|
System.out.println("没有数据");
|
return;
|
}
|
for (AOrderStatus orderStatus : orderStatusList) {
|
int count = tbOrdersService.checkServiceOrdIDExists(orderStatus.getServiceOrdID());
|
if (count > 0) {
|
System.out.println("服务订单ID存在:" + orderStatus.getServiceOrdID());
|
|
TbOrders tbOrders = tbOrdersService.selectTbOrdersByServiceOrdID(orderStatus.getServiceOrdID());
|
|
|
|
//获取车牌号
|
String carLicense = "";
|
StringBuilder driverNames = new StringBuilder();
|
StringBuilder driverMobiles = new StringBuilder();
|
try{
|
DispatchOrd dispatchOrd = dispatchOrdService.selectDispatchOrdByServiceOrdIDDt(orderStatus.getServiceOrdID());
|
if(dispatchOrd!=null){
|
carLicense = dispatchOrdService.selectCarLicenseByCarId(Integer.valueOf(dispatchOrd.getDispatchOrdCarID()));
|
|
String dispatchOAEntourage = dispatchOrd.getDispatchOrd_OAEntourage();
|
String dispatchOAName = dispatchOrd.getDispatchOrd_OAName();
|
|
if (dispatchOAEntourage != null && dispatchOAName != null) {
|
|
String[] entourages = dispatchOAEntourage.split(",");
|
String[] names = dispatchOAName.split(",");
|
|
// 查找所有司机信息
|
for (int i = 0; i < Math.min(entourages.length, names.length); i++) {
|
if ("司机".equals(entourages[i].trim())) {
|
String driverMobile = dispatchOrdService.selectDriverMobileByName(names[i].trim());
|
if (driverNames.length() > 0) {
|
driverNames.append(",");
|
}
|
driverNames.append(names[i].trim());
|
if (driverMobiles.length() > 0) {
|
driverMobiles.append(",");
|
}
|
driverMobiles.append(driverMobile);
|
}
|
}
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
log.error("获取调度单异常:"+e.getMessage());
|
}
|
|
SysClientApp clientApp = sysClientAppService.selectSysClientAppByAppId(1L);
|
if(clientApp==null){
|
log.error("回调地址不存在");
|
return;
|
}
|
|
String callbackUrl = clientApp.getCallbackUrl();
|
try {
|
// 构建请求参数
|
Map<String, String> map = new HashMap<>();
|
map.put("orderID", tbOrders.getOrderID().toString());
|
map.put("thirdOrderNo", orderStatus.getServiceOrdID());
|
map.put("orderStatus","1");
|
map.put("orderRemark", orderStatus.getMsg());
|
map.put("plateNo",carLicense);
|
map.put("driverMobile",driverMobiles.toString());
|
map.put("driverName", driverNames.toString());
|
|
// 第一次尝试
|
String response = sendCallback(callbackUrl, map);
|
|
if (response == null) {
|
// 如果第一次失败,等待3秒后重试
|
Thread.sleep(3000);
|
log.info("第一次回调失败,准备重试");
|
response = sendCallback(callbackUrl, map);
|
}
|
|
if (response != null) {
|
// 更新状态
|
log.info("回调推送成功,参数如下:");
|
map.forEach((key, value) -> log.info(" {} : {}", key, value));
|
orderStatusService.updateAOrderStatusFlag(orderStatus.getId());
|
} else {
|
log.error("回调请求重试后仍然失败");
|
orderStatusService.updateAOrderStatusFlag(orderStatus.getId());
|
}
|
} catch (Exception e) {
|
log.error("回调请求失败: " + e.getMessage());
|
orderStatusService.updateAOrderStatusFlag(orderStatus.getId());
|
}
|
}
|
else {
|
log.info("服务订单ID不存在:" + orderStatus.getServiceOrdID());
|
orderStatusService.updateAOrderStatusFlag(orderStatus.getId());
|
}
|
}
|
} catch (Exception e) {
|
log.error("执行失败: " + e.getMessage());
|
e.printStackTrace();
|
}
|
}
|
|
// 新增发送回调的方法
|
private String sendCallback(String callbackUrl, Map<String, String> params) {
|
try {
|
// 打印请求参数
|
log.info("发送回调请求,URL: " + callbackUrl);
|
log.info("请求参数: " + params);
|
|
// 发送请求并获取响应
|
String response = HttpUtil.post(callbackUrl, params);
|
|
// 打印响应结果
|
log.info("回调响应结果: " + response);
|
|
return response;
|
} catch (Exception e) {
|
log.error("回调请求异常: " + e.getMessage());
|
return null;
|
}
|
}
|
}
|