From 5305a3e7537325bb0640b99613d0f5987c801496 Mon Sep 17 00:00:00 2001 From: JH <935007339@qq.com> Date: Sat, 20 Jan 2024 17:17:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E5=8E=9FCloum=E7=9A=84=E6=96=87?= =?UTF-8?q?=E4=BB=B6,=E6=9C=9F=E5=88=8A=E9=87=8D=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/luoo/music/MusicApplication.java | 1 + ...troller.java => CMSJournalController.java} | 36 +-- .../music/controller/CMSSongController.java | 10 +- .../java/com/luoo/music/dao/CMSSongDao.java | 35 --- .../java/com/luoo/music/dao/ColumnDao.java | 54 ----- .../com/luoo/music/dao/ColumnSongDao.java | 31 --- .../java/com/luoo/music/dao/ColumnTagDao.java | 27 --- .../java/com/luoo/music/dao/JournalDao.java | 36 +++ .../com/luoo/music/dao/JournalSongDao.java | 37 ++++ .../com/luoo/music/dao/JournalTagDao.java | 29 +++ .../java/com/luoo/music/dao/SongInfoDao.java | 27 +++ .../java/com/luoo/music/dao/SongTagDao.java | 2 + .../main/java/com/luoo/music/dao/TagDao.java | 12 - .../music/pojo/{Column.java => Journal.java} | 4 +- .../{ColumnSong.java => JournalSong.java} | 6 +- ...mnSongCount.java => JournalSongCount.java} | 4 +- .../pojo/{ColumnTag.java => JournalTag.java} | 6 +- .../pojo/{CMSSong.java => SongInfo.java} | 4 +- .../java/com/luoo/music/pojo/SongTag.java | 2 +- ...lumnAddModel.java => JournalAddModel.java} | 2 +- ...QueryModel.java => JournalQueryModel.java} | 4 +- .../com/luoo/music/response/cms/ColumnVO.java | 61 ------ .../luoo/music/response/cms/JournalVO.java | 61 ++++++ .../com/luoo/music/response/cms/SongVO.java | 30 +-- ...umnService.java => CMSJournalService.java} | 206 +++++++++--------- .../luoo/music/service/CMSSongService.java | 67 +++--- 26 files changed, 384 insertions(+), 410 deletions(-) rename luoo_music/src/main/java/com/luoo/music/controller/{CMSColumnController.java => CMSJournalController.java} (72%) delete mode 100644 luoo_music/src/main/java/com/luoo/music/dao/CMSSongDao.java delete mode 100644 luoo_music/src/main/java/com/luoo/music/dao/ColumnDao.java delete mode 100644 luoo_music/src/main/java/com/luoo/music/dao/ColumnSongDao.java delete mode 100644 luoo_music/src/main/java/com/luoo/music/dao/ColumnTagDao.java create mode 100644 luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java create mode 100644 luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java create mode 100644 luoo_music/src/main/java/com/luoo/music/dao/JournalTagDao.java create mode 100644 luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java rename luoo_music/src/main/java/com/luoo/music/pojo/{Column.java => Journal.java} (95%) rename luoo_music/src/main/java/com/luoo/music/pojo/{ColumnSong.java => JournalSong.java} (75%) rename luoo_music/src/main/java/com/luoo/music/pojo/{ColumnSongCount.java => JournalSongCount.java} (62%) rename luoo_music/src/main/java/com/luoo/music/pojo/{ColumnTag.java => JournalTag.java} (75%) rename luoo_music/src/main/java/com/luoo/music/pojo/{CMSSong.java => SongInfo.java} (95%) rename luoo_music/src/main/java/com/luoo/music/request/cms/{ColumnAddModel.java => JournalAddModel.java} (95%) rename luoo_music/src/main/java/com/luoo/music/request/cms/{ColumnQueryModel.java => JournalQueryModel.java} (91%) delete mode 100644 luoo_music/src/main/java/com/luoo/music/response/cms/ColumnVO.java create mode 100644 luoo_music/src/main/java/com/luoo/music/response/cms/JournalVO.java rename luoo_music/src/main/java/com/luoo/music/service/{CMSColumnService.java => CMSJournalService.java} (58%) diff --git a/luoo_music/src/main/java/com/luoo/music/MusicApplication.java b/luoo_music/src/main/java/com/luoo/music/MusicApplication.java index c7079a6..ee147ed 100644 --- a/luoo_music/src/main/java/com/luoo/music/MusicApplication.java +++ b/luoo_music/src/main/java/com/luoo/music/MusicApplication.java @@ -6,6 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSColumnController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java similarity index 72% rename from luoo_music/src/main/java/com/luoo/music/controller/CMSColumnController.java rename to luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java index 48cd6ed..ffaa860 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/CMSColumnController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSJournalController.java @@ -2,10 +2,10 @@ package com.luoo.music.controller; import api.PageResult; import api.Result; -import com.luoo.music.request.cms.ColumnAddModel; -import com.luoo.music.request.cms.ColumnQueryModel; -import com.luoo.music.response.cms.ColumnVO; -import com.luoo.music.service.CMSColumnService; +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 io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -19,39 +19,39 @@ import org.springframework.web.multipart.MultipartFile; @RestController @CrossOrigin @Api(tags = "雀跃期刊后台CMS APIs") -@RequestMapping("/cms/column") -public class CMSColumnController { +@RequestMapping("/cms/journal") +public class CMSJournalController { @Autowired - private CMSColumnService columnService; + private CMSJournalService journalService; @ApiOperation(value = "查询期刊列表", notes = "查询期刊列表") @RequestMapping(value="/search/{page}/{size}", method= RequestMethod.POST) - public Result search(@ApiParam(value = "查询条件", required = true) @RequestBody ColumnQueryModel queryModel, + public Result> search(@ApiParam(value = "查询条件对象", required = true) @RequestBody JournalQueryModel queryModel, @ApiParam(value = "页码", required = true) @PathVariable int page, @ApiParam(value = "每页条数", required = true) @PathVariable int size){ - return columnService.search(queryModel, page, size); + return journalService.search(queryModel, page, size); } @ApiOperation(value = "新增期刊", notes = "新增期刊") @RequestMapping(value = "/add", method = RequestMethod.POST) - public Result add(@ApiParam(value = "期刊信息", required = true) @RequestBody ColumnAddModel addModel, + public Result add(@ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel addModel, @ApiParam(value = "封面文件", required = true) @RequestParam("imageFile") MultipartFile imageFile){ - return columnService.add(addModel, imageFile); + return journalService.add(addModel, imageFile); } @ApiOperation(value = "查询期刊详情", notes = "查询期刊详情") @RequestMapping(value="/{id}",method= RequestMethod.GET) - public Result findOne(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){ - return columnService.findOne(id); + public Result findOne(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){ + return journalService.findOne(id); } @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 ColumnAddModel updateModel, + @ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel updateModel, @ApiParam(value = "封面文件", required = true) @RequestParam("imageFile") MultipartFile imageFile){ - return columnService.update(id, updateModel, imageFile); + return journalService.update(id, updateModel, imageFile); } @ApiOperation(value = "发布期刊", notes = "发布期刊") @@ -59,19 +59,19 @@ public class CMSColumnController { public Result publish(@PathVariable String id, @ApiParam(value = "是否定时发布,0:否,1:是", required = true) @RequestParam("state") String scheduled, @ApiParam(value = "定时发布时间") @RequestParam("state") String pubTime){ - return columnService.publish(id, scheduled, pubTime); + return journalService.publish(id, scheduled, pubTime); } @ApiOperation(value = "更新期刊启停状态", notes = "更新期刊启停状态") @RequestMapping(value="/update/state/{id}",method= RequestMethod.PUT) public Result updateColumnState(@ApiParam(value = "期刊ID", required = true) @PathVariable String id, @ApiParam(value = "期刊启停状态,0:停用,1:启用", required = true) @RequestParam("state") String state){ - return columnService.updateColumnState(id, state); + return journalService.updateJournalState(id, state); } @ApiOperation(value = "删除单条期刊", notes = "删除单条期刊") @RequestMapping(value="/{id}", method= RequestMethod.DELETE) public Result delete(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){ - return columnService.deleteById(id); + return journalService.deleteById(id); } } 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 5ce42f9..699461d 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 @@ -1,8 +1,10 @@ package com.luoo.music.controller; +import api.PageResult; import api.Result; 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 io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; @@ -25,9 +27,9 @@ public class CMSSongController { @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, - @ApiParam(value = "每页条数", required = true)@PathVariable int size){ + public Result> search(@ApiParam(value = "查询条件") @RequestBody SongQueryModel queryModel, + @ApiParam(value = "页码", required = true) @PathVariable int page, + @ApiParam(value = "每页条数", required = true)@PathVariable int size){ return songService.search(queryModel, page, size); } @@ -41,7 +43,7 @@ public class CMSSongController { @ApiOperation(value = "查询歌曲详情", notes = "查询歌曲详情") @RequestMapping(value="/{id}",method= RequestMethod.GET) - public Result findOne(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id){ + public Result findOne(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id){ return songService.findOne(id); } diff --git a/luoo_music/src/main/java/com/luoo/music/dao/CMSSongDao.java b/luoo_music/src/main/java/com/luoo/music/dao/CMSSongDao.java deleted file mode 100644 index 7a810c3..0000000 --- a/luoo_music/src/main/java/com/luoo/music/dao/CMSSongDao.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.luoo.music.dao; - -import com.luoo.music.pojo.CMSSong; -import com.luoo.music.pojo.Song; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; -import java.util.Set; - -/** - * @author locust - */ -public interface CMSSongDao extends JpaRepository, JpaSpecificationExecutor { - - // public List findSongsByVolid(String volid); - - @Modifying - @Query("UPDATE CMSSong s SET s.state = :state WHERE s.id = :id") - int updateSongState(@Param("id") String id, @Param("state") String state); - - @Modifying - @Query("UPDATE CMSSong s SET s.lyric = :lyric WHERE s.id = :id") - int updateSongLyric(@Param("id") String id, @Param("lyric") String lyric); - - List findByIdIn(Set ids); - - - /*@Modifying - @Query("UPDATE Song s SET s.name = :#{#song.name}, s.artist = :#{#song.artist}, s.album = :#{#song.album}, s.picture = :#{#song.picture}, s.url = :#{#song.url}, s.size = :#{#song.size}, s.duration = :#{#song.duration}, s.updatetime = :#{#song.updatetime} WHERE s.id = :#{#song.id}") - int updateSong(@Param("song") Song song);*/ -} diff --git a/luoo_music/src/main/java/com/luoo/music/dao/ColumnDao.java b/luoo_music/src/main/java/com/luoo/music/dao/ColumnDao.java deleted file mode 100644 index f00ea71..0000000 --- a/luoo_music/src/main/java/com/luoo/music/dao/ColumnDao.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.luoo.music.dao; - -import com.luoo.music.pojo.Column; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Set; - -/** - * @author locust - */ -public interface ColumnDao extends JpaRepository,JpaSpecificationExecutor{ - - List findByIdIn(Set ids); - - @Modifying - @Query("UPDATE Column c SET c.state = '1', c.pubTime = :pubTime WHERE c.id = :id") - int updatePubById(@Param("id") String id, - @Param("pubTime") LocalDateTime pubTime); - - @Modifying - @Query("UPDATE Column c SET c.scheduled = :scheduled, c.pubTime = :pubTime WHERE c.id = :id") - int updateScheduledPubById(@Param("id") String id, - @Param("scheduled") String scheduled, - @Param("pubTime") LocalDateTime pubTime); - - @Modifying - @Query("UPDATE Column c SET c.state = :state WHERE c.id = :id") - int updateColumnState(@Param("id") String id, @Param("state") String state); - - /*@Modifying - @Query("UPDATE Column c SET c.number = :#{#column.number}, c.name = :#{#column.name}, c.userid = :#{#column.userid}, c.summary = :#{#column.summary}, c.coverphoto = :#{#column.coverphoto} WHERE c.id = :#{#column.id}") - int updateColumn(@Param("column") Column column); - - @Modifying - @Query("UPDATE Column c SET " + - "c.number = CASE WHEN :#{#column.number != null} THEN :#{#column.number} ELSE c.number END, " + - "c.name = CASE WHEN :#{#column.name != null} THEN :#{#column.name} ELSE c.name END, " + - "c.summary = CASE WHEN :#{#column.summary != null} THEN :#{#column.summary} ELSE c.summary END, " + - "c.state = CASE WHEN :#{#column.state != null} THEN :#{#column.state} ELSE c.state END, " + - "c.scheduled = CASE WHEN :#{#column.scheduled != null} THEN :#{#column.scheduled} ELSE c.scheduled END, " + - "c.userId = CASE WHEN :#{#column.userId != null} THEN :#{#column.userId} ELSE c.userId END, " + - "c.coverPhoto = CASE WHEN :#{#column.coverPhoto != null} THEN :#{#column.coverPhoto} ELSE c.coverPhoto END, " + - "c.pubTime = CASE WHEN :#{#column.pubTime != null} THEN :#{#column.pubTime} ELSE c.pubTime END " + - "WHERE c.id = :#{#column.id}") - int dynamicUpdateColumn(@Param("column") Column column);*/ - -} - diff --git a/luoo_music/src/main/java/com/luoo/music/dao/ColumnSongDao.java b/luoo_music/src/main/java/com/luoo/music/dao/ColumnSongDao.java deleted file mode 100644 index 9a3eae5..0000000 --- a/luoo_music/src/main/java/com/luoo/music/dao/ColumnSongDao.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.luoo.music.dao; - -import com.luoo.music.pojo.ColumnSong; -import com.luoo.music.pojo.ColumnSongCount; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; - -/** - * @author locust - */ -public interface ColumnSongDao extends JpaRepository, JpaSpecificationExecutor { - - @Query("SELECT cs.columnId, COUNT(cs) AS songCount FROM ColumnSong cs WHERE cs.columnId IN :columnIds GROUP BY cs.columnId") - List findSongCountByColumnIds(@Param("columnIds") List columnIds); - - @Query("SELECT cs.columnId FROM ColumnSong cs WHERE cs.songId = :id") - List findColumnsBySongId(@Param("id") String id); - - @Query("SELECT cs FROM ColumnSong cs WHERE cs.songId IN :ids ORDER BY cs.id ") - List findBySongId(@Param("ids") List ids); - - @Query("SELECT cs FROM ColumnSong cs WHERE cs.columnId = :id ORDER BY cs.id ") - List findByColumnId(@Param("id") String id); - - @Query("DELETE FROM ColumnSong cs WHERE cs.columnId = :id") - int deleteByColumnId(@Param("id") String id); -} diff --git a/luoo_music/src/main/java/com/luoo/music/dao/ColumnTagDao.java b/luoo_music/src/main/java/com/luoo/music/dao/ColumnTagDao.java deleted file mode 100644 index ed7f1c4..0000000 --- a/luoo_music/src/main/java/com/luoo/music/dao/ColumnTagDao.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.luoo.music.dao; - -import com.luoo.music.pojo.ColumnTag; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; - -/** - * @author locust - */ -public interface ColumnTagDao extends JpaRepository, JpaSpecificationExecutor { - - @Query("SELECT ct FROM ColumnTag ct WHERE ct.columnId IN :columnIds ORDER BY ct.id") - List findByColumnIds(@Param("columnIds") List columnIds); - - @Query("SELECT ct.columnId FROM ColumnTag ct WHERE ct.tagId IN :tags") - List findColumnIdsByTags(@Param("tags") List tags); - - @Query("SELECT ct.tagId FROM ColumnTag ct WHERE ct.columnId = :id") - List findTagsByColumnId(@Param("id") String id); - - @Query("DELETE FROM ColumnTag ct WHERE ct.columnId = :id") - int deleteByColumnId(@Param("id") String id); -} 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 new file mode 100644 index 0000000..8ed0470 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/dao/JournalDao.java @@ -0,0 +1,36 @@ +package com.luoo.music.dao; + +import com.luoo.music.pojo.Journal; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; + +/** + * @author locust + */ +public interface JournalDao extends JpaRepository,JpaSpecificationExecutor{ + + List findByIdIn(Set ids); + + @Modifying + @Query("UPDATE Journal j SET j.state = '1', j.pubTime = :pubTime WHERE j.id = :id") + int updatePubById(@Param("id") String id, + @Param("pubTime") LocalDateTime pubTime); + + @Modifying + @Query("UPDATE Journal j SET j.scheduled = :scheduled, j.pubTime = :pubTime WHERE j.id = :id") + int updateScheduledPubById(@Param("id") String id, + @Param("scheduled") String scheduled, + @Param("pubTime") LocalDateTime pubTime); + + @Modifying + @Query("UPDATE Journal j SET j.state = :state WHERE j.id = :id") + int updateJournalState(@Param("id") String id, @Param("state") String state); +} + 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 new file mode 100644 index 0000000..9bbde1c --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/dao/JournalSongDao.java @@ -0,0 +1,37 @@ +package com.luoo.music.dao; + +import com.luoo.music.pojo.JournalSong; +import com.luoo.music.pojo.JournalSongCount; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +/** + * @author locust + */ +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.journalId FROM JournalSong js WHERE js.songId = :songId") + List findJournalBySongId(@Param("songId") String songId); + + @Query("SELECT js FROM JournalSong js WHERE js.songId IN :songIds ORDER BY js.id") + List findBySongId(@Param("songIds") List songIds); + + @Query("SELECT js FROM JournalSong js WHERE js.journalId = :journalId ORDER BY js.id") + List findByJournalId(@Param("journalId") String journalId); + + @Modifying + @Query("DELETE FROM JournalSong js WHERE js.journalId = :journalId") + int deleteByJournalId(@Param("journalId") String journalId); + + @Modifying + @Query("DELETE FROM JournalSong js WHERE js.songId = :songId") + int deleteBySongId(@Param("songId") String songId); +} diff --git a/luoo_music/src/main/java/com/luoo/music/dao/JournalTagDao.java b/luoo_music/src/main/java/com/luoo/music/dao/JournalTagDao.java new file mode 100644 index 0000000..87449c4 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/dao/JournalTagDao.java @@ -0,0 +1,29 @@ +package com.luoo.music.dao; + +import com.luoo.music.pojo.JournalTag; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +/** + * @author locust + */ +public interface JournalTagDao extends JpaRepository, JpaSpecificationExecutor { + + @Query("SELECT jt FROM JournalTag jt WHERE jt.journalId IN :journalIds ORDER BY jt.id") + List findByJournalIds(@Param("journalIds") List journalIds); + + @Query("SELECT jt.journalId FROM JournalTag jt WHERE jt.tagId IN :tagIds") + List findJournalIdsByTags(@Param("tagIds") List tagIds); + + @Query("SELECT jt.tagId FROM JournalTag jt WHERE jt.journalId = :journalId") + List findTagsByJournalId(@Param("journalId") String journalId); + + @Modifying + @Query("DELETE FROM JournalTag jt WHERE jt.journalId = :journalId") + int deleteByJournalId(@Param("journalId") String journalId); +} 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 new file mode 100644 index 0000000..39302a2 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/dao/SongInfoDao.java @@ -0,0 +1,27 @@ +package com.luoo.music.dao; + +import com.luoo.music.pojo.SongInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; +import java.util.Set; + +/** + * @author locust + */ +public interface SongInfoDao extends JpaRepository, JpaSpecificationExecutor { + + @Modifying + @Query("UPDATE SongInfo s SET s.state = :state WHERE s.id = :id") + int updateSongState(@Param("id") String id, @Param("state") String state); + + @Modifying + @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); +} diff --git a/luoo_music/src/main/java/com/luoo/music/dao/SongTagDao.java b/luoo_music/src/main/java/com/luoo/music/dao/SongTagDao.java index 7f4b572..7491c13 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/SongTagDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/SongTagDao.java @@ -3,6 +3,7 @@ package com.luoo.music.dao; import com.luoo.music.pojo.SongTag; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -19,6 +20,7 @@ public interface SongTagDao extends JpaRepository, JpaSpecificat @Query("SELECT st FROM SongTag st WHERE st.songId IN :ids ORDER BY st.id ") List findBySongId(@Param("ids") List ids); + @Modifying @Query("DELETE FROM SongTag st WHERE st.songId = :id") int deleteBySongId(@Param("id") String id); } diff --git a/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java b/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java index ac93711..b8eb885 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/TagDao.java @@ -13,16 +13,4 @@ import java.util.Set; public interface TagDao extends JpaRepository, JpaSpecificationExecutor{ List findByIdIn(Set ids); - - /*@Query(value = "SELECT " + - " t1.id AS id, " + - "CASE " + - " WHEN t1.LEVEL = 1 THEN " + - " t1.name_ch ELSE CONCAT(( SELECT t2.name_ch FROM tb_tag_info t2 WHERE t2.id = t1.parent_id ), '-', t1.name_ch ) " + - " END AS name_cn " + - "FROM " + - " tb_tag_info t1 " + - "WHERE " + - " t1.id IN :ids", nativeQuery = true) - List findTagCustomByIds(@Param("ids") List ids);*/ } diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/Column.java b/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java similarity index 95% rename from luoo_music/src/main/java/com/luoo/music/pojo/Column.java rename to luoo_music/src/main/java/com/luoo/music/pojo/Journal.java index da131b0..e5b2308 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/Column.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/Journal.java @@ -20,11 +20,11 @@ import java.time.LocalDateTime; */ @Data @Entity -@Table(name="tb_column") +@Table(name="tb_journal") @DynamicInsert @DynamicUpdate @EntityListeners(AuditingEntityListener.class) -public class Column implements Serializable{ +public class Journal implements Serializable{ @Id private String id; diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/ColumnSong.java b/luoo_music/src/main/java/com/luoo/music/pojo/JournalSong.java similarity index 75% rename from luoo_music/src/main/java/com/luoo/music/pojo/ColumnSong.java rename to luoo_music/src/main/java/com/luoo/music/pojo/JournalSong.java index c69fd8b..e6ac244 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/ColumnSong.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/JournalSong.java @@ -12,12 +12,12 @@ import javax.persistence.Table; */ @Data @Entity -@Table(name="tb_column_song") -public class ColumnSong { +@Table(name="tb_journal_song") +public class JournalSong { @Id private String id; - private String columnId; + private String journalId; private String songId; } diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/ColumnSongCount.java b/luoo_music/src/main/java/com/luoo/music/pojo/JournalSongCount.java similarity index 62% rename from luoo_music/src/main/java/com/luoo/music/pojo/ColumnSongCount.java rename to luoo_music/src/main/java/com/luoo/music/pojo/JournalSongCount.java index b0ee0e9..770c36c 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/ColumnSongCount.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/JournalSongCount.java @@ -4,9 +4,9 @@ package com.luoo.music.pojo; * 自定义对象 * @author locust */ -public interface ColumnSongCount { +public interface JournalSongCount { - String getColumnId(); + String getJournalId(); Long getSongCount(); } diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/ColumnTag.java b/luoo_music/src/main/java/com/luoo/music/pojo/JournalTag.java similarity index 75% rename from luoo_music/src/main/java/com/luoo/music/pojo/ColumnTag.java rename to luoo_music/src/main/java/com/luoo/music/pojo/JournalTag.java index d52496b..9e9d44f 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/ColumnTag.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/JournalTag.java @@ -12,12 +12,12 @@ import javax.persistence.Table; */ @Data @Entity -@Table(name="tb_column_tag") -public class ColumnTag { +@Table(name="tb_journal_tag") +public class JournalTag { @Id private String id; - private String columnId; + private String journalId; private String tagId; } diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/CMSSong.java b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java similarity index 95% rename from luoo_music/src/main/java/com/luoo/music/pojo/CMSSong.java rename to luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java index 9c9f93a..dbf47a2 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/CMSSong.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java @@ -23,9 +23,9 @@ import java.time.LocalDateTime; @Entity @DynamicInsert @DynamicUpdate -@Table(name = "tb_song_cms") +@Table(name = "tb_song_info") @EntityListeners(AuditingEntityListener.class) -public class CMSSong implements Serializable { +public class SongInfo implements Serializable { @Id private String id; diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/SongTag.java b/luoo_music/src/main/java/com/luoo/music/pojo/SongTag.java index eb242dd..a143299 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/SongTag.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/SongTag.java @@ -7,7 +7,7 @@ import javax.persistence.Id; import javax.persistence.Table; /** - * 曲目标签关系表 + * 歌曲标签关系表 * @author locust */ @Data diff --git a/luoo_music/src/main/java/com/luoo/music/request/cms/ColumnAddModel.java b/luoo_music/src/main/java/com/luoo/music/request/cms/JournalAddModel.java similarity index 95% rename from luoo_music/src/main/java/com/luoo/music/request/cms/ColumnAddModel.java rename to luoo_music/src/main/java/com/luoo/music/request/cms/JournalAddModel.java index 67e633d..cef17aa 100644 --- a/luoo_music/src/main/java/com/luoo/music/request/cms/ColumnAddModel.java +++ b/luoo_music/src/main/java/com/luoo/music/request/cms/JournalAddModel.java @@ -11,7 +11,7 @@ import java.util.List; */ @Data @ApiModel(value = "增加或修改期刊对象") -public class ColumnAddModel { +public class JournalAddModel { @ApiModelProperty(value = "期刊编号") private String number; diff --git a/luoo_music/src/main/java/com/luoo/music/request/cms/ColumnQueryModel.java b/luoo_music/src/main/java/com/luoo/music/request/cms/JournalQueryModel.java similarity index 91% rename from luoo_music/src/main/java/com/luoo/music/request/cms/ColumnQueryModel.java rename to luoo_music/src/main/java/com/luoo/music/request/cms/JournalQueryModel.java index 6d19f93..9e423cf 100644 --- a/luoo_music/src/main/java/com/luoo/music/request/cms/ColumnQueryModel.java +++ b/luoo_music/src/main/java/com/luoo/music/request/cms/JournalQueryModel.java @@ -11,7 +11,7 @@ import java.util.List; */ @Data @ApiModel(value = "期刊请求对象") -public class ColumnQueryModel { +public class JournalQueryModel { @ApiModelProperty(value = "列表Tab,新建:0,已发布:1, 回收站:2") private String tab = "0"; @@ -30,6 +30,4 @@ public class ColumnQueryModel { @ApiModelProperty(value = "标签ID") private List tags; - - private List columns; } diff --git a/luoo_music/src/main/java/com/luoo/music/response/cms/ColumnVO.java b/luoo_music/src/main/java/com/luoo/music/response/cms/ColumnVO.java deleted file mode 100644 index 6b79917..0000000 --- a/luoo_music/src/main/java/com/luoo/music/response/cms/ColumnVO.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.luoo.music.response.cms; - -import com.luoo.music.response.cms.SongVO; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import java.util.List; - -/** - * @author locust - */ -@Data -@ApiModel(description = "期刊信息") -public class ColumnVO { - - @ApiModelProperty(value = "主键ID", example = "123") - private String id; - - @ApiModelProperty(value = "期刊编号", example = "123") - private String number; - - @ApiModelProperty(value = "期刊标题", example = "123") - private String name; - - @ApiModelProperty(value = "期刊封面", example = "123") - private String coverPhoto; - - @ApiModelProperty(value = "期刊标签", example = "123") - private List tag; - - @ApiModelProperty(value = "歌曲数", example = "123") - private long songCount; - - @ApiModelProperty(value = "评论数", example = "123") - private long commentCount; - - @ApiModelProperty(value = "播放数", example = "123") - private long playCount; - - @ApiModelProperty(value = "发布作者", example = "123") - private String userId;// - - @ApiModelProperty(value = "创建时间", example = "123") - private String createTime; - - @ApiModelProperty(value = "发布时间", example = "123") - private String pubTime; - - @ApiModelProperty(value = "期刊启停状态,0:停用,1:启用", example = "123") - private String state; - - @ApiModelProperty(value = "期刊发布状态,0:待发布,1:已发布", example = "123") - private String status; - - @ApiModelProperty(value = "期刊歌曲信息", example = "123") - private List songs; - - @ApiModelProperty(value = "期刊简介信息", example = "123") - private String summary; -} 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 new file mode 100644 index 0000000..97dfa9b --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/response/cms/JournalVO.java @@ -0,0 +1,61 @@ +package com.luoo.music.response.cms; + +import com.luoo.music.response.cms.SongVO; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author locust + */ +@Data +@ApiModel(description = "期刊信息") +public class JournalVO { + + @ApiModelProperty(value = "主键ID") + private String id; + + @ApiModelProperty(value = "期刊编号") + private String number; + + @ApiModelProperty(value = "期刊标题") + private String name; + + @ApiModelProperty(value = "期刊封面") + private String coverPhoto; + + @ApiModelProperty(value = "期刊标签") + private List tag; + + @ApiModelProperty(value = "歌曲数") + private long songCount; + + @ApiModelProperty(value = "评论数") + private long commentCount; + + @ApiModelProperty(value = "播放数") + private long playCount; + + @ApiModelProperty(value = "发布作者") + private String userId;// + + @ApiModelProperty(value = "创建时间") + private String createTime; + + @ApiModelProperty(value = "发布时间") + private String pubTime; + + @ApiModelProperty(value = "期刊启停状态,0:停用,1:启用") + private String state; + + @ApiModelProperty(value = "期刊发布状态,0:待发布,1:已发布") + private String status; + + @ApiModelProperty(value = "期刊歌曲信息") + private List songs; + + @ApiModelProperty(value = "期刊简介信息") + private String summary; +} 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 6b22a5a..80f1df6 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 @@ -13,45 +13,45 @@ import java.util.List; @ApiModel(description = "歌曲信息") public class SongVO { - @ApiModelProperty(value = "主键ID", example = "123") + @ApiModelProperty(value = "主键ID") private String id; - @ApiModelProperty(value = "歌曲名称", example = "123") + @ApiModelProperty(value = "歌曲名称") private String name; - @ApiModelProperty(value = "歌手或乐队", example = "123") + @ApiModelProperty(value = "歌手或乐队") private String artist; - @ApiModelProperty(value = "专辑", example = "123") + @ApiModelProperty(value = "专辑") private String album; - @ApiModelProperty(value = "歌曲风格", example = "123") + @ApiModelProperty(value = "歌曲风格") private List tags; - @ApiModelProperty(value = "封面路径", example = "123") + @ApiModelProperty(value = "封面路径") private String picture; - @ApiModelProperty(value = "文件大小", example = "123") + @ApiModelProperty(value = "文件大小") private String size; - @ApiModelProperty(value = "歌曲时长", example = "123") + @ApiModelProperty(value = "歌曲时长") private String duration; - @ApiModelProperty(value = "关联期刊", example = "123") - private List column; + @ApiModelProperty(value = "关联期刊") + private List journal; - @ApiModelProperty(value = "修改时间", example = "123") + @ApiModelProperty(value = "修改时间") private String updateTime; - @ApiModelProperty(value = "歌曲启停状态,0:停用,1:启用", example = "123") + @ApiModelProperty(value = "歌曲启停状态,0:停用,1:启用") private String state; - @ApiModelProperty(value = "上传人员", example = "123") + @ApiModelProperty(value = "上传人员") private String userId; - @ApiModelProperty(value = "文件路径", example = "123") + @ApiModelProperty(value = "文件路径") private String url; - @ApiModelProperty(value = "歌词", example = "123") + @ApiModelProperty(value = "歌词") private String lyric; } diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSColumnService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java similarity index 58% rename from luoo_music/src/main/java/com/luoo/music/service/CMSColumnService.java rename to luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java index b65c52b..afbd0d6 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/CMSColumnService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/CMSJournalService.java @@ -4,9 +4,9 @@ import api.PageResult; import api.Result; import com.luoo.music.dao.*; import com.luoo.music.pojo.*; -import com.luoo.music.request.cms.ColumnAddModel; -import com.luoo.music.request.cms.ColumnQueryModel; -import com.luoo.music.response.cms.ColumnVO; +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.UploadUtil; @@ -34,20 +34,20 @@ import java.util.stream.Collectors; * @author locust */ @Service -public class CMSColumnService { +public class CMSJournalService { @Autowired - private ColumnTagDao columnTagDao; + private IdWorker idWorker; @Autowired - private ColumnDao columnDao; + private JournalTagDao journalTagDao; @Autowired - private IdWorker idWorker; + private JournalDao journalDao; @Autowired - private ColumnSongDao columnSongDao; + private JournalSongDao journalSongDao; @Autowired private TagDao tagDao; @Autowired - private CMSSongDao songDao; + private SongInfoDao songDao; private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -59,30 +59,29 @@ public class CMSColumnService { * @param size * @return */ - public Result search(ColumnQueryModel param, int page, int size) { - List result = new ArrayList<>(); + public Result> search(JournalQueryModel param, int page, int size) { + List result = new ArrayList<>(); Sort sort = new Sort(Sort.Direction.DESC, "createTime"); PageRequest pageRequest = PageRequest.of(page - 1, size, sort); - Page columnPage; + Page journalPage; if (!Objects.isNull(param)) { - List columnIdsByTags = null; + List journalIdsByTags = null; if (!CollectionUtils.isEmpty(param.getTags())) { - columnIdsByTags = columnTagDao.findColumnIdsByTags(param.getTags()); + journalIdsByTags = journalTagDao.findJournalIdsByTags(param.getTags()); } - param.setColumns(columnIdsByTags); - Specification columnSpecification = buildSearchSpecification(param); - columnPage = columnDao.findAll(columnSpecification, pageRequest); + Specification journalSpecification = buildSearchSpecification(param, journalIdsByTags); + journalPage = journalDao.findAll(journalSpecification, pageRequest); } else { - columnPage = columnDao.findAll(pageRequest); + journalPage = journalDao.findAll(pageRequest); } - long totalElements = columnPage.getTotalElements(); - List content = columnPage.getContent(); + long totalElements = journalPage.getTotalElements(); + List content = journalPage.getContent(); if (!CollectionUtils.isEmpty(content)) { - List ids = content.stream().map(Column::getId).collect(Collectors.toList()); + List ids = content.stream().map(Journal::getId).collect(Collectors.toList()); Map songCountMap = songCountInfo(ids); - Map> columnTagMap = tagInfo(ids); - for (Column item : content) { - ColumnVO response = new ColumnVO(); + Map> journalTagMap = tagInfo(ids); + for (Journal item : content) { + JournalVO response = new JournalVO(); response.setId(item.getId()); response.setNumber(item.getNumber()); response.setName(item.getName()); @@ -96,7 +95,7 @@ public class CMSColumnService { // TODO 编号文字转换 response.setUserId(item.getUserId()); response.setSongCount(songCountMap.get(item.getId())); - response.setTag(columnTagMap.get(item.getId())); + response.setTag(journalTagMap.get(item.getId())); if (!"1".equals(param.getTab())) { response.setPlayCount(0); response.setCommentCount(0); @@ -116,8 +115,8 @@ public class CMSColumnService { * @param param * @return */ - private Specification buildSearchSpecification(ColumnQueryModel param) { - return (Root root, CriteriaQuery query, CriteriaBuilder builder) -> { + private Specification buildSearchSpecification(JournalQueryModel param, List ids) { + return (Root root, CriteriaQuery query, CriteriaBuilder builder) -> { List predicateList = new ArrayList(); if("1".equals(param.getTab())) { Predicate state = builder.equal(root.get("state"), "1"); @@ -136,8 +135,8 @@ public class CMSColumnService { if (StringUtils.isNotBlank(param.getStart()) && StringUtils.isNotBlank(param.getEnd())) { predicateList.add(builder.between(root.get("createTime"), param.getStart(), param.getEnd())); } - if (!CollectionUtils.isEmpty(param.getColumns())) { - predicateList.add(root.get("id").in(param.getColumns())); + if (!CollectionUtils.isEmpty(ids)) { + predicateList.add(root.get("id").in(ids)); } if(StringUtils.isNotBlank(param.getKeyword())) { String likeExpression = "%" + param.getKeyword() + "%"; @@ -157,8 +156,8 @@ public class CMSColumnService { private Map songCountInfo(List ids) { Map songCountMap = new HashMap<>(); if (!CollectionUtils.isEmpty(ids)) { - List columnSongCountList = columnSongDao.findSongCountByColumnIds(ids); - songCountMap = columnSongCountList.stream().collect(Collectors.toMap(ColumnSongCount::getColumnId, ColumnSongCount::getSongCount)); + List journalSongCountList = journalSongDao.findSongCountByJournalIds(ids); + songCountMap = journalSongCountList.stream().collect(Collectors.toMap(JournalSongCount::getJournalId, JournalSongCount::getSongCount)); } return songCountMap; } @@ -169,16 +168,16 @@ public class CMSColumnService { * @return */ private Map> tagInfo(List ids) { - Map> columnTagMap = new HashMap<>(); - List columnTagList = columnTagDao.findByColumnIds(ids); - Set tagIdSet = columnTagList.stream().map(ColumnTag::getTagId).collect(Collectors.toSet()); + Map> journalTagMap = new HashMap<>(); + List journalTagList = journalTagDao.findByJournalIds(ids); + Set tagIdSet = journalTagList.stream().map(JournalTag::getTagId).collect(Collectors.toSet()); List tagList = tagDao.findByIdIn(tagIdSet); Map idTagMap = tagList.stream().collect(Collectors.toMap(Tag::getId, obj -> obj)); List list; - for (ColumnTag item : columnTagList) { - String columnId = item.getColumnId(); - if (columnTagMap.containsKey(columnId)) { - list = columnTagMap.get(columnId); + for (JournalTag item : journalTagList) { + String journalId = item.getJournalId(); + if (journalTagMap.containsKey(journalId)) { + list = journalTagMap.get(journalId); } else { list = new ArrayList<>(); } @@ -186,9 +185,9 @@ public class CMSColumnService { if (StringUtils.isNotBlank(tag.getParentId())) { list.add(tag.getNameCh()); } - columnTagMap.put(columnId, list); + journalTagMap.put(journalId, list); } - return columnTagMap; + return journalTagMap; } /** @@ -197,27 +196,27 @@ public class CMSColumnService { * @param image * @return */ - public Result add(ColumnAddModel param, MultipartFile image) { + public Result add(JournalAddModel param, MultipartFile image) { String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR); - Column column = buildColumn(null, param); + Journal journal = buildJournal(null, param); String id = String.valueOf(idWorker.nextId()); - column.setId(id); - column.setCoverPhoto(imagePath); - columnDao.save(column); - batchSaveColumnRelatesInfo(id, param); + journal.setId(id); + journal.setCoverPhoto(imagePath); + journalDao.save(journal); + batchSaveJournalRelatesInfo(id, param); return Result.success(); } - private Column buildColumn(String id, ColumnAddModel param) { - Column column = new Column(); + private Journal buildJournal(String id, JournalAddModel param) { + Journal journal = new Journal(); if (!StringUtils.isBlank(id)) { - column.setId(id); + journal.setId(id); } - column.setNumber(param.getNumber()); - column.setName(param.getName()); - column.setUserId(param.getUserId()); - column.setSummary(param.getSummary()); - return column; + journal.setNumber(param.getNumber()); + journal.setName(param.getName()); + journal.setUserId(param.getUserId()); + journal.setSummary(param.getSummary()); + return journal; } /** @@ -225,27 +224,27 @@ public class CMSColumnService { * @param id * @param param */ - private void batchSaveColumnRelatesInfo(String id, ColumnAddModel param) { + private void batchSaveJournalRelatesInfo(String id, JournalAddModel param) { if (!CollectionUtils.isEmpty(param.getTags())) { - List columnTagList = new ArrayList<>(); + List journalTagList = new ArrayList<>(); for (String item : param.getTags()) { - ColumnTag columnTag = new ColumnTag(); - columnTag.setId(String.valueOf(idWorker.nextId())); - columnTag.setColumnId(id); - columnTag.setTagId(item); - columnTagList.add(columnTag); + JournalTag journalTag = new JournalTag(); + journalTag.setId(String.valueOf(idWorker.nextId())); + journalTag.setJournalId(id); + journalTag.setTagId(item); + journalTagList.add(journalTag); } - columnTagDao.saveAll(columnTagList); + journalTagDao.saveAll(journalTagList); } if (!CollectionUtils.isEmpty(param.getSongs())) { - List columnSongList = new ArrayList<>(); + List journalSongList = new ArrayList<>(); for (String item : param.getSongs()) { - ColumnSong columnSong = new ColumnSong(); - columnSong.setId(String.valueOf(idWorker.nextId())); - columnSong.setColumnId(id); - columnSong.setSongId(item); + JournalSong journalSong = new JournalSong(); + journalSong.setId(String.valueOf(idWorker.nextId())); + journalSong.setJournalId(id); + journalSong.setSongId(item); } - columnSongDao.saveAll(columnSongList); + journalSongDao.saveAll(journalSongList); } } @@ -254,17 +253,17 @@ public class CMSColumnService { * @param id * @return */ - public Result findOne(String id) { - Column column = columnDao.findById(id).get(); - ColumnVO response = new ColumnVO(); - response.setId(column.getId()); - response.setNumber(column.getNumber()); - response.setName(column.getName()); - response.setTag(columnTagDao.findTagsByColumnId(id)); - response.setUserId(column.getUserId()); - response.setCoverPhoto(column.getCoverPhoto()); - response.setSongs(songInfo(column.getId())); - response.setSummary(column.getSummary()); + public Result findOne(String id) { + Journal journal = journalDao.findById(id).get(); + JournalVO response = new JournalVO(); + response.setId(journal.getId()); + response.setNumber(journal.getNumber()); + response.setName(journal.getName()); + response.setTag(journalTagDao.findTagsByJournalId(id)); + response.setUserId(journal.getUserId()); + response.setCoverPhoto(journal.getCoverPhoto()); + response.setSongs(songInfo(journal.getId())); + response.setSummary(journal.getSummary()); return Result.success(response); } @@ -275,14 +274,14 @@ public class CMSColumnService { */ private List songInfo(String id) { List list = new ArrayList<>(); - List columnSongList = columnSongDao.findByColumnId(id); - if (!CollectionUtils.isEmpty(columnSongList)) { - Set songIdSet = columnSongList.stream().map(ColumnSong::getSongId).collect(Collectors.toSet()); - List songList = songDao.findByIdIn(songIdSet); - Map idTagMap = songList.stream().collect(Collectors.toMap(CMSSong::getId, obj -> obj)); - for (ColumnSong item : columnSongList) { + List journalSongList = journalSongDao.findByJournalId(id); + 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())) { - CMSSong song = idTagMap.get(item.getSongId()); + SongInfo song = idTagMap.get(item.getSongId()); SongVO songVO = new SongVO(); songVO.setId(song.getId()); songVO.setPicture(song.getPicture()); @@ -305,17 +304,17 @@ public class CMSColumnService { * @param image * @return */ - public Result update(String id, ColumnAddModel param, MultipartFile image) { - Column column = buildColumn(id, param); - Column oldColumn = columnDao.findById(id).get(); - boolean bool = UploadUtil.fileHasChanged(oldColumn.getCoverPhoto(), image); + public Result update(String id, JournalAddModel param, MultipartFile image) { + Journal journal = buildJournal(id, param); + Journal oldJournal = journalDao.findById(id).get(); + boolean bool = UploadUtil.fileHasChanged(oldJournal.getCoverPhoto(), image); if (bool) { String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR); - column.setCoverPhoto(imagePath); + journal.setCoverPhoto(imagePath); } - columnDao.save(column); - batchDeleteColumnRelatesInfo(id); - batchSaveColumnRelatesInfo(id, param); + journalDao.save(journal); + batchDeleteJournalRelatesInfo(id); + batchSaveJournalRelatesInfo(id, param); return Result.success(); } @@ -323,9 +322,9 @@ public class CMSColumnService { * 删除期刊的标签、音乐信息 * @param id */ - private void batchDeleteColumnRelatesInfo(String id) { - columnTagDao.deleteByColumnId(id); - columnSongDao.deleteByColumnId(id); + private void batchDeleteJournalRelatesInfo(String id) { + journalTagDao.deleteByJournalId(id); + journalSongDao.deleteByJournalId(id); } @@ -341,10 +340,10 @@ public class CMSColumnService { if ("1".equals(scheduled)) { if (StringUtils.isNotBlank(pubTimeStr)){ pubTime = LocalDateTime.parse(pubTimeStr, formatter); - columnDao.updateScheduledPubById(id, scheduled, pubTime); + journalDao.updateScheduledPubById(id, scheduled, pubTime); } } - columnDao.updatePubById(id, pubTime); + journalDao.updatePubById(id, pubTime); return Result.success(); } @@ -354,8 +353,8 @@ public class CMSColumnService { * @param state * @return */ - public Result updateColumnState(String id, String state) { - columnDao.updateColumnState(id, state); + public Result updateJournalState(String id, String state) { + journalDao.updateJournalState(id, state); return Result.success("更新成功"); } @@ -365,9 +364,8 @@ public class CMSColumnService { * @return */ public Result deleteById(String id) { - columnDao.deleteById(id); - batchDeleteColumnRelatesInfo(id); + journalDao.deleteById(id); + batchDeleteJournalRelatesInfo(id); 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 1e27779..db9d116 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 @@ -43,15 +43,15 @@ import java.util.stream.Collectors; public class CMSSongService { @Autowired - private CMSSongDao songDao; + private SongInfoDao songDao; @Autowired private IdWorker idWorker; @Autowired private SongTagDao songTagDao; @Autowired - private ColumnSongDao columnSongDao; + private JournalSongDao journalSongDao; @Autowired - private ColumnDao columnDao; + private JournalDao journalDao; @Autowired private TagDao tagDao; @@ -64,25 +64,25 @@ public class CMSSongService { * @param size * @return */ - public Result search(SongQueryModel param, int page, int size) { + public Result> search(SongQueryModel param, int page, int size) { List result = new ArrayList<>(); // Sort sort = new Sort(Sort.Direction.DESC, "create_time"); // PageRequest pageRequest = PageRequest.of(page - 1, size, sort); PageRequest pageRequest = PageRequest.of(page - 1, size); - Page songPage; + Page songPage; if (!Objects.isNull(param)) { - Specification columnSpecification = buildSearchSpecification(param); - songPage = songDao.findAll(columnSpecification, pageRequest); + Specification songSpecification = buildSearchSpecification(param); + songPage = songDao.findAll(songSpecification, pageRequest); } else { songPage = songDao.findAll(pageRequest); } long totalElements = songPage.getTotalElements(); - List content = songPage.getContent(); + List content = songPage.getContent(); if (!CollectionUtils.isEmpty(content)) { - List ids = content.stream().map(CMSSong::getId).collect(Collectors.toList()); - Map> songColumnMap = buildSongColumnInfo(ids); + List ids = content.stream().map(SongInfo::getId).collect(Collectors.toList()); + Map> songJournalMap = buildSongJournalInfo(ids); Map> songTagMap = buildSongTagInfo(ids); - for (CMSSong item : content) { + for (SongInfo item : content) { SongVO response = new SongVO(); String id = item.getId(); response.setId(id); @@ -93,7 +93,7 @@ public class CMSSongService { response.setPicture(item.getPicture()); response.setSize(CommonUtil.formatSongSize(item.getSize())); response.setDuration(CommonUtil.formatSongDuration(item.getDuration())); - response.setColumn(songColumnMap.get(id)); + response.setJournal(songJournalMap.get(id)); response.setUpdateTime(df.format(item.getUpdateTime())); response.setState(item.getState()); response.setUserId(item.getUserId()); @@ -109,8 +109,8 @@ public class CMSSongService { * @param param * @return */ - private Specification buildSearchSpecification(SongQueryModel param) { - return (Root root, CriteriaQuery query, CriteriaBuilder builder) -> { + private Specification buildSearchSpecification(SongQueryModel param) { + 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())); @@ -131,25 +131,25 @@ public class CMSSongService { }; } - private Map> buildSongColumnInfo(List ids) { + private Map> buildSongJournalInfo(List ids) { Map> result = new HashMap<>(); - List bySongId = columnSongDao.findBySongId(ids); + List bySongId = journalSongDao.findBySongId(ids); if (!CollectionUtils.isEmpty(bySongId)) { - Set idSet = bySongId.stream().map(ColumnSong::getColumnId).collect(Collectors.toSet()); - List columnList = columnDao.findByIdIn(idSet); - Map idColumnMap = columnList.stream().collect(Collectors.toMap(Column::getId, obj -> obj)); - for (ColumnSong item : 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)); + for (JournalSong item : bySongId) { String songId = item.getSongId(); - String columnId = item.getColumnId(); + String journalId = item.getJournalId(); List list; if (result.keySet().contains(songId)) { list = result.get(songId); } else { list = new ArrayList<>(); } - if (idColumnMap.keySet().contains(columnId)) { - Column column = idColumnMap.get(columnId); - list.add(column.getNumber() + " " + column.getName()); + if (idJournalMap.keySet().contains(journalId)) { + Journal journal = idJournalMap.get(journalId); + list.add(journal.getNumber() + " " + journal.getName()); } result.put(songId, list); } @@ -193,7 +193,7 @@ public class CMSSongService { 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); - CMSSong song = new CMSSong(); + SongInfo song = new SongInfo(); String id = String.valueOf(idWorker.nextId()); song.setId(id); song.setName(param.getName()); @@ -256,8 +256,8 @@ public class CMSSongService { * @param id * @return */ - public Result findOne(String id) { - CMSSong song = songDao.findById(id).get(); + public Result findOne(String id) { + SongInfo song = songDao.findById(id).get(); SongVO response = new SongVO(); response.setId(song.getId()); response.setName(song.getName()); @@ -278,8 +278,8 @@ public class CMSSongService { * @return */ public Result update(String id, SongAddModel param, MultipartFile imageFile, MultipartFile songFile) { - CMSSong oldSong = songDao.findById(id).get(); - CMSSong song = new CMSSong(); + SongInfo oldSong = songDao.findById(id).get(); + SongInfo song = new SongInfo(); song.setId(id); song.setName(param.getName()); song.setArtist(param.getAlbum()); @@ -312,6 +312,9 @@ public class CMSSongService { */ public Result updateSongState(String id, String state) { songDao.updateSongState(id, state); + if ("0".equals(state)) { + journalSongDao.deleteBySongId(id); + } return Result.success("更新成功"); } @@ -333,7 +336,7 @@ public class CMSSongService { */ public Result batchUpload(List files) { for (MultipartFile file : files) { - CMSSong song = new CMSSong(); + SongInfo song = new SongInfo(); String id = String.valueOf(idWorker.nextId()); song.setId(id); String songPath = UploadUtil.upload(file, UploadUtil.SONG_DIR); @@ -351,8 +354,8 @@ public class CMSSongService { * @return */ public Result deleteById(String id) { - List columnsBySongId = columnSongDao.findColumnsBySongId(id); - if (CollectionUtils.isEmpty(columnsBySongId)) { + List journalsBySongId = journalSongDao.findJournalBySongId(id); + if (CollectionUtils.isEmpty(journalsBySongId)) { return Result.success("该歌曲被期刊使用,删除失败"); } else { songDao.deleteById(id);