Commit d3087f12 by 杨林龙

修改导入错误信息提示

1 parent 1216a8cf
...@@ -216,23 +216,31 @@ public class VehicleInfoImportListener extends AnalysisEventListener<VehicleInfo ...@@ -216,23 +216,31 @@ public class VehicleInfoImportListener extends AnalysisEventListener<VehicleInfo
// 校验组织机构 // 校验组织机构
if (StringUtils.isNullOrEmpty(vi.getOrganizationName())) { if (StringUtils.isNullOrEmpty(vi.getOrganizationName())) {
failMsg.add(new VehicleInfoFailExport("组织机构", "必填项")); failMsg.add(new VehicleInfoFailExport("组织机构", "必填项"));
} } else {
// 校验组织机构 是否存在 // 校验组织机构 是否存在
Long userId = userApiService.getUserIdByUsername(vi.getOrganizationName()); Long userId = userApiService.getUserIdByUsername(vi.getOrganizationName());
if (userId == null) { if (userId == null) {
failMsg.add(new VehicleInfoFailExport(vi.getOrganizationName(), "该组织机构不存在,请选择用户级别的组织名称")); failMsg.add(new VehicleInfoFailExport(vi.getOrganizationName(), "该组织机构不存在,请选择用户级别的组织名称"));
} }
}
// 校验车架号 // 校验车架号
if (StringUtils.isNullOrEmpty(vi.getVin())) { if (StringUtils.isNullOrEmpty(vi.getVin())) {
failMsg.add(new VehicleInfoFailExport("车架号", "必填项")); failMsg.add(new VehicleInfoFailExport("车架号", "必填项"));
} else {
boolean flag = true;
String pattern = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{17}$";
boolean matches = vi.getVin().matches(pattern);
if (!matches) {
flag = false;
failMsg.add(new VehicleInfoFailExport(vi.getVin(), "车架号车架号必须是17位数字+字母组合"));
} }
// 校验车架号时候存在 // 校验车架号时候存在
if (vinList.contains(vi.getVin())) { if (flag && vinList.contains(vi.getVin())) {
failMsg.add(new VehicleInfoFailExport(vi.getVin(), "车架号已经存在,请勿重复导入")); failMsg.add(new VehicleInfoFailExport(vi.getVin(), "车架号已经存在,请勿重复导入"));
} }
}
// 校验设备号是否存在 // 校验设备号是否存在
if (!allSnList.contains(vi.getSn())) { if (!allSnList.contains(vi.getSn())) {
......
...@@ -41,6 +41,8 @@ import org.springframework.boot.test.context.SpringBootTest; ...@@ -41,6 +41,8 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -2158,4 +2160,16 @@ public class VehicleServiceTest { ...@@ -2158,4 +2160,16 @@ public class VehicleServiceTest {
deviceService.updateDevice(device); deviceService.updateDevice(device);
} }
@Test
public void test16(){
String pattern = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{17}$";
String line = "1231231234qwe54789";
boolean matches = line.matches(pattern);
if (matches){
System.out.println("matches = " + matches);
}
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!