diff --git a/luoo_music/pom.xml b/luoo_music/pom.xml
index 0cce7b0..d1a57fd 100644
--- a/luoo_music/pom.xml
+++ b/luoo_music/pom.xml
@@ -52,13 +52,13 @@
org.springframework.boot
spring-boot-starter-actuator
+
org.apache.tika
tika-core
1.27
-
-
+
software.amazon.awssdk
s3
diff --git a/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java b/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java
index ba8e41a..539d499 100644
--- a/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java
+++ b/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java
@@ -27,7 +27,6 @@ public class AwsS3Config {
.region(region)
.serviceConfiguration(s3Config)
.build();
-
return s3;
}
@@ -38,7 +37,6 @@ public class AwsS3Config {
.endpointOverride(URI.create("https://s3.bitiful.net/"))
.region(region)
.build();
-
return presigner;
}
}
diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java
index ffaa860..05d0830 100644
--- a/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java
+++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java
@@ -6,6 +6,7 @@ import com.luoo.music.request.cms.JournalAddModel;
import com.luoo.music.request.cms.JournalQueryModel;
import com.luoo.music.response.cms.JournalVO;
import com.luoo.music.service.CMSJournalService;
+import com.luoo.music.service.S3Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -24,20 +25,22 @@ public class CMSJournalController {
@Autowired
private CMSJournalService journalService;
+ @Autowired
+ private S3Service s3Service;
@ApiOperation(value = "查询期刊列表", notes = "查询期刊列表")
@RequestMapping(value="/search/{page}/{size}", method= RequestMethod.POST)
public Result> search(@ApiParam(value = "查询条件对象", required = true) @RequestBody JournalQueryModel queryModel,
- @ApiParam(value = "页码", required = true) @PathVariable int page,
- @ApiParam(value = "每页条数", required = true) @PathVariable int size){
+ @ApiParam(value = "页码", required = true) @PathVariable int page,
+ @ApiParam(value = "每页条数", required = true) @PathVariable int size){
return journalService.search(queryModel, page, size);
}
@ApiOperation(value = "新增期刊", notes = "新增期刊")
@RequestMapping(value = "/add", method = RequestMethod.POST)
- public Result add(@ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel addModel,
- @ApiParam(value = "封面文件", required = true) @RequestParam("imageFile") MultipartFile imageFile){
- return journalService.add(addModel, imageFile);
+ public Result add(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token,
+ @ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel addModel){
+ return journalService.add(token, addModel);
}
@ApiOperation(value = "查询期刊详情", notes = "查询期刊详情")
@@ -49,17 +52,17 @@ public class CMSJournalController {
@ApiOperation(value = "更新期刊", notes = "更新期刊")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Result update(@ApiParam(value = "期刊ID", required = true) @PathVariable String id,
- @ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel updateModel,
- @ApiParam(value = "封面文件", required = true) @RequestParam("imageFile") MultipartFile imageFile){
- return journalService.update(id, updateModel, imageFile);
+ @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token,
+ @ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel updateModel){
+ return journalService.update(id, token, updateModel);
}
@ApiOperation(value = "发布期刊", notes = "发布期刊")
@RequestMapping(value="/publish/{id}",method= RequestMethod.PUT)
public Result publish(@PathVariable String id,
- @ApiParam(value = "是否定时发布,0:否,1:是", required = true) @RequestParam("state") String scheduled,
+ @ApiParam(value = "是否定时发布,0:否,1:是", required = true) @RequestParam("isScheduled") String isScheduled,
@ApiParam(value = "定时发布时间") @RequestParam("state") String pubTime){
- return journalService.publish(id, scheduled, pubTime);
+ return journalService.publish(id, isScheduled, pubTime);
}
@ApiOperation(value = "更新期刊启停状态", notes = "更新期刊启停状态")
@@ -74,4 +77,10 @@ public class CMSJournalController {
public Result delete(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){
return journalService.deleteById(id);
}
+
+ @ApiOperation(value = "上传期刊封面", notes = "上传期刊封面")
+ @RequestMapping(value = "/upload/image", method = RequestMethod.POST)
+ public Result batchUpload(@ApiParam(value = "封面图片文件", required = true) @RequestParam("file") MultipartFile file) {
+ return s3Service.upload(file, Boolean.FALSE);
+ }
}
diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java
index 699461d..f4907bc 100644
--- a/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java
+++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSSongController.java
@@ -6,6 +6,7 @@ import com.luoo.music.request.cms.SongAddModel;
import com.luoo.music.request.cms.SongQueryModel;
import com.luoo.music.response.cms.SongVO;
import com.luoo.music.service.CMSSongService;
+import com.luoo.music.service.S3Service;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -24,8 +25,10 @@ public class CMSSongController {
@Autowired
private CMSSongService songService;
+ @Autowired
+ private S3Service s3Service;
- @ApiOperation(value = "查询曲目列表", notes = "查询曲目列表")
+ @ApiOperation(value = "查询歌曲列表", notes = "查询歌曲列表")
@RequestMapping(value="/search/{page}/{size}",method= RequestMethod.POST)
public Result> search(@ApiParam(value = "查询条件") @RequestBody SongQueryModel queryModel,
@ApiParam(value = "页码", required = true) @PathVariable int page,
@@ -35,10 +38,9 @@ public class CMSSongController {
@ApiOperation(value = "新增歌曲", notes = "新增歌曲")
@RequestMapping(value = "/add", method = RequestMethod.POST)
- public Result add(@ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel addModel,
- @ApiParam(value = "封面图片", required = true) @RequestParam("imageFile") MultipartFile imageFile,
- @ApiParam(value = "歌曲文件", required = true) @RequestParam("songFile") MultipartFile songFile){
- return songService.add(addModel, imageFile, songFile);
+ public Result add(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token,
+ @ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel addModel){
+ return songService.add(token, addModel);
}
@ApiOperation(value = "查询歌曲详情", notes = "查询歌曲详情")
@@ -49,11 +51,10 @@ public class CMSSongController {
@ApiOperation(value = "更新歌曲信息", notes = "更新歌曲信息")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
- public Result update(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id,
- @ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel updateModel,
- @ApiParam(value = "封面图片", required = true) @RequestParam("imageFile") MultipartFile imageFile,
- @ApiParam(value = "歌曲文件", required = true) @RequestParam("songFile") MultipartFile songFile){
- return songService.update(id, updateModel, imageFile, songFile);
+ public Result update(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token,
+ @ApiParam(value = "歌曲ID", required = true) @PathVariable String id,
+ @ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel updateModel){
+ return songService.update(id, token, updateModel);
}
@ApiOperation(value = "更新歌曲启停状态", notes = "更新歌曲启停状态")
@@ -66,20 +67,26 @@ public class CMSSongController {
@ApiOperation(value = "更新歌曲歌词", notes = "更新歌曲歌词")
@RequestMapping(value="/update/lyric/{id}",method= RequestMethod.PUT)
public Result updateSongLyric(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id,
- @ApiParam(value = "歌曲歌词", required = true) @RequestParam("lyric") String lyric){
- return songService.updateSongLyric(id, lyric);
+ @ApiParam(value = "歌曲歌词信息", required = true) @RequestBody SongAddModel updateModel){
+ return songService.updateSongLyric(id, updateModel.getLyric());
}
- @ApiOperation(value = "批量上传歌曲", notes = "批量上传歌曲")
- @RequestMapping(value = "/batch", method = RequestMethod.POST)
- public Result batchUpload(@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List files) {
- return songService.batchUpload(files);
- }
-
@ApiOperation(value = "删除单条歌曲", notes = "删除单条歌曲")
@RequestMapping(value="/{id}", method= RequestMethod.DELETE)
public Result delete(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id){
return songService.deleteById(id);
}
+
+ @ApiOperation(value = "上传歌曲", notes = "上传歌曲")
+ @RequestMapping(value = "/upload/song", method = RequestMethod.POST)
+ public Result batchUpload(@ApiParam(value = "歌曲文件", required = true) @RequestParam("file") MultipartFile file) {
+ return s3Service.upload(file, Boolean.TRUE);
+ }
+
+ @ApiOperation(value = "批量上传歌曲", notes = "批量上传歌曲")
+ @RequestMapping(value = "/batch", method = RequestMethod.POST)
+ public Result batchUpload(@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List files) {
+ return songService.batchUpload(files);
+ }
}
diff --git a/luoo_music/src/main/java/com/luoo/music/controller/S3Controller.java b/luoo_music/src/main/java/com/luoo/music/controller/S3Controller.java
index d9a3aa2..05ceabc 100644
--- a/luoo_music/src/main/java/com/luoo/music/controller/S3Controller.java
+++ b/luoo_music/src/main/java/com/luoo/music/controller/S3Controller.java
@@ -1,75 +1,75 @@
-package com.luoo.music.controller;
-
-
-import api.Result;
-import com.luoo.music.service.S3Service;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.io.UnsupportedEncodingException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-
-@RestController
-@CrossOrigin
-public class S3Controller {
-
- @Autowired
- private S3Service s3Service;
-
-
- @GetMapping("/awstest")
- public Result test() throws UnsupportedEncodingException {
-
-// s3Service.listObjects()
- List list = s3Service.list();
- return Result.success();
- }
-
-
- /**
- * 文件存储目录规划
- *
- * music 存放期刊和期刊歌曲 二级目录为期刊期刊号 三级目录存放期刊歌曲和封面图片和歌曲图片
- *
- * song 存放通用歌曲
- *
- * image存放图片
- *
- * img
- *
- * user/avatar/111.jpg
- *
- *
- *
- *
- */
- @PostMapping("/awsUpload")
- public Result upload(MultipartFile file) {
-
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
-// String fileName = UUID.randomUUID().toString().trim().replaceAll("-", "");
-
-
- String filePath = sdf.format(new Date()) + "/" + file.getOriginalFilename();
- try{
- int code = s3Service.singleUpload("indie", filePath, file);
-
- } catch (Exception ex){
- }
-
-
- return Result.success();
- }
-
- @PostMapping("/awsCopy")
- public Result copy() {
- s3Service.copy();
- return Result.success();
- }
-}
+//package com.luoo.music.controller;
+//
+//
+//import api.Result;
+//import com.luoo.music.service.S3Service;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.web.bind.annotation.CrossOrigin;
+//import org.springframework.web.bind.annotation.GetMapping;
+//import org.springframework.web.bind.annotation.PostMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//import org.springframework.web.multipart.MultipartFile;
+//
+//import java.io.UnsupportedEncodingException;
+//import java.text.SimpleDateFormat;
+//import java.util.Date;
+//import java.util.List;
+//
+//@RestController
+//@CrossOrigin
+//public class S3Controller {
+//
+// @Autowired
+// private S3Service s3Service;
+//
+//
+// @GetMapping("/awstest")
+// public Result test() throws UnsupportedEncodingException {
+//
+//// s3Service.listObjects()
+// List list = s3Service.list();
+// return Result.success();
+// }
+//
+//
+// /**
+// * 文件存储目录规划
+// *
+// * music 存放期刊和期刊歌曲 二级目录为期刊期刊号 三级目录存放期刊歌曲和封面图片和歌曲图片
+// *
+// * song 存放通用歌曲
+// *
+// * image存放图片
+// *
+// * img
+// *
+// * user/avatar/111.jpg
+// *
+// *
+// *
+// *
+// */
+// @PostMapping("/awsUpload")
+// public Result upload(MultipartFile file) {
+//
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+//// String fileName = UUID.randomUUID().toString().trim().replaceAll("-", "");
+//
+//
+// String filePath = sdf.format(new Date()) + "/" + file.getOriginalFilename();
+// try{
+// int code = s3Service.singleUpload("indie", filePath, file);
+//
+// } catch (Exception ex){
+// }
+//
+//
+// return Result.success();
+// }
+//
+// @PostMapping("/awsCopy")
+// public Result copy() {
+// s3Service.copy();
+// return Result.success();
+// }
+//}
diff --git a/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java b/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java
index 8ed0470..fad706a 100644
--- a/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java
+++ b/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java
@@ -16,6 +16,10 @@ import java.util.Set;
*/
public interface JournalDao extends JpaRepository,JpaSpecificationExecutor{
+ List findByJournalNo(String journalNo);
+
+ List findByJournalNoIn(Set journalNos);
+
List findByIdIn(Set ids);
@Modifying
@@ -24,9 +28,8 @@ public interface JournalDao extends JpaRepository,JpaSpecificati
@Param("pubTime") LocalDateTime pubTime);
@Modifying
- @Query("UPDATE Journal j SET j.scheduled = :scheduled, j.pubTime = :pubTime WHERE j.id = :id")
+ @Query("UPDATE Journal j SET j.isScheduled = '1', j.pubTime = :pubTime WHERE j.id = :id")
int updateScheduledPubById(@Param("id") String id,
- @Param("scheduled") String scheduled,
@Param("pubTime") LocalDateTime pubTime);
@Modifying
diff --git a/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java b/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java
index 9bbde1c..2567c31 100644
--- a/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java
+++ b/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java
@@ -15,21 +15,21 @@ import java.util.List;
*/
public interface JournalSongDao extends JpaRepository, JpaSpecificationExecutor {
- @Query("SELECT js.journalId, COUNT(js) AS songCount FROM JournalSong js WHERE js.journalId IN :journalIds GROUP BY js.journalId")
- List findSongCountByJournalIds(@Param("journalIds") List journalIds);
+ @Query("SELECT js.journalNo, COUNT(js) AS songCount FROM JournalSong js WHERE js.journalNo IN :journalNos GROUP BY js.journalNo")
+ List findSongCountByJournalNos(@Param("journalNos") List journalNos);
- @Query("SELECT js.journalId FROM JournalSong js WHERE js.songId = :songId")
- List findJournalBySongId(@Param("songId") String songId);
+ @Query("SELECT js FROM JournalSong js WHERE js.journalNo = :journalNo ORDER BY js.songNo")
+ List findByJournalNo(@Param("journalNo") String journalNo);
- @Query("SELECT js FROM JournalSong js WHERE js.songId IN :songIds ORDER BY js.id")
- List findBySongId(@Param("songIds") List songIds);
+ @Modifying
+ @Query("DELETE FROM JournalSong js WHERE js.journalNo = :journalNo")
+ int deleteByJournalNo(@Param("journalNo") String journalNo);
- @Query("SELECT js FROM JournalSong js WHERE js.journalId = :journalId ORDER BY js.id")
- List findByJournalId(@Param("journalId") String journalId);
+ @Query("SELECT js.journalNo FROM JournalSong js WHERE js.songId = :songId")
+ List findJournalBySongId(@Param("songId") String songId);
- @Modifying
- @Query("DELETE FROM JournalSong js WHERE js.journalId = :journalId")
- int deleteByJournalId(@Param("journalId") String journalId);
+ @Query("SELECT js FROM JournalSong js WHERE js.songId IN :songIds")
+ List findBySongId(@Param("songIds") List songIds);
@Modifying
@Query("DELETE FROM JournalSong js WHERE js.songId = :songId")
diff --git a/luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java b/luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java
index 39302a2..d3bb7bb 100644
--- a/luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java
+++ b/luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java
@@ -23,5 +23,5 @@ public interface SongInfoDao extends JpaRepository, JpaSpecific
@Query("UPDATE SongInfo s SET s.lyric = :lyric WHERE s.id = :id")
int updateSongLyric(@Param("id") String id, @Param("lyric") String lyric);
- List findByIdIn(Set ids);
+ List findByIdIn(List ids);
}
diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java b/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java
index e5b2308..a0fa22a 100644
--- a/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java
+++ b/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java
@@ -20,9 +20,9 @@ import java.time.LocalDateTime;
*/
@Data
@Entity
-@Table(name="tb_journal")
@DynamicInsert
@DynamicUpdate
+@Table(name="tb_journal")
@EntityListeners(AuditingEntityListener.class)
public class Journal implements Serializable{
@@ -32,19 +32,19 @@ public class Journal implements Serializable{
/**
* 期刊编号
*/
- private String number;
+ private String journalNo;
/**
* 期刊标题
*/
- private String name;
+ private String title;
/**
- * 期刊简介
+ * 封面路径
*/
- private String summary;
+ private String image;
/**
- * 用户ID
+ * 期刊文案
*/
- private String userId;
+ private String content;
/**
* 启停状态 停用:0,启用:1
*/
@@ -52,27 +52,43 @@ public class Journal implements Serializable{
/**
* 发布状态 未发布:0,已发布:1
*/
- private String status;
+ private String isPublish;
/**
- * 是否定时 否:0 是:1
+ * 是否定时发布 否:0 是:1
*/
- private String scheduled;
+ private String isScheduled;
/**
- * 封面路径
+ * 浏览量
+ */
+ private Integer visits;
+ /**
+ * 评论量
*/
- private String coverPhoto;
+ private Integer comment;
/**
- * 发布日期
+ * 发布时间
*/
private LocalDateTime pubTime;
/**
- * 创建日期
+ * 创建时间
*/
@CreatedDate
private LocalDateTime createTime;
/**
- * 更新日期
+ * 更新时间
*/
@LastModifiedDate
private LocalDateTime updateTime;
+ /**
+ * 用户ID
+ */
+ private String userId;
+ /**
+ * 用户昵称
+ */
+ private String userName;
+ /**
+ * 用户类型
+ */
+ private String userType;
}
diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/JournalSong.java b/luoo_music/src/main/java/com/luoo/music/pojo/JournalSong.java
index e6ac244..50181c8 100644
--- a/luoo_music/src/main/java/com/luoo/music/pojo/JournalSong.java
+++ b/luoo_music/src/main/java/com/luoo/music/pojo/JournalSong.java
@@ -7,7 +7,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
/**
- * 期刊曲目关系表
+ * 期刊歌曲表
* @author locust
*/
@Data
@@ -18,6 +18,36 @@ public class JournalSong {
@Id
private String id;
- private String journalId;
+ /**
+ * 歌曲名称
+ */
+ private String name;
+ /**
+ * 歌手/乐队
+ */
+ private String artist;
+ /**
+ * 所属专辑
+ */
+ private String album;
+ /**
+ * 文件路径
+ */
+ private String url;
+ /**
+ * 文件路径
+ */
+ private String image;
+ /**
+ * 期刊编号
+ */
+ private String journalNo;
+ /**
+ * 歌曲顺序编号
+ */
+ private Integer songNo;
+ /**
+ * 歌曲ID
+ */
private String songId;
}
diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/JournalSongCount.java b/luoo_music/src/main/java/com/luoo/music/pojo/JournalSongCount.java
index 770c36c..2784add 100644
--- a/luoo_music/src/main/java/com/luoo/music/pojo/JournalSongCount.java
+++ b/luoo_music/src/main/java/com/luoo/music/pojo/JournalSongCount.java
@@ -6,7 +6,7 @@ package com.luoo.music.pojo;
*/
public interface JournalSongCount {
- String getJournalId();
+ String getJournalNo();
Long getSongCount();
}
diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java
index dbf47a2..a8b6770 100644
--- a/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java
+++ b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java
@@ -43,13 +43,13 @@ public class SongInfo implements Serializable {
*/
private String album;
/**
- * 封面图片路径
+ * 歌曲文件路径
*/
- private String picture;
+ private String url;
/**
- * 歌曲状态 0:停用,1:启用
+ * 图片路径
*/
- private String state;
+ private String image;
/**
* 文件大小
*/
@@ -59,25 +59,33 @@ public class SongInfo implements Serializable {
*/
private Long duration;
/**
- * 歌曲文件路径
+ * 歌曲状态 0:停用,1:启用
*/
- private String url;
+ private String state;
/**
- * 歌词
+ * 创建时间
*/
- private String lyric;
+ @CreatedDate
+ private LocalDateTime createTime;
/**
- * 上传人员ID
+ * 更新时间
+ */
+ @LastModifiedDate
+ private LocalDateTime updateTime;
+ /**
+ * 用户ID
*/
private String userId;
/**
- * 创建日期
+ * 用户昵称
*/
- @CreatedDate
- private LocalDateTime createTime;
+ private String userName;
/**
- * 更新日期
+ * 用户类型
*/
- @LastModifiedDate
- private LocalDateTime updateTime;
+ private String userType;
+ /**
+ * 歌词
+ */
+ private String lyric;
}
diff --git a/luoo_music/src/main/java/com/luoo/music/request/cms/JournalAddModel.java b/luoo_music/src/main/java/com/luoo/music/request/cms/JournalAddModel.java
index cef17aa..078df15 100644
--- a/luoo_music/src/main/java/com/luoo/music/request/cms/JournalAddModel.java
+++ b/luoo_music/src/main/java/com/luoo/music/request/cms/JournalAddModel.java
@@ -14,20 +14,23 @@ import java.util.List;
public class JournalAddModel {
@ApiModelProperty(value = "期刊编号")
- private String number;
+ private String journalNo;
@ApiModelProperty(value = "期刊标题")
- private String name;
+ private String title;
+
+ @ApiModelProperty(value = "关联标签,标签ID")
+ private List tags;
@ApiModelProperty(value = "发布人ID")
private String userId;
- @ApiModelProperty(value = "关联标签,标签ID")
- private List tags;
+ @ApiModelProperty(value = "期刊封面路径")
+ private String image;
@ApiModelProperty(value = "关联歌曲,音乐ID")
private List songs;
@ApiModelProperty(value = "期刊内容")
- private String summary;
+ private String content;
}
diff --git a/luoo_music/src/main/java/com/luoo/music/request/cms/SongAddModel.java b/luoo_music/src/main/java/com/luoo/music/request/cms/SongAddModel.java
index 8059261..a6e2a2d 100644
--- a/luoo_music/src/main/java/com/luoo/music/request/cms/SongAddModel.java
+++ b/luoo_music/src/main/java/com/luoo/music/request/cms/SongAddModel.java
@@ -30,4 +30,16 @@ public class SongAddModel {
@ApiModelProperty(value = "风格标签ID集合")
private List tags;
+
+ @ApiModelProperty(value = "歌曲文件路径")
+ private String url;
+
+ @ApiModelProperty(value = "图片文件路径")
+ private String image;
+
+ @ApiModelProperty(value = "文件大小")
+ private Long size;
+
+ @ApiModelProperty(value = "歌曲时长")
+ private Long duration;
}
diff --git a/luoo_music/src/main/java/com/luoo/music/request/cms/SongQueryModel.java b/luoo_music/src/main/java/com/luoo/music/request/cms/SongQueryModel.java
index b4bd14a..ef275f5 100644
--- a/luoo_music/src/main/java/com/luoo/music/request/cms/SongQueryModel.java
+++ b/luoo_music/src/main/java/com/luoo/music/request/cms/SongQueryModel.java
@@ -14,6 +14,9 @@ public class SongQueryModel {
@ApiModelProperty(value = "关键词")
private String keyword;
+ @ApiModelProperty(value = "歌曲启用状态,曲库添加音乐检索歌曲时需传此参数 state=1")
+ private String state;
+
@ApiModelProperty(value = "发布者ID")
private String userId;
diff --git a/luoo_music/src/main/java/com/luoo/music/response/cms/JournalVO.java b/luoo_music/src/main/java/com/luoo/music/response/cms/JournalVO.java
index 97dfa9b..17cb351 100644
--- a/luoo_music/src/main/java/com/luoo/music/response/cms/JournalVO.java
+++ b/luoo_music/src/main/java/com/luoo/music/response/cms/JournalVO.java
@@ -18,13 +18,13 @@ public class JournalVO {
private String id;
@ApiModelProperty(value = "期刊编号")
- private String number;
+ private String journalNo;
@ApiModelProperty(value = "期刊标题")
- private String name;
+ private String title;
@ApiModelProperty(value = "期刊封面")
- private String coverPhoto;
+ private String image;
@ApiModelProperty(value = "期刊标签")
private List tag;
@@ -33,13 +33,16 @@ public class JournalVO {
private long songCount;
@ApiModelProperty(value = "评论数")
- private long commentCount;
+ private long comment;
@ApiModelProperty(value = "播放数")
- private long playCount;
+ private long visits;
- @ApiModelProperty(value = "发布作者")
- private String userId;//
+ @ApiModelProperty(value = "发布作者id")
+ private String userId;
+
+ @ApiModelProperty(value = "发布作者昵称")
+ private String userName;
@ApiModelProperty(value = "创建时间")
private String createTime;
@@ -51,11 +54,11 @@ public class JournalVO {
private String state;
@ApiModelProperty(value = "期刊发布状态,0:待发布,1:已发布")
- private String status;
+ private String isPublish;
@ApiModelProperty(value = "期刊歌曲信息")
private List songs;
@ApiModelProperty(value = "期刊简介信息")
- private String summary;
+ private String content;
}
diff --git a/luoo_music/src/main/java/com/luoo/music/response/cms/SongVO.java b/luoo_music/src/main/java/com/luoo/music/response/cms/SongVO.java
index 80f1df6..ee95e63 100644
--- a/luoo_music/src/main/java/com/luoo/music/response/cms/SongVO.java
+++ b/luoo_music/src/main/java/com/luoo/music/response/cms/SongVO.java
@@ -29,7 +29,7 @@ public class SongVO {
private List tags;
@ApiModelProperty(value = "封面路径")
- private String picture;
+ private String image;
@ApiModelProperty(value = "文件大小")
private String size;
@@ -46,9 +46,12 @@ public class SongVO {
@ApiModelProperty(value = "歌曲启停状态,0:停用,1:启用")
private String state;
- @ApiModelProperty(value = "上传人员")
+ @ApiModelProperty(value = "上传人员ID")
private String userId;
+ @ApiModelProperty(value = "上传人员昵称")
+ private String userName;
+
@ApiModelProperty(value = "文件路径")
private String url;
diff --git a/luoo_music/src/main/java/com/luoo/music/response/cms/UploadRespDto.java b/luoo_music/src/main/java/com/luoo/music/response/cms/UploadRespDto.java
new file mode 100644
index 0000000..5c4792b
--- /dev/null
+++ b/luoo_music/src/main/java/com/luoo/music/response/cms/UploadRespDto.java
@@ -0,0 +1,27 @@
+package com.luoo.music.response.cms;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author locust
+ */
+@Data
+@ApiModel(description = "文件上传后的路径")
+public class UploadRespDto {
+
+ @ApiModelProperty(value = "部分路径")
+ private String partUrl;
+
+ @ApiModelProperty(value = "全路径")
+ private String fullUrl;
+
+ @ApiModelProperty(value = "文件大小")
+ private Long size;
+
+ @ApiModelProperty(value = "歌曲时长")
+ private Long duration;
+}
diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java
index afbd0d6..c94d4c8 100644
--- a/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java
+++ b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java
@@ -8,8 +8,9 @@ import com.luoo.music.request.cms.JournalAddModel;
import com.luoo.music.request.cms.JournalQueryModel;
import com.luoo.music.response.cms.JournalVO;
import com.luoo.music.response.cms.SongVO;
-import com.luoo.music.util.CommonUtil;
+import com.luoo.music.util.Constants;
import com.luoo.music.util.UploadUtil;
+import dto.UserLoginDto;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -18,13 +19,14 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
-import org.springframework.web.multipart.MultipartFile;
import util.IdWorker;
+import util.JwtUtil;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
+import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@@ -36,6 +38,8 @@ import java.util.stream.Collectors;
@Service
public class CMSJournalService {
+ @Autowired
+ private S3Service s3Service;
@Autowired
private IdWorker idWorker;
@Autowired
@@ -48,6 +52,8 @@ public class CMSJournalService {
private TagDao tagDao;
@Autowired
private SongInfoDao songDao;
+ @Autowired
+ private JwtUtil jwtUtil;
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -78,32 +84,27 @@ public class CMSJournalService {
List content = journalPage.getContent();
if (!CollectionUtils.isEmpty(content)) {
List ids = content.stream().map(Journal::getId).collect(Collectors.toList());
- Map songCountMap = songCountInfo(ids);
Map> journalTagMap = tagInfo(ids);
+ List journalNos = content.stream().map(Journal::getJournalNo).collect(Collectors.toList());
+ Map songCountMap = songCountInfo(journalNos);
for (Journal item : content) {
JournalVO response = new JournalVO();
response.setId(item.getId());
- response.setNumber(item.getNumber());
- response.setName(item.getName());
- response.setCoverPhoto(item.getCoverPhoto());
+ response.setJournalNo(Constants.JOURNAL_NO_PREF + item.getJournalNo());
+ response.setTitle(item.getTitle());
+ response.setImage(item.getImage());
response.setCreateTime(item.getCreateTime().format(formatter));
response.setState(item.getState());
- response.setStatus(item.getStatus());
+ response.setIsPublish(item.getIsPublish());
if (!Objects.isNull(item.getPubTime())) {
response.setPubTime(item.getPubTime().format(formatter));
}
- // TODO 编号文字转换
response.setUserId(item.getUserId());
+ response.setUserName(item.getUserName());
response.setSongCount(songCountMap.get(item.getId()));
response.setTag(journalTagMap.get(item.getId()));
- if (!"1".equals(param.getTab())) {
- response.setPlayCount(0);
- response.setCommentCount(0);
- } else {
- // TODO 播放 评论 数
- response.setPlayCount(0);
- response.setCommentCount(0);
- }
+ response.setVisits(item.getVisits());
+ response.setComment(item.getComment());
result.add(response);
}
}
@@ -119,30 +120,30 @@ public class CMSJournalService {
return (Root root, CriteriaQuery> query, CriteriaBuilder builder) -> {
List predicateList = new ArrayList();
if("1".equals(param.getTab())) {
- Predicate state = builder.equal(root.get("state"), "1");
- Predicate status = builder.equal(root.get("status"), "1");
- predicateList.add(builder.and(state, status));
+ predicateList.add(builder.equal(root.get("isPublish"), "1"));
} else if ("2".equals(param.getTab())) {
predicateList.add(builder.equal(root.get("state"), "0"));
} else {
Predicate state = builder.equal(root.get("state"), "1");
- Predicate status = builder.equal(root.get("status"), "0");
- predicateList.add(builder.and(state, status));
+ Predicate isPublish = builder.equal(root.get("isPublish"), "0");
+ predicateList.add(builder.and(state, isPublish));
}
if(StringUtils.isNotBlank(param.getUserId())) {
predicateList.add(builder.equal(root.get("userId"), param.getUserId()));
}
if (StringUtils.isNotBlank(param.getStart()) && StringUtils.isNotBlank(param.getEnd())) {
- predicateList.add(builder.between(root.get("createTime"), param.getStart(), param.getEnd()));
+ LocalDateTime start = LocalDateTime.parse(param.getStart() + "T00:00:00");
+ LocalDateTime end = LocalDateTime.parse(param.getEnd() + "T00:00:00");
+ predicateList.add(builder.between(root.get("createTime"), start, end));
}
if (!CollectionUtils.isEmpty(ids)) {
- predicateList.add(root.get("id").in(ids));
+ predicateList.add(root.get("journalNo").in(ids));
}
if(StringUtils.isNotBlank(param.getKeyword())) {
String likeExpression = "%" + param.getKeyword() + "%";
- Predicate name = builder.like(root.get("number"), likeExpression);
- Predicate summary = builder.like(root.get("name"), likeExpression);
- predicateList.add(builder.or(name, summary));
+ Predicate journalNo = builder.like(root.get("journalNo"), likeExpression);
+ Predicate title = builder.like(root.get("title"), likeExpression);
+ predicateList.add(builder.or(journalNo, title));
}
return builder.and(predicateList.toArray(new Predicate[predicateList.size()]));
};
@@ -150,14 +151,14 @@ public class CMSJournalService {
/**
* 期刊的音乐数量
- * @param ids
+ * @param journalNos
* @return
*/
- private Map songCountInfo(List ids) {
+ private Map songCountInfo(List journalNos) {
Map songCountMap = new HashMap<>();
- if (!CollectionUtils.isEmpty(ids)) {
- List journalSongCountList = journalSongDao.findSongCountByJournalIds(ids);
- songCountMap = journalSongCountList.stream().collect(Collectors.toMap(JournalSongCount::getJournalId, JournalSongCount::getSongCount));
+ if (!CollectionUtils.isEmpty(journalNos)) {
+ List journalSongCountList = journalSongDao.findSongCountByJournalNos(journalNos);
+ songCountMap = journalSongCountList.stream().collect(Collectors.toMap(JournalSongCount::getJournalNo, JournalSongCount::getSongCount));
}
return songCountMap;
}
@@ -193,56 +194,107 @@ public class CMSJournalService {
/**
* 新增期刊
* @param param
- * @param image
* @return
*/
- public Result add(JournalAddModel param, MultipartFile image) {
- String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR);
- Journal journal = buildJournal(null, param);
- String id = String.valueOf(idWorker.nextId());
- journal.setId(id);
- journal.setCoverPhoto(imagePath);
- journalDao.save(journal);
- batchSaveJournalRelatesInfo(id, param);
- return Result.success();
+ public Result add(String token, JournalAddModel param) {
+ List byJournalNo = journalDao.findByJournalNo(param.getJournalNo());
+ if (byJournalNo.size() > 0) {
+ return Result.failed("保存失败,期刊编号已存在");
+ }
+ String image = moveJournalImage(param);
+ if (StringUtils.isNotBlank(image)) {
+ Journal journal = buildJournal(null, param, token);
+ String id = String.valueOf(idWorker.nextId());
+ journal.setId(id);
+ journal.setImage(image);
+ journalDao.save(journal);
+ batchSaveJournalRelatesInfo(id, param);
+ return Result.success();
+ } else {
+ return Result.failed("保存失败");
+ }
+ }
+
+ /**
+ * 移动对象
+ * @param param
+ * @return
+ */
+ private String moveJournalImage(JournalAddModel param) {
+ String image = param.getImage();
+ String srcKey = image.substring(image.indexOf(Constants.TEMP_KEY_PREFIX));
+ String suffix = image.substring(image.lastIndexOf(Constants.DOT));
+ String format = String.format("%05d", param.getJournalNo());
+ String destKeySuffix = format + "/00" + suffix;
+ String destKey = Constants.IMAGE_KEY_PREFIX + destKeySuffix;
+ int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
+ if (copy > 0) {
+ return destKeySuffix;
+ }
+ return null;
}
- private Journal buildJournal(String id, JournalAddModel param) {
+ /**
+ * 构建对象
+ * @param id
+ * @param param
+ * @param token
+ * @return
+ */
+ private Journal buildJournal(String id, JournalAddModel param, String token) {
Journal journal = new Journal();
if (!StringUtils.isBlank(id)) {
journal.setId(id);
}
- journal.setNumber(param.getNumber());
- journal.setName(param.getName());
- journal.setUserId(param.getUserId());
- journal.setSummary(param.getSummary());
+ journal.setJournalNo(param.getJournalNo());
+ journal.setTitle(param.getTitle());
+ journal.setContent(param.getContent());
+ UserLoginDto user = jwtUtil.getUserLoginDto(token);
+ journal.setUserId(user.getUserId());
+ journal.setUserName(user.getNickName());
+ journal.setUserType(user.getRoles());
return journal;
}
/**
* 保存期刊的标签、音乐信息
- * @param id
+ * @param journalId
* @param param
*/
- private void batchSaveJournalRelatesInfo(String id, JournalAddModel param) {
+ private void batchSaveJournalRelatesInfo(String journalId, JournalAddModel param) {
+ // 标签信息
if (!CollectionUtils.isEmpty(param.getTags())) {
List journalTagList = new ArrayList<>();
for (String item : param.getTags()) {
JournalTag journalTag = new JournalTag();
journalTag.setId(String.valueOf(idWorker.nextId()));
- journalTag.setJournalId(id);
+ journalTag.setJournalId(journalId);
journalTag.setTagId(item);
journalTagList.add(journalTag);
}
journalTagDao.saveAll(journalTagList);
}
+ // 歌曲信息
if (!CollectionUtils.isEmpty(param.getSongs())) {
+ List songList = songDao.findByIdIn(param.getSongs());
+ Map idSongMap = songList.stream().collect(Collectors.toMap(SongInfo::getId, obj -> obj));
List journalSongList = new ArrayList<>();
+ int num = 0;
for (String item : param.getSongs()) {
- JournalSong journalSong = new JournalSong();
- journalSong.setId(String.valueOf(idWorker.nextId()));
- journalSong.setJournalId(id);
- journalSong.setSongId(item);
+ if (idSongMap.containsKey(item)) {
+ SongInfo song = idSongMap.get(item);
+ JournalSong journalSong = new JournalSong();
+ journalSong.setId(String.valueOf(idWorker.nextId()));
+ journalSong.setName(song.getName());
+ journalSong.setArtist(song.getArtist());
+ journalSong.setUrl(song.getUrl());
+ journalSong.setImage(song.getImage());
+ journalSong.setSongId(item);
+ journalSong.setJournalNo(param.getJournalNo());
+ journalSong.setSongNo(num + 1);
+ journalSong.setSongId(song.getId());
+ journalSongList.add(journalSong);
+ }
}
journalSongDao.saveAll(journalSongList);
}
@@ -257,41 +309,33 @@ public class CMSJournalService {
Journal journal = journalDao.findById(id).get();
JournalVO response = new JournalVO();
response.setId(journal.getId());
- response.setNumber(journal.getNumber());
- response.setName(journal.getName());
+ response.setJournalNo(journal.getJournalNo());
+ response.setTitle(journal.getTitle());
response.setTag(journalTagDao.findTagsByJournalId(id));
response.setUserId(journal.getUserId());
- response.setCoverPhoto(journal.getCoverPhoto());
- response.setSongs(songInfo(journal.getId()));
- response.setSummary(journal.getSummary());
+ response.setImage(Constants.IMAGE_RESOURCE_PREFIX + journal.getImage());
+ response.setSongs(journalSongInfo(journal.getJournalNo()));
+ response.setContent(journal.getContent());
return Result.success(response);
}
/**
* 期刊的音乐信息
- * @param id
+ * @param journalNo
* @return
*/
- private List songInfo(String id) {
+ private List journalSongInfo(String journalNo) {
List list = new ArrayList<>();
- List journalSongList = journalSongDao.findByJournalId(id);
+ List journalSongList = journalSongDao.findByJournalNo(journalNo);
if (!CollectionUtils.isEmpty(journalSongList)) {
- Set songIdSet = journalSongList.stream().map(JournalSong::getSongId).collect(Collectors.toSet());
- List songList = songDao.findByIdIn(songIdSet);
- Map idTagMap = songList.stream().collect(Collectors.toMap(SongInfo::getId, obj -> obj));
for (JournalSong item : journalSongList) {
- if (idTagMap.containsKey(item.getSongId())) {
- SongInfo song = idTagMap.get(item.getSongId());
- SongVO songVO = new SongVO();
- songVO.setId(song.getId());
- songVO.setPicture(song.getPicture());
- songVO.setName(song.getName());
- songVO.setArtist(song.getArtist());
- songVO.setAlbum(song.getAlbum());
- songVO.setDuration(CommonUtil.formatSongDuration(song.getDuration()));
- songVO.setLyric(song.getLyric());
- list.add(songVO);
- }
+ SongVO songVO = new SongVO();
+ songVO.setId(item.getSongId());
+ songVO.setImage(Constants.RESOURCE_PREFIX + Constants.MUSIC_KEY_PREFIX + item.getImage());
+ songVO.setName(item.getName());
+ songVO.setArtist(item.getArtist());
+ songVO.setAlbum(item.getAlbum());
+ list.add(songVO);
}
}
return list;
@@ -300,32 +344,39 @@ public class CMSJournalService {
/**
* 更新期刊
* @param id
+ * @param token
* @param param
- * @param image
* @return
*/
- public Result update(String id, JournalAddModel param, MultipartFile image) {
- Journal journal = buildJournal(id, param);
+ public Result update(String id, String token, JournalAddModel param) {
+ List byJournalNo = journalDao.findByJournalNo(param.getJournalNo());
+ if (byJournalNo.size() > 0) {
+ return Result.failed("更新失败,期刊编号已存在");
+ }
+ Journal journal = buildJournal(id, param, token);
Journal oldJournal = journalDao.findById(id).get();
- boolean bool = UploadUtil.fileHasChanged(oldJournal.getCoverPhoto(), image);
- if (bool) {
- String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR);
- journal.setCoverPhoto(imagePath);
+ String image = null;
+ if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
+ image = moveJournalImage(param);
+ if (StringUtils.isBlank(image)) {
+ Result.failed("更新失败");
+ }
}
+ journal.setImage(image);
journalDao.save(journal);
- batchDeleteJournalRelatesInfo(id);
+ batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo());
batchSaveJournalRelatesInfo(id, param);
return Result.success();
}
/**
* 删除期刊的标签、音乐信息
- * @param id
+ * @param journalId
+ * @param journalNo
*/
- private void batchDeleteJournalRelatesInfo(String id) {
- journalTagDao.deleteByJournalId(id);
- journalSongDao.deleteByJournalId(id);
-
+ private void batchDeleteJournalRelatesInfo(String journalId, String journalNo) {
+ journalTagDao.deleteByJournalId(journalId);
+ journalSongDao.deleteByJournalNo(journalNo);
}
/**
@@ -340,7 +391,7 @@ public class CMSJournalService {
if ("1".equals(scheduled)) {
if (StringUtils.isNotBlank(pubTimeStr)){
pubTime = LocalDateTime.parse(pubTimeStr, formatter);
- journalDao.updateScheduledPubById(id, scheduled, pubTime);
+ journalDao.updateScheduledPubById(id, pubTime);
}
}
journalDao.updatePubById(id, pubTime);
@@ -364,8 +415,11 @@ public class CMSJournalService {
* @return
*/
public Result deleteById(String id) {
- journalDao.deleteById(id);
- batchDeleteJournalRelatesInfo(id);
+ Journal journal = journalDao.findById(id).get();
+ if (!Objects.isNull(journal)) {
+ journalDao.deleteById(id);
+ batchDeleteJournalRelatesInfo(id, journal.getJournalNo());
+ }
return Result.success();
}
}
diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java
index db9d116..876dff1 100644
--- a/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java
+++ b/luoo_music/src/main/java/com/luoo/music/service/CMSSongService.java
@@ -8,7 +8,9 @@ import com.luoo.music.request.cms.SongAddModel;
import com.luoo.music.request.cms.SongQueryModel;
import com.luoo.music.response.cms.SongVO;
import com.luoo.music.util.CommonUtil;
+import com.luoo.music.util.Constants;
import com.luoo.music.util.UploadUtil;
+import dto.UserLoginDto;
import org.apache.commons.lang.StringUtils;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
@@ -23,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import util.IdWorker;
+import util.JwtUtil;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
@@ -33,6 +36,7 @@ import java.io.FileInputStream;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -42,6 +46,8 @@ import java.util.stream.Collectors;
@Service
public class CMSSongService {
+ @Autowired
+ private S3Service s3Service;
@Autowired
private SongInfoDao songDao;
@Autowired
@@ -54,6 +60,8 @@ public class CMSSongService {
private JournalDao journalDao;
@Autowired
private TagDao tagDao;
+ @Autowired
+ private JwtUtil jwtUtil;
private DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
@@ -90,7 +98,7 @@ public class CMSSongService {
response.setArtist(item.getArtist());
response.setAlbum(item.getAlbum());
response.setTags(songTagMap.get(id));
- response.setPicture(item.getPicture());
+ response.setImage(item.getImage());
response.setSize(CommonUtil.formatSongSize(item.getSize()));
response.setDuration(CommonUtil.formatSongDuration(item.getDuration()));
response.setJournal(songJournalMap.get(id));
@@ -113,10 +121,15 @@ public class CMSSongService {
return (Root root, CriteriaQuery> query, CriteriaBuilder builder) -> {
List predicateList = new ArrayList();
if(StringUtils.isNotBlank(param.getUserId())) {
- predicateList.add(builder.equal(root.get("user_id"), param.getUserId()));
+ predicateList.add(builder.equal(root.get("userId"), param.getUserId()));
}
if (StringUtils.isNotBlank(param.getStart()) && StringUtils.isNotBlank(param.getEnd())) {
- predicateList.add(builder.between(root.get("create_time"), param.getStart(), param.getEnd()));
+ LocalDateTime start = LocalDateTime.parse(param.getStart() + "T00:00:00");
+ LocalDateTime end = LocalDateTime.parse(param.getEnd() + "T00:00:00");
+ predicateList.add(builder.between(root.get("createTime"), start, end));
+ }
+ if(StringUtils.isNotBlank(param.getState())) {
+ predicateList.add(builder.equal(root.get("state"), param.getState()));
}
if(StringUtils.isNotBlank(param.getKeyword())) {
// 歌曲、歌手、专辑、歌词文本
@@ -135,21 +148,21 @@ public class CMSSongService {
Map> result = new HashMap<>();
List bySongId = journalSongDao.findBySongId(ids);
if (!CollectionUtils.isEmpty(bySongId)) {
- Set idSet = bySongId.stream().map(JournalSong::getJournalId).collect(Collectors.toSet());
- List journalList = journalDao.findByIdIn(idSet);
- Map idJournalMap = journalList.stream().collect(Collectors.toMap(Journal::getId, obj -> obj));
+ Set idSet = bySongId.stream().map(JournalSong::getJournalNo).collect(Collectors.toSet());
+ List journalList = journalDao.findByJournalNoIn(idSet);
+ Map idJournalMap = journalList.stream().collect(Collectors.toMap(Journal::getJournalNo, obj -> obj));
for (JournalSong item : bySongId) {
String songId = item.getSongId();
- String journalId = item.getJournalId();
+ String journalNo = item.getJournalNo();
List list;
if (result.keySet().contains(songId)) {
list = result.get(songId);
} else {
list = new ArrayList<>();
}
- if (idJournalMap.keySet().contains(journalId)) {
- Journal journal = idJournalMap.get(journalId);
- list.add(journal.getNumber() + " " + journal.getName());
+ if (idJournalMap.keySet().contains(journalNo)) {
+ Journal journal = idJournalMap.get(journalNo);
+ list.add(Constants.JOURNAL_NO_PREF + journalNo + " " + journal.getTitle());
}
result.put(songId, list);
}
@@ -185,51 +198,76 @@ public class CMSSongService {
/**
* 新增曲目
+ * @param token
* @param param
- * @param imageFile
- * @param songFile
* @return
*/
- public Result add(SongAddModel param, MultipartFile imageFile, MultipartFile songFile) {
- String imagePath= UploadUtil.upload(imageFile, UploadUtil.IMAGE_DIR);
- String songPath = UploadUtil.upload(songFile, UploadUtil.SONG_DIR);
- SongInfo song = new SongInfo();
+ public Result add(String token, SongAddModel param) {
String id = String.valueOf(idWorker.nextId());
+ String url = null;
+ if (StringUtils.isNotBlank(param.getUrl())) {
+ url = moveSongFile(id, param);
+ if (StringUtils.isBlank(url)) {
+ return Result.failed("保存失败");
+ }
+ }
+ String image = null;
+ if (StringUtils.isNotBlank(param.getImage())) {
+ image = moveSongImage(id, param);
+ if (StringUtils.isBlank(image)) {
+ return Result.failed("保存失败");
+ }
+ }
+ SongInfo song = buildSong(id, param, token);
song.setId(id);
- song.setName(param.getName());
- song.setArtist(param.getArtist());
- song.setAlbum(param.getAlbum());
- song.setPicture(imagePath);
- song.setUrl(songPath);
- song.setUserId(param.getUserId());
- song.setSize(songFile.isEmpty() ? 0L : songFile.getSize());
- song.setDuration(getSongDuration(songPath));
+ song.setUrl(url);
+ song.setImage(image);
songDao.save(song);
batchSaveSongRelatesInfo(id, param);
return Result.success("新增成功");
}
- /**
- * 获取歌曲时长
- * @param songPath
- * @return
- */
- private long getSongDuration(String songPath) {
- try {
- File audioFile = new File(songPath);
- InputStream inputStream = new FileInputStream(audioFile);
- Parser parser = new AutoDetectParser();
- Metadata metadata = new Metadata();
- BodyContentHandler handler = new BodyContentHandler();
- parser.parse(inputStream, handler, metadata, new ParseContext());
- String durationString = metadata.get("xmpDM:duration");
- long duration = Long.parseLong(durationString);
- inputStream.close();
- return duration;
- } catch (Exception e) {
- e.printStackTrace();
- return 0;
+ private SongInfo buildSong(String id, SongAddModel param, String token) {
+ SongInfo song = new SongInfo();
+ if (!StringUtils.isBlank(id)) {
+ song.setId(id);
+ }
+ song.setName(param.getName());
+ song.setArtist(param.getArtist());
+ song.setAlbum(param.getAlbum());
+ song.setSize(param.getSize());
+ song.setDuration(param.getDuration());
+ UserLoginDto user = jwtUtil.getUserLoginDto(token);
+ song.setUserId(user.getUserId());
+ song.setUserName(user.getNickName());
+ song.setUserType(user.getRoles());
+ return song;
+ }
+
+ private String moveSongFile(String id, SongAddModel param) {
+ String url = param.getUrl();
+ String srcKey = url.substring(url.indexOf(Constants.TEMP_KEY_PREFIX));
+ String suffix = url.substring(url.lastIndexOf(Constants.DOT));
+ String destKeySuffix = id + "/00" + suffix;
+ String destKey = Constants.SONG_KEY_PREFIX + destKeySuffix;
+ int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
+ if (copy > 0) {
+ return destKeySuffix;
}
+ return null;
+ }
+
+ private String moveSongImage(String id, SongAddModel param) {
+ String image = param.getImage();
+ String srcKey = image.substring(image.indexOf(Constants.TEMP_KEY_PREFIX));
+ String suffix = image.substring(image.lastIndexOf(Constants.DOT));
+ String destKeySuffix = id + "/00" + suffix;
+ String destKey = Constants.SONG_KEY_PREFIX + destKeySuffix;
+ int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
+ if (copy > 0) {
+ return destKeySuffix;
+ }
+ return null;
}
/**
@@ -264,39 +302,37 @@ public class CMSSongService {
response.setArtist(song.getArtist());
response.setAlbum(song.getAlbum());
response.setTags(songTagDao.findTagsBySongId(id));
- response.setPicture(song.getPicture());
- response.setUrl(song.getUrl());
+ response.setUrl(Constants.SONG_RESOURCE_PREFIX + song.getUrl());
+ response.setImage(Constants.SONG_RESOURCE_PREFIX + song.getImage());
return Result.success(response);
}
/**
- * 更新曲目
+ * 更新歌曲
* @param id
+ * @param token
* @param param
- * @param imageFile
- * @param songFile
* @return
*/
- public Result update(String id, SongAddModel param, MultipartFile imageFile, MultipartFile songFile) {
- SongInfo oldSong = songDao.findById(id).get();
- SongInfo song = new SongInfo();
- song.setId(id);
- song.setName(param.getName());
- song.setArtist(param.getAlbum());
- song.setAlbum(param.getAlbum());
- song.setUserId(param.getUserId());
- boolean imageBool = UploadUtil.fileHasChanged(oldSong.getPicture(), imageFile);
- if (imageBool) {
- String imagePath = UploadUtil.upload(imageFile, UploadUtil.IMAGE_DIR);
- song.setPicture(imagePath);
+ public Result update(String id, String token, SongAddModel param) {
+ SongInfo song = buildSong(id, param, token);
+ String url = null;
+ if (param.getUrl().contains(Constants.TEMP_KEY_PREFIX)) {
+ url = moveSongFile(id, param);
+ if (StringUtils.isBlank(url)) {
+ return Result.failed("更新失败");
+ }
+ song.setUrl(url);
+ song.setSize(param.getSize());
+ song.setDuration(param.getDuration());
}
-
- boolean songBool = UploadUtil.fileHasChanged(oldSong.getUrl(), songFile);
- if (songBool) {
- String songPath = UploadUtil.upload(imageFile, UploadUtil.SONG_DIR);
- song.setUrl(songPath);
- song.setSize(songFile.isEmpty() ? 0L : songFile.getSize());
- song.setDuration(getSongDuration(songPath));
+ String image = null;
+ if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
+ image = moveSongImage(id, param);
+ if (StringUtils.isBlank(image)) {
+ Result.failed("更新失败");
+ }
+ song.setImage(image);
}
songDao.save(song);
songTagDao.deleteBySongId(id);
@@ -329,25 +365,6 @@ public class CMSSongService {
return Result.success("更新成功");
}
- /**
- * 批量上传歌曲
- * @param files
- * @return
- */
- public Result batchUpload(List files) {
- for (MultipartFile file : files) {
- SongInfo song = new SongInfo();
- String id = String.valueOf(idWorker.nextId());
- song.setId(id);
- String songPath = UploadUtil.upload(file, UploadUtil.SONG_DIR);
- song.setUrl(songPath);
- song.setSize(file.isEmpty() ? 0L : file.getSize());
- song.setDuration(getSongDuration(songPath));
- songDao.save(song);
- }
- return Result.success("上传成功");
- }
-
/**
* 删除曲目
* @param id
@@ -363,4 +380,31 @@ public class CMSSongService {
return Result.success("该歌曲已被删除");
}
}
+
+ /**
+ * 批量上传歌曲
+ * @param files
+ * @return
+ */
+ public Result batchUpload(List files) {
+ for (MultipartFile file : files) {
+ if (!file.isEmpty()) {
+ String id = String.valueOf(idWorker.nextId());
+ String originalFilename = file.getOriginalFilename();
+ String suffix = originalFilename.substring(originalFilename.lastIndexOf(Constants.DOT));
+ String keySuffix = id + "/00" + suffix;
+ String key = Constants.SONG_KEY_PREFIX + keySuffix;
+ int upload = s3Service.upload(Constants.BUCKET, key, file);
+ if (upload > 1) {
+ SongInfo song = new SongInfo();
+ song.setId(id);
+ song.setUrl(keySuffix);
+ song.setSize(file.isEmpty() ? 0L : file.getSize());
+ song.setDuration(CommonUtil.getSongDuration(Constants.SONG_RESOURCE_PREFIX + keySuffix));
+ songDao.save(song);
+ }
+ }
+ }
+ return Result.success("上传成功");
+ }
}
diff --git a/luoo_music/src/main/java/com/luoo/music/service/S3Service.java b/luoo_music/src/main/java/com/luoo/music/service/S3Service.java
index a7a83a6..72fe111 100644
--- a/luoo_music/src/main/java/com/luoo/music/service/S3Service.java
+++ b/luoo_music/src/main/java/com/luoo/music/service/S3Service.java
@@ -1,89 +1,99 @@
package com.luoo.music.service;
+import api.Result;
+import com.luoo.music.response.cms.UploadRespDto;
+import com.luoo.music.util.CommonUtil;
+import com.luoo.music.util.Constants;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.http.SdkHttpResponse;
import software.amazon.awssdk.services.s3.S3Client;
-import software.amazon.awssdk.services.s3.model.*;
-import software.amazon.awssdk.services.s3.presigner.S3Presigner;
+import software.amazon.awssdk.services.s3.model.CopyObjectRequest;
+import software.amazon.awssdk.services.s3.model.CopyObjectResponse;
+import software.amazon.awssdk.services.s3.model.PutObjectRequest;
+import software.amazon.awssdk.services.s3.model.PutObjectResponse;
+import util.IdWorker;
import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.List;
@Service
public class S3Service {
- @Resource
- private S3Client s3Client;
@Resource
- private S3Presigner s3Presigner;
-
-//
-// public ListObjectsResponse listObjects(){
-// ListObjectsResponse indie = s3Client.listObjects( ListObjectsV2Request.builder().bucket("indie"));
-// return indie;
-// }
-
-
- public List list() throws UnsupportedEncodingException {
-// if(StringUtil.isEmpty(bucket)) return ResultUtil.resultFail("参数错误");
-
- ListObjectsV2Request.Builder builder = ListObjectsV2Request.builder();
- // 设置bucket
- builder.bucket("indie");
-
-
- ListObjectsV2Request listObjReq = builder.build();
- ListObjectsV2Response listObjRes = s3Client.listObjectsV2(listObjReq);
-
-
-
- List s3ObjectList = listObjRes.contents();
-
+ private S3Client s3Client;
+ @Autowired
+ private IdWorker idWorker;
- return s3ObjectList;
+ /**
+ * @param file
+ * @return
+ */
+ public Result upload(MultipartFile file, boolean isSong) {
+ if (!file.isEmpty()) {
+ String originalFilename = file.getOriginalFilename();
+ String suffix = originalFilename.substring(originalFilename.lastIndexOf(Constants.DOT));
+ String keySuffix = String.valueOf(idWorker.nextId()) + suffix;
+ String key = Constants.TEMP_KEY_PREFIX + keySuffix;
+ int upload = upload(Constants.BUCKET, key, file);
+ if (upload < 1) {
+ return Result.failed("上传失败");
+ } else {
+ UploadRespDto resp = new UploadRespDto();
+ resp.setFullUrl(Constants.RESOURCE_PREFIX + key);
+ if (isSong) {
+ resp.setSize(file.isEmpty() ? 0L : file.getSize());
+ resp.setDuration(CommonUtil.getSongDuration(Constants.RESOURCE_PREFIX + key));
+ }
+ resp.setFullUrl(Constants.RESOURCE_PREFIX + key);
+ return Result.success(resp);
+ }
+ } else {
+ return Result.failed("文件为空,上传失败");
+ }
}
-
-
/**
- * 异步完整上传不分片
- * @param bucket bucket
- * @param key 对象路径
- * @param file 文件对象
+ * 上传文件至 s3
+ * @param bucket
+ * @param key
+ * @param file
+ * @return
+ * @throws IOException
*/
-// @Async("awsThreadPoolExecutor")
- public int singleUpload(String bucket, String key, MultipartFile file) throws IOException {
- Long startTime = System.currentTimeMillis() / 1000;
- PutObjectRequest putObjectRequest = PutObjectRequest.builder()
- .bucket(bucket)
- .key(key)
- .build();
- RequestBody requestBody = RequestBody.fromInputStream(file.getInputStream(), file.getSize());
- PutObjectResponse putObjectResponse = s3Client.putObject(putObjectRequest, requestBody);
- SdkHttpResponse sdkHttpResponse = putObjectResponse.sdkHttpResponse();
- if(!sdkHttpResponse.isSuccessful()){
- return -1;
+ public int upload(String bucket, String key, MultipartFile file) {
+ try {
+ PutObjectRequest putObjectRequest = PutObjectRequest.builder()
+ .bucket(bucket)
+ .key(key)
+ .build();
+ RequestBody requestBody = RequestBody.fromInputStream(file.getInputStream(), file.getSize());
+ PutObjectResponse putObjectResponse = s3Client.putObject(putObjectRequest, requestBody);
+ SdkHttpResponse sdkHttpResponse = putObjectResponse.sdkHttpResponse();
+ if (!sdkHttpResponse.isSuccessful()) {
+ return -1;
+ }
+ } catch (Exception e) {
+ return -1;
}
- long endTime = System.currentTimeMillis() / 1000;
-// log.info("上传文件(" + key + ")总计耗费时间为:" + (endTime - startTime) + " 秒");
-
return 1;
}
-
-
- public int copy() {
-
- String bucket = "indie"; //存储桶名
- String sourceKey = "20240121/1.mp3"; //copy的源文件路径
- String destinationKey = "20240121/2.mp3"; // copy的目的地路径
- CopyObjectResponse copyObjectResponse = s3Client.copyObject(CopyObjectRequest.builder().sourceBucket(bucket).sourceKey(sourceKey).destinationBucket(bucket).destinationKey(destinationKey).build());
+ /**
+ * s3复制文件
+ * @param bucket
+ * @param srcKey
+ * @param destKey
+ * @return
+ */
+ public int copy(String bucket, String srcKey, String destKey) {
+ CopyObjectRequest copyObjectRequest = CopyObjectRequest.builder()
+ .sourceBucket(bucket).sourceKey(srcKey).destinationBucket(bucket).destinationKey(destKey).build();
+ CopyObjectResponse copyObjectResponse = s3Client.copyObject(copyObjectRequest);
SdkHttpResponse sdkHttpResponse = copyObjectResponse.sdkHttpResponse();
if(!sdkHttpResponse.isSuccessful()){
return -1;
@@ -91,13 +101,12 @@ public class S3Service {
return 1;
}
- public void uploadAvatar(String bucket, String key, byte[] buffer) {
+ public void uploadAvatar(String bucket, String key, byte[] buffer) {
PutObjectRequest putObjectRequest = PutObjectRequest.builder()
.bucket(bucket)
.key(key)
.build();
RequestBody requestBody = RequestBody.fromInputStream(new ByteArrayInputStream(buffer), buffer.length);
s3Client.putObject(putObjectRequest, requestBody);
- }
-
+ }
}
diff --git a/luoo_music/src/main/java/com/luoo/music/util/CommonUtil.java b/luoo_music/src/main/java/com/luoo/music/util/CommonUtil.java
index fccc1fe..3e6760d 100644
--- a/luoo_music/src/main/java/com/luoo/music/util/CommonUtil.java
+++ b/luoo_music/src/main/java/com/luoo/music/util/CommonUtil.java
@@ -1,5 +1,14 @@
package com.luoo.music.util;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.AutoDetectParser;
+import org.apache.tika.parser.ParseContext;
+import org.apache.tika.parser.Parser;
+import org.apache.tika.sax.BodyContentHandler;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.text.DecimalFormat;
/**
@@ -8,7 +17,30 @@ import java.text.DecimalFormat;
public class CommonUtil {
/**
- * 文件大小格式
+ * 获取歌曲时长
+ * @param songPath
+ * @return
+ */
+ public static long getSongDuration(String songPath) {
+ try {
+ File audioFile = new File(songPath);
+ InputStream inputStream = new FileInputStream(audioFile);
+ Parser parser = new AutoDetectParser();
+ Metadata metadata = new Metadata();
+ BodyContentHandler handler = new BodyContentHandler();
+ parser.parse(inputStream, handler, metadata, new ParseContext());
+ String durationString = metadata.get("xmpDM:duration");
+ long duration = Long.parseLong(durationString);
+ inputStream.close();
+ return duration;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return 0;
+ }
+ }
+
+ /**
+ * 格式化文件大小格式
* @param size
* @return
*/
@@ -19,7 +51,7 @@ public class CommonUtil {
}
/**
- * 歌曲长度格式
+ * 格式化歌曲播放时长
* @param duration
* @return
*/
diff --git a/luoo_music/src/main/java/com/luoo/music/util/Constants.java b/luoo_music/src/main/java/com/luoo/music/util/Constants.java
new file mode 100644
index 0000000..993f04e
--- /dev/null
+++ b/luoo_music/src/main/java/com/luoo/music/util/Constants.java
@@ -0,0 +1,27 @@
+package com.luoo.music.util;
+
+/**
+ * @author locust
+ */
+public class Constants {
+
+ public static String JOURNAL_NO_PREF = "VOL•";
+
+ private String SONG_PREF = "song";
+
+
+ public static final String MUSIC_RESOURCE_PREFIX="http://cdn.indie.cn/music/";
+ public static final String IMAGE_RESOURCE_PREFIX="http://cdn.indie.cn/image/";
+ public static final String SONG_RESOURCE_PREFIX="http://cdn.indie.cn/song/";
+
+
+ public static final String BUCKET = "indie";
+ public static final String RESOURCE_PREFIX="http://cdn.indie.cn/";
+ public static final String MUSIC_KEY_PREFIX = "music/";
+ public static final String IMAGE_KEY_PREFIX = "image/";
+ public static final String SONG_KEY_PREFIX = "song/";
+ public static final String TEMP_KEY_PREFIX = "temp/";
+
+ public static final String DOT = ".";
+ public static final String SLASH = "/";
+}