|
|
@ -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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 删除期刊的标签、音乐信息
|
|
|
|
* 删除期刊的标签、音乐信息
|
|
|
|