接口联调
This commit is contained in:
parent
b55a5931a4
commit
17aaba4440
|
|
@ -47,6 +47,16 @@ public class Constants {
|
|||
*/
|
||||
public static final String CREDENTIALS_CODE_PATTERN = "^[1-9]\\d{5}[1-9]\\d{3}((0[1-9])|(1[0-2]))(0[1-9]|([1|2][0-9])|3[0-1])((\\d{4})|\\d{3}X)$";
|
||||
|
||||
/**
|
||||
* 经度正则表达式
|
||||
*/
|
||||
public static final String LONGITUDE_PATTERN = "^(-?\\d{1,3}(\\.\\d{1,6})?)$";
|
||||
|
||||
/**
|
||||
* 纬度正则表达式
|
||||
*/
|
||||
public static final String LATITUDE_PATTERN = "^(-?([1-8]?\\d(\\.\\d{1,6})?)|90(\\.0{1,6})?)$";
|
||||
|
||||
/**
|
||||
* 登录失败状态
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -382,26 +382,25 @@ public class TbPeopleServiceImpl implements TbPeopleService {
|
|||
Row row = sheet.getRow(r);
|
||||
// 循环Excel列数
|
||||
for (int c = 0; c < totalCells; c++) {
|
||||
Cell cell = row.getCell(c);
|
||||
String cellValue = dataFormatter.formatCellValue(row.getCell(c));
|
||||
switch (c) {
|
||||
case 0:
|
||||
checkBlank(cell, r, c);
|
||||
checkBlank(cellValue, r, c);
|
||||
break;
|
||||
case 1:
|
||||
checkBlank(cell, r, c);
|
||||
checkBlank(cellValue, r, c);
|
||||
checkGender(cellValue, r, c);
|
||||
break;
|
||||
case 2:
|
||||
checkBlank(cell, r, c);
|
||||
checkBlank(cellValue, r, c);
|
||||
checkPostCode(cellValue, r, c);
|
||||
break;
|
||||
case 3:
|
||||
checkBlank(cell, r, c);
|
||||
checkBlank(cellValue, r, c);
|
||||
checkIdCard(cellValue, r, c);
|
||||
break;
|
||||
case 4:
|
||||
checkBlank(cell, r, c);
|
||||
checkBlank(cellValue, r, c);
|
||||
checkPhone(cellValue, r, c);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -471,12 +470,12 @@ public class TbPeopleServiceImpl implements TbPeopleService {
|
|||
|
||||
/**
|
||||
* 检查数据是否为空
|
||||
* @param cell
|
||||
* @param cellValue
|
||||
* @param rowIndex
|
||||
* @param colIndex
|
||||
*/
|
||||
private void checkBlank(Cell cell, int rowIndex, int colIndex) {
|
||||
if (cell == null) {
|
||||
private void checkBlank(String cellValue, int rowIndex, int colIndex) {
|
||||
if (StringUtils.isBlank(cellValue)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("第 %d 行,第 %d 列数据为空,请检查后重新导入", rowIndex + 1, colIndex + 1));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,12 +201,28 @@ public class TbProPowerServiceImpl implements TbProPowerService {
|
|||
}
|
||||
//读取Excel表格数据,做非空判断
|
||||
// 循环Excel行数
|
||||
DataFormatter dataFormatter = new DataFormatter();
|
||||
for (int r = 1; r < totalRows; r++) {
|
||||
Row row = sheet.getRow(r);
|
||||
// 循环Excel列数
|
||||
for (int c = 0; c < totalCells; c++) {
|
||||
Cell cell = row.getCell(c);
|
||||
checkCellNotEmpty(cell, r + 1, c + 1);
|
||||
String cellValue = dataFormatter.formatCellValue(row.getCell(c));
|
||||
switch (c) {
|
||||
case 0:
|
||||
checkCellNotEmpty(cellValue, r, c);
|
||||
break;
|
||||
case 1:
|
||||
checkCellNotEmpty(cellValue, r, c);
|
||||
checkLON(cellValue, r, c);
|
||||
break;
|
||||
case 2:
|
||||
checkCellNotEmpty(cellValue, r, c);
|
||||
checklAT(cellValue, r, c);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
String.format("第 %d 行,第 %d 列超出范围,请检查后重新导入", r + 1, c + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
ExcelUtil<TbProPower> util = new ExcelUtil<>(TbProPower.class);
|
||||
|
|
@ -234,15 +250,54 @@ public class TbProPowerServiceImpl implements TbProPowerService {
|
|||
return AjaxResult.error(ExceptionEnum.SAVE_TO_DATABASE.getCode(), ExceptionEnum.SAVE_TO_DATABASE.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查纬度格式
|
||||
* @param cellValue
|
||||
* @param r
|
||||
* @param c
|
||||
*/
|
||||
private void checklAT(String cellValue, int r, int c) {
|
||||
try {
|
||||
boolean b = cellValue.matches(Constants.LATITUDE_PATTERN);
|
||||
if (!b) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("第 %d 行,第 %d 列纬度格式不正确,请检查后重新导入", r + 1, c + 1));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("第 %d 行,第 %d 列纬度格式不正确,请检查后重新导入", r + 1, c + 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查经度格式
|
||||
* @param cellValue
|
||||
* @param rowIndex
|
||||
* @param colIndex
|
||||
*/
|
||||
private void checkLON(String cellValue, int rowIndex, int colIndex) {
|
||||
try {
|
||||
boolean b = cellValue.matches(Constants.LONGITUDE_PATTERN);
|
||||
if (!b) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("第 %d 行,第 %d 列经度格式不正确,请检查后重新导入", rowIndex + 1, colIndex + 1));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("第 %d 行,第 %d 列经度格式不正确,请检查后重新导入", rowIndex + 1, colIndex + 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取方法用于检查单元格内容是否为空,并抛出异常
|
||||
* @param cell
|
||||
* @param cellValue
|
||||
* @param rowNum
|
||||
* @param colNum
|
||||
*/
|
||||
private void checkCellNotEmpty(Cell cell, int rowNum, int colNum) {
|
||||
if (cell == null) {
|
||||
throw new IllegalArgumentException("Excel中第 " + rowNum + " 行第 " + colNum + " 列数据为空,请检查后重新导入");
|
||||
private void checkCellNotEmpty(String cellValue, int rowNum, int colNum) {
|
||||
if (StringUtils.isBlank(cellValue)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("第 %d 行,第 %d 列数据为空,请检查后重新导入", rowNum + 1, colNum + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue