refactor: 注释掉出口卷数据同步相关代码并优化钢卷对比默认查询逻辑
本次提交主要变更: 1. 注释掉所有出口卷数据同步的接口、服务实现和相关工具方法 2. 优化钢卷对比页面的默认时间逻辑,移除默认7天前的起始时间,改为默认查询今日全天数据 3. 新增日期格式化工具方法统一处理时间字符串拼接 4. 完善钢卷对比接口的注释和字段映射逻辑
This commit is contained in:
@@ -98,15 +98,15 @@ public class MesExCoilController extends BaseController {
|
||||
return toAjax(iMesExCoilService.deleteWithValidByIds(Arrays.asList(exIds), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 L2 系统同步出口卷实绩数据。
|
||||
* 首次全量同步,后续增量同步(以 insdate 为锚点)。
|
||||
*/
|
||||
@Log(title = "出口卷数据同步", businessType = BusinessType.OTHER)
|
||||
@RepeatSubmit(interval = 300000, message = "同步任务已提交,请勿重复操作")
|
||||
@PostMapping("/sync")
|
||||
public R<Map<String, Object>> sync() {
|
||||
Map<String, Object> result = iMesExCoilService.syncExCoilData();
|
||||
return R.ok(result);
|
||||
}
|
||||
// /**
|
||||
// * 从 L2 系统同步出口卷实绩数据。
|
||||
// * 首次全量同步,后续增量同步(以 insdate 为锚点)。
|
||||
// */
|
||||
// @Log(title = "出口卷数据同步", businessType = BusinessType.OTHER)
|
||||
// @RepeatSubmit(interval = 300000, message = "同步任务已提交,请勿重复操作")
|
||||
// @PostMapping("/sync")
|
||||
// public R<Map<String, Object>> sync() {
|
||||
// Map<String, Object> result = iMesExCoilService.syncExCoilData();
|
||||
// return R.ok(result);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public interface IMesExCoilService {
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 从 L2 系统同步出口卷实绩数据
|
||||
*/
|
||||
Map<String, Object> syncExCoilData();
|
||||
// /**
|
||||
// * 从 L2 系统同步出口卷实绩数据
|
||||
// */
|
||||
// Map<String, Object> syncExCoilData();
|
||||
}
|
||||
|
||||
@@ -143,217 +143,217 @@ public class MesExCoilServiceImpl implements IMesExCoilService {
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> syncExCoilData() {
|
||||
Date maxInsdate = baseMapper.getMaxInsdate();
|
||||
boolean isFullSync = (maxInsdate == null);
|
||||
|
||||
List<Map<String, Object>> apiRows;
|
||||
if (isFullSync) {
|
||||
apiRows = fetchAllFromApi();
|
||||
} else {
|
||||
apiRows = fetchIncrementalFromApi(maxInsdate);
|
||||
}
|
||||
|
||||
if (apiRows == null || apiRows.isEmpty()) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("totalFetched", 0);
|
||||
result.put("insertCount", 0);
|
||||
result.put("updateCount", 0);
|
||||
result.put("fullSync", isFullSync);
|
||||
return result;
|
||||
}
|
||||
|
||||
int insertCount = 0;
|
||||
int updateCount = 0;
|
||||
Date now = new Date();
|
||||
|
||||
// 1. 批量转换所有数据
|
||||
List<MesExCoil> allEntities = new ArrayList<>(apiRows.size());
|
||||
for (Map<String, Object> row : apiRows) {
|
||||
MesExCoil entity = mapRowToEntity(row);
|
||||
entity.setSyncTime(now);
|
||||
allEntities.add(entity);
|
||||
}
|
||||
|
||||
// // 2. 收集所有 excoilid
|
||||
// List<String> excoilids = allEntities.stream()
|
||||
// .map(MesExCoil::getExcoilid)
|
||||
// .filter(StringUtils::isNotBlank)
|
||||
// .distinct()
|
||||
// .collect(java.util.stream.Collectors.toList());
|
||||
|
||||
// // 3. 批量查询已存在的记录
|
||||
// Map<String, MesExCoil> existingMap = new HashMap<>();
|
||||
// if (!excoilids.isEmpty()) {
|
||||
// LambdaQueryWrapper<MesExCoil> wrapper = Wrappers.lambdaQuery();
|
||||
// wrapper.in(MesExCoil::getExcoilid, excoilids);
|
||||
// List<MesExCoil> existingList = baseMapper.selectList(wrapper);
|
||||
// existingMap = existingList.stream()
|
||||
// .collect(java.util.stream.Collectors.toMap(MesExCoil::getExcoilid, v -> v, (a, b) -> a));
|
||||
// @Override
|
||||
// public Map<String, Object> syncExCoilData() {
|
||||
// Date maxInsdate = baseMapper.getMaxInsdate();
|
||||
// boolean isFullSync = (maxInsdate == null);
|
||||
//
|
||||
// List<Map<String, Object>> apiRows;
|
||||
// if (isFullSync) {
|
||||
// apiRows = fetchAllFromApi();
|
||||
// } else {
|
||||
// apiRows = fetchIncrementalFromApi(maxInsdate);
|
||||
// }
|
||||
|
||||
// 4. 分离新增和更新的记录
|
||||
List<MesExCoil> toInsert = new ArrayList<>();
|
||||
// List<MesExCoil> toUpdate = new ArrayList<>();
|
||||
|
||||
for (MesExCoil entity : allEntities) {
|
||||
// MesExCoil existing = existingMap.get(entity.getExcoilid());
|
||||
// if (existing != null) {
|
||||
// // 更新:设置主键
|
||||
// entity.setExId(existing.getExId());
|
||||
// toUpdate.add(entity);
|
||||
// } else {
|
||||
// 新增
|
||||
toInsert.add(entity);
|
||||
// }
|
||||
}
|
||||
|
||||
// 5. 批量插入
|
||||
if (!toInsert.isEmpty()) {
|
||||
// 分批插入,每批500条
|
||||
int batchSize = 500;
|
||||
for (int i = 0; i < toInsert.size(); i += batchSize) {
|
||||
int end = Math.min(i + batchSize, toInsert.size());
|
||||
List<MesExCoil> batch = toInsert.subList(i, end);
|
||||
baseMapper.insertBatch(batch);
|
||||
}
|
||||
insertCount = toInsert.size();
|
||||
}
|
||||
|
||||
// // 6. 批量更新
|
||||
// if (!toUpdate.isEmpty()) {
|
||||
// // 分批更新,每批500条
|
||||
//
|
||||
// if (apiRows == null || apiRows.isEmpty()) {
|
||||
// Map<String, Object> result = new HashMap<>();
|
||||
// result.put("totalFetched", 0);
|
||||
// result.put("insertCount", 0);
|
||||
// result.put("updateCount", 0);
|
||||
// result.put("fullSync", isFullSync);
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// int insertCount = 0;
|
||||
// int updateCount = 0;
|
||||
// Date now = new Date();
|
||||
//
|
||||
// // 1. 批量转换所有数据
|
||||
// List<MesExCoil> allEntities = new ArrayList<>(apiRows.size());
|
||||
// for (Map<String, Object> row : apiRows) {
|
||||
// MesExCoil entity = mapRowToEntity(row);
|
||||
// entity.setSyncTime(now);
|
||||
// allEntities.add(entity);
|
||||
// }
|
||||
//
|
||||
//// // 2. 收集所有 excoilid
|
||||
//// List<String> excoilids = allEntities.stream()
|
||||
//// .map(MesExCoil::getExcoilid)
|
||||
//// .filter(StringUtils::isNotBlank)
|
||||
//// .distinct()
|
||||
//// .collect(java.util.stream.Collectors.toList());
|
||||
//
|
||||
//// // 3. 批量查询已存在的记录
|
||||
//// Map<String, MesExCoil> existingMap = new HashMap<>();
|
||||
//// if (!excoilids.isEmpty()) {
|
||||
//// LambdaQueryWrapper<MesExCoil> wrapper = Wrappers.lambdaQuery();
|
||||
//// wrapper.in(MesExCoil::getExcoilid, excoilids);
|
||||
//// List<MesExCoil> existingList = baseMapper.selectList(wrapper);
|
||||
//// existingMap = existingList.stream()
|
||||
//// .collect(java.util.stream.Collectors.toMap(MesExCoil::getExcoilid, v -> v, (a, b) -> a));
|
||||
//// }
|
||||
//
|
||||
// // 4. 分离新增和更新的记录
|
||||
// List<MesExCoil> toInsert = new ArrayList<>();
|
||||
//// List<MesExCoil> toUpdate = new ArrayList<>();
|
||||
//
|
||||
// for (MesExCoil entity : allEntities) {
|
||||
//// MesExCoil existing = existingMap.get(entity.getExcoilid());
|
||||
//// if (existing != null) {
|
||||
//// // 更新:设置主键
|
||||
//// entity.setExId(existing.getExId());
|
||||
//// toUpdate.add(entity);
|
||||
//// } else {
|
||||
// // 新增
|
||||
// toInsert.add(entity);
|
||||
//// }
|
||||
// }
|
||||
//
|
||||
// // 5. 批量插入
|
||||
// if (!toInsert.isEmpty()) {
|
||||
// // 分批插入,每批500条
|
||||
// int batchSize = 500;
|
||||
// for (int i = 0; i < toUpdate.size(); i += batchSize) {
|
||||
// int end = Math.min(i + batchSize, toUpdate.size());
|
||||
// List<MesExCoil> batch = toUpdate.subList(i, end);
|
||||
// baseMapper.updateBatchById(batch, batch.size());
|
||||
// for (int i = 0; i < toInsert.size(); i += batchSize) {
|
||||
// int end = Math.min(i + batchSize, toInsert.size());
|
||||
// List<MesExCoil> batch = toInsert.subList(i, end);
|
||||
// baseMapper.insertBatch(batch);
|
||||
// }
|
||||
// updateCount = toUpdate.size();
|
||||
// insertCount = toInsert.size();
|
||||
// }
|
||||
//
|
||||
//// // 6. 批量更新
|
||||
//// if (!toUpdate.isEmpty()) {
|
||||
//// // 分批更新,每批500条
|
||||
//// int batchSize = 500;
|
||||
//// for (int i = 0; i < toUpdate.size(); i += batchSize) {
|
||||
//// int end = Math.min(i + batchSize, toUpdate.size());
|
||||
//// List<MesExCoil> batch = toUpdate.subList(i, end);
|
||||
//// baseMapper.updateBatchById(batch, batch.size());
|
||||
//// }
|
||||
//// updateCount = toUpdate.size();
|
||||
//// }
|
||||
//
|
||||
// Map<String, Object> result = new HashMap<>();
|
||||
// result.put("totalFetched", apiRows.size());
|
||||
// result.put("insertCount", insertCount);
|
||||
// result.put("updateCount", updateCount);
|
||||
// result.put("fullSync", isFullSync);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("totalFetched", apiRows.size());
|
||||
result.put("insertCount", insertCount);
|
||||
result.put("updateCount", updateCount);
|
||||
result.put("fullSync", isFullSync);
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> fetchAllFromApi() {
|
||||
List<Map<String, Object>> all = new ArrayList<>();
|
||||
int page = 1;
|
||||
int pageSize = 500;
|
||||
String baseUrl = getInternalApiBaseUrl();
|
||||
|
||||
while (true) {
|
||||
String url = baseUrl + "/sql-server-api/excoil?page=" + page + "&pageSize=" + pageSize;
|
||||
Map<String, Object> response = getRestTemplate().getForObject(url, Map.class);
|
||||
if (response == null) break;
|
||||
|
||||
Map<String, Object> data = (Map<String, Object>) response.get("data");
|
||||
if (data == null) break;
|
||||
|
||||
List<Map<String, Object>> rows = (List<Map<String, Object>>) data.get("rows");
|
||||
if (rows == null || rows.isEmpty()) break;
|
||||
|
||||
all.addAll(rows);
|
||||
if (rows.size() < pageSize) break;
|
||||
page++;
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> fetchIncrementalFromApi(Date since) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String startTime = sdf.format(since);
|
||||
String baseUrl = getInternalApiBaseUrl();
|
||||
String url = baseUrl + "/sql-server-api/excoil/by-insdate?startTime=" + startTime;
|
||||
|
||||
Map<String, Object> response = getRestTemplate().getForObject(url, Map.class);
|
||||
if (response != null && response.get("data") instanceof List) {
|
||||
return (List<Map<String, Object>>) response.get("data");
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private MesExCoil mapRowToEntity(Map<String, Object> row) {
|
||||
MesExCoil entity = new MesExCoil();
|
||||
entity.setExcoilid(str(row.get("excoilid")));
|
||||
entity.setEncoilid(str(row.get("encoilid")));
|
||||
entity.setHotCoilid(str(row.get("hot_coilid")));
|
||||
entity.setGrade(str(row.get("grade")));
|
||||
entity.setOrderQuality(str(row.get("order_quality")));
|
||||
entity.setProductType(str(row.get("product_type")));
|
||||
entity.setStatus(str(row.get("status")));
|
||||
entity.setShift(str(row.get("shift")));
|
||||
entity.setParkType(str(row.get("park_type")));
|
||||
entity.setSideTrim(str(row.get("side_trim")));
|
||||
entity.setEntryThick(bd(row.get("entry_thick")));
|
||||
entity.setEntryWidth(bd(row.get("entry_width")));
|
||||
entity.setEntryWeight(bd(row.get("entry_weight")));
|
||||
entity.setUsedEntryWeight(bd(row.get("used_entry_weight")));
|
||||
entity.setExitThick(bd(row.get("exit_thick")));
|
||||
entity.setExitWidth(bd(row.get("exit_width")));
|
||||
entity.setExitLength(bd(row.get("exit_length")));
|
||||
entity.setExitWeight(bd(row.get("exit_weight")));
|
||||
entity.setCalcExitWeight(bd(row.get("calc_exit_weight")));
|
||||
entity.setMeasExitWeight(bd(row.get("meas_exit_weight")));
|
||||
entity.setExitPosDev(bd(row.get("exit_pos_dev")));
|
||||
entity.setExitNegDev(bd(row.get("exit_neg_dev")));
|
||||
entity.setInnerDiameter(bd(row.get("inner_diameter")));
|
||||
entity.setOuterDiameter(bd(row.get("outer_diameter")));
|
||||
entity.setHeadpos(bd(row.get("headpos")));
|
||||
entity.setTailpos(bd(row.get("tailpos")));
|
||||
entity.setQuality(bd(row.get("quality")));
|
||||
entity.setShapeQuality(bd(row.get("shape_quality")));
|
||||
entity.setCrew(str(row.get("crew")));
|
||||
entity.setReportFlag(longVal(row.get("report_flag")));
|
||||
entity.setSubid(longVal(row.get("subid")));
|
||||
entity.setRn(longVal(row.get("rn")));
|
||||
entity.setOnlineDate(parseDate(row.get("online_date")));
|
||||
entity.setStartDate(parseDate(row.get("start_date")));
|
||||
entity.setEndDate(parseDate(row.get("end_date")));
|
||||
entity.setWeldedDate(parseDate(row.get("welded_date")));
|
||||
entity.setInsdate(parseDate(row.get("insdate")));
|
||||
entity.setComments(str(row.get("comments")));
|
||||
entity.setRemark(str(row.get("remark")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String str(Object value) {
|
||||
return value == null ? null : String.valueOf(value);
|
||||
}
|
||||
|
||||
private BigDecimal bd(Object value) {
|
||||
if (value == null) return null;
|
||||
if (value instanceof BigDecimal) return (BigDecimal) value;
|
||||
if (value instanceof Number) return BigDecimal.valueOf(((Number) value).doubleValue());
|
||||
try { return new BigDecimal(String.valueOf(value)); } catch (Exception e) { return null; }
|
||||
}
|
||||
|
||||
private Long longVal(Object value) {
|
||||
if (value == null) return null;
|
||||
if (value instanceof Number) return ((Number) value).longValue();
|
||||
try { return Long.parseLong(String.valueOf(value)); } catch (Exception e) { return null; }
|
||||
}
|
||||
|
||||
private Date parseDate(Object value) {
|
||||
if (value == null) return null;
|
||||
if (value instanceof Date) return (Date) value;
|
||||
String s = String.valueOf(value);
|
||||
if (s.isEmpty() || "null".equals(s)) return null;
|
||||
try {
|
||||
if (s.contains("T")) {
|
||||
s = s.replace("T", " ");
|
||||
if (s.length() > 19) s = s.substring(0, 19);
|
||||
}
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(s);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// @SuppressWarnings("unchecked")
|
||||
// private List<Map<String, Object>> fetchAllFromApi() {
|
||||
// List<Map<String, Object>> all = new ArrayList<>();
|
||||
// int page = 1;
|
||||
// int pageSize = 500;
|
||||
// String baseUrl = getInternalApiBaseUrl();
|
||||
//
|
||||
// while (true) {
|
||||
// String url = baseUrl + "/sql-server-api/excoil?page=" + page + "&pageSize=" + pageSize;
|
||||
// Map<String, Object> response = getRestTemplate().getForObject(url, Map.class);
|
||||
// if (response == null) break;
|
||||
//
|
||||
// Map<String, Object> data = (Map<String, Object>) response.get("data");
|
||||
// if (data == null) break;
|
||||
//
|
||||
// List<Map<String, Object>> rows = (List<Map<String, Object>>) data.get("rows");
|
||||
// if (rows == null || rows.isEmpty()) break;
|
||||
//
|
||||
// all.addAll(rows);
|
||||
// if (rows.size() < pageSize) break;
|
||||
// page++;
|
||||
// }
|
||||
// return all;
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// private List<Map<String, Object>> fetchIncrementalFromApi(Date since) {
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// String startTime = sdf.format(since);
|
||||
// String baseUrl = getInternalApiBaseUrl();
|
||||
// String url = baseUrl + "/sql-server-api/excoil/by-insdate?startTime=" + startTime;
|
||||
//
|
||||
// Map<String, Object> response = getRestTemplate().getForObject(url, Map.class);
|
||||
// if (response != null && response.get("data") instanceof List) {
|
||||
// return (List<Map<String, Object>>) response.get("data");
|
||||
// }
|
||||
// return new ArrayList<>();
|
||||
// }
|
||||
//
|
||||
// private MesExCoil mapRowToEntity(Map<String, Object> row) {
|
||||
// MesExCoil entity = new MesExCoil();
|
||||
// entity.setExcoilid(str(row.get("excoilid")));
|
||||
// entity.setEncoilid(str(row.get("encoilid")));
|
||||
// entity.setHotCoilid(str(row.get("hot_coilid")));
|
||||
// entity.setGrade(str(row.get("grade")));
|
||||
// entity.setOrderQuality(str(row.get("order_quality")));
|
||||
// entity.setProductType(str(row.get("product_type")));
|
||||
// entity.setStatus(str(row.get("status")));
|
||||
// entity.setShift(str(row.get("shift")));
|
||||
// entity.setParkType(str(row.get("park_type")));
|
||||
// entity.setSideTrim(str(row.get("side_trim")));
|
||||
// entity.setEntryThick(bd(row.get("entry_thick")));
|
||||
// entity.setEntryWidth(bd(row.get("entry_width")));
|
||||
// entity.setEntryWeight(bd(row.get("entry_weight")));
|
||||
// entity.setUsedEntryWeight(bd(row.get("used_entry_weight")));
|
||||
// entity.setExitThick(bd(row.get("exit_thick")));
|
||||
// entity.setExitWidth(bd(row.get("exit_width")));
|
||||
// entity.setExitLength(bd(row.get("exit_length")));
|
||||
// entity.setExitWeight(bd(row.get("exit_weight")));
|
||||
// entity.setCalcExitWeight(bd(row.get("calc_exit_weight")));
|
||||
// entity.setMeasExitWeight(bd(row.get("meas_exit_weight")));
|
||||
// entity.setExitPosDev(bd(row.get("exit_pos_dev")));
|
||||
// entity.setExitNegDev(bd(row.get("exit_neg_dev")));
|
||||
// entity.setInnerDiameter(bd(row.get("inner_diameter")));
|
||||
// entity.setOuterDiameter(bd(row.get("outer_diameter")));
|
||||
// entity.setHeadpos(bd(row.get("headpos")));
|
||||
// entity.setTailpos(bd(row.get("tailpos")));
|
||||
// entity.setQuality(bd(row.get("quality")));
|
||||
// entity.setShapeQuality(bd(row.get("shape_quality")));
|
||||
// entity.setCrew(str(row.get("crew")));
|
||||
// entity.setReportFlag(longVal(row.get("report_flag")));
|
||||
// entity.setSubid(longVal(row.get("subid")));
|
||||
// entity.setRn(longVal(row.get("rn")));
|
||||
// entity.setOnlineDate(parseDate(row.get("online_date")));
|
||||
// entity.setStartDate(parseDate(row.get("start_date")));
|
||||
// entity.setEndDate(parseDate(row.get("end_date")));
|
||||
// entity.setWeldedDate(parseDate(row.get("welded_date")));
|
||||
// entity.setInsdate(parseDate(row.get("insdate")));
|
||||
// entity.setComments(str(row.get("comments")));
|
||||
// entity.setRemark(str(row.get("remark")));
|
||||
// return entity;
|
||||
// }
|
||||
//
|
||||
// private String str(Object value) {
|
||||
// return value == null ? null : String.valueOf(value);
|
||||
// }
|
||||
//
|
||||
// private BigDecimal bd(Object value) {
|
||||
// if (value == null) return null;
|
||||
// if (value instanceof BigDecimal) return (BigDecimal) value;
|
||||
// if (value instanceof Number) return BigDecimal.valueOf(((Number) value).doubleValue());
|
||||
// try { return new BigDecimal(String.valueOf(value)); } catch (Exception e) { return null; }
|
||||
// }
|
||||
//
|
||||
// private Long longVal(Object value) {
|
||||
// if (value == null) return null;
|
||||
// if (value instanceof Number) return ((Number) value).longValue();
|
||||
// try { return Long.parseLong(String.valueOf(value)); } catch (Exception e) { return null; }
|
||||
// }
|
||||
//
|
||||
// private Date parseDate(Object value) {
|
||||
// if (value == null) return null;
|
||||
// if (value instanceof Date) return (Date) value;
|
||||
// String s = String.valueOf(value);
|
||||
// if (s.isEmpty() || "null".equals(s)) return null;
|
||||
// try {
|
||||
// if (s.contains("T")) {
|
||||
// s = s.replace("T", " ");
|
||||
// if (s.length() > 19) s = s.substring(0, 19);
|
||||
// }
|
||||
// return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(s);
|
||||
// } catch (Exception e) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user