修复文件上传大小限制问题

This commit is contained in:
刘倡
2025-08-01 13:56:33 +08:00
parent aeb511676e
commit 11a5f02330
5 changed files with 69 additions and 52 deletions

View File

@ -1,13 +1,10 @@
package com.coscoshipping.ebtp.system; package com.coscoshipping.ebtp.system;
import io.micrometer.core.instrument.MeterRegistry;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication @SpringBootApplication
@ -16,6 +13,7 @@ import org.springframework.context.annotation.ComponentScan;
@MapperScan({"com.coscoshipping.ebtp.system.**.dao", "com.chinaunicom.mall.ebtp.**.dao" }) @MapperScan({"com.coscoshipping.ebtp.system.**.dao", "com.chinaunicom.mall.ebtp.**.dao" })
@ComponentScan(basePackages = { "com.coscoshipping.ebtp.system.*", "com.chinaunicom.mall.ebtp.cloud.*", @ComponentScan(basePackages = { "com.coscoshipping.ebtp.system.*", "com.chinaunicom.mall.ebtp.cloud.*",
"com.chinaunicom.mall.ebtp.*" }) "com.chinaunicom.mall.ebtp.*" })
@EnableDiscoveryClient
public class SysManagerEbtpProjectApplication { public class SysManagerEbtpProjectApplication {
public static void main(String[] args) { public static void main(String[] args) {
@ -23,16 +21,4 @@ public class SysManagerEbtpProjectApplication {
System.out.println("启动成功!"); System.out.println("启动成功!");
} }
/**
* Grafana 注册项
*
* @param applicationName 应用名称, 用于grafana应用列表
* @return
*/
@Bean
public MeterRegistryCustomizer<MeterRegistry> configurer(
@Value("${spring.application.name}") String applicationName) {
return (registry) -> registry.config().commonTags("application", applicationName);
}
} }

View File

@ -103,21 +103,25 @@ public class FileController extends BaseController {
@RequestParam(required = false, value = "objectTable") String objectTable, @RequestParam(required = false, value = "objectTable") String objectTable,
@RequestParam(required = false, value = "objectParam") String objectParam, @RequestParam(required = false, value = "objectParam") String objectParam,
@RequestParam(defaultValue = "file", value = "objectType") String objectType, @RequestParam(defaultValue = "file", value = "objectType") String objectType,
@RequestParam(value = "multipartFiles") MultipartFile... multipartFiles) @RequestParam(value = "multipartFiles") MultipartFile... multipartFiles) {
throws Exception {
if (StringUtils.isEmpty(appCode) || StringUtils.isEmpty(String.valueOf(objectId))) { if (StringUtils.isEmpty(appCode) || StringUtils.isEmpty(String.valueOf(objectId))) {
return new BaseResponse<List<AnnexAndStorageVO>>(400, false, ResponseEnum.REQUEST_ERROR.getMsg(), null); return new BaseResponse<List<AnnexAndStorageVO>>(400, false, ResponseEnum.REQUEST_ERROR.getMsg(), null);
} }
List<AnnexAndStorageVO> annexAndStorageVOs = new ArrayList<>(); List<AnnexAndStorageVO> annexAndStorageVOs = new ArrayList<>();
if (multipartFiles != null && multipartFiles.length > 0) { try {
for (MultipartFile file : multipartFiles) { if (multipartFiles != null && multipartFiles.length > 0) {
List<AnnexAndStorageVO> annexAndStorageVOList = this.fileService.uploadFile(file, appCode, objectId, objectTable, objectType, objectParam); for (MultipartFile file : multipartFiles) {
annexAndStorageVOs.addAll(annexAndStorageVOList); List<AnnexAndStorageVO> annexAndStorageVOList = this.fileService.uploadFile(file, appCode, objectId, objectTable, objectType, objectParam);
annexAndStorageVOs.addAll(annexAndStorageVOList);
}
return ok(annexAndStorageVOs);
} else {
return new BaseResponse<>(400, false, ResponseEnum.FILE_NOT_EXIST_OR_REQUEST_ERROR.getMsg(), null);
} }
return ok(annexAndStorageVOs); } catch (Exception e) {
} else { return new BaseResponse<>(400, false, e.getMessage(), null);
return new BaseResponse<>(400, false, ResponseEnum.FILE_NOT_EXIST_OR_REQUEST_ERROR.getMsg(), null);
} }
} }
/** /**
@ -389,8 +393,8 @@ public class FileController extends BaseController {
* @Date 创建时间: 2021/6/24 * @Date 创建时间: 2021/6/24
*/ */
@GetMapping("/getDownload") @GetMapping("/getDownload")
public BaseResponse<Boolean> getDownload(@RequestParam("fileId") String fileId,HttpServletResponse httpServletResponse ,@RequestParam("documentSecretKey") String documentSecretKey){ public BaseResponse<Boolean> getDownload(@RequestParam("fileId") String fileId, HttpServletResponse httpServletResponse, @RequestParam("documentSecretKey") String documentSecretKey) {
return fileService.getDownload(fileId,httpServletResponse,documentSecretKey); return fileService.getDownload(fileId, httpServletResponse, documentSecretKey);
} }
@ -401,7 +405,7 @@ public class FileController extends BaseController {
* @Date 创建时间: 2021/6/24 * @Date 创建时间: 2021/6/24
*/ */
@GetMapping("/getSecretKey") @GetMapping("/getSecretKey")
public BaseResponse<String> getSecretKey(){ public BaseResponse<String> getSecretKey() {
return fileService.getSecretKey(); return fileService.getSecretKey();
} }

View File

@ -69,7 +69,7 @@ public class LoginController {
return BaseResponse.success(result); return BaseResponse.success(result);
} }
@ApiOperation("账号登录") @ApiOperation("专家账号登录")
@PostMapping("/accountLogin/expert") @PostMapping("/accountLogin/expert")
public BaseResponse idcardExpertLogin(HttpServletResponse response,@RequestBody LoginUserVo vo) { public BaseResponse idcardExpertLogin(HttpServletResponse response,@RequestBody LoginUserVo vo) {
if(captchaGenerator.checkCaptcha(vo.getIdentifying(),vo.getEncryptValue())){ if(captchaGenerator.checkCaptcha(vo.getIdentifying(),vo.getEncryptValue())){
@ -81,7 +81,7 @@ public class LoginController {
return BaseResponse.success(null); return BaseResponse.success(null);
} }
} }
@ApiOperation("账号登录") @ApiOperation("供应商账号登录")
@PostMapping("/accountLogin/supplier") @PostMapping("/accountLogin/supplier")
public BaseResponse idcardSupplierLogin(HttpServletResponse response,@RequestBody LoginUserVo vo) { public BaseResponse idcardSupplierLogin(HttpServletResponse response,@RequestBody LoginUserVo vo) {
if(captchaGenerator.checkCaptcha(vo.getIdentifying(),vo.getEncryptValue())){ if(captchaGenerator.checkCaptcha(vo.getIdentifying(),vo.getEncryptValue())){

View File

@ -86,7 +86,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
@Value("${login.password.publickey}") @Value("${login.password.publickey}")
private String publickey; private String publickey;
@Value("${login.token.time_limit}") @Value("${login.token.time_limit}")
private String valid_time_limit; private String validTimeLimit;
@Value("${login.reset_password}") @Value("${login.reset_password}")
private String resetPassword; private String resetPassword;
@Resource @Resource
@ -190,7 +190,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
userinfoRedisTemplate.opsForValue().set( userinfoRedisTemplate.opsForValue().set(
REDIS_USER_KEY + token, REDIS_USER_KEY + token,
baseCacheUser, baseCacheUser,
Long.parseLong(valid_time_limit), Long.parseLong(validTimeLimit),
TimeUnit.HOURS); TimeUnit.HOURS);
// 5. 记录登录成功日志 // 5. 记录登录成功日志
@ -255,6 +255,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
// 检查是否为首次登录 // 检查是否为首次登录
boolean isFirstLogin = user.getFirstLogin() != null && user.getFirstLogin() == 1; boolean isFirstLogin = user.getFirstLogin() != null && user.getFirstLogin() == 1;
String userId = user.getUserId().toString();
if (isFirstLogin) { if (isFirstLogin) {
// 首次登录需要强制修改密码,返回特殊状态 // 首次登录需要强制修改密码,返回特殊状态
BaseSelf baseSelf = userSupplierLogin(user); BaseSelf baseSelf = userSupplierLogin(user);
@ -263,7 +264,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
// 记录首次登录日志 // 记录首次登录日志
long loginTime = System.currentTimeMillis() - startTime; long loginTime = System.currentTimeMillis() - startTime;
sysLoginLogService.recordLoginSuccess( sysLoginLogService.recordLoginSuccess(
user.getUserId().toString(), userId,
user.getName(), user.getName(),
user.getUsername(), user.getUsername(),
SysLoginLog.USER_TYPE_SUPPLIER, SysLoginLog.USER_TYPE_SUPPLIER,
@ -283,27 +284,51 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
BaseSelf baseSelf = userSupplierLogin(user); BaseSelf baseSelf = userSupplierLogin(user);
// 1. 查询角色信息
List<AuthorityEntity> authorityList = baseUserMapper.selectRoleByUserId(userId);
// 2. 组装BaseCacheUser
BaseCacheUser baseCacheUser = new BaseCacheUser();
baseCacheUser.setUserId(userId);
baseCacheUser.setFullName(user.getName());
baseCacheUser.setLoginName(user.getName());
baseCacheUser.setMobilePhone(user.getMobile());
baseCacheUser.setOfficePhone(user.getMobile());
baseCacheUser.setSex(user.getSex() != null ? user.getSex().toString() : null);
baseCacheUser.setEmailAddress(user.getEmail());
baseCacheUser.setUserType("0");
baseCacheUser.setAuthorityList(authorityList);
// 角色ID字符串拼接
if (authorityList != null && !authorityList.isEmpty()) {
StringBuilder roleIds = new StringBuilder();
for (AuthorityEntity ae : authorityList) {
if (roleIds.length() > 0)
roleIds.append(",");
roleIds.append(ae.getRoleId());
}
baseCacheUser.setRoleIds(roleIds.toString());
}
// 存入redis // 存入redis
// String token = baseSelf.getToken(); String token = baseSelf.getToken();
// userinfoRedisTemplate.opsForValue().set( userinfoRedisTemplate.opsForValue().set(
// REDIS_USER_KEY + token, REDIS_USER_KEY + token,
// baseCacheUser, baseCacheUser,
// Long.parseLong(valid_time_limit), Long.parseLong(validTimeLimit),
// TimeUnit.HOURS); TimeUnit.HOURS);
// 记录登录成功日志 // 记录登录成功日志
long loginTime = System.currentTimeMillis() - startTime; long loginTime = System.currentTimeMillis() - startTime;
sysLoginLogService.recordLoginSuccess( sysLoginLogService.recordLoginSuccess(
user.getUserId().toString(), userId,
user.getName(), user.getName(),
user.getUsername(), user.getUsername(),
SysLoginLog.USER_TYPE_SUPPLIER, SysLoginLog.USER_TYPE_SUPPLIER,
loginIp, loginIp,
baseSelf.getToken(), baseSelf.getToken(),
loginTime, loginTime,
userAgent, userAgent,
false false);
);
return baseSelf; return baseSelf;
} catch (BadPaddingException e) { } catch (BadPaddingException e) {
@ -663,7 +688,7 @@ public class BaseUserServiceImpl extends BaseServiceImpl<BaseUserMapper, SysUser
BaseUserToken userToken = tokenList.get(0); BaseUserToken userToken = tokenList.get(0);
CommonExceptionEnum.LOGIN_EXPIRATION.assertStringNotNullByKey("", tokenList.get(0).getUserObject()); CommonExceptionEnum.LOGIN_EXPIRATION.assertStringNotNullByKey("", tokenList.get(0).getUserObject());
SecurityEntity securityEntity = JSON.parseObject(userToken.getUserObject(), SecurityEntity.class); SecurityEntity securityEntity = JSON.parseObject(userToken.getUserObject(), SecurityEntity.class);
userToken.setValidTime(LocalDateTime.now().plusMinutes(Long.valueOf(valid_time_limit))); userToken.setValidTime(LocalDateTime.now().plusMinutes(Long.valueOf(validTimeLimit)));
this.baseUserTokenService.saveOrUpdate(userToken); this.baseUserTokenService.saveOrUpdate(userToken);

View File

@ -6,6 +6,10 @@ server:
spring: spring:
main: main:
allow-bean-definition-overriding: true allow-bean-definition-overriding: true
servlet:
multipart:
max-file-size: 30MB
max-request-size: 100MB
cloud: cloud:
feign: feign:
client: client:
@ -16,8 +20,6 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: 192.168.110.231:8848 server-addr: 192.168.110.231:8848
namespace: seata
group: SEATA_GROUP
aop: aop:
auto: true #开启spring的aop配置 auto: true #开启spring的aop配置
proxy-target-class: true proxy-target-class: true