|
|
|
@ -3,17 +3,13 @@ package hw.tagApi.service.service.impl;
|
|
|
|
|
import hw.tagApi.common.utils.uuid.IdGenerator;
|
|
|
|
|
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 hw.tagApi.system.service.ISysAttachInfoService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.*;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
@ -22,14 +18,14 @@ import java.util.Map;
|
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
|
|
|
|
|
import hw.tagApi.service.constant.ApiConstants;
|
|
|
|
|
import hw.tagApi.service.mapper.HwTagRecordMapper;
|
|
|
|
|
import hw.tagApi.service.domain.HwTagRecord;
|
|
|
|
|
import hw.tagApi.common.utils.poi.TagExcelUtil;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
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.util.StringUtils;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 云文档服务实现类
|
|
|
|
@ -44,6 +40,8 @@ public class KDocsServiceImpl implements IKDocsService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IHwTagRecordService tagRecordService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int BATCH_SIZE = 100;
|
|
|
|
|
|
|
|
|
|
// 创建线程池
|
|
|
|
@ -86,7 +84,7 @@ public class KDocsServiceImpl implements IKDocsService {
|
|
|
|
|
resList.add(resContent);
|
|
|
|
|
}
|
|
|
|
|
// 发送处理结果到回调接口
|
|
|
|
|
httpClientUtils.sendResultToCallback(resList);
|
|
|
|
|
httpClientUtils.sendResultToCallback(resList, ApiConstants.IN_CALLBACK_URL);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return resApiContentList;
|
|
|
|
@ -164,7 +162,7 @@ public class KDocsServiceImpl implements IKDocsService {
|
|
|
|
|
// 设置标签数据
|
|
|
|
|
record.setModelCode(model);
|
|
|
|
|
record.setTagSequence(tagData.get("序号"));
|
|
|
|
|
record.settId(tagData.get("TID"));
|
|
|
|
|
record.setTId(tagData.get("TID"));
|
|
|
|
|
record.setEpc(tagData.get("EPC"));
|
|
|
|
|
record.setPassword(tagData.get("密码"));
|
|
|
|
|
record.setFields1(tagData.get("测试结果"));
|
|
|
|
@ -178,11 +176,11 @@ public class KDocsServiceImpl implements IKDocsService {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//校验tId唯一
|
|
|
|
|
HwTagRecord tagRecord = tagRecordService.selectHwTagRecordByTID(record.gettId());
|
|
|
|
|
HwTagRecord tagRecord = tagRecordService.selectHwTagRecordByTID(record.getTId());
|
|
|
|
|
if (tagRecord != null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
record.setrId(IdGenerator.nextId());
|
|
|
|
|
record.setRId(IdGenerator.nextId());
|
|
|
|
|
// 添加到批处理列表
|
|
|
|
|
batchList.add(record);
|
|
|
|
|
if (batchList.size() >= BATCH_SIZE) {
|
|
|
|
@ -227,12 +225,6 @@ public class KDocsServiceImpl implements IKDocsService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String exportData(String query) {
|
|
|
|
|
// TODO: 实现数据导出逻辑
|
|
|
|
|
return getSystemStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询数据
|
|
|
|
|
*
|
|
|
|
@ -270,7 +262,7 @@ public class KDocsServiceImpl implements IKDocsService {
|
|
|
|
|
// 设置查询条件
|
|
|
|
|
if (fields.containsKey("TID")) {
|
|
|
|
|
String tid = (String) fields.get("TID");
|
|
|
|
|
selectTagRecord.settId(tid);
|
|
|
|
|
selectTagRecord.setTId(tid);
|
|
|
|
|
}
|
|
|
|
|
if (fields.containsKey("EPC")) {
|
|
|
|
|
String epc = (String) fields.get("EPC");
|
|
|
|
@ -294,14 +286,14 @@ public class KDocsServiceImpl implements IKDocsService {
|
|
|
|
|
|
|
|
|
|
// 处理查询结果
|
|
|
|
|
if (data != null) {
|
|
|
|
|
log.info("查询成功 - ID: {}, TID: {}, EPC: {}", queryId, data.gettId(), data.getEpc());
|
|
|
|
|
log.info("查询成功 - ID: {}, TID: {}, EPC: {}", queryId, data.getTId(), data.getEpc());
|
|
|
|
|
// 查询成功
|
|
|
|
|
response.getFields().put("搜索状态", "搜索成功");
|
|
|
|
|
response.getFields().put("TID", data.gettId());
|
|
|
|
|
response.getFields().put("TID", data.getTId());
|
|
|
|
|
response.getFields().put("EPC", data.getEpc());
|
|
|
|
|
response.getFields().put("标签序号", data.getTagSequence());
|
|
|
|
|
response.getFields().put("密码", data.getPassword() != null ? data.getPassword() : "");
|
|
|
|
|
response.getFields().put("RID", data.getrId());
|
|
|
|
|
response.getFields().put("RID", data.getTId());
|
|
|
|
|
response.getFields().put("LOT", data.getOrderCode());
|
|
|
|
|
response.getFields().put("卷编号", data.getBatchNumber());
|
|
|
|
|
response.getFields().put("本卷数量", data.getTotalQuantity() != null ? data.getTotalQuantity() : "");
|
|
|
|
@ -330,4 +322,119 @@ public class KDocsServiceImpl implements IKDocsService {
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出数据
|
|
|
|
|
*
|
|
|
|
|
* @param content 导出条件列表
|
|
|
|
|
* @return 导出结果列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<ApiContent> exportDataList(List<ApiContent> content) {
|
|
|
|
|
List<ApiContent> result = new ArrayList<>();
|
|
|
|
|
if (content == null || content.isEmpty()) {
|
|
|
|
|
log.warn("导出条件列表为空");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
log.info("开始处理导出请求,导出条件数量: {}", content.size());
|
|
|
|
|
// 创建初始响应
|
|
|
|
|
for (ApiContent condition : content) {
|
|
|
|
|
ApiContent response = new ApiContent();
|
|
|
|
|
response.setId(condition.getId());
|
|
|
|
|
Map<String, Object> responseFields = new HashMap<>();
|
|
|
|
|
responseFields.put("导出状态", "导出中");
|
|
|
|
|
responseFields.put("情况说明", "预计需要3分钟");
|
|
|
|
|
response.setFields(responseFields);
|
|
|
|
|
result.add(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 异步执行导出任务
|
|
|
|
|
executorService.execute(() -> {
|
|
|
|
|
List<ApiContent> resApiContentList = new ArrayList<>();
|
|
|
|
|
for (ApiContent condition : content) {
|
|
|
|
|
ApiContent response = new ApiContent();
|
|
|
|
|
response.setId(condition.getId());
|
|
|
|
|
try {
|
|
|
|
|
Map<String, Object> fields = condition.getFields();
|
|
|
|
|
String lot = fields.get("LOT") != null ? (String) fields.get("LOT") : "";
|
|
|
|
|
String startDate = fields.get("导出日期起点") != null ? (String) fields.get("导出日期起点") : "";
|
|
|
|
|
String endDate = fields.get("导出日期终点") != null ? (String) fields.get("导出日期终点") : "";
|
|
|
|
|
String tagBatch = fields.get("标签批次号") != null ? (String) fields.get("标签批次号") : "";
|
|
|
|
|
String batchNumber = fields.get("卷编号") != null ? (String) fields.get("卷编号") : "";
|
|
|
|
|
String modelCode = fields.get("型号") != null ? (String) fields.get("型号") : "";
|
|
|
|
|
String TID = fields.get("TID") != null ? (String) fields.get("TID") : "";
|
|
|
|
|
String EPC = fields.get("EPC") != null ? (String) fields.get("EPC") : "";
|
|
|
|
|
|
|
|
|
|
// 构建查询条件
|
|
|
|
|
HwTagRecord queryCondition = new HwTagRecord();
|
|
|
|
|
if (StringUtils.hasText(lot)) {
|
|
|
|
|
queryCondition.setOrderCode(lot);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.hasText(startDate)) {
|
|
|
|
|
queryCondition.setStartDate(startDate);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.hasText(endDate)) {
|
|
|
|
|
queryCondition.setEndDate(endDate);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.hasText(tagBatch)) {
|
|
|
|
|
queryCondition.setTagBatch(tagBatch);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.hasText(batchNumber)) {
|
|
|
|
|
queryCondition.setBatchNumber(batchNumber);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.hasText(modelCode)) {
|
|
|
|
|
queryCondition.setModelCode(modelCode);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.hasText(TID)) {
|
|
|
|
|
queryCondition.setSelectTID(TID);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.hasText(EPC)) {
|
|
|
|
|
queryCondition.setSelectEPC(EPC);
|
|
|
|
|
}
|
|
|
|
|
// 执行查询
|
|
|
|
|
log.info("执行数据导出查询 - ID: {}", condition.getId());
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
List<HwTagRecord> records = tagRecordService.selectHwTagRecordList(queryCondition);
|
|
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
|
|
log.info("查询完成 - ID: {}, 记录数: {}, 耗时: {}ms", condition.getId(), records.size(), (endTime - startTime));
|
|
|
|
|
|
|
|
|
|
Map<String, Object> responseFields = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
if (records != null && !records.isEmpty()) {
|
|
|
|
|
try {
|
|
|
|
|
String fileName = String.format("标签数据_%s.xlsx", condition.getId());
|
|
|
|
|
String filePath = TagExcelUtil.generateTagExcel(records, fileName);
|
|
|
|
|
responseFields.put("导出状态", "导出成功");
|
|
|
|
|
responseFields.put("文件路径", filePath);
|
|
|
|
|
responseFields.put("记录数量", records.size());
|
|
|
|
|
log.info("导出文件生成成功 - ID: {}, 路径: {}", condition.getId(), filePath);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("生成导出文件失败 - ID: {}", condition.getId(), e);
|
|
|
|
|
responseFields.put("导出状态", "导出失败");
|
|
|
|
|
responseFields.put("错误信息", "生成导出文件失败: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
responseFields.put("导出状态", "未找到记录");
|
|
|
|
|
responseFields.put("情况说明", "未找到符合条件的记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.setFields(responseFields);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("处理导出任务失败 - ID: {}", condition.getId(), e);
|
|
|
|
|
response.setId(condition.getId());
|
|
|
|
|
Map<String, Object> responseFields = new HashMap<>();
|
|
|
|
|
responseFields.put("导出状态", "导出失败");
|
|
|
|
|
responseFields.put("错误信息", "处理导出任务失败: " + e.getMessage());
|
|
|
|
|
response.setFields(responseFields);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
resApiContentList.add(response);
|
|
|
|
|
}
|
|
|
|
|
// 发送处理结果到回调接口
|
|
|
|
|
httpClientUtils.sendResultToCallback(resApiContentList, ApiConstants.OUT_CALLBACK_URL);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|