123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- package com.ruoyi.system.service.impl;
- import java.sql.Time;
- import java.text.SimpleDateFormat;
- import java.time.LocalDateTime;
- import java.util.Date;
- import java.util.List;
- import java.util.stream.Collectors;
- import com.fasterxml.jackson.annotation.JsonFormat;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.system.domain.vo.CollectionsVo;
- import com.ruoyi.system.mapper.PostCollectionsMapper;
- import com.ruoyi.system.service.IPostCollectionsService;
- import org.apache.commons.lang3.builder.ToStringExclude;
- import org.apache.ibatis.type.LocalDateTimeTypeHandler;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.format.annotation.DateTimeFormat;
- import org.springframework.stereotype.Service;
- import com.ruoyi.system.mapper.PostCollectionsSystemMapper;
- import com.ruoyi.system.domain.PostCollectionsSystem;
- import com.ruoyi.system.service.IPostCollectionsSystemService;
- import static com.ruoyi.common.utils.SecurityUtils.getUsername;
- /**
- * 藏品套系Service业务层处理
- *
- * @author ruoyi
- * @date 2023-02-15
- */
- @Service
- public class PostCollectionsSystemServiceImpl implements IPostCollectionsSystemService
- {
- @Autowired
- private PostCollectionsSystemMapper postCollectionsSystemMapper;
- /**
- * 查询藏品套系
- *
- * @param id 藏品套系主键
- * @return 藏品套系
- */
- @Override
- public PostCollectionsSystem selectPostCollectionsSystemById(Long id)
- {
- return postCollectionsSystemMapper.selectPostCollectionsSystemById(id);
- }
- /**
- * 查询藏品套系列表
- *
- * @param postCollectionsSystem 藏品套系
- * @return 藏品套系
- */
- @Override
- public List<PostCollectionsSystem> selectPostCollectionsSystemList(PostCollectionsSystem postCollectionsSystem)
- {
- return postCollectionsSystemMapper.selectPostCollectionsSystemList(postCollectionsSystem);
- }
- /**
- * 新增藏品套系
- *
- * @param postCollectionsSystem 藏品套系
- * @return 结果
- */
- @Override
- public int insertPostCollectionsSystem(PostCollectionsSystem postCollectionsSystem)
- {
- /**
- * 判断时间 (在售0/预售1/已过期2)
- * 根据当前时间,对比套系时间,当前小于套系时间,该套系藏品为“以过期”,
- * 当前时间大于套系时间为“预售”
- */
- Date nowDate = DateUtils.getNowDate();
- Date startTime = postCollectionsSystem.getStartTime();
- Date endTime = postCollectionsSystem.getEndTime();
- //当前时间早于套系时间 ->预售
- if (null!=startTime && null!=endTime){
- if (nowDate.before(startTime)){
- postCollectionsSystem.setType((long) 1);
- }
- else if (nowDate.after(endTime)){
- postCollectionsSystem.setType((long) 2);
- }
- else {
- postCollectionsSystem.setType((long) 0);
- }
- }
- //补充字段
- postCollectionsSystem.setCreateBy(getUsername());
- postCollectionsSystem.setCreateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
- postCollectionsSystem.setUpdateBy(getUsername());
- postCollectionsSystem.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
- return postCollectionsSystemMapper.insertPostCollectionsSystem(postCollectionsSystem);
- }
- /**
- * 修改藏品套系
- *
- * @param postCollectionsSystem 藏品套系
- * @return 结果
- */
- @Override
- public int updatePostCollectionsSystem(PostCollectionsSystem postCollectionsSystem)
- {
- //补充字段
- postCollectionsSystem.setUpdateBy(getUsername());
- postCollectionsSystem.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
- /*SimpleDateFormat formatter= new SimpleDateFormat("YYYY_MM_DD_HH_MM_SS");
- Date localDate = new Date(System.currentTimeMillis());
- Date startDate=postCollectionsSystem.getStartTime();
- Date endDate=postCollectionsSystem.getEndTime();
- if(localDate.after(startDate)){
- postCollectionsSystem.setType(Long.valueOf(1));
- }else if(startDate.after(localDate)&&endDate.after(localDate)){
- postCollectionsSystem.setType(Long.valueOf(0));
- }else {
- postCollectionsSystem.setType(Long.valueOf(2));
- }*/
- /**
- * 判断时间 (在售0/预售1/已过期2)
- * 根据当前时间,对比套系时间,当前小于套系时间,该套系藏品为“以过期”,
- * 当前时间大于套系时间为“预售”
- */
- Date nowDate = DateUtils.getNowDate();
- Date startTime = postCollectionsSystem.getStartTime();
- Date endTime = postCollectionsSystem.getEndTime();
- //当前时间早于套系时间 ->预售
- if (null!=startTime && null!=endTime){
- if (nowDate.before(startTime)){
- postCollectionsSystem.setType((long) 1);
- }
- else if (nowDate.after(endTime)){
- postCollectionsSystem.setType((long) 2);
- }
- else {
- postCollectionsSystem.setType((long) 0);
- }
- }
- return postCollectionsSystemMapper.updatePostCollectionsSystem(postCollectionsSystem);
- }
- /**
- * 批量删除藏品套系
- *
- * @param ids 需要删除的藏品套系主键
- * @return 结果
- */
- @Override
- public int deletePostCollectionsSystemByIds(Long[] ids)
- {
- return postCollectionsSystemMapper.deletePostCollectionsSystemByIds(ids);
- }
- /**
- * 删除藏品套系信息
- *
- * @param id 藏品套系主键
- * @return 结果
- */
- @Override
- public int deletePostCollectionsSystemById(Long id)
- {
- return postCollectionsSystemMapper.deletePostCollectionsSystemById(id);
- }
- /**
- * 套系搜索功能
- * @return
- */
- @Override
- public List<PostCollectionsSystem> selectByTitleAndTime(String title, Date TimeLeft, Date TimeRight) {
- if (title != null) {
- //标题不为空则判断时间
- if (TimeLeft != null && TimeRight != null) {
- if( TimeLeft.before(TimeRight)) {
- return postCollectionsSystemMapper.selectPostListByTitleOrTime(title, TimeLeft, TimeRight);
- }else {
- return null;
- }
- }else {
- //时间为空
- return postCollectionsSystemMapper.selectPostListByTitleOrTime(title, TimeLeft, TimeRight);
- }
- } else {
- //标题为空
- //确保查询到的公告为已发布的公告
- if (TimeLeft != null && TimeRight != null) {
- //时间不为空 ,且左时间在右时间之前
- if( TimeLeft.before(TimeRight)) {
- return postCollectionsSystemMapper.selectPostListByTitleOrTime(title, TimeLeft, TimeRight);
- }else {
- return null;
- }
- }
- }
- PostCollectionsSystem post = new PostCollectionsSystem();
- return postCollectionsSystemMapper.selectPostCollectionsSystemList(post);
- }
- /**
- * 获取该套系下 藏品数量
- * @param id
- * @return
- */
- @Override
- public int getCopies(Long id) {
- return postCollectionsSystemMapper.getCopiesById(id);
- }
- @Override
- public List<CollectionsVo> selectPostCollectionsSystemListPage(PostCollectionsSystem postCollectionsSystem) {
- List<PostCollectionsSystem> list = postCollectionsSystemMapper.selectPostCollectionsSystemList(postCollectionsSystem);
- List<CollectionsVo> collectionsVos=list.stream().map((item)->{
- // 创建 vo实体
- CollectionsVo collectionsVo=new CollectionsVo();
- BeanUtils.copyProperties(item,collectionsVo);
- // 获取套系id
- Long id = item.getId();
- //根据id 查询该套系藏品数量
- Integer copiesById = postCollectionsSystemMapper.getCopiesById(id);
- collectionsVo.setCopies(copiesById);
- return collectionsVo;
- }).collect(Collectors.toList());
- return collectionsVos;
- }
- @Override
- public int selectPostCollectionsSystemByName(PostCollectionsSystem postCollectionsSystem) {
- return postCollectionsSystemMapper.selectPostCollectionsSystemByName(postCollectionsSystem);
- }
- @Override
- public List<PostCollectionsSystem> listByIds(List<Long> ids) {
- return postCollectionsSystemMapper.selectPostCollectionsSystemByIds(ids);
- }
- @Override
- public int updateBatchById(List<PostCollectionsSystem> postCollectionsSystemList) {
- for (int i = 0; i < postCollectionsSystemList.size(); i++) {
- //补充字段
- postCollectionsSystemList.get(i). setUpdateBy(getUsername());
- postCollectionsSystemList.get(i).setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
- }
- return postCollectionsSystemMapper.updateBatchById(postCollectionsSystemList);
- }
- }
|