|
@@ -35,10 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @description:
|
|
@@ -132,7 +129,7 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
if (newsArticleDto.getUrlList() != null) {
|
|
|
try {
|
|
|
for (String url : newsArticleDto.getUrlList()) {
|
|
|
- url = File.separator + url.replace(accessPath, "").replace(accessResource, "");
|
|
|
+ url = "/" + url.replace(accessPath, "").replace(accessResource, "");
|
|
|
PhotoPo photoPo = photoService.getPhotoByUrl(url);
|
|
|
photoDto.setId(photoPo.getId());
|
|
|
// 更新新闻content中的图片
|
|
@@ -203,7 +200,14 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
throw new ServiceException("编辑新闻失败");
|
|
|
}
|
|
|
// 更新导航栏
|
|
|
- editNewsArticleNavigationBar(newsArticleDto);
|
|
|
+ if (newsArticleDto.getNavigationBarIds() != null && !newsArticleDto.getNavigationBarIds().isEmpty()) {
|
|
|
+ editNewsArticleNavigationBar(newsArticleDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新新闻内容中的图片
|
|
|
+ if (newsArticleDto.getUrlList() != null && !newsArticleDto.getUrlList().isEmpty()) {
|
|
|
+ editNewsArticlePhoto(newsArticleDto);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void editNewsArticleNavigationBar(NewsArticleDto newsArticleDto) {
|
|
@@ -213,10 +217,10 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
for (NewsArticleNavigationBarDto dto : newsArticleNavigationBarDtoList) {
|
|
|
idFromDataBase.add(dto.getNavigationBarId());
|
|
|
}
|
|
|
- List<Long> deleleNavigationBarIdList = CommonUtil.getSubtraction(new HashSet<>(idFromDataBase), new HashSet<>(newsArticleDto.getNavigationBarIds()));
|
|
|
+ List<Long> deleteNavigationBarIdList = CommonUtil.getSubtraction(new HashSet<>(idFromDataBase), new HashSet<>(newsArticleDto.getNavigationBarIds()));
|
|
|
List<Long> addNavigationBarIdList = CommonUtil.getSubtraction(new HashSet<>(newsArticleDto.getNavigationBarIds()), new HashSet<>(idFromDataBase));
|
|
|
try {
|
|
|
- for (Long navigationBarId : deleleNavigationBarIdList) {
|
|
|
+ for (Long navigationBarId : deleteNavigationBarIdList) {
|
|
|
Long id = newsArticleNavigationBarService.getArticleNavigationBarId(newsArticleDto.getId(), navigationBarId);
|
|
|
newsArticleNavigationBarService.deleteNewsArticleNavigationBar(id);
|
|
|
}
|
|
@@ -232,6 +236,63 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void editNewsArticlePhoto(NewsArticleDto newsArticleDto) {
|
|
|
+ // 查询已有新闻-图片关联数据
|
|
|
+ List<NewsArticlePhotoPo> newsArticlePhotoPoList = newsArticlePhotoService.getArticlePhotoByNewsId(newsArticleDto.getId());
|
|
|
+
|
|
|
+ // 封装数据库数据
|
|
|
+ Map<Long, NewsArticlePhotoPo> newsArticlePhotoPoMap = new HashMap<>();
|
|
|
+ List<Long> idFromDataBase = new ArrayList<>();
|
|
|
+ for (NewsArticlePhotoPo po : newsArticlePhotoPoList) {
|
|
|
+ idFromDataBase.add(po.getPhotoId());
|
|
|
+ newsArticlePhotoPoMap.put(po.getPhotoId(), po);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装前端传入图片
|
|
|
+ List<Long> idFromWeb = new ArrayList<>();
|
|
|
+ Map<Long, PhotoPo> photoPoMap = new HashMap<>();
|
|
|
+ for (String url : newsArticleDto.getUrlList()) {
|
|
|
+ url = "/" + url.replace(accessPath, "").replace(accessResource, "");
|
|
|
+ PhotoPo photoPo = photoService.getPhotoByUrl(url);
|
|
|
+ idFromWeb.add(photoPo.getId());
|
|
|
+ photoPoMap.put(photoPo.getId(), photoPo);
|
|
|
+ }
|
|
|
+ List<Long> deleteArticlePhotoList = CommonUtil.getSubtraction(new HashSet<>(idFromDataBase), new HashSet<>(idFromWeb));
|
|
|
+ List<Long> addArticlePhotoList = CommonUtil.getSubtraction(new HashSet<>(idFromWeb), new HashSet<>(idFromDataBase));
|
|
|
+
|
|
|
+ try {
|
|
|
+ for (Long photoId : deleteArticlePhotoList) {
|
|
|
+ NewsArticlePhotoPo newsArticlePhotoPo = newsArticlePhotoPoMap.get(photoId);
|
|
|
+ // 删除新闻-图片关联数据
|
|
|
+ newsArticlePhotoService.deleteNewsArticlePhoto(newsArticlePhotoPo.getId());
|
|
|
+ // 删除图片
|
|
|
+ photoService.deletePhoto(photoId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (addArticlePhotoList != null && addArticlePhotoList.size() != 0) {
|
|
|
+ NewsArticlePo newsArticlePo = mapper.getNewsArticleById(newsArticleDto.getId());
|
|
|
+ for (Long photoId : addArticlePhotoList) {
|
|
|
+ NewsArticlePhotoDto newsArticlePhotoDto = new NewsArticlePhotoDto();
|
|
|
+ newsArticlePhotoDto.setNewsArticleId(newsArticleDto.getId());
|
|
|
+ newsArticlePhotoDto.setPhotoId(photoId);
|
|
|
+ // 新增新闻-图片关联数据
|
|
|
+ newsArticlePhotoService.saveNewsArticlePhoto(newsArticlePhotoDto);
|
|
|
+ // todo 为新闻内图片增加标题状态
|
|
|
+ PhotoPo photoPo = photoPoMap.get(photoId);
|
|
|
+ PhotoDto photoDto = new PhotoDto();
|
|
|
+ BeanUtil.copyProperties(photoDto, photoPo);
|
|
|
+ photoDto.setName(newsArticlePo.getTitle());
|
|
|
+ photoDto.setType(PhotoTypeEnum.NEWS_PHOTO.getValue());
|
|
|
+ photoDto.setStatus(PhotoStatusEnum.UPLOAD_SUCCESS_HAVE_USED.getValue());
|
|
|
+ photoService.editPhoto(photoDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("编辑新闻失败-编辑新闻图片关联表失败,失败原因:{}", e.getMessage());
|
|
|
+ throw new ServiceException("编辑新闻失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = ServiceException.class)
|
|
|
public void deleteNewsArticle(Long id) {
|
|
@@ -247,6 +308,16 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
+ List<NewsArticlePhotoPo> newsArticlePhotoPoList = newsArticlePhotoService.getArticlePhotoByNewsId(id);
|
|
|
+ for (NewsArticlePhotoPo po : newsArticlePhotoPoList) {
|
|
|
+ newsArticlePhotoService.deleteNewsArticlePhoto(po.getId());
|
|
|
+ photoService.deletePhoto(po.getPhotoId());
|
|
|
+ }
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("删除新闻图片/新闻-图片关联表失败,失败原因:{}", e.getMessage());
|
|
|
+ throw new ServiceException("删除新闻失败");
|
|
|
+ }
|
|
|
+ try {
|
|
|
List<NewsArticleNavigationBarDto> newsArticleNavigationBarDtoList = newsArticleNavigationBarService.getArticleNavigationBarByNewsId(id);
|
|
|
for (NewsArticleNavigationBarDto dto : newsArticleNavigationBarDtoList) {
|
|
|
newsArticleNavigationBarService.deleteNewsArticleNavigationBar(dto.getId());
|