增加对excel导入文件扩展名的校验

This commit is contained in:
jishenghua
2025-11-14 21:39:59 +08:00
parent c56d7d2e81
commit eae6f266ed
5 changed files with 49 additions and 16 deletions

View File

@@ -1063,17 +1063,17 @@ public class DepotItemController {
String message = "";
try {
String barCodes = "";
//文件合法性校验
Sheet src = null;
try {
Workbook workbook = Workbook.getWorkbook(file.getInputStream());
src = workbook.getSheet(0);
} catch (Exception e) {
message = "导入文件不合法,请检查";
data.put("message", message);
res.code = 400;
res.data = data;
//文件扩展名只能为xls
String fileName = file.getOriginalFilename();
if(StringUtil.isNotEmpty(fileName)) {
String fileExt = fileName.substring(fileName.indexOf(".")+1);
if(!"xls".equals(fileExt)) {
throw new BusinessRunTimeException(ExceptionConstants.FILE_EXTENSION_ERROR_CODE,
ExceptionConstants.FILE_EXTENSION_ERROR_MSG);
}
}
Workbook workbook = Workbook.getWorkbook(file.getInputStream());
Sheet src = workbook.getSheet(0);
if(src.getRows()>1000) {
message = "导入失败明细不能超出1000条";
res.code = 500;

View File

@@ -7,6 +7,7 @@ import com.jsh.erp.base.TableDataInfo;
import com.jsh.erp.datasource.entities.Supplier;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.vo.SupplierSimple;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.SupplierService;
import com.jsh.erp.service.SystemConfigService;
import com.jsh.erp.service.UserService;
@@ -403,9 +404,13 @@ public class SupplierController extends BaseController {
HttpServletRequest request, HttpServletResponse response) throws Exception{
BaseResponseInfo res = new BaseResponseInfo();
try {
supplierService.checkFileExt(file);
supplierService.importVendor(file, request);
res.code = 200;
res.data = "导入成功";
} catch(BusinessRunTimeException e) {
res.code = e.getCode();
res.data = e.getData().get("message");
} catch(Exception e){
logger.error(e.getMessage(), e);
res.code = 500;
@@ -427,9 +432,13 @@ public class SupplierController extends BaseController {
HttpServletRequest request, HttpServletResponse response) throws Exception{
BaseResponseInfo res = new BaseResponseInfo();
try {
supplierService.checkFileExt(file);
supplierService.importCustomer(file, request);
res.code = 200;
res.data = "导入成功";
} catch(BusinessRunTimeException e) {
res.code = e.getCode();
res.data = e.getData().get("message");
} catch(Exception e){
logger.error(e.getMessage(), e);
res.code = 500;
@@ -451,9 +460,13 @@ public class SupplierController extends BaseController {
HttpServletRequest request, HttpServletResponse response) throws Exception{
BaseResponseInfo res = new BaseResponseInfo();
try {
supplierService.checkFileExt(file);
supplierService.importMember(file, request);
res.code = 200;
res.data = "导入成功";
} catch(BusinessRunTimeException e) {
res.code = e.getCode();
res.data = e.getData().get("message");
} catch(Exception e){
logger.error(e.getMessage(), e);
res.code = 500;