PoNewsServiceImpl.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package com.ruoyi.system.service.impl;
  2. import com.ruoyi.common.constant.UserConstants;
  3. import com.ruoyi.common.utils.DateUtils;
  4. import com.ruoyi.common.utils.StringUtils;
  5. import com.ruoyi.common.utils.bean.BeanUtils;
  6. import com.ruoyi.system.domain.PoNews;
  7. import com.ruoyi.system.mapper.PoNewsMapper;
  8. import com.ruoyi.system.service.IPoNewsService;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import java.util.ArrayList;
  12. import java.util.Date;
  13. import java.util.List;
  14. import java.util.stream.Collectors;
  15. /**
  16. * 消息Service业务层处理
  17. * @date 2023-01-15
  18. */
  19. @Service
  20. public class PoNewsServiceImpl implements IPoNewsService {
  21. @Autowired
  22. private PoNewsMapper poNewsMapper;
  23. /**
  24. * 根据Id查询
  25. *
  26. * @param newsId
  27. * @return
  28. */
  29. @Override
  30. public List<PoNews> selectPoNewsByNewsId(String newsId) {
  31. List list = new ArrayList();
  32. List<PoNews> poNewsList =new ArrayList<>();
  33. poNewsList.add(poNewsMapper.selectPoNewsByNewsId(newsId));
  34. List<PoNews> collect = poNewsList.stream().map((item) -> {
  35. PoNews poNews = new PoNews();
  36. //将所有消息数据拷贝到消息用户链接对象实例
  37. BeanUtils.copyProperties(item, poNews);
  38. List<PoNews> newsAndUserVos = poNewsMapper.selectUserByNewsId(newsId);
  39. list.add(newsAndUserVos);
  40. poNews.setPhonenumber(list.toString());
  41. return poNews;
  42. }).collect(Collectors.toList());
  43. return collect;
  44. }
  45. /**
  46. * 分页查询
  47. *
  48. * @param poNews
  49. * @return
  50. */
  51. @Override
  52. public List<PoNews> selectPoNewsList(PoNews poNews) {
  53. return poNewsMapper.selectPoNewsList(poNews);
  54. }
  55. /**
  56. * 新增
  57. *
  58. * @param poNews
  59. * @return
  60. */
  61. @Override
  62. public int insertPoNews(PoNews poNews) {
  63. poNews.setCreateTime(DateUtils.getNowDate());
  64. return poNewsMapper.insertPoNews(poNews);
  65. }
  66. /**
  67. * 修改
  68. *
  69. * @param poNews
  70. * @return
  71. */
  72. @Override
  73. public int updatePoNews(PoNews poNews) {
  74. poNews.setUpdateTime(DateUtils.getNowDate());
  75. return poNewsMapper.updatePoNews(poNews);
  76. }
  77. /**
  78. * 批量删除
  79. *
  80. * @param newsIds
  81. * @return
  82. */
  83. @Override
  84. public int deletePoNewsByNewsIds(String[] newsIds) {
  85. return poNewsMapper.deletePoNewsByNewsIds(newsIds);
  86. }
  87. /**
  88. * 删除
  89. *
  90. * @param newsId
  91. * @return
  92. */
  93. @Override
  94. public int deletePoNewsByNewsId(String newsId) {
  95. return poNewsMapper.deletePoNewsByNewsId(newsId);
  96. }
  97. /**
  98. * 校验标题是否重复
  99. *
  100. * @param poNews
  101. * @return
  102. */
  103. @Override
  104. public String checkPostNewsTitleUnique(PoNews poNews) {
  105. String poNewsId = StringUtils.isNull(poNews.getNewsId()) ? "消息不存在" : poNews.getNewsId();
  106. PoNews info = poNewsMapper.checkPostNewsTitleUnique(poNews.getNewsTitle());
  107. if (StringUtils.isNotNull(info) && info.getNewsId() != poNewsId) {
  108. return UserConstants.NOT_UNIQUE;
  109. }
  110. return UserConstants.UNIQUE;
  111. }
  112. /**
  113. * 搜索消息
  114. * @param title
  115. * @param newsTimeStart
  116. * @param newsTimeEnd
  117. * @return
  118. */
  119. @Override
  120. public List<PoNews> selectListByTitleAndTime(String title, Date newsTimeStart, Date newsTimeEnd) {
  121. if (title != null) {
  122. //标题不为空且开始时间和结束时间都不为空
  123. if (newsTimeStart != null && newsTimeEnd != null) {
  124. if (newsTimeStart.before(newsTimeEnd)) {
  125. return poNewsMapper.selectPoNewsListByTitleAndNewsTimeStartAndNewsTimeEnd(title, newsTimeStart, newsTimeEnd);
  126. }
  127. else if((newsTimeStart != null && newsTimeEnd == null) || (newsTimeStart == null && newsTimeEnd != null)) {
  128. //有一个时间不为空返回提示信息
  129. List list = new ArrayList();
  130. list.add("请选择正确的时间段");
  131. return list;
  132. }
  133. }
  134. else {//时间都为空
  135. return poNewsMapper.selectPoNewsListByTitle(title);
  136. }
  137. }
  138. //标题为空
  139. else {
  140. //时间不为空
  141. if (newsTimeStart != null && newsTimeEnd != null) {
  142. return poNewsMapper.selectPoNewsByTime(newsTimeStart, newsTimeEnd);
  143. }
  144. }
  145. //都为空执行分页查询
  146. PoNews poNews = new PoNews();
  147. return poNewsMapper.selectPoNewsList(poNews);
  148. }
  149. /**
  150. * 获取详细消息内容
  151. * @param newsId
  152. * @return
  153. */
  154. @Override
  155. public PoNews selectContentByNewsId(String newsId) {
  156. return poNewsMapper.selectContentByNewsId(newsId);
  157. }
  158. /**
  159. * 校验图片是否重复
  160. * @param poNews
  161. * @return
  162. */
  163. @Override
  164. public String checkPostNewsImageUnique(PoNews poNews) {
  165. String poNewsId = StringUtils.isNull(poNews.getNewsId()) ? "图片不存在" : poNews.getNewsId();
  166. PoNews info = poNewsMapper.checkPostNewsImageUnique(poNews.getImage());
  167. if (StringUtils.isNotNull(info) && info.getNewsId() != poNewsId) {
  168. return UserConstants.NOT_UNIQUE;
  169. }
  170. return UserConstants.UNIQUE;
  171. }
  172. /**
  173. * 校验时间是否相等
  174. * @param poNews
  175. * @return
  176. */
  177. @Override
  178. public String checkPostNewsTimeUnique(PoNews poNews) {
  179. String poNewsId = StringUtils.isNull(poNews.getNewsId())? "图片不存在" : poNews.getNewsId();
  180. PoNews info = poNewsMapper.checkPostNewsTimeUnique(poNews.getCreateTime());
  181. if (StringUtils.isNotNull(info) && info.getNewsId() != poNewsId){
  182. return UserConstants.NOT_UNIQUE;
  183. }
  184. return UserConstants.UNIQUE;
  185. }
  186. }