Merge remote-tracking branch 'origin/main'

main
wangqing 10 months ago
commit 651d28fa55

@ -6,6 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@ -2,10 +2,10 @@ package com.luoo.music.controller;
import api.PageResult; import api.PageResult;
import api.Result; import api.Result;
import com.luoo.music.request.cms.ColumnAddModel; import com.luoo.music.request.cms.JournalAddModel;
import com.luoo.music.request.cms.ColumnQueryModel; import com.luoo.music.request.cms.JournalQueryModel;
import com.luoo.music.response.cms.ColumnVO; import com.luoo.music.response.cms.JournalVO;
import com.luoo.music.service.CMSColumnService; import com.luoo.music.service.CMSJournalService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
@ -19,39 +19,39 @@ import org.springframework.web.multipart.MultipartFile;
@RestController @RestController
@CrossOrigin @CrossOrigin
@Api(tags = "雀跃期刊后台CMS APIs") @Api(tags = "雀跃期刊后台CMS APIs")
@RequestMapping("/cms/column") @RequestMapping("/cms/journal")
public class CMSColumnController { public class CMSJournalController {
@Autowired @Autowired
private CMSColumnService columnService; private CMSJournalService journalService;
@ApiOperation(value = "查询期刊列表", notes = "查询期刊列表") @ApiOperation(value = "查询期刊列表", notes = "查询期刊列表")
@RequestMapping(value="/search/{page}/{size}", method= RequestMethod.POST) @RequestMapping(value="/search/{page}/{size}", method= RequestMethod.POST)
public Result<PageResult> search(@ApiParam(value = "查询条件", required = true) @RequestBody ColumnQueryModel queryModel, public Result<PageResult<JournalVO>> search(@ApiParam(value = "查询条件对象", required = true) @RequestBody JournalQueryModel queryModel,
@ApiParam(value = "页码", required = true) @PathVariable int page, @ApiParam(value = "页码", required = true) @PathVariable int page,
@ApiParam(value = "每页条数", required = true) @PathVariable int size){ @ApiParam(value = "每页条数", required = true) @PathVariable int size){
return columnService.search(queryModel, page, size); return journalService.search(queryModel, page, size);
} }
@ApiOperation(value = "新增期刊", notes = "新增期刊") @ApiOperation(value = "新增期刊", notes = "新增期刊")
@RequestMapping(value = "/add", method = RequestMethod.POST) @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){ @ApiParam(value = "封面文件", required = true) @RequestParam("imageFile") MultipartFile imageFile){
return columnService.add(addModel, imageFile); return journalService.add(addModel, imageFile);
} }
@ApiOperation(value = "查询期刊详情", notes = "查询期刊详情") @ApiOperation(value = "查询期刊详情", notes = "查询期刊详情")
@RequestMapping(value="/{id}",method= RequestMethod.GET) @RequestMapping(value="/{id}",method= RequestMethod.GET)
public Result<ColumnVO> findOne(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){ public Result<JournalVO> findOne(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){
return columnService.findOne(id); return journalService.findOne(id);
} }
@ApiOperation(value = "更新期刊", notes = "更新期刊") @ApiOperation(value = "更新期刊", notes = "更新期刊")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT) @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Result update(@ApiParam(value = "期刊ID", required = true) @PathVariable String id, 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){ @ApiParam(value = "封面文件", required = true) @RequestParam("imageFile") MultipartFile imageFile){
return columnService.update(id, updateModel, imageFile); return journalService.update(id, updateModel, imageFile);
} }
@ApiOperation(value = "发布期刊", notes = "发布期刊") @ApiOperation(value = "发布期刊", notes = "发布期刊")
@ -59,19 +59,19 @@ public class CMSColumnController {
public Result publish(@PathVariable String id, public Result publish(@PathVariable String id,
@ApiParam(value = "是否定时发布0:否1:是", required = true) @RequestParam("state") String scheduled, @ApiParam(value = "是否定时发布0:否1:是", required = true) @RequestParam("state") String scheduled,
@ApiParam(value = "定时发布时间") @RequestParam("state") String pubTime){ @ApiParam(value = "定时发布时间") @RequestParam("state") String pubTime){
return columnService.publish(id, scheduled, pubTime); return journalService.publish(id, scheduled, pubTime);
} }
@ApiOperation(value = "更新期刊启停状态", notes = "更新期刊启停状态") @ApiOperation(value = "更新期刊启停状态", notes = "更新期刊启停状态")
@RequestMapping(value="/update/state/{id}",method= RequestMethod.PUT) @RequestMapping(value="/update/state/{id}",method= RequestMethod.PUT)
public Result updateColumnState(@ApiParam(value = "期刊ID", required = true) @PathVariable String id, public Result updateColumnState(@ApiParam(value = "期刊ID", required = true) @PathVariable String id,
@ApiParam(value = "期刊启停状态0:停用1:启用", required = true) @RequestParam("state") String state){ @ApiParam(value = "期刊启停状态0:停用1:启用", required = true) @RequestParam("state") String state){
return columnService.updateColumnState(id, state); return journalService.updateJournalState(id, state);
} }
@ApiOperation(value = "删除单条期刊", notes = "删除单条期刊") @ApiOperation(value = "删除单条期刊", notes = "删除单条期刊")
@RequestMapping(value="/{id}", method= RequestMethod.DELETE) @RequestMapping(value="/{id}", method= RequestMethod.DELETE)
public Result delete(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){ public Result delete(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){
return columnService.deleteById(id); return journalService.deleteById(id);
} }
} }

@ -1,8 +1,10 @@
package com.luoo.music.controller; package com.luoo.music.controller;
import api.PageResult;
import api.Result; import api.Result;
import com.luoo.music.request.cms.SongAddModel; import com.luoo.music.request.cms.SongAddModel;
import com.luoo.music.request.cms.SongQueryModel; 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.CMSSongService;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -25,7 +27,7 @@ public class CMSSongController {
@ApiOperation(value = "查询曲目列表", notes = "查询曲目列表") @ApiOperation(value = "查询曲目列表", notes = "查询曲目列表")
@RequestMapping(value="/search/{page}/{size}",method= RequestMethod.POST) @RequestMapping(value="/search/{page}/{size}",method= RequestMethod.POST)
public Result search(@ApiParam(value = "查询条件") @RequestBody SongQueryModel queryModel, public Result<PageResult<SongVO>> search(@ApiParam(value = "查询条件") @RequestBody SongQueryModel queryModel,
@ApiParam(value = "页码", required = true) @PathVariable int page, @ApiParam(value = "页码", required = true) @PathVariable int page,
@ApiParam(value = "每页条数", required = true)@PathVariable int size){ @ApiParam(value = "每页条数", required = true)@PathVariable int size){
return songService.search(queryModel, page, size); return songService.search(queryModel, page, size);
@ -41,7 +43,7 @@ public class CMSSongController {
@ApiOperation(value = "查询歌曲详情", notes = "查询歌曲详情") @ApiOperation(value = "查询歌曲详情", notes = "查询歌曲详情")
@RequestMapping(value="/{id}",method= RequestMethod.GET) @RequestMapping(value="/{id}",method= RequestMethod.GET)
public Result findOne(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id){ public Result<SongVO> findOne(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id){
return songService.findOne(id); return songService.findOne(id);
} }

@ -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<CMSSong,String>, JpaSpecificationExecutor<CMSSong> {
// public List<Song> 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<CMSSong> findByIdIn(Set<String> 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);*/
}

@ -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<Column,String>,JpaSpecificationExecutor<Column>{
List<Column> findByIdIn(Set<String> 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);*/
}

@ -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<ColumnSong,String>, JpaSpecificationExecutor<ColumnSong> {
@Query("SELECT cs.columnId, COUNT(cs) AS songCount FROM ColumnSong cs WHERE cs.columnId IN :columnIds GROUP BY cs.columnId")
List<ColumnSongCount> findSongCountByColumnIds(@Param("columnIds") List<String> columnIds);
@Query("SELECT cs.columnId FROM ColumnSong cs WHERE cs.songId = :id")
List<String> findColumnsBySongId(@Param("id") String id);
@Query("SELECT cs FROM ColumnSong cs WHERE cs.songId IN :ids ORDER BY cs.id ")
List<ColumnSong> findBySongId(@Param("ids") List<String> ids);
@Query("SELECT cs FROM ColumnSong cs WHERE cs.columnId = :id ORDER BY cs.id ")
List<ColumnSong> findByColumnId(@Param("id") String id);
@Query("DELETE FROM ColumnSong cs WHERE cs.columnId = :id")
int deleteByColumnId(@Param("id") String id);
}

@ -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<ColumnTag,String>, JpaSpecificationExecutor<ColumnTag> {
@Query("SELECT ct FROM ColumnTag ct WHERE ct.columnId IN :columnIds ORDER BY ct.id")
List<ColumnTag> findByColumnIds(@Param("columnIds") List<String> columnIds);
@Query("SELECT ct.columnId FROM ColumnTag ct WHERE ct.tagId IN :tags")
List<String> findColumnIdsByTags(@Param("tags") List<String> tags);
@Query("SELECT ct.tagId FROM ColumnTag ct WHERE ct.columnId = :id")
List<String> findTagsByColumnId(@Param("id") String id);
@Query("DELETE FROM ColumnTag ct WHERE ct.columnId = :id")
int deleteByColumnId(@Param("id") String id);
}

@ -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<Journal,String>,JpaSpecificationExecutor<Journal>{
List<Journal> findByIdIn(Set<String> 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);
}

@ -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<JournalSong,String>, JpaSpecificationExecutor<JournalSong> {
@Query("SELECT js.journalId, COUNT(js) AS songCount FROM JournalSong js WHERE js.journalId IN :journalIds GROUP BY js.journalId")
List<JournalSongCount> findSongCountByJournalIds(@Param("journalIds") List<String> journalIds);
@Query("SELECT js.journalId FROM JournalSong js WHERE js.songId = :songId")
List<String> findJournalBySongId(@Param("songId") String songId);
@Query("SELECT js FROM JournalSong js WHERE js.songId IN :songIds ORDER BY js.id")
List<JournalSong> findBySongId(@Param("songIds") List<String> songIds);
@Query("SELECT js FROM JournalSong js WHERE js.journalId = :journalId ORDER BY js.id")
List<JournalSong> 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);
}

@ -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<JournalTag,String>, JpaSpecificationExecutor<JournalTag> {
@Query("SELECT jt FROM JournalTag jt WHERE jt.journalId IN :journalIds ORDER BY jt.id")
List<JournalTag> findByJournalIds(@Param("journalIds") List<String> journalIds);
@Query("SELECT jt.journalId FROM JournalTag jt WHERE jt.tagId IN :tagIds")
List<String> findJournalIdsByTags(@Param("tagIds") List<String> tagIds);
@Query("SELECT jt.tagId FROM JournalTag jt WHERE jt.journalId = :journalId")
List<String> findTagsByJournalId(@Param("journalId") String journalId);
@Modifying
@Query("DELETE FROM JournalTag jt WHERE jt.journalId = :journalId")
int deleteByJournalId(@Param("journalId") String journalId);
}

@ -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<SongInfo,String>, JpaSpecificationExecutor<SongInfo> {
@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<SongInfo> findByIdIn(Set<String> ids);
}

@ -3,6 +3,7 @@ package com.luoo.music.dao;
import com.luoo.music.pojo.SongTag; import com.luoo.music.pojo.SongTag;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 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.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
@ -19,6 +20,7 @@ public interface SongTagDao extends JpaRepository<SongTag,String>, JpaSpecificat
@Query("SELECT st FROM SongTag st WHERE st.songId IN :ids ORDER BY st.id ") @Query("SELECT st FROM SongTag st WHERE st.songId IN :ids ORDER BY st.id ")
List<SongTag> findBySongId(@Param("ids") List<String> ids); List<SongTag> findBySongId(@Param("ids") List<String> ids);
@Modifying
@Query("DELETE FROM SongTag st WHERE st.songId = :id") @Query("DELETE FROM SongTag st WHERE st.songId = :id")
int deleteBySongId(@Param("id") String id); int deleteBySongId(@Param("id") String id);
} }

@ -13,16 +13,4 @@ import java.util.Set;
public interface TagDao extends JpaRepository<Tag, String>, JpaSpecificationExecutor<Tag>{ public interface TagDao extends JpaRepository<Tag, String>, JpaSpecificationExecutor<Tag>{
List<Tag> findByIdIn(Set<String> ids); List<Tag> findByIdIn(Set<String> 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<TagCustom> findTagCustomByIds(@Param("ids") List<String> ids);*/
} }

@ -20,11 +20,11 @@ import java.time.LocalDateTime;
*/ */
@Data @Data
@Entity @Entity
@Table(name="tb_column") @Table(name="tb_journal")
@DynamicInsert @DynamicInsert
@DynamicUpdate @DynamicUpdate
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
public class Column implements Serializable{ public class Journal implements Serializable{
@Id @Id
private String id; private String id;

@ -12,12 +12,12 @@ import javax.persistence.Table;
*/ */
@Data @Data
@Entity @Entity
@Table(name="tb_column_song") @Table(name="tb_journal_song")
public class ColumnSong { public class JournalSong {
@Id @Id
private String id; private String id;
private String columnId; private String journalId;
private String songId; private String songId;
} }

@ -4,9 +4,9 @@ package com.luoo.music.pojo;
* *
* @author locust * @author locust
*/ */
public interface ColumnSongCount { public interface JournalSongCount {
String getColumnId(); String getJournalId();
Long getSongCount(); Long getSongCount();
} }

@ -12,12 +12,12 @@ import javax.persistence.Table;
*/ */
@Data @Data
@Entity @Entity
@Table(name="tb_column_tag") @Table(name="tb_journal_tag")
public class ColumnTag { public class JournalTag {
@Id @Id
private String id; private String id;
private String columnId; private String journalId;
private String tagId; private String tagId;
} }

@ -23,9 +23,9 @@ import java.time.LocalDateTime;
@Entity @Entity
@DynamicInsert @DynamicInsert
@DynamicUpdate @DynamicUpdate
@Table(name = "tb_song_cms") @Table(name = "tb_song_info")
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
public class CMSSong implements Serializable { public class SongInfo implements Serializable {
@Id @Id
private String id; private String id;

@ -7,7 +7,7 @@ import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
/** /**
* *
* @author locust * @author locust
*/ */
@Data @Data

@ -11,7 +11,7 @@ import java.util.List;
*/ */
@Data @Data
@ApiModel(value = "增加或修改期刊对象") @ApiModel(value = "增加或修改期刊对象")
public class ColumnAddModel { public class JournalAddModel {
@ApiModelProperty(value = "期刊编号") @ApiModelProperty(value = "期刊编号")
private String number; private String number;

@ -11,7 +11,7 @@ import java.util.List;
*/ */
@Data @Data
@ApiModel(value = "期刊请求对象") @ApiModel(value = "期刊请求对象")
public class ColumnQueryModel { public class JournalQueryModel {
@ApiModelProperty(value = "列表Tab新建0已发布1 回收站2") @ApiModelProperty(value = "列表Tab新建0已发布1 回收站2")
private String tab = "0"; private String tab = "0";
@ -30,6 +30,4 @@ public class ColumnQueryModel {
@ApiModelProperty(value = "标签ID") @ApiModelProperty(value = "标签ID")
private List<String> tags; private List<String> tags;
private List<String> columns;
} }

@ -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<String> 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<SongVO> songs;
@ApiModelProperty(value = "期刊简介信息", example = "123")
private String summary;
}

@ -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<String> 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<SongVO> songs;
@ApiModelProperty(value = "期刊简介信息")
private String summary;
}

@ -13,45 +13,45 @@ import java.util.List;
@ApiModel(description = "歌曲信息") @ApiModel(description = "歌曲信息")
public class SongVO { public class SongVO {
@ApiModelProperty(value = "主键ID", example = "123") @ApiModelProperty(value = "主键ID")
private String id; private String id;
@ApiModelProperty(value = "歌曲名称", example = "123") @ApiModelProperty(value = "歌曲名称")
private String name; private String name;
@ApiModelProperty(value = "歌手或乐队", example = "123") @ApiModelProperty(value = "歌手或乐队")
private String artist; private String artist;
@ApiModelProperty(value = "专辑", example = "123") @ApiModelProperty(value = "专辑")
private String album; private String album;
@ApiModelProperty(value = "歌曲风格", example = "123") @ApiModelProperty(value = "歌曲风格")
private List<String> tags; private List<String> tags;
@ApiModelProperty(value = "封面路径", example = "123") @ApiModelProperty(value = "封面路径")
private String picture; private String picture;
@ApiModelProperty(value = "文件大小", example = "123") @ApiModelProperty(value = "文件大小")
private String size; private String size;
@ApiModelProperty(value = "歌曲时长", example = "123") @ApiModelProperty(value = "歌曲时长")
private String duration; private String duration;
@ApiModelProperty(value = "关联期刊", example = "123") @ApiModelProperty(value = "关联期刊")
private List<String> column; private List<String> journal;
@ApiModelProperty(value = "修改时间", example = "123") @ApiModelProperty(value = "修改时间")
private String updateTime; private String updateTime;
@ApiModelProperty(value = "歌曲启停状态0:停用1:启用", example = "123") @ApiModelProperty(value = "歌曲启停状态0:停用1:启用")
private String state; private String state;
@ApiModelProperty(value = "上传人员", example = "123") @ApiModelProperty(value = "上传人员")
private String userId; private String userId;
@ApiModelProperty(value = "文件路径", example = "123") @ApiModelProperty(value = "文件路径")
private String url; private String url;
@ApiModelProperty(value = "歌词", example = "123") @ApiModelProperty(value = "歌词")
private String lyric; private String lyric;
} }

@ -4,9 +4,9 @@ import api.PageResult;
import api.Result; import api.Result;
import com.luoo.music.dao.*; import com.luoo.music.dao.*;
import com.luoo.music.pojo.*; import com.luoo.music.pojo.*;
import com.luoo.music.request.cms.ColumnAddModel; import com.luoo.music.request.cms.JournalAddModel;
import com.luoo.music.request.cms.ColumnQueryModel; import com.luoo.music.request.cms.JournalQueryModel;
import com.luoo.music.response.cms.ColumnVO; import com.luoo.music.response.cms.JournalVO;
import com.luoo.music.response.cms.SongVO; import com.luoo.music.response.cms.SongVO;
import com.luoo.music.util.CommonUtil; import com.luoo.music.util.CommonUtil;
import com.luoo.music.util.UploadUtil; import com.luoo.music.util.UploadUtil;
@ -34,20 +34,20 @@ import java.util.stream.Collectors;
* @author locust * @author locust
*/ */
@Service @Service
public class CMSColumnService { public class CMSJournalService {
@Autowired @Autowired
private ColumnTagDao columnTagDao; private IdWorker idWorker;
@Autowired @Autowired
private ColumnDao columnDao; private JournalTagDao journalTagDao;
@Autowired @Autowired
private IdWorker idWorker; private JournalDao journalDao;
@Autowired @Autowired
private ColumnSongDao columnSongDao; private JournalSongDao journalSongDao;
@Autowired @Autowired
private TagDao tagDao; private TagDao tagDao;
@Autowired @Autowired
private CMSSongDao songDao; private SongInfoDao songDao;
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@ -59,30 +59,29 @@ public class CMSColumnService {
* @param size * @param size
* @return * @return
*/ */
public Result<PageResult> search(ColumnQueryModel param, int page, int size) { public Result<PageResult<JournalVO>> search(JournalQueryModel param, int page, int size) {
List<ColumnVO> result = new ArrayList<>(); List<JournalVO> result = new ArrayList<>();
Sort sort = new Sort(Sort.Direction.DESC, "createTime"); Sort sort = new Sort(Sort.Direction.DESC, "createTime");
PageRequest pageRequest = PageRequest.of(page - 1, size, sort); PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
Page<Column> columnPage; Page<Journal> journalPage;
if (!Objects.isNull(param)) { if (!Objects.isNull(param)) {
List<String> columnIdsByTags = null; List<String> journalIdsByTags = null;
if (!CollectionUtils.isEmpty(param.getTags())) { if (!CollectionUtils.isEmpty(param.getTags())) {
columnIdsByTags = columnTagDao.findColumnIdsByTags(param.getTags()); journalIdsByTags = journalTagDao.findJournalIdsByTags(param.getTags());
} }
param.setColumns(columnIdsByTags); Specification<Journal> journalSpecification = buildSearchSpecification(param, journalIdsByTags);
Specification<Column> columnSpecification = buildSearchSpecification(param); journalPage = journalDao.findAll(journalSpecification, pageRequest);
columnPage = columnDao.findAll(columnSpecification, pageRequest);
} else { } else {
columnPage = columnDao.findAll(pageRequest); journalPage = journalDao.findAll(pageRequest);
} }
long totalElements = columnPage.getTotalElements(); long totalElements = journalPage.getTotalElements();
List<Column> content = columnPage.getContent(); List<Journal> content = journalPage.getContent();
if (!CollectionUtils.isEmpty(content)) { if (!CollectionUtils.isEmpty(content)) {
List<String> ids = content.stream().map(Column::getId).collect(Collectors.toList()); List<String> ids = content.stream().map(Journal::getId).collect(Collectors.toList());
Map<String, Long> songCountMap = songCountInfo(ids); Map<String, Long> songCountMap = songCountInfo(ids);
Map<String, List<String>> columnTagMap = tagInfo(ids); Map<String, List<String>> journalTagMap = tagInfo(ids);
for (Column item : content) { for (Journal item : content) {
ColumnVO response = new ColumnVO(); JournalVO response = new JournalVO();
response.setId(item.getId()); response.setId(item.getId());
response.setNumber(item.getNumber()); response.setNumber(item.getNumber());
response.setName(item.getName()); response.setName(item.getName());
@ -96,7 +95,7 @@ public class CMSColumnService {
// TODO 编号文字转换 // TODO 编号文字转换
response.setUserId(item.getUserId()); response.setUserId(item.getUserId());
response.setSongCount(songCountMap.get(item.getId())); response.setSongCount(songCountMap.get(item.getId()));
response.setTag(columnTagMap.get(item.getId())); response.setTag(journalTagMap.get(item.getId()));
if (!"1".equals(param.getTab())) { if (!"1".equals(param.getTab())) {
response.setPlayCount(0); response.setPlayCount(0);
response.setCommentCount(0); response.setCommentCount(0);
@ -116,8 +115,8 @@ public class CMSColumnService {
* @param param * @param param
* @return * @return
*/ */
private Specification<Column> buildSearchSpecification(ColumnQueryModel param) { private Specification<Journal> buildSearchSpecification(JournalQueryModel param, List<String> ids) {
return (Root<Column> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> { return (Root<Journal> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
List<Predicate> predicateList = new ArrayList<Predicate>(); List<Predicate> predicateList = new ArrayList<Predicate>();
if("1".equals(param.getTab())) { if("1".equals(param.getTab())) {
Predicate state = builder.equal(root.get("state"), "1"); Predicate state = builder.equal(root.get("state"), "1");
@ -136,8 +135,8 @@ public class CMSColumnService {
if (StringUtils.isNotBlank(param.getStart()) && StringUtils.isNotBlank(param.getEnd())) { if (StringUtils.isNotBlank(param.getStart()) && StringUtils.isNotBlank(param.getEnd())) {
predicateList.add(builder.between(root.get("createTime"), param.getStart(), param.getEnd())); predicateList.add(builder.between(root.get("createTime"), param.getStart(), param.getEnd()));
} }
if (!CollectionUtils.isEmpty(param.getColumns())) { if (!CollectionUtils.isEmpty(ids)) {
predicateList.add(root.get("id").in(param.getColumns())); predicateList.add(root.get("id").in(ids));
} }
if(StringUtils.isNotBlank(param.getKeyword())) { if(StringUtils.isNotBlank(param.getKeyword())) {
String likeExpression = "%" + param.getKeyword() + "%"; String likeExpression = "%" + param.getKeyword() + "%";
@ -157,8 +156,8 @@ public class CMSColumnService {
private Map<String, Long> songCountInfo(List<String> ids) { private Map<String, Long> songCountInfo(List<String> ids) {
Map<String, Long> songCountMap = new HashMap<>(); Map<String, Long> songCountMap = new HashMap<>();
if (!CollectionUtils.isEmpty(ids)) { if (!CollectionUtils.isEmpty(ids)) {
List<ColumnSongCount> columnSongCountList = columnSongDao.findSongCountByColumnIds(ids); List<JournalSongCount> journalSongCountList = journalSongDao.findSongCountByJournalIds(ids);
songCountMap = columnSongCountList.stream().collect(Collectors.toMap(ColumnSongCount::getColumnId, ColumnSongCount::getSongCount)); songCountMap = journalSongCountList.stream().collect(Collectors.toMap(JournalSongCount::getJournalId, JournalSongCount::getSongCount));
} }
return songCountMap; return songCountMap;
} }
@ -169,16 +168,16 @@ public class CMSColumnService {
* @return * @return
*/ */
private Map<String, List<String>> tagInfo(List<String> ids) { private Map<String, List<String>> tagInfo(List<String> ids) {
Map<String, List<String>> columnTagMap = new HashMap<>(); Map<String, List<String>> journalTagMap = new HashMap<>();
List<ColumnTag> columnTagList = columnTagDao.findByColumnIds(ids); List<JournalTag> journalTagList = journalTagDao.findByJournalIds(ids);
Set<String> tagIdSet = columnTagList.stream().map(ColumnTag::getTagId).collect(Collectors.toSet()); Set<String> tagIdSet = journalTagList.stream().map(JournalTag::getTagId).collect(Collectors.toSet());
List<Tag> tagList = tagDao.findByIdIn(tagIdSet); List<Tag> tagList = tagDao.findByIdIn(tagIdSet);
Map<String, Tag> idTagMap = tagList.stream().collect(Collectors.toMap(Tag::getId, obj -> obj)); Map<String, Tag> idTagMap = tagList.stream().collect(Collectors.toMap(Tag::getId, obj -> obj));
List<String> list; List<String> list;
for (ColumnTag item : columnTagList) { for (JournalTag item : journalTagList) {
String columnId = item.getColumnId(); String journalId = item.getJournalId();
if (columnTagMap.containsKey(columnId)) { if (journalTagMap.containsKey(journalId)) {
list = columnTagMap.get(columnId); list = journalTagMap.get(journalId);
} else { } else {
list = new ArrayList<>(); list = new ArrayList<>();
} }
@ -186,9 +185,9 @@ public class CMSColumnService {
if (StringUtils.isNotBlank(tag.getParentId())) { if (StringUtils.isNotBlank(tag.getParentId())) {
list.add(tag.getNameCh()); 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 * @param image
* @return * @return
*/ */
public Result add(ColumnAddModel param, MultipartFile image) { public Result add(JournalAddModel param, MultipartFile image) {
String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR); String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR);
Column column = buildColumn(null, param); Journal journal = buildJournal(null, param);
String id = String.valueOf(idWorker.nextId()); String id = String.valueOf(idWorker.nextId());
column.setId(id); journal.setId(id);
column.setCoverPhoto(imagePath); journal.setCoverPhoto(imagePath);
columnDao.save(column); journalDao.save(journal);
batchSaveColumnRelatesInfo(id, param); batchSaveJournalRelatesInfo(id, param);
return Result.success(); return Result.success();
} }
private Column buildColumn(String id, ColumnAddModel param) { private Journal buildJournal(String id, JournalAddModel param) {
Column column = new Column(); Journal journal = new Journal();
if (!StringUtils.isBlank(id)) { if (!StringUtils.isBlank(id)) {
column.setId(id); journal.setId(id);
} }
column.setNumber(param.getNumber()); journal.setNumber(param.getNumber());
column.setName(param.getName()); journal.setName(param.getName());
column.setUserId(param.getUserId()); journal.setUserId(param.getUserId());
column.setSummary(param.getSummary()); journal.setSummary(param.getSummary());
return column; return journal;
} }
/** /**
@ -225,27 +224,27 @@ public class CMSColumnService {
* @param id * @param id
* @param param * @param param
*/ */
private void batchSaveColumnRelatesInfo(String id, ColumnAddModel param) { private void batchSaveJournalRelatesInfo(String id, JournalAddModel param) {
if (!CollectionUtils.isEmpty(param.getTags())) { if (!CollectionUtils.isEmpty(param.getTags())) {
List<ColumnTag> columnTagList = new ArrayList<>(); List<JournalTag> journalTagList = new ArrayList<>();
for (String item : param.getTags()) { for (String item : param.getTags()) {
ColumnTag columnTag = new ColumnTag(); JournalTag journalTag = new JournalTag();
columnTag.setId(String.valueOf(idWorker.nextId())); journalTag.setId(String.valueOf(idWorker.nextId()));
columnTag.setColumnId(id); journalTag.setJournalId(id);
columnTag.setTagId(item); journalTag.setTagId(item);
columnTagList.add(columnTag); journalTagList.add(journalTag);
} }
columnTagDao.saveAll(columnTagList); journalTagDao.saveAll(journalTagList);
} }
if (!CollectionUtils.isEmpty(param.getSongs())) { if (!CollectionUtils.isEmpty(param.getSongs())) {
List<ColumnSong> columnSongList = new ArrayList<>(); List<JournalSong> journalSongList = new ArrayList<>();
for (String item : param.getSongs()) { for (String item : param.getSongs()) {
ColumnSong columnSong = new ColumnSong(); JournalSong journalSong = new JournalSong();
columnSong.setId(String.valueOf(idWorker.nextId())); journalSong.setId(String.valueOf(idWorker.nextId()));
columnSong.setColumnId(id); journalSong.setJournalId(id);
columnSong.setSongId(item); journalSong.setSongId(item);
} }
columnSongDao.saveAll(columnSongList); journalSongDao.saveAll(journalSongList);
} }
} }
@ -254,17 +253,17 @@ public class CMSColumnService {
* @param id * @param id
* @return * @return
*/ */
public Result<ColumnVO> findOne(String id) { public Result<JournalVO> findOne(String id) {
Column column = columnDao.findById(id).get(); Journal journal = journalDao.findById(id).get();
ColumnVO response = new ColumnVO(); JournalVO response = new JournalVO();
response.setId(column.getId()); response.setId(journal.getId());
response.setNumber(column.getNumber()); response.setNumber(journal.getNumber());
response.setName(column.getName()); response.setName(journal.getName());
response.setTag(columnTagDao.findTagsByColumnId(id)); response.setTag(journalTagDao.findTagsByJournalId(id));
response.setUserId(column.getUserId()); response.setUserId(journal.getUserId());
response.setCoverPhoto(column.getCoverPhoto()); response.setCoverPhoto(journal.getCoverPhoto());
response.setSongs(songInfo(column.getId())); response.setSongs(songInfo(journal.getId()));
response.setSummary(column.getSummary()); response.setSummary(journal.getSummary());
return Result.success(response); return Result.success(response);
} }
@ -275,14 +274,14 @@ public class CMSColumnService {
*/ */
private List<SongVO> songInfo(String id) { private List<SongVO> songInfo(String id) {
List<SongVO> list = new ArrayList<>(); List<SongVO> list = new ArrayList<>();
List<ColumnSong> columnSongList = columnSongDao.findByColumnId(id); List<JournalSong> journalSongList = journalSongDao.findByJournalId(id);
if (!CollectionUtils.isEmpty(columnSongList)) { if (!CollectionUtils.isEmpty(journalSongList)) {
Set<String> songIdSet = columnSongList.stream().map(ColumnSong::getSongId).collect(Collectors.toSet()); Set<String> songIdSet = journalSongList.stream().map(JournalSong::getSongId).collect(Collectors.toSet());
List<CMSSong> songList = songDao.findByIdIn(songIdSet); List<SongInfo> songList = songDao.findByIdIn(songIdSet);
Map<String, CMSSong> idTagMap = songList.stream().collect(Collectors.toMap(CMSSong::getId, obj -> obj)); Map<String, SongInfo> idTagMap = songList.stream().collect(Collectors.toMap(SongInfo::getId, obj -> obj));
for (ColumnSong item : columnSongList) { for (JournalSong item : journalSongList) {
if (idTagMap.containsKey(item.getSongId())) { if (idTagMap.containsKey(item.getSongId())) {
CMSSong song = idTagMap.get(item.getSongId()); SongInfo song = idTagMap.get(item.getSongId());
SongVO songVO = new SongVO(); SongVO songVO = new SongVO();
songVO.setId(song.getId()); songVO.setId(song.getId());
songVO.setPicture(song.getPicture()); songVO.setPicture(song.getPicture());
@ -305,17 +304,17 @@ public class CMSColumnService {
* @param image * @param image
* @return * @return
*/ */
public Result update(String id, ColumnAddModel param, MultipartFile image) { public Result update(String id, JournalAddModel param, MultipartFile image) {
Column column = buildColumn(id, param); Journal journal = buildJournal(id, param);
Column oldColumn = columnDao.findById(id).get(); Journal oldJournal = journalDao.findById(id).get();
boolean bool = UploadUtil.fileHasChanged(oldColumn.getCoverPhoto(), image); boolean bool = UploadUtil.fileHasChanged(oldJournal.getCoverPhoto(), image);
if (bool) { if (bool) {
String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR); String imagePath = UploadUtil.upload(image, UploadUtil.IMAGE_DIR);
column.setCoverPhoto(imagePath); journal.setCoverPhoto(imagePath);
} }
columnDao.save(column); journalDao.save(journal);
batchDeleteColumnRelatesInfo(id); batchDeleteJournalRelatesInfo(id);
batchSaveColumnRelatesInfo(id, param); batchSaveJournalRelatesInfo(id, param);
return Result.success(); return Result.success();
} }
@ -323,9 +322,9 @@ public class CMSColumnService {
* *
* @param id * @param id
*/ */
private void batchDeleteColumnRelatesInfo(String id) { private void batchDeleteJournalRelatesInfo(String id) {
columnTagDao.deleteByColumnId(id); journalTagDao.deleteByJournalId(id);
columnSongDao.deleteByColumnId(id); journalSongDao.deleteByJournalId(id);
} }
@ -341,10 +340,10 @@ public class CMSColumnService {
if ("1".equals(scheduled)) { if ("1".equals(scheduled)) {
if (StringUtils.isNotBlank(pubTimeStr)){ if (StringUtils.isNotBlank(pubTimeStr)){
pubTime = LocalDateTime.parse(pubTimeStr, formatter); 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(); return Result.success();
} }
@ -354,8 +353,8 @@ public class CMSColumnService {
* @param state * @param state
* @return * @return
*/ */
public Result updateColumnState(String id, String state) { public Result updateJournalState(String id, String state) {
columnDao.updateColumnState(id, state); journalDao.updateJournalState(id, state);
return Result.success("更新成功"); return Result.success("更新成功");
} }
@ -365,9 +364,8 @@ public class CMSColumnService {
* @return * @return
*/ */
public Result deleteById(String id) { public Result deleteById(String id) {
columnDao.deleteById(id); journalDao.deleteById(id);
batchDeleteColumnRelatesInfo(id); batchDeleteJournalRelatesInfo(id);
return Result.success(); return Result.success();
} }
} }

@ -43,15 +43,15 @@ import java.util.stream.Collectors;
public class CMSSongService { public class CMSSongService {
@Autowired @Autowired
private CMSSongDao songDao; private SongInfoDao songDao;
@Autowired @Autowired
private IdWorker idWorker; private IdWorker idWorker;
@Autowired @Autowired
private SongTagDao songTagDao; private SongTagDao songTagDao;
@Autowired @Autowired
private ColumnSongDao columnSongDao; private JournalSongDao journalSongDao;
@Autowired @Autowired
private ColumnDao columnDao; private JournalDao journalDao;
@Autowired @Autowired
private TagDao tagDao; private TagDao tagDao;
@ -64,25 +64,25 @@ public class CMSSongService {
* @param size * @param size
* @return * @return
*/ */
public Result search(SongQueryModel param, int page, int size) { public Result<PageResult<SongVO>> search(SongQueryModel param, int page, int size) {
List<SongVO> result = new ArrayList<>(); List<SongVO> result = new ArrayList<>();
// Sort sort = new Sort(Sort.Direction.DESC, "create_time"); // Sort sort = new Sort(Sort.Direction.DESC, "create_time");
// PageRequest pageRequest = PageRequest.of(page - 1, size, sort); // PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
PageRequest pageRequest = PageRequest.of(page - 1, size); PageRequest pageRequest = PageRequest.of(page - 1, size);
Page<CMSSong> songPage; Page<SongInfo> songPage;
if (!Objects.isNull(param)) { if (!Objects.isNull(param)) {
Specification<CMSSong> columnSpecification = buildSearchSpecification(param); Specification<SongInfo> songSpecification = buildSearchSpecification(param);
songPage = songDao.findAll(columnSpecification, pageRequest); songPage = songDao.findAll(songSpecification, pageRequest);
} else { } else {
songPage = songDao.findAll(pageRequest); songPage = songDao.findAll(pageRequest);
} }
long totalElements = songPage.getTotalElements(); long totalElements = songPage.getTotalElements();
List<CMSSong> content = songPage.getContent(); List<SongInfo> content = songPage.getContent();
if (!CollectionUtils.isEmpty(content)) { if (!CollectionUtils.isEmpty(content)) {
List<String> ids = content.stream().map(CMSSong::getId).collect(Collectors.toList()); List<String> ids = content.stream().map(SongInfo::getId).collect(Collectors.toList());
Map<String, List<String>> songColumnMap = buildSongColumnInfo(ids); Map<String, List<String>> songJournalMap = buildSongJournalInfo(ids);
Map<String, List<String>> songTagMap = buildSongTagInfo(ids); Map<String, List<String>> songTagMap = buildSongTagInfo(ids);
for (CMSSong item : content) { for (SongInfo item : content) {
SongVO response = new SongVO(); SongVO response = new SongVO();
String id = item.getId(); String id = item.getId();
response.setId(id); response.setId(id);
@ -93,7 +93,7 @@ public class CMSSongService {
response.setPicture(item.getPicture()); response.setPicture(item.getPicture());
response.setSize(CommonUtil.formatSongSize(item.getSize())); response.setSize(CommonUtil.formatSongSize(item.getSize()));
response.setDuration(CommonUtil.formatSongDuration(item.getDuration())); response.setDuration(CommonUtil.formatSongDuration(item.getDuration()));
response.setColumn(songColumnMap.get(id)); response.setJournal(songJournalMap.get(id));
response.setUpdateTime(df.format(item.getUpdateTime())); response.setUpdateTime(df.format(item.getUpdateTime()));
response.setState(item.getState()); response.setState(item.getState());
response.setUserId(item.getUserId()); response.setUserId(item.getUserId());
@ -109,8 +109,8 @@ public class CMSSongService {
* @param param * @param param
* @return * @return
*/ */
private Specification<CMSSong> buildSearchSpecification(SongQueryModel param) { private Specification<SongInfo> buildSearchSpecification(SongQueryModel param) {
return (Root<CMSSong> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> { return (Root<SongInfo> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
List<Predicate> predicateList = new ArrayList<Predicate>(); List<Predicate> predicateList = new ArrayList<Predicate>();
if(StringUtils.isNotBlank(param.getUserId())) { if(StringUtils.isNotBlank(param.getUserId())) {
predicateList.add(builder.equal(root.get("user_id"), param.getUserId())); predicateList.add(builder.equal(root.get("user_id"), param.getUserId()));
@ -131,25 +131,25 @@ public class CMSSongService {
}; };
} }
private Map<String, List<String>> buildSongColumnInfo(List<String> ids) { private Map<String, List<String>> buildSongJournalInfo(List<String> ids) {
Map<String, List<String>> result = new HashMap<>(); Map<String, List<String>> result = new HashMap<>();
List<ColumnSong> bySongId = columnSongDao.findBySongId(ids); List<JournalSong> bySongId = journalSongDao.findBySongId(ids);
if (!CollectionUtils.isEmpty(bySongId)) { if (!CollectionUtils.isEmpty(bySongId)) {
Set<String> idSet = bySongId.stream().map(ColumnSong::getColumnId).collect(Collectors.toSet()); Set<String> idSet = bySongId.stream().map(JournalSong::getJournalId).collect(Collectors.toSet());
List<Column> columnList = columnDao.findByIdIn(idSet); List<Journal> journalList = journalDao.findByIdIn(idSet);
Map<String, Column> idColumnMap = columnList.stream().collect(Collectors.toMap(Column::getId, obj -> obj)); Map<String, Journal> idJournalMap = journalList.stream().collect(Collectors.toMap(Journal::getId, obj -> obj));
for (ColumnSong item : bySongId) { for (JournalSong item : bySongId) {
String songId = item.getSongId(); String songId = item.getSongId();
String columnId = item.getColumnId(); String journalId = item.getJournalId();
List<String> list; List<String> list;
if (result.keySet().contains(songId)) { if (result.keySet().contains(songId)) {
list = result.get(songId); list = result.get(songId);
} else { } else {
list = new ArrayList<>(); list = new ArrayList<>();
} }
if (idColumnMap.keySet().contains(columnId)) { if (idJournalMap.keySet().contains(journalId)) {
Column column = idColumnMap.get(columnId); Journal journal = idJournalMap.get(journalId);
list.add(column.getNumber() + " " + column.getName()); list.add(journal.getNumber() + " " + journal.getName());
} }
result.put(songId, list); result.put(songId, list);
} }
@ -193,7 +193,7 @@ public class CMSSongService {
public Result add(SongAddModel param, MultipartFile imageFile, MultipartFile songFile) { public Result add(SongAddModel param, MultipartFile imageFile, MultipartFile songFile) {
String imagePath= UploadUtil.upload(imageFile, UploadUtil.IMAGE_DIR); String imagePath= UploadUtil.upload(imageFile, UploadUtil.IMAGE_DIR);
String songPath = UploadUtil.upload(songFile, UploadUtil.SONG_DIR); String songPath = UploadUtil.upload(songFile, UploadUtil.SONG_DIR);
CMSSong song = new CMSSong(); SongInfo song = new SongInfo();
String id = String.valueOf(idWorker.nextId()); String id = String.valueOf(idWorker.nextId());
song.setId(id); song.setId(id);
song.setName(param.getName()); song.setName(param.getName());
@ -256,8 +256,8 @@ public class CMSSongService {
* @param id * @param id
* @return * @return
*/ */
public Result findOne(String id) { public Result<SongVO> findOne(String id) {
CMSSong song = songDao.findById(id).get(); SongInfo song = songDao.findById(id).get();
SongVO response = new SongVO(); SongVO response = new SongVO();
response.setId(song.getId()); response.setId(song.getId());
response.setName(song.getName()); response.setName(song.getName());
@ -278,8 +278,8 @@ public class CMSSongService {
* @return * @return
*/ */
public Result update(String id, SongAddModel param, MultipartFile imageFile, MultipartFile songFile) { public Result update(String id, SongAddModel param, MultipartFile imageFile, MultipartFile songFile) {
CMSSong oldSong = songDao.findById(id).get(); SongInfo oldSong = songDao.findById(id).get();
CMSSong song = new CMSSong(); SongInfo song = new SongInfo();
song.setId(id); song.setId(id);
song.setName(param.getName()); song.setName(param.getName());
song.setArtist(param.getAlbum()); song.setArtist(param.getAlbum());
@ -312,6 +312,9 @@ public class CMSSongService {
*/ */
public Result updateSongState(String id, String state) { public Result updateSongState(String id, String state) {
songDao.updateSongState(id, state); songDao.updateSongState(id, state);
if ("0".equals(state)) {
journalSongDao.deleteBySongId(id);
}
return Result.success("更新成功"); return Result.success("更新成功");
} }
@ -333,7 +336,7 @@ public class CMSSongService {
*/ */
public Result batchUpload(List<MultipartFile> files) { public Result batchUpload(List<MultipartFile> files) {
for (MultipartFile file : files) { for (MultipartFile file : files) {
CMSSong song = new CMSSong(); SongInfo song = new SongInfo();
String id = String.valueOf(idWorker.nextId()); String id = String.valueOf(idWorker.nextId());
song.setId(id); song.setId(id);
String songPath = UploadUtil.upload(file, UploadUtil.SONG_DIR); String songPath = UploadUtil.upload(file, UploadUtil.SONG_DIR);
@ -351,8 +354,8 @@ public class CMSSongService {
* @return * @return
*/ */
public Result deleteById(String id) { public Result deleteById(String id) {
List<String> columnsBySongId = columnSongDao.findColumnsBySongId(id); List<String> journalsBySongId = journalSongDao.findJournalBySongId(id);
if (CollectionUtils.isEmpty(columnsBySongId)) { if (CollectionUtils.isEmpty(journalsBySongId)) {
return Result.success("该歌曲被期刊使用,删除失败"); return Result.success("该歌曲被期刊使用,删除失败");
} else { } else {
songDao.deleteById(id); songDao.deleteById(id);

Loading…
Cancel
Save