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
@@ -198,5 +198,12 @@ public class ResultCommon {
public static final String DATA_DOES_NOT_EXIST = "data.does.not.exist";
// 第{0}行
public static final String ROW_N_IMPORT = "row.n.import";
// 分解单上传模板错误,请检查后重试
public static final String SPLIT_IMPORT_TEMPLATE_ERROR = "split.import.template.error";
// 车型文件上传模板错误,请检查后重试
public static final String MODEL_IMPORT_TEMPLATE_ERROR = "model.import.template.error";
public static final String MODEL_IMPORT_DATA_ERROR = "model.import.data.error";
public static final String FILE_EMPTY_IMPORT_ERROR = "file.empty.import.error";
}
@@ -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;
}
@@ -80,3 +80,7 @@ message.no.exists.standard=\u6807\u51C6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u8054\u7CF
scc.delete.standard.error=\u6CD5\u89C4\u7B26\u5408\u6027\u6392\u67E5\u6D41\u7A0B\u6709\u6B63\u5728\u8FDB\u884C\u4E2D\u7684\u6D41\u7A0B\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664
scc.delete.standard.error2=\u6807\u51C6\u6709\u88AB\u62C6\u5206\u7684\u6570\u636E\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664
scc.delete.standard.error3=\u6807\u51C6\u89E3\u8BFB\u6D41\u7A0B\u6709\u6B63\u5728\u8FDB\u884C\u4E2D\u7684\u6D41\u7A0B\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664
split.import.template.error=\u5206\u89E3\u5355\u4E0A\u4F20\u6A21\u677F\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5
model.import.template.error=\u8F66\u578B\u6587\u4EF6\u4E0A\u4F20\u6A21\u677F\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5
model.import.data.error=\u8F66\u578B\u6587\u4EF6\u4E0A\u4F20\u6570\u636E\u9519\u8BEF\u3002{0}
FILE_EMPTY_IMPORT_ERROR=\u6587\u4EF6\u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5
@@ -96,3 +96,7 @@ row.n.import=Row {0}
scc.delete.standard.error=The standard has been used by the Standard Compliance Check Process, can not delete
scc.delete.standard.error2=Standards have split data, can not delete
scc.delete.standard.error3=The standard interpretation process has ongoing processes, can not delete
split.import.template.error=Split import template error
model.import.template.error=Model import template error
model.import.data.error=Model import data error.{0}
FILE_EMPTY_IMPORT_ERROR=The file is empty, please upload again
@@ -95,3 +95,7 @@ row.n.import=\u7B2C{0}\u884C
scc.delete.standard.error=\u6709\u6B63\u5728\u8FDB\u884C\u4E2D\u7684\u6CD5\u89C4\u7B26\u5408\u6027\u6392\u67E5\u6D41\u7A0B\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664
scc.delete.standard.error2=\u6807\u51C6\u6709\u88AB\u62C6\u5206\u7684\u6570\u636E\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664
scc.delete.standard.error3=\u6807\u51C6\u89E3\u8BFB\u6D41\u7A0B\u6709\u6B63\u5728\u8FDB\u884C\u4E2D\u7684\u6D41\u7A0B\uFF0C\u4E0D\u5141\u8BB8\u5220\u9664
split.import.template.error=\u5206\u89E3\u5355\u4E0A\u4F20\u6A21\u677F\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5
model.import.template.error=\u8F66\u578B\u6587\u4EF6\u4E0A\u4F20\u6A21\u677F\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5
model.import.data.error=\u8F66\u578B\u6587\u4EF6\u4E0A\u4F20\u6570\u636E\u9519\u8BEF\u3002{0}
FILE_EMPTY_IMPORT_ERROR=\u6587\u4EF6\u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5