From 9f6d1c42234c6611ac1cac53ab1586d4fb59ac0c Mon Sep 17 00:00:00 2001 From: yinq Date: Thu, 24 Apr 2025 13:14:48 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=AF=BC=E5=85=A5=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tagApi/service/constant/ApiConstants.java | 6 +- .../service/impl/KDocsServiceImpl.java | 69 ++++++++++++++----- .../hw/tagApi/service/utils/TagExcelUtil.java | 10 --- .../tagApi/service/utils/httpClientUtils.java | 4 +- 4 files changed, 57 insertions(+), 32 deletions(-) diff --git a/tagApi-service/src/main/java/hw/tagApi/service/constant/ApiConstants.java b/tagApi-service/src/main/java/hw/tagApi/service/constant/ApiConstants.java index ff97739..ebc7dbf 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/constant/ApiConstants.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/constant/ApiConstants.java @@ -13,7 +13,7 @@ public class ApiConstants { * 本机IP端口 */ // public static final String BASE_URL = "http://127.0.0.1:9000/docs/export/"; - public static final String BASE_URL = "http://1.13.177.47:9000/docs/export/"; + public static final String BASE_URL = "http://database.rfidtire.com/docs/export/"; /** * 过期时间(毫秒) 6小时 @@ -23,12 +23,12 @@ public class ApiConstants { /** * 导入回调返回请求 */ - public static final String IN_CALLBACK_URL = "https://www.kdocs.cn/chatflow/api/v2/func/webhook/2uZIRSpxLvtfaoCjRoLg4EvwIc5"; + public static final String IN_CALLBACK_URL = "https://www.kdocs.cn/chatflow/api/v2/func/webhook/2w7TqqdGMqmLwdfQY3wFidcBF4K"; /** * 导出回调返回请求 */ - public static final String OUT_CALLBACK_URL = "https://www.kdocs.cn/chatflow/api/v2/func/webhook/2uZIRSpxLvtfaoCjRoLg4EvwIc5"; + public static final String OUT_CALLBACK_URL = "https://www.kdocs.cn/chatflow/api/v2/func/webhook/2w7TqqdGMqmLwdfQY3wFidcBF4K"; /** * 数据库状态 diff --git a/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java b/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java index 0e19888..558d66b 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java @@ -5,7 +5,9 @@ import hw.tagApi.service.service.IHwTagRecordService; import hw.tagApi.service.service.IKDocsService; import hw.tagApi.service.utils.TagExcelUtil; import hw.tagApi.service.utils.httpClientUtils; + import java.time.Duration; + import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +23,7 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.ObjectMapper; import hw.tagApi.service.domain.ApiResponse; import hw.tagApi.service.domain.ApiContent; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; /** @@ -37,7 +40,6 @@ public class KDocsServiceImpl implements IKDocsService { private IHwTagRecordService tagRecordService; - private static final int BATCH_SIZE = 100; // 创建线程池 @@ -117,17 +119,20 @@ public class KDocsServiceImpl implements IKDocsService { * @param apiContent 包含导入数据的ApiContent对象 * @return 处理后的ApiContent对象 */ + @Transactional(rollbackFor = Exception.class) public ApiContent importData(ApiContent apiContent) { Map fields = apiContent.getFields(); String importMode = String.valueOf(fields.get("导入模式")); String model = String.valueOf(fields.getOrDefault("型号", "")); String fileUrl = String.valueOf(fields.get("文件链接")); + String fileName = String.valueOf(fields.getOrDefault("文件名", "")); + String TIDCheck = String.valueOf(fields.getOrDefault("TID校验", "")); + int charCount = TIDCheck.length(); List batchList = new ArrayList<>(); Map resFields = new HashMap<>(); apiContent.setFields(resFields); try { log.info("开始处理文件,URL: {}", fileUrl); - // 获取文件字节数组 byte[] fileData = httpClientUtils.getByteArrayFromUrl(fileUrl); if (fileData == null) { @@ -150,11 +155,25 @@ public class KDocsServiceImpl implements IKDocsService { Map orderInfo = (Map) excelResult.get("orderInfo"); // 获取标签数据列表 List> tagList = (List>) excelResult.get("tagList"); - // 获取文件名 - String fileName = (String) excelResult.get("fileName"); // 批量处理标签数据 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (Map tagData : tagList) { + String tid = tagData.get("TID").replace("-", ""); + String epc = tagData.get("EPC").replace("-", ""); + if (tid.length() != 24) { + String errorMsg = String.format("TID长度校验失败!预期长度:24,实际长度:%d,TID值:%s", tid.length(), tid); + log.error("TID长度校验异常 - {}", errorMsg); + resFields.put(ApiConstants.IMPORT_STATUS, "导入失败"); + resFields.put(ApiConstants.DESCRIPTION, "TID长度不符合要求:" + errorMsg); + return apiContent; + } + if (charCount > 0 && !startsWithCheck(tid, TIDCheck)) { + String errorMsg = String.format("TID校验失败!TID校验:%s,实际TID:%s", TIDCheck, tid); + log.error("TID校验异常 - {}", errorMsg); + resFields.put(ApiConstants.IMPORT_STATUS, "导入失败"); + resFields.put(ApiConstants.DESCRIPTION, "TID校验不符合要求:" + errorMsg); + return apiContent; + } HwTagRecord record = new HwTagRecord(); record.setOrderCode(orderInfo.get("orderNo")); record.setBatchNumber(orderInfo.get("batchNo")); @@ -164,8 +183,8 @@ public class KDocsServiceImpl implements IKDocsService { // 设置标签数据 record.setModelCode(model); record.setTagSequence(tagData.get("序号")); - record.setTId(tagData.get("TID")); - record.setEpc(tagData.get("EPC")); + record.setTId(tid); + record.setEpc(epc); record.setPassword(tagData.get("密码")); record.setTestResult(tagData.get("测试结果")); record.setTestValue(tagData.get("测试值")); @@ -246,13 +265,13 @@ public class KDocsServiceImpl implements IKDocsService { 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 fields = query.getFields(); HwTagRecord selectTagRecord = new HwTagRecord(); - + // 检查查询条件 if (!fields.containsKey("TID") && !fields.containsKey("EPC")) { log.warn("查询条件错误 - ID: {}, 缺少必要的查询参数(TID或EPC)", queryId); @@ -311,10 +330,10 @@ public class KDocsServiceImpl implements IKDocsService { response.getFields().put("搜索状态", "未找到记录"); if (fields.containsKey("搜索日期起点") && fields.containsKey("搜索日期终点")) { String message = String.format("已遍历整个数据库,生产日期从%s到%s,未查询到该TID。", - fields.get("搜索日期起点"), fields.get("搜索日期终点")); + fields.get("搜索日期起点"), fields.get("搜索日期终点")); response.getFields().put("情况说明", message); - log.debug("未找到记录详情 - ID: {}, 日期范围: {} - {}", - queryId, fields.get("搜索日期起点"), fields.get("搜索日期终点")); + log.debug("未找到记录详情 - ID: {}, 日期范围: {} - {}", + queryId, fields.get("搜索日期起点"), fields.get("搜索日期终点")); } else { response.getFields().put("情况说明", "未找到匹配的记录"); } @@ -328,7 +347,7 @@ public class KDocsServiceImpl implements IKDocsService { /** * 导出数据 - * + * * @param content 导出条件列表 * @return 导出结果列表 */ @@ -350,7 +369,7 @@ public class KDocsServiceImpl implements IKDocsService { response.setFields(responseFields); result.add(response); } - + // 异步执行导出任务 executorService.execute(() -> { List resApiContentList = new ArrayList<>(); @@ -399,9 +418,9 @@ public class KDocsServiceImpl implements IKDocsService { long startTime = System.currentTimeMillis(); List records = tagRecordService.selectHwTagRecordList(queryCondition); - + Map responseFields = new HashMap<>(); - + if (records != null && !records.isEmpty()) { try { String fileName = String.format("标签数据_%s.xlsx", condition.getId()); @@ -427,7 +446,7 @@ public class KDocsServiceImpl implements IKDocsService { responseFields.put("导出状态", "未找到记录"); responseFields.put("情况说明", "未找到符合条件的记录"); } - + response.setFields(responseFields); } catch (Exception e) { @@ -444,7 +463,23 @@ public class KDocsServiceImpl implements IKDocsService { // 发送处理结果到回调接口 httpClientUtils.sendResultToCallback(resApiContentList, ApiConstants.OUT_CALLBACK_URL); }); - + return result; } + + public static boolean startsWithCheck(String tid, String TIDCheck) { + if (tid == null || TIDCheck == null || tid.length() < TIDCheck.length()) { + return false; + } + char[] tidChars = tid.toCharArray(); + char[] checkChars = TIDCheck.toCharArray(); + for (int i = 0; i < checkChars.length; i++) { + if (tidChars[i] != checkChars[i]) { + return false; + } + } + return true; + } + + } diff --git a/tagApi-service/src/main/java/hw/tagApi/service/utils/TagExcelUtil.java b/tagApi-service/src/main/java/hw/tagApi/service/utils/TagExcelUtil.java index 81a1261..bfe13ec 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/utils/TagExcelUtil.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/utils/TagExcelUtil.java @@ -47,16 +47,6 @@ public class TagExcelUtil { List> tagList = parseTagList(sheet); result.put("tagList", tagList); - // 获取文件名 - String fileName = sheet.getSheetName(); - if (fileName == null || fileName.isEmpty()) { - // 如果没有sheet名称,使用默认格式 - fileName = String.format("Lot_%s_%s.xlsx", - orderInfo.get("orderNo"), - new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())); - } - result.put("fileName", fileName); - return result; } catch (Exception e) { log.error("解析Excel文件失败", e); diff --git a/tagApi-service/src/main/java/hw/tagApi/service/utils/httpClientUtils.java b/tagApi-service/src/main/java/hw/tagApi/service/utils/httpClientUtils.java index a4a45b8..6e3bc04 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/utils/httpClientUtils.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/utils/httpClientUtils.java @@ -116,7 +116,7 @@ public class httpClientUtils { // 将对象转换为JSON字符串 String jsonBody = objectMapper.writeValueAsString(response); - log.debug("准备发送的数据: {}", jsonBody); + log.info("准备发送的数据: {}", jsonBody); // 设置请求体 StringEntity entity = new StringEntity(jsonBody, "UTF-8"); @@ -130,7 +130,7 @@ public class httpClientUtils { if (statusCode == 200) { log.info("发送处理结果到回调接口成功,响应状态码: {}", statusCode); - log.debug("回调接口响应内容: {}", responseBody); + log.info("回调接口响应内容: {}", responseBody); } else { log.error("发送处理结果到回调接口失败,响应状态码: {}, 响应内容: {}", statusCode, responseBody); }