wzp
2025-05-06 5d5a187689e51a8a74f16b91d23d32a74b39e803
feat: 新增回调手动重推
9个文件已修改
197 ■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TbCallbackLogController.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TbOrdersController.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/domain/OrderStatusCallBackVo.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/ITbCallbackLogService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TbCallbackLogServiceImpl.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/resources/mapper/system/TbCallbackLogMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/api/system/callbacklog.js 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/views/system/callbacklog/index.vue 63 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TbCallbackLogController.java
@@ -101,4 +101,15 @@
    {
        return toAjax(tbCallbackLogService.deleteTbCallbackLogByIds(ids));
    }
    /**
     * 重试回调
     */
    @PreAuthorize("@ss.hasPermi('system:callbacklog:retry')")
    @Log(title = "回调记录", businessType = BusinessType.UPDATE)
    @PostMapping("/retry/{ids}")
    public AjaxResult retry(@PathVariable Long[] ids)
    {
        return toAjax(tbCallbackLogService.retryTbCallbackLogByIds(ids));
    }
}
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TbOrdersController.java
@@ -4,6 +4,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.annotation.Anonymous;
@@ -83,8 +84,8 @@
     * @param tbOrders
     * @return
     */
//    @Anonymous(needSign = true)
    @Anonymous
    @Anonymous(needSign = true)
//    @Anonymous
//    @Log(title = "orders", businessType = BusinessType.INSERT)
    @ApiOperation("新增订单")
    @ApiImplicitParams({
@@ -103,17 +104,25 @@
        @ApiImplicitParam(name = "bookingPrice", value = "报价", dataType = "BigDecimal")
    })
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TbOrders tbOrders) {
    public AjaxResult add(@RequestBody TbOrders tbOrders,String appId) {
        try {
            if (tbOrders == null || tbOrders.getOrderID() == null) {
                return AjaxResult.error("传输数据为空!");
            }
            if(appId ==null|| Objects.equals(appId, ""))
            {
                return AjaxResult.error("appid不能为空!");
            }
            tbOrders.setAppId(appId);
            tbOrders.setCreateTime(new Date());
            tbOrdersService.insertTbOrders(tbOrders);
            SysClientApp scApp = clientAppService.selectSysClientAppByAppId(1L);
            SysClientApp scApp = clientAppService.selectSysClientAppByAppKey(tbOrders.getAppId());
            ServiceOrderAppVo model = new ServiceOrderAppVo();
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
@@ -25,6 +25,29 @@
public class RyTask
{
    private static final Logger log = LoggerFactory.getLogger(RyTask.class);
    // 添加状态映射字典
    private static final Map<String, String> ORDER_STATUS_MAP = new HashMap<String, String>() {{
        put("-1", "无效取消");
        put("1", "未报价");
        put("2", "已报价");
        put("3", "1 - 完全未确认");
        put("4", "2 - 部分已确认");
        put("5", "未出车");
        put("6", "3 - 已出车(去接患者途中)");
        put("7", "已出车(等待患者)");
        put("8", "4 - 已出车(服务中)");
        put("9", "5 - 已送达(回程中)");
        put("10", "已返回");
        put("11", "跑空单,已返回");
        put("12", "取消");
        put("13", "0 - 新调度单(未下发)");
        put("14", "已提交,等待审核");
        put("15", "审核完成");
        put("16", "审核不通过");
        put("17", "已站点");
    }};
    @Autowired
    private IAOrderStatusService orderStatusService;
@@ -54,6 +77,9 @@
    {
        System.out.println("执行无参方法");
    }
    /**
     * 回调推送状态
@@ -125,7 +151,12 @@
                        Map<String, String> map = new HashMap<>();
                        map.put("orderID", tbOrders.getOrderID().toString());
                        map.put("thirdOrderNo", orderStatus.getServiceOrdID());
                        map.put("orderStatus","1");
                        map.put("orderStatus", ORDER_STATUS_MAP.entrySet()
                            .stream()
                            .filter(entry -> entry.getValue().equals(orderStatus.getMsg()))
                            .map(Map.Entry::getKey)
                            .findFirst()
                            .orElse("0"));
                        map.put("orderRemark", orderStatus.getMsg());
                        map.put("plateNo",carLicense);
                        map.put("driverMobile",driverMobiles.toString());
ruoyi-system/src/main/java/com/ruoyi/system/domain/OrderStatusCallBackVo.java
@@ -1,8 +1,11 @@
package com.ruoyi.system.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class OrderStatusCallBackVo {
    /**
ruoyi-system/src/main/java/com/ruoyi/system/service/ITbCallbackLogService.java
@@ -56,4 +56,12 @@
     * @return 结果
     */
    public int deleteTbCallbackLogById(Long id);
    /**
     * 重试回调
     *
     * @param ids 需要重试的回调记录主键集合
     * @return 结果
     */
    public int retryTbCallbackLogByIds(Long[] ids);
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TbCallbackLogServiceImpl.java
@@ -1,11 +1,19 @@
package com.ruoyi.system.service.impl;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TbCallbackLogMapper;
import com.ruoyi.system.domain.TbCallbackLog;
import com.ruoyi.system.service.ITbCallbackLogService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.ruoyi.common.utils.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * 回调记录Service业务层处理
@@ -14,6 +22,8 @@
@Service
public class TbCallbackLogServiceImpl implements ITbCallbackLogService 
{
    private static final Logger log = LoggerFactory.getLogger(TbCallbackLogServiceImpl.class);
    @Autowired
    private TbCallbackLogMapper tbCallbackLogMapper;
@@ -88,4 +98,46 @@
    {
        return tbCallbackLogMapper.deleteTbCallbackLogById(id);
    }
    /**
     * 重试回调
     */
    @Override
    public int retryTbCallbackLogByIds(Long[] ids) {
        int successCount = 0;
        for (Long id : ids) {
            TbCallbackLog callbackLog = tbCallbackLogMapper.selectTbCallbackLogById(id);
            if (callbackLog != null) {
                try {
                    // 解析原始请求参数
                    Map<String, String> params = JSON.parseObject(callbackLog.getRequestParams(),
                        new TypeReference<Map<String, String>>() {});
                    // 转换key的首字母为大写
                    Map<String, String> capitalizedParams = new HashMap<>();
                    params.forEach((key, value) -> {
                        String capitalizedKey = key.substring(0, 1).toUpperCase() + key.substring(1);
                        capitalizedParams.put(capitalizedKey, value);
                    });
                    // 重新发送回调
                    String response = HttpUtil.post(callbackLog.getCallbackUrl(), capitalizedParams);
                    if (response != null) {
                        callbackLog.setRetryCount(callbackLog.getRetryCount()+1);
                        callbackLog.setResponseResult(response);
                        callbackLog.setStatus("1"); // 更新状态为成功
                        successCount++;
                        tbCallbackLogMapper.updateTbCallbackLog(callbackLog);
                    }
                } catch (Exception e) {
                    log.error("重试回调失败,ID: " + id + ", 错误: " + e.getMessage());
                    callbackLog.setErrorMsg(e.getMessage());
                    callbackLog.setStatus("0"); // 更新状态为失败
                    tbCallbackLogMapper.updateTbCallbackLog(callbackLog);
                }
            }
        }
        return successCount;
    }
ruoyi-system/src/main/resources/mapper/system/TbCallbackLogMapper.xml
@@ -37,7 +37,7 @@
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
        order by create_time,id desc
        order by id desc
    </select>
    
    <select id="selectTbCallbackLogById" parameterType="Long" resultMap="TbCallbackLogResult">
ruoyi-ui/src/api/system/callbacklog.js
@@ -42,3 +42,11 @@
    method: 'delete'
  })
}
// 重试回调
export function retryCallbacklog(ids) {
  return request({
    url: '/system/callbacklog/retry/' + ids,
    method: 'post'
  })
}
ruoyi-ui/src/views/system/callbacklog/index.vue
@@ -48,8 +48,8 @@
    </el-form>
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
      <el-col :span="1.5">
        <!-- <el-button
          type="primary"
          plain
          icon="el-icon-plus"
@@ -78,8 +78,9 @@
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:callbacklog:remove']"
        >删除</el-button>
      </el-col> -->
        >删除</el-button> -->
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
@@ -89,6 +90,16 @@
          @click="handleExport"
          v-hasPermi="['system:callbacklog:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-s-promotion"
          size="mini"
          :disabled="multiple"
          @click="handleBatchRetry"
        >批量重试</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
@@ -116,24 +127,17 @@
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:callbacklog:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:callbacklog:remove']"
          >删除</el-button>
            icon="el-icon-s-promotion"
            @click="handleRetry(scope.row)"
            v-hasPermi="['system:callbacklog:retry']"
          >重试回调</el-button>
        </template>
      </el-table-column> -->
      </el-table-column>
    </el-table>
    
    <pagination
@@ -181,7 +185,7 @@
</template>
<script>
import { listCallbacklog, getCallbacklog, delCallbacklog, addCallbacklog, updateCallbacklog } from "@/api/system/callbacklog";
import { listCallbacklog, getCallbacklog, delCallbacklog, addCallbacklog, updateCallbacklog, retryCallbacklog } from "@/api/system/callbacklog";
export default {
  name: "Callbacklog",
@@ -328,6 +332,29 @@
      this.download('system/callbacklog/export', {
        ...this.queryParams
      }, `callbacklog_${new Date().getTime()}.xlsx`)
    },
    /** 触发单个回调重试 */
    handleRetry(row) {
      const id = row.id;
      this.$modal.confirm('是否确认重试该回调记录?').then(function() {
        return retryCallbacklog(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("触发重试成功");
      }).catch(() => {});
    },
    /** 批量触发回调重试 */
    handleBatchRetry() {
      if (this.ids.length === 0) {
        this.$modal.msgError("请选择需要重试的记录");
        return;
      }
      this.$modal.confirm('是否确认重试选中的' + this.ids.length + '条回调记录?').then(() => {
        return retryCallbacklog(this.ids.join(','));
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("批量重试成功");
      }).catch(() => {});
    }
  }
};