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 org.springframework.util.CollectionUtils;
import util.IdWorker; import util.IdWorker;
import util.JwtUtil; import util.JwtUtil;
import util.StringTools;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@ -368,41 +369,52 @@ public class CMSJournalService {
* @return * @return
*/ */
public Result update(String id, String token, JournalAddModel param) { public Result update(String id, String token, JournalAddModel param) {
Journal oldJournal = journalDao.findById(id).get(); Optional<Journal> optional = journalDao.findById(id);
List<Journal> byJournalNo = journalDao.findByJournalNo(param.getJournalNo()); if(!optional.isPresent()) {
if (!oldJournal.getJournalNo().equals(param.getJournalNo()) && byJournalNo.size() > 0) { return Result.failed("找不到期刊: "+id);
return Result.failed("更新失败,期刊编号已存在");
}
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)) { if (!CollectionUtils.isEmpty(param.getSongs())) {
String image = moveJournalImage(srcKey, param); journalSongDao.deleteByJournalNo(id);
if (StringUtils.isBlank(image)) {
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); batchSaveJournalRelatesInfo(id, param);
return Result.success(); 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,7 +36,9 @@ public class S3Service {
* @param journalSongList * @param journalSongList
*/ */
public void fromSongToMusic(List<JournalSong> journalSongList) { public void fromSongToMusic(List<JournalSong> journalSongList) {
for (JournalSong item : journalSongList) { journalSongList.parallelStream().forEach(this::fromSongToMusic);
}
private void fromSongToMusic(JournalSong item) {
String tempLyric = null; String tempLyric = null;
String format = String.format("%05d/%02d", Integer.parseInt(item.getJournalNo()), item.getSongNo()); String format = String.format("%05d/%02d", Integer.parseInt(item.getJournalNo()), item.getSongNo());
if (StringUtils.isNotBlank(item.getUrl())) { if (StringUtils.isNotBlank(item.getUrl())) {
@ -69,8 +71,6 @@ public class S3Service {
} }
} }
} }
}
/** /**
* @param file * @param file
* @return * @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 * @return

Loading…
Cancel
Save