main
JH 10 months ago
parent dcbc48cbce
commit 7cbb2b3daf

@ -41,7 +41,7 @@ public class CMSJournalController {
@ApiOperation(value = "新增期刊", notes = "新增期刊")
@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("Authorization") String token,
@ApiParam(value = "期刊信息", required = true) @Valid @RequestBody JournalAddModel addModel){
return journalService.add(token, addModel);
}
@ -55,7 +55,7 @@ public class CMSJournalController {
@ApiOperation(value = "更新期刊", notes = "更新期刊")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Result update(@ApiParam(value = "期刊ID", required = true) @PathVariable String id,
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token,
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel updateModel){
return journalService.update(id, token, updateModel);
}

@ -38,7 +38,7 @@ public class CMSSongController {
@ApiOperation(value = "新增歌曲", notes = "新增歌曲")
@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("Authorization") String token,
@ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel addModel){
return songService.add(token, addModel);
}
@ -51,7 +51,7 @@ public class CMSSongController {
@ApiOperation(value = "更新歌曲信息", notes = "更新歌曲信息")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Result update(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Admin-Token") String token,
public Result update(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "歌曲ID", required = true) @PathVariable String id,
@ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel updateModel){
return songService.update(id, token, updateModel);
@ -92,7 +92,8 @@ public class CMSSongController {
@ApiOperation(value = "批量上传歌曲", notes = "批量上传歌曲")
@RequestMapping(value = "/batch", method = RequestMethod.POST)
public Result batchUpload(@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List<MultipartFile> files) {
return songService.batchUpload(files);
public Result batchUpload(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List<MultipartFile> files) {
return songService.batchUpload(files, token);
}
}

@ -95,7 +95,9 @@ public class CMSJournalService {
response.setJournalNo(item.getJournalNo());
response.setTitle(item.getTitle());
response.setImage(Constants.MUSIC_RESOURCE_PREFIX + item.getImage());
response.setCreateTime(item.getCreateTime().format(Constants.formatter));
if (!Objects.isNull(item.getCreateTime())) {
response.setCreateTime(item.getCreateTime().format(Constants.formatter));
}
response.setState(item.getState());
response.setIsPublish(item.getIsPublish());
if (!Objects.isNull(item.getPubTime())) {
@ -380,15 +382,19 @@ public class CMSJournalService {
if (StringUtils.isNotBlank(srcKey)) {
String image = moveJournalImage(srcKey, param);
if (StringUtils.isBlank(image)) {
Result.failed("更新失败");
return Result.failed("更新失败");
}
journal.setImage(image);
} else {
journal.setImage(oldJournal.getImage());
}
journal.setState(oldJournal.getState());
journal.setIsPublish(oldJournal.getIsPublish());
journal.setIsScheduled(oldJournal.getIsScheduled());
journal.setVisits(oldJournal.getVisits());
journal.setComment(oldJournal.getComment());
journal.setCreateTime(oldJournal.getCreateTime());
journal.setPubTime(oldJournal.getPubTime());
journalDao.save(journal);
batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo());
batchSaveJournalRelatesInfo(id, param);

@ -14,6 +14,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@ -66,9 +67,9 @@ public class CMSSongService {
*/
public Result<PageResult<SongVO>> search(SongQueryModel param, int page, int size) {
List<SongVO> result = new ArrayList<>();
// Sort sort = new Sort(Sort.Direction.DESC, "create_time");
// PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
PageRequest pageRequest = PageRequest.of(page - 1, size);
Sort sort = new Sort(Sort.Direction.DESC, "id");
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
// PageRequest pageRequest = PageRequest.of(page - 1, size);
Page<SongInfo> songPage;
if (!Objects.isNull(param)) {
Specification<SongInfo> songSpecification = buildSearchSpecification(param);
@ -90,14 +91,19 @@ public class CMSSongService {
response.setArtist(item.getArtist());
response.setAlbum(item.getAlbum());
response.setTags(songTagMap.get(id));
response.setImage(Constants.SONG_RESOURCE_PREFIX + item.getImage());
if (StringUtils.isNotBlank(item.getImage())) {
response.setImage(Constants.SONG_RESOURCE_PREFIX + item.getImage());
}
response.setSize(CommonUtil.formatSongSize(item.getSize()));
response.setDuration(CommonUtil.formatSongDuration(item.getDuration()));
response.setJournal(songJournalMap.get(id));
response.setUpdateTime(item.getUpdateTime().format(Constants.formatter));
response.setState(item.getState());
response.setUserId(item.getUserId());
response.setUrl(Constants.SONG_RESOURCE_PREFIX + item.getUrl());
response.setUserName(item.getUserName());
if (StringUtils.isNotBlank(item.getUrl())) {
response.setUrl(Constants.SONG_RESOURCE_PREFIX + item.getUrl());
}
result.add(response);
}
}
@ -228,10 +234,9 @@ public class CMSSongService {
song.setName(param.getName());
song.setArtist(param.getArtist());
song.setAlbum(param.getAlbum());
song.setSize(param.getSize());
song.setDuration(param.getDuration());
if (StringUtils.isNotBlank(token)) {
UserLoginDto user = jwtUtil.getUserLoginDto(token);
song.setLyric(param.getLyric());
UserLoginDto user = getUserInfoByToken(token);
if (!Objects.isNull(user)) {
song.setUserId(user.getUserId());
song.setUserName(user.getNickName());
song.setUserType(user.getRoles());
@ -284,15 +289,6 @@ public class CMSSongService {
}
}
/**
*
* @param id
* @param param
*/
private void batchSaveSongJournalInfo(String id, SongAddModel param) {
// TODO
}
/**
*
* @param id
@ -339,19 +335,41 @@ public class CMSSongService {
if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
image = moveSongImage(id, param);
if (StringUtils.isBlank(image)) {
Result.failed("更新失败");
return Result.failed("更新失败");
}
song.setImage(image);
} else {
song.setImage(oldSong.getImage());
}
song.setState(oldSong.getState());
song.setCreateTime(oldSong.getCreateTime());
songDao.save(song);
songTagDao.deleteBySongId(id);
batchSaveSongTagInfo(id, param);
batchUpdateJournalSongInfo(id, song);
return Result.success();
}
/**
*
* @param id
* @param song
*/
private void batchUpdateJournalSongInfo(String id, SongInfo song) {
List<JournalSong> journalSongList = journalSongDao.findBySongId(id);
if (journalSongList.size() > 0) {
for (JournalSong item : journalSongList) {
item.setName(song.getName());
item.setArtist(song.getArtist());
item.setAlbum(song.getAlbum());
item.setUrl(song.getUrl());
item.setImage(song.getImage());
}
s3Service.fromSongToMusic(journalSongList);
journalSongDao.saveAll(journalSongList);
}
}
/**
*
* @param id
@ -427,17 +445,18 @@ public class CMSSongService {
}
/**
*
*
* @param files
* @return
*/
public Result batchUpload(List<MultipartFile> files) {
for (MultipartFile file : files) {
public Result batchUpload(List<MultipartFile> files, String token) {
UserLoginDto user = getUserInfoByToken(token);
for (MultipartFile file : files)
if (!file.isEmpty()) {
String id = String.valueOf(idWorker.nextId());
String originalFilename = file.getOriginalFilename();
String suffix = originalFilename.substring(originalFilename.lastIndexOf(Constants.DOT));
String keySuffix = id + "/00" + suffix;
String keySuffix = id + "/00" + suffix;
String key = Constants.SONG_KEY_PREFIX + keySuffix;
int upload = s3Service.upload(Constants.BUCKET, key, file);
if (upload > 0) {
@ -447,13 +466,40 @@ public class CMSSongService {
song.setUrl(keySuffix);
song.setSize(file.isEmpty() ? 0L : file.getSize());
song.setDuration(CommonUtil.getSongDuration(file));
if (!Objects.isNull(user)) {
song.setUserId(user.getUserId());
song.setUserName(user.getNickName());
song.setUserType(user.getRoles());
}
songDao.save(song);
}
}
}
return Result.success();
}
/**
* token
* @param token
* @return
*/
private UserLoginDto getUserInfoByToken(String token) {
if (StringUtils.isNotBlank(token)) {
try {
UserLoginDto user = jwtUtil.getUserLoginDto(token);
if (!Objects.isNull(user)) {
return user;
}
} catch (Exception e) {
}
}
return null;
}
/**
*
* @param lyricUrl
* @return
*/
private String readLyric(String lyricUrl) {
try {
// 创建 URL 对象

@ -43,7 +43,10 @@ public class S3Service {
String destUrlSuffix = format + srcUrl.substring(srcUrl.lastIndexOf(Constants.DOT));
String destUrl = Constants.MUSIC_KEY_PREFIX + destUrlSuffix;
item.setUrl(destUrlSuffix);
copy(Constants.BUCKET, srcUrl, destUrl);
int copy = copy(Constants.BUCKET, srcUrl, destUrl);
if (copy == -1) {
item.setUrl(null);
}
tempLyric = srcUrl;
}
if (StringUtils.isNotBlank(item.getImage())) {
@ -51,7 +54,10 @@ public class S3Service {
String destImageSuffix = format + srcImage.substring(srcImage.lastIndexOf(Constants.DOT));
String destImage = Constants.MUSIC_KEY_PREFIX + destImageSuffix;
item.setImage(destImageSuffix);
copy(Constants.BUCKET, srcImage, destImage);
int copy = copy(Constants.BUCKET, srcImage, destImage);
if (copy == -1) {
item.setImage(null);
}
}
if (StringUtils.isNotBlank(tempLyric)) {
String srcLyric = tempLyric.substring(0, tempLyric.lastIndexOf(Constants.DOT)) + ".lyric";

Loading…
Cancel
Save