Compare commits
No commits in common. "097ecfa023faa59e8ca6642848e404b43ea30d97" and "e26568d0df770e9585ee7de2971e729da2fe2f64" have entirely different histories.
097ecfa023
...
e26568d0df
|
@ -1,7 +1,6 @@
|
||||||
package com.mcwl.web.controller.resource;
|
package com.mcwl.web.controller.resource;
|
||||||
|
|
||||||
import com.mcwl.common.core.domain.AjaxResult;
|
import com.mcwl.common.core.domain.AjaxResult;
|
||||||
import com.mcwl.common.utils.obs.ObsUtils;
|
|
||||||
import com.mcwl.resource.service.impl.FileServiceImpl;
|
import com.mcwl.resource.service.impl.FileServiceImpl;
|
||||||
import com.mcwl.web.controller.common.OssUtil;
|
import com.mcwl.web.controller.common.OssUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
@ -10,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -30,9 +28,6 @@ public class FileController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private FileServiceImpl fileService;
|
private FileServiceImpl fileService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObsUtils obsUtils;
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
*
|
*
|
||||||
* 图片
|
* 图片
|
||||||
|
@ -62,7 +57,11 @@ public class FileController {
|
||||||
@PostMapping("/fileUpload")
|
@PostMapping("/fileUpload")
|
||||||
public AjaxResult fileUpload(@RequestParam MultipartFile file) {
|
public AjaxResult fileUpload(@RequestParam MultipartFile file) {
|
||||||
|
|
||||||
Map<String, String> map = obsUtils.uploadFile(file);
|
String s = OssUtil.uploadMultipartFile(file);
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("fileName", fileName);
|
||||||
|
map.put("url", s);
|
||||||
|
|
||||||
return AjaxResult.success(map);
|
return AjaxResult.success(map);
|
||||||
}
|
}
|
||||||
|
@ -103,26 +102,10 @@ public class FileController {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/selectFileName")
|
@GetMapping("/selectFileName")
|
||||||
@ApiOperation(value = "根据文件名查找是否存在并返回秘钥")
|
@ApiOperation(value = "根据文件名查找是否存在")
|
||||||
public AjaxResult selectFileName(@RequestParam String name,String type){
|
public AjaxResult selectFileName(@RequestParam String name,String type){
|
||||||
|
|
||||||
return fileService.selectFileName(name,type);
|
return fileService.selectFileName(name,type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/selectFile")
|
|
||||||
@ApiOperation(value = "根据文件名查找是否存在")
|
|
||||||
public AjaxResult selectFile(@RequestParam String name,String type){
|
|
||||||
|
|
||||||
return fileService.selectFile(name,type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/download")
|
|
||||||
@ApiOperation(value = "读取文件内容")
|
|
||||||
public AjaxResult download(@RequestParam String name) throws IOException {
|
|
||||||
|
|
||||||
obsUtils.download(name);
|
|
||||||
|
|
||||||
return AjaxResult.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ token:
|
||||||
# 令牌密钥
|
# 令牌密钥
|
||||||
secret: abcdefghijklmnopqrstuvwxyz
|
secret: abcdefghijklmnopqrstuvwxyz
|
||||||
# 令牌有效期(默认30分钟)
|
# 令牌有效期(默认30分钟)
|
||||||
expireTime: 30
|
expireTime: 43200
|
||||||
|
|
||||||
# MyBatis Plus配置
|
# MyBatis Plus配置
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
|
|
|
@ -395,12 +395,6 @@
|
||||||
<version>5.3.25</version> <!-- 请确保与 spring-web 使用相同的主要版本 -->
|
<version>5.3.25</version> <!-- 请确保与 spring-web 使用相同的主要版本 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- obs文件存储 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.huaweicloud</groupId>
|
|
||||||
<artifactId>esdk-obs-java</artifactId>
|
|
||||||
<version>3.19.7</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,23 @@
|
||||||
package com.mcwl.common.utils;
|
package com.mcwl.common.utils;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.util.PatternMatchUtils;
|
||||||
import com.mcwl.common.constant.Constants;
|
import com.mcwl.common.constant.Constants;
|
||||||
import com.mcwl.common.constant.HttpStatus;
|
import com.mcwl.common.constant.HttpStatus;
|
||||||
import com.mcwl.common.core.domain.entity.SysRole;
|
import com.mcwl.common.core.domain.entity.SysRole;
|
||||||
import com.mcwl.common.core.domain.model.LoginUser;
|
import com.mcwl.common.core.domain.model.LoginUser;
|
||||||
import com.mcwl.common.exception.ServiceException;
|
import com.mcwl.common.exception.ServiceException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.util.PatternMatchUtils;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安全服务工具类
|
* 安全服务工具类
|
||||||
*
|
*
|
||||||
* @author mcwl
|
* @author mcwl
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
public class SecurityUtils
|
public class SecurityUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -39,22 +36,6 @@ public class SecurityUtils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Long getUserIdMax(){
|
|
||||||
|
|
||||||
Long userId = null;
|
|
||||||
try {
|
|
||||||
userId = SecurityUtils.getUserId();
|
|
||||||
if (userId == null){
|
|
||||||
userId = 0L;
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取部门ID
|
* 获取部门ID
|
||||||
**/
|
**/
|
||||||
|
@ -135,7 +116,7 @@ public class SecurityUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为管理员
|
* 是否为管理员
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@ -146,7 +127,7 @@ public class SecurityUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证用户是否具备某权限
|
* 验证用户是否具备某权限
|
||||||
*
|
*
|
||||||
* @param permission 权限字符串
|
* @param permission 权限字符串
|
||||||
* @return 用户是否具备某权限
|
* @return 用户是否具备某权限
|
||||||
*/
|
*/
|
||||||
|
@ -157,7 +138,7 @@ public class SecurityUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否包含权限
|
* 判断是否包含权限
|
||||||
*
|
*
|
||||||
* @param authorities 权限列表
|
* @param authorities 权限列表
|
||||||
* @param permission 权限字符串
|
* @param permission 权限字符串
|
||||||
* @return 用户是否具备某权限
|
* @return 用户是否具备某权限
|
||||||
|
@ -170,7 +151,7 @@ public class SecurityUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证用户是否拥有某个角色
|
* 验证用户是否拥有某个角色
|
||||||
*
|
*
|
||||||
* @param role 角色标识
|
* @param role 角色标识
|
||||||
* @return 用户是否具备某角色
|
* @return 用户是否具备某角色
|
||||||
*/
|
*/
|
||||||
|
@ -183,7 +164,7 @@ public class SecurityUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否包含角色
|
* 判断是否包含角色
|
||||||
*
|
*
|
||||||
* @param roles 角色列表
|
* @param roles 角色列表
|
||||||
* @param role 角色
|
* @param role 角色
|
||||||
* @return 用户是否具备某角色权限
|
* @return 用户是否具备某角色权限
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package com.mcwl.common.utils.obs;
|
|
||||||
|
|
||||||
import com.obs.services.ObsClient;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* obs配置类
|
|
||||||
* @author DaiZibo
|
|
||||||
* @date 2025/2/18
|
|
||||||
* @apiNote
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class ObsConfig {
|
|
||||||
@Value("${huawei.obs.ak}")
|
|
||||||
private String ak;
|
|
||||||
@Value("${huawei.obs.sk}")
|
|
||||||
private String sk;
|
|
||||||
@Value("${huawei.obs.upload.endPoint}")
|
|
||||||
private String endPoint;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ObsClient getObsClient() {
|
|
||||||
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
|
|
||||||
return obsClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,104 +0,0 @@
|
||||||
package com.mcwl.common.utils.obs;
|
|
||||||
|
|
||||||
import com.obs.services.ObsClient;
|
|
||||||
import com.obs.services.model.ObsObject;
|
|
||||||
import com.obs.services.model.PutObjectResult;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 华为云obs上传文件工具类
|
|
||||||
*
|
|
||||||
* @author DaiZibo
|
|
||||||
* @date 2025/2/18
|
|
||||||
* @apiNote
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class ObsUtils {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ObsClient obsClient;
|
|
||||||
|
|
||||||
@Value("${huawei.obs.bucketName}")
|
|
||||||
private String bucketName;
|
|
||||||
|
|
||||||
//上传文件,multipartFile就是你要的文件,
|
|
||||||
//objectKey就是文件名,如果桶中有文件夹的话,如往test文件上传test.txt文件,那么objectKey就是test/test.txt
|
|
||||||
public Map<String,String> uploadFile(MultipartFile multipartFile){
|
|
||||||
|
|
||||||
HashMap<String, String> map = new HashMap<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
InputStream inputStream = multipartFile.getInputStream();
|
|
||||||
String uuid = UUID.randomUUID().toString();
|
|
||||||
String ossDefaultPath = getOssDefaultPath(multipartFile.getOriginalFilename(),uuid);
|
|
||||||
PutObjectResult putObjectResult = obsClient.putObject(bucketName, ossDefaultPath, inputStream);
|
|
||||||
inputStream.close();
|
|
||||||
map.put("path",putObjectResult.getObjectUrl());
|
|
||||||
map.put("objectKey",putObjectResult.getObjectKey());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteFile(String objectKey) throws Exception {
|
|
||||||
obsClient.deleteObject(bucketName, objectKey);
|
|
||||||
obsClient.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOssDefaultPath(String name,String uuid) {
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
String url =
|
|
||||||
now.getYear() + "/" +
|
|
||||||
now.getMonth() + "/" +
|
|
||||||
now.getDayOfMonth() + "/"
|
|
||||||
+ uuid + "_"
|
|
||||||
+ name;
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void download(String name) throws IOException {
|
|
||||||
|
|
||||||
ObsObject obsObject = obsClient.getObject(bucketName, name);
|
|
||||||
InputStream content = obsObject.getObjectContent();
|
|
||||||
if (content != null) {
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
|
|
||||||
while (true) {
|
|
||||||
String line = reader.readLine();
|
|
||||||
if (line == null){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.out.println("\n" + line);
|
|
||||||
}
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@PreDestroy
|
|
||||||
public void cleanup() {
|
|
||||||
if (obsClient != null) {
|
|
||||||
try {
|
|
||||||
obsClient.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -130,8 +130,7 @@ public class SecurityConfig
|
||||||
permitAllUrl.getUrls().forEach(url -> requests.antMatchers(url).permitAll());
|
permitAllUrl.getUrls().forEach(url -> requests.antMatchers(url).permitAll());
|
||||||
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
||||||
requests.antMatchers("/login", "/register", "/captchaImage","/ali/pay/doPay","/ali/pay/notify",
|
requests.antMatchers("/login", "/register", "/captchaImage","/ali/pay/doPay","/ali/pay/notify",
|
||||||
"/ali/pay/callback","/file/**","/model/modelSquare","/image/imageList","/WorkFlow/workFlowList",
|
"/ali/pay/callback","/file/**").permitAll()
|
||||||
"/system/dict/data/type/**","").permitAll()
|
|
||||||
// 静态资源,可匿名访问
|
// 静态资源,可匿名访问
|
||||||
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
||||||
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
|
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class Report {
|
||||||
* 举报类型
|
* 举报类型
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "举报类型 字典值")
|
@ApiModelProperty(value = "举报类型 字典值")
|
||||||
private Integer reportType;
|
private Integer reportId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 区分举报内容(1模型 2图片 3工作流)
|
* 区分举报内容(1模型 2图片 3工作流)
|
||||||
|
|
|
@ -10,6 +10,4 @@ import com.mcwl.common.core.domain.AjaxResult;
|
||||||
|
|
||||||
public interface FileService {
|
public interface FileService {
|
||||||
AjaxResult selectFileName(String name, String type);
|
AjaxResult selectFileName(String name, String type);
|
||||||
|
|
||||||
AjaxResult selectFile(String name, String type);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,34 +54,4 @@ public class FileServiceImpl implements FileService {
|
||||||
|
|
||||||
return AjaxResult.error("type不合法");
|
return AjaxResult.error("type不合法");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public AjaxResult selectFile(String name, String type) {
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(type)){
|
|
||||||
|
|
||||||
return AjaxResult.error("请输入type");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.equals("model")) {
|
|
||||||
|
|
||||||
ModelVersion modelVersion = versionMapper.selectByFileName(name);
|
|
||||||
if (modelVersion != null) {
|
|
||||||
|
|
||||||
return AjaxResult.success(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return AjaxResult.success(1);
|
|
||||||
}else if (type.equals("workflow")){
|
|
||||||
WorkFlowVersion workFlowVersion = workFlowVersionMapper.selectByFileName(name);
|
|
||||||
if (workFlowVersion != null) {
|
|
||||||
|
|
||||||
return AjaxResult.success(0);
|
|
||||||
}
|
|
||||||
return AjaxResult.success(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return AjaxResult.error("type不合法");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue