From 51ee3c4db2eb49062d3236bf44f95dc22f8f6ac9 Mon Sep 17 00:00:00 2001 From: puhanshu <a9236326> Date: 星期五, 14 一月 2022 17:59:03 +0800 Subject: [PATCH] 商业街bug修改 --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsInformationServiceImpl.java | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 252 insertions(+), 4 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsInformationServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsInformationServiceImpl.java index d4a1130..5952e34 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsInformationServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsInformationServiceImpl.java @@ -1,10 +1,37 @@ package com.panzhihua.service_community.service.impl; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.panzhihua.service_community.dao.McsInformationDAO; -import com.panzhihua.service_community.entity.McsInformation; -import com.panzhihua.service_community.service.McsInformationService; +import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; +import static org.apache.commons.lang3.StringUtils.isNotEmpty; + +import javax.annotation.Resource; + +import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsInfoDTO; +import com.panzhihua.common.model.vos.community.microCommercialStreet.McsGameVO; +import com.panzhihua.common.model.vos.community.microCommercialStreet.McsMerchantVO; +import com.panzhihua.common.utlis.DateUtils; +import com.panzhihua.service_community.util.NearbyUtil; +import com.spatial4j.core.shape.Rectangle; +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)表服务实现类 @@ -16,4 +43,225 @@ public class McsInformationServiceImpl extends ServiceImpl<McsInformationDAO, McsInformation> implements McsInformationService { + @Resource + private McsGameDAO mcsGameDAO; + @Resource + private McsMerchantDAO mcsMerchantDAO; + + /** + * 分页查询戳戳资讯 + * @param pageMcsInformationDTO + * @return + */ + @Override + public R pageMcsInfo(PageMcsInformationDTO pageMcsInformationDTO) { + Page page = new Page<>(); + page.setSize(pageMcsInformationDTO.getPageSize()); + page.setCurrent(pageMcsInformationDTO.getPageNum()); + IPage<McsInformationVO> mcsInfos = this.baseMapper.pageMcsInfo(page, pageMcsInformationDTO); + return R.ok(mcsInfos); + } + + /** + * 上架/下架戳戳资讯 + * @param setShelfForInfoDTO + * @return + */ + @Override + public R setShelfForMcsInfo(SetShelfForInfoDTO setShelfForInfoDTO) { + 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("修改失败,请重新尝试"); + } + + /** + * 删除戳戳资讯 + * @param infoId + * @param userId + * @return + */ + @Override + public R deleteMcsInfo(Long infoId, Long userId) { + 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()); + if (nonNull(mcsMerchant.getExpireAt())) { + int surplusLitDays = DateUtils.retrieveRemainingDays(mcsMerchant.getExpireAt()); + topStatisticsVO.setSurplusLitDays(surplusLitDays > 0 ? surplusLitDays : 0); + } + + 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("发布失败,请重新尝试"); + } + + /** + * h5分页查询戳戳资讯 + * @param pageMcsInformationDTO + * @return + */ + @Override + public R pageH5McsInfo(PageMcsInformationDTO pageMcsInformationDTO) { + Page page = new Page<>(); + page.setSize(pageMcsInformationDTO.getPageSize()); + page.setCurrent(pageMcsInformationDTO.getPageNum()); + String lat = pageMcsInformationDTO.getLat(); + String lon = pageMcsInformationDTO.getLon(); + Integer distance = pageMcsInformationDTO.getDistance(); + IPage<McsInformationVO> mcsInfos; + if (isNotEmpty(lat) && isNotEmpty(lon) && nonNull(distance)) { + Rectangle rectangle =new NearbyUtil().getRectangle(pageMcsInformationDTO.getDistance(), + Double.parseDouble(pageMcsInformationDTO.getLon()), Double.parseDouble(pageMcsInformationDTO.getLat())); + mcsInfos = this.baseMapper.pageH5McsInfo(page, rectangle.getMinX(), rectangle.getMaxX(), + rectangle.getMinY(), rectangle.getMaxY(), pageMcsInformationDTO); + } else { + mcsInfos = this.baseMapper.pageH5McsInfo(page, null, null, null, null, pageMcsInformationDTO); + } + return R.ok(mcsInfos); + } + + /** + * 资讯详情 + * @param infoId + * @return + */ + @Override + public R getMcsInfo(Long infoId) { + McsInformation mcsInformation = this.baseMapper.selectById(infoId); + if (isNull(mcsInformation)) { + return R.fail("资源不存在"); + } + McsInformationVO mcsInformationVO = new McsInformationVO(); + BeanUtils.copyProperties(mcsInformation, mcsInformationVO); + McsMerchant mcsMerchant = mcsMerchantDAO.selectById(mcsInformation.getMerchantId()); + McsMerchantVO mcsMerchantVO = new McsMerchantVO(); + if (nonNull(mcsMerchant)) { + mcsMerchantVO.setId(mcsMerchant.getId()); + mcsMerchantVO.setName(mcsMerchant.getName()); + mcsMerchantVO.setLogo(mcsMerchant.getLogo()); + mcsMerchantVO.setIntroduction(mcsMerchant.getIntroduction()); + mcsMerchantVO.setLat(mcsMerchant.getLat()); + mcsMerchantVO.setLon(mcsMerchant.getLon()); + mcsMerchantVO.setAddress(mcsMerchant.getAddress()); + } + mcsInformationVO.setMerchantInfo(mcsMerchantVO); + return R.ok(mcsInformationVO); + } } -- Gitblit v1.7.1