feat: 车型项目导入
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package com.jero.modules.oss.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public interface IOSSFileService extends IService<OSSFile> {
|
||||
|
||||
void upload(MultipartFile multipartFile) throws IOException;
|
||||
@@ -27,4 +28,9 @@ public interface IOSSFileService extends IService<OSSFile> {
|
||||
void updateFileInfo(List<OSSFile> ossFileList);
|
||||
|
||||
OSSFile uploadLocalOfCos(MultipartFile mf, String bizPath, String state, String cut);
|
||||
|
||||
Result<OSSFile> outUpload(HttpServletRequest request);
|
||||
|
||||
Result<OSSFile> commonUpload(MultipartFile file, String bizPath);
|
||||
|
||||
}
|
||||
|
||||
+70
@@ -2,11 +2,14 @@ package com.jero.modules.oss.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.CommonUtils;
|
||||
import com.jero.common.util.MinioUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.common.util.obs.ObsBootUtil;
|
||||
import com.jero.common.util.oss.OssBootUtil;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
@@ -19,7 +22,9 @@ import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@@ -29,6 +34,11 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
|
||||
private String uploadpath;
|
||||
@Value(value = "${jero.path.uploadCos}")
|
||||
private String uploadCospath;
|
||||
/**
|
||||
* 本地:local minio:minio 阿里:alioss
|
||||
*/
|
||||
@Value(value = "${jero.uploadType}")
|
||||
private String uploadType;
|
||||
/**
|
||||
* 文件后缀黑名单
|
||||
*/
|
||||
@@ -335,4 +345,64 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
|
||||
oSSFile.setUrl(null);
|
||||
return oSSFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<OSSFile> outUpload(HttpServletRequest request) {
|
||||
Result<OSSFile> result = new Result<>();
|
||||
String savePath = "";
|
||||
String bizPath = request.getParameter("biz");
|
||||
|
||||
//sys/common/upload接口存在任意文件上传漏洞
|
||||
if (oConvertUtils.isNotEmpty(bizPath) && (bizPath.contains("../") || bizPath.contains("..\\"))) {
|
||||
throw new JeroBootException("上传目录bizPath,格式非法!");
|
||||
}
|
||||
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = multipartRequest.getFile("file");
|
||||
if (file == null) {
|
||||
return result;
|
||||
}
|
||||
return commonUpload(file, bizPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<OSSFile> commonUpload(MultipartFile file, String bizPath) {
|
||||
Result<OSSFile> result = new Result<>();
|
||||
String savePath = "";
|
||||
// 文件类型是否处于黑名单
|
||||
if (CommonUtils.limitFileSuffix(file.getOriginalFilename(), fileSuffixLimits)) {
|
||||
result.setMessage("该文件类型不允许上传");
|
||||
result.setSuccess(false);
|
||||
result.setCode(0);
|
||||
return result;
|
||||
}
|
||||
if (oConvertUtils.isEmpty(bizPath)) {
|
||||
bizPath = "";
|
||||
}
|
||||
if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
|
||||
// 本地上传
|
||||
savePath = CommonUtils.uploadLocal(file, bizPath, uploadpath);
|
||||
} else {
|
||||
// minio上传
|
||||
savePath = CommonUtils.upload(file, bizPath, uploadType);
|
||||
}
|
||||
if (oConvertUtils.isNotEmpty(savePath)) {
|
||||
//上传成功 进行数据库存储
|
||||
OSSFile ossFile = new OSSFile();
|
||||
// 文件名
|
||||
String fileName = file.getOriginalFilename();
|
||||
fileName = CommonUtils.getFileName(fileName);
|
||||
ossFile.setFileName(fileName);
|
||||
ossFile.setUrl(savePath);
|
||||
this.save(ossFile);
|
||||
result.setMessage(savePath);
|
||||
result.setResult(ossFile);
|
||||
result.setSuccess(true);
|
||||
} else {
|
||||
result.setMessage("上传失败!");
|
||||
result.setSuccess(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-55
@@ -1,7 +1,5 @@
|
||||
package com.jero.modules.system.controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -9,12 +7,14 @@ import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.util.*;
|
||||
import com.jero.common.util.MinioUtil;
|
||||
import com.jero.common.util.RestUtil;
|
||||
import com.jero.common.util.TokenUtils;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.common.util.obs.ObsBootUtil;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.modules.system.util.SysWaterMarkUtil;
|
||||
import com.jero.modules.system.util.UserUtils;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -25,8 +25,6 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@@ -95,55 +93,7 @@ public class CommonController {
|
||||
*/
|
||||
@PostMapping(value = "/upload")
|
||||
public Result<OSSFile> upload(HttpServletRequest request, HttpServletResponse response) {
|
||||
Result<OSSFile> result = new Result<>();
|
||||
String savePath = "";
|
||||
String bizPath = request.getParameter("biz");
|
||||
|
||||
//sys/common/upload接口存在任意文件上传漏洞
|
||||
if (oConvertUtils.isNotEmpty(bizPath) && (bizPath.contains("../") || bizPath.contains("..\\"))) {
|
||||
throw new JeroBootException("上传目录bizPath,格式非法!");
|
||||
}
|
||||
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = multipartRequest.getFile("file");
|
||||
if (file == null) {
|
||||
return result;
|
||||
}
|
||||
// 文件类型是否处于黑名单
|
||||
if (CommonUtils.limitFileSuffix(file.getOriginalFilename(), fileSuffixLimits)) {
|
||||
result.setMessage("该文件类型不允许上传");
|
||||
result.setSuccess(false);
|
||||
result.setCode(0);
|
||||
return result;
|
||||
}
|
||||
if (oConvertUtils.isEmpty(bizPath)) {
|
||||
bizPath = "";
|
||||
}
|
||||
if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
|
||||
// 本地上传
|
||||
savePath = CommonUtils.uploadLocal(file, bizPath, uploadpath);
|
||||
} else {
|
||||
// minio上传
|
||||
savePath = CommonUtils.upload(file, bizPath, uploadType);
|
||||
}
|
||||
if (oConvertUtils.isNotEmpty(savePath)) {
|
||||
//上传成功 进行数据库存储
|
||||
OSSFile ossFile = new OSSFile();
|
||||
// 文件名
|
||||
String fileName = file.getOriginalFilename();
|
||||
fileName = CommonUtils.getFileName(fileName);
|
||||
ossFile.setFileName(fileName);
|
||||
ossFile.setUrl(savePath);
|
||||
ossFileService.save(ossFile);
|
||||
result.setMessage(savePath);
|
||||
result.setResult(ossFile);
|
||||
result.setSuccess(true);
|
||||
} else {
|
||||
result.setMessage("上传失败!");
|
||||
result.setSuccess(false);
|
||||
}
|
||||
return result;
|
||||
return ossFileService.outUpload(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+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