音乐期刊内容更新

main
JH 10 months ago
parent 4af43dd130
commit 1113b70a0f

@ -1,12 +1,9 @@
package com.luoo.music; package com.luoo.music;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.slf4j.Logger; 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;
@ -14,10 +11,13 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import util.IdWorker; import util.IdWorker;
import util.JwtUtil; import util.JwtUtil;
import java.net.InetAddress;
import java.net.UnknownHostException;
@SpringBootApplication @SpringBootApplication
@EnableEurekaClient @EnableEurekaClient
@EnableDiscoveryClient @EnableDiscoveryClient

@ -3,6 +3,7 @@ package com.luoo.music.controller;
import api.PageResult; import api.PageResult;
import api.Result; import api.Result;
import com.luoo.music.request.cms.JournalAddModel; import com.luoo.music.request.cms.JournalAddModel;
import com.luoo.music.request.cms.JournalPublishReq;
import com.luoo.music.request.cms.JournalQueryModel; import com.luoo.music.request.cms.JournalQueryModel;
import com.luoo.music.response.cms.JournalVO; import com.luoo.music.response.cms.JournalVO;
import com.luoo.music.service.CMSJournalService; import com.luoo.music.service.CMSJournalService;
@ -14,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
/** /**
* @author locust * @author locust
*/ */
@ -39,7 +42,7 @@ public class CMSJournalController {
@ApiOperation(value = "新增期刊", notes = "新增期刊") @ApiOperation(value = "新增期刊", notes = "新增期刊")
@RequestMapping(value = "/add", method = RequestMethod.POST) @RequestMapping(value = "/add", method = RequestMethod.POST)
public Result add(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token, public Result add(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token,
@ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel addModel){ @ApiParam(value = "期刊信息", required = true) @Valid @RequestBody JournalAddModel addModel){
return journalService.add(token, addModel); return journalService.add(token, addModel);
} }
@ -59,16 +62,15 @@ public class CMSJournalController {
@ApiOperation(value = "发布期刊", notes = "发布期刊") @ApiOperation(value = "发布期刊", notes = "发布期刊")
@RequestMapping(value="/publish/{id}",method= RequestMethod.PUT) @RequestMapping(value="/publish/{id}",method= RequestMethod.PUT)
public Result publish(@PathVariable String id, public Result publish(@ApiParam(value = "期刊ID", required = true) @PathVariable String id,
@ApiParam(value = "是否定时发布0:否1:是", required = true) @RequestParam("isScheduled") String isScheduled, @ApiParam(value = "期刊发布请求对象", required = true) @RequestBody JournalPublishReq queryModel){
@ApiParam(value = "定时发布时间") @RequestParam("state") String pubTime){ return journalService.publish(id, queryModel);
return journalService.publish(id, isScheduled, 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) @RequestBody String state){
return journalService.updateJournalState(id, state); return journalService.updateJournalState(id, state);
} }
@ -78,7 +80,7 @@ public class CMSJournalController {
return journalService.deleteById(id); return journalService.deleteById(id);
} }
@ApiOperation(value = "上传期刊封面", notes = "上传期刊封面") @ApiOperation(value = "上传封面", notes = "上传封面")
@RequestMapping(value = "/upload/image", method = RequestMethod.POST) @RequestMapping(value = "/upload/image", method = RequestMethod.POST)
public Result batchUpload(@ApiParam(value = "封面图片文件", required = true) @RequestParam("file") MultipartFile file) { public Result batchUpload(@ApiParam(value = "封面图片文件", required = true) @RequestParam("file") MultipartFile file) {
return s3Service.upload(file, Boolean.FALSE); return s3Service.upload(file, Boolean.FALSE);

@ -60,7 +60,7 @@ public class CMSSongController {
@ApiOperation(value = "更新歌曲启停状态", notes = "更新歌曲启停状态") @ApiOperation(value = "更新歌曲启停状态", notes = "更新歌曲启停状态")
@RequestMapping(value="/update/state/{id}",method= RequestMethod.PUT) @RequestMapping(value="/update/state/{id}",method= RequestMethod.PUT)
public Result updateSongState(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id, public Result updateSongState(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id,
@ApiParam(value = "歌曲状态0:停用1:启用", required = true) @RequestParam("state") String state){ @ApiParam(value = "歌曲状态0:停用1:启用", required = true) @RequestBody String state){
return songService.updateSongState(id, state); return songService.updateSongState(id, state);
} }
@ -73,8 +73,8 @@ public class CMSSongController {
@ApiOperation(value = "更新歌曲歌词", notes = "更新歌曲歌词") @ApiOperation(value = "更新歌曲歌词", notes = "更新歌曲歌词")
@RequestMapping(value="/update/lyric/{id}",method= RequestMethod.PUT) @RequestMapping(value="/update/lyric/{id}",method= RequestMethod.PUT)
public Result updateSongLyric(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id, public Result updateSongLyric(@ApiParam(value = "歌曲ID", required = true) @PathVariable String id,
@ApiParam(value = "歌曲歌词信息", required = true) @RequestBody SongAddModel updateModel){ @ApiParam(value = "歌曲歌词信息", required = true) @RequestBody String lyric){
return songService.updateSongLyric(id, updateModel.getLyric()); return songService.updateSongLyric(id, lyric);
} }

@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; 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;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -16,23 +17,26 @@ import java.util.Set;
*/ */
public interface JournalDao extends JpaRepository<Journal,String>,JpaSpecificationExecutor<Journal>{ public interface JournalDao extends JpaRepository<Journal,String>,JpaSpecificationExecutor<Journal>{
List<Journal> findByJournalNo(String journalNo); List<Journal> findByJournalNo(String journalNo);
List<Journal> findByJournalNoIn(Set<String> journalNos); List<Journal> findByJournalNoIn(Set<String> journalNos);
List<Journal> findByIdIn(Set<String> ids); List<Journal> findByIdIn(Set<String> ids);
@Modifying @Modifying
@Transactional
@Query("UPDATE Journal j SET j.state = '1', j.pubTime = :pubTime WHERE j.id = :id") @Query("UPDATE Journal j SET j.state = '1', j.pubTime = :pubTime WHERE j.id = :id")
int updatePubById(@Param("id") String id, int updatePubById(@Param("id") String id,
@Param("pubTime") LocalDateTime pubTime); @Param("pubTime") LocalDateTime pubTime);
@Modifying @Modifying
@Transactional
@Query("UPDATE Journal j SET j.isScheduled = '1', j.pubTime = :pubTime WHERE j.id = :id") @Query("UPDATE Journal j SET j.isScheduled = '1', j.pubTime = :pubTime WHERE j.id = :id")
int updateScheduledPubById(@Param("id") String id, int updateScheduledPubById(@Param("id") String id,
@Param("pubTime") LocalDateTime pubTime); @Param("pubTime") LocalDateTime pubTime);
@Modifying @Modifying
@Transactional
@Query("UPDATE Journal j SET j.state = :state WHERE j.id = :id") @Query("UPDATE Journal j SET j.state = :state WHERE j.id = :id")
int updateJournalState(@Param("id") String id, @Param("state") String state); int updateJournalState(@Param("id") String id, @Param("state") String state);
} }

@ -1,27 +1,29 @@
package com.luoo.music.dao; package com.luoo.music.dao;
import com.luoo.music.pojo.JournalSong; 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.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.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;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author locust * @author locust
*/ */
public interface JournalSongDao extends JpaRepository<JournalSong,String>, JpaSpecificationExecutor<JournalSong> { public interface JournalSongDao extends JpaRepository<JournalSong,String>, JpaSpecificationExecutor<JournalSong> {
@Query("SELECT js.journalNo, COUNT(js) AS songCount FROM JournalSong js WHERE js.journalNo IN :journalNos GROUP BY js.journalNo") @Query("SELECT js.journalNo AS journalNo, COUNT(js) AS songCount FROM JournalSong js WHERE js.journalNo IN :journalNos GROUP BY js.journalNo")
List<JournalSongCount> findSongCountByJournalNos(@Param("journalNos") List<String> journalNos); List<Map<String, Long>> findSongCountByJournalNos(@Param("journalNos") List<String> journalNos);
@Query("SELECT js FROM JournalSong js WHERE js.journalNo = :journalNo ORDER BY js.songNo") @Query("SELECT js FROM JournalSong js WHERE js.journalNo = :journalNo ORDER BY js.songNo")
List<JournalSong> findByJournalNo(@Param("journalNo") String journalNo); List<JournalSong> findByJournalNo(@Param("journalNo") String journalNo);
@Modifying @Modifying
@Transactional
@Query("DELETE FROM JournalSong js WHERE js.journalNo = :journalNo") @Query("DELETE FROM JournalSong js WHERE js.journalNo = :journalNo")
int deleteByJournalNo(@Param("journalNo") String journalNo); int deleteByJournalNo(@Param("journalNo") String journalNo);
@ -35,6 +37,7 @@ public interface JournalSongDao extends JpaRepository<JournalSong,String>, JpaSp
List<JournalSong> findBySongId(@Param("songId") String songId); List<JournalSong> findBySongId(@Param("songId") String songId);
@Modifying @Modifying
@Transactional
@Query("DELETE FROM JournalSong js WHERE js.songId = :songId") @Query("DELETE FROM JournalSong js WHERE js.songId = :songId")
int deleteBySongId(@Param("songId") String songId); int deleteBySongId(@Param("songId") String songId);
} }

@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; 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;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@ -24,6 +25,7 @@ public interface JournalTagDao extends JpaRepository<JournalTag,String>, JpaSpec
List<String> findTagsByJournalId(@Param("journalId") String journalId); List<String> findTagsByJournalId(@Param("journalId") String journalId);
@Modifying @Modifying
@Transactional
@Query("DELETE FROM JournalTag jt WHERE jt.journalId = :journalId") @Query("DELETE FROM JournalTag jt WHERE jt.journalId = :journalId")
int deleteByJournalId(@Param("journalId") String journalId); int deleteByJournalId(@Param("journalId") String journalId);
} }

@ -6,9 +6,9 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; 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;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author locust * @author locust
@ -16,10 +16,12 @@ import java.util.Set;
public interface SongInfoDao extends JpaRepository<SongInfo,String>, JpaSpecificationExecutor<SongInfo> { public interface SongInfoDao extends JpaRepository<SongInfo,String>, JpaSpecificationExecutor<SongInfo> {
@Modifying @Modifying
@Transactional
@Query("UPDATE SongInfo s SET s.state = :state WHERE s.id = :id") @Query("UPDATE SongInfo s SET s.state = :state WHERE s.id = :id")
int updateSongState(@Param("id") String id, @Param("state") String state); int updateSongState(@Param("id") String id, @Param("state") String state);
@Modifying @Modifying
@Transactional
@Query("UPDATE SongInfo s SET s.lyric = :lyric WHERE s.id = :id") @Query("UPDATE SongInfo s SET s.lyric = :lyric WHERE s.id = :id")
int updateSongLyric(@Param("id") String id, @Param("lyric") String lyric); int updateSongLyric(@Param("id") String id, @Param("lyric") String lyric);

@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying; 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;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@ -14,13 +15,14 @@ import java.util.List;
*/ */
public interface SongTagDao extends JpaRepository<SongTag,String>, JpaSpecificationExecutor<SongTag> { public interface SongTagDao extends JpaRepository<SongTag,String>, JpaSpecificationExecutor<SongTag> {
@Query("SELECT st.tagId FROM SongTag st WHERE st.songId = :id") @Query("SELECT st.tagId FROM SongTag st WHERE st.songId = :songId")
List<String> findTagsBySongId(@Param("id") String id); List<String> findTagIdsBySongId(@Param("songId") String songId);
@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 :songIds ORDER BY st.id ")
List<SongTag> findBySongId(@Param("ids") List<String> ids); List<SongTag> findBySongIds(@Param("songIds") List<String> songIds);
@Modifying @Modifying
@Query("DELETE FROM SongTag st WHERE st.songId = :id") @Transactional
int deleteBySongId(@Param("id") String id); @Query("DELETE FROM SongTag st WHERE st.songId = :songId")
int deleteBySongId(@Param("songId") String songId);
} }

@ -60,11 +60,11 @@ public class Journal implements Serializable{
/** /**
* *
*/ */
private Integer visits; private Long visits;
/** /**
* *
*/ */
private Integer comment; private Long comment;
/** /**
* *
*/ */

@ -1,12 +0,0 @@
package com.luoo.music.pojo;
/**
*
* @author locust
*/
public interface JournalSongCount {
String getJournalNo();
Long getSongCount();
}

@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.util.List; import java.util.List;
/** /**
@ -13,9 +14,11 @@ import java.util.List;
@ApiModel(value = "增加或修改期刊对象") @ApiModel(value = "增加或修改期刊对象")
public class JournalAddModel { public class JournalAddModel {
@NotBlank(message = "期刊的期刊必填")
@ApiModelProperty(value = "期刊编号") @ApiModelProperty(value = "期刊编号")
private String journalNo; private String journalNo;
@NotBlank(message = "期刊的标题必填")
@ApiModelProperty(value = "期刊标题") @ApiModelProperty(value = "期刊标题")
private String title; private String title;
@ -25,12 +28,14 @@ public class JournalAddModel {
@ApiModelProperty(value = "发布人ID") @ApiModelProperty(value = "发布人ID")
private String userId; private String userId;
@NotBlank(message = "期刊的封面必填")
@ApiModelProperty(value = "期刊封面路径") @ApiModelProperty(value = "期刊封面路径")
private String image; private String image;
@ApiModelProperty(value = "关联歌曲音乐ID") @ApiModelProperty(value = "关联歌曲音乐ID")
private List<String> songs; private List<String> songs;
@NotBlank(message = "期刊的文案必填")
@ApiModelProperty(value = "期刊内容") @ApiModelProperty(value = "期刊内容")
private String content; private String content;
} }

@ -0,0 +1,19 @@
package com.luoo.music.request.cms;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author locust
*/
@Data
@ApiModel(value = "期刊发布请求对象")
public class JournalPublishReq {
@ApiModelProperty(value = "是否定时发布0:否1:是")
private String isScheduled;
@ApiModelProperty(value = "定时发布时间yyyy-MM-dd HH:mm:ss")
private String pubTime;
}

@ -28,6 +28,6 @@ public class JournalQueryModel {
@ApiModelProperty(value = "结束时间") @ApiModelProperty(value = "结束时间")
private String end; private String end;
@ApiModelProperty(value = "标签ID") @ApiModelProperty(value = "标签ID, 各种类型的标签")
private List<String> tags; private List<String> tags;
} }

@ -42,4 +42,7 @@ public class SongAddModel {
@ApiModelProperty(value = "歌曲时长") @ApiModelProperty(value = "歌曲时长")
private Long duration; private Long duration;
@ApiModelProperty(value = "歌曲状态0:停用1:启用")
private String state;
} }

@ -26,17 +26,17 @@ public class JournalVO {
@ApiModelProperty(value = "期刊封面") @ApiModelProperty(value = "期刊封面")
private String image; private String image;
@ApiModelProperty(value = "期刊标签") @ApiModelProperty(value = "期刊标签, 标签ID的一个集合")
private List<String> tag; private List<String> tag;
@ApiModelProperty(value = "歌曲数") @ApiModelProperty(value = "歌曲数")
private long songCount; private Long songCount;
@ApiModelProperty(value = "评论数") @ApiModelProperty(value = "评论数")
private long comment; private Long comment;
@ApiModelProperty(value = "播放数") @ApiModelProperty(value = "播放数")
private long visits; private Long visits;
@ApiModelProperty(value = "发布作者id") @ApiModelProperty(value = "发布作者id")
private String userId; private String userId;

@ -5,13 +5,14 @@ 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.JournalAddModel; import com.luoo.music.request.cms.JournalAddModel;
import com.luoo.music.request.cms.JournalPublishReq;
import com.luoo.music.request.cms.JournalQueryModel; import com.luoo.music.request.cms.JournalQueryModel;
import com.luoo.music.response.cms.JournalVO; 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.Constants; import com.luoo.music.util.Constants;
import com.luoo.music.util.UploadUtil;
import dto.UserLoginDto; import dto.UserLoginDto;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
@ -26,9 +27,7 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import java.io.File;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -55,8 +54,6 @@ public class CMSJournalService {
@Autowired @Autowired
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/** /**
* + * +
@ -93,15 +90,15 @@ public class CMSJournalService {
response.setJournalNo(Constants.JOURNAL_NO_PREF + item.getJournalNo()); response.setJournalNo(Constants.JOURNAL_NO_PREF + item.getJournalNo());
response.setTitle(item.getTitle()); response.setTitle(item.getTitle());
response.setImage(item.getImage()); response.setImage(item.getImage());
response.setCreateTime(item.getCreateTime().format(formatter)); response.setCreateTime(item.getCreateTime().format(Constants.formatter));
response.setState(item.getState()); response.setState(item.getState());
response.setIsPublish(item.getIsPublish()); response.setIsPublish(item.getIsPublish());
if (!Objects.isNull(item.getPubTime())) { if (!Objects.isNull(item.getPubTime())) {
response.setPubTime(item.getPubTime().format(formatter)); response.setPubTime(item.getPubTime().format(Constants.formatter));
} }
response.setUserId(item.getUserId()); response.setUserId(item.getUserId());
response.setUserName(item.getUserName()); response.setUserName(item.getUserName());
response.setSongCount(songCountMap.get(item.getId())); response.setSongCount(songCountMap.get(item.getJournalNo()));
response.setTag(journalTagMap.get(item.getId())); response.setTag(journalTagMap.get(item.getId()));
response.setVisits(item.getVisits()); response.setVisits(item.getVisits());
response.setComment(item.getComment()); response.setComment(item.getComment());
@ -157,8 +154,11 @@ public class CMSJournalService {
private Map<String, Long> songCountInfo(List<String> journalNos) { private Map<String, Long> songCountInfo(List<String> journalNos) {
Map<String, Long> songCountMap = new HashMap<>(); Map<String, Long> songCountMap = new HashMap<>();
if (!CollectionUtils.isEmpty(journalNos)) { if (!CollectionUtils.isEmpty(journalNos)) {
List<JournalSongCount> journalSongCountList = journalSongDao.findSongCountByJournalNos(journalNos); List<Map<String, Long>> journalSongCountList = journalSongDao.findSongCountByJournalNos(journalNos);
songCountMap = journalSongCountList.stream().collect(Collectors.toMap(JournalSongCount::getJournalNo, JournalSongCount::getSongCount)); songCountMap = journalSongCountList.stream()
.collect(Collectors.toMap(
map -> String.valueOf(map.get("journalNo")),
map -> Long.valueOf(String.valueOf(map.get("songCount")))));
} }
return songCountMap; return songCountMap;
} }
@ -201,7 +201,8 @@ public class CMSJournalService {
if (byJournalNo.size() > 0) { if (byJournalNo.size() > 0) {
return Result.failed("保存失败,期刊编号已存在"); return Result.failed("保存失败,期刊编号已存在");
} }
String image = moveJournalImage(param); String srcKey = param.getImage().substring(param.getImage().indexOf(Constants.TEMP_KEY_PREFIX));
String image = moveJournalImage(srcKey, param);
if (StringUtils.isNotBlank(image)) { if (StringUtils.isNotBlank(image)) {
Journal journal = buildJournal(null, param, token); Journal journal = buildJournal(null, param, token);
String id = String.valueOf(idWorker.nextId()); String id = String.valueOf(idWorker.nextId());
@ -220,12 +221,11 @@ public class CMSJournalService {
* @param param * @param param
* @return * @return
*/ */
private String moveJournalImage(JournalAddModel param) { private String moveJournalImage(String srcKey, JournalAddModel param) {
String image = param.getImage(); String image = param.getImage();
String srcKey = image.substring(image.indexOf(Constants.TEMP_KEY_PREFIX));
String suffix = image.substring(image.lastIndexOf(Constants.DOT)); String suffix = image.substring(image.lastIndexOf(Constants.DOT));
String destKeySuffix = String.format("%05d/00%s", param.getJournalNo(), suffix); String destKeySuffix = String.format("%05d/00%s", Integer.parseInt(param.getJournalNo()), suffix);
String destKey = Constants.IMAGE_KEY_PREFIX + destKeySuffix; String destKey = Constants.IMAGE_KEY_PREFIX + destKeySuffix;
int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey); int copy = s3Service.copy(Constants.BUCKET, srcKey, destKey);
if (copy > 0) { if (copy > 0) {
return destKeySuffix; return destKeySuffix;
@ -248,10 +248,12 @@ public class CMSJournalService {
journal.setJournalNo(param.getJournalNo()); journal.setJournalNo(param.getJournalNo());
journal.setTitle(param.getTitle()); journal.setTitle(param.getTitle());
journal.setContent(param.getContent()); journal.setContent(param.getContent());
UserLoginDto user = jwtUtil.getUserLoginDto(token); if (StringUtils.isNotBlank(token)) {
journal.setUserId(user.getUserId()); UserLoginDto user = jwtUtil.getUserLoginDto(token);
journal.setUserName(user.getNickName()); journal.setUserId(user.getUserId());
journal.setUserType(user.getRoles()); journal.setUserName(user.getNickName());
journal.setUserType(user.getRoles());
}
return journal; return journal;
} }
@ -358,16 +360,28 @@ public class CMSJournalService {
if (byJournalNo.size() > 0) { if (byJournalNo.size() > 0) {
return Result.failed("更新失败,期刊编号已存在"); return Result.failed("更新失败,期刊编号已存在");
} }
Journal journal = buildJournal(id, param, token);
Journal oldJournal = journalDao.findById(id).get(); Journal oldJournal = journalDao.findById(id).get();
String image = null; Journal journal = buildJournal(id, param, token);
String srcKey = null;
if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) { if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
image = moveJournalImage(param); srcKey = param.getImage().substring(param.getImage().indexOf(Constants.TEMP_KEY_PREFIX));
} else {
if (!oldJournal.getJournalNo().equals(param.getJournalNo())) {
srcKey = param.getImage().substring(param.getImage().indexOf(Constants.IMAGE_KEY_PREFIX));
}
}
if (StringUtils.isNotBlank(srcKey)) {
String image = moveJournalImage(srcKey, param);
if (StringUtils.isBlank(image)) { if (StringUtils.isBlank(image)) {
Result.failed("更新失败"); Result.failed("更新失败");
} }
journal.setImage(image);
} }
journal.setImage(image); journal.setState(oldJournal.getState());
journal.setIsPublish(oldJournal.getIsPublish());
journal.setIsScheduled(oldJournal.getIsScheduled());
journal.setVisits(oldJournal.getVisits());
journal.setComment(oldJournal.getComment());
journalDao.save(journal); journalDao.save(journal);
batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo()); batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo());
batchSaveJournalRelatesInfo(id, param); batchSaveJournalRelatesInfo(id, param);
@ -387,19 +401,21 @@ public class CMSJournalService {
/** /**
* *
* @param id * @param id
* @param scheduled * @param queryModel
* @param pubTimeStr
* @return * @return
*/ */
public Result publish(String id, String scheduled, String pubTimeStr) { public Result publish(String id, JournalPublishReq queryModel) {
String scheduled = queryModel.getIsScheduled();
String pubTimeStr = queryModel.getPubTime();
LocalDateTime pubTime = LocalDateTime.now(); LocalDateTime pubTime = LocalDateTime.now();
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, Constants.formatter);
journalDao.updateScheduledPubById(id, pubTime); journalDao.updateScheduledPubById(id, pubTime);
} }
} else {
journalDao.updatePubById(id, pubTime);
} }
journalDao.updatePubById(id, pubTime);
return Result.success(); return Result.success();
} }
@ -411,7 +427,7 @@ public class CMSJournalService {
*/ */
public Result updateJournalState(String id, String state) { public Result updateJournalState(String id, String state) {
journalDao.updateJournalState(id, state); journalDao.updateJournalState(id, state);
return Result.success("更新成功"); return Result.success();
} }
/** /**

@ -25,11 +25,11 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import java.io.*; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -57,8 +57,6 @@ public class CMSSongService {
@Autowired @Autowired
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
private DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
/** /**
* + * +
* @param param * @param param
@ -96,7 +94,7 @@ public class CMSSongService {
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.setJournal(songJournalMap.get(id)); response.setJournal(songJournalMap.get(id));
response.setUpdateTime(df.format(item.getUpdateTime())); response.setUpdateTime(item.getUpdateTime().format(Constants.formatter));
response.setState(item.getState()); response.setState(item.getState());
response.setUserId(item.getUserId()); response.setUserId(item.getUserId());
response.setUrl(item.getUrl()); response.setUrl(item.getUrl());
@ -166,7 +164,7 @@ public class CMSSongService {
private Map<String, List<String>> buildSongTagInfo(List<String> ids) { private Map<String, List<String>> buildSongTagInfo(List<String> ids) {
Map<String, List<String>> result = new HashMap<>(); Map<String, List<String>> result = new HashMap<>();
List<SongTag> bySongId = songTagDao.findBySongId(ids); List<SongTag> bySongId = songTagDao.findBySongIds(ids);
if (!CollectionUtils.isEmpty(bySongId)) { if (!CollectionUtils.isEmpty(bySongId)) {
Set<String> idSet = bySongId.stream().map(SongTag::getTagId).collect(Collectors.toSet()); Set<String> idSet = bySongId.stream().map(SongTag::getTagId).collect(Collectors.toSet());
List<Tag> tagList = tagDao.findByIdIn(idSet); List<Tag> tagList = tagDao.findByIdIn(idSet);
@ -217,8 +215,8 @@ public class CMSSongService {
song.setUrl(url); song.setUrl(url);
song.setImage(image); song.setImage(image);
songDao.save(song); songDao.save(song);
batchSaveSongRelatesInfo(id, param); batchSaveSongTagInfo(id, param);
return Result.success("新增成功"); return Result.success();
} }
private SongInfo buildSong(String id, SongAddModel param, String token) { private SongInfo buildSong(String id, SongAddModel param, String token) {
@ -231,10 +229,12 @@ public class CMSSongService {
song.setAlbum(param.getAlbum()); song.setAlbum(param.getAlbum());
song.setSize(param.getSize()); song.setSize(param.getSize());
song.setDuration(param.getDuration()); song.setDuration(param.getDuration());
UserLoginDto user = jwtUtil.getUserLoginDto(token); if (StringUtils.isNotBlank(token)) {
song.setUserId(user.getUserId()); UserLoginDto user = jwtUtil.getUserLoginDto(token);
song.setUserName(user.getNickName()); song.setUserId(user.getUserId());
song.setUserType(user.getRoles()); song.setUserName(user.getNickName());
song.setUserType(user.getRoles());
}
return song; return song;
} }
@ -269,7 +269,7 @@ public class CMSSongService {
* @param id * @param id
* @param param * @param param
*/ */
private void batchSaveSongRelatesInfo(String id, SongAddModel param) { private void batchSaveSongTagInfo(String id, SongAddModel param) {
if (!CollectionUtils.isEmpty(param.getTags())) { if (!CollectionUtils.isEmpty(param.getTags())) {
List<SongTag> songTagList = new ArrayList<>(); List<SongTag> songTagList = new ArrayList<>();
for (String item : param.getTags()) { for (String item : param.getTags()) {
@ -283,6 +283,15 @@ public class CMSSongService {
} }
} }
/**
*
* @param id
* @param param
*/
private void batchSaveSongJournalInfo(String id, SongAddModel param) {
// TODO
}
/** /**
* *
* @param id * @param id
@ -295,7 +304,7 @@ public class CMSSongService {
response.setName(song.getName()); response.setName(song.getName());
response.setArtist(song.getArtist()); response.setArtist(song.getArtist());
response.setAlbum(song.getAlbum()); response.setAlbum(song.getAlbum());
response.setTags(songTagDao.findTagsBySongId(id)); response.setTags(songTagDao.findTagIdsBySongId(id));
response.setUrl(Constants.SONG_RESOURCE_PREFIX + song.getUrl()); response.setUrl(Constants.SONG_RESOURCE_PREFIX + song.getUrl());
response.setImage(Constants.SONG_RESOURCE_PREFIX + song.getImage()); response.setImage(Constants.SONG_RESOURCE_PREFIX + song.getImage());
return Result.success(response); return Result.success(response);
@ -328,10 +337,12 @@ public class CMSSongService {
} }
song.setImage(image); song.setImage(image);
} }
SongInfo oldSong = songDao.findById(id).get();
song.setState(oldSong.getState());
songDao.save(song); songDao.save(song);
songTagDao.deleteBySongId(id); songTagDao.deleteBySongId(id);
batchSaveSongRelatesInfo(id, param); batchSaveSongTagInfo(id, param);
return Result.success("更新成功"); return Result.success();
} }
/** /**
@ -345,7 +356,7 @@ public class CMSSongService {
if ("0".equals(state)) { if ("0".equals(state)) {
journalSongDao.deleteBySongId(id); journalSongDao.deleteBySongId(id);
} }
return Result.success("更新成功"); return Result.success();
} }
/** /**
@ -389,7 +400,7 @@ public class CMSSongService {
s3Service.copy(Constants.BUCKET, key, destLyric); s3Service.copy(Constants.BUCKET, key, destLyric);
} }
} }
return Result.success("更新成功"); return Result.success();
} }
/** /**
@ -404,7 +415,7 @@ public class CMSSongService {
} else { } else {
songDao.deleteById(id); songDao.deleteById(id);
songTagDao.deleteBySongId(id); songTagDao.deleteBySongId(id);
return Result.success("该歌曲已被删除"); return Result.success();
} }
} }
@ -422,17 +433,17 @@ public class CMSSongService {
String keySuffix = id + "/00" + suffix; String keySuffix = id + "/00" + suffix;
String key = Constants.SONG_KEY_PREFIX + keySuffix; String key = Constants.SONG_KEY_PREFIX + keySuffix;
int upload = s3Service.upload(Constants.BUCKET, key, file); int upload = s3Service.upload(Constants.BUCKET, key, file);
if (upload > 1) { if (upload > 0) {
SongInfo song = new SongInfo(); SongInfo song = new SongInfo();
song.setId(id); song.setId(id);
song.setUrl(keySuffix); song.setUrl(keySuffix);
song.setSize(file.isEmpty() ? 0L : file.getSize()); song.setSize(file.isEmpty() ? 0L : file.getSize());
song.setDuration(CommonUtil.getSongDuration(Constants.SONG_RESOURCE_PREFIX + keySuffix)); song.setDuration(CommonUtil.getSongDuration(file));
songDao.save(song); songDao.save(song);
} }
} }
} }
return Result.success("上传成功"); return Result.success();
} }
private String readLyric(String lyricUrl) { private String readLyric(String lyricUrl) {

@ -83,7 +83,7 @@ public class S3Service {
resp.setFullUrl(Constants.RESOURCE_PREFIX + key); resp.setFullUrl(Constants.RESOURCE_PREFIX + key);
if (isSong) { if (isSong) {
resp.setSize(file.isEmpty() ? 0L : file.getSize()); resp.setSize(file.isEmpty() ? 0L : file.getSize());
resp.setDuration(CommonUtil.getSongDuration(Constants.RESOURCE_PREFIX + key)); resp.setDuration(CommonUtil.getSongDuration(file));
} }
resp.setFullUrl(Constants.RESOURCE_PREFIX + key); resp.setFullUrl(Constants.RESOURCE_PREFIX + key);
return Result.success(resp); return Result.success(resp);

@ -5,9 +5,8 @@ import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext; import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser; import org.apache.tika.parser.Parser;
import org.apache.tika.sax.BodyContentHandler; import org.apache.tika.sax.BodyContentHandler;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -18,17 +17,17 @@ public class CommonUtil {
/** /**
* *
* @param songPath * @param file
* @return * @return
*/ */
public static long getSongDuration(String songPath) { public static long getSongDuration(MultipartFile file) {
try { try {
File audioFile = new File(songPath); InputStream inputStream = file.getInputStream();
InputStream inputStream = new FileInputStream(audioFile);
Parser parser = new AutoDetectParser(); Parser parser = new AutoDetectParser();
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
BodyContentHandler handler = new BodyContentHandler(); BodyContentHandler handler = new BodyContentHandler();
parser.parse(inputStream, handler, metadata, new ParseContext()); ParseContext parseContext = new ParseContext();
parser.parse(inputStream, handler, metadata, parseContext);
String durationString = metadata.get("xmpDM:duration"); String durationString = metadata.get("xmpDM:duration");
long duration = Long.parseLong(durationString); long duration = Long.parseLong(durationString);
inputStream.close(); inputStream.close();
@ -45,8 +44,9 @@ public class CommonUtil {
* @return * @return
*/ */
public static String formatSongSize(long size){ public static String formatSongSize(long size){
DecimalFormat df = new DecimalFormat("#.00"); double fileSizeInMB = size / (1024.0 * 1024.0);
String fileSizeString = df.format((double) size / 1048576) + "MB"; DecimalFormat df = new DecimalFormat("0.##");
String fileSizeString = df.format(fileSizeInMB) + " MB";
return fileSizeString; return fileSizeString;
} }

@ -1,11 +1,17 @@
package com.luoo.music.util; package com.luoo.music.util;
import java.time.format.DateTimeFormatter;
/** /**
* @author locust * @author locust
*/ */
public class Constants { public class Constants {
public static String JOURNAL_NO_PREF = "VOL•"; // public static String JOURNAL_NO_PREF = "VOL•";
public static String JOURNAL_NO_PREF = "VOL ";
public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private String SONG_PREF = "song"; private String SONG_PREF = "song";

@ -5,4 +5,8 @@ spring:
profile: dev profile: dev
label: master label: master
uri: http://116.62.145.60:12000 uri: http://116.62.145.60:12000
# uri: http://127.0.0.1:12000 # uri: http://127.0.0.1:12000
servlet:
multipart:
max-file-size: 20MB
max-request-size: 200MB
Loading…
Cancel
Save