PostCollectionsSystemServiceImpl.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package com.ruoyi.system.service.impl;
  2. import java.util.Date;
  3. import java.util.List;
  4. import java.util.stream.Collectors;
  5. import com.ruoyi.common.utils.DateUtils;
  6. import com.ruoyi.system.domain.vo.CollectionsVo;
  7. import org.springframework.beans.BeanUtils;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import com.ruoyi.system.mapper.PostCollectionsSystemMapper;
  11. import com.ruoyi.system.domain.PostCollectionsSystem;
  12. import com.ruoyi.system.service.IPostCollectionsSystemService;
  13. import static com.ruoyi.common.utils.SecurityUtils.getUsername;
  14. /**
  15. * 藏品套系Service业务层处理
  16. *
  17. * @author ruoyi
  18. * @date 2023-02-15
  19. */
  20. @Service
  21. public class PostCollectionsSystemServiceImpl implements IPostCollectionsSystemService
  22. {
  23. @Autowired
  24. private PostCollectionsSystemMapper postCollectionsSystemMapper;
  25. /**
  26. * 查询藏品套系
  27. *
  28. * @param id 藏品套系主键
  29. * @return 藏品套系
  30. */
  31. @Override
  32. public PostCollectionsSystem selectPostCollectionsSystemById(Long id)
  33. {
  34. return postCollectionsSystemMapper.selectPostCollectionsSystemById(id);
  35. }
  36. /**
  37. * 查询藏品套系列表
  38. *
  39. * @param postCollectionsSystem 藏品套系
  40. * @return 藏品套系
  41. */
  42. @Override
  43. public List<PostCollectionsSystem> selectPostCollectionsSystemList(PostCollectionsSystem postCollectionsSystem)
  44. {
  45. return postCollectionsSystemMapper.selectPostCollectionsSystemList(postCollectionsSystem);
  46. }
  47. /**
  48. * 新增藏品套系
  49. *
  50. * @param postCollectionsSystem 藏品套系
  51. * @return 结果
  52. */
  53. @Override
  54. public int insertPostCollectionsSystem(PostCollectionsSystem postCollectionsSystem)
  55. {
  56. /**
  57. * 判断时间 (在售0/预售1/已过期2)
  58. * 根据当前时间,对比套系时间,当前小于套系时间,该套系藏品为“以过期”,
  59. * 当前时间大于套系时间为“预售”
  60. */
  61. Date nowDate = DateUtils.getNowDate();
  62. Date startTime = postCollectionsSystem.getStartTime();
  63. Date endTime = postCollectionsSystem.getEndTime();
  64. //当前时间早于套系时间 ->预售
  65. if (null!=startTime && null!=endTime){
  66. if (nowDate.before(startTime)){
  67. postCollectionsSystem.setType((long) 1);
  68. }
  69. else if (nowDate.after(endTime)){
  70. postCollectionsSystem.setType((long) 2);
  71. }
  72. else {
  73. postCollectionsSystem.setType((long) 0);
  74. }
  75. }
  76. //补充字段
  77. postCollectionsSystem.setCreateBy(getUsername());
  78. postCollectionsSystem.setCreateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
  79. postCollectionsSystem.setUpdateBy(getUsername());
  80. postCollectionsSystem.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
  81. return postCollectionsSystemMapper.insertPostCollectionsSystem(postCollectionsSystem);
  82. }
  83. /**
  84. * 修改藏品套系
  85. *
  86. * @param postCollectionsSystem 藏品套系
  87. * @return 结果
  88. */
  89. @Override
  90. public int updatePostCollectionsSystem(PostCollectionsSystem postCollectionsSystem)
  91. {
  92. //补充字段
  93. postCollectionsSystem.setUpdateBy(getUsername());
  94. postCollectionsSystem.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
  95. return postCollectionsSystemMapper.updatePostCollectionsSystem(postCollectionsSystem);
  96. }
  97. /**
  98. * 批量删除藏品套系
  99. *
  100. * @param ids 需要删除的藏品套系主键
  101. * @return 结果
  102. */
  103. @Override
  104. public int deletePostCollectionsSystemByIds(Long[] ids)
  105. {
  106. return postCollectionsSystemMapper.deletePostCollectionsSystemByIds(ids);
  107. }
  108. /**
  109. * 删除藏品套系信息
  110. *
  111. * @param id 藏品套系主键
  112. * @return 结果
  113. */
  114. @Override
  115. public int deletePostCollectionsSystemById(Long id)
  116. {
  117. return postCollectionsSystemMapper.deletePostCollectionsSystemById(id);
  118. }
  119. /**
  120. * 套系搜索功能
  121. * @return
  122. */
  123. @Override
  124. public List<PostCollectionsSystem> selectByTitleAndTime(String title, Date TimeLeft, Date TimeRight) {
  125. if (title != null) {
  126. //标题不为空则判断时间
  127. if (TimeLeft != null && TimeRight != null) {
  128. if( TimeLeft.before(TimeRight)) {
  129. return postCollectionsSystemMapper.selectPostListByTitleOrTime(title, TimeLeft, TimeRight);
  130. }else {
  131. return null;
  132. }
  133. }else {
  134. //时间为空
  135. return postCollectionsSystemMapper.selectPostListByTitleOrTime(title, TimeLeft, TimeRight);
  136. }
  137. } else {
  138. //标题为空
  139. //确保查询到的公告为已发布的公告
  140. if (TimeLeft != null && TimeRight != null) {
  141. //时间不为空 ,且左时间在右时间之前
  142. if( TimeLeft.before(TimeRight)) {
  143. return postCollectionsSystemMapper.selectPostListByTitleOrTime(title, TimeLeft, TimeRight);
  144. }else {
  145. return null;
  146. }
  147. }
  148. }
  149. PostCollectionsSystem post = new PostCollectionsSystem();
  150. return postCollectionsSystemMapper.selectPostCollectionsSystemList(post);
  151. }
  152. /**
  153. * 获取该套系下 藏品数量
  154. * @param id
  155. * @return
  156. */
  157. @Override
  158. public int getCopies(Long id) {
  159. return postCollectionsSystemMapper.getCopiesById(id);
  160. }
  161. @Override
  162. public List<CollectionsVo> selectPostCollectionsSystemListPage(PostCollectionsSystem postCollectionsSystem) {
  163. List<PostCollectionsSystem> list = postCollectionsSystemMapper.selectPostCollectionsSystemList(postCollectionsSystem);
  164. List<CollectionsVo> collectionsVos=list.stream().map((item)->{
  165. // 创建 vo实体
  166. CollectionsVo collectionsVo=new CollectionsVo();
  167. BeanUtils.copyProperties(item,collectionsVo);
  168. // 获取套系id
  169. Long id = item.getId();
  170. //根据id 查询该套系藏品数量
  171. Integer copiesById = postCollectionsSystemMapper.getCopiesById(id);
  172. collectionsVo.setCopies(copiesById);
  173. return collectionsVo;
  174. }).collect(Collectors.toList());
  175. return collectionsVos;
  176. }
  177. @Override
  178. public int selectPostCollectionsSystemByName(PostCollectionsSystem postCollectionsSystem) {
  179. return postCollectionsSystemMapper.selectPostCollectionsSystemByName(postCollectionsSystem);
  180. }
  181. }