jiangqs
2023-07-07 5627daeb1ac1a29947e902f9a7efb6730ed98611
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/activity/ActivityServiceImpl.java
@@ -1,6 +1,7 @@
package com.ruoyi.goods.service.impl.activity;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;
@@ -8,26 +9,36 @@
import com.ruoyi.goods.domain.dto.MgtActivityEditDto;
import com.ruoyi.goods.domain.dto.MgtActivityGoodsEditDto;
import com.ruoyi.goods.domain.dto.MgtActivityPageDto;
import com.ruoyi.goods.domain.dto.MgtActivityRecordPageDto;
import com.ruoyi.goods.domain.pojo.activity.Activity;
import com.ruoyi.goods.domain.pojo.activity.ActivityTotal;
import com.ruoyi.goods.domain.vo.MgtActivityGetVo;
import com.ruoyi.goods.domain.vo.MgtActivityGoodsListVo;
import com.ruoyi.goods.domain.vo.MgtActivityPageVo;
import com.ruoyi.goods.domain.vo.*;
import com.ruoyi.goods.mapper.activity.ActivityMapper;
import com.ruoyi.goods.service.activity.ActivityGoodsService;
import com.ruoyi.goods.service.activity.ActivityRecordService;
import com.ruoyi.goods.service.activity.ActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.goods.service.activity.ActivityTotalService;
import com.ruoyi.system.api.constant.AppErrorConstant;
import com.ruoyi.system.api.domain.dto.ActivityGoodsGetDto;
import com.ruoyi.system.api.domain.dto.MerPageDto;
import com.ruoyi.system.api.domain.dto.MgtBaseBathDto;
import com.ruoyi.system.api.domain.dto.MgtUserIdByKeywordDto;
import com.ruoyi.system.api.domain.poji.activity.ActivityGoods;
import com.ruoyi.system.api.domain.vo.ActivityGoodsGetVo;
import com.ruoyi.system.api.domain.vo.MgtSimpleMemberVo;
import com.ruoyi.system.api.domain.vo.MgtSimpleShopVo;
import com.ruoyi.system.api.domain.vo.MgtUserIdByKeywordVo;
import com.ruoyi.system.api.service.RemoteMemberService;
import com.ruoyi.system.api.service.RemoteShopService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -51,7 +62,14 @@
    private ActivityTotalService activityTotalService;
    @Resource
    private ActivityRecordService activityRecordService;
    @Resource
    private RemoteShopService remoteShopService;
    @Resource
    private RemoteMemberService remoteMemberService;
    /**
     * @param mgtActivityEditDto
     * @return void
@@ -133,6 +151,8 @@
                        activityGoods.setActivityNumber(dto.getActivityNumber());
                        activityGoods.setActivityDeadline(activity.getActivityEndTime());
                        activityGoods.setSellOutFlag(0);
                        activityGoods.setPurchaseLimitationFlag(activity.getPurchaseLimitationFlag());
                        activityGoods.setLimitNumber(activity.getLimitNumber());
                        return activityGoods;
                    }
            ).collect(Collectors.toList());
@@ -170,7 +190,9 @@
        //活动关联商户
        if(activity.getShopFlag()==2&&StringUtils.isNotBlank(activity.getApplicableShop())){
            String applicableShop = activity.getApplicableShop();
            List<MgtSimpleShopVo> mgtSimpleShopVoList= remoteShopService.listShopSimpleVoByIds(applicableShop).getData();
            MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto();
            mgtBaseBathDto.setIds(applicableShop);
            List<MgtSimpleShopVo> mgtSimpleShopVoList= remoteShopService.listShopSimpleVoByIds(mgtBaseBathDto).getData();
            mgtActivityGetVo.setMgtSimpleShopVosList(mgtSimpleShopVoList);
        }
        //活动关联商品
@@ -196,4 +218,140 @@
        activity.setActivityStatus(-1);
        this.saveOrUpdate(activity);
    }
    /**
     * @description 分页获取活动参与记录列表
     * @param mgtActivityRecordPageDto
     * @return MgtActivityRecordPageVo
     * @author jqs34
     * @date 2023/6/24 16:58
     */
    @Override
    public List<MgtActivityRecordPageVo> pageMgtActivityRecord(Page page, MgtActivityRecordPageDto mgtActivityRecordPageDto){
        if(StringUtils.isNotBlank(mgtActivityRecordPageDto.getKeyword())){
            MgtUserIdByKeywordDto mgtUserIdByKeywordDto = new MgtUserIdByKeywordDto();
            mgtUserIdByKeywordDto.setKeyword(mgtActivityRecordPageDto.getKeyword());
            MgtUserIdByKeywordVo mgtUserIdByKeywordVo = remoteMemberService.getUserIdByKeyword(mgtUserIdByKeywordDto).getData();
            if(StringUtils.isNotBlank(mgtUserIdByKeywordVo.getUserIds())){
                mgtActivityRecordPageDto.setUserIds(mgtUserIdByKeywordVo.getUserIds());
            }
        }
        List<MgtActivityRecordPageVo> activityRecordPageVoList = activityMapper.pageMgtActivityRecord(page, mgtActivityRecordPageDto);
        if(!activityRecordPageVoList.isEmpty()){
            // 定义变量
            HashSet<Long> userIdSet = new HashSet<>();
            // 遍历列表,用户 ID
            for (MgtActivityRecordPageVo mgtActivityRecordPageVo : activityRecordPageVoList) {
                userIdSet.add(mgtActivityRecordPageVo.getUserId());
            }
            // 将店铺 ID 和用户 ID 转换为逗号分隔的字符串
            String userJoinedString = String.join(",", userIdSet.stream().map(Object::toString).collect(Collectors.toList()));
            // 从远程服务获取店铺和用户信息
            MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto();
            mgtBaseBathDto = new MgtBaseBathDto();
            mgtBaseBathDto.setIds(userJoinedString);
            List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData();
            Map<Long, MgtSimpleMemberVo> userMap = simpleMemberVoList.stream()
                    .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity()));
            for (MgtActivityRecordPageVo mgtActivityRecordPageVo : activityRecordPageVoList) {
                mgtActivityRecordPageVo.setNickName(userMap.get(mgtActivityRecordPageVo.getUserId()).getNickName()+"/"+(userMap.get(mgtActivityRecordPageVo.getUserId()).getRealName()));
                mgtActivityRecordPageVo.setMobile(userMap.get(mgtActivityRecordPageVo.getUserId()).getUserMobile());
            }
        }
        return activityRecordPageVoList;
    }
    /**
     * @description  分页获取平台活动列表
     * @author  jqs
     * @date    2023/6/30 17:33
     * @param page
     * @param merPageDto
     * @return  List<MerActivityPageVo>
     */
    @Override
    public List<MerActivityPageVo> pagePlatformMerActivity(Page page, MerPageDto merPageDto){
        List<MerActivityPageVo> activityPageVoList = activityMapper.pagePlatformMerActivity(page, merPageDto);
        return activityPageVoList;
    }
    /**
     * @description  获取活动列表
     * @author  jqs
     * @date    2023/7/4 15:31
     * @param
     * @return  List<MgtActivityListVo>
     */
    @Override
    public List<MgtActivityListVo> listMgtActivity(){
        return activityMapper.listMgtActivity();
    }
    /**
     * @description  获取商户推荐活动
     * @author  jqs
     * @date    2023/7/4 18:14
     * @param shopId
     * @return  Activity
     */
    @Override
    public Activity getRecommendActivity(Long shopId){
        return activityMapper.getRecommendActivity(shopId);
    }
    /**
     * @description  获取商户参与活动id
     * @author  jqs
     * @date    2023/7/4 19:55
     * @param shopId
     * @return  List<Long>
     */
    @Override
    public List<String> listActivityIdByShopId(Long shopId){
        return activityMapper.listActivityIdByShopId(shopId);
    }
    /**
     * @description  分页获取活动列表
     * @author  jqs
     * @date    2023/7/5 18:45
     * @param page
     * @param shopId
     * @return  List<AppActivityPageVo>
     */
    @Override
    public List<AppActivityPageVo> pageAppActivity(Page page, Long shopId){
        return activityMapper.pageAppActivity(page, shopId);
    }
    /**
     * @description  获取用户活动商品信息
     * @author  jqs
     * @date    2023/7/6 16:18
     * @param activityGoodsGetDto
     * @return  ActivityGoodsGetVo
     */
    @Override
    public ActivityGoodsGetVo getUserActivityGoods(ActivityGoodsGetDto activityGoodsGetDto){
        ActivityGoodsGetVo activityGoodsGetVo = new ActivityGoodsGetVo();
        String activityId = activityGoodsGetDto.getActivityId();
        String goodsId = activityGoodsGetDto.getGoodsId();
        Activity activity = this.getById(activityId);
        ActivityGoods activityGoods = activityGoodsService.getByGoodsId(activityId,goodsId);
        activityGoodsGetVo.setActivityPrice(activityGoods.getActivityPrice());
        activityGoodsGetVo.setActivitySubscription(activityGoods.getActivitySubscription());
        activityGoodsGetVo.setActivityStatus(activity.getActivityStatus());
        Integer availableBuyNum = activityGoods.getActivityNumber() - activityGoods.getSalesNumber();
        //限购判断
        if(activityGoods.getPurchaseLimitationFlag()==1){
            Integer buyNum = activityRecordService.getUserActivityGoodsNum(goodsId,activityId,activityGoodsGetDto.getUserId());
            Integer limitBuyNum = activityGoods.getLimitNumber() - buyNum;
            if(limitBuyNum<availableBuyNum){
                availableBuyNum = limitBuyNum;
            }
        }
        activityGoodsGetVo.setPurchaseLimitationFlag(activity.getPurchaseLimitationFlag());
        activityGoodsGetVo.setAvailableBuyNum(availableBuyNum);
        return activityGoodsGetVo;
    }
}