update add查询数据接口

master
yinq 2 months ago
parent 789c5060f7
commit 8c247abaee

@ -22,7 +22,7 @@ import java.util.List;
*/
@RestController
@RequestMapping("/docs")
public class KDocsApiController {
public class KDocsApiController extends BaseController {
private static final Logger log = LoggerFactory.getLogger(KDocsApiController.class);
@ -70,14 +70,13 @@ public class KDocsApiController {
return apiResponse;
}
log.info("开始查询数据: {}", content);
// TODO: 调用查询服务
List<ApiContent> queryResults = ikDocsService.queryDataList(content);
apiResponse.setResult(queryResults);
return apiResponse;
case ApiConstants.DATA_EXPORT:
// 数据导出
log.info("开始导出数据");
return apiResponse;
default:
log.warn("未知的功能代码: {}", caseCode);
return apiResponse;

@ -13,17 +13,17 @@ public class ApiContent {
/** 字段集合 */
@JsonProperty("fields")
private Map<String, String> fields;
private Map<String, Object> fields;
/** 记录ID */
@JsonProperty("id")
private String id;
public Map<String, String> getFields() {
public Map<String, Object> getFields() {
return fields;
}
public void setFields(Map<String, String> fields) {
public void setFields(Map<String, Object> fields) {
this.fields = fields;
}

@ -80,7 +80,33 @@ public class HwTagRecord extends BaseEntity
// @Excel(name = "预留字段3")
private String fields3;
public void setrId(Long rId)
/**
*
*/
private String startDate;
/**
*
*/
private String endDate;
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public void setrId(Long rId)
{
this.rId = rId;
}

@ -74,4 +74,12 @@ public interface HwTagRecordMapper
* @return
*/
public int updateHwTagRecordByTID(HwTagRecord record);
/**
* TID
*
* @param tId TID
*/
public HwTagRecord selectHwTagRecordByTxId(String tId);
}

@ -72,4 +72,15 @@ public interface IHwTagRecordService
* @param batchList
*/
public void batchInsertHwTagRecord(List<HwTagRecord> batchList);
public HwTagRecord selectHwTagRecordData(HwTagRecord selectTagRecord);
/**
* TID
*
* @param tId TID
*/
public HwTagRecord selectHwTagRecordByTID(String tId);
}

@ -27,22 +27,6 @@ public interface IKDocsService {
*/
List<ApiContent> importDataList(List<ApiContent> content);
/**
*
*
* @param id ID
* @return
*/
String deleteData(String id);
/**
*
*
* @param query
* @return
*/
String queryData(String query);
/**
*
*
@ -50,4 +34,12 @@ public interface IKDocsService {
* @return
*/
String exportData(String query);
/**
*
*
* @param content
* @return
*/
List<ApiContent> queryDataList(List<ApiContent> content);
}

@ -116,6 +116,26 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService
hwTagRecordMapper.batchInsertHwTagRecord(batchList);
}
@Override
public HwTagRecord selectHwTagRecordData(HwTagRecord selectTagRecord) {
List<HwTagRecord> tagRecordList = hwTagRecordMapper.selectHwTagRecordList(selectTagRecord);
if (!tagRecordList.isEmpty()){
return tagRecordList.get(0);
}
return null;
}
/**
* TID
*
* @param tId TID
*/
@Override
public HwTagRecord selectHwTagRecordByTID(String tId) {
return hwTagRecordMapper.selectHwTagRecordByTxId(tId);
}
/**
* hwTagRecord
* @param hwTagRecord hwTagRecord

@ -78,7 +78,7 @@ public class KDocsServiceImpl implements IKDocsService {
resContent.setFields(result.getFields());
} catch (Exception e) {
log.error("导入任务执行失败: {}", e.getMessage(), e);
Map<String, String> errorFields = new HashMap<>();
Map<String, Object> errorFields = new HashMap<>();
errorFields.put(ApiConstants.IMPORT_STATUS, "系统错误");
errorFields.put(ApiConstants.DESCRIPTION, "导入任务执行失败: " + e.getMessage());
resContent.setFields(errorFields);
@ -102,7 +102,7 @@ public class KDocsServiceImpl implements IKDocsService {
List<ApiContent> resApiContentList = new ArrayList<>();
for (ApiContent apiContent : contentList) {
// 创建初始响应
Map<String, String> resFields = new HashMap<>();
Map<String, Object> resFields = new HashMap<>();
resFields.put(ApiConstants.IMPORT_STATUS, "导入中");
resFields.put(ApiConstants.DESCRIPTION, "后台处理中");
ApiContent responseContent = new ApiContent();
@ -120,12 +120,12 @@ public class KDocsServiceImpl implements IKDocsService {
* @return ApiContent
*/
public ApiContent importData(ApiContent apiContent) {
Map<String, String> fields = apiContent.getFields();
String importMode = fields.get("导入模式");
String model = fields.getOrDefault("型号", "");
String fileUrl = fields.get("文件链接");
Map<String, Object> fields = apiContent.getFields();
String importMode = String.valueOf(fields.get("导入模式"));
String model = String.valueOf(fields.getOrDefault("型号", ""));
String fileUrl = String.valueOf(fields.get("文件链接"));
List<HwTagRecord> batchList = new ArrayList<>();
Map<String, String> resFields = new HashMap<>();
Map<String, Object> resFields = new HashMap<>();
apiContent.setFields(resFields);
try {
log.info("开始处理文件URL: {}", fileUrl);
@ -160,6 +160,7 @@ public class KDocsServiceImpl implements IKDocsService {
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("序号"));
@ -176,8 +177,13 @@ public class KDocsServiceImpl implements IKDocsService {
tagRecordService.updateHwTagRecordByTID(record);
continue;
}
// 添加到批处理列表
//校验tId唯一
HwTagRecord tagRecord = tagRecordService.selectHwTagRecordByTID(record.gettId());
if (tagRecord != null) {
continue;
}
record.setrId(IdGenerator.nextId());
// 添加到批处理列表
batchList.add(record);
if (batchList.size() >= BATCH_SIZE) {
tagRecordService.batchInsertHwTagRecord(batchList);
@ -221,21 +227,107 @@ public class KDocsServiceImpl implements IKDocsService {
}
}
@Override
public String deleteData(String id) {
// TODO: 实现数据删除逻辑
return getSystemStatus();
}
@Override
public String queryData(String query) {
// TODO: 实现数据查询逻辑
return getSystemStatus();
}
@Override
public String exportData(String query) {
// TODO: 实现数据导出逻辑
return getSystemStatus();
}
/**
*
*
* @param content
* @return
*/
@Override
public List<ApiContent> queryDataList(List<ApiContent> content) {
List<ApiContent> result = new ArrayList<>();
if (content == null || content.isEmpty()) {
log.warn("查询条件列表为空");
return result;
}
log.info("开始处理查询请求,查询条件数量: {}", content.size());
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);
response.getFields().put("搜索状态", "查询条件错误");
response.getFields().put("情况说明", "查询条件必须包含TID或EPC");
result.add(response);
continue;
}
// 设置查询条件
if (fields.containsKey("TID")) {
String tid = (String) fields.get("TID");
selectTagRecord.settId(tid);
}
if (fields.containsKey("EPC")) {
String epc = (String) fields.get("EPC");
selectTagRecord.setEpc(epc);
}
if (fields.containsKey("搜索日期起点")) {
String startDate = (String) fields.get("搜索日期起点");
selectTagRecord.setStartDate(startDate);
}
if (fields.containsKey("搜索日期终点")) {
String endDate = (String) fields.get("搜索日期终点");
selectTagRecord.setEndDate(endDate);
}
// 执行查询
log.info("执行数据库查询 - ID: {}", queryId);
long startTime = System.currentTimeMillis();
HwTagRecord data = tagRecordService.selectHwTagRecordData(selectTagRecord);
long endTime = System.currentTimeMillis();
log.info("数据库查询完成 - ID: {}, 耗时: {}ms", queryId, (endTime - startTime));
// 处理查询结果
if (data != null) {
log.info("查询成功 - ID: {}, TID: {}, EPC: {}", queryId, data.gettId(), data.getEpc());
// 查询成功
response.getFields().put("搜索状态", "搜索成功");
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("LOT", data.getOrderCode());
response.getFields().put("卷编号", data.getBatchNumber());
response.getFields().put("本卷数量", data.getTotalQuantity() != null ? data.getTotalQuantity() : "");
response.getFields().put("标签批次号", data.getTagBatch() != null ? data.getTagBatch() : "");
response.getFields().put("型号", data.getModelCode() != null ? data.getModelCode() : "");
response.getFields().put("加工时间", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(data.getProcessingTime()));
response.getFields().put("生产人员编号", data.getOperatorId());
log.debug("查询结果详情 - ID: {}, 结果: {}", queryId, response.getFields());
} else {
log.info("未找到记录 - ID: {}", queryId);
// 未找到记录
response.getFields().put("搜索状态", "未找到记录");
if (fields.containsKey("搜索日期起点") && fields.containsKey("搜索日期终点")) {
String message = String.format("已遍历整个数据库,生产日期从%s到%s未查询到该TID。",
fields.get("搜索日期起点"), fields.get("搜索日期终点"));
response.getFields().put("情况说明", message);
log.debug("未找到记录详情 - ID: {}, 日期范围: {} - {}",
queryId, fields.get("搜索日期起点"), fields.get("搜索日期终点"));
} else {
response.getFields().put("情况说明", "未找到匹配的记录");
}
}
result.add(response);
}
return result;
}
}

@ -49,6 +49,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="fields1 != null and fields1 != ''"> and fields_1 = #{fields1}</if>
<if test="fields2 != null and fields2 != ''"> and fields_2 = #{fields2}</if>
<if test="fields3 != null and fields3 != ''"> and fields_3 = #{fields3}</if>
<if test="startDate != null and startDate != ''"> and DATE_FORMAT(processing_time, '%Y/%m/%d') >= #{startDate}</if>
<if test="endDate != null and endDate != ''"> and #{endDate} >= DATE_FORMAT(processing_time, '%Y/%m/%d')</if>
</where>
</select>
@ -57,6 +59,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where r_id = #{rId}
</select>
<select id="selectHwTagRecordByTxId" parameterType="String" resultMap="HwTagRecordResult">
select r_id, t_id, epc from hw_tag_record
where t_id = #{tId}
</select>
<insert id="insertHwTagRecord" parameterType="HwTagRecord">
insert into hw_tag_record
<trim prefix="(" suffix=")" suffixOverrides=",">

Loading…
Cancel
Save