lichen 2 meses atrás
pai
commit
dd5a573d92

+ 29 - 11
.gitignore

@@ -1,14 +1,32 @@
-# ---> Java
-*.class
+/target/
+!.mvn/wrapper/maven-wrapper.jar
 
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+target/
+.DS_Store
+../img/
+../song/
+img/
+song/
+logs/
 
-# Package Files #
-*.jar
-*.war
-*.ear
-
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
 
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

+ 30 - 0
pom.xml

@@ -122,6 +122,36 @@
             <artifactId>easyexcel</artifactId>
             <version>3.1.3</version>
         </dependency>
+
+        <!-- redis -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+            <version>2.6.6</version>
+        </dependency>
+        <!--<spring2.X集成redis所需common-pool2-->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-pool2</artifactId>
+            <version>2.11.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-mail</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>io.minio</groupId>
+            <artifactId>minio</artifactId>
+            <version>8.3.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.squareup.okhttp3</groupId>
+            <artifactId>okhttp</artifactId>
+            <version>4.8.1</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 27 - 0
src/main/java/org/example/music/config/MinioConfig.java

@@ -0,0 +1,27 @@
+package org.example.music.config;
+
+import io.minio.MinioClient;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MinioConfig {
+
+    @Value("${minio.endpoint}")
+    private String minioEndpoint;
+
+    @Value("${minio.access-key}")
+    private String minioAccessKey;
+
+    @Value("${minio.secret-key}")
+    private String minioSecretKey;
+
+    @Bean
+    public MinioClient minioClient() {
+        return MinioClient.builder()
+                .endpoint(minioEndpoint)
+                .credentials(minioAccessKey, minioSecretKey)
+                .build();
+    }
+}

+ 63 - 0
src/main/java/org/example/music/config/RedisConfig.java

@@ -0,0 +1,63 @@
+package org.example.music.config;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.CachingConfigurerSupport;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.cache.RedisCacheConfiguration;
+import org.springframework.data.redis.cache.RedisCacheManager;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.RedisSerializationContext;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+import java.time.Duration;
+
+@EnableCaching //开启缓存注解
+@Configuration
+public class RedisConfig extends CachingConfigurerSupport {
+    @Bean
+    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
+        RedisTemplate<String, Object> template = new RedisTemplate<>();
+        RedisSerializer<String> redisSerializer = new StringRedisSerializer();
+        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
+        ObjectMapper om = new ObjectMapper();
+        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+        jackson2JsonRedisSerializer.setObjectMapper(om);
+        template.setConnectionFactory(factory);
+        //key序列化方式
+        template.setKeySerializer(redisSerializer);
+        //value序列化
+        template.setValueSerializer(jackson2JsonRedisSerializer);
+        //value hashmap序列化
+        template.setHashValueSerializer(jackson2JsonRedisSerializer);
+        return template;
+    }
+
+    @Bean
+    public CacheManager cacheManager(RedisConnectionFactory factory) {
+        RedisSerializer<String> redisSerializer = new StringRedisSerializer();
+        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
+        //解决查询缓存转换异常的问题
+        ObjectMapper om = new ObjectMapper();
+        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+        jackson2JsonRedisSerializer.setObjectMapper(om);
+        // 配置序列化(解决乱码的问题),过期时间600秒
+        RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
+                .entryTtl(Duration.ofSeconds(600))
+                .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
+                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer))
+                .disableCachingNullValues();
+        return RedisCacheManager.builder(factory)
+                .cacheDefaults(config)
+                .build();
+    }
+}

+ 4 - 0
src/main/java/org/example/music/controller/AdminController.java

@@ -1,5 +1,7 @@
 package org.example.music.controller;
 
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.example.music.common.R;
 import org.example.music.model.request.AdminRequest;
 import org.example.music.service.AdminService;
@@ -13,12 +15,14 @@ import javax.servlet.http.HttpSession;
 /**
  * 后台管理的相关事宜
  */
+@Api(value = "AdminController", tags = {"登录控制类"})
 @RestController
 public class AdminController {
     @Autowired
     private AdminService adminService;
 
     // 判断是否登录成功
+    @ApiOperation(value = "登录校验")
     @PostMapping("/admin/login/status")
     public R loginStatus(@RequestBody AdminRequest adminRequest, HttpSession session) {
         return adminService.verityPasswd(adminRequest, session);

+ 4 - 2
src/main/java/org/example/music/controller/BannerController.java

@@ -1,5 +1,6 @@
 package org.example.music.controller;
 
+import io.swagger.annotations.ApiOperation;
 import org.example.music.common.R;
 import org.example.music.service.BannerService;
 import io.swagger.annotations.Api;
@@ -9,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * @Author 祝英台炸油条
+ * @Author lc
  * @Time : 2022/6/13 13:16
  **/
 @RestController
@@ -20,8 +21,9 @@ public class BannerController {
     @Autowired
     private BannerService bannerService;
 
+    @ApiOperation(value = "获取全部轮播图")
     @GetMapping("/getAllBanner")
     public R getAllBanner(){
-        return R.success("成功获取轮播图",bannerService.getAllBanner());
+        return R.success("成功获取轮播图",bannerService.getAllBanner());
     }
 }

+ 4 - 2
src/main/java/org/example/music/controller/CollectController.java

@@ -8,14 +8,13 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-@Api(value = "BannerController", tags = {"轮播控制类"})
+@Api(value = "CollectController", tags = {"歌曲收藏控制类"})
 @RestController
 public class CollectController {
 
     @Autowired
     private CollectService collectService;
 
-
     // 添加收藏的歌曲
     //前台界面逻辑
     @ApiOperation(value = "添加收藏歌曲")
@@ -26,12 +25,14 @@ public class CollectController {
 
     //TODO  这些其实有点偏简单的逻辑  所以就一点 所以放在外面  拿到里面
     // 取消收藏的歌曲
+    @ApiOperation(value = "取消收藏歌曲")
     @DeleteMapping("/collection/delete")
     public R deleteCollection(@RequestParam Integer userId, @RequestParam Integer songId) {
         return collectService.deleteCollect(userId, songId);
     }
 
     // 是否收藏歌曲
+    @ApiOperation(value = "判断是否已经收藏歌曲")
     @PostMapping("/collection/status")
     public R isCollection(@RequestBody CollectRequest isCollectRequest) {
         return collectService.existSongId(isCollectRequest);
@@ -39,6 +40,7 @@ public class CollectController {
     }
 
     // 返回的指定用户 ID 收藏的列表
+    @ApiOperation(value = "查询收藏列表")
     @GetMapping("/collection/detail")
     public R collectionOfUser(@RequestParam Integer userId) {
         return collectService.collectionOfUser(userId);

+ 8 - 1
src/main/java/org/example/music/controller/CommentController.java

@@ -1,42 +1,49 @@
 package org.example.music.controller;
 
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.example.music.common.R;
 import org.example.music.model.request.CommentRequest;
 import org.example.music.service.CommentService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+@Api(value = "CommentController", tags = {"评论控制类"})
 @RestController
 public class CommentController {
     @Autowired
     private CommentService commentService;
 
-
     // 提交评论
+    @ApiOperation(value = "新增评论")
     @PostMapping("/comment/add")
     public R addComment(@RequestBody CommentRequest addCommentRequest) {
         return commentService.addComment(addCommentRequest);
     }
 
     // 删除评论
+    @ApiOperation(value = "删除评论")
     @GetMapping("/comment/delete")
     public R deleteComment(@RequestParam Integer id) {
         return commentService.deleteComment(id);
     }
 
     // 获得指定歌曲 ID 的评论列表
+    @ApiOperation(value = "获取指定歌曲的评论列表")
     @GetMapping("/comment/song/detail")
     public R commentOfSongId(@RequestParam Integer songId) {
         return commentService.commentOfSongId(songId);
     }
 
     // 获得指定歌单 ID 的评论列表
+    @ApiOperation(value = "获取指定歌单的评论列表")
     @GetMapping("/comment/songList/detail")
     public R commentOfSongListId(@RequestParam Integer songListId) {
         return commentService.commentOfSongListId(songListId);
     }
 
     // 点赞
+    @ApiOperation(value = "点赞")
     @PostMapping("/comment/like")
     public R commentOfLike(@RequestBody CommentRequest upCommentRequest) {
         return commentService.updateCommentMsg(upCommentRequest);

+ 31 - 15
src/main/java/org/example/music/controller/ConsumerController.java

@@ -1,5 +1,7 @@
 package org.example.music.controller;
 
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.example.music.common.R;
 import org.example.music.model.domain.Consumer;
 import org.example.music.model.domain.ResetPasswordRequest;
@@ -10,12 +12,14 @@ import org.example.music.service.impl.SimpleOrderManager;
 import org.example.music.util.RandomUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpSession;
 import java.util.concurrent.TimeUnit;
 
+@Api(value = "ConsumerController", tags = {"用户控制类"})
 @RestController
 public class ConsumerController {
 
@@ -28,12 +32,14 @@ public class ConsumerController {
     @Autowired
     private SimpleOrderManager simpleOrderManager;
 
-//    @Autowired
-//    StringRedisTemplate stringRedisTemplate;
+    @Autowired
+    StringRedisTemplate stringRedisTemplate;
+
     /**
      * TODO 前台页面调用 注册
      * 用户注册
      */
+    @ApiOperation(value = "注册")
     @PostMapping("/user/add")
     public R addUser(@RequestBody ConsumerRequest registryRequest) {
         return consumerService.addUser(registryRequest);
@@ -43,13 +49,16 @@ public class ConsumerController {
      * TODO 前台页面调用  登录
      * 登录判断
      */
+    @ApiOperation(value = "登录")
     @PostMapping("/user/login/status")
     public R loginStatus(@RequestBody ConsumerRequest loginRequest, HttpSession session) {
         return consumerService.loginStatus(loginRequest, session);
     }
+
     /**
      * email登录
      */
+    @ApiOperation(value = "email登录")
     @PostMapping("/user/email/status")
     public R loginEmailStatus(@RequestBody ConsumerRequest loginRequest, HttpSession session) {
         return consumerService.loginEmailStatus(loginRequest, session);
@@ -58,17 +67,17 @@ public class ConsumerController {
     /**
      * 密码恢复(忘记密码)
      */
-
+    @ApiOperation(value = "重置密码")
     @PostMapping("/user/resetPassword")
-    public R resetPassword(@RequestBody ResetPasswordRequest passwordRequest){
+    public R resetPassword(@RequestBody ResetPasswordRequest passwordRequest) {
         Consumer user = consumerService.findByEmail(passwordRequest.getEmail());
-//        String code = stringRedisTemplate.opsForValue().get("code");
-//        if (user==null){
-//            return R.fatal("用户不存在");
-//        }else if (!code.equals(passwordRequest.getCode())){
-//            return R.fatal("验证码不存在或失效");
-//        }
-        ConsumerRequest consumerRequest=new ConsumerRequest();
+        String code = stringRedisTemplate.opsForValue().get("code");
+        if (user==null){
+            return R.fatal("用户不存在");
+        }else if (!code.equals(passwordRequest.getCode())){
+            return R.fatal("验证码不存在或失效");
+        }
+        ConsumerRequest consumerRequest = new ConsumerRequest();
         BeanUtils.copyProperties(user, consumerRequest);
         System.out.println(user);
         System.out.println(consumerRequest);
@@ -81,16 +90,17 @@ public class ConsumerController {
     /**
      * 发送验证码功能
      */
+    @ApiOperation(value = "发送验证码")
     @GetMapping("/user/sendVerificationCode")
-    public R sendCode(@RequestParam String email){
+    public R sendCode(@RequestParam String email) {
         Consumer user = consumerService.findByEmail(email);
-        if (user==null){
+        if (user == null) {
             return R.fatal("用户不存在");
         }
         String code = RandomUtils.code();
-//        simpleOrderManager.sendCode(code,email);
+        simpleOrderManager.sendCode(code,email);
         //保存在redis中
-//        stringRedisTemplate.opsForValue().set("code",code,5, TimeUnit.MINUTES);
+        stringRedisTemplate.opsForValue().set("code",code,5, TimeUnit.MINUTES);
         return R.success("发送成功");
     }
 
@@ -99,6 +109,7 @@ public class ConsumerController {
      * TODO 管理界面调用
      * 返回所有用户
      */
+    @ApiOperation(value = "查询所有用户")
     @GetMapping("/user")
     public R allUser() {
         return consumerService.allUser();
@@ -109,6 +120,7 @@ public class ConsumerController {
      * TODO 用户界面调用
      * 返回指定 ID 的用户
      */
+    @ApiOperation(value = "用户详情")
     @GetMapping("/user/detail")
     public R userOfId(@RequestParam int id) {
         return consumerService.userOfId(id);
@@ -118,6 +130,7 @@ public class ConsumerController {
      * TODO 管理界面的调用
      * 删除用户
      */
+    @ApiOperation(value = "删除用户")
     @GetMapping("/user/delete")
     public R deleteUser(@RequestParam int id) {
         return consumerService.deleteUser(id);
@@ -127,6 +140,7 @@ public class ConsumerController {
      * TODO 前后台界面的调用
      * 更新用户信息
      */
+    @ApiOperation(value = "更新用户信息")
     @PostMapping("/user/update")
     public R updateUserMsg(@RequestBody ConsumerRequest updateRequest) {
         return consumerService.updateUserMsg(updateRequest);
@@ -136,6 +150,7 @@ public class ConsumerController {
      * TODO 前后台更新用户的密码
      * 更新用户密码
      */
+    @ApiOperation(value = "更新用户密码")
     @PostMapping("/user/updatePassword")
     public R updatePassword(@RequestBody ConsumerRequest updatePasswordRequest) {
         return consumerService.updatePassword(updatePasswordRequest);
@@ -144,6 +159,7 @@ public class ConsumerController {
     /**
      * 更新用户头像
      */
+    @ApiOperation(value = "更新用户头像")
     @PostMapping("/user/avatar/update")
     public R updateUserPic(@RequestParam("file") MultipartFile avatorFile, @RequestParam("id") int id) {
         return consumerService.updateUserAvator(avatorFile, id);

+ 41 - 33
src/main/java/org/example/music/controller/FileDownloadController.java

@@ -1,5 +1,10 @@
 package org.example.music.controller;
 
+import io.minio.GetObjectArgs;
+import io.minio.MinioClient;
+import io.minio.errors.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.io.ByteArrayResource;
@@ -19,41 +24,44 @@ import java.io.InputStream;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
 
+@Api(value = "FileDownloadController", tags = {"下载控制类"})
 @Controller
 @RequestMapping("/download")
 public class FileDownloadController {
 
-//    @Autowired
-//    private MinioClient minioClient;
-//    @Value("${minio.bucket-name}")
-//    private String bucketName;
-//
-//    @GetMapping("/{fileName}")
-//    public ResponseEntity<Resource> downloadFile(@PathVariable String fileName, HttpServletRequest request) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
-//
-//        GetObjectArgs args = GetObjectArgs.builder()
-//                .bucket(bucketName)
-//                .object(fileName)
-//                .build();
-//        InputStream inputStream = minioClient.getObject(args);
-//
-//        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-//        byte[] buffer = new byte[1024];
-//        int bytesRead;
-//        while ((bytesRead = inputStream.read(buffer)) != -1) {
-//            outputStream.write(buffer, 0, bytesRead);
-//        }
-//        byte[] musicBytes = outputStream.toByteArray();
-//        // 创建一个ByteArrayResource对象,用于包装字节数组
-//        ByteArrayResource resource = new ByteArrayResource(musicBytes);
-//        // 构建响应头
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName);
-//        // 返回一个 ResponseEntity 对象
-//        return ResponseEntity.ok()
-//                .headers(headers)
-//                .contentLength(musicBytes.length)
-//                .contentType(MediaType.APPLICATION_OCTET_STREAM)
-//                .body(resource);
-//    }
+    @Autowired
+    private MinioClient minioClient;
+
+    @Value("${minio.bucket-name}")
+    private String bucketName;
+
+    @ApiOperation(value = "下载")
+    @GetMapping("/{fileName}")
+    public ResponseEntity<Resource> downloadFile(@PathVariable String fileName, HttpServletRequest request) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
+
+        GetObjectArgs args = GetObjectArgs.builder()
+                .bucket(bucketName)
+                .object(fileName)
+                .build();
+        InputStream inputStream = minioClient.getObject(args);
+
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        byte[] buffer = new byte[1024];
+        int bytesRead;
+        while ((bytesRead = inputStream.read(buffer)) != -1) {
+            outputStream.write(buffer, 0, bytesRead);
+        }
+        byte[] musicBytes = outputStream.toByteArray();
+        // 创建一个ByteArrayResource对象,用于包装字节数组
+        ByteArrayResource resource = new ByteArrayResource(musicBytes);
+        // 构建响应头
+        HttpHeaders headers = new HttpHeaders();
+        headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName);
+        // 返回一个 ResponseEntity 对象
+        return ResponseEntity.ok()
+                .headers(headers)
+                .contentLength(musicBytes.length)
+                .contentType(MediaType.APPLICATION_OCTET_STREAM)
+                .body(resource);
+    }
  }

+ 9 - 1
src/main/java/org/example/music/controller/ListSongController.java

@@ -1,6 +1,8 @@
 package org.example.music.controller;
 
 import com.alibaba.excel.EasyExcel;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.example.music.common.R;
 import org.example.music.model.domain.SongList;
 import org.example.music.model.request.ListSongRequest;
@@ -21,6 +23,7 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.util.List;
 
+@Api(value = "ListSongController", tags = {"歌单控制类"})
 @RestController
 public class ListSongController {
 
@@ -28,30 +31,35 @@ public class ListSongController {
     private ListSongService listSongService;
     @Autowired
     private SongListService service;
+
     // 给歌单添加歌曲
+    @ApiOperation(value = "给歌单添加歌曲")
     @PostMapping("/listSong/add")
     public R addListSong(@RequestBody ListSongRequest addListSongRequest) {
         return listSongService.addListSong(addListSongRequest);
     }
 
-    // 删除歌单里的歌曲
+    @ApiOperation(value = "删除歌单里的歌曲")
     @GetMapping("/listSong/delete")
     public R deleteListSong(@RequestParam int songId) {
         return listSongService.deleteListSong(songId);
     }
 
     // 返回歌单里指定歌单 ID 的歌曲
+    @ApiOperation(value = "返回歌单里指定歌单 ID 的歌曲")
     @GetMapping("/listSong/detail")
     public R listSongOfSongId(@RequestParam int songListId) {
         return listSongService.listSongOfSongId(songListId);
     }
 
     // 更新歌单里面的歌曲信息
+    @ApiOperation(value = "更新歌单里面的歌曲信息")
     @PostMapping("/listSong/update")
     public R updateListSongMsg(@RequestBody ListSongRequest updateListSongRequest) {
         return listSongService.updateListSongMsg(updateListSongRequest);
     }
     //导出歌单
+    @ApiOperation(value = "导出歌单")
     @GetMapping("/excle")
     public ResponseEntity<Resource> getExcle(HttpServletRequest request) throws IOException {
         String fileName = "SongList" + System.currentTimeMillis() + ".xlsx";

+ 102 - 99
src/main/java/org/example/music/controller/MinioController.java

@@ -1,5 +1,8 @@
 package org.example.music.controller;
 
+import io.minio.GetObjectArgs;
+import io.minio.MinioClient;
+import org.apache.commons.compress.utils.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpHeaders;
@@ -15,103 +18,103 @@ import java.io.InputStream;
 
 @Controller
 public class MinioController {
-//    @Value("${minio.bucket-name}")
-//    private String bucketName;
-//    @Autowired
-//    private MinioClient minioClient;
-//    //获取歌曲
-//    @GetMapping("/user01/{fileName:.+}")
-//    public ResponseEntity<byte[]> getMusic(@PathVariable String fileName) {
-//        try {
-//            GetObjectArgs args = GetObjectArgs.builder()
-//                    .bucket(bucketName)
-//                    .object(fileName)
-//                    .build();
-//            InputStream inputStream = minioClient.getObject(args);
-//
-//            // 将文件内容读取为字节数组
-//            byte[] bytes = IOUtils.toByteArray(inputStream);
-//
-//            // 设置响应头,指示浏览器如何处理响应内容
-//            HttpHeaders headers = new HttpHeaders();
-//            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
-//            headers.setContentDispositionFormData("attachment", fileName); // 如果需要下载文件,可以使用此头部
-//
-//            // 返回字节数组作为响应
-//            return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
-//        }
-//    }
-//    //获取歌手图片
-//    @GetMapping("/user01/singer/img/{fileName:.+}")
-//    public ResponseEntity<byte[]> getImage(@PathVariable String fileName) throws Exception {
-//        InputStream stream = minioClient.getObject(
-//                GetObjectArgs.builder()
-//                        .bucket(bucketName)
-//                        .object("singer/img/"+fileName)
-//                        .build()
-//        );
-//
-//        byte[] bytes = IOUtils.toByteArray(stream);
-//
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.setContentType(MediaType.IMAGE_JPEG); // 设置响应内容类型为图片类型,根据实际情况修改
-//
-//        return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
-//    }
-//    //获取歌单图片
-//    @GetMapping("/user01/songlist/{fileName:.+}")
-//    public ResponseEntity<byte[]> getImage1(@PathVariable String fileName) throws Exception {
-//        InputStream stream = minioClient.getObject(
-//                GetObjectArgs.builder()
-//                        .bucket(bucketName)
-//                        .object("songlist/"+fileName)
-//                        .build()
-//        );
-//
-//        byte[] bytes = IOUtils.toByteArray(stream);
-//
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.setContentType(MediaType.IMAGE_JPEG); // 设置响应内容类型为图片类型,根据实际情况修改
-//
-//        return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
-//    }
-//    //获取歌的图片
-//    ///user01/singer/song/98329722.jfif
-//    @GetMapping("/user01/singer/song/{fileName:.+}")
-//    public ResponseEntity<byte[]> getImage2(@PathVariable String fileName) throws Exception {
-//        InputStream stream = minioClient.getObject(
-//                GetObjectArgs.builder()
-//                        .bucket(bucketName)
-//                        .object("singer/song/"+fileName)
-//                        .build()
-//        );
-//
-//        byte[] bytes = IOUtils.toByteArray(stream);
-//
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.setContentType(MediaType.IMAGE_JPEG); // 设置响应内容类型为图片类型,根据实际情况修改
-//
-//        return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
-//    }
-//    //获取头像
-//    ///img/avatorImages/
-//    @GetMapping("/img/avatorImages/{fileName:.+}")
-//    public ResponseEntity<byte[]> getImage3(@PathVariable String fileName) throws Exception {
-//        InputStream stream = minioClient.getObject(
-//                GetObjectArgs.builder()
-//                        .bucket(bucketName)
-//                        .object("img/avatorImages/"+fileName)
-//                        .build()
-//        );
-//
-//        byte[] bytes = IOUtils.toByteArray(stream);
-//
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.setContentType(MediaType.IMAGE_JPEG); // 设置响应内容类型为图片类型,根据实际情况修改
-//
-//        return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
-//    }
+    @Value("${minio.bucket-name}")
+    private String bucketName;
+    @Autowired
+    private MinioClient minioClient;
+    //获取歌曲
+    @GetMapping("/user01/{fileName:.+}")
+    public ResponseEntity<byte[]> getMusic(@PathVariable String fileName) {
+        try {
+            GetObjectArgs args = GetObjectArgs.builder()
+                    .bucket(bucketName)
+                    .object(fileName)
+                    .build();
+            InputStream inputStream = minioClient.getObject(args);
+
+            // 将文件内容读取为字节数组
+            byte[] bytes = IOUtils.toByteArray(inputStream);
+
+            // 设置响应头,指示浏览器如何处理响应内容
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+            headers.setContentDispositionFormData("attachment", fileName); // 如果需要下载文件,可以使用此头部
+
+            // 返回字节数组作为响应
+            return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+    //获取歌手图片
+    @GetMapping("/user01/singer/img/{fileName:.+}")
+    public ResponseEntity<byte[]> getImage(@PathVariable String fileName) throws Exception {
+        InputStream stream = minioClient.getObject(
+                GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object("singer/img/"+fileName)
+                        .build()
+        );
+
+        byte[] bytes = IOUtils.toByteArray(stream);
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.IMAGE_JPEG); // 设置响应内容类型为图片类型,根据实际情况修改
+
+        return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
+    }
+    //获取歌单图片
+    @GetMapping("/user01/songlist/{fileName:.+}")
+    public ResponseEntity<byte[]> getImage1(@PathVariable String fileName) throws Exception {
+        InputStream stream = minioClient.getObject(
+                GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object("songlist/"+fileName)
+                        .build()
+        );
+
+        byte[] bytes = IOUtils.toByteArray(stream);
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.IMAGE_JPEG); // 设置响应内容类型为图片类型,根据实际情况修改
+
+        return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
+    }
+    //获取歌的图片
+    ///user01/singer/song/98329722.jfif
+    @GetMapping("/user01/singer/song/{fileName:.+}")
+    public ResponseEntity<byte[]> getImage2(@PathVariable String fileName) throws Exception {
+        InputStream stream = minioClient.getObject(
+                GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object("singer/song/"+fileName)
+                        .build()
+        );
+
+        byte[] bytes = IOUtils.toByteArray(stream);
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.IMAGE_JPEG); // 设置响应内容类型为图片类型,根据实际情况修改
+
+        return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
+    }
+    //获取头像
+    ///img/avatorImages/
+    @GetMapping("/img/avatorImages/{fileName:.+}")
+    public ResponseEntity<byte[]> getImage3(@PathVariable String fileName) throws Exception {
+        InputStream stream = minioClient.getObject(
+                GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object("img/avatorImages/"+fileName)
+                        .build()
+        );
+
+        byte[] bytes = IOUtils.toByteArray(stream);
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.IMAGE_JPEG); // 设置响应内容类型为图片类型,根据实际情况修改
+
+        return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
+    }
 }

+ 119 - 121
src/main/java/org/example/music/controller/MinioUploadController.java

@@ -1,5 +1,8 @@
 package org.example.music.controller;
 
+import io.minio.MinioClient;
+import io.minio.PutObjectArgs;
+import io.minio.errors.MinioException;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -12,135 +15,130 @@ import java.util.Properties;
 @Service
 public class MinioUploadController {
 
-//    private static MinioClient minioClient;
-//    private static String bucketName;
-//
-//    public static void init(){
-//        Properties properties = new Properties();
-//        try {
-//            // 使用类加载器获取资源文件的输入流
-//            InputStream inputStream = org.example.music.controller.MinioUploadController.class.getClassLoader().getResourceAsStream("application-dev.properties");
-//            if (inputStream != null) {
-//                properties.load(inputStream);
-//                String minioEndpoint = properties.getProperty("minio.endpoint");
-//                String minioAccessKey = properties.getProperty("minio.access-key");
-//                String minioSecretKey = properties.getProperty("minio.secret-key");
-//                String minioBucketName = properties.getProperty("minio.bucket-name");
-//                bucketName = minioBucketName;
-//                minioClient = MinioClient.builder()
-//                        .endpoint(minioEndpoint)
-//                        .credentials(minioAccessKey, minioSecretKey)
-//                        .build();
-//            }
-//        }catch (Exception e){
-//            System.out.println(e);
-//        }
-//    }
-//
+    private static MinioClient minioClient;
+    private static String bucketName;
+
+    public static void init(){
+        Properties properties = new Properties();
+        try {
+            // 使用类加载器获取资源文件的输入流
+            InputStream inputStream = org.example.music.controller.MinioUploadController.class.getClassLoader().getResourceAsStream("application-dev.properties");
+            if (inputStream != null) {
+                properties.load(inputStream);
+                String minioEndpoint = properties.getProperty("minio.endpoint");
+                String minioAccessKey = properties.getProperty("minio.access-key");
+                String minioSecretKey = properties.getProperty("minio.secret-key");
+                String minioBucketName = properties.getProperty("minio.bucket-name");
+                bucketName = minioBucketName;
+                minioClient = MinioClient.builder()
+                        .endpoint(minioEndpoint)
+                        .credentials(minioAccessKey, minioSecretKey)
+                        .build();
+            }
+        }catch (Exception e){
+            System.out.println(e);
+        }
+    }
+
     public static String uploadFile(MultipartFile file) {
-//        try {
-//            init();
-//            InputStream inputStream = file.getInputStream();
-//            minioClient.putObject(
-//                    PutObjectArgs.builder()
-//                            .bucket(bucketName)
-//                            .object(file.getOriginalFilename())
-//                            .stream(inputStream, inputStream.available(), -1)
-//                            .contentType(file.getContentType())
-//                            .build()
-//            );
-//            return "File uploaded successfully!";
-//        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
-//            e.printStackTrace();
-//            return "Error uploading file to MinIO: " + e.getMessage();
-//        } catch (Exception e) {
-//            throw new RuntimeException(e);
-//        }
-        return "File uploaded successfully!";
+        try {
+            init();
+            InputStream inputStream = file.getInputStream();
+            minioClient.putObject(
+                    PutObjectArgs.builder()
+                            .bucket(bucketName)
+                            .object(file.getOriginalFilename())
+                            .stream(inputStream, inputStream.available(), -1)
+                            .contentType(file.getContentType())
+                            .build()
+            );
+            return "File uploaded successfully!";
+        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
+            e.printStackTrace();
+            return "Error uploading file to MinIO: " + e.getMessage();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
     public static String uploadImgFile(MultipartFile file) {
-//        try {
-//            init();
-//            InputStream inputStream = file.getInputStream();
-//            minioClient.putObject(
-//                    PutObjectArgs.builder()
-//                            .bucket(bucketName)
-//                            .object("/singer/img/"+file.getOriginalFilename())
-//                            .stream(inputStream, inputStream.available(), -1)
-//                            .contentType(file.getContentType())
-//                            .build()
-//            );
-//            return "File uploaded successfully!";
-//        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
-//            e.printStackTrace();
-//            return "Error uploading file to MinIO: " + e.getMessage();
-//        } catch (Exception e) {
-//            throw new RuntimeException(e);
-//        }
-        return "File uploaded successfully!";
+        try {
+            init();
+            InputStream inputStream = file.getInputStream();
+            minioClient.putObject(
+                    PutObjectArgs.builder()
+                            .bucket(bucketName)
+                            .object("/singer/img/"+file.getOriginalFilename())
+                            .stream(inputStream, inputStream.available(), -1)
+                            .contentType(file.getContentType())
+                            .build()
+            );
+            return "File uploaded successfully!";
+        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
+            e.printStackTrace();
+            return "Error uploading file to MinIO: " + e.getMessage();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
     public static String uploadSonglistImgFile(MultipartFile file) {
-//        try {
-//            init();
-//            InputStream inputStream = file.getInputStream();
-//            minioClient.putObject(
-//                    PutObjectArgs.builder()
-//                            .bucket(bucketName)
-//                            .object("/songlist/"+file.getOriginalFilename())
-//                            .stream(inputStream, inputStream.available(), -1)
-//                            .contentType(file.getContentType())
-//                            .build()
-//            );
-//            return "File uploaded successfully!";
-//        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
-//            e.printStackTrace();
-//            return "Error uploading file to MinIO: " + e.getMessage();
-//        } catch (Exception e) {
-//            throw new RuntimeException(e);
-//        }
-        return "File uploaded successfully!";
+        try {
+            init();
+            InputStream inputStream = file.getInputStream();
+            minioClient.putObject(
+                    PutObjectArgs.builder()
+                            .bucket(bucketName)
+                            .object("/songlist/"+file.getOriginalFilename())
+                            .stream(inputStream, inputStream.available(), -1)
+                            .contentType(file.getContentType())
+                            .build()
+            );
+            return "File uploaded successfully!";
+        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
+            e.printStackTrace();
+            return "Error uploading file to MinIO: " + e.getMessage();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
     public static String uploadSongImgFile(MultipartFile file) {
-//        try {
-//            init();
-//            InputStream inputStream = file.getInputStream();
-//            minioClient.putObject(
-//                    PutObjectArgs.builder()
-//                            .bucket(bucketName)
-//                            .object("/singer/song/"+file.getOriginalFilename())
-//                            .stream(inputStream, inputStream.available(), -1)
-//                            .contentType(file.getContentType())
-//                            .build()
-//            );
-//            return "File uploaded successfully!";
-//        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
-//            e.printStackTrace();
-//            return "Error uploading file to MinIO: " + e.getMessage();
-//        } catch (Exception e) {
-//            throw new RuntimeException(e);
-//        }
-        return "File uploaded successfully!";
+        try {
+            init();
+            InputStream inputStream = file.getInputStream();
+            minioClient.putObject(
+                    PutObjectArgs.builder()
+                            .bucket(bucketName)
+                            .object("/singer/song/"+file.getOriginalFilename())
+                            .stream(inputStream, inputStream.available(), -1)
+                            .contentType(file.getContentType())
+                            .build()
+            );
+            return "File uploaded successfully!";
+        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
+            e.printStackTrace();
+            return "Error uploading file to MinIO: " + e.getMessage();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
-//
+
     public static String uploadAtorImgFile(MultipartFile file) {
-//        try {
-//            init();
-//            InputStream inputStream = file.getInputStream();
-//            minioClient.putObject(
-//                    PutObjectArgs.builder()
-//                            .bucket(bucketName)
-//                            .object("/img/avatorImages/"+file.getOriginalFilename())
-//                            .stream(inputStream, inputStream.available(), -1)
-//                            .contentType(file.getContentType())
-//                            .build()
-//            );
-//            return "File uploaded successfully!";
-//        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
-//            e.printStackTrace();
-//            return "Error uploading file to MinIO: " + e.getMessage();
-//        } catch (Exception e) {
-//            throw new RuntimeException(e);
-//        }
-        return "File uploaded successfully!";
+        try {
+            init();
+            InputStream inputStream = file.getInputStream();
+            minioClient.putObject(
+                    PutObjectArgs.builder()
+                            .bucket(bucketName)
+                            .object("/img/avatorImages/"+file.getOriginalFilename())
+                            .stream(inputStream, inputStream.available(), -1)
+                            .contentType(file.getContentType())
+                            .build()
+            );
+            return "File uploaded successfully!";
+        } catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
+            e.printStackTrace();
+            return "Error uploading file to MinIO: " + e.getMessage();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
 }

+ 7 - 3
src/main/java/org/example/music/model/request/AdminRequest.java

@@ -1,16 +1,20 @@
 package org.example.music.model.request;
 
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 /**
- * @Author 祝英台炸油条
+ * @Author lc
  * @Time : 2022/6/6 18:44
  **/
+@ApiModel(value = "AdminRequest", description = "登录")
 @Data
 public class AdminRequest {
+    @ApiModelProperty(value = "自增id", required = false, example = "")
     private Integer id;
-
+    @ApiModelProperty(value = "用户名", required = true, example = "")
     private String username;
-
+    @ApiModelProperty(value = "密码", required = true, example = "")
     private String password;
 }

+ 26 - 19
src/main/java/org/example/music/service/impl/SimpleOrderManager.java

@@ -4,8 +4,15 @@ import org.example.music.model.domain.Order;
 import org.example.music.service.OrderManager;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.MimeMessagePreparator;
 import org.springframework.stereotype.Service;
 
+import javax.mail.Message;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.validation.constraints.NotNull;
+
 
 /**
  * 邮箱信息的发送
@@ -14,15 +21,15 @@ import org.springframework.stereotype.Service;
 @Service
 public class SimpleOrderManager implements OrderManager {
 
-//    @Value("${mail.address}")
-//    private String sendAddress;
+    @Value("${mail.address}")
+    private String sendAddress;
 
-//    @Autowired
-//    private JavaMailSender mailSender;
-//
-//    public void setMailSender(JavaMailSender mailSender) {
-//        this.mailSender = mailSender;
-//    }
+    @Autowired
+    private JavaMailSender mailSender;
+
+    public void setMailSender(JavaMailSender mailSender) {
+        this.mailSender = mailSender;
+    }
 //
 //    public void sendPassword(Order order, String reciveAddress) {
 //        MimeMessagePreparator preparator = new MimeMessagePreparator() {
@@ -43,15 +50,15 @@ public class SimpleOrderManager implements OrderManager {
 //        }
 //    }
 //
-//    public void sendCode(String code, String reciveAddress) {
-//        MimeMessagePreparator preparator = new MimeMessagePreparator() {
-//            public void prepare(@NotNull MimeMessage mimeMessage) throws Exception {
-//                mimeMessage.setRecipient(Message.RecipientType.TO,
-//                        new InternetAddress(reciveAddress));
-//                mimeMessage.setFrom(new InternetAddress(sendAddress));
-//                mimeMessage.setText("Dear you code is " + code);
-//            }
-//        };
-//        this.mailSender.send(preparator);
-//    }
+    public void sendCode(String code, String reciveAddress) {
+        MimeMessagePreparator preparator = new MimeMessagePreparator() {
+            public void prepare(@NotNull MimeMessage mimeMessage) throws Exception {
+                mimeMessage.setRecipient(Message.RecipientType.TO,
+                        new InternetAddress(reciveAddress));
+                mimeMessage.setFrom(new InternetAddress(sendAddress));
+                mimeMessage.setText("Dear you code is " + code);
+            }
+        };
+        this.mailSender.send(preparator);
+    }
 }

+ 11 - 1
src/main/resources/application-dev.properties

@@ -1,4 +1,14 @@
 spring.datasource.url=jdbc:mysql://47.113.125.203:3306/music?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8
 spring.datasource.username=music
 spring.datasource.password=music_1234
-spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+
+
+minio.endpoint=http://47.113.125.203:9001
+minio.access-key=admin
+minio.secret-key=password
+minio.bucket-name=music
+# 文件上传的大小
+spring.servlet.multipart.max-file-size= 50MB
+# 文件上传的最大请求大小
+spring.servlet.multipart.max-request-size= 50MB

+ 10 - 1
src/main/resources/application.properties

@@ -5,4 +5,13 @@ server.port=8080
 
 #logging.level.org.springframework.boot.autoconfigure=ERROR
 
-spring.profiles.active=dev
+spring.profiles.active=dev
+
+spring.redis.host=47.113.125.203
+spring.redis.port=6379
+spring.redis.database=0
+spring.redis.timeout=1800000
+spring.redis.lettuce.pool.max-active=20
+spring.redis.lettuce.pool.max-wait=-1
+spring.redis.lettuce.pool.max-idle=5
+spring.redis.lettuce.pool.min-idle=0

+ 16 - 0
src/main/resources/application.yml

@@ -0,0 +1,16 @@
+spring:
+  mail:
+    host: smtp.163.com # 网站发送邮件邮箱服务 host
+    port: 465
+    username:   # 开启那个服务的邮箱
+    password:  # 开启服务的那个认证码
+    properties:
+      mail:
+        smtp:
+          auth: true
+          socketFactory:
+            class: javax.net.ssl.SSLSocketFactory
+          starttls:
+            enable: true
+mail:
+  address:   # 开启那个服务的邮箱