| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsInfoDTO; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageMcsInformationDTO; |
| | | import com.panzhihua.common.model.dtos.community.microCommercialStreet.SetShelfForInfoDTO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.microCommercialStreet.McsInformationVO; |
| | | import com.panzhihua.common.model.vos.community.microCommercialStreet.TopStatisticsVO; |
| | | import com.panzhihua.service_community.dao.McsGameDAO; |
| | | import com.panzhihua.service_community.dao.McsInformationDAO; |
| | | import com.panzhihua.service_community.dao.McsMerchantDAO; |
| | | import com.panzhihua.service_community.entity.McsInformation; |
| | | import com.panzhihua.service_community.entity.McsMerchant; |
| | | import com.panzhihua.service_community.service.McsInformationService; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * (McsInformation)表服务实现类 |
| | |
| | | public class McsInformationServiceImpl extends ServiceImpl<McsInformationDAO, McsInformation> |
| | | implements McsInformationService { |
| | | |
| | | @Resource |
| | | private McsGameDAO mcsGameDAO; |
| | | @Resource |
| | | private McsMerchantDAO mcsMerchantDAO; |
| | | |
| | | /** |
| | | * 分页查询戳戳资讯 |
| | | * @param pageMcsInformationDTO |
| | |
| | | */ |
| | | @Override |
| | | public R pageMcsInfo(PageMcsInformationDTO pageMcsInformationDTO) { |
| | | return null; |
| | | Page page = new Page<>(); |
| | | page.setSize(pageMcsInformationDTO.getPageSize()); |
| | | page.setCurrent(pageMcsInformationDTO.getPageNum()); |
| | | IPage<McsInformationVO> mcsInfos = this.baseMapper.pageMcsInfo(page, pageMcsInformationDTO); |
| | | return R.ok(mcsInfos); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public R setShelfForMcsInfo(SetShelfForInfoDTO setShelfForInfoDTO) { |
| | | return null; |
| | | McsInformation mcsInformation = this.baseMapper.selectById(setShelfForInfoDTO.getInfoId()); |
| | | if (isNull(mcsInformation)) { |
| | | return R.fail("修改数据不存在"); |
| | | } |
| | | Integer type = setShelfForInfoDTO.getType(); |
| | | if (type.equals(1)) { |
| | | //上架 |
| | | McsMerchant mcsMerchant = mcsMerchantDAO.selectById(mcsInformation.getMerchantId()); |
| | | Integer publishLimit = mcsMerchant.getPublishLimit(); |
| | | Integer publishCount = mcsGameDAO.selectPublishCount(mcsInformation.getMerchantId()); |
| | | if (publishCount >= publishLimit) { |
| | | return R.fail("空闲戳戳点不足"); |
| | | } |
| | | mcsInformation.setStatus(2); |
| | | } else if (type.equals(2)) { |
| | | //下架 |
| | | mcsInformation.setStatus(3); |
| | | } else { |
| | | return R.fail("未知错误"); |
| | | } |
| | | int num = this.baseMapper.updateById(mcsInformation); |
| | | if (num > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("修改失败,请重新尝试"); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public R deleteMcsInfo(Long infoId, Long userId) { |
| | | return null; |
| | | McsInformation mcsInformation = this.baseMapper.selectById(infoId); |
| | | if (isNull(mcsInformation)) { |
| | | return R.fail("修改数据不存在"); |
| | | } |
| | | mcsInformation.setIsDel(true); |
| | | mcsInformation.setStatus(McsInformation.Status.yxj); |
| | | mcsInformation.setUpdatedBy(userId); |
| | | int num = this.baseMapper.updateById(mcsInformation); |
| | | if (num > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("删除失败,请重新尝试"); |
| | | } |
| | | |
| | | /** |
| | | * 戳戳资讯顶部统计数据 |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getTopStatistics(Long userId) { |
| | | McsMerchant mcsMerchant = mcsMerchantDAO.selectOne(new QueryWrapper<McsMerchant>().lambda().eq(McsMerchant::getUserId, userId)); |
| | | if (isNull(mcsMerchant)) { |
| | | return R.fail("未查询到商家信息"); |
| | | } |
| | | TopStatisticsVO topStatisticsVO = new TopStatisticsVO(); |
| | | topStatisticsVO.setExpireAt(mcsMerchant.getExpireAt()); |
| | | |
| | | Integer publishLimit = mcsMerchant.getPublishLimit(); |
| | | Integer publishCount = mcsGameDAO.selectPublishCount(mcsMerchant.getId()); |
| | | Integer idleTotal = publishLimit - publishCount; |
| | | topStatisticsVO.setIdleTotal(idleTotal > 0 ? idleTotal : 0); |
| | | return R.ok(topStatisticsVO); |
| | | } |
| | | |
| | | /** |
| | | * 新增戳戳资讯 |
| | | * @param mcsInfoDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R addMcsInfo(McsInfoDTO mcsInfoDTO) { |
| | | Long userId = mcsInfoDTO.getCreatedBy(); |
| | | McsMerchant mcsMerchant = mcsMerchantDAO.selectOne(new QueryWrapper<McsMerchant>().lambda().eq(McsMerchant::getUserId, userId)); |
| | | if (isNull(mcsMerchant)) { |
| | | return R.fail("未查询到商家信息"); |
| | | } |
| | | McsInformation mcsInformation = new McsInformation(); |
| | | BeanUtils.copyProperties(mcsInfoDTO, mcsInformation); |
| | | mcsInformation.setMerchantId(mcsMerchant.getId()); |
| | | mcsInformation.setStatus(McsInformation.Status.wfb); |
| | | int num = this.baseMapper.insert(mcsInformation); |
| | | if (num > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("新增失败,请重新尝试"); |
| | | } |
| | | |
| | | /** |
| | | * 编辑戳戳资讯 |
| | | * @param mcsInfoDTO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R putMcsInfo(McsInfoDTO mcsInfoDTO) { |
| | | McsInformation mcsInformation = this.baseMapper.selectById(mcsInfoDTO.getId()); |
| | | if (isNull(mcsInformation)) { |
| | | return R.fail("资源不存在"); |
| | | } |
| | | BeanUtils.copyProperties(mcsInfoDTO, mcsInformation); |
| | | int num = this.baseMapper.updateById(mcsInformation); |
| | | if (num > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("编辑失败,请重新尝试"); |
| | | } |
| | | |
| | | /** |
| | | * 发布戳戳资讯 |
| | | * @param infoId |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R publishMcsInfo(Long infoId, Long userId) { |
| | | McsInformation mcsInformation = this.baseMapper.selectById(infoId); |
| | | if (isNull(mcsInformation)) { |
| | | return R.fail("资源不存在"); |
| | | } |
| | | McsMerchant mcsMerchant = mcsMerchantDAO.selectById(mcsInformation.getMerchantId()); |
| | | Integer publishLimit = mcsMerchant.getPublishLimit(); |
| | | Integer publishCount = mcsGameDAO.selectPublishCount(mcsInformation.getMerchantId()); |
| | | if (publishCount >= publishLimit) { |
| | | return R.fail("空闲戳戳点不足"); |
| | | } |
| | | mcsInformation.setStatus(McsInformation.Status.yfb); |
| | | mcsInformation.setPublishAt(new Date()); |
| | | int num = this.baseMapper.updateById(mcsInformation); |
| | | if (num > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("发布失败,请重新尝试"); |
| | | } |
| | | } |