From eeae4fb8efb6d6cd610fb2d8302bab61d831f4f5 Mon Sep 17 00:00:00 2001 From: Diyu0904 <1819728964@qq.com> Date: Wed, 12 Mar 2025 14:04:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8A=A0=E5=AF=86=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20=E6=96=B0=E5=A2=9E=E5=88=86=E6=AE=B5=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=97=A5=E5=BF=97=20=E6=94=B6=E8=97=8F=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BD=9C=E5=93=81=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/CollectController.java | 10 +- .../controller/resource/FileController.java | 2 + .../mcwl/web/controller/resource/Test.java | 180 ------------------ .../com/mcwl/resource/domain/Collect.java | 11 +- .../mcwl/resource/mapper/CollectMapper.java | 2 +- .../mcwl/resource/service/CollectService.java | 3 + .../service/impl/CollectServiceImpl.java | 18 +- .../mapper/resource/CollectMapper.xml | 2 +- 8 files changed, 42 insertions(+), 186 deletions(-) delete mode 100644 mcwl-admin/src/main/java/com/mcwl/web/controller/resource/Test.java diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/CollectController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/CollectController.java index c5d088f..516e98e 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/CollectController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/CollectController.java @@ -42,11 +42,17 @@ public class CollectController { } - + /** + * 查询收藏列表 + * @param pageVo + * @return + */ + @ApiOperation(value = "查询收藏列表") + @PostMapping("/selectCollect") public R selectCollect(@RequestBody PageVo pageVo){ - return R.ok(); + return collectService.selectCollect(pageVo); } } 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 ea35cb9..7cf201f 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 @@ -171,6 +171,7 @@ public class FileController { @RequestParam("uploadId") String uploadId) throws Exception { File file1 = multipartFileToFile(file); Map map = uploadChunk(uploadId, file1, chunk, objectKey); + log.info("上传的文件大小:{}",file.getSize()); return R.ok(map); } @@ -224,6 +225,7 @@ public class FileController { UploadPartResult result = obsClient.uploadPart(request); map.put("etag",result.getEtag()); map.put("partNumber",String.valueOf(result.getPartNumber())); + log.info("分段上传完成:{}",chunk); return map; } diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/Test.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/Test.java deleted file mode 100644 index a934ac3..0000000 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/Test.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.mcwl.web.controller.resource; - -import com.mcwl.web.controller.common.OssUtil; -import org.springframework.mock.web.MockMultipartFile; - -import javax.crypto.Cipher; -import javax.crypto.CipherInputStream; -import javax.crypto.CipherOutputStream; -import javax.crypto.SecretKey; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.SecretKeySpec; -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.security.AlgorithmParameters; -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; - -/** - * @author DaiZibo - * @date 2025/2/5 - * @apiNote - */ - -public class Test { - - - private static final String ALGORITHM = "AES/CBC/PKCS5Padding"; - private static final String TRANSFORMATION = "AES"; - private static final String KEY = "iamkeyeeddzasdfs"; - private static byte[] SAVED_IV; // 静态变量存储IV,确保解密时可访问 -// iv=gHauCGwTlX/mgXrvTUCifQ==, key=aWFta2V5ZWVkZHphc2Rmcw== - - public static void main(String[] args) throws Exception { - // 示例:加密文件并获取密钥 - Map stringStringMap = encryptFile("D:\\ASE\\encryption\\十二女花神 -1-5月花神_十二花神-上1.safetensors", "D:\\ASE\\decode\\加密文件2.safetensors"); -// System.out.println("-------------------"+keyBase64); -// System.out.println("Encryption Key: " + keyBase64); -// -// // 使用上面得到的密钥解密文件 -// decryptFile("C:\\Users\\Dzb\\Desktop\\a.enc", "D:\\ASE\\encryption\\解密测试文件3.txt","aWFta2V5ZWVkZHphc2Rmcw==","gHauCGwTlX/mgXrvTUCifQ=="); - -// Map stringStringMap = uploadEncryptedFileToOSS("D:\\ASE\\encryption\\测试文件1.txt", "encrypted-test-file1.enc"); -// System.out.println("-------------"+stringStringMap); - - } - - public static Map encryptFile(String sourcePath, String encryptedPath) throws Exception { - Cipher cipher = initCipher(Cipher.ENCRYPT_MODE); - try (FileInputStream fis = new FileInputStream(sourcePath); - FileOutputStream fos = new FileOutputStream(encryptedPath); - CipherOutputStream cos = new CipherOutputStream(fos, cipher)) { - byte[] buffer = new byte[1024]; - int read; - while ((read = fis.read(buffer)) != -1) { - cos.write(buffer, 0, read); - } - } - System.out.println("加密完成"); - - SecretKey secretKey = new SecretKeySpec(KEY.getBytes(), TRANSFORMATION); - Map result = new HashMap<>(); - result.put("key", Base64.getEncoder().encodeToString(secretKey.getEncoded())); - result.put("iv", Base64.getEncoder().encodeToString(SAVED_IV)); - return result; - } - -// public static void decryptFile(String encryptedPath, String decryptedPath, String keyBase64) throws Exception { -// byte[] keyBytes = Base64.getDecoder().decode(keyBase64); -// SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, TRANSFORMATION); -// Cipher cipher = initCipher(Cipher.DECRYPT_MODE, secretKeySpec); -// -// try (FileInputStream fis = new FileInputStream(encryptedPath); -// CipherInputStream cis = new CipherInputStream(fis, cipher); -// FileOutputStream fos = new FileOutputStream(decryptedPath)) { -// byte[] buffer = new byte[1024]; -// int read; -// while ((read = cis.read(buffer)) != -1) { -// fos.write(buffer, 0, read); -// } -// } -// System.out.println("解密完成"); -// } - - - public static void decryptFile(String encryptedPath, String decryptedPath, String keyBase64, String ivBase64) throws Exception { - byte[] keyBytes = Base64.getDecoder().decode(keyBase64); - byte[] ivBytes = Base64.getDecoder().decode(ivBase64); - SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, TRANSFORMATION); - IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes); - Cipher cipher = initCipher(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); - - try (FileInputStream fis = new FileInputStream(encryptedPath); - CipherInputStream cis = new CipherInputStream(fis, cipher); - FileOutputStream fos = new FileOutputStream(decryptedPath)) { - byte[] buffer = new byte[1024]; - int read; - while ((read = cis.read(buffer)) != -1) { - fos.write(buffer, 0, read); - } - } - System.out.println("解密完成"); - } - - -// private static Cipher initCipher(int mode) throws Exception { -//// return initCipher(mode, null); -//// } -//// -//// private static Cipher initCipher(int mode, SecretKeySpec secretKeySpec) throws Exception { -//// Cipher cipher = Cipher.getInstance(ALGORITHM); -//// if (secretKeySpec == null) { -//// secretKeySpec = new SecretKeySpec(KEY.getBytes(), TRANSFORMATION); -//// } -//// if (mode == Cipher.ENCRYPT_MODE && SAVED_IV == null) { -//// cipher.init(mode, secretKeySpec); -//// AlgorithmParameters params = cipher.getParameters(); -//// SAVED_IV = params.getParameterSpec(IvParameterSpec.class).getIV(); -//// System.out.println("Generated IV: " + Base64.getEncoder().encodeToString(SAVED_IV)); -//// } else { -//// cipher.init(mode, secretKeySpec, new IvParameterSpec(SAVED_IV)); -//// } -//// return cipher; -//// } - - - private static Cipher initCipher(int mode, SecretKeySpec secretKeySpec, IvParameterSpec ivParameterSpec) throws Exception { - Cipher cipher = Cipher.getInstance(ALGORITHM); - if (secretKeySpec == null){ - secretKeySpec = new SecretKeySpec(KEY.getBytes(), TRANSFORMATION); - } - if (mode == Cipher.ENCRYPT_MODE) { - cipher.init(mode, secretKeySpec); - AlgorithmParameters params = cipher.getParameters(); - SAVED_IV = params.getParameterSpec(IvParameterSpec.class).getIV(); - System.out.println("Generated IV: " + Base64.getEncoder().encodeToString(SAVED_IV)); - } else { - cipher.init(mode, secretKeySpec, ivParameterSpec); - } - return cipher; - } - - private static Cipher initCipher(int mode) throws Exception { - return initCipher(mode, null, null); - } - - private static Cipher initCipher(int mode, SecretKeySpec secretKeySpec) throws Exception { - return initCipher(mode, secretKeySpec, null); - } - - - public static Map uploadEncryptedFileToOSS(String sourcePath, String ossFileName) throws Exception { - Cipher cipher = initCipher(Cipher.ENCRYPT_MODE); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - try (FileInputStream fis = new FileInputStream(sourcePath); - CipherInputStream cis = new CipherInputStream(fis, cipher)) { - byte[] buffer = new byte[1024]; - int read; - while ((read = cis.read(buffer)) != -1) { - bos.write(buffer, 0, read); - } - } - System.out.println("加密完成"); - - // 将加密后的字节数组转换为MultipartFile - MockMultipartFile multipartFile = new MockMultipartFile(ossFileName, ossFileName, "application/octet-stream", bos.toByteArray()); - // 调用上传方法 - String uploadedUrl = OssUtil.uploadMultipartFile(multipartFile); - - Map result = new HashMap<>(); - result.put("uploadedUrl", uploadedUrl); - SecretKey secretKey = new SecretKeySpec(KEY.getBytes(), TRANSFORMATION); - - result.put("key",Base64.getEncoder().encodeToString(secretKey.getEncoded())); - result.put("iv", Base64.getEncoder().encodeToString(SAVED_IV)); - return result; - } -} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/Collect.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/Collect.java index 5308603..1d25d34 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/domain/Collect.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/Collect.java @@ -2,6 +2,7 @@ package com.mcwl.resource.domain; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -25,16 +26,24 @@ import java.util.Date; @Data public class Collect { + @ApiModelProperty(value = "主键ID") private Long id; + @ApiModelProperty(value = "作品ID") private Long productId; + @ApiModelProperty(value = "收藏人") private Long userId; - private Long productType; + @ApiModelProperty(value = "收藏类型 0模型 1工作流") + private Integer collectType; + @ApiModelProperty(value = "创建时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date createTime; + @ApiModelProperty(value = "作品的类型") + private Integer productType; + } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/CollectMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/CollectMapper.java index e0ee250..12f9b59 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/CollectMapper.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/CollectMapper.java @@ -13,7 +13,7 @@ import org.apache.ibatis.annotations.Param; @Mapper public interface CollectMapper extends BaseMapper { - Collect selectCollect(@Param("userId") Long userId, @Param("productId") Long productId, @Param("productType") Long productType); + Collect selectCollect(@Param("userId") Long userId, @Param("productId") Long productId, @Param("collectType") Integer collectType); Collect selectCollectById(@Param("modelId") Long modelId, @Param("userIdMax") Long userIdMax, @Param("type") Integer type); diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/CollectService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/CollectService.java index 5406a8e..0a63738 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/CollectService.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/CollectService.java @@ -2,6 +2,7 @@ package com.mcwl.resource.service; import com.mcwl.common.core.domain.R; import com.mcwl.resource.domain.Collect; +import com.mcwl.resource.domain.vo.PageVo; /** * 收藏服务层 @@ -14,4 +15,6 @@ public interface CollectService { R addCollect(Collect collect); Collect selectCollectById(Long modelId, Long userIdMax,Integer type); + + R selectCollect(PageVo pageVo); } diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/CollectServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/CollectServiceImpl.java index b394831..6484f8c 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/CollectServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/CollectServiceImpl.java @@ -3,6 +3,7 @@ package com.mcwl.resource.service.impl; import com.mcwl.common.core.domain.R; import com.mcwl.common.utils.SecurityUtils; import com.mcwl.resource.domain.Collect; +import com.mcwl.resource.domain.vo.PageVo; import com.mcwl.resource.mapper.CollectMapper; import com.mcwl.resource.service.CollectService; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +28,7 @@ public class CollectServiceImpl implements CollectService { @Override public R addCollect(Collect collect) { - Collect collect1 = collectMapper.selectCollect(SecurityUtils.getUserId(),collect.getProductId(),collect.getProductType()); + Collect collect1 = collectMapper.selectCollect(SecurityUtils.getUserId(),collect.getProductId(),collect.getCollectType()); collect.setUserId(SecurityUtils.getUserId()); collect.setCreateTime(new Date()); if (collect1 == null){ @@ -47,4 +48,19 @@ public class CollectServiceImpl implements CollectService { return collectMapper.selectCollectById(modelId,userIdMax,type); } + + @Override + public R selectCollect(PageVo pageVo) { + + //查询个人收藏 + Long userIdMax = SecurityUtils.getUserIdMax(); + + if (pageVo.getType() == 0){ + //查询工作流 + } + + //查询模型 + + return R.ok(); + } } diff --git a/mcwl-resource/src/main/resources/mapper/resource/CollectMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/CollectMapper.xml index c2324a8..9319f48 100644 --- a/mcwl-resource/src/main/resources/mapper/resource/CollectMapper.xml +++ b/mcwl-resource/src/main/resources/mapper/resource/CollectMapper.xml @@ -7,7 +7,7 @@