Merge remote-tracking branch 'origin/master'

This commit is contained in:
guofeihu
2024-08-23 11:16:25 +08:00
3 changed files with 108 additions and 14 deletions

View File

@@ -84,6 +84,8 @@ public enum CommonResponseEnum {
FILE_EXIST("A0096", "文件已存在"), FILE_EXIST("A0096", "文件已存在"),
FILE_NAME_ERROR("A0096", "文件格式有误"),
FILE_SIZE_ERROR("A0096", "文件过大"), FILE_SIZE_ERROR("A0096", "文件过大"),
FILE_XLSX_ERROR("A0096", "请上传excel文件"), FILE_XLSX_ERROR("A0096", "请上传excel文件"),

View File

@@ -1,6 +1,7 @@
package com.njcn.common.utils; package com.njcn.common.utils;
import cn.hutool.core.text.StrPool; import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -56,5 +57,90 @@ public class FileUtil {
} }
} }
/**
* 判断文件是否为word格式
*
* @param fileName 文件名
*/
public static boolean judgeFileIsWord(String fileName) {
// 检查文件名是否为空
if (StrUtil.isBlank(fileName)) {
return false;
}
// 获取文件扩展名
String fileExtension = getFileExtension(fileName);
// 定义支持的文件类型
String[] allowedExtensions = {"doc", "docx"};
// 检查扩展名是否在允许的列表中
for (String ext : allowedExtensions) {
if (ext.equalsIgnoreCase(fileExtension)) {
return true;
}
}
return false;
}
/**
* 判断文件是否为pdf格式
*
* @param fileName 文件名
*/
public static boolean judgeFileIsPdf(String fileName) {
// 检查文件名是否为空
if (StrUtil.isBlank(fileName)) {
return false;
}
// 获取文件扩展名
String fileExtension = getFileExtension(fileName);
// 定义支持的文件类型
String[] allowedExtensions = {"pdf"};
// 检查扩展名是否在允许的列表中
for (String ext : allowedExtensions) {
if (ext.equalsIgnoreCase(fileExtension)) {
return true;
}
}
return false;
}
/**
* 判断文件是否为excel格式
*
* @param fileName 文件名
*/
public static boolean judgeFileIsExcel(String fileName) {
// 检查文件名是否为空
if (StrUtil.isBlank(fileName)) {
return false;
}
// 获取文件扩展名
String fileExtension = getFileExtension(fileName);
// 定义支持的文件类型
String[] allowedExtensions = {"xls", "xlsx"};
// 检查扩展名是否在允许的列表中
for (String ext : allowedExtensions) {
if (ext.equalsIgnoreCase(fileExtension)) {
return true;
}
}
return false;
}
/**
* 从文件名中提取扩展名
*
* @param fileName 文件名
* @return 扩展名
*/
private static String getFileExtension(String fileName) {
int dotIndex = fileName.lastIndexOf('.');
if (dotIndex == -1) {
return "";
}
return fileName.substring(dotIndex + 1);
}
} }

View File

@@ -9,6 +9,7 @@ import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.FileUtil;
import com.njcn.common.utils.HttpResultUtil; import com.njcn.common.utils.HttpResultUtil;
import com.njcn.process.pojo.param.SupvAlarmParam; import com.njcn.process.pojo.param.SupvAlarmParam;
import com.njcn.process.pojo.param.SupvFileParam; import com.njcn.process.pojo.param.SupvFileParam;
@@ -47,40 +48,45 @@ public class SupvFileController extends BaseController {
@PostMapping("planUpload") @PostMapping("planUpload")
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.UPLOAD) @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
@ApiOperation("监督计划问题附件上传") @ApiOperation("监督计划问题附件上传")
public HttpResult<Object> planUpload(@ApiParam(value = "文件", required = true) @RequestPart("files") MultipartFile file, public HttpResult<Object> planUpload(@ApiParam(value = "文件", required = true) @RequestPart("files") MultipartFile file,
@RequestParam("planId") String planId, @RequestParam("planId") String planId,
@RequestParam("type") Integer type, @RequestParam("type") Integer type,
@RequestParam("uploaderId") String uploaderId, @RequestParam("uploaderId") String uploaderId,
@RequestParam("uploaderName") String uploaderName, @RequestParam("uploaderName") String uploaderName,
@RequestParam("attachmentType")String attachmentType, @RequestParam("attachmentType") String attachmentType,
@RequestParam("uploadTime")String uploadTime @RequestParam("uploadTime") String uploadTime
){ ) {
String methodDescribe = getMethodDescribe("planUpload"); String methodDescribe = getMethodDescribe("planUpload");
if(!StrUtil.isAllNotBlank(planId,uploaderId,uploaderName,attachmentType,uploadTime)||type==null){ String originalFilename = file.getOriginalFilename();
if (FileUtil.judgeFileIsWord(originalFilename) || FileUtil.judgeFileIsPdf(originalFilename) || FileUtil.judgeFileIsExcel(originalFilename)) {
if (!StrUtil.isAllNotBlank(planId, uploaderId, uploaderName, attachmentType, uploadTime) || type == null) {
throw new BusinessException("必填字段不能为空"); throw new BusinessException("必填字段不能为空");
} }
iSupvFileService.planUpload(file,planId,type,uploaderId,uploaderName,attachmentType,uploadTime); iSupvFileService.planUpload(file, planId, type, uploaderId, uploaderName, attachmentType, uploadTime);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FILE_NAME_ERROR, null, methodDescribe);
}
@PostMapping("list") @PostMapping("list")
@OperateInfo(info = LogEnum.BUSINESS_COMMON) @OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("查询附件信息集合") @ApiOperation("查询附件信息集合")
@ApiImplicitParam(name = "param",value = "请求体",required = true) @ApiImplicitParam(name = "param", value = "请求体", required = true)
public HttpResult<List<SupvFile>> pageAlarm(@RequestBody SupvFileParam param){ public HttpResult<List<SupvFile>> pageAlarm(@RequestBody SupvFileParam param) {
String methodDescribe = getMethodDescribe("pageAlarm"); String methodDescribe = getMethodDescribe("pageAlarm");
List<SupvFile> supvFiles = iSupvFileService.listFile(param); List<SupvFile> supvFiles = iSupvFileService.listFile(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, supvFiles, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, supvFiles, methodDescribe);
} }
@PostMapping("detail") @PostMapping("detail")
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.DOWNLOAD) @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
@ApiOperation("监督计划问题附件下载") @ApiOperation("监督计划问题附件下载")
public HttpResult<Object> detail(HttpServletResponse response, @RequestParam("busId") String busId, @RequestParam("type") Integer type,@RequestParam("attachmentType") String attachmentType){ public HttpResult<Object> detail(HttpServletResponse response, @RequestParam("busId") String busId, @RequestParam("type") Integer type, @RequestParam("attachmentType") String attachmentType) {
String methodDescribe = getMethodDescribe("detail"); String methodDescribe = getMethodDescribe("detail");
iSupvFileService.detail(response,busId,type,attachmentType); iSupvFileService.detail(response, busId, type, attachmentType);
return null; return null;
} }
} }