1.remove unused class

2.enhance journal upload logic
main
Gary 12 months ago
parent bf7c86b300
commit 604476f6d0

@ -1,37 +0,0 @@
package com.luoo.music.pojo;
import lombok.Getter;
import lombok.Setter;
import java.util.LinkedList;
import org.springframework.data.annotation.Id;
import java.io.Serializable;
/**
*
*/
@Getter
@Setter
public class UserCollect implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@Id
private String userId;
/**
* ID ID,ID
*/
private String objectId;
/**
* 0:,1:
*/
private Integer collectType;
private LinkedList<String> journals;
private LinkedList<String> songs;
}

@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import util.IdWorker;
import util.JwtUtil;
import util.StringTools;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
@ -368,41 +369,52 @@ public class CMSJournalService {
* @return
*/
public Result update(String id, String token, JournalAddModel param) {
Journal oldJournal = journalDao.findById(id).get();
List<Journal> byJournalNo = journalDao.findByJournalNo(param.getJournalNo());
if (!oldJournal.getJournalNo().equals(param.getJournalNo()) && byJournalNo.size() > 0) {
return Result.failed("更新失败,期刊编号已存在");
Optional<Journal> optional = journalDao.findById(id);
if(!optional.isPresent()) {
return Result.failed("找不到期刊: "+id);
}
Journal journal = buildJournal(id, param, token);
String srcKey = null;
if (param.getImage().contains(Constants.TEMP_KEY_PREFIX)) {
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.MUSIC_KEY_PREFIX));
}
Journal journal=optional.get();
updateJournal(journal, param, token);
journalDao.save(journal);
if (!CollectionUtils.isEmpty(param.getTag())) {
journalTagDao.deleteByJournalId(id);
}
if (StringUtils.isNotBlank(srcKey)) {
String image = moveJournalImage(srcKey, param);
if (StringUtils.isBlank(image)) {
return Result.failed("更新失败");
}
journal.setImage(image);
} else {
journal.setImage(oldJournal.getImage());
if (!CollectionUtils.isEmpty(param.getSongs())) {
journalSongDao.deleteByJournalNo(id);
}
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);
return Result.success();
}
private void updateJournal(Journal journal, JournalAddModel param, String token) {
String title=param.getTitle();
if(!StringTools.isEmpty(title)) {
journal.setTitle(title);
}
String content=param.getContent();
if(!StringTools.isEmpty(content)) {
journal.setContent(content);
}
String userId=param.getUserId();
if(!StringTools.isEmpty(userId)) {
UserInfo userInfo = userClient.queryUserInfoById(userId);
if (!Objects.isNull(userInfo)) {
journal.setUserId(userInfo.getId());
journal.setUserName(userInfo.getName());
journal.setUserType(userInfo.getType());
}
}
String tempImage=param.getImage();
if(!StringTools.isEmpty(tempImage)&&tempImage.contains(Constants.TEMP_KEY_PREFIX)) {
String srcKey=param.getImage().substring(param.getImage().indexOf(Constants.TEMP_KEY_PREFIX));
String image = moveJournalImage(srcKey, param);
if (!StringUtils.isBlank(image)) {
journal.setImage(image);
}
}
}
/**
*

@ -36,41 +36,41 @@ public class S3Service {
* @param journalSongList
*/
public void fromSongToMusic(List<JournalSong> journalSongList) {
for (JournalSong item : journalSongList) {
String tempLyric = null;
String format = String.format("%05d/%02d", Integer.parseInt(item.getJournalNo()), item.getSongNo());
if (StringUtils.isNotBlank(item.getUrl())) {
String srcUrl = Constants.SONG_KEY_PREFIX + item.getUrl();
String destUrlSuffix = format + srcUrl.substring(srcUrl.lastIndexOf(Constants.DOT));
String destUrl = Constants.MUSIC_KEY_PREFIX + destUrlSuffix;
item.setUrl(destUrlSuffix);
int copy = copy(Constants.BUCKET, srcUrl, destUrl);
if (copy == -1) {
item.setUrl(null);
}
tempLyric = srcUrl;
journalSongList.parallelStream().forEach(this::fromSongToMusic);
}
private void fromSongToMusic(JournalSong item) {
String tempLyric = null;
String format = String.format("%05d/%02d", Integer.parseInt(item.getJournalNo()), item.getSongNo());
if (StringUtils.isNotBlank(item.getUrl())) {
String srcUrl = Constants.SONG_KEY_PREFIX + item.getUrl();
String destUrlSuffix = format + srcUrl.substring(srcUrl.lastIndexOf(Constants.DOT));
String destUrl = Constants.MUSIC_KEY_PREFIX + destUrlSuffix;
item.setUrl(destUrlSuffix);
int copy = copy(Constants.BUCKET, srcUrl, destUrl);
if (copy == -1) {
item.setUrl(null);
}
if (StringUtils.isNotBlank(item.getImage())) {
String srcImage = Constants.SONG_KEY_PREFIX + item.getImage();
String destImageSuffix = format + srcImage.substring(srcImage.lastIndexOf(Constants.DOT));
String destImage = Constants.MUSIC_KEY_PREFIX + destImageSuffix;
item.setImage(destImageSuffix);
int copy = copy(Constants.BUCKET, srcImage, destImage);
if (copy == -1) {
item.setImage(null);
}
tempLyric = srcUrl;
}
if (StringUtils.isNotBlank(item.getImage())) {
String srcImage = Constants.SONG_KEY_PREFIX + item.getImage();
String destImageSuffix = format + srcImage.substring(srcImage.lastIndexOf(Constants.DOT));
String destImage = Constants.MUSIC_KEY_PREFIX + destImageSuffix;
item.setImage(destImageSuffix);
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";
if (checkFileExist(Constants.BUCKET, srcLyric)) {
String destLyricSuffix = format + srcLyric.substring(srcLyric.lastIndexOf(Constants.DOT));
String destLyric = Constants.MUSIC_KEY_PREFIX + destLyricSuffix;
copy(Constants.BUCKET, srcLyric, destLyric);
}
}
if (StringUtils.isNotBlank(tempLyric)) {
String srcLyric = tempLyric.substring(0, tempLyric.lastIndexOf(Constants.DOT)) + ".lyric";
if (checkFileExist(Constants.BUCKET, srcLyric)) {
String destLyricSuffix = format + srcLyric.substring(srcLyric.lastIndexOf(Constants.DOT));
String destLyric = Constants.MUSIC_KEY_PREFIX + destLyricSuffix;
copy(Constants.BUCKET, srcLyric, destLyric);
}
}
}
/**
* @param file
* @return

@ -71,6 +71,23 @@ public class CMSAdminController {
}
}
@PostMapping("/login2/{username}/{password}")
public Result login2(@PathVariable String username,@PathVariable String password) {
Admin admin = adminService.findByLoginnameAndPassword(username,password);
if (admin !=null) {
//生成token
String token = jwtUtil.createJWT(admin.getId(),admin.getLoginname(),"admin","");
Map<String, Object> map = new HashMap<>();
map.put("token",token);
map.put("roles","admin");
map.put("name",admin.getLoginname());
return Result.success(map);
} else {
return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
}
}
/**
*
* @return

Loading…
Cancel
Save