Commit 00a496e7 authored by 刘林's avatar 刘林

fix(jg):修改使用登记作废-气瓶导入作废,修改气瓶导入

parent 91738d0d
...@@ -2768,30 +2768,25 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -2768,30 +2768,25 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
@Override @Override
public Object importPressureData(MultipartFile multipartFile) throws Exception { public Object importPressureData(MultipartFile multipartFile) throws Exception {
List<EquipInfoCylinderExcelDto> aircraftList = new ArrayList<>(); List<EquipInfoCylinderExcelDto> aircraftList = new ArrayList<>();
List<String> errorList = new ArrayList<>(); // 临时错误列表,用于批量插入
List<String> innerCodeList = new ArrayList<>(); // 临时列表
List<String> codeList = new ArrayList<>();
List<String> factoryList = new ArrayList<>();
resultError.clear(); resultError.clear();
useInnerCodeList.clear(); useInnerCodeList.clear();
equCodeList.clear(); equCodeList.clear();
factoryNumList.clear(); factoryNumList.clear();
try { try {
EasyExcel.read(multipartFile.getInputStream(), EquipInfoCylinderExcelDto.class, new AnalysisEventListener<EquipInfoCylinderExcelDto>() { EasyExcel.read(multipartFile.getInputStream(), EquipInfoCylinderExcelDto.class, new AnalysisEventListener<EquipInfoCylinderExcelDto>() {
// 每读取一行时调用 // 每读取一行就调用该方法
@Override @Override
public void invoke(EquipInfoCylinderExcelDto data, AnalysisContext context) { public void invoke(EquipInfoCylinderExcelDto data, AnalysisContext context) {
// 直接操作原数据,避免不必要的对象复制 EquipInfoCylinderExcelDto fireExperts = new EquipInfoCylinderExcelDto();
errorList.add(checkExcelData(data, context).toString()); BeanUtils.copyProperties(data, fireExperts);
aircraftList.add(data); // 直接加入原对象,而不是复制 resultError.add(checkExcelData(data, context).toString());
innerCodeList.add(data.getUseInnerCode()); aircraftList.add(fireExperts);
codeList.add(data.getEquCode()); useInnerCodeList.add(data.getUseInnerCode());
factoryList.add("0".equals(data.getWhetherVehicleCylinder()) ? data.getFactoryNum() : null); equCodeList.add(data.getEquCode());
factoryNumList.add("0".equals(data.getWhetherVehicleCylinder()) ? data.getFactoryNum() : null);
} }
// 全部读取完成后调用 // 全部读取完成就调用该方法
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
if (CollectionUtils.isEmpty(aircraftList)) { if (CollectionUtils.isEmpty(aircraftList)) {
...@@ -2799,23 +2794,13 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -2799,23 +2794,13 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
resultError.add("你上传了一个空数据的Excel文档!"); resultError.add("你上传了一个空数据的Excel文档!");
throw new BadRequest("你上传了一个空数据的Excel文档!"); throw new BadRequest("你上传了一个空数据的Excel文档!");
} }
// 批量添加,减少集合操作的次数
resultError.addAll(errorList);
useInnerCodeList.addAll(innerCodeList);
equCodeList.addAll(codeList);
factoryNumList.addAll(factoryList);
} }
}).headRowNumber(4).sheet().doRead(); }).headRowNumber(4).sheet().doRead();
// 检查错误
if (resultError.stream().anyMatch(input -> !input.isEmpty())) { if (resultError.stream().anyMatch(input -> !input.isEmpty())) {
throw new BadRequest("上传失败!"); throw new BadRequest("上传失败!");
} }
return aircraftList; return aircraftList;
} catch (Exception e) { } catch (Exception e) {
// 处理并抛出所有错误
throw new Exception(resultError.stream() throw new Exception(resultError.stream()
.filter(s -> !s.isEmpty()) .filter(s -> !s.isEmpty())
.collect(Collectors.joining("<br/>"))); .collect(Collectors.joining("<br/>")));
...@@ -2874,47 +2859,51 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -2874,47 +2859,51 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
String key = useRegistrationCode.length() >= 5 ? useRegistrationCode.substring(0, 5) : useRegistrationCode; String key = useRegistrationCode.length() >= 5 ? useRegistrationCode.substring(0, 5) : useRegistrationCode;
List<String> prefixes = Collections.unmodifiableList(Arrays.asList("容", "锅", "管", "瓶", "梯", "起", "索", "游", "车")); List<String> prefixes = Collections.unmodifiableList(Arrays.asList("容", "锅", "管", "瓶", "梯", "起", "索", "游", "车"));
//容15鲁G00302(12) //容15鲁G00302(12)
if (useRegistrationCode.length() == 14 && prefixes.stream().anyMatch(key::startsWith) && redisUtils.hasKey(useRegistrationCode.substring(0, 5))) { if (useRegistrationCode.length() == 14 && prefixes.stream().anyMatch(key::startsWith)) {
String prefix = useRegistrationCode.substring(0, 3); if (redisUtils.hasKey(useRegistrationCode.substring(0, 5))){
// 如果 prefix 不等于 "瓶31" 或 "瓶32" 则继续执行逻辑 String prefix = useRegistrationCode.substring(0, 3);
ValueOperations<String, String> valueOps = redisTemplate.opsForValue(); // 如果 prefix 不等于 "瓶31" 或 "瓶32" 则继续执行逻辑
String currentSequenceStr = valueOps.get(key); ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
if (Stream.of("瓶31", "瓶32").noneMatch(prefix::equals) && currentSequenceStr != null) { String currentSequenceStr = valueOps.get(key);
String extractedValue = useRegistrationCode.substring(5, 10); if (Stream.of("瓶31", "瓶32").noneMatch(prefix::equals) && currentSequenceStr != null) {
String extractedYearStr = useRegistrationCode.substring(useRegistrationCode.indexOf('(') + 1, useRegistrationCode.indexOf(')')); String extractedValue = useRegistrationCode.substring(5, 10);
int currentYearLastTwoDigits = LocalDate.now().getYear() % 100; String extractedYearStr = useRegistrationCode.substring(useRegistrationCode.indexOf('(') + 1, useRegistrationCode.indexOf(')'));
try { int currentYearLastTwoDigits = LocalDate.now().getYear() % 100;
// 提取年份 try {
int extractedYear = Integer.parseInt(extractedYearStr); // 提取年份
if(currentYearLastTwoDigits == extractedYear){ int extractedYear = Integer.parseInt(extractedYearStr);
if (Character.isLetter(extractedValue.charAt(0))) { if(currentYearLastTwoDigits == extractedYear){
// 提取字母部分并比较 if (Character.isLetter(extractedValue.charAt(0))) {
char extractedLetter = extractedValue.charAt(0); // 提取字母部分并比较
int extractedNumber = Integer.parseInt(extractedValue.substring(1)); // 提取数字部分 char extractedLetter = extractedValue.charAt(0);
int extractedNumber = Integer.parseInt(extractedValue.substring(1)); // 提取数字部分
// 提取 Redis 中的字母和数字部分
char redisLetter = currentSequenceStr.charAt(0); // 提取 Redis 中的字母和数字部分
char redisLetter = currentSequenceStr.charAt(0);
//redis中不是字母开头,输入的是字母开头
if (!Character.isLetter(redisLetter) ) { //redis中不是字母开头,输入的是字母开头
throw new BadRequest("登记证编号不能使用系统还未生成编号!"); if (!Character.isLetter(redisLetter) ) {
} throw new BadRequest("登记证编号不能使用系统还未生成编号!");
int redisNumber = Integer.parseInt(currentSequenceStr.substring(1)); }
int redisNumber = Integer.parseInt(currentSequenceStr.substring(1));
// 比较字母和数字 // 比较字母和数字
if ((extractedLetter > redisLetter || (extractedLetter == redisLetter && extractedNumber > redisNumber))) { if ((extractedLetter > redisLetter || (extractedLetter == redisLetter && extractedNumber > redisNumber))) {
throw new BadRequest("登记证编号不能使用系统还未生成编号!"); throw new BadRequest("登记证编号不能使用系统还未生成编号!");
} }
} else { } else {
// 如果首字符不是字母,直接进行字符串比较 // 如果首字符不是字母,直接进行字符串比较
if (extractedValue.compareTo(currentSequenceStr) > 0) { if (extractedValue.compareTo(currentSequenceStr) > 0) {
throw new BadRequest("登记证编号不能使用系统还未生成编号!"); throw new BadRequest("登记证编号不能使用系统还未生成编号!");
}
} }
} }
} catch (NumberFormatException e) {
throw new BadRequest("数据格式错误");
} }
} catch (NumberFormatException e) {
throw new BadRequest("数据格式错误");
} }
} else {
throw new BadRequest("登记证编号不能使用系统还未生成编号!");
} }
} }
} }
......
...@@ -2441,6 +2441,8 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -2441,6 +2441,8 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
superviseInfoMapper.deleteDataAll(records); superviseInfoMapper.deleteDataAll(records);
//删除es中的数据 //删除es中的数据
esEquipmentCategory.deleteAll(esDtoList); esEquipmentCategory.deleteAll(esDtoList);
//作废使用登记证 & 生成使用登记证的流水
this.invalidUseRegistrationCertificate(jgUseRegistration);
}else{ }else{
// 处理非批量导入数据,更新关联业务状态 // 处理非批量导入数据,更新关联业务状态
processElseDataByStatus(oldStatus, jgUseRegistration); processElseDataByStatus(oldStatus, jgUseRegistration);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment