main
JH 10 months ago
parent dcbc48cbce
commit 7cbb2b3daf

@ -41,7 +41,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("Authorization") String token,
@ApiParam(value = "期刊信息", required = true) @Valid @RequestBody JournalAddModel addModel){ @ApiParam(value = "期刊信息", required = true) @Valid @RequestBody JournalAddModel addModel){
return journalService.add(token, addModel); return journalService.add(token, addModel);
} }
@ -55,7 +55,7 @@ public class CMSJournalController {
@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 = "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){ @ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel updateModel){
return journalService.update(id, token, updateModel); return journalService.update(id, token, updateModel);
} }

@ -38,7 +38,7 @@ public class CMSSongController {
@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("Authorization") String token,
@ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel addModel){ @ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel addModel){
return songService.add(token, addModel); return songService.add(token, addModel);
} }
@ -51,7 +51,7 @@ public class CMSSongController {
@ApiOperation(value = "更新歌曲信息", notes = "更新歌曲信息") @ApiOperation(value = "更新歌曲信息", notes = "更新歌曲信息")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT) @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 = "歌曲ID", required = true) @PathVariable String id,
@ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel updateModel){ @ApiParam(value = "歌曲信息", required = true) @RequestBody SongAddModel updateModel){
return songService.update(id, token, updateModel); return songService.update(id, token, updateModel);
@ -92,7 +92,8 @@ public class CMSSongController {
@ApiOperation(value = "批量上传歌曲", notes = "批量上传歌曲") @ApiOperation(value = "批量上传歌曲", notes = "批量上传歌曲")
@RequestMapping(value = "/batch", method = RequestMethod.POST) @RequestMapping(value = "/batch", method = RequestMethod.POST)
public Result batchUpload(@ApiParam(value = "多歌曲文件", required = true) @RequestParam("files") List<MultipartFile> files) { public Result batchUpload(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
return songService.batchUpload(files); @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.setJournalNo(item.getJournalNo());
response.setTitle(item.getTitle()); response.setTitle(item.getTitle());
response.setImage(Constants.MUSIC_RESOURCE_PREFIX + item.getImage()); 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.setState(item.getState());
response.setIsPublish(item.getIsPublish()); response.setIsPublish(item.getIsPublish());
if (!Objects.isNull(item.getPubTime())) { if (!Objects.isNull(item.getPubTime())) {
@ -380,15 +382,19 @@ public class CMSJournalService {
if (StringUtils.isNotBlank(srcKey)) { if (StringUtils.isNotBlank(srcKey)) {
String image = moveJournalImage(srcKey, param); String image = moveJournalImage(srcKey, param);
if (StringUtils.isBlank(image)) { if (StringUtils.isBlank(image)) {
Result.failed("更新失败"); return Result.failed("更新失败");
} }
journal.setImage(image); journal.setImage(image);
} else {
journal.setImage(oldJournal.getImage());
} }
journal.setState(oldJournal.getState()); journal.setState(oldJournal.getState());
journal.setIsPublish(oldJournal.getIsPublish()); journal.setIsPublish(oldJournal.getIsPublish());
journal.setIsScheduled(oldJournal.getIsScheduled()); journal.setIsScheduled(oldJournal.getIsScheduled());
journal.setVisits(oldJournal.getVisits()); journal.setVisits(oldJournal.getVisits());
journal.setComment(oldJournal.getComment()); journal.setComment(oldJournal.getComment());
journal.setCreateTime(oldJournal.getCreateTime());
journal.setPubTime(oldJournal.getPubTime());
journalDao.save(journal); journalDao.save(journal);
batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo()); batchDeleteJournalRelatesInfo(id, oldJournal.getJournalNo());
batchSaveJournalRelatesInfo(id, param); batchSaveJournalRelatesInfo(id, param);

@ -14,6 +14,7 @@ import org.apache.commons.lang.StringUtils;
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;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -66,9 +67,9 @@ public class CMSSongService {
*/ */
public Result<PageResult<SongVO>> 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, "id");
// 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<SongInfo> songPage; Page<SongInfo> songPage;
if (!Objects.isNull(param)) { if (!Objects.isNull(param)) {
Specification<SongInfo> songSpecification = buildSearchSpecification(param); Specification<SongInfo> songSpecification = buildSearchSpecification(param);
@ -90,14 +91,19 @@ public class CMSSongService {
response.setArtist(item.getArtist()); response.setArtist(item.getArtist());
response.setAlbum(item.getAlbum()); response.setAlbum(item.getAlbum());
response.setTags(songTagMap.get(id)); 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.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(item.getUpdateTime().format(Constants.formatter)); 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(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); result.add(response);
} }
} }
@ -228,10 +234,9 @@ public class CMSSongService {
song.setName(param.getName()); song.setName(param.getName());
song.setArtist(param.getArtist()); song.setArtist(param.getArtist());
song.setAlbum(param.getAlbum()); song.setAlbum(param.getAlbum());
song.setSize(param.getSize()); song.setLyric(param.getLyric());
song.setDuration(param.getDuration()); UserLoginDto user = getUserInfoByToken(token);
if (StringUtils.isNotBlank(token)) { if (!Objects.isNull(user)) {
UserLoginDto user = jwtUtil.getUserLoginDto(token);
song.setUserId(user.getUserId()); song.setUserId(user.getUserId());
song.setUserName(user.getNickName()); song.setUserName(user.getNickName());
song.setUserType(user.getRoles()); 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 * @param id
@ -339,19 +335,41 @@ public class CMSSongService {
if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) { if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
image = moveSongImage(id, param); image = moveSongImage(id, param);
if (StringUtils.isBlank(image)) { if (StringUtils.isBlank(image)) {
Result.failed("更新失败"); return Result.failed("更新失败");
} }
song.setImage(image); song.setImage(image);
} else { } else {
song.setImage(oldSong.getImage()); song.setImage(oldSong.getImage());
} }
song.setState(oldSong.getState()); song.setState(oldSong.getState());
song.setCreateTime(oldSong.getCreateTime());
songDao.save(song); songDao.save(song);
songTagDao.deleteBySongId(id); songTagDao.deleteBySongId(id);
batchSaveSongTagInfo(id, param); batchSaveSongTagInfo(id, param);
batchUpdateJournalSongInfo(id, song);
return Result.success(); 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 * @param id
@ -427,17 +445,18 @@ public class CMSSongService {
} }
/** /**
* *
* @param files * @param files
* @return * @return
*/ */
public Result batchUpload(List<MultipartFile> files) { public Result batchUpload(List<MultipartFile> files, String token) {
for (MultipartFile file : files) { UserLoginDto user = getUserInfoByToken(token);
for (MultipartFile file : files)
if (!file.isEmpty()) { if (!file.isEmpty()) {
String id = String.valueOf(idWorker.nextId()); String id = String.valueOf(idWorker.nextId());
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
String suffix = originalFilename.substring(originalFilename.lastIndexOf(Constants.DOT)); 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; 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 > 0) { if (upload > 0) {
@ -447,13 +466,40 @@ public class CMSSongService {
song.setUrl(keySuffix); song.setUrl(keySuffix);
song.setSize(file.isEmpty() ? 0L : file.getSize()); song.setSize(file.isEmpty() ? 0L : file.getSize());
song.setDuration(CommonUtil.getSongDuration(file)); song.setDuration(CommonUtil.getSongDuration(file));
if (!Objects.isNull(user)) {
song.setUserId(user.getUserId());
song.setUserName(user.getNickName());
song.setUserType(user.getRoles());
}
songDao.save(song); songDao.save(song);
} }
} }
}
return Result.success(); 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) { private String readLyric(String lyricUrl) {
try { try {
// 创建 URL 对象 // 创建 URL 对象

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

Loading…
Cancel
Save