package com.ruoyi.system.utils; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.system.domain.PostCollections; import com.ruoyi.system.domain.vo.PostCollectionsVo; import com.ruoyi.system.mapper.PostCollectionsMapper; import com.ruoyi.system.mapper.PostCollectionsSystemMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Date; import java.util.Objects; import static com.ruoyi.common.utils.SecurityUtils.getUsername; @Component public class CollectionStatusJudgment { private static PostCollectionsSystemMapper postCollectionsSystemMapper; private static PostCollectionsMapper postCollectionsMapper; @Autowired public void setPostCollectionsSystemMapper(PostCollectionsSystemMapper postCollectionsSystemMapper) { CollectionStatusJudgment.postCollectionsSystemMapper = postCollectionsSystemMapper; } @Autowired public void setPostCollectionsMapper(PostCollectionsMapper postCollectionsMapper) { CollectionStatusJudgment.postCollectionsMapper = postCollectionsMapper; } /** * 如果已经上架,判断藏品状态时间 * * @param postCollectionsVo * @return 结果 */ public static void JudgmentTime(PostCollectionsVo postCollectionsVo) { Date nowDate = DateUtils.getNowDate(); Date startTime = postCollectionsVo.getStartTime(); Date endTime = postCollectionsVo.getEndTime(); //获取此藏品套系status Long systemId = postCollectionsVo.getSystemId(); String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId); if (Objects.equals(postCollectionsSystemStatus, "1")) { //判空 if (null != startTime && null != endTime) { /** * 判断时间 (0预售 /1已售尽 /2正在售卖 /3已过期) * 根据当前时间,对比售卖时间, * 当前时间小于售卖时间,该套系藏品为预售, * 当前时间大于售卖时间为已过期, * 当前时间在售卖时间之间并且数量大于0为正在售卖 * 其余情况已售尽 */ if (nowDate.before(startTime)) { postCollectionsVo.setStatus("0");//预售 } else if (nowDate.after(endTime)) { postCollectionsVo.setStatus("3");//已过期 } else if (startTime.before(nowDate) && endTime.after(nowDate) && postCollectionsVo.getCollectionsNumber() > 0) { postCollectionsVo.setStatus("2");//正在售卖 } else if (postCollectionsVo.getCollectionsNumber() == 0) { postCollectionsVo.setStatus("1");//售尽 } } } } /** * 如果未上架,令藏品状态为未上架 * * @param systemId * @return 结果 */ public static void JudgmentStatus(Long systemId) { PostCollections postCollections = new PostCollections(); String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId); //判断藏品套系是否上架,如果没上架,令藏品status全部置为未上架 if (null != postCollectionsSystemStatus) { if (Objects.equals(postCollectionsSystemStatus, "0")) { postCollections.setUpdateBy(getUsername()); postCollections.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getTime())); postCollections.setSystemId(systemId); //批量修改status,动态查询藏品列表 postCollectionsMapper.updatePostCollectionsStatus(postCollections); } else { //上架 } } } }