update 导入接口校验优化

master
yinq 2 months ago
parent cfdf1dfb1c
commit 9f6d1c4223

@ -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";
/**
*

@ -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<String, Object> 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<HwTagRecord> batchList = new ArrayList<>();
Map<String, Object> 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<String, String> orderInfo = (Map<String, String>) excelResult.get("orderInfo");
// 获取标签数据列表
List<Map<String, String>> tagList = (List<Map<String, String>>) excelResult.get("tagList");
// 获取文件名
String fileName = (String) excelResult.get("fileName");
// 批量处理标签数据
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (Map<String, String> tagData : tagList) {
String tid = tagData.get("TID").replace("-", "");
String epc = tagData.get("EPC").replace("-", "");
if (tid.length() != 24) {
String errorMsg = String.format("TID长度校验失败预期长度24实际长度%dTID值%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<String, Object> 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<ApiContent> resApiContentList = new ArrayList<>();
@ -399,9 +418,9 @@ public class KDocsServiceImpl implements IKDocsService {
long startTime = System.currentTimeMillis();
List<HwTagRecord> records = tagRecordService.selectHwTagRecordList(queryCondition);
Map<String, Object> 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;
}
}

@ -47,16 +47,6 @@ public class TagExcelUtil {
List<Map<String, String>> 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);

@ -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);
}

Loading…
Cancel
Save