diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/FileController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/FileController.java index 5465f97..d30bced 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/FileController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/FileController.java @@ -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 map = new HashMap<>(); - map.put("fileName", fileName); - map.put("url", s); + Map 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(); + } + } diff --git a/mcwl-admin/src/main/resources/application-druid.yml b/mcwl-admin/src/main/resources/application-druid.yml index e019d08..c8156d2 100644 --- a/mcwl-admin/src/main/resources/application-druid.yml +++ b/mcwl-admin/src/main/resources/application-druid.yml @@ -133,6 +133,14 @@ mall: notifyUrl: https://7d014da8.r27.cpolar.top/ali/pay/notify # 沙箱支付宝网关 gatewayUrl: https://openapi-sandbox.dl.alipaydev.com/gateway.do +huawei: + obs: + ak: NWXJ93POA9NCDVV1WQYJ + sk: 3aBuzYdUgSsxdNnycD2mESnVwtcyjAKPxqewE79N + bucketName: mcwl + upload: + endPoint: obs.cn-south-1.myhuaweicloud.com + ## 线上环境 #mall: diff --git a/mcwl-common/pom.xml b/mcwl-common/pom.xml index 3207fef..0d16b32 100644 --- a/mcwl-common/pom.xml +++ b/mcwl-common/pom.xml @@ -395,6 +395,12 @@ 5.3.25 + + + com.huaweicloud + esdk-obs-java + 3.19.7 + diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/SecurityUtils.java b/mcwl-common/src/main/java/com/mcwl/common/utils/SecurityUtils.java index b298d19..86885af 100644 --- a/mcwl-common/src/main/java/com/mcwl/common/utils/SecurityUtils.java +++ b/mcwl-common/src/main/java/com/mcwl/common/utils/SecurityUtils.java @@ -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 用户是否具备某角色权限 diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsConfig.java b/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsConfig.java new file mode 100644 index 0000000..2e528ee --- /dev/null +++ b/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsConfig.java @@ -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; + } + + +} diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsUtils.java b/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsUtils.java new file mode 100644 index 0000000..41e77d1 --- /dev/null +++ b/mcwl-common/src/main/java/com/mcwl/common/utils/obs/ObsUtils.java @@ -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 uploadFile(MultipartFile multipartFile){ + + HashMap 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); + } + } + } +} diff --git a/mcwl-framework/src/main/java/com/mcwl/framework/config/SecurityConfig.java b/mcwl-framework/src/main/java/com/mcwl/framework/config/SecurityConfig.java index b7b2b7a..261e0dc 100644 --- a/mcwl-framework/src/main/java/com/mcwl/framework/config/SecurityConfig.java +++ b/mcwl-framework/src/main/java/com/mcwl/framework/config/SecurityConfig.java @@ -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() diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/Report.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/Report.java index 9f38a3d..33ba937 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/domain/Report.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/Report.java @@ -50,7 +50,7 @@ public class Report { * 举报类型 */ @ApiModelProperty(value = "举报类型 字典值") - private Integer reportId; + private Integer reportType; /** * 区分举报内容(1模型 2图片 3工作流) diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/FileService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/FileService.java index 7ae27e7..461332e 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/FileService.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/FileService.java @@ -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); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/FileServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/FileServiceImpl.java index 02c2257..c000fd6 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/FileServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/FileServiceImpl.java @@ -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不合法"); + + } } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java index 615ef7f..e40d671 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelImageLikeServiceImpl.java @@ -167,8 +167,9 @@ public class ModelImageLikeServiceImpl extends ServiceImpl