feat(SqlServerApiClient): 优化热卷ID查询工艺段逻辑

- 添加ArrayList导入用于存储COILID列表
- 修改queryProSegByHotCoilId方法实现分步查询
- 首先从PLTCM_PDI_PLAN表查询COILID
- 添加空结果检查和异常处理逻辑
- 收集有效的COILID并过滤空值
- 使用IN查询一次性获取PLTCM_PRO_SEG表数据
- 按ENCOILID和SEGNO排序返回结果
This commit is contained in:
2026-05-11 14:48:06 +08:00
parent 0865e040ee
commit 90cb7f4e99

View File

@@ -10,6 +10,7 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI; import java.net.URI;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -369,11 +370,47 @@ public class SqlServerApiClient {
} }
public ExecuteSqlResponse queryProSegByHotCoilId(String hotCoilId) { public ExecuteSqlResponse queryProSegByHotCoilId(String hotCoilId) {
return executeSql( // 先通过 HOT_COILID 从 PLTCM_PDI_PLAN 表查询到所有的 COILID
ExecuteSqlResponse planResponse = executeSql(
"oracle", "oracle",
"select * from JXPLTCM.PLTCM_PRO_SEG where HOT_COILID = :hotCoilId order by SEGNO", "select COILID from JXPLTCM.PLTCM_PDI_PLAN where HOT_COILID = :hotCoilId",
singletonParam("hotCoilId", hotCoilId) singletonParam("hotCoilId", hotCoilId)
); );
List<Map<String, Object>> rows = (List<Map<String, Object>>) planResponse.getResult();
if (rows == null || rows.isEmpty()) {
// 如果没有找到对应的计划记录,返回空结果
return new ExecuteSqlResponse();
}
// 收集所有有效的 COILID
List<String> coilIds = new ArrayList<>();
for (Map<String, Object> row : rows) {
String coilId = (String) row.get("COILID");
if (coilId != null && !coilId.trim().isEmpty()) {
coilIds.add(coilId);
}
}
if (coilIds.isEmpty()) {
return new ExecuteSqlResponse();
}
// 用所有的 COILID 去查询 PLTCM_PRO_SEG 表的 ENCOILID
// 使用 IN 查询一次性获取所有数据
Map<String, Object> params = new java.util.HashMap<>();
StringBuilder sql = new StringBuilder("select * from JXPLTCM.PLTCM_PRO_SEG where ENCOILID IN (");
for (int i = 0; i < coilIds.size(); i++) {
if (i > 0) {
sql.append(", ");
}
String paramName = "coilId" + i;
sql.append(":").append(paramName);
params.put(paramName, coilIds.get(i));
}
sql.append(") order by ENCOILID, SEGNO");
return executeSql("oracle", sql.toString(), params);
} }
public ExecuteSqlResponse queryProSegByExcoilId(String excoilId) { public ExecuteSqlResponse queryProSegByExcoilId(String excoilId) {