|
|
|
@ -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,实际长度:%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<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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|