update 查改接口独立线程执行

master
yinq 2 months ago
parent 07ca306fd5
commit dd6c574de4

@ -7,8 +7,8 @@ spring:
# 主库数据源
master:
url: jdbc:mysql://1.13.177.47:3306/hw_tag_api?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: haiwei@123
username: hw_tag_user
password: hwPassword123
# 从库数据源
slave:
# 从数据源开关/默认关闭

@ -118,7 +118,8 @@ public class ApiConstants {
*/
public static final String IMPORT_TEMPLATE_ONE = "1";//导出再导入模板
public static final String IMPORT_TEMPLATE_TWO = "2";//桌面读写器盘点模板
public static final String IMPORT_TEMPLATE_THREE = "3";//标签模板
public static final String IMPORT_TEMPLATE_THREE = "3";//标签模板、少一行模板
public static final String IMPORT_TEMPLATE_FOUR = "4";//写码机写读盘点模板
public static final String IMPORT_TEMPLATE_FIVE = "5";//无头模板
}

@ -65,6 +65,11 @@ public class ImportParams {
*/
private String intendedUse;
/**
*
*/
private String tagBatch;
/**
*
*

@ -215,13 +215,33 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService {
HwTagRecord record = new HwTagRecord();
// 设置订单信息
String lot = orderInfo.getOrDefault("orderNo", "").replace("Lot", "");
record.setOrderCode(lot);
record.setBatchNumber(orderInfo.getOrDefault("batchNo", ""));
String lot = orderInfo.getOrDefault("orderNo", "").replaceAll("Lot-?", "");
// 新模板订单号Lot20250207-001
if (lot.contains("-")) {
String[] parts = lot.split("-");
String orderCode = parts[0];
String batchNumber = parts[1];
record.setOrderCode(orderCode);
record.setBatchNumber(batchNumber);
record.setTagBatch(orderInfo.getOrDefault("batchNo", ""));
} else {
record.setOrderCode(lot);
record.setBatchNumber(orderInfo.getOrDefault("batchNo", ""));
}
if (StringUtils.hasText(params.getTagBatch())) {
record.setTagBatch(params.getTagBatch());
}
record.setOperatorId(orderInfo.getOrDefault("operatorId", ""));
Date processTime = orderInfo.containsKey("processTime") && !orderInfo.get("processTime").isEmpty() ?
sdf.parse(orderInfo.get("processTime")) : nowDate;
record.setProcessingTime(processTime);
Date testingTime = tagData.containsKey("测试时间") ? sdf.parse(tagData.get("测试时间")) : nowDate;
if (tagData.containsKey("测试时间")) {
record.setProcessingTime(testingTime);
} else {
record.setProcessingTime(processTime);
}
record.setTotalQuantity(Long.valueOf(orderInfo.getOrDefault("totalCount", "0")));
// 设置标签数据
@ -233,8 +253,6 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService {
record.setTestResult(tagData.get("测试结果"));
record.setTestValue(tagData.get("测试值"));
record.setReferenceValue(tagData.get("参考值"));
Date testingTime = tagData.containsKey("测试时间") ?
sdf.parse(tagData.get("测试时间")) : nowDate;
record.setTestingTime(testingTime);
record.setFileName(params.getFileName());
record.setDestinationInfo(params.getDestinationInfo());
@ -302,6 +320,22 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService {
// 转换Excel数据为HwTagRecord列表
tagRecordList = convertExcelDataToTagRecords(orderInfo, tagList, params);
}
if (templateType.equals(ApiConstants.IMPORT_TEMPLATE_FIVE)) {
// 获取订单信息和标签数据
Map<String, String> orderInfo = new HashMap<>();
String fileName = params.getFileName().replace(".xlx", "").replace(".xlsx", "");
String lotAndNo = fileName.replaceAll("Lot-?", "");
String[] parts = lotAndNo.split("-");
String orderCode = parts[0];
String batchNumber = parts[1];
orderInfo.put("orderNo", orderCode);
orderInfo.put("batchNo", batchNumber);
List<Map<String, String>> tagList = (List<Map<String, String>>) excelResult.get("tagList");
// 转换Excel数据为HwTagRecord列表
tagRecordList = convertExcelDataToTagRecords(orderInfo, tagList, params);
}
// 检查TID是否存在
if (tagRecordList.stream().anyMatch(tag -> !StringUtils.hasText(tag.getTId()))) {
throw new IllegalArgumentException("解析excel错误存在缺少TID的数据");

@ -407,183 +407,206 @@ public class KDocsServiceImpl implements IKDocsService {
log.warn("查改条件列表为空");
return result;
}
log.info("开始处理查改请求,查改条件数量: {}", content.size());
for (ApiContent query : content) {
String queryId = query.getId();
log.info("处理查改条件 ID: {}, 查改参数: {}", queryId, query.getFields());
for (ApiContent condition : content) {
ApiContent response = new ApiContent();
response.setId(queryId);
response.setFields(new HashMap<>());
Map<String, Object> fields = query.getFields();
HwTagRecord selectTagRecord = new HwTagRecord();
// 处理查询结果
int successCount = 0;
int failCount = 0;
List<String> errorMessages = new ArrayList<>();
response.setId(condition.getId());
Map<String, Object> fields = condition.getFields();
Map<String, Object> responseFields = new HashMap<>();
String limitNumber = String.valueOf(fields.getOrDefault("查改数限制", ""));
if (limitNumber == null || limitNumber.isEmpty()) {
responseFields.put(ApiConstants.CHECK_STATUS, "查改失败");
responseFields.put(ApiConstants.DESCRIPTION, "查改数限制不能为空");
} else {
responseFields.put(ApiConstants.CHECK_STATUS, "查改中");
responseFields.put(ApiConstants.DESCRIPTION, "预计需要3分钟");
}
response.setFields(responseFields);
result.add(response);
String limitNumber = String.valueOf(fields.getOrDefault("查改数限制", ""));
// 获取更新字段
String upPassword = String.valueOf(fields.getOrDefault("改-密码", ""));
String upOrderCode = String.valueOf(fields.getOrDefault("改-LOT", ""));
String upTagBatch = String.valueOf(fields.getOrDefault("改-标签批次号", ""));
String upModelCode = String.valueOf(fields.getOrDefault("改-型号", ""));
String upDestinationInfo = String.valueOf(fields.getOrDefault("改-去向信息", ""));
String upLibraryFlag = String.valueOf(fields.getOrDefault("改-是否在库", ""));
String upIntendedUse = String.valueOf(fields.getOrDefault("改-计划用途", ""));
String upRemark = String.valueOf(fields.getOrDefault("改-备注", ""));
String upBatchNumber = String.valueOf(fields.getOrDefault("改-卷编号", ""));
// 设置查询条件
if (fields.containsKey("TID")) {
String tid = (String) fields.get("TID");
selectTagRecord.setSelectTID(tid);
}
if (fields.containsKey("EPC")) {
String epc = (String) fields.get("EPC");
selectTagRecord.setSelectEPC(epc);
}
if (fields.containsKey("密码")) {
String password = (String) fields.get("密码");
selectTagRecord.setPassword(password);
}
if (fields.containsKey("LOT")) {
String orderCode = (String) fields.get("LOT");
selectTagRecord.setOrderCode(orderCode);
}
if (fields.containsKey("标签批次号")) {
String tagBatch = (String) fields.get("标签批次号");
selectTagRecord.setTagBatch(tagBatch);
}
if (fields.containsKey("型号")) {
String modelCode = (String) fields.get("型号");
selectTagRecord.setModelCode(modelCode);
}
if (fields.containsKey("筛选日期起点")) {
String startDate = (String) fields.get("筛选日期起点");
selectTagRecord.setStartDate(startDate);
}
if (fields.containsKey("筛选日期终点")) {
String endDate = (String) fields.get("筛选日期终点");
selectTagRecord.setEndDate(endDate);
}
if (fields.containsKey("去向信息")) {
String destinationInfo = (String) fields.get("去向信息");
selectTagRecord.setDestinationInfo(destinationInfo);
}
if (fields.containsKey("是否在库")) {
String libraryFlag = (String) fields.get("是否在库");
selectTagRecord.setLibraryFlag(libraryFlag);
}
if (fields.containsKey("计划用途")) {
String intendedUse = (String) fields.get("计划用途");
selectTagRecord.setIntendedUse(intendedUse);
}
if (fields.containsKey("备注")) {
String remark = (String) fields.get("备注");
selectTagRecord.setRemark(remark);
}
if (fields.containsKey("卷编号")) {
String batchNumber = (String) fields.get("卷编号");
if (StringUtils.hasText(batchNumber) && !batchNumber.contains("-")) {
selectTagRecord.setBatchNumber(batchNumber);
log.info("设置查询条件 - 卷编号: {}", batchNumber);
} else if (StringUtils.hasText(batchNumber) && batchNumber.contains("-")) {
List<String> batchNumberList = TagExcelUtil.splitHorizontalBarString(batchNumber, false);
selectTagRecord.setBatchNumberList(batchNumberList);
log.info("设置查询条件 - 卷编号范围: {}", batchNumberList);
}
}
if (fields.containsKey("标签序号")) {
String tagSequence = (String) fields.get("标签序号");
if (StringUtils.hasText(tagSequence) && !tagSequence.contains("-")) {
selectTagRecord.setTagSequence(tagSequence);
log.info("设置查询条件 - 标签序号: {}", tagSequence);
} else if (StringUtils.hasText(tagSequence) && tagSequence.contains("-")) {
List<String> tagSequenceList = TagExcelUtil.splitHorizontalBarString(tagSequence, true);
selectTagRecord.setTagSequenceList(tagSequenceList);
log.info("设置查询条件 - 标签序号范围: {}", tagSequenceList);
}
}
// 执行查询
log.info("执行查改数据库查询 - ID: {}", queryId);
long startTime = System.currentTimeMillis();
List<HwTagRecord> tagRecordList = tagRecordService.selectHwTagRecordList(selectTagRecord);
int tagRecordListSize = tagRecordList.size();
long endTime = System.currentTimeMillis();
log.info("数据库查询完成 - ID: {}, 耗时: {}ms, 查询到记录数: {}", queryId, (endTime - startTime), tagRecordListSize);
try {
TagExcelUtil.validateRecordLimit(limitNumber, tagRecordListSize);
} catch (Exception e) {
responseFields.put(ApiConstants.CHECK_STATUS, "查改失败");
responseFields.put(ApiConstants.DESCRIPTION, e.getMessage());
responseFields.put("查改记录数", tagRecordListSize);
return result;
}
for (HwTagRecord tagRecord : tagRecordList) {
try {
if (StringUtils.hasText(upPassword)) {
tagRecord.setPassword(upPassword);
}
if (StringUtils.hasText(upOrderCode)) {
tagRecord.setOrderCode(upOrderCode);
}
if (StringUtils.hasText(upBatchNumber)) {
tagRecord.setBatchNumber(upBatchNumber);
}
if (StringUtils.hasText(upTagBatch)) {
tagRecord.setTagBatch(upTagBatch);
}
if (StringUtils.hasText(upModelCode)) {
tagRecord.setModelCode(upModelCode);
}
if (StringUtils.hasText(upDestinationInfo)) {
tagRecord.setDestinationInfo(upDestinationInfo);
}
if (StringUtils.hasText(upLibraryFlag)) {
tagRecord.setLibraryFlag(upLibraryFlag);
}
if (StringUtils.hasText(upIntendedUse)) {
tagRecord.setIntendedUse(upIntendedUse);
}
if (StringUtils.hasText(upRemark)) {
tagRecord.setRemark(upRemark);
}
if (StringUtils.hasText(upBatchNumber)) {
tagRecord.setBatchNumber(upBatchNumber);
}
tagRecordService.updateHwTagRecordByTID(tagRecord);
successCount++;
log.info("更新成功 - TID: {}", tagRecord.getTId());
} catch (Exception e) {
failCount++;
String errorMsg = String.format("更新失败 - TID: %s, 错误: %s", tagRecord.getTId(), e.getMessage());
errorMessages.add(errorMsg);
log.error(errorMsg, e);
}
}
// 设置响应结果
if (!errorMessages.isEmpty()) {
responseFields.put(ApiConstants.CHECK_STATUS, "查改失败");
responseFields.put(ApiConstants.DESCRIPTION, errorMessages);
responseFields.put("查改记录数", tagRecordListSize);
} else {
responseFields.put(ApiConstants.CHECK_STATUS, "查改成功");
responseFields.put(ApiConstants.DESCRIPTION, "");
responseFields.put("查改记录数", tagRecordListSize);
}
log.info("查改处理完成 - ID: {}, 成功: {}, 失败: {}", queryId, successCount, failCount);
}
// 异步执行导出任务
executorService.execute(() -> {
List<ApiContent> resApiContentList = new ArrayList<>();
for (ApiContent query : content) {
String queryId = query.getId();
log.info("处理查改条件 ID: {}, 查改参数: {}", queryId, query.getFields());
ApiContent response = new ApiContent();
response.setId(queryId);
response.setFields(new HashMap<>());
Map<String, Object> fields = query.getFields();
HwTagRecord selectTagRecord = new HwTagRecord();
// 处理查询结果
int successCount = 0;
int failCount = 0;
List<String> errorMessages = new ArrayList<>();
Map<String, Object> responseFields = new HashMap<>();
response.setFields(responseFields);
resApiContentList.add(response);
String limitNumber = String.valueOf(fields.getOrDefault("查改数限制", ""));
// 获取更新字段
String upPassword = String.valueOf(fields.getOrDefault("改-密码", ""));
String upOrderCode = String.valueOf(fields.getOrDefault("改-LOT", ""));
String upTagBatch = String.valueOf(fields.getOrDefault("改-标签批次号", ""));
String upModelCode = String.valueOf(fields.getOrDefault("改-型号", ""));
String upDestinationInfo = String.valueOf(fields.getOrDefault("改-去向信息", ""));
String upLibraryFlag = String.valueOf(fields.getOrDefault("改-是否在库", ""));
String upIntendedUse = String.valueOf(fields.getOrDefault("改-计划用途", ""));
String upRemark = String.valueOf(fields.getOrDefault("改-备注", ""));
String upBatchNumber = String.valueOf(fields.getOrDefault("改-卷编号", ""));
// 设置查询条件
if (fields.containsKey("TID")) {
String tid = (String) fields.get("TID");
selectTagRecord.setSelectTID(tid);
}
if (fields.containsKey("EPC")) {
String epc = (String) fields.get("EPC");
selectTagRecord.setSelectEPC(epc);
}
if (fields.containsKey("密码")) {
String password = (String) fields.get("密码");
selectTagRecord.setPassword(password);
}
if (fields.containsKey("LOT")) {
String orderCode = (String) fields.get("LOT");
selectTagRecord.setOrderCode(orderCode);
}
if (fields.containsKey("标签批次号")) {
String tagBatch = (String) fields.get("标签批次号");
selectTagRecord.setTagBatch(tagBatch);
}
if (fields.containsKey("型号")) {
String modelCode = (String) fields.get("型号");
selectTagRecord.setModelCode(modelCode);
}
if (fields.containsKey("筛选日期起点")) {
String startDate = (String) fields.get("筛选日期起点");
selectTagRecord.setStartDate(startDate);
}
if (fields.containsKey("筛选日期终点")) {
String endDate = (String) fields.get("筛选日期终点");
selectTagRecord.setEndDate(endDate);
}
if (fields.containsKey("去向信息")) {
String destinationInfo = (String) fields.get("去向信息");
selectTagRecord.setDestinationInfo(destinationInfo);
}
if (fields.containsKey("是否在库")) {
String libraryFlag = (String) fields.get("是否在库");
selectTagRecord.setLibraryFlag(libraryFlag);
}
if (fields.containsKey("计划用途")) {
String intendedUse = (String) fields.get("计划用途");
selectTagRecord.setIntendedUse(intendedUse);
}
if (fields.containsKey("备注")) {
String remark = (String) fields.get("备注");
selectTagRecord.setRemark(remark);
}
if (fields.containsKey("卷编号")) {
String batchNumber = (String) fields.get("卷编号");
if (StringUtils.hasText(batchNumber) && !batchNumber.contains("-")) {
selectTagRecord.setBatchNumber(batchNumber);
log.info("设置查询条件 - 卷编号: {}", batchNumber);
} else if (StringUtils.hasText(batchNumber) && batchNumber.contains("-")) {
List<String> batchNumberList = TagExcelUtil.splitHorizontalBarString(batchNumber, false);
selectTagRecord.setBatchNumberList(batchNumberList);
log.info("设置查询条件 - 卷编号范围: {}", batchNumberList);
}
}
if (fields.containsKey("标签序号")) {
String tagSequence = (String) fields.get("标签序号");
if (StringUtils.hasText(tagSequence) && !tagSequence.contains("-")) {
selectTagRecord.setTagSequence(tagSequence);
log.info("设置查询条件 - 标签序号: {}", tagSequence);
} else if (StringUtils.hasText(tagSequence) && tagSequence.contains("-")) {
List<String> tagSequenceList = TagExcelUtil.splitHorizontalBarString(tagSequence, true);
selectTagRecord.setTagSequenceList(tagSequenceList);
log.info("设置查询条件 - 标签序号范围: {}", tagSequenceList);
}
}
// 执行查询
log.info("执行查改数据库查询 - ID: {}", queryId);
long startTime = System.currentTimeMillis();
List<HwTagRecord> tagRecordList = tagRecordService.selectHwTagRecordList(selectTagRecord);
int tagRecordListSize = tagRecordList.size();
long endTime = System.currentTimeMillis();
log.info("数据库查询完成 - ID: {}, 耗时: {}ms, 查询到记录数: {}", queryId, (endTime - startTime), tagRecordListSize);
try {
TagExcelUtil.validateRecordLimit(limitNumber, tagRecordListSize);
} catch (Exception e) {
responseFields.put(ApiConstants.CHECK_STATUS, "查改失败");
responseFields.put(ApiConstants.DESCRIPTION, e.getMessage());
responseFields.put("查改记录数", tagRecordListSize);
continue;
}
for (HwTagRecord tagRecord : tagRecordList) {
try {
if (StringUtils.hasText(upPassword)) {
tagRecord.setPassword(upPassword);
}
if (StringUtils.hasText(upOrderCode)) {
tagRecord.setOrderCode(upOrderCode);
}
if (StringUtils.hasText(upBatchNumber)) {
tagRecord.setBatchNumber(upBatchNumber);
}
if (StringUtils.hasText(upTagBatch)) {
tagRecord.setTagBatch(upTagBatch);
}
if (StringUtils.hasText(upModelCode)) {
tagRecord.setModelCode(upModelCode);
}
if (StringUtils.hasText(upDestinationInfo)) {
tagRecord.setDestinationInfo(upDestinationInfo);
}
if (StringUtils.hasText(upLibraryFlag)) {
tagRecord.setLibraryFlag(upLibraryFlag);
}
if (StringUtils.hasText(upIntendedUse)) {
tagRecord.setIntendedUse(upIntendedUse);
}
if (StringUtils.hasText(upRemark)) {
tagRecord.setRemark(upRemark);
}
if (StringUtils.hasText(upBatchNumber)) {
tagRecord.setBatchNumber(upBatchNumber);
}
tagRecordService.updateHwTagRecordByTID(tagRecord);
successCount++;
log.info("更新成功 - TID: {}", tagRecord.getTId());
} catch (Exception e) {
failCount++;
String errorMsg = String.format("更新失败 - TID: %s, 错误: %s", tagRecord.getTId(), e.getMessage());
errorMessages.add(errorMsg);
log.error(errorMsg, e);
}
}
// 设置响应结果
if (!errorMessages.isEmpty()) {
responseFields.put(ApiConstants.CHECK_STATUS, "查改失败");
responseFields.put(ApiConstants.DESCRIPTION, errorMessages);
responseFields.put("查改记录数", tagRecordListSize);
} else {
responseFields.put(ApiConstants.CHECK_STATUS, "查改成功");
responseFields.put(ApiConstants.DESCRIPTION, "");
responseFields.put("查改记录数", tagRecordListSize);
}
log.info("查改处理完成 - ID: {}, 成功: {}, 失败: {}", queryId, successCount, failCount);
}
// 发送处理结果到回调接口
httpClientUtils.sendResultToCallback(resApiContentList, ApiConstants.CALLBACK_URL, ApiConstants.DATA_CHECK_REVISE);
});
return result;
}

Loading…
Cancel
Save