Commit 3a83a94e authored by jichao's avatar jichao

项目管理--导入参数库bug

parent 46c282bd
...@@ -115,7 +115,6 @@ public class ParamLibraryController { ...@@ -115,7 +115,6 @@ public class ParamLibraryController {
// @ApiImplicitParams({@ApiImplicitParam(name = "devNum", value = "设备编号", required = true, dataType = "字符串")}) // @ApiImplicitParams({@ApiImplicitParam(name = "devNum", value = "设备编号", required = true, dataType = "字符串")})
@RequestMapping("/uploadExcel") @RequestMapping("/uploadExcel")
public Result uploadExcel(@RequestParam MultipartFile file, @RequestParam String devNum) { public Result uploadExcel(@RequestParam MultipartFile file, @RequestParam String devNum) {
Integer result = paramLibraryService.uploadExcel(file, devNum); return Result.builder(paramLibraryService.uploadExcel(file, devNum));
return Result.builder(new PersistModel(result), MessageConstant.MESSAGE_ALERT_SUCCESS, "没有可以保存的数据", result);
} }
} }
...@@ -37,5 +37,5 @@ public interface ParamLibraryService { ...@@ -37,5 +37,5 @@ public interface ParamLibraryService {
* @param devNum * @param devNum
* @return * @return
*/ */
Integer uploadExcel(MultipartFile file, String devNum); PersistModel uploadExcel(MultipartFile file, String devNum);
} }
...@@ -170,10 +170,13 @@ public class ParamLibraryServiceImpl implements ParamLibraryService { ...@@ -170,10 +170,13 @@ public class ParamLibraryServiceImpl implements ParamLibraryService {
@Transactional @Transactional
@Override @Override
public Integer uploadExcel(MultipartFile file, String devNum) { public PersistModel uploadExcel(MultipartFile file, String devNum) {
// 返回值
Integer resultCount = 0;
String resultMsg = "";
HSSFWorkbook workbook = null; HSSFWorkbook workbook = null;
List<BusParamLibrary> resultList = new ArrayList<>(); List<BusParamLibrary> resultList = new ArrayList<>();
int result = 0; // int result = 0;
try(InputStream is = file.getInputStream()) { try(InputStream is = file.getInputStream()) {
workbook = new HSSFWorkbook(is); workbook = new HSSFWorkbook(is);
//读取sheet //读取sheet
...@@ -187,7 +190,10 @@ public class ParamLibraryServiceImpl implements ParamLibraryService { ...@@ -187,7 +190,10 @@ public class ParamLibraryServiceImpl implements ParamLibraryService {
excel_devNum = this.getValue(first_row.getCell(1)); excel_devNum = this.getValue(first_row.getCell(1));
year = this.getValue(first_row.getCell(4)); year = this.getValue(first_row.getCell(4));
//如果不等于页面传来的值,直接返回 //如果不等于页面传来的值,直接返回
if (!StringUtils.equals(excel_devNum, devNum)) return result; if (!StringUtils.equals(excel_devNum, devNum)) {
resultMsg = "设备编号不一致";
return new PersistModel(resultCount, resultMsg);
}
} }
//取得4个参数 //取得4个参数
String param1 = this.getCode(sheet, 3, 2), String param1 = this.getCode(sheet, 3, 2),
...@@ -243,6 +249,40 @@ public class ParamLibraryServiceImpl implements ParamLibraryService { ...@@ -243,6 +249,40 @@ public class ParamLibraryServiceImpl implements ParamLibraryService {
String param4Value = this.getValue(row.getCell(6));//参数4 String param4Value = this.getValue(row.getCell(6));//参数4
//如果都为null,表明已经没有数据,跳出循环 //如果都为null,表明已经没有数据,跳出循环
if (StringUtils.isEmpty(power) && StringUtils.isEmpty(speed) && StringUtils.isEmpty(param1Value) && StringUtils.isEmpty(param2Value) && StringUtils.isEmpty(param3Value) && StringUtils.isEmpty(param4Value)) break; if (StringUtils.isEmpty(power) && StringUtils.isEmpty(speed) && StringUtils.isEmpty(param1Value) && StringUtils.isEmpty(param2Value) && StringUtils.isEmpty(param3Value) && StringUtils.isEmpty(param4Value)) break;
// 判断输入的内容,错误的输入方式不保存直接退出
// 功率不能为空
if (power == null) {
resultMsg = "功率不能为空";
return new PersistModel(resultCount, resultMsg);
}
// 主参数1不能为空
if (param1Value == null) {
resultMsg = "参数1的值不能为空";
return new PersistModel(resultCount, resultMsg);
}
// 当存在4个参数的时候,四个参数均不能为空
if (param2 != null) {
if (param2Value == null || param3Value == null || param4Value == null) {
resultMsg = "参数为4个时,参数值均不能为空";
return new PersistModel(resultCount, resultMsg);
}
} else {
// 当存在3个以下参数的时候
// 当存在3个参数时,参数3,4不能为空
if (param3 != null && param4 != null) {
if (param3Value == null || param4Value == null) {
resultMsg = "参数为3个时,参数3、4的值不能为空";
return new PersistModel(resultCount, resultMsg);
}
}
// 当存在2个参数时,参数3不能为空
if (param3 != null) {
if (param3Value == null) {
resultMsg = "参数为2个时,参数3的值不能为空";
return new PersistModel(resultCount, resultMsg);
}
}
}
//赋值 //赋值
b.setDevNum(devNum); b.setDevNum(devNum);
b.setPower(StringUtils.isEmpty(power) ? null : new BigDecimal(power)); b.setPower(StringUtils.isEmpty(power) ? null : new BigDecimal(power));
...@@ -293,7 +333,7 @@ public class ParamLibraryServiceImpl implements ParamLibraryService { ...@@ -293,7 +333,7 @@ public class ParamLibraryServiceImpl implements ParamLibraryService {
criteria_BusEnergyplanV.andGreaterThanOrEqualTo("tm", date); criteria_BusEnergyplanV.andGreaterThanOrEqualTo("tm", date);
busEnergyplanVRepository.deleteByExample(example_BusEnergyplanV); busEnergyplanVRepository.deleteByExample(example_BusEnergyplanV);
//添加 //添加
result = paramLibraryRepository.saveBusParamLibraryList(resultList); resultCount = paramLibraryRepository.saveBusParamLibraryList(resultList);
} }
} }
} catch (IOException e) { } catch (IOException e) {
...@@ -305,7 +345,7 @@ public class ParamLibraryServiceImpl implements ParamLibraryService { ...@@ -305,7 +345,7 @@ public class ParamLibraryServiceImpl implements ParamLibraryService {
e.printStackTrace(); e.printStackTrace();
} }
} }
return result; return new PersistModel(resultCount, resultMsg);
} }
/** /**
......
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