PostCollectionsSystemServiceImpl.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. @Autowired
  35. private IPostCollectionsService postCollectionsService;
  36. /**
  37. * 查询藏品套系
  38. *
  39. * @param id 藏品套系主键
  40. * @return 藏品套系
  41. */
  42. @Override
  43. public PostCollectionsSystem selectPostCollectionsSystemById(Long id)
  44. {
  45. return postCollectionsSystemMapper.selectPostCollectionsSystemById(id);
  46. }
  47. /**
  48. * 查询藏品套系列表
  49. *
  50. * @param postCollectionsSystem 藏品套系
  51. * @return 藏品套系
  52. */
  53. @Override
  54. public List<PostCollectionsSystem> selectPostCollectionsSystemList(PostCollectionsSystem postCollectionsSystem)
  55. {
  56. return postCollectionsSystemMapper.selectPostCollectionsSystemList(postCollectionsSystem);
  57. }
  58. /**
  59. * 新增藏品套系
  60. *
  61. * @param postCollectionsSystem 藏品套系
  62. * @return 结果
  63. */
  64. @Override
  65. public int insertPostCollectionsSystem(PostCollectionsSystem postCollectionsSystem)
  66. {
  67. /**
  68. * 判断时间 (在售0/预售1/已过期2)
  69. * 根据当前时间,对比套系时间,当前小于套系时间,该套系藏品为“以过期”,
  70. * 当前时间大于套系时间为“预售”
  71. */
  72. Date nowDate = DateUtils.getNowDate();
  73. Date startTime = postCollectionsSystem.getStartTime();
  74. Date endTime = postCollectionsSystem.getEndTime();
  75. //当前时间早于套系时间 ->预售
  76. if (null!=startTime && null!=endTime){
  77. if (nowDate.before(startTime)){
  78. postCollectionsSystem.setType((long) 1);
  79. }
  80. else if (nowDate.after(endTime)){
  81. postCollectionsSystem.setType((long) 2);
  82. }
  83. else {
  84. postCollectionsSystem.setType((long) 0);
  85. }
  86. }
  87. //补充字段
  88. postCollectionsSystem.setCreateBy(getUsername());
  89. postCollectionsSystem.setCreateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
  90. postCollectionsSystem.setUpdateBy(getUsername());
  91. postCollectionsSystem.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
  92. return postCollectionsSystemMapper.insertPostCollectionsSystem(postCollectionsSystem);
  93. }
  94. /**
  95. * 修改藏品套系
  96. *
  97. * @param postCollectionsSystem 藏品套系
  98. * @return 结果
  99. */
  100. @Override
  101. public int updatePostCollectionsSystem(PostCollectionsSystem postCollectionsSystem)
  102. {
  103. //补充字段
  104. postCollectionsSystem.setUpdateBy(getUsername());
  105. postCollectionsSystem.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
  106. /*SimpleDateFormat formatter= new SimpleDateFormat("YYYY_MM_DD_HH_MM_SS");
  107. Date localDate = new Date(System.currentTimeMillis());
  108. Date startDate=postCollectionsSystem.getStartTime();
  109. Date endDate=postCollectionsSystem.getEndTime();
  110. if(localDate.after(startDate)){
  111. postCollectionsSystem.setType(Long.valueOf(1));
  112. }else if(startDate.after(localDate)&&endDate.after(localDate)){
  113. postCollectionsSystem.setType(Long.valueOf(0));
  114. }else {
  115. postCollectionsSystem.setType(Long.valueOf(2));
  116. }*/
  117. /**
  118. * 判断时间 (在售0/预售1/已过期2)
  119. * 根据当前时间,对比套系时间,当前小于套系时间,该套系藏品为“以过期”,
  120. * 当前时间大于套系时间为“预售”
  121. */
  122. Date nowDate = DateUtils.getNowDate();
  123. Date startTime = postCollectionsSystem.getStartTime();
  124. Date endTime = postCollectionsSystem.getEndTime();
  125. //当前时间早于套系时间 ->预售
  126. if (null!=startTime && null!=endTime){
  127. if (nowDate.before(startTime)){
  128. postCollectionsSystem.setType((long) 1);
  129. }
  130. else if (nowDate.after(endTime)){
  131. postCollectionsSystem.setType((long) 2);
  132. }
  133. else {
  134. postCollectionsSystem.setType((long) 0);
  135. }
  136. }
  137. return postCollectionsSystemMapper.updatePostCollectionsSystem(postCollectionsSystem);
  138. }
  139. /**
  140. * 批量删除藏品套系
  141. *
  142. * @param ids 需要删除的藏品套系主键
  143. * @return 结果
  144. */
  145. @Override
  146. public int deletePostCollectionsSystemByIds(Long[] ids)
  147. {
  148. return postCollectionsSystemMapper.deletePostCollectionsSystemByIds(ids);
  149. }
  150. /**
  151. * 删除藏品套系信息
  152. *
  153. * @param id 藏品套系主键
  154. * @return 结果
  155. */
  156. @Override
  157. public int deletePostCollectionsSystemById(Long id)
  158. {
  159. return postCollectionsSystemMapper.deletePostCollectionsSystemById(id);
  160. }
  161. /**
  162. * 套系搜索功能
  163. * @return
  164. */
  165. @Override
  166. public List<PostCollectionsSystem> selectByTitleAndTime(String title, Date TimeLeft, Date TimeRight) {
  167. if (title != null) {
  168. //标题不为空则判断时间
  169. if (TimeLeft != null && TimeRight != null) {
  170. if( TimeLeft.before(TimeRight)) {
  171. return postCollectionsSystemMapper.selectPostListByTitleOrTime(title, TimeLeft, TimeRight);
  172. }else {
  173. return null;
  174. }
  175. }else {
  176. //时间为空
  177. return postCollectionsSystemMapper.selectPostListByTitleOrTime(title, TimeLeft, TimeRight);
  178. }
  179. } else {
  180. //标题为空
  181. //确保查询到的公告为已发布的公告
  182. if (TimeLeft != null && TimeRight != null) {
  183. //时间不为空 ,且左时间在右时间之前
  184. if( TimeLeft.before(TimeRight)) {
  185. return postCollectionsSystemMapper.selectPostListByTitleOrTime(title, TimeLeft, TimeRight);
  186. }else {
  187. return null;
  188. }
  189. }
  190. }
  191. PostCollectionsSystem post = new PostCollectionsSystem();
  192. return postCollectionsSystemMapper.selectPostCollectionsSystemList(post);
  193. }
  194. /**
  195. * 获取该套系下 藏品数量
  196. * @param id
  197. * @return
  198. */
  199. @Override
  200. public int getCopies(Long id) {
  201. return postCollectionsSystemMapper.getCopiesById(id);
  202. }
  203. @Override
  204. public List<CollectionsVo> selectPostCollectionsSystemListPage(PostCollectionsSystem postCollectionsSystem) {
  205. List<PostCollectionsSystem> list = postCollectionsSystemMapper.selectPostCollectionsSystemList(postCollectionsSystem);
  206. List<CollectionsVo> collectionsVos=list.stream().map((item)->{
  207. // 创建 vo实体
  208. CollectionsVo collectionsVo=new CollectionsVo();
  209. BeanUtils.copyProperties(item,collectionsVo);
  210. // 获取套系id
  211. Long id = item.getId();
  212. //根据id 查询该套系藏品数量
  213. Integer copiesById = postCollectionsSystemMapper.getCopiesById(id);
  214. collectionsVo.setCopies(copiesById);
  215. return collectionsVo;
  216. }).collect(Collectors.toList());
  217. return collectionsVos;
  218. }
  219. @Override
  220. public int selectPostCollectionsSystemByName(PostCollectionsSystem postCollectionsSystem) {
  221. return postCollectionsSystemMapper.selectPostCollectionsSystemByName(postCollectionsSystem);
  222. }
  223. @Override
  224. public List<PostCollectionsSystem> listByIds(List<Long> ids) {
  225. return postCollectionsSystemMapper.selectPostCollectionsSystemByIds(ids);
  226. }
  227. @Override
  228. public int updateBatchById(List<PostCollectionsSystem> postCollectionsSystemList) {
  229. for (int i = 0; i < postCollectionsSystemList.size(); i++) {
  230. //更改藏品的状态
  231. postCollectionsService.selectPostCollectionsList(postCollectionsSystemList.get(i).getId());
  232. postCollectionsSystemList.get(i). setUpdateBy(getUsername());
  233. postCollectionsSystemList.get(i).setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
  234. }
  235. return postCollectionsSystemMapper.updateBatchById(postCollectionsSystemList);
  236. }
  237. }