| | |
| | | package com.ruoyi.quartz.task; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | 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.*; |
| | | 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.Date; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | |
| | | @Autowired |
| | | private ISysClientAppService sysClientAppService; |
| | | |
| | | @Autowired |
| | | private ITbCallbackLogService tbCallbackLogService; |
| | | |
| | | public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) |
| | | { |
| | |
| | | for (AOrderStatus orderStatus : orderStatusList) { |
| | | int count = tbOrdersService.checkServiceOrdIDExists(orderStatus.getServiceOrdID()); |
| | | if (count > 0) { |
| | | System.out.println("服务订单ID存在:" + orderStatus.getServiceOrdID()); |
| | | log.info("服务订单ID存在:" + orderStatus.getServiceOrdID()); |
| | | |
| | | TbOrders tbOrders = tbOrdersService.selectTbOrdersByServiceOrdID(orderStatus.getServiceOrdID()); |
| | | |
| | |
| | | log.error("获取调度单异常:"+e.getMessage()); |
| | | } |
| | | |
| | | SysClientApp clientApp = sysClientAppService.selectSysClientAppByAppKey("appId1"); |
| | | SysClientApp clientApp = sysClientAppService.selectSysClientAppByAppKey(tbOrders.getAppId()); |
| | | if(clientApp==null){ |
| | | log.error("回调地址不存在"); |
| | | return; |
| | |
| | | map.put("plateNo",carLicense); |
| | | map.put("driverMobile",driverMobiles.toString()); |
| | | map.put("driverName", driverNames.toString()); |
| | | map.put("appId", tbOrders.getAppId()); |
| | | |
| | | // 第一次尝试 |
| | | String response = sendCallback(callbackUrl, map); |
| | |
| | | log.info("回调推送成功,参数如下:"); |
| | | map.forEach((key, value) -> log.info(" {} : {}", key, value)); |
| | | orderStatusService.updateAOrderStatusFlag(orderStatus.getId()); |
| | | |
| | | |
| | | |
| | | } else { |
| | | log.error("回调请求重试后仍然失败"); |
| | | orderStatusService.updateAOrderStatusFlag(orderStatus.getId()); |
| | |
| | | |
| | | // 新增发送回调的方法 |
| | | private String sendCallback(String callbackUrl, Map<String, String> params) { |
| | | TbCallbackLog callbackLog = new TbCallbackLog(); |
| | | callbackLog.setCallbackUrl(callbackUrl); |
| | | callbackLog.setRequestParams(JSON.toJSONString(params)); |
| | | callbackLog.setCreateTime(new Date()); |
| | | callbackLog.setStatus("0"); // 默认失败 |
| | | callbackLog.setRetryCount(0); |
| | | callbackLog.setServiceOrdId(params.get("thirdOrderNo")); |
| | | callbackLog.setOrderId(Long.valueOf(params.get("orderID"))); |
| | | callbackLog.setAppId(params.get("appId")); |
| | | |
| | | try { |
| | | // 打印请求参数 |
| | | log.info("发送回调请求,URL: " + callbackUrl); |
| | |
| | | // 打印响应结果 |
| | | log.info("回调响应结果: " + response); |
| | | |
| | | // 更新日志状态 |
| | | callbackLog.setResponseResult(response); |
| | | callbackLog.setStatus("1"); // 成功 |
| | | |
| | | tbCallbackLogService.insertTbCallbackLog(callbackLog); |
| | | return response; |
| | | } catch (Exception e) { |
| | | log.error("回调请求异常: " + e.getMessage()); |
| | | // 记录错误信息 |
| | | callbackLog.setErrorMsg(e.getMessage()); |
| | | callbackLog.setRetryCount(1); // 如果是重试的情况下需要+1 |
| | | tbCallbackLogService.insertTbCallbackLog(callbackLog); |
| | | return null; |
| | | } |
| | | } |