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.java
master
Diyu0904 2025-02-20 14:20:37 +08:00
commit 91b2ade9f8
9 changed files with 233 additions and 21 deletions

View File

@ -1,6 +1,7 @@
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;
@ -9,6 +10,7 @@ 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;
@ -28,6 +30,9 @@ public class FileController {
@Autowired @Autowired
private FileServiceImpl fileService; private FileServiceImpl fileService;
@Autowired
private ObsUtils obsUtils;
/*** /***
* *
* *
@ -57,11 +62,7 @@ public class FileController {
@PostMapping("/fileUpload") @PostMapping("/fileUpload")
public AjaxResult fileUpload(@RequestParam MultipartFile file) { public AjaxResult fileUpload(@RequestParam MultipartFile file) {
String s = OssUtil.uploadMultipartFile(file); Map<String, String> map = obsUtils.uploadFile(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);
} }
@ -102,10 +103,26 @@ 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();
}
} }

View File

@ -395,6 +395,12 @@
<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>

View File

@ -1,23 +1,26 @@
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
{ {
@ -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 * ID
**/ **/

View File

@ -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;
}
}

View File

@ -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);
}
}
}
}

View File

@ -130,7 +130,8 @@ 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/**").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(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()

View File

@ -50,7 +50,7 @@ public class Report {
* *
*/ */
@ApiModelProperty(value = "举报类型 字典值") @ApiModelProperty(value = "举报类型 字典值")
private Integer reportId; private Integer reportType;
/** /**
* (1 2 3) * (1 2 3)

View File

@ -10,4 +10,6 @@ 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);
} }

View File

@ -54,4 +54,34 @@ 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不合法");
}
} }