Commit c2e9da45 by 章家宝

feat:存量车辆数据定时任务修改

1 parent 8d539292
...@@ -11,6 +11,7 @@ import lombok.Getter; ...@@ -11,6 +11,7 @@ import lombok.Getter;
public enum SystemConfigKeyEnum { public enum SystemConfigKeyEnum {
MAIN_PAGE_SCRIPT("main_page_script", "首页脚本"), MAIN_PAGE_SCRIPT("main_page_script", "首页脚本"),
MAIN_PAGE_LINK("main_page_link", "首页链接"), MAIN_PAGE_LINK("main_page_link", "首页链接"),
TRANSFER_MATERIALS_SYNCED("transfer_materials_synced", "过户资料是否已同步"),
; ;
private String key; private String key;
private String desc; private String desc;
......
...@@ -221,4 +221,25 @@ public class SystemConfigService { ...@@ -221,4 +221,25 @@ public class SystemConfigService {
return StringUtils.hasText(configOpt.get().getConfigValue()) return StringUtils.hasText(configOpt.get().getConfigValue())
? configOpt.get().getConfigValue() : defaultValue; ? configOpt.get().getConfigValue() : defaultValue;
} }
/**
* 更新配置值(根据配置键)
* @param configKey 配置键
* @param configValue 新配置值
* @param operator 操作人
* @return 是否更新成功
*/
@Transactional(rollbackFor = Exception.class)
public boolean updateConfigValue(String configKey, String configValue, String operator) {
SystemConfig config = systemConfigDao.findByConfigKeyAndDeletedFlag(configKey, "N");
if (config == null) {
log.warn("配置键[{}]不存在,无法更新", configKey);
return false;
}
config.setConfigValue(configValue);
config.setUpdatedBy(operator);
systemConfigDao.save(config);
log.info("更新配置成功,配置键: {}, 新值: {}", configKey, configValue);
return true;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,8 @@ package com.glsx.usedcar.task; ...@@ -2,6 +2,8 @@ package com.glsx.usedcar.task;
import com.glsx.usedcar.gsc.GscInvoker; import com.glsx.usedcar.gsc.GscInvoker;
import com.glsx.usedcar.gsc.dto.VehicleSyncDataDTO; import com.glsx.usedcar.gsc.dto.VehicleSyncDataDTO;
import com.glsx.usedcar.module.system.enums.SystemConfigKeyEnum;
import com.glsx.usedcar.module.system.service.SystemConfigService;
import com.glsx.usedcar.module.vehicle.dao.VehicleDao; import com.glsx.usedcar.module.vehicle.dao.VehicleDao;
import com.glsx.usedcar.module.vehicle.entity.Vehicle; import com.glsx.usedcar.module.vehicle.entity.Vehicle;
import com.glsx.usedcar.module.vehicle.entity.Vehicle_; import com.glsx.usedcar.module.vehicle.entity.Vehicle_;
...@@ -23,6 +25,14 @@ import java.util.Map; ...@@ -23,6 +25,14 @@ import java.util.Map;
* <p> * <p>
* 从收车端同步存量车辆的过户资料和评估人员信息 * 从收车端同步存量车辆的过户资料和评估人员信息
* </p> * </p>
* <p>
* 同步状态说明(通过 system_config.transfer_materials_synced 控制):
* <ul>
* <li>0: 未执行,开始执行</li>
* <li>1: 执行中,跳过</li>
* <li>2: 已完成,跳过</li>
* </ul>
* </p>
*/ */
@Slf4j @Slf4j
@Component @Component
...@@ -37,23 +47,51 @@ public class TransferMaterialsSyncSchedule { ...@@ -37,23 +47,51 @@ public class TransferMaterialsSyncSchedule {
@Resource @Resource
private GscInvoker gscInvoker; private GscInvoker gscInvoker;
@Resource
private SystemConfigService systemConfigService;
/** /**
* 每批次处理数量 * 每批次处理数量
*/ */
private static final int BATCH_SIZE = 100; private static final int BATCH_SIZE = 100;
/** /**
* 同步状态常量
*/
private static final String STATUS_NOT_SYNCED = "0";
private static final String STATUS_SYNCING = "1";
private static final String STATUS_SYNCED = "2";
/**
* 定时同步车辆数据 * 定时同步车辆数据
* <p> * <p>
* 每小时执行一次,同步收车端来源的车辆过户资料和评估人员信息 * 每30分钟执行一次,检查同步状态,仅当状态为0时执行
* </p> * </p>
*/ */
@Scheduled(fixedDelay = 1000 * 60 * 60, initialDelay = 1000 * 60 * 5) @Scheduled(fixedDelay = 1000 * 60 * 30)
public void syncTransferMaterials() { public void syncTransferMaterials() {
log.info("开始执行车辆同步数据定时任务"); String configKey = SystemConfigKeyEnum.TRANSFER_MATERIALS_SYNCED.getKey();
String status = systemConfigService.getConfigValueAsString(configKey, STATUS_NOT_SYNCED);
// 状态为2(已完成)或1(执行中),跳过
if (STATUS_SYNCED.equals(status)) {
log.debug("过户资料同步任务已完成,跳过");
return;
}
if (STATUS_SYNCING.equals(status)) {
log.info("过户资料同步任务执行中,跳过");
return;
}
// 状态为0(未执行),开始同步
log.info("开始执行过户资料同步任务");
int totalSynced = 0; int totalSynced = 0;
int totalFailed = 0; int totalFailed = 0;
try {
// 更新状态为执行中
systemConfigService.updateConfigValue(configKey, STATUS_SYNCING, "system");
// 分页查询收车端来源的车辆 // 分页查询收车端来源的车辆
int page = 0; int page = 0;
Page<Vehicle> vehiclePage; Page<Vehicle> vehiclePage;
...@@ -127,6 +165,11 @@ public class TransferMaterialsSyncSchedule { ...@@ -127,6 +165,11 @@ public class TransferMaterialsSyncSchedule {
page++; page++;
} while (vehiclePage.hasNext()); } while (vehiclePage.hasNext());
log.info("车辆同步数据定时任务完成,成功: {}, 失败: {}", totalSynced, totalFailed); log.info("车辆同步数据任务完成,成功: {}, 失败: {}", totalSynced, totalFailed);
} finally {
// 更新状态为已完成
systemConfigService.updateConfigValue(configKey, STATUS_SYNCED, "system");
}
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!