package com.ruoyi.system.service.impl; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.bean.BeanUtils; import com.ruoyi.system.domain.PoCollection; import com.ruoyi.system.domain.PoNews; import com.ruoyi.system.domain.PoTetherandcollection; import com.ruoyi.system.domain.vo.TetherVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.PoTetherMapper; import com.ruoyi.system.domain.PoTether; import com.ruoyi.system.service.IPoTetherService; /** * 套系Service业务层处理 * * @author ruoyi * @date 2023-02-12 */ @Service public class PoTetherServiceImpl implements IPoTetherService { @Autowired private PoTetherMapper poTetherMapper; /** * 在售 * @param poTether 套系 在售 * @return */ @Override public List selectPoTetherSellingList(PoTether poTether) { return poTetherMapper.selectPoTetherSellingList(poTether); } /** * 按照标题和时间搜索 * @param tetherName * @param tetherTimeStart * @param tetherTimeEnd * @return */ @Override public List selectListByTitleAndTime(String tetherName, Date tetherTimeStart, Date tetherTimeEnd) { if (tetherName != null) { //标题不为空且开始时间和结束时间都不为空 if (tetherTimeStart != null && tetherTimeEnd != null) { if (DateUtils.getNowDate().before(tetherTimeEnd)){ tetherTimeEnd = DateUtils.getNowDate(); } if (tetherTimeStart.before(tetherTimeEnd)) { return poTetherMapper.selectPoTetherListByTitleAndTetherTimeStartAndTetherTimeEnd(tetherName, tetherTimeStart, tetherTimeEnd); } else{ //有一个时间不为空返回提示信息 List list = new ArrayList(); list.add("请选择正确的时间段"); return list; } } else {//时间都为空 return poTetherMapper.selectPoTetherListByTitleAndTetherTimeStartAndTetherTimeEnd(tetherName,tetherTimeStart,tetherTimeEnd); } } //标题为空 else { //时间不为空 if (tetherTimeStart != null && tetherTimeEnd != null) { if (tetherTimeStart.before(tetherTimeEnd)){ return poTetherMapper.selectPoTetherListByTitleAndTetherTimeStartAndTetherTimeEnd(tetherName,tetherTimeStart,tetherTimeEnd); }else{ //有一个时间不为空返回提示信息 List list = new ArrayList(); list.add("请选择正确的时间段"); return list; } } } //都为空执行分页查询 PoTether poTether = new PoTether(); return poTetherMapper.selectPoTetherList(poTether); } /** * 预售 * @param poTether * @return */ @Override public List selectPoTetherAdvanceList(PoTether poTether) { return poTetherMapper.selectPoTetherAdvanceList(poTether); } /** * 已过期 * @param poTether * @return */ @Override public List selectPoTetherSelledList(PoTether poTether) { return poTetherMapper.selectPoTetherSelledList(poTether); } /** * 查询套系列表 * @param poTether * @return */ @Override public List selectPoTetherList(PoTether poTether) { return poTetherMapper.selectPoTetherList(poTether); } /** * 藏品按钮 * @param * @return */ @Override public List selectPoCollectionListById(Long tetherId) { return poTetherMapper.selectPoCollectionListById(tetherId); } /** * 新增套系 同时保存对应的藏品数据 * * @param tetherVo * @return */ @Override public boolean insertPoTetherWithCollection(TetherVo tetherVo) { //保存套系的基本数据到套系表tether this.poTetherMapper.insertPoTether(tetherVo); Long tetherId = tetherVo.getTetherId(); //套系包含藏品 List poCollections = tetherVo.getPoTetherandcollections(); poCollections.stream().map((item)->{ item.setTetherId(tetherId); return item; }).collect(Collectors.toList()); //保存藏品数据到藏品表 po_collection //后续添加代码 return true; } /** * 通过id查询套系信息和对应的藏品信息 * @param tetherId * @return */ @Override public TetherVo selectPoTetherByTetherIdWithCollection(Long tetherId) { //查询套系基本信息 po_tether PoTether poTether = this.poTetherMapper.selectPoTetherByTetherId(tetherId); TetherVo tetherVo = new TetherVo(); if (poTether != null) { BeanUtils.copyProperties(poTether, tetherVo); } //查询当前套系对应的藏品信息 //后续添加代码 return tetherVo; } /** * 修改套系信息 * @param tetherVo * @return */ @Override public boolean updatePoTetherWithCollection(TetherVo tetherVo) { //更新po_tether表基本信息 this.poTetherMapper.updatePoTether(tetherVo); //清理po_collection表数据 //添加当前提交过来的藏品数据--po_tether表的insert操作 return true; } /** * 同时删除套系和藏品的关联关系 * @param tetherIds * @return */ @Override public boolean deletePoTetherByTetherIdsWithCollection(Long[] tetherIds) { //查询藏品状态确认是否可以删除 //如果可以删除 先删除套系po_tether表中的数据 this.poTetherMapper.deletePoTetherByTetherIds(tetherIds); //删除po_collection表中的数据 return true; } /** * 校验套系名称是否存在 * @param tetherVo * @return */ @Override public String checkPostTetherNameUnique(TetherVo tetherVo) { Long tetherId = StringUtils.isNull(tetherVo.getTetherId()) ? -1L : tetherVo.getTetherId(); PoTether info = poTetherMapper.checkPostTetherTitleUnique(tetherVo.getTetherName()); if (StringUtils.isNotNull(info) && info.getTetherId() != tetherId) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; } /** * 检验图片是否重复 * @param tetherVo * @return */ @Override public String checkPostTetherImageUnique(TetherVo tetherVo) { Long tetherId = StringUtils.isNull(tetherVo.getTetherId()) ? -1L : tetherVo.getTetherId(); PoTether info = poTetherMapper.checkPostTetherImageUnique(tetherVo.getImage()); if (StringUtils.isNotNull(info) && info.getTetherId() != tetherId) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; } /** * 批量查询套系信息 * @param tetherIds * @return */ @Override public TetherVo selectPoTetherByTetherIdsWithCollection(Long[] tetherIds) { //查询套系基本信息 po_tether PoTether poTether = this.poTetherMapper.selectPoTetherByTetherIds(tetherIds); TetherVo tetherVo = new TetherVo(); if (poTether != null) { BeanUtils.copyProperties(poTether, tetherVo); } //查询当前套系对应的藏品信息 //后续添加代码 return tetherVo; } /** * 修改状态 是否上链 * @param cochain * @param tetherId * @return */ @Override public boolean updatePoTetherIsCochain(Integer cochain, Long tetherId) { return poTetherMapper.updatePoTetherIsCochain(cochain,tetherId); } /** * 修改状态 是否上架 * @param grounding * @param tetherId * @return */ @Override public boolean updatePoTetherIsGrounding(Integer grounding, Long tetherId) { return poTetherMapper.updatePoTetherIsGrounding(grounding, tetherId); } /** * 藏品种类个数 * @param poTether * @return */ @Override public List selectPoTetherCollectionList(PoTether poTether) { poTetherMapper.updatePostTetherCollection(poTether); return poTetherMapper.selectPoTetherCollectionList(poTether); } }