PostCollectionsSystemServiceImpl.java 6.3 KB

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