update 添加快速数据导入接口

master
yinq 2 months ago
parent c37f105361
commit c2b8e2da39

@ -13,7 +13,8 @@ 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://database.rfidtire.com/docs/export/";
// public static final String BASE_URL = "http://database.rfidtire.com/docs/export/";
public static final String BASE_URL = "http://1.13.177.47/docs/export/";
/**
* () 6
@ -57,6 +58,11 @@ public class ApiConstants {
*/
public static final String DATA_IMPORT = "10";
/**
*
*/
public static final String FAST_DATA_IMPORT = "11";
/**
*
*/

@ -90,6 +90,15 @@ public class KDocsApiController extends BaseController {
List<ApiContent> apiContents = ikDocsService.importDataList(content);
apiResponse.setResult(apiContents);
return apiResponse;
case ApiConstants.FAST_DATA_IMPORT:
// 快速数据导入
if (content == null || content.isEmpty()) {
log.warn("快速导入数据为空");
return apiResponse;
}
List<ApiContent> fastApiContents = ikDocsService.fastImportDataList(content);
apiResponse.setResult(fastApiContents);
return apiResponse;
case ApiConstants.DATA_QUERY:
// 数据查询
if (content == null || content.isEmpty()) {

@ -3,6 +3,7 @@ package hw.tagApi.service.service;
import java.util.List;
import java.util.Set;
import hw.tagApi.service.domain.ApiContent;
import hw.tagApi.service.domain.HwTagRecord;
/**
@ -106,4 +107,12 @@ public interface IHwTagRecordService
* @return EPC
*/
public Set<String> selectExistingEpcs(List<String> epcs);
/**
*
*
* @param apiContent ApiContent
* @return ApiContent
*/
public ApiContent importData(ApiContent apiContent);
}

@ -12,13 +12,6 @@ import java.util.List;
*/
public interface IKDocsService {
/**
*
*
* @return
*/
String getSystemStatus();
/**
*
*
@ -42,4 +35,12 @@ public interface IKDocsService {
* @return
*/
List<ApiContent> exportDataList(List<ApiContent> content);
/**
*
*
* @param content
* @return
*/
List<ApiContent> fastImportDataList(List<ApiContent> content);
}

@ -1,113 +1,125 @@
package hw.tagApi.service.service.impl;
import java.io.ByteArrayInputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import hw.tagApi.common.exception.ServiceException;
import hw.tagApi.common.utils.DateUtils;
import hw.tagApi.common.utils.uuid.IdGenerator;
import hw.tagApi.service.constant.ApiConstants;
import hw.tagApi.service.domain.ApiContent;
import hw.tagApi.service.utils.TagExcelUtil;
import hw.tagApi.service.utils.httpClientUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import hw.tagApi.service.mapper.HwTagRecordMapper;
import hw.tagApi.service.domain.HwTagRecord;
import hw.tagApi.service.service.IHwTagRecordService;
import org.springframework.transaction.annotation.Transactional;
import static hw.tagApi.service.utils.TagExcelUtil.startsWithCheck;
/**
* Service
*
*
* @author Yinq
* @date 2025-04-15
*/
@Service
public class HwTagRecordServiceImpl implements IHwTagRecordService
{
public class HwTagRecordServiceImpl implements IHwTagRecordService {
private static final Logger log = LoggerFactory.getLogger(HwTagRecordServiceImpl.class);
@Autowired
private HwTagRecordMapper hwTagRecordMapper;
private static final int BATCH_SIZE = 100;
/**
*
*
*
* @param rId
* @return
*/
@Override
public HwTagRecord selectHwTagRecordByRId(Long rId)
{
public HwTagRecord selectHwTagRecordByRId(Long rId) {
return hwTagRecordMapper.selectHwTagRecordByRId(rId);
}
/**
*
*
*
* @param hwTagRecord
* @return
*/
@Override
public List<HwTagRecord> selectHwTagRecordList(HwTagRecord hwTagRecord)
{
public List<HwTagRecord> selectHwTagRecordList(HwTagRecord hwTagRecord) {
return hwTagRecordMapper.selectHwTagRecordList(hwTagRecord);
}
/**
*
*
*
* @param hwTagRecord
* @return
*/
@Override
public int insertHwTagRecord(HwTagRecord hwTagRecord)
{
public int insertHwTagRecord(HwTagRecord hwTagRecord) {
hwTagRecord.setCreateTime(DateUtils.getNowDate());
return hwTagRecordMapper.insertHwTagRecord(hwTagRecord);
}
/**
*
*
*
* @param hwTagRecord
* @return
*/
@Override
public int updateHwTagRecord(HwTagRecord hwTagRecord)
{
public int updateHwTagRecord(HwTagRecord hwTagRecord) {
initTagRecord(hwTagRecord);
return hwTagRecordMapper.updateHwTagRecord(hwTagRecord);
}
/**
* hwTagRecord
*
* @param hwTagRecord hwTagRecord
*/
public void initTagRecord(HwTagRecord hwTagRecord){
public void initTagRecord(HwTagRecord hwTagRecord) {
hwTagRecord.setRId(IdGenerator.nextId());
hwTagRecord.setCreateTime(DateUtils.getNowDate());
}
/**
*
*
*
* @param rIds
* @return
*/
@Override
public int deleteHwTagRecordByRIds(Long[] rIds)
{
public int deleteHwTagRecordByRIds(Long[] rIds) {
return hwTagRecordMapper.deleteHwTagRecordByRIds(rIds);
}
/**
*
*
*
* @param rId
* @return
*/
@Override
public int deleteHwTagRecordByRId(Long rId)
{
public int deleteHwTagRecordByRId(Long rId) {
return hwTagRecordMapper.deleteHwTagRecordByRId(rId);
}
/**
* TID
*
*
* @param record
*/
@Override
@ -117,7 +129,7 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService
/**
*
*
*
* @param batchList
*/
@Override
@ -134,7 +146,7 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService
@Override
public HwTagRecord selectHwTagRecordData(HwTagRecord selectTagRecord) {
List<HwTagRecord> tagRecordList = hwTagRecordMapper.selectHwTagRecordList(selectTagRecord);
if (!tagRecordList.isEmpty()){
if (!tagRecordList.isEmpty()) {
HwTagRecord tagRecord = tagRecordList.get(0);
tagRecord.setQueryResultsNumber(tagRecordList.size());
return tagRecord;
@ -179,4 +191,195 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService
}
return new HashSet<>(hwTagRecordMapper.selectExistingEpcs(epcs));
}
/**
*
*
* @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校验", ""));
String EPCCheck = String.valueOf(fields.getOrDefault("EPC校验", ""));
String EPCNumberCheck = String.valueOf(fields.getOrDefault("EPC位数校验", "0"));
int EPCNumberCheckLength = Integer.parseInt(EPCNumberCheck);
int tidCharCount = TIDCheck.length();
int epcCharCount = EPCCheck.length();
List<HwTagRecord> batchList = new ArrayList<>();
Map<String, Object> resFields = new HashMap<>();
List<String> errorMessages = new ArrayList<>();
int successCount = 0;
int failCount = 0;
apiContent.setFields(resFields);
try {
log.info("开始处理文件URL: {}", fileUrl);
// 获取文件字节数组
byte[] fileData = httpClientUtils.getByteArrayFromUrl(fileUrl);
if (fileData == null) {
log.error("获取文件失败");
resFields.put(ApiConstants.IMPORT_STATUS, "系统错误");
resFields.put(ApiConstants.DESCRIPTION, "获取文件失败");
return apiContent;
}
// 解析Excel数据
try (ByteArrayInputStream bis = new ByteArrayInputStream(fileData)) {
Map<String, Object> excelResult = TagExcelUtil.parseTagExcel(bis);
if (!excelResult.containsKey("tagList")) {
log.error("解析Excel文件失败未找到标签数据");
resFields.put(ApiConstants.IMPORT_STATUS, "导入失败");
resFields.put(ApiConstants.DESCRIPTION, "解析Excel文件失败未找到标签数据");
return apiContent;
}
// 获取订单信息
Map<String, String> orderInfo = (Map<String, String>) excelResult.get("orderInfo");
// 获取标签数据列表
List<Map<String, String>> tagList = (List<Map<String, String>>) excelResult.get("tagList");
// 批量处理标签数据
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 如果不是更新模式先批量查询所有TID
Set<String> existingTids = new HashSet<>();
boolean tIdFlag = ApiConstants.MODE_ADD.equals(importMode) || ApiConstants.MODE_ADD_NO_CHECK.equals(importMode);
if (tIdFlag) {
List<String> allTids = tagList.stream()
.map(tag -> tag.get("TID").replace("-", ""))
.collect(Collectors.toList());
existingTids = this.selectExistingTids(allTids);
}
// 如果不是更新模式批量查询所有EPC
Set<String> existingEpcs = new HashSet<>();
boolean epcCheckFlag = ApiConstants.MODE_ADD.equals(importMode) || ApiConstants.MODE_UPDATE.equals(importMode);
if (epcCheckFlag) {
List<String> allEpcs = tagList.stream()
.map(tag -> tag.get("EPC").replace("-", ""))
.collect(Collectors.toList());
existingEpcs = this.selectExistingEpcs(allEpcs);
}
for (Map<String, String> tagData : tagList) {
try {
String tid = tagData.get("TID").replace("-", "");
String epc = tagData.get("EPC").replace("-", "");
if (tid.length() != ApiConstants.TE_LENGTH || (EPCNumberCheckLength > 0 && epc.length() != EPCNumberCheckLength)) {
StringBuilder builder = new StringBuilder();
if (tid.length() != ApiConstants.TE_LENGTH) {
String errorMsg = String.format("TID长度校验失败预期长度24实际长度%dTID值%s", tid.length(), tid);
builder.append(errorMsg);
log.error("异常 - {}", errorMsg);
}
if (EPCNumberCheckLength > 0 && epc.length() != EPCNumberCheckLength) {
String errorMsg = String.format("EPC长度校验失败预期长度24实际长度%dEPC值%s", epc.length(), epc);
builder.append(errorMsg);
log.error("EPC长度校验异常 - {}", errorMsg);
}
errorMessages.add(builder.toString());
failCount++;
continue;
}
if (tidCharCount > 0 && !startsWithCheck(tid, TIDCheck)) {
String errorMsg = String.format("TID校验失败TID校验%s实际TID%s", TIDCheck, tid);
log.error("TID校验异常 - {}", errorMsg);
errorMessages.add(errorMsg);
failCount++;
continue;
}
if (epcCharCount > 0 && !startsWithCheck(epc, EPCCheck)) {
String errorMsg = String.format("EPC校验失败EPC校验%s实际EPC%s", EPCCheck, epc);
log.error("EPC校验异常 - {}", errorMsg);
errorMessages.add(errorMsg);
failCount++;
continue;
}
HwTagRecord record = new HwTagRecord();
record.setOrderCode(orderInfo.get("orderNo"));
record.setBatchNumber(orderInfo.get("batchNo"));
record.setOperatorId(orderInfo.get("operatorId"));
record.setProcessingTime(sdf.parse(orderInfo.get("processTime")));
record.setTotalQuantity(Long.valueOf(orderInfo.get("totalCount")));
// 设置标签数据
record.setModelCode(model);
record.setTagSequence(tagData.get("序号"));
record.setTId(tid);
record.setEpc(epc);
record.setPassword(tagData.get("密码"));
record.setTestResult(tagData.get("测试结果"));
record.setTestValue(tagData.get("测试值"));
record.setReferenceValue(tagData.get("参考值"));
record.setTestingTime(sdf.parse(tagData.get("测试时间")));
record.setFileName(fileName);
//校验tId唯一
if (tIdFlag && existingTids.contains(tid)) {
String errorMsg = String.format("TID已存在%s", tid);
log.error(errorMsg);
errorMessages.add(errorMsg);
failCount++;
continue;
}
//校验EPC唯一
if (epcCheckFlag && existingEpcs.contains(epc)) {
String errorMsg = String.format("EPC已存在%s", epc);
log.error(errorMsg);
errorMessages.add(errorMsg);
failCount++;
continue;
}
// 更新方法
if ((ApiConstants.MODE_UPDATE.equals(importMode) || ApiConstants.MODE_UPDATE_NO_CHECK.equals(importMode)) && failCount == 0) {
this.updateHwTagRecordByTID(record);
successCount++;
continue;
}
record.setRId(IdGenerator.nextId());
// 添加到批处理列表
batchList.add(record);
// 达到批量大小时执行插入
if (batchList.size() >= BATCH_SIZE && failCount == 0) {
this.batchInsertHwTagRecord(batchList);
log.info("批量插入{}条数据成功", batchList.size());
successCount += batchList.size();
batchList.clear();
}
} catch (Exception e) {
String errorMsg = String.format("处理数据失败:%s", e.getMessage());
log.error(errorMsg);
errorMessages.add(errorMsg);
failCount++;
}
}
// 处理剩余的数据
if (!batchList.isEmpty() && failCount == 0) {
this.batchInsertHwTagRecord(batchList);
log.info("批量插入剩余{}条数据成功", batchList.size());
successCount += batchList.size();
batchList.clear();
}
// 设置导入结果
if (failCount > 0) {
throw new ServiceException(String.format(importMode + "失败:%d条。失败原因%s",
failCount, String.join("; ", errorMessages)));
} else {
resFields.put(ApiConstants.IMPORT_STATUS, "导入成功");
resFields.put(ApiConstants.DESCRIPTION, String.format("成功导入%d条数据", successCount));
}
}
} catch (Exception e) {
log.error("处理文件失败: {}", e.getMessage(), e);
resFields.put(ApiConstants.IMPORT_STATUS, "导入失败");
resFields.put(ApiConstants.DESCRIPTION, e.getMessage());
}
return apiContent;
}
}

@ -1,35 +1,26 @@
package hw.tagApi.service.service.impl;
import hw.tagApi.common.exception.ServiceException;
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 java.rmi.server.ServerCloneException;
import java.time.Duration;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import hw.tagApi.service.constant.ApiConstants;
import hw.tagApi.service.domain.HwTagRecord;
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.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import static hw.tagApi.service.utils.TagExcelUtil.startsWithCheck;
/**
*
@ -44,9 +35,6 @@ public class KDocsServiceImpl implements IKDocsService {
@Autowired
private IHwTagRecordService tagRecordService;
private static final int BATCH_SIZE = 100;
// 创建线程池
private static final ExecutorService executorService = new ThreadPoolExecutor(
5, // 核心线程数
@ -75,7 +63,7 @@ public class KDocsServiceImpl implements IKDocsService {
ApiContent resContent = new ApiContent();
resContent.setId(apiContent.getId());
try {
ApiContent result = this.importData(apiContent);
ApiContent result = tagRecordService.importData(apiContent);
// 更新响应内容
resContent.setFields(result.getFields());
} catch (Exception e) {
@ -91,7 +79,7 @@ public class KDocsServiceImpl implements IKDocsService {
}
// 发送处理结果到回调接口
httpClientUtils.sendResultToCallback(resList, ApiConstants.IN_CALLBACK_URL);
httpClientUtils.sendResultToCallback(resList, ApiConstants.IN_CALLBACK_URL, ApiConstants.DATA_IMPORT);
});
return resApiContentList;
@ -118,213 +106,6 @@ public class KDocsServiceImpl implements IKDocsService {
return resApiContentList;
}
/**
*
*
* @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校验", ""));
String EPCCheck = String.valueOf(fields.getOrDefault("EPC校验", ""));
String EPCNumberCheck = String.valueOf(fields.getOrDefault("EPC位数校验", "0"));
int EPCNumberCheckLength = Integer.parseInt(EPCNumberCheck);
int tidCharCount = TIDCheck.length();
int epcCharCount = EPCCheck.length();
List<HwTagRecord> batchList = new ArrayList<>();
Map<String, Object> resFields = new HashMap<>();
List<String> errorMessages = new ArrayList<>();
int successCount = 0;
int failCount = 0;
apiContent.setFields(resFields);
try {
log.info("开始处理文件URL: {}", fileUrl);
// 获取文件字节数组
byte[] fileData = httpClientUtils.getByteArrayFromUrl(fileUrl);
if (fileData == null) {
log.error("获取文件失败");
resFields.put(ApiConstants.IMPORT_STATUS, "系统错误");
resFields.put(ApiConstants.DESCRIPTION, "获取文件失败");
return apiContent;
}
// 解析Excel数据
try (ByteArrayInputStream bis = new ByteArrayInputStream(fileData)) {
Map<String, Object> excelResult = TagExcelUtil.parseTagExcel(bis);
if (!excelResult.containsKey("tagList")) {
log.error("解析Excel文件失败未找到标签数据");
resFields.put(ApiConstants.IMPORT_STATUS, "导入失败");
resFields.put(ApiConstants.DESCRIPTION, "解析Excel文件失败未找到标签数据");
return apiContent;
}
// 获取订单信息
Map<String, String> orderInfo = (Map<String, String>) excelResult.get("orderInfo");
// 获取标签数据列表
List<Map<String, String>> tagList = (List<Map<String, String>>) excelResult.get("tagList");
// 批量处理标签数据
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 如果不是更新模式先批量查询所有TID
Set<String> existingTids = new HashSet<>();
boolean tIdFlag = ApiConstants.MODE_ADD.equals(importMode) || ApiConstants.MODE_ADD_NO_CHECK.equals(importMode);
if (tIdFlag) {
List<String> allTids = tagList.stream()
.map(tag -> tag.get("TID").replace("-", ""))
.collect(Collectors.toList());
existingTids = tagRecordService.selectExistingTids(allTids);
}
// 如果不是更新模式批量查询所有EPC
Set<String> existingEpcs = new HashSet<>();
boolean epcCheckFlag = ApiConstants.MODE_ADD.equals(importMode) || ApiConstants.MODE_UPDATE.equals(importMode);
if (epcCheckFlag) {
List<String> allEpcs = tagList.stream()
.map(tag -> tag.get("EPC").replace("-", ""))
.collect(Collectors.toList());
existingEpcs = tagRecordService.selectExistingEpcs(allEpcs);
}
for (Map<String, String> tagData : tagList) {
try {
String tid = tagData.get("TID").replace("-", "");
String epc = tagData.get("EPC").replace("-", "");
if (tid.length() != ApiConstants.TE_LENGTH || (EPCNumberCheckLength > 0 && epc.length() != EPCNumberCheckLength)) {
StringBuilder builder = new StringBuilder();
if (tid.length() != ApiConstants.TE_LENGTH) {
String errorMsg = String.format("TID长度校验失败预期长度24实际长度%dTID值%s", tid.length(), tid);
builder.append(errorMsg);
log.error("异常 - {}", errorMsg);
}
if (EPCNumberCheckLength > 0 && epc.length() != EPCNumberCheckLength) {
String errorMsg = String.format("EPC长度校验失败预期长度24实际长度%dEPC值%s", epc.length(), epc);
builder.append(errorMsg);
log.error("EPC长度校验异常 - {}", errorMsg);
}
errorMessages.add(builder.toString());
failCount++;
continue;
}
if (tidCharCount > 0 && !startsWithCheck(tid, TIDCheck)) {
String errorMsg = String.format("TID校验失败TID校验%s实际TID%s", TIDCheck, tid);
log.error("TID校验异常 - {}", errorMsg);
errorMessages.add(errorMsg);
failCount++;
continue;
}
if (epcCharCount > 0 && !startsWithCheck(epc, EPCCheck)) {
String errorMsg = String.format("EPC校验失败EPC校验%s实际EPC%s", EPCCheck, epc);
log.error("EPC校验异常 - {}", errorMsg);
errorMessages.add(errorMsg);
failCount++;
continue;
}
HwTagRecord record = new HwTagRecord();
record.setOrderCode(orderInfo.get("orderNo"));
record.setBatchNumber(orderInfo.get("batchNo"));
record.setOperatorId(orderInfo.get("operatorId"));
record.setProcessingTime(sdf.parse(orderInfo.get("processTime")));
record.setTotalQuantity(Long.valueOf(orderInfo.get("totalCount")));
// 设置标签数据
record.setModelCode(model);
record.setTagSequence(tagData.get("序号"));
record.setTId(tid);
record.setEpc(epc);
record.setPassword(tagData.get("密码"));
record.setTestResult(tagData.get("测试结果"));
record.setTestValue(tagData.get("测试值"));
record.setReferenceValue(tagData.get("参考值"));
record.setTestingTime(sdf.parse(tagData.get("测试时间")));
record.setFileName(fileName);
//校验tId唯一
if (tIdFlag && existingTids.contains(tid)) {
String errorMsg = String.format("TID已存在%s", tid);
log.error(errorMsg);
errorMessages.add(errorMsg);
failCount++;
continue;
}
//校验EPC唯一
if (epcCheckFlag && existingEpcs.contains(epc)) {
String errorMsg = String.format("EPC已存在%s", epc);
log.error(errorMsg);
errorMessages.add(errorMsg);
failCount++;
continue;
}
// 更新方法
if ((ApiConstants.MODE_UPDATE.equals(importMode) || ApiConstants.MODE_UPDATE_NO_CHECK.equals(importMode)) && failCount == 0) {
tagRecordService.updateHwTagRecordByTID(record);
successCount++;
continue;
}
record.setRId(IdGenerator.nextId());
// 添加到批处理列表
batchList.add(record);
// 达到批量大小时执行插入
if (batchList.size() >= BATCH_SIZE && failCount == 0) {
tagRecordService.batchInsertHwTagRecord(batchList);
log.info("批量插入{}条数据成功", batchList.size());
successCount += batchList.size();
batchList.clear();
}
} catch (Exception e) {
String errorMsg = String.format("处理数据失败:%s", e.getMessage());
log.error(errorMsg);
errorMessages.add(errorMsg);
failCount++;
}
}
// 处理剩余的数据
if (!batchList.isEmpty() && failCount == 0) {
tagRecordService.batchInsertHwTagRecord(batchList);
log.info("批量插入剩余{}条数据成功", batchList.size());
successCount += batchList.size();
batchList.clear();
}
// 设置导入结果
if (failCount > 0) {
throw new ServiceException(String.format(importMode + "失败:%d条。失败原因%s",
failCount, String.join("; ", errorMessages)));
} else {
resFields.put(ApiConstants.IMPORT_STATUS, "导入成功");
resFields.put(ApiConstants.DESCRIPTION, String.format("成功导入%d条数据", successCount));
}
}
} catch (Exception e) {
log.error("处理文件失败: {}", e.getMessage(), e);
resFields.put(ApiConstants.IMPORT_STATUS, "导入失败");
resFields.put(ApiConstants.DESCRIPTION, e.getMessage());
}
return apiContent;
}
@Override
public String getSystemStatus() {
try {
ApiResponse response = new ApiResponse();
response.setCaseCode("10");
// 添加导入模式信息
ApiContent modeContent = new ApiContent();
Map<String, String> modeFields = new HashMap<>();
modeFields.put(ApiConstants.DESCRIPTION, "");
// 使用ObjectMapper将对象转换为JSON字符串
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(response);
} catch (Exception e) {
log.error("生成系统状态响应失败", e);
return null;
}
}
/**
*
*
@ -517,7 +298,7 @@ public class KDocsServiceImpl implements IKDocsService {
log.info("数据库导出完成 - ID: {}, 记录数: {}, 耗时: {}分{}秒", condition.getId(), records.size(), minutes, seconds);
responseFields.put(ApiConstants.EXPORT_STATUS, "导出成功");
responseFields.put(ApiConstants.DESCRIPTION, "耗时: " + minutes + "分" + seconds + "秒");
responseFields.put("文件路径", filePath);
responseFields.put("文件链接", filePath);
responseFields.put("链接有效期", sdf.format(futureDate));
log.info("导出文件生成成功 - ID: {}, 路径: {}", condition.getId(), filePath);
} catch (Exception e) {
@ -544,13 +325,42 @@ public class KDocsServiceImpl implements IKDocsService {
resApiContentList.add(response);
}
// 发送处理结果到回调接口
httpClientUtils.sendResultToCallback(resApiContentList, ApiConstants.OUT_CALLBACK_URL);
httpClientUtils.sendResultToCallback(resApiContentList, ApiConstants.OUT_CALLBACK_URL, ApiConstants.DATA_EXPORT);
});
return result;
}
/**
*
*
* @param content
* @return
*/
@Override
public List<ApiContent> fastImportDataList(List<ApiContent> content) {
List<ApiContent> resList = new ArrayList<>();
for (ApiContent apiContent : content) {
long startTime = System.currentTimeMillis();
ApiContent resContent = new ApiContent();
resContent.setId(apiContent.getId());
try {
ApiContent result = tagRecordService.importData(apiContent);
// 更新响应内容
resContent.setFields(result.getFields());
} catch (Exception e) {
log.error("快速导入任务执行失败: {}", e.getMessage(), e);
Map<String, Object> errorFields = new HashMap<>();
errorFields.put(ApiConstants.IMPORT_STATUS, "导入失败");
errorFields.put(ApiConstants.DESCRIPTION, "快速导入任务执行失败: " + e.getMessage());
resContent.setFields(errorFields);
}
resList.add(resContent);
long endTime = System.currentTimeMillis();
log.info("数据库快速导入完成 - ID: {}, 耗时: {}ms", apiContent.getId(), (endTime - startTime));
}
return resList;
}
}

@ -92,7 +92,7 @@ public class httpClientUtils {
*
* @param resList
*/
public static void sendResultToCallback(List<ApiContent> resList, String url) {
public static void sendResultToCallback(List<ApiContent> resList, String url, String caseCode) {
if (resList == null || resList.isEmpty()) {
log.warn("处理结果列表为空,不发送回调请求");
return;
@ -111,7 +111,7 @@ public class httpClientUtils {
// 创建响应对象
ApiResponse response = new ApiResponse();
response.setCaseCode(ApiConstants.DATA_IMPORT);
response.setCaseCode(caseCode);
response.setResult(resList);
// 将对象转换为JSON字符串

Loading…
Cancel
Save