Merge branch 'feature/admin' into preview
# Conflicts: # mcwl-admin/src/main/resources/application-druid.yml # mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.javamaster
commit
91b2ade9f8
|
@ -1,6 +1,7 @@
|
|||
package com.mcwl.web.controller.resource;
|
||||
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.utils.obs.ObsUtils;
|
||||
import com.mcwl.resource.service.impl.FileServiceImpl;
|
||||
import com.mcwl.web.controller.common.OssUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
|
@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -28,6 +30,9 @@ public class FileController {
|
|||
@Autowired
|
||||
private FileServiceImpl fileService;
|
||||
|
||||
@Autowired
|
||||
private ObsUtils obsUtils;
|
||||
|
||||
/***
|
||||
*
|
||||
* 图片
|
||||
|
@ -57,11 +62,7 @@ public class FileController {
|
|||
@PostMapping("/fileUpload")
|
||||
public AjaxResult fileUpload(@RequestParam MultipartFile file) {
|
||||
|
||||
String s = OssUtil.uploadMultipartFile(file);
|
||||
String fileName = file.getOriginalFilename();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("fileName", fileName);
|
||||
map.put("url", s);
|
||||
Map<String, String> map = obsUtils.uploadFile(file);
|
||||
|
||||
return AjaxResult.success(map);
|
||||
}
|
||||
|
@ -102,10 +103,26 @@ public class FileController {
|
|||
* @return
|
||||
*/
|
||||
@GetMapping("/selectFileName")
|
||||
@ApiOperation(value = "根据文件名查找是否存在")
|
||||
@ApiOperation(value = "根据文件名查找是否存在并返回秘钥")
|
||||
public AjaxResult selectFileName(@RequestParam String name,String 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -395,6 +395,12 @@
|
|||
<version>5.3.25</version> <!-- 请确保与 spring-web 使用相同的主要版本 -->
|
||||
</dependency>
|
||||
|
||||
<!-- obs文件存储 -->
|
||||
<dependency>
|
||||
<groupId>com.huaweicloud</groupId>
|
||||
<artifactId>esdk-obs-java</artifactId>
|
||||
<version>3.19.7</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
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.HttpStatus;
|
||||
import com.mcwl.common.core.domain.entity.SysRole;
|
||||
import com.mcwl.common.core.domain.model.LoginUser;
|
||||
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
|
||||
*/
|
||||
@Slf4j
|
||||
public class SecurityUtils
|
||||
{
|
||||
|
||||
|
@ -36,6 +39,22 @@ 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
|
||||
**/
|
||||
|
@ -116,7 +135,7 @@ public class SecurityUtils
|
|||
|
||||
/**
|
||||
* 是否为管理员
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -127,7 +146,7 @@ public class SecurityUtils
|
|||
|
||||
/**
|
||||
* 验证用户是否具备某权限
|
||||
*
|
||||
*
|
||||
* @param permission 权限字符串
|
||||
* @return 用户是否具备某权限
|
||||
*/
|
||||
|
@ -138,7 +157,7 @@ public class SecurityUtils
|
|||
|
||||
/**
|
||||
* 判断是否包含权限
|
||||
*
|
||||
*
|
||||
* @param authorities 权限列表
|
||||
* @param permission 权限字符串
|
||||
* @return 用户是否具备某权限
|
||||
|
@ -151,7 +170,7 @@ public class SecurityUtils
|
|||
|
||||
/**
|
||||
* 验证用户是否拥有某个角色
|
||||
*
|
||||
*
|
||||
* @param role 角色标识
|
||||
* @return 用户是否具备某角色
|
||||
*/
|
||||
|
@ -164,7 +183,7 @@ public class SecurityUtils
|
|||
|
||||
/**
|
||||
* 判断是否包含角色
|
||||
*
|
||||
*
|
||||
* @param roles 角色列表
|
||||
* @param role 角色
|
||||
* @return 用户是否具备某角色权限
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
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,7 +130,8 @@ public class SecurityConfig
|
|||
permitAllUrl.getUrls().forEach(url -> requests.antMatchers(url).permitAll());
|
||||
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
||||
requests.antMatchers("/login", "/register", "/captchaImage","/ali/pay/doPay","/ali/pay/notify",
|
||||
"/ali/pay/callback","/file/**").permitAll()
|
||||
"/ali/pay/callback","/file/**","/model/modelSquare","/image/imageList","/WorkFlow/workFlowList",
|
||||
"/system/dict/data/type/**","").permitAll()
|
||||
// 静态资源,可匿名访问
|
||||
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
||||
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
|
||||
|
|
|
@ -50,7 +50,7 @@ public class Report {
|
|||
* 举报类型
|
||||
*/
|
||||
@ApiModelProperty(value = "举报类型 字典值")
|
||||
private Integer reportId;
|
||||
private Integer reportType;
|
||||
|
||||
/**
|
||||
* 区分举报内容(1模型 2图片 3工作流)
|
||||
|
|
|
@ -10,4 +10,6 @@ import com.mcwl.common.core.domain.AjaxResult;
|
|||
|
||||
public interface FileService {
|
||||
AjaxResult selectFileName(String name, String type);
|
||||
|
||||
AjaxResult selectFile(String name, String type);
|
||||
}
|
||||
|
|
|
@ -54,4 +54,34 @@ public class FileServiceImpl implements FileService {
|
|||
|
||||
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