package com.hzs.activity.recommend.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.activity.base.param.ActivityParam;
import com.hzs.activity.base.service.IActivityService;
import com.hzs.activity.base.service.IAcApprovalLogService;
import com.hzs.activity.base.service.IAcBaseConfigService;
import com.hzs.activity.base.service.IAcGoalMemberConfigService;
import com.hzs.activity.base.vo.AcGiftConfigVO;
import com.hzs.activity.base.vo.BaseConfigVo;
import com.hzs.activity.pick.service.IAcPickService;
import com.hzs.activity.recommend.mapper.AcRepurCouponsRuleConfigMapper;
import com.hzs.activity.recommend.param.AcRecommendParam;
import com.hzs.activity.recommend.service.*;
import com.hzs.activity.recommend.vo.*;

import com.hzs.activity.wares.service.IAcGiftConfigService;
import com.hzs.common.core.constant.SystemFieldConstants;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.utils.CommonUtil;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.domain.activity.base.AcApprovalLog;
import com.hzs.common.domain.activity.base.AcBaseConfig;
import com.hzs.common.domain.activity.base.AcGiftConfig;
import com.hzs.common.domain.activity.base.AcGoalMemberConfig;
import com.hzs.common.domain.activity.recommend.*;
import com.hzs.common.domain.activity.base.ext.AcGiftConfigExt;
import com.hzs.sale.product.IProductServiceApi;
import com.hzs.system.sys.IApprovalServiceApi;
import com.hzs.system.sys.dto.ApprovalBusinessResultDTO;
import com.hzs.system.sys.dto.ApprovalSubmitDTO;
import com.hzs.system.sys.dto.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 直推配置 服务实现类
 */
@Slf4j
@Service
public class AcRepurCouponsRuleConfigServiceImpl extends ServiceImpl<AcRepurCouponsRuleConfigMapper, AcRepurCouponsRuleConfig> implements IAcRepurCouponsRuleConfigService {

    @Autowired
    IActivityService IActivityService;

    @Autowired
    IAcRecomUpgradeRuleConfigService recomUpgradeRuleConfigService;

    @Autowired
    IAcGiftConfigService giftConfigService;

    @Autowired
    IAcBaseConfigService baseConfigService;

    @Autowired
    IAcApprovalLogService acApprovalLogService;

    @Autowired
    IAcRecomUpgradeRecordService acRecomUpgradeRecordService;

    @Autowired
    IAcPickService acPickService;

    @Autowired
    IAcGoalMemberConfigService acGoalMemberConfigService;

    @Autowired
    IAcRepurSharOrderTypeService acRepurSharOrderTypeService;

    @Autowired
    IAcRepurSharRuleConfigService acRepurSharRuleConfigService;

    @DubboReference
    IApprovalServiceApi approvalServiceApi;

    @DubboReference
    IProductServiceApi productServiceApi;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean onLinePetition(AcRecommendParam recommendParam) {
        List<Integer> atcModuleList = recommendParam.getActivityParam().getAtcModuleList();
        EApprovalBusiness approvalBusiness = EApprovalBusiness.DIRECT_PUSH_GIFT;
/*        for (Integer atcModule : atcModuleList) {
            switch (EActModule.getByValue(atcModule)) {
                case REPURCHASE_COUPON:
                    approvalBusiness = EApprovalBusiness.REPURCHASE_COUPON;
                    break;
                case DIRECT_PUSH_UPGRADE:
                    approvalBusiness = EApprovalBusiness.DIRECT_PUSH_UPGRADE;
                    break;
                default:
                    approvalBusiness = EApprovalBusiness.REPURCHASE_SHAR;
                    break;
            }
        }*/
        //根据产品ID查询产品名称
        List<AcRecommendUpgradeVO> recommendUpgradeList = recommendParam.getRecommendUpgradeList();
        if (CollUtil.isNotEmpty(recommendUpgradeList)) {
            for (AcRecommendUpgradeVO recommendUpgradeVO : recommendUpgradeList) {
                List<AcGiftConfigVO> giftConfigList = recommendUpgradeVO.getGiftConfigList();
                if (CollUtil.isNotEmpty(giftConfigList)) {
                    for (AcGiftConfigVO giftConfigVO : giftConfigList) {
                        Integer pkProduct = giftConfigVO.getPkProduct();
                        if (null != pkProduct) {
                            giftConfigVO.setProductName(productServiceApi.getProduct(pkProduct).getData().getProductName());
                        }
                    }
                }
            }
        }
        //提交审批
        return submitApproval(recommendParam, approvalBusiness);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public String ApprovalAgree(ApprovalBusinessResultDTO businessResult) {
        EApprovalBusiness eApprovalBusiness = businessResult.getEApprovalBusiness();
        String businessCode = businessResult.getBusinessCode();
        LoginUser loginUser = businessResult.getLoginUser();
        AcApprovalLog approvalLog = acApprovalLogService.queryApprovalLog(eApprovalBusiness, businessCode, loginUser.getDataCountry());
        if (null == approvalLog) {
            return "审批数据不存在！";
        }
        Integer controlType = approvalLog.getControlType();
        String data = approvalLog.getAfterData();
        if (StringUtils.isNotEmpty(data)) {
            AcRecommendParam recommendParam = JSONUtil.toBean(data, AcRecommendParam.class);
            if (controlType.equals(EControlType.SAVE.getValue())) {
                return saveRecommendData(recommendParam);
            } else if (controlType.equals(EControlType.MODIFY.getValue())) {
                deleteRecommendData(recommendParam);
                return saveRecommendData(recommendParam);
            } else {
                deleteRecommendData(recommendParam);
            }
        }
        //更新审批状态
        acApprovalLogService.updateApprovalLog(eApprovalBusiness, businessCode, loginUser.getDataCountry(),
                loginUser.getUserId(), EApproveRechargeStatus.AGREE, businessResult.getApproveRemark());
        return null;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public String ApprovalReject(ApprovalBusinessResultDTO businessResult) {
        EApprovalBusiness eApprovalBusiness = businessResult.getEApprovalBusiness();
        String businessCode = businessResult.getBusinessCode();
        LoginUser loginUser = businessResult.getLoginUser();
        AcApprovalLog approvalLog = acApprovalLogService.queryApprovalLog(eApprovalBusiness, businessCode, loginUser.getDataCountry());
        if (null == approvalLog) {
            return "审批数据不存在！";
        }
        //更新审批状态
        acApprovalLogService.updateApprovalLog(eApprovalBusiness, businessCode, loginUser.getDataCountry(),
                loginUser.getUserId(), EApproveRechargeStatus.REJECT, businessResult.getApproveRemark());
        return null;
    }

    /**
     * 保存直推赠送数据
     *
     * @param recommendParam 入参
     * @return String
     */
    private String saveRecommendData(AcRecommendParam recommendParam) {
        //保存活动基本信息
        String message = saveBaseConfig(recommendParam);
        //保存复购券配置信息
        saveRepurchaseCouponsInfo(recommendParam);
        //保存直推升级配置信息
        saveRecommendUpgradeRuleInfo(recommendParam);
        //保存复购均分
        saveRepurchaseSharInfo(recommendParam);
        return message;
    }

    /**
     * 删除直推赠送数据
     *
     * @param recommendParam 入参
     * @return String
     */
    public String deleteRecommendData(AcRecommendParam recommendParam) {
        Long pkBaseId = recommendParam.getActivityParam().getPkId();
        Long pkModifyId = recommendParam.getPkMember();
        //删除活动基本信息
        baseConfigService.deleteBaseConfigById(pkBaseId, pkModifyId);
        acGoalMemberConfigService.deleteGoalMemberConfig(pkBaseId, pkModifyId);
        //删除复购券配置信息
        List<AcRepurchaseCouponsShowVO> repurchaseCouponsShowList = recommendParam.getRepurchaseCouponsShowList();
        if (CollUtil.isNotEmpty(repurchaseCouponsShowList)) {
            deleteCouponsRuleConfigByBaseId(pkBaseId, pkModifyId);
        }
        //删除直推升级配置信息
        List<AcRecommendUpgradeVO> recommendUpgradeList = recommendParam.getRecommendUpgradeList();
        if (CollUtil.isNotEmpty(recommendUpgradeList)) {
            recomUpgradeRuleConfigService.deleteUpgradeRuleConfigByBaseId(pkBaseId, pkModifyId);
        }
        //删除复购均分
        AcRecommendSharVO acRecommendSharVO = recommendParam.getAcRecommendSharVO();
        if (null != acRecommendSharVO && CollUtil.isNotEmpty(acRecommendSharVO.getOrderTypeList())) {
            AcRepurSharRuleConfig repurSharRuleConfig = acRepurSharRuleConfigService.selectAcRepurSharRuleConfigByBaseId(pkBaseId);
            if (null == repurSharRuleConfig) {
                return "复购均分规则配置不存在！";
            }
            acRepurSharRuleConfigService.deleteSharRuleConfigByActivityId(pkBaseId, pkModifyId);
            acRepurSharOrderTypeService.deleteSharOrderTypeByRuleId(repurSharRuleConfig.getPkId(), pkModifyId);
        }
        return null;
    }


    /**
     * 保存活动基本信息
     *
     * @param recommendParam 入参
     * @return
     */
    private String saveBaseConfig(AcRecommendParam recommendParam) {
        ActivityParam activityParam = recommendParam.getActivityParam();
        if (null == activityParam) {
            return "没有活动的基本信息！";
        }
        List<AcRecommendUpgradeVO> recommendUpgradeList = recommendParam.getRecommendUpgradeList();
        if (CollUtil.isNotEmpty(recommendUpgradeList)) {
            activityParam.setAtcModule(EActModule.DIRECT_PUSH_UPGRADE.getValue());
        }
        activityParam.setActType(EActType.DIRECT_PUSH_GIFT.getValue());
        //保存基础配置
        activityParam.setPkCreator(recommendParam.getPkMember());
        activityParam.setPkCountry(recommendParam.getPkCountry());
        AcBaseConfig acBaseConfig = IActivityService.saveBaseConfig(activityParam);
        recommendParam.setPkBaseId(acBaseConfig.getPkId());
        IActivityService.saveGoalMemberConfig(activityParam, acBaseConfig);

        return null;
    }


    /**
     * 保存复购券配置信息
     *
     * @param recommendParam 入参
     * @return Boolean
     */
    private Boolean saveRepurchaseCouponsInfo(AcRecommendParam recommendParam) {
        List<AcRepurCouponsRuleConfig> repurCouponsRuleConfigList = new ArrayList<>();
        List<AcRepurchaseCouponsShowVO> repurchaseCouponsShowList = recommendParam.getRepurchaseCouponsShowList();
        if (CollUtil.isNotEmpty(repurchaseCouponsShowList)) {
            for (AcRepurchaseCouponsShowVO repurchaseCouponsShowVO : repurchaseCouponsShowList) {
                repurCouponsRuleConfigList.addAll(getRepurchaseCouponsRuleConfig(recommendParam, repurchaseCouponsShowVO));
            }

        }
        return saveBatch(repurCouponsRuleConfigList);
    }


    /**
     * 保存复购均分配置信息
     *
     * @param recommendParam 入参
     * @return Boolean
     */
    private Boolean saveRepurchaseSharInfo(AcRecommendParam recommendParam) {
        AcRecommendSharVO acRecommendSharVO = recommendParam.getAcRecommendSharVO();
        Long pkBaseId = recommendParam.getPkBaseId();
        if (null != acRecommendSharVO) {
            List<Integer> orderTypeList = acRecommendSharVO.getOrderTypeList();
            if (CollUtil.isNotEmpty(orderTypeList)) {
                AcRepurSharRuleConfig repurSharRuleConfig = AcRepurSharRuleConfig.builder().pkBaseId(pkBaseId)
                        .orderAmount(acRecommendSharVO.getOrderAmount()).orderAchieve(acRecommendSharVO.getOrderAchieve())
                        .ratioValue(acRecommendSharVO.getRatioValue()).build();
                repurSharRuleConfig.setPkCreator(recommendParam.getPkMember());
                repurSharRuleConfig.setPkCountry(recommendParam.getPkCountry());
                //复购券均分-规则配置信息
                acRepurSharRuleConfigService.save(repurSharRuleConfig);

                AcRepurSharOrderType repurSharOrderType;
                List<AcRepurSharOrderType> sharOrderTypes = new ArrayList<>();
                for (Integer orderType : orderTypeList) {
                    repurSharOrderType = AcRepurSharOrderType.builder().pkRuleId(repurSharRuleConfig.getPkId())
                            .orderType(orderType).build();
                    repurSharOrderType.setPkCreator(recommendParam.getPkMember());
                    repurSharOrderType.setPkCountry(recommendParam.getPkCountry());
                    sharOrderTypes.add(repurSharOrderType);
                }
                //复购券均分-订单类型
                acRepurSharOrderTypeService.saveBatch(sharOrderTypes);
            }
        }
        return true;
    }

    /**
     * 每个专区复购券规则配置
     *
     * @param recommendParam          直推赠送
     * @param repurchaseCouponsShowVO 专区复购券规则
     * @return List<AcRepurCouponsRuleConfig>
     */
    private List<AcRepurCouponsRuleConfig> getRepurchaseCouponsRuleConfig(AcRecommendParam recommendParam, AcRepurchaseCouponsShowVO repurchaseCouponsShowVO) {
        AcRepurCouponsRuleConfig repurCouponsRuleConfig;
        List<AcRepurCouponsRuleConfig> repurCouponsRuleConfigList = new ArrayList<>();
        //专区
        Integer orderType = repurchaseCouponsShowVO.getOrderType();
        List<AcRepurchaseCouponsVO> repurchaseCouponsList = repurchaseCouponsShowVO.getRepurchaseCouponsList();
        if (CollUtil.isNotEmpty(repurchaseCouponsList)) {
            //循环每个专区
            for (AcRepurchaseCouponsVO repurchaseCouponsVO : repurchaseCouponsList) {
                repurCouponsRuleConfig = AcRepurCouponsRuleConfig.builder().pkBaseId(recommendParam.getPkBaseId())
                        .orderType(orderType).orderAmount(repurchaseCouponsVO.getOrderAmount())
                        .orderAchieve(repurchaseCouponsVO.getOrderAchieve()).ratioType(repurchaseCouponsVO.getRatioType())
                        .ratioValue(repurchaseCouponsVO.getRatioValue()).build();
                repurCouponsRuleConfig.setPkCreator(recommendParam.getPkMember());
                repurCouponsRuleConfig.setPkCountry(recommendParam.getPkCountry());
                repurCouponsRuleConfigList.add(repurCouponsRuleConfig);
            }
        }
        return repurCouponsRuleConfigList;
    }


    /**
     * 保存直推升级配置信息
     *
     * @param recommendParam 直推信息
     * @return Boolean
     */
    private Boolean saveRecommendUpgradeRuleInfo(AcRecommendParam recommendParam) {
        AcRecomUpgradeRuleConfig recomUpgradeRuleConfig;
        //直推升级规则配置
        List<AcRecommendUpgradeVO> recommendUpgradeList = recommendParam.getRecommendUpgradeList();
        if (CollUtil.isNotEmpty(recommendUpgradeList)) {
            for (AcRecommendUpgradeVO recommendUpgradeVO : recommendUpgradeList) {
                recommendUpgradeVO.setPkCreator(recommendParam.getPkMember());
                recommendUpgradeVO.setPkCountry(recommendParam.getPkCountry());
                recomUpgradeRuleConfig = BeanUtil.copyProperties(recommendUpgradeVO, AcRecomUpgradeRuleConfig.class);
                recomUpgradeRuleConfig.setPkBaseId(recommendParam.getPkBaseId());
                recomUpgradeRuleConfigService.save(recomUpgradeRuleConfig);
                List<AcGiftConfig> giftConfigs = saveRecommendUpgradeGift(recommendUpgradeVO, recomUpgradeRuleConfig.getPkId());
                giftConfigService.saveBatch(giftConfigs);
            }
        }
        return true;
    }


    /**
     * 提交审批
     *
     * @param recommendParam 直推赠送参数
     */
    public Boolean submitApproval(AcRecommendParam recommendParam, EApprovalBusiness approvalBusiness) {
        //保存审批日志
        AcApprovalLog approvalLog = saveApprovalLog(recommendParam, approvalBusiness);
        ApprovalSubmitDTO approvalSubmitDTO = ApprovalSubmitDTO.builder().eApprovalBusiness(approvalBusiness)
                .businessCode(approvalLog.getBusinessCode())
                .signType(ESignType.getEnumByValue(recommendParam.getSignType())).userIdList(recommendParam.getUserIdList())
                .sendIdList(recommendParam.getSendIdList()).remark(recommendParam.getRemark()).build();
        R<String> submit = approvalServiceApi.submit(approvalSubmitDTO, recommendParam.getLoginUser());
        if (!submit.isSuccess()) {
            throw new RuntimeException("直推赠送提交审批失败！");
        }
        return submit.isSuccess();
    }

    /**
     * 保存活动审批日志信息
     *
     * @param recommendParam   直推赠送参数
     * @param approvalBusiness 审批业务
     * @return boolean
     */
    public AcApprovalLog saveApprovalLog(AcRecommendParam recommendParam, EApprovalBusiness approvalBusiness) {
        String detailJson = null;
        Integer controlType = recommendParam.getControlType();
        //查询变更前的数据
        Long pkBaseId = recommendParam.getActivityParam().getPkId();
        if (null != pkBaseId) {
            String detail = JSONUtil.toJsonStr(showDetailInfo(pkBaseId, recommendParam.getPkCountry()));
            detailJson = null != detail ? JSONUtil.toJsonStr(detail) : null;
        }

        String afterData = JSONUtil.toJsonStr(recommendParam);
        String beforeData = controlType.equals(EControlType.MODIFY.getValue()) ? detailJson : null;
        //业务单号
        String businessCode = CommonUtil.createSerialNumber(EOrderPrefix.ACTIVITY_CODE.getValue());
        AcApprovalLog approvalLog = AcApprovalLog.builder().approvalType(approvalBusiness.getValue())
                .beforeData(beforeData).businessCode(businessCode).controlType(controlType)
                .approvalStatus(EApproveRechargeStatus.WAIT.getValue()).afterData(afterData)
                .build();
        approvalLog.setPkCreator(recommendParam.getPkMember());
        approvalLog.setPkCountry(recommendParam.getPkCountry());
        acApprovalLogService.save(approvalLog);
        return approvalLog;
    }

    /**
     * 直推升级赠品
     *
     * @param recommendUpgradeVO 直推升级赠品VO
     * @param pkRuleId           规则ID
     * @return List<AcGiftConfig>
     */
    public List<AcGiftConfig> saveRecommendUpgradeGift(AcRecommendUpgradeVO recommendUpgradeVO, Long pkRuleId) {
        AcGiftConfig giftConfig;
        List<AcGiftConfig> giftConfigList = new ArrayList<>();
        List<AcGiftConfigVO> giftConfigVOList = recommendUpgradeVO.getGiftConfigList();
        if (CollUtil.isNotEmpty(giftConfigVOList)) {
            for (AcGiftConfigVO giftConfigVO : giftConfigVOList) {
                if (null == giftConfigVO.getPkProduct()) {
                    continue;
                }
                giftConfig = BeanUtil.copyProperties(giftConfigVO, AcGiftConfig.class);
                giftConfig.setPkCreator(recommendUpgradeVO.getPkCreator());
                giftConfig.setPkCountry(recommendUpgradeVO.getPkCountry());
                giftConfig.setPkRuleId(pkRuleId);
                giftConfig.setActType(EActType.DIRECT_PUSH_GIFT.getValue());
                giftConfigList.add(giftConfig);
            }
        }
        return giftConfigList;
    }

    @Override
    public AcRecommendVO showDetailInfo(Long activityId, Integer pkCountry) {
        AcRecommendVO recommendVO = new AcRecommendVO();
        recommendVO.setPkBaseId(activityId);
        AcBaseConfig baseConfig = baseConfigService.getById(activityId);
        //查询目标用户群体
        List<AcGoalMemberConfig> acGoalMemberConfigs = acGoalMemberConfigService.selectMemberConfig(activityId);
        BaseConfigVo baseConfigVo = BeanUtil.copyProperties(baseConfig, BaseConfigVo.class);
        baseConfigVo.setGoalMemberConfigList(acGoalMemberConfigs);

        recommendVO.setPkBaseId(baseConfig.getPkId());
        recommendVO.setActivityParam(baseConfigVo);
        //查询复购券规则
        List<AcRepurCouponsRuleConfig> repurCouponsRuleConfigList = selectRuleConfigByActivityId(activityId);
        recommendVO.setRepurchaseCouponsShowList(conversionAcRepurchaseCouponsShowVO(repurCouponsRuleConfigList));
        //查询直推升级规则
        List<AcRecomUpgradeRuleConfig> recomUpgradeRuleConfigList = recomUpgradeRuleConfigService.selectByActivityId(activityId);
        recommendVO.setRecommendUpgradeList(conversionRecommendUpgradeVO(recomUpgradeRuleConfigList, pkCountry));
        //复购券均分
        AcRepurSharRuleConfig repurSharRuleConfig = acRepurSharRuleConfigService.selectAcRepurSharRuleConfigByBaseId(activityId);
        if (null != repurSharRuleConfig) {
            List<AcRepurSharOrderType> repurSharOrderTypes = acRepurSharOrderTypeService.selectSharOrderByRuleId(repurSharRuleConfig.getPkId());
            //订单类型
            List<Integer> orderTypeList = repurSharOrderTypes.stream().map(AcRepurSharOrderType::getOrderType).collect(Collectors.toList());

            AcRecommendSharVO recommendSharVO = BeanUtil.copyProperties(repurSharRuleConfig, AcRecommendSharVO.class);
            recommendSharVO.setOrderTypeList(orderTypeList);
            recommendVO.setAcRecommendSharVO(recommendSharVO);
        }

        return recommendVO;
    }

    /**
     * 转化推荐升级
     *
     * @param recomUpgradeRuleConfigList 推荐升级
     * @param pkCountry                  国家ID
     * @return List<AcRecommendUpgradeVO>
     */
    private List<AcRecommendUpgradeVO> conversionRecommendUpgradeVO(List<AcRecomUpgradeRuleConfig> recomUpgradeRuleConfigList, Integer pkCountry) {
        List<AcRecommendUpgradeVO> recommendUpgradeVOList = new ArrayList<>();
        if (CollUtil.isNotEmpty(recomUpgradeRuleConfigList)) {
            AcRecommendUpgradeVO acRecommendUpgradeVO;
            List<Long> ruleId = recomUpgradeRuleConfigList.stream().map(AcRecomUpgradeRuleConfig::getPkId).collect(Collectors.toList());
            Map<Long, List<AcGiftConfigExt>> listMap = giftConfigService.queryListByRuleIdList(ruleId, pkCountry);
            for (AcRecomUpgradeRuleConfig recomUpgradeRuleConfig : recomUpgradeRuleConfigList) {
                acRecommendUpgradeVO = BeanUtil.copyProperties(recomUpgradeRuleConfig, AcRecommendUpgradeVO.class);
                //赠品
                List<AcGiftConfigVO> giftConfigList = BeanUtil.copyToList(listMap.get(recomUpgradeRuleConfig.getPkId()), AcGiftConfigVO.class);
                acRecommendUpgradeVO.setGiftConfigList(giftConfigList);
                recommendUpgradeVOList.add(acRecommendUpgradeVO);
            }
        }
        return recommendUpgradeVOList;
    }

    /**
     * 转化直推复购券VO
     *
     * @param repurCouponsRuleConfigList 直推复购券
     * @return List<AcRepurchaseCouponsShowVO>
     */
    private List<AcRepurchaseCouponsShowVO> conversionAcRepurchaseCouponsShowVO(List<AcRepurCouponsRuleConfig> repurCouponsRuleConfigList) {
        List<AcRepurchaseCouponsShowVO> showVOList = new ArrayList<>();
        AcRepurchaseCouponsShowVO repurchaseCouponsShowVO = null;
        if (CollUtil.isNotEmpty(repurCouponsRuleConfigList)) {
            AcRepurchaseCouponsVO acRepurchaseCouponsVO;
            List<AcRepurchaseCouponsVO> repurchaseCouponsVOList;
            //转换每个专区的配置
            Map<Integer, List<AcRepurCouponsRuleConfig>> map = repurCouponsRuleConfigList.stream().collect(Collectors.groupingBy(AcRepurCouponsRuleConfig::getOrderType));
            //封装AcRepurchaseCouponsShowVO
            for (Map.Entry<Integer, List<AcRepurCouponsRuleConfig>> entry : map.entrySet()) {
                repurchaseCouponsShowVO = new AcRepurchaseCouponsShowVO();
                repurchaseCouponsVOList = new ArrayList<>();
                //循环每个分区
                repurchaseCouponsShowVO.setOrderType(entry.getKey());
                for (AcRepurCouponsRuleConfig repurCouponsRuleConfig : entry.getValue()) {
                    acRepurchaseCouponsVO = BeanUtil.copyProperties(repurCouponsRuleConfig, AcRepurchaseCouponsVO.class);
                    repurchaseCouponsVOList.add(acRepurchaseCouponsVO);
                }
                repurchaseCouponsShowVO.setRepurchaseCouponsList(repurchaseCouponsVOList);
                showVOList.add(repurchaseCouponsShowVO);
            }
        }
        return showVOList;
    }

    public List<AcRepurCouponsRuleConfig> selectRuleConfigByActivityId(Long activityId) {
        QueryWrapper<AcRepurCouponsRuleConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PK_BASE_ID", activityId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public Boolean deleteRecommendConfig(Long activityId) {
        return null;
    }

    @Override
    public Boolean updateRecommendConfig(AcRecommendVO recommendVO) {
        return null;
    }

    @Override
    public Boolean deleteCouponsRuleConfigByBaseId(Long pkBaseId, Long pkModifyId) {
        UpdateWrapper<AcRepurCouponsRuleConfig> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set(SystemFieldConstants.DEL_FLAG, EDelFlag.DELETE.getValue());
        updateWrapper.set(SystemFieldConstants.PK_MODIFIED, pkModifyId);
        updateWrapper.set(SystemFieldConstants.MODIFIED_TIME, new Date());
        updateWrapper.eq("PK_BASE_ID", pkBaseId);
        return update(updateWrapper);
    }

}
