update 添加导入模板(盘点)

master
yinq 2 months ago
parent c2b8e2da39
commit a271df14b9

@ -214,6 +214,7 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService {
List<HwTagRecord> batchList = new ArrayList<>();
Map<String, Object> resFields = new HashMap<>();
List<String> errorMessages = new ArrayList<>();
Date nowDate = new Date();
int successCount = 0;
int failCount = 0;
apiContent.setFields(resFields);
@ -298,10 +299,12 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService {
continue;
}
HwTagRecord record = new HwTagRecord();
record.setOrderCode(orderInfo.get("orderNo"));
String lot = orderInfo.get("orderNo").replace("Lot", "");
record.setOrderCode(lot);
record.setBatchNumber(orderInfo.get("batchNo"));
record.setOperatorId(orderInfo.get("operatorId"));
record.setProcessingTime(sdf.parse(orderInfo.get("processTime")));
Date processTime = orderInfo.containsKey("processTime") ? sdf.parse(orderInfo.get("processTime")) : nowDate;
record.setProcessingTime(processTime);
record.setTotalQuantity(Long.valueOf(orderInfo.get("totalCount")));
// 设置标签数据
record.setModelCode(model);
@ -312,7 +315,8 @@ public class HwTagRecordServiceImpl implements IHwTagRecordService {
record.setTestResult(tagData.get("测试结果"));
record.setTestValue(tagData.get("测试值"));
record.setReferenceValue(tagData.get("参考值"));
record.setTestingTime(sdf.parse(tagData.get("测试时间")));
Date testingTime = tagData.containsKey("测试时间") ? sdf.parse(tagData.get("测试时间")) : nowDate;
record.setTestingTime(testingTime);
record.setFileName(fileName);
//校验tId唯一

@ -37,13 +37,22 @@ public class TagExcelUtil {
try (Workbook workbook = WorkbookFactory.create(is)) {
Sheet sheet = workbook.getSheetAt(0);
// 解析订单信息
Map<String, String> orderInfo = parseOrderInfo(sheet);
result.put("orderInfo", orderInfo);
Row row = sheet.getRow(0);
Cell cellI1 = row.getCell(8); // I列是第9列(索引8)
Cell cellJ1 = row.getCell(9); // J列是第10列(索引9)
boolean isInventoryFlag = validateCells(cellI1, cellJ1);//桌面读写器盘点模板
// 解析标签数据
List<Map<String, String>> tagList = parseTagList(sheet);
result.put("tagList", tagList);
if (isInventoryFlag) {
List<Map<String, String>> tagList = parseTagList(sheet, 1);
result.put("tagList", tagList);
} else {
// 解析订单信息
Map<String, String> orderInfo = parseOrderInfo(sheet);
result.put("orderInfo", orderInfo);
// 解析标签数据
List<Map<String, String>> tagList = parseTagList(sheet, 7);
result.put("tagList", tagList);
}
return result;
} catch (Exception e) {
@ -52,6 +61,22 @@ public class TagExcelUtil {
}
}
/**
*
*
* @param cellI1 I1
* @param cellJ1 J1
* @return
*/
private static boolean validateCells(Cell cellI1, Cell cellJ1) {
// 获取单元格值并转换为字符串
String valueI1 = getCellStringValue(cellI1);
String valueJ1 = getCellStringValue(cellJ1);
// 校验是否满足条件
return "EPC".equalsIgnoreCase(valueI1) && "TID".equalsIgnoreCase(valueJ1);
}
/**
* 5
*/
@ -115,21 +140,25 @@ public class TagExcelUtil {
/**
* 8
*
* @param sheet sheet
* @param startRow 8
* @return ArrayList
*/
private static List<Map<String, String>> parseTagList(Sheet sheet) {
private static List<Map<String, String>> parseTagList(Sheet sheet, int startRow) {
List<Map<String, String>> tagList = new ArrayList<>();
try {
// 获取表头
Row headerRow = sheet.getRow(6);
Row headerRow = sheet.getRow(startRow - 1);
List<String> headers = new ArrayList<>();
for (Cell cell : headerRow) {
headers.add(getCellStringValue(cell));
}
// 解析数据行
int startRow = 7;
Row row;
while ((row = sheet.getRow(startRow)) != null) {
int thisStartRow = startRow;
while ((row = sheet.getRow(thisStartRow)) != null) {
Map<String, String> tagData = new HashMap<>();
boolean hasData = false;
@ -146,7 +175,7 @@ public class TagExcelUtil {
} else {
break;
}
startRow++;
thisStartRow++;
}
} catch (Exception e) {
log.error("解析标签数据失败", e);
@ -245,8 +274,9 @@ public class TagExcelUtil {
/**
* '*'
*
* @param originalField
* @param checkField '*'
* @param checkField '*'
* @return
*/
public static boolean startsWithCheck(String originalField, String checkField) {

Loading…
Cancel
Save