123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- package com.ruoyi.system.service.impl;
- import com.ruoyi.common.constant.UserConstants;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.common.utils.bean.BeanUtils;
- import com.ruoyi.system.domain.PoNews;
- import com.ruoyi.system.mapper.PoNewsMapper;
- import com.ruoyi.system.service.IPoNewsService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * 消息Service业务层处理
- * @date 2023-01-15
- */
- @Service
- public class PoNewsServiceImpl implements IPoNewsService {
- @Autowired
- private PoNewsMapper poNewsMapper;
- /**
- * 根据Id查询
- *
- * @param newsId
- * @return
- */
- @Override
- public List<PoNews> selectPoNewsByNewsId(String newsId) {
- List list = new ArrayList();
- List<PoNews> poNewsList =new ArrayList<>();
- poNewsList.add(poNewsMapper.selectPoNewsByNewsId(newsId));
- List<PoNews> collect = poNewsList.stream().map((item) -> {
- PoNews poNews = new PoNews();
- //将所有消息数据拷贝到消息用户链接对象实例
- BeanUtils.copyProperties(item, poNews);
- List<PoNews> newsAndUserVos = poNewsMapper.selectUserByNewsId(newsId);
- list.add(newsAndUserVos);
- poNews.setPhonenumber(list.toString());
- return poNews;
- }).collect(Collectors.toList());
- return collect;
- }
- /**
- * 分页查询
- *
- * @param poNews
- * @return
- */
- @Override
- public List<PoNews> selectPoNewsList(PoNews poNews) {
- return poNewsMapper.selectPoNewsList(poNews);
- }
- /**
- * 新增
- *
- * @param poNews
- * @return
- */
- @Override
- public int insertPoNews(PoNews poNews) {
- poNews.setCreateTime(DateUtils.getNowDate());
- return poNewsMapper.insertPoNews(poNews);
- }
- /**
- * 修改
- *
- * @param poNews
- * @return
- */
- @Override
- public int updatePoNews(PoNews poNews) {
- poNews.setUpdateTime(DateUtils.getNowDate());
- return poNewsMapper.updatePoNews(poNews);
- }
- /**
- * 批量删除
- *
- * @param newsIds
- * @return
- */
- @Override
- public int deletePoNewsByNewsIds(String[] newsIds) {
- return poNewsMapper.deletePoNewsByNewsIds(newsIds);
- }
- /**
- * 删除
- *
- * @param newsId
- * @return
- */
- @Override
- public int deletePoNewsByNewsId(String newsId) {
- return poNewsMapper.deletePoNewsByNewsId(newsId);
- }
- /**
- * 校验标题是否重复
- *
- * @param poNews
- * @return
- */
- @Override
- public String checkPostNewsTitleUnique(PoNews poNews) {
- String poNewsId = StringUtils.isNull(poNews.getNewsId()) ? "消息不存在" : poNews.getNewsId();
- PoNews info = poNewsMapper.checkPostNewsTitleUnique(poNews.getNewsTitle());
- if (StringUtils.isNotNull(info) && info.getNewsId() != poNewsId) {
- return UserConstants.NOT_UNIQUE;
- }
- return UserConstants.UNIQUE;
- }
- /**
- * 搜索消息
- * @param title
- * @param newsTimeStart
- * @param newsTimeEnd
- * @return
- */
- @Override
- public List<PoNews> selectListByTitleAndTime(String title, Date newsTimeStart, Date newsTimeEnd) {
- if (title != null) {
- //标题不为空且开始时间和结束时间都不为空
- if (newsTimeStart != null && newsTimeEnd != null) {
- if (newsTimeStart.before(newsTimeEnd)) {
- return poNewsMapper.selectPoNewsListByTitleAndNewsTimeStartAndNewsTimeEnd(title, newsTimeStart, newsTimeEnd);
- }
- else if((newsTimeStart != null && newsTimeEnd == null) || (newsTimeStart == null && newsTimeEnd != null)) {
- //有一个时间不为空返回提示信息
- List list = new ArrayList();
- list.add("请选择正确的时间段");
- return list;
- }
- }
- else {//时间都为空
- return poNewsMapper.selectPoNewsListByTitle(title);
- }
- }
- //标题为空
- else {
- //时间不为空
- if (newsTimeStart != null && newsTimeEnd != null) {
- return poNewsMapper.selectPoNewsByTime(newsTimeStart, newsTimeEnd);
- }
- }
- //都为空执行分页查询
- PoNews poNews = new PoNews();
- return poNewsMapper.selectPoNewsList(poNews);
- }
- /**
- * 获取详细消息内容
- * @param newsId
- * @return
- */
- @Override
- public PoNews selectContentByNewsId(String newsId) {
- return poNewsMapper.selectContentByNewsId(newsId);
- }
- /**
- * 校验图片是否重复
- * @param poNews
- * @return
- */
- @Override
- public String checkPostNewsImageUnique(PoNews poNews) {
- String poNewsId = StringUtils.isNull(poNews.getNewsId()) ? "图片不存在" : poNews.getNewsId();
- PoNews info = poNewsMapper.checkPostNewsImageUnique(poNews.getImage());
- if (StringUtils.isNotNull(info) && info.getNewsId() != poNewsId) {
- return UserConstants.NOT_UNIQUE;
- }
- return UserConstants.UNIQUE;
- }
- /**
- * 校验时间是否相等
- * @param poNews
- * @return
- */
- @Override
- public String checkPostNewsTimeUnique(PoNews poNews) {
- String poNewsId = StringUtils.isNull(poNews.getNewsId())? "图片不存在" : poNews.getNewsId();
- PoNews info = poNewsMapper.checkPostNewsTimeUnique(poNews.getCreateTime());
- if (StringUtils.isNotNull(info) && info.getNewsId() != poNewsId){
- return UserConstants.NOT_UNIQUE;
- }
- return UserConstants.UNIQUE;
- }
- }
|