feat: 车型项目导入
This commit is contained in:
+18
-1
@@ -18,6 +18,7 @@ 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;
|
||||
@@ -196,6 +197,21 @@ 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")
|
||||
@@ -203,7 +219,8 @@ public class ProcessStandardComplianceCheckController extends JeroController<Pro
|
||||
Map<String, Object> resultMap = sccService.importExcelWithData(file);
|
||||
Object flag = resultMap.get("flag");
|
||||
if (flag == YesOrNoEnum.YES.getValue()) {
|
||||
List<ProcessStandardComplianceCheckDetail> dataList = (List<ProcessStandardComplianceCheckDetail>) resultMap.get("dataList");
|
||||
List<ProcessStandardComplianceCheckDetail> dataList = (List<ProcessStandardComplianceCheckDetail>)
|
||||
resultMap.get("dataList");
|
||||
return Result.OK(dataList);
|
||||
} else {
|
||||
List<String> msg = (List<String>) resultMap.get("msg");
|
||||
|
||||
+2
@@ -19,6 +19,8 @@ public class ModelExcelVO {
|
||||
@Excel(name = "车型状态", dicCode = "model_status")
|
||||
private String modelState;
|
||||
|
||||
private String sort;
|
||||
|
||||
public boolean emptyRowOrNot() {
|
||||
ModelExcelVO modelExcel = this;
|
||||
return modelExcel.getModel() == null && modelExcel.getModelState() == null;
|
||||
|
||||
+2
@@ -36,4 +36,6 @@ public interface IProcessStandardComplianceCheckService extends IService<Process
|
||||
void exportXlsWithoutDistribute(String taskId, HttpServletResponse response);
|
||||
|
||||
Map<String, Object> importExcelWithData(MultipartFile file) throws IOException;
|
||||
|
||||
Map<String, Object> importExcelModel(MultipartFile file) throws IOException;
|
||||
}
|
||||
|
||||
+95
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -670,6 +671,100 @@ 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;
|
||||
Iterator<ModelExcelVO> iterator = list.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ModelExcelVO data = iterator.next();
|
||||
if (ExcelUtils.isEmptyRow(data)) {
|
||||
iterator.remove();
|
||||
if (list.isEmpty()) {
|
||||
errorMsgs.add("文件暂无数据,请检查后重试。");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
String modelState = data.getModelState();
|
||||
|
||||
StringBuilder errMsgHeader = new StringBuilder();
|
||||
StringBuilder errMsg = new StringBuilder();
|
||||
data.setSort(String.valueOf(i++));
|
||||
errMsgHeader.append("第").append(data.getSort()).append("行");
|
||||
|
||||
// 检查所有数据字典校验的字段
|
||||
errMsg.append(excelUtils.validModelState(modelState, listDict));
|
||||
// 如果数据有问题,则将提示信息添加到 errorMsgs 中
|
||||
if (errMsg.length() > 0) {
|
||||
errorMsgs.add(errMsgHeader.append(errMsg).toString());
|
||||
}
|
||||
}
|
||||
return errorMsgs;
|
||||
}
|
||||
|
||||
private void cleanData(List<WithoutDistributeExcelTemplate> list) {
|
||||
list.forEach(item -> {
|
||||
String result = item.getResult();
|
||||
|
||||
@@ -612,4 +612,15 @@ public class ExcelUtils {
|
||||
}
|
||||
return importUtil.convertFileIds(material, fileMap);
|
||||
}
|
||||
|
||||
public String validModelState(String value, List<SysDictItemCore> listDict) {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
return "";
|
||||
}
|
||||
// 检查排查结果
|
||||
if (!excelUtils.validDict("model_state", value, null, null, true, listDict)) {
|
||||
return "'车型状态'无效。";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user