CollectionStatusJudgment.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.ruoyi.system.utils;
  2. import com.ruoyi.common.utils.DateUtils;
  3. import com.ruoyi.system.domain.PostCollections;
  4. import com.ruoyi.system.domain.vo.PostCollectionsVo;
  5. import com.ruoyi.system.mapper.PostCollectionsMapper;
  6. import com.ruoyi.system.mapper.PostCollectionsSystemMapper;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Component;
  9. import java.util.Date;
  10. import java.util.Objects;
  11. import static com.ruoyi.common.utils.SecurityUtils.getUsername;
  12. @Component
  13. public class CollectionStatusJudgment {
  14. private static PostCollectionsSystemMapper postCollectionsSystemMapper;
  15. private static PostCollectionsMapper postCollectionsMapper;
  16. @Autowired
  17. public void setPostCollectionsSystemMapper(PostCollectionsSystemMapper postCollectionsSystemMapper) {
  18. CollectionStatusJudgment.postCollectionsSystemMapper = postCollectionsSystemMapper;
  19. }
  20. @Autowired
  21. public void setPostCollectionsMapper(PostCollectionsMapper postCollectionsMapper) {
  22. CollectionStatusJudgment.postCollectionsMapper = postCollectionsMapper;
  23. }
  24. /**
  25. * 如果已经上架,判断藏品状态时间
  26. *
  27. * @param postCollectionsVo
  28. * @return 结果
  29. */
  30. public static void JudgmentTime(PostCollectionsVo postCollectionsVo) {
  31. Date nowDate = DateUtils.getNowDate();
  32. Date startTime = postCollectionsVo.getStartTime();
  33. Date endTime = postCollectionsVo.getEndTime();
  34. //获取此藏品套系status
  35. Long systemId = postCollectionsVo.getSystemId();
  36. String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId);
  37. if (Objects.equals(postCollectionsSystemStatus, "1")) {
  38. //判空
  39. if (null != startTime && null != endTime) {
  40. /**
  41. * 判断时间 (0预售 /1已售尽 /2正在售卖 /3已过期)
  42. * 根据当前时间,对比售卖时间,
  43. * 当前时间小于售卖时间,该套系藏品为预售,
  44. * 当前时间大于售卖时间为已过期,
  45. * 当前时间在售卖时间之间并且数量大于0为正在售卖
  46. * 其余情况已售尽
  47. */
  48. if (nowDate.before(startTime)) {
  49. postCollectionsVo.setStatus("0");//预售
  50. } else if (nowDate.after(endTime)) {
  51. postCollectionsVo.setStatus("3");//已过期
  52. } else if (startTime.before(nowDate) &&
  53. endTime.after(nowDate) &&
  54. postCollectionsVo.getCollectionsNumber() > 0) {
  55. postCollectionsVo.setStatus("2");//正在售卖
  56. } else if (postCollectionsVo.getCollectionsNumber() == 0) {
  57. postCollectionsVo.setStatus("1");//售尽
  58. }
  59. }
  60. }
  61. }
  62. /**
  63. * 如果未上架,令藏品状态为未上架
  64. *
  65. * @param systemId
  66. * @return 结果
  67. */
  68. public static void JudgmentStatus(Long systemId) {
  69. PostCollections postCollections = new PostCollections();
  70. String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId);
  71. //判断藏品套系是否上架,如果没上架,令藏品status全部置为未上架
  72. if (null != postCollectionsSystemStatus) {
  73. if (Objects.equals(postCollectionsSystemStatus, "0")) {
  74. postCollections.setUpdateBy(getUsername());
  75. postCollections.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getTime()));
  76. postCollections.setSystemId(systemId);
  77. //批量修改status,动态查询藏品列表
  78. postCollectionsMapper.updatePostCollectionsStatus(postCollections);
  79. } else {
  80. //上架
  81. }
  82. }
  83. }
  84. }