PostCollectionsSystemServiceImpl.java 9.2 KB

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