提交 7574acd8 authored 作者: 吕本才's avatar 吕本才

1、优化区分定时任务空执行和报错情况

上级 f99a75cc
......@@ -27,5 +27,6 @@ public class FinanceSyncOrderDetailDto {
* 错误信息
*/
private String message;
private Integer code = 200;
}
......@@ -2,6 +2,7 @@ package com.sfa.job.service.order.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONReader;
import com.baomidou.dynamic.datasource.annotation.DS;
......@@ -91,17 +92,22 @@ public class FinanceOrderSyncServiceImpl extends ServiceImpl<FinanceOrderMapper,
}
}
if (ObjectUtils.isEmpty(endTime)) {
endTime = DateUtils.addMinutes(startTime, 60);
}
// 调用查询旺店通接口api 获取最新日期前的2小时
Date currentLatest = DateUtils.addHours(new Date(), -2);
if (currentLatest.compareTo(startTime) < 0) {
detailDto.setMessage(String.format("开始时间%s不能大于当前时间%s", startTime, currentLatest));
log.warn(detailDto.getMessage());
detailDto.setTotalCount(0);
detailDto.setBatchNo(batchNo);
detailDto.setStartTime(startTime);
detailDto.setEndTime(endTime);
detailDto.setMessage(String.format("开始时间%s不能大于当前时间%s", DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(currentLatest) ));
log.warn(String.format("开始时间%s不能大于当前时间%s", DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(currentLatest) ));
return detailDto;
}
if (ObjectUtils.isEmpty(endTime)) {
endTime = DateUtils.addMinutes(startTime, 60);
}
log.info("查询订单参数:开始时间{},结束时间{},当前页:{}", DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime), beginPageNo.get());
WangdiantongQueryVO wangdiantongQueryVO = new WangdiantongQueryVO();
......@@ -229,12 +235,13 @@ public class FinanceOrderSyncServiceImpl extends ServiceImpl<FinanceOrderMapper,
// 记录错误日志表 collect_error_info
CollectErrorInfo errorInfo = new CollectErrorInfo();
errorInfo.setBatchNo(batchNo);
errorInfo.setType("");
errorInfo.setType("xxlJob");
errorInfo.setErrorMsg(e.getMessage());
errorInfo.setEndTime(endTime);
errorInfo.setStartTime(startTime);
errorInfo.setCollectTime(new Date());
errorInfoDao.insert(errorInfo);
detailDto.setCode(HttpStatus.HTTP_INTERNAL_ERROR);
detailDto.setMessage(e.toString());
}
return detailDto;
......
......@@ -2,6 +2,7 @@ package com.sfa.job.xxljob.order;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson2.JSONObject;
import com.sfa.job.pojo.response.FinanceSyncOrderDetailDto;
import com.sfa.job.service.order.FinanceOrderSyncService;
......@@ -45,10 +46,10 @@ public class FinanceOrderTask {
XxlJobHelper.log("xxl-job结束同步-旺店通订单明细api接口数据, 共同步订单{}条数据,订单明细{}条,订单批次号:{},订单的开始时间{}和结束时间{}",
detailDto.getOrderCount(),detailDto.getOrderDetailCount(),detailDto.getBatchNo(),
DateUtil.formatDateTime(detailDto.getStartTime()),DateUtil.formatDateTime(detailDto.getEndTime()) );
if(ObjectUtil.isNotEmpty(detailDto.getMessage())){
XxlJobHelper.handleFail(detailDto.getMessage());
if(ObjectUtil.equals(HttpStatus.HTTP_OK,detailDto.getCode()) ){
XxlJobHelper.handleSuccess(JSONObject.toJSONString(detailDto));
}else{
XxlJobHelper.handleSuccess( JSONObject.toJSONString( detailDto));
XxlJobHelper.handleFail(detailDto.getMessage());
}
return detailDto;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论