代码拉取完成,页面将自动刷新
定时任务跑着跑着自己就停了,程序也没报错,重启后台就又可以开始执行了
1.这个是定时任务调用目标字符串的方法
@Component("DownloadVehicleData")
public class DownloadVehicleData {
/**
* @Description: 下载防盗码数据
* @Author: WZX
* @Date: 2024/1/17
*/
public void downloadKeyCodeData() throws Exception {
keyCodeService.downloadKeyCodeData();
}
}
2.这个是具体的实现的内容的代码
@Override
@Transactional(rollbackFor = Exception.class)
public void downloadKeyCodeData() throws Exception {
String maxUpdateTime = serviceKeyCodeMapper.selectMaxUpdateTime();
// 如果本地数据为空,就从系统参数中获取
if (maxUpdateTime == null) {
maxUpdateTime = configService.selectConfigByKey("keyCodeUpdateTime");
}
// 创建log
LogUtils logUtils = new LogUtils(logPath + "/keyCodeData/", "keyCode-" + maxUpdateTime.replace(" ", "-").replace(":", "-"));
try {
String factoryCode = configService.selectConfigByKey("factoryCode");
if (factoryCode == null) {
throw new Exception("未维护工厂代号!");
}
JSONObject param = new JSONObject();
param.put("pageSize", 50);
param.put("startTime", maxUpdateTime);
// 设置序列化特性,格式化输出
SerializerFeature[] features = {SerializerFeature.PrettyFormat};
// 格式化日期
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
logUtils.writeData("[" + format.format(new Date()) + "]:密文入参数据:");
logUtils.writeData(JSON.toJSONString(param, features));
ServiceExternalInterfaceInfo externalInterfaceInfo = externalInterfaceInfoService.selectByFactoryCodeAndKey(factoryCode, "keyCode-cipherData");
if (externalInterfaceInfo == null) {
throw new Exception("未维护工厂:" + factoryCode + "的明文Api信息");
}
JSONObject result = HttpRequest.sendPost(param, externalInterfaceInfo.getUrl(), externalInterfaceInfo.getAppKey(), externalInterfaceInfo.getSign());
logUtils.writeData("[" + format.format(new Date()) + "]:密文出参数据:");
logUtils.writeData(JSON.toJSONString(result, features));
int size = result.getJSONArray("rows").size();
if (size != 0) {
JSONArray keyCodeArray = result.getJSONArray("rows");
getKeyCodeMenu(keyCodeArray, logUtils, factoryCode);
} else {
interfaceOutputUtils.print(InterfaceOutputConstants.bottom, InterfaceOutputConstants.green, FunctionConstants.KeyCode, "查询不到updateTime为:" + maxUpdateTime + "以后的防盗码密文数据");
logUtils.writeData("查询不到updateTime为:" + maxUpdateTime + "以后的密文数据");
}
ServiceKeyCode serviceKeyCode = new ServiceKeyCode();
serviceKeyCode.setStatus(0);
List<ServiceKeyCode> serviceKeyCodes = serviceKeyCodeMapper.selectKeyCodeList(serviceKeyCode);
if (serviceKeyCodes != null && serviceKeyCodes.size() > 0) {
for (ServiceKeyCode keyCode : serviceKeyCodes) {
String vin = keyCode.getVin();
interfaceOutputUtils.print(InterfaceOutputConstants.bottom, InterfaceOutputConstants.green, FunctionConstants.KeyCode, "vin为" + vin + "的防盗码明文数据为空,重新获取");
logger.info("vin为" + vin + "的明文数据为空,重新获取");
keyCode = selectDeCrYPtdData(vin, logUtils, factoryCode, keyCode);
if (keyCode.getStatus() == 1) {
interfaceOutputUtils.print(InterfaceOutputConstants.bottom, InterfaceOutputConstants.green, FunctionConstants.KeyCode, "vin为" + vin + "的防盗码明文数据重新获取成功");
logger.info("vin为" + vin + "的明文数据重新获取成功");
serviceKeyCodeMapper.updateKeyCode(keyCode);
}
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("下载数据异常,{}", e.getMessage());
interfaceOutputUtils.print(InterfaceOutputConstants.bottom, InterfaceOutputConstants.red, FunctionConstants.KeyCode, e.getMessage());
dingUtils.sendMessage("下载数据异常:" + e.getMessage(), DingMsgTypeConstant.FAIL);
} finally {
logUtils.close();
}
}
3.定时任务的执行策略是 立即执行,禁止并发
大佬帮我看看这是咋回事