feat: scc流程导入校验

This commit is contained in:
2024-08-01 11:02:51 +08:00
parent c3a6c177f4
commit 730d925798
7 changed files with 40 additions and 92 deletions
@@ -18,7 +18,6 @@ import com.jero.modules.activiti.process.standardComplianceCheck.entity.vo.Model
import com.jero.modules.activiti.process.standardComplianceCheck.entity.vo.ProcessSccVO;
import com.jero.modules.activiti.process.standardComplianceCheck.entity.vo.SplitExcelVO;
import com.jero.modules.activiti.process.standardComplianceCheck.service.IProcessStandardComplianceCheckService;
import com.jero.modules.oss.entity.OSSFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -197,21 +196,6 @@ public class ProcessStandardComplianceCheckController extends JeroController<Pro
sccService.exportXlsWithoutDistribute(taskId, response);
}
@AutoLog(value = "法规符合性排查流程-导入车型项目")
@ApiOperation(value="法规符合性排查流程-导入车型项目", notes="法规符合性排查流程-导入车型项目")
@PostMapping("/importExcelModel")
public Result<?> importExcelModel(@RequestParam("file") @ApiParam("文件") MultipartFile file) throws IOException {
Map<String, Object> resultMap = sccService.importExcelModel(file);
Object flag = resultMap.get("flag");
if (flag == YesOrNoEnum.YES.getValue()) {
Result<OSSFile> result = (Result<OSSFile>)resultMap.get("result");
return Result.OK(result);
} else {
List<String> msg = (List<String>) resultMap.get("msg");
return Result.error(MessageUtils.getMessage(ResultCommon.IMPORT_ERROR), msg);
}
}
@AutoLog(value = "法规符合性排查流程-导入")
@ApiOperation(value="法规符合性排查流程-导入", notes="法规符合性排查流程-导入")
@PostMapping("/importExcelWithData")
@@ -37,5 +37,4 @@ public interface IProcessStandardComplianceCheckService extends IService<Process
Map<String, Object> importExcelWithData(MultipartFile file) throws IOException;
Map<String, Object> importExcelModel(MultipartFile file) throws IOException;
}
@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.CommonAPI;
import com.jero.common.api.vo.Result;
import com.jero.common.api.vo.ResultCommon;
import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.exception.JeroBootException;
@@ -671,70 +670,6 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
return resultMap;
}
@Override
public Map<String, Object> importExcelModel(MultipartFile file) {
List<SysDictItemCore> listDict = commonAPI.getDictItemAll();
Map<String, Object> resultMap = new HashMap<>();
List<String> errorMsgs = new ArrayList<>();
// 获取Excel的header
List<String> headers;
try {
headers = ExcelUtils.getHeaderFromExcel(file.getInputStream(), 0);
} catch (Exception e) {
errorMsgs.add("模板错误,请按照系统模板导入!");
resultMap.put("msg", errorMsgs);
resultMap.put("flag", YesOrNoEnum.NO.getValue());
log.error(e.getMessage(), e);
return resultMap; // 返回错误信息
}
// 使用静态方法验证header
boolean isMatched = headers.equals(ExcelUtils.getSortedHeadersFromClass(ModelExcelVO.class));
if (!isMatched) {
errorMsgs.add("模板错误,请按照系统模板导入!");
resultMap.put("msg", errorMsgs);
resultMap.put("flag", YesOrNoEnum.NO.getValue());
return resultMap; // 返回错误信息
}
ImportParams params = new ImportParams();
params.setTitleRows(0);
params.setHeadRows(1);
params.setNeedSave(true);
try {
@Cleanup
InputStream inputStream = file.getInputStream();
List<ModelExcelVO> list = ExcelImportUtil.importExcel(inputStream, ModelExcelVO.class, params);
list.remove(0);
list.remove(0);
if (list.isEmpty()) {
errorMsgs.add("文件暂无数据,请检查后重试。");
resultMap.put("msg", errorMsgs);
resultMap.put("flag", YesOrNoEnum.NO.getValue());
return resultMap; // 返回错误信息
}
// 批量检查数据是否有效
errorMsgs = this.validationModelList(list, listDict);
if (!errorMsgs.isEmpty()) {
resultMap.put("msg", errorMsgs);
resultMap.put("flag", YesOrNoEnum.NO.getValue());
} else {
resultMap.put("flag", YesOrNoEnum.YES.getValue());
// 保存文件数据
Result<OSSFile> result = ossFileService.commonUpload(file, "sccProcess");
resultMap.put("result", result);
}
} catch (Exception e) {
errorMsgs.add("文件导入异常:" + e.getMessage());
resultMap.put("msg", errorMsgs);
resultMap.put("flag", YesOrNoEnum.NO.getValue());
log.error(e.getMessage(), e);
}
return resultMap;
}
private List<String> validationModelList(List<ModelExcelVO> list, List<SysDictItemCore> listDict) {
List<String> errorMsgs = new ArrayList<>();
int i = 4;
@@ -1070,6 +1005,8 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
* @return
*/
private List<ProcessStandardComplianceCheckDetail> getSplitData(ProcessStandardComplianceCheck scc, MultipartFile splitFile) {
// 校验拆分数据
List<ProcessStandardComplianceCheckDetail> result = new ArrayList<>();
// 是否上传分解单
if (splitFile == null) {
@@ -1101,11 +1038,11 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
headers = ExcelUtils.getHeaderFromExcel(splitFile.getInputStream());
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new JeroBootException("上传模板错误,请检查后重试。");
throw new JeroBootException(ResultCommon.SPLIT_IMPORT_TEMPLATE_ERROR);
}
boolean isMatched = SplitExcelVO.validateExcelHeaders(headers);
if (!isMatched) {
throw new JeroBootException("上传模板错误,请检查后重试。");
throw new JeroBootException(ResultCommon.SPLIT_IMPORT_TEMPLATE_ERROR);
}
ImportParams params = new ImportParams();
params.setHeadRows(0);
@@ -1114,11 +1051,11 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
try {
splitExcelVOList = ExcelImportUtil.importExcel(splitFile.getInputStream(), SplitExcelVO.class, params);
if (splitExcelVOList.isEmpty()) {
throw new JeroBootException("文件导入失败:数据为空");
throw new JeroBootException(ResultCommon.FILE_EMPTY_IMPORT_ERROR);
}
} catch (Exception e) {
log.error("文件导入异常:" + e.getMessage(), e);
throw new JeroBootException("文件导入失败:" + e.getMessage());
log.error("分解单文件导入异常:" + e.getMessage(), e);
throw new JeroBootException(ResultCommon.SPLIT_IMPORT_TEMPLATE_ERROR);
}
List<ProcessStandardComplianceCheckDetail> result = BeanCopyUtils.copyBeanList(splitExcelVOList, ProcessStandardComplianceCheckDetail.class);
result.forEach(detail -> detail.setCheckId(sccId));
@@ -1126,17 +1063,19 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
}
private List<ModelExcelVO> getModelExcelData(MultipartFile file) {
List<SysDictItemCore> listDict = commonAPI.getDictItemAll();
List<String> errorMsgs;
// 获取Excel的header
List<String> headers;
try {
headers = ExcelUtils.getHeaderFromExcel(file.getInputStream());
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new JeroBootException("上传模板错误,请检查后重试。");
throw new JeroBootException(ResultCommon.MODEL_IMPORT_TEMPLATE_ERROR);
}
boolean isMatched = ModelExcelVO.validateExcelHeaders(headers);
if (!isMatched) {
throw new JeroBootException("上传模板错误,请检查后重试。");
throw new JeroBootException(ResultCommon.MODEL_IMPORT_TEMPLATE_ERROR);
}
ImportParams params = new ImportParams();
params.setHeadRows(0);
@@ -1145,12 +1084,19 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
try {
modelExcelVOList = ExcelImportUtil.importExcel(file.getInputStream(), ModelExcelVO.class, params);
if (modelExcelVOList.isEmpty()) {
throw new JeroBootException("文件导入失败:数据为空");
throw new JeroBootException(ResultCommon.FILE_EMPTY_IMPORT_ERROR);
}
} catch (Exception e) {
log.error("文件导入异常:" + e.getMessage(), e);
throw new JeroBootException("文件导入失败:" + e.getMessage());
log.error("车型项目文件导入异常:" + e.getMessage(), e);
throw new JeroBootException(ResultCommon.MODEL_IMPORT_TEMPLATE_ERROR);
}
// 批量检查数据是否有效
errorMsgs = this.validationModelList(modelExcelVOList, listDict);
if (!errorMsgs.isEmpty()) {
String errorMsg = String.join("<br>", errorMsgs);
throw new JeroBootException(ResultCommon.MODEL_IMPORT_DATA_ERROR, errorMsg);
}
return modelExcelVOList;
}