|
@@ -101,6 +101,7 @@ public class ChenYuTestScheduled {
|
|
|
private CloseableHttpClient httpClient;
|
|
|
private static final String TOKEN_REDIS_KEY = "blade:cqcy:token";
|
|
|
private static final String PROJECT_CODE = "cqcyfx";
|
|
|
+ private static final String CONTRACT_CODE = "CYTJ03";
|
|
|
private static Long PROJECT_ID = null;
|
|
|
private static final String BASE_URL = "https://apicqcyfx.qdm123.com";
|
|
|
private final Map<String, Long> contractCodeMap = new ConcurrentHashMap<>();
|
|
@@ -209,62 +210,20 @@ public class ChenYuTestScheduled {
|
|
|
if (!SystemUtils.isLinux()) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- contractCodeMap.clear();
|
|
|
- String token = getToken();
|
|
|
- ensureProjectIdInitialized();
|
|
|
-
|
|
|
- if (token == null || PROJECT_ID == null) {
|
|
|
- log.error("Invalid token or project ID");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
try {
|
|
|
- //获取合同段列表接口
|
|
|
- Result result = getContractList();
|
|
|
- if (result == null || result.getState() != 1) {
|
|
|
- log.error("Failed to get contract sections: {}",
|
|
|
- result != null ? result.getMessage() : "No response");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- JSONArray data = (JSONArray) result.getData();
|
|
|
- if (CollectionUtil.isEmpty(data)) {
|
|
|
- log.warn("No contract sections found");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- List<String> codes = new ArrayList<>();
|
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
- JSONObject obj = data.getJSONObject(i);
|
|
|
- String name = obj.getString("Name");
|
|
|
- if (StringUtil.isNotBlank(name)) {
|
|
|
- codes.add(name);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (CollectionUtil.isEmpty(codes)) {
|
|
|
- log.info("No valid contract codes found");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
// 构建参数化查询
|
|
|
- String placeholders = String.join(",", Collections.nCopies(codes.size(), "?"));
|
|
|
- String sql = "SELECT * FROM m_contract_info WHERE contract_number IN (" + placeholders + ")";
|
|
|
-
|
|
|
+ String sql = "SELECT id FROM m_contract_info WHERE contract_number = '" + CONTRACT_CODE + "'";
|
|
|
List<ContractInfo> contracts = jdbcTemplate.query(
|
|
|
sql,
|
|
|
- codes.toArray(),
|
|
|
new BeanPropertyRowMapper<>(ContractInfo.class)
|
|
|
);
|
|
|
-
|
|
|
- for (ContractInfo contract : contracts) {
|
|
|
- contractCodeMap.put(contract.getContractNumber(), contract.getId());
|
|
|
+ if(CollectionUtil.isNotEmpty(contracts)){
|
|
|
+ ContractInfo contractInfo = contracts.get(0);
|
|
|
+ contractCodeMap.put(CONTRACT_CODE, contractInfo.getId());
|
|
|
}
|
|
|
-
|
|
|
log.info("Loaded {} contract mappings", contractCodeMap.size());
|
|
|
} catch (Exception e) {
|
|
|
- log.error("Error processing contract sections", e);
|
|
|
+ log.error(CONTRACT_CODE + " 合同段编码不存在", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -294,6 +253,8 @@ public class ChenYuTestScheduled {
|
|
|
.eq(TrialCyFinishTestReport::getContractId, contractId));
|
|
|
//等会准备删除的历史数据
|
|
|
List<Long> ids = list.stream().map(TrialCyFinishTestReport::getId).collect(Collectors.toList());
|
|
|
+ //获取旧数据 task_id 与 id的映射关系
|
|
|
+ Map<Integer, Long> taskIdMap = list.stream().collect(Collectors.toMap(TrialCyFinishTestReport::getTaskId, TrialCyFinishTestReport::getId));
|
|
|
|
|
|
int pageIndex = 0;
|
|
|
final int pageSize = 100;
|
|
@@ -335,7 +296,10 @@ public class ChenYuTestScheduled {
|
|
|
for (TrialCyFinishTestReport report : reports) {
|
|
|
//数据太长且不需要
|
|
|
report.setTestParamInfo(null);
|
|
|
- Long id = SnowFlakeUtil.getId();
|
|
|
+ Long id = taskIdMap.get(report.getTaskId());
|
|
|
+ if(id == null){
|
|
|
+ id = SnowFlakeUtil.getId();
|
|
|
+ }
|
|
|
report.setId(id);
|
|
|
report.setContractId(contractId);
|
|
|
//处理boolean值
|
|
@@ -352,9 +316,10 @@ public class ChenYuTestScheduled {
|
|
|
//处理附件
|
|
|
List<TrialCyAccessories> accessories = report.getAccessories();
|
|
|
if (CollectionUtil.isNotEmpty(accessories)) {
|
|
|
+ Long finalId = id;
|
|
|
accessories.forEach(f -> {
|
|
|
f.setId(SnowFlakeUtil.getId());
|
|
|
- f.setReportId(id);
|
|
|
+ f.setReportId(finalId);
|
|
|
if (StringUtil.isNotBlank(f.getFilePath())) {
|
|
|
urls.add(f.getFilePath());
|
|
|
}
|
|
@@ -438,7 +403,8 @@ public class ChenYuTestScheduled {
|
|
|
.eq(TrialCyThirdReport::getContractId, contractId));
|
|
|
//等会要删除的id
|
|
|
List<Long> ids = list.stream().map(TrialCyThirdReport::getPKeyId).collect(Collectors.toList());
|
|
|
-
|
|
|
+ //获取旧数据 id 和 pKId的映射关系
|
|
|
+ Map<String, Long> linkMap = list.stream().collect(Collectors.toMap(TrialCyThirdReport::getId, TrialCyThirdReport::getPKeyId));
|
|
|
|
|
|
int pageIndex = 0;
|
|
|
final int pageSize = 100;
|
|
@@ -489,8 +455,11 @@ public class ChenYuTestScheduled {
|
|
|
if (StringUtil.isNotBlank(report.getRecordDocFilePath())) {
|
|
|
urls.add(report.getRecordDocFilePath());
|
|
|
}
|
|
|
-
|
|
|
- Long id = SnowFlakeUtil.getId();
|
|
|
+ //如果能通过id找到旧pkid 就使用旧pkid
|
|
|
+ Long id = linkMap.get(report.getId());
|
|
|
+ if(id == null){
|
|
|
+ id = SnowFlakeUtil.getId();
|
|
|
+ }
|
|
|
report.setPKeyId(id);
|
|
|
report.setContractId(contractId);
|
|
|
//报告类型
|
|
@@ -502,9 +471,10 @@ public class ChenYuTestScheduled {
|
|
|
//处理附件
|
|
|
List<TrialCyAccessories> accessories = report.getAccessories();
|
|
|
if (CollectionUtil.isNotEmpty(accessories)) {
|
|
|
+ Long finalId = id;
|
|
|
accessories.forEach(f -> {
|
|
|
f.setId(SnowFlakeUtil.getId());
|
|
|
- f.setReportId(id);
|
|
|
+ f.setReportId(finalId);
|
|
|
|
|
|
if (StringUtil.isNotBlank(f.getFilePath())) {
|
|
|
urls.add(f.getFilePath());
|
|
@@ -600,6 +570,7 @@ public class ChenYuTestScheduled {
|
|
|
for (TrialCyTestType type : testTypes) {
|
|
|
type.setPKeyId(SnowFlakeUtil.getId());
|
|
|
type.setProjectId(PROJECT_ID);
|
|
|
+ type.setContractId(contractCodeMap.get(CONTRACT_CODE));
|
|
|
type.setFatherId(type.getFatherId() == null || type.getFatherId().isEmpty() ? "0" : type.getFatherId());
|
|
|
}
|
|
|
//先删除旧数据
|