|
@@ -6,17 +6,21 @@ import com.jkcredit.sysnews.enums.PhotoStatusEnum;
|
|
|
import com.jkcredit.sysnews.enums.PhotoTypeEnum;
|
|
|
import com.jkcredit.sysnews.mapper.NewsArticleMapper;
|
|
|
import com.jkcredit.sysnews.model.dto.newsArticle.NewsArticleDto;
|
|
|
+import com.jkcredit.sysnews.model.dto.newsArticleNavigationBar.NewsArticleNavigationBarDto;
|
|
|
import com.jkcredit.sysnews.model.dto.photo.PhotoDto;
|
|
|
import com.jkcredit.sysnews.model.po.newsArticle.NewsArticlePo;
|
|
|
+import com.jkcredit.sysnews.model.po.newsArticleNavigationBar.NewsArticleNavigationBarPo;
|
|
|
import com.jkcredit.sysnews.model.po.photo.PhotoPo;
|
|
|
import com.jkcredit.sysnews.model.vo.newsArticle.NewsArticleVo;
|
|
|
import com.jkcredit.sysnews.model.vo.photo.PhotoVo;
|
|
|
import com.jkcredit.sysnews.service.base.BaseService;
|
|
|
+import com.jkcredit.sysnews.service.newsArticleNavigationBar.NewsArticleNavigationBarService;
|
|
|
import com.jkcredit.sysnews.service.photo.PhotoService;
|
|
|
import com.jkcredit.sysnews.spi.lang.constant.CommonConstant;
|
|
|
import com.jkcredit.sysnews.spi.lang.exception.ServiceException;
|
|
|
import com.jkcredit.sysnews.util.AssertUtils;
|
|
|
import com.jkcredit.sysnews.util.BeanUtil;
|
|
|
+import com.jkcredit.sysnews.util.CommonUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.commons.lang.enums.EnumUtils;
|
|
@@ -28,7 +32,10 @@ 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;
|
|
|
|
|
|
/**
|
|
|
* @description:
|
|
@@ -51,6 +58,8 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
NewsArticleMapper mapper;
|
|
|
@Autowired
|
|
|
PhotoService photoService;
|
|
|
+ @Autowired
|
|
|
+ NewsArticleNavigationBarService newsArticleNavigationBarService;
|
|
|
|
|
|
@Override
|
|
|
public IPage<NewsArticleVo> getNewsArticles(Page page, NewsArticleDto newsArticleDto) {
|
|
@@ -91,16 +100,18 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
photoDto.setStatus(PhotoStatusEnum.UPLOAD_SUCCESS_HAVE_USED.getValue());
|
|
|
|
|
|
// 更新新闻content中的图片
|
|
|
- try {
|
|
|
- for (String url : newsArticleDto.getUrlList()) {
|
|
|
- url = File.separator + url.replace(accessPath, "").replace(accessResource, "");
|
|
|
- PhotoPo photoPo = photoService.getPhotoByUrl(url);
|
|
|
- photoDto.setId(photoPo.getId());
|
|
|
- photoService.editPhoto(photoDto);
|
|
|
+ if (newsArticleDto.getUrlList() != null) {
|
|
|
+ try {
|
|
|
+ for (String url : newsArticleDto.getUrlList()) {
|
|
|
+ url = File.separator + url.replace(accessPath, "").replace(accessResource, "");
|
|
|
+ PhotoPo photoPo = photoService.getPhotoByUrl(url);
|
|
|
+ photoDto.setId(photoPo.getId());
|
|
|
+ photoService.editPhoto(photoDto);
|
|
|
+ }
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("新增新闻-更新图片失败,失败原因:{}", e.getMessage());
|
|
|
+ throw new ServiceException("新增新闻失败");
|
|
|
}
|
|
|
- } catch (ServiceException e) {
|
|
|
- log.error("新增新闻-更新图片失败,失败原因:{}", e.getMessage());
|
|
|
- throw new ServiceException("新增新闻失败");
|
|
|
}
|
|
|
|
|
|
// 保存新闻首图
|
|
@@ -125,6 +136,19 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
log.error("新增新闻失败,失败原因:{}", e.getMessage());
|
|
|
throw new ServiceException("新增新闻失败");
|
|
|
}
|
|
|
+
|
|
|
+ // 保存导航栏
|
|
|
+ try {
|
|
|
+ for (Long navigationBarId : newsArticleDto.getNavigationBarIds()) {
|
|
|
+ NewsArticleNavigationBarDto dto = new NewsArticleNavigationBarDto();
|
|
|
+ dto.setNewsArticleId(newsArticlePo.getId());
|
|
|
+ dto.setNavigationBarId(navigationBarId);
|
|
|
+ newsArticleNavigationBarService.saveNewsArticleNavigationBar(dto);
|
|
|
+ }
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("新增新闻-新增新闻导航关联表失败,失败原因:{}", e.getMessage());
|
|
|
+ throw new ServiceException("新增新闻失败");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -167,6 +191,34 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
log.error("编辑新闻失败,失败原因:{}", e.getMessage());
|
|
|
throw new ServiceException("编辑新闻失败");
|
|
|
}
|
|
|
+ // 更新导航栏
|
|
|
+ editNewsArticleNavigationBar(newsArticleDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void editNewsArticleNavigationBar(NewsArticleDto newsArticleDto) {
|
|
|
+ List<NewsArticleNavigationBarDto> newsArticleNavigationBarDtoList = newsArticleNavigationBarService.getArticleNavigationBarByNewsId(newsArticleDto.getId());
|
|
|
+ // 现有1 2 3 4 更新后 2 3 4 5 删掉1 新增 5
|
|
|
+ List<Long> idFromDataBase = new ArrayList<>();
|
|
|
+ for (NewsArticleNavigationBarDto dto : newsArticleNavigationBarDtoList) {
|
|
|
+ idFromDataBase.add(dto.getNavigationBarId());
|
|
|
+ }
|
|
|
+ List<Long> deleleNavigationBarIdList = 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) {
|
|
|
+ Long id = newsArticleNavigationBarService.getArticleNavigationBarId(newsArticleDto.getId(), navigationBarId);
|
|
|
+ newsArticleNavigationBarService.deleteNewsArticleNavigationBar(id);
|
|
|
+ }
|
|
|
+ for (Long navigationBarId : addNavigationBarIdList) {
|
|
|
+ NewsArticleNavigationBarDto dto = new NewsArticleNavigationBarDto();
|
|
|
+ dto.setNavigationBarId(navigationBarId);
|
|
|
+ dto.setNewsArticleId(newsArticleDto.getId());
|
|
|
+ newsArticleNavigationBarService.saveNewsArticleNavigationBar(dto);
|
|
|
+ }
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("编辑新闻失败-编辑新闻导航栏关联表失败,失败原因:{}", e.getMessage());
|
|
|
+ throw new ServiceException("编辑新闻失败");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -182,5 +234,15 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
|
|
|
log.error("删除新闻失败,失败原因:{}", e.getMessage());
|
|
|
throw new ServiceException("删除新闻失败");
|
|
|
}
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<NewsArticleNavigationBarDto> newsArticleNavigationBarDtoList = newsArticleNavigationBarService.getArticleNavigationBarByNewsId(id);
|
|
|
+ for (NewsArticleNavigationBarDto dto : newsArticleNavigationBarDtoList) {
|
|
|
+ newsArticleNavigationBarService.deleteNewsArticleNavigationBar(dto.getId());
|
|
|
+ }
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ log.error("删除新闻导航栏关联表数据失败,失败原因:{}", e.getMessage());
|
|
|
+ throw new ServiceException("删除新闻失败");
|
|
|
+ }
|
|
|
}
|
|
|
}
|