
package com.tmerclub.cloud.discount.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.tmerclub.cloud.api.multishop.bo.EsShopDetailBO;
import com.tmerclub.cloud.api.multishop.constant.ShopStatus;
import com.tmerclub.cloud.api.multishop.feign.ShopDetailFeignClient;
import com.tmerclub.cloud.api.multishop.vo.ShopDetailVO;
import com.tmerclub.cloud.api.platform.constant.OfflineHandleEventStatus;
import com.tmerclub.cloud.api.platform.constant.OfflineHandleEventType;
import com.tmerclub.cloud.api.platform.dto.OfflineHandleEventDTO;
import com.tmerclub.cloud.api.platform.feign.OfflineHandleEventFeignClient;
import com.tmerclub.cloud.api.platform.vo.OfflineHandleEventVO;
import com.tmerclub.cloud.common.cache.constant.CacheNames;
import com.tmerclub.cloud.common.cache.constant.DiscountCacheNames;
import com.tmerclub.cloud.common.cache.util.RedisUtil;
import com.tmerclub.cloud.common.constant.Constant;
import com.tmerclub.cloud.common.constant.SendTypeEnum;
import com.tmerclub.cloud.common.constant.StatusEnum;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.util.PageUtil;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.exception.LuckException;
import com.tmerclub.cloud.common.order.vo.DiscountOrderVO;
import com.tmerclub.cloud.common.order.vo.SendNotifyBO;
import com.tmerclub.cloud.common.response.ResponseEnum;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.discount.constant.DiscountStatusEnum;
import com.tmerclub.cloud.discount.constant.SuitableProdTypeEnum;
import com.tmerclub.cloud.discount.dto.DiscountDTO;
import com.tmerclub.cloud.discount.dto.DiscountItemDTO;
import com.tmerclub.cloud.discount.mapper.DiscountItemMapper;
import com.tmerclub.cloud.discount.mapper.DiscountMapper;
import com.tmerclub.cloud.discount.mapper.DiscountSpuMapper;
import com.tmerclub.cloud.discount.model.Discount;
import com.tmerclub.cloud.discount.model.DiscountSpu;
import com.tmerclub.cloud.discount.service.DiscountService;
import com.tmerclub.cloud.discount.vo.DiscountVO;
import io.seata.spring.annotation.GlobalTransactional;
import jakarta.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 满减满折优惠
 *
 * @author lhd
 * @date 2020-12-17 13:43:38
 */
@Service
public class DiscountServiceImpl implements DiscountService {

    @Autowired
    private DiscountMapper discountMapper;
    @Autowired
    private DiscountItemMapper discountItemMapper;
    @Autowired
    private DiscountSpuMapper discountSpuMapper;
    @DubboReference
    private ShopDetailFeignClient shopDetailFeignClient;
    @DubboReference
    private OfflineHandleEventFeignClient offlineHandleEventFeignClient;
    @Autowired
    private RocketMQTemplate sendActivityOfflineNotifyToShopTemplate;

    @Autowired
    private RocketMQTemplate sendActivityAuditNotifyToShopTemplate;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateDiscountAndItemAndSpu(DiscountDTO discount) {
        checkDiscountParam(discount);
        discountMapper.update(discount);

        discountItemMapper.deleteByDiscountId(discount.getDiscountId());

        discountSpuMapper.deleteByDiscountId(discount.getDiscountId());

        insertDiscountItemsAndDiscountSpu(discount);
    }

    private void checkDiscountParam(DiscountDTO discount) {
        ServerResponseEntity<EsShopDetailBO> shopResponseEntity = shopDetailFeignClient.getShopByShopId(discount.getShopId());
        EsShopDetailBO shopDetail = shopResponseEntity.getData();
        if (!shopResponseEntity.isSuccess() || Objects.isNull(shopDetail)) {
            throw new LuckException("店铺信息不存在");
        }
        if (ShopStatus.offlineOrDelete(shopDetail.getShopStatus())) {
            throw new LuckException("店铺处于违规下架状态，不能新增或修改满减活动");
        }
        // 每满一下减一次，需要(优惠金额上限 >= 优惠金额)
        if (Objects.equals(discount.getDiscountType(), 1)) {
            for (DiscountItemDTO discountItemDTO : discount.getDiscountItemList()) {
                if (discount.getMaxReduceAmount() < discountItemDTO.getDiscount()) {
                    throw new LuckException("优惠金额上限不能小于优惠金额");
                }
            }
        }
    }

    /**
     * 插入满减项
     *
     * @param discount 满减、满减项、关联spu信息
     */
    private void insertDiscountItemsAndDiscountSpu(DiscountDTO discount) {
        List<DiscountItemDTO> discountItems = discount.getDiscountItemList();
        for (DiscountItemDTO discountItem : discountItems) {
            if (discountItem.getNeedAmount() == null || discountItem.getDiscount() == null) {
                throw new LuckException("请填写完整满减信息");
            }
            discountItem.setDiscountId(discount.getDiscountId());
        }
        discountItemMapper.insertDiscountItems(discountItems);

        if (discount.getSuitableSpuType() != 0) {
            List<Long> spuIds = discount.getSpuIds();
            if (CollectionUtil.isNotEmpty(spuIds)) {
                List<DiscountSpu> discountSpuList = new ArrayList<>(Constant.INITIAL_CAPACITY);
                for (Long spuId : spuIds) {
                    DiscountSpu discountSpu = new DiscountSpu();
                    discountSpu.setDiscountId(discount.getDiscountId());
                    discountSpu.setSpuId(spuId);
                    discountSpuList.add(discountSpu);
                }
                discountSpuMapper.insertDiscountSpuList(discountSpuList);
            }
        }
    }

    @Override
    @Cacheable(cacheNames = DiscountCacheNames.DISCOUNT_BY_ID, key = "#discountId")
    public DiscountVO discountInfo(Long discountId) {
        DiscountVO discount = discountMapper.getDiscountAndSpu(discountId, StatusEnum.ENABLE.value());
        if (Objects.isNull(discount)) {
            throw new LuckException("当前活动已关闭");
        }
        ServerResponseEntity<EsShopDetailBO> shopResponEntity = shopDetailFeignClient.getShopByShopId(discount.getShopId());
        if (!shopResponEntity.isSuccess() || Objects.isNull(shopResponEntity.getData())) {
            throw new LuckException("店铺信息不存在");
        }
        EsShopDetailBO shopDetail = shopResponEntity.getData();
        discount.setShopLogo(shopDetail.getShopLogo());
        discount.setShopName(shopDetail.getShopName());

        long now = System.currentTimeMillis();

        // 活动还没结束
        if (discount.getEndTime().getTime() > now) {
            // 距离活动开始还有
            discount.setExpiresIn((int) (discount.getEndTime().getTime() - now) / 1000);
        }
        // 活动还没开始
        if (discount.getStartTime().getTime() > now) {
            // 距离活动开始还有
            discount.setStartIn((int) (discount.getStartTime().getTime() - now) / 1000);
        }
        // 活动还没开始
        if (discount.getStartTime().getTime() > now) {
            // 距离活动开始还有
            discount.setStartIn((int) (discount.getStartTime().getTime() - now) / 1000);
        }
        // 活动还没开始
        if (discount.getStartTime().getTime() > now) {
            // 距离活动开始还有
            discount.setStartIn((int) (discount.getStartTime().getTime() - now) / 1000);
        }
        // 活动还没开始
        if (discount.getStartTime().getTime() > now) {
            // 距离活动开始还有
            discount.setStartIn((int) (discount.getStartTime().getTime() - now) / 1000);
        }
        // 活动还没开始
        if (discount.getStartTime().getTime() > now) {
            // 距离活动开始还有
            discount.setStartIn((int) (discount.getStartTime().getTime() - now) / 1000);
        }
        return discount;
    }

    @Override
    public DiscountVO getDiscountAndSpu(Long discountId) {
        return discountMapper.getDiscountAndSpu(discountId, null);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    @CacheEvict(cacheNames = CacheNames.DISCOUNT_BY_SHOPID, key = "#discount.shopId")
    public void insertDiscountAndItemAndSpu(@Valid DiscountDTO discount) {
        checkDiscountParam(discount);
        discountMapper.save(discount);

        List<DiscountItemDTO> discountItems = discount.getDiscountItemList();
        if (CollectionUtil.isEmpty(discountItems)) {
            throw new LuckException("活动项不能为空，最少要有一个活动项");
        }
        insertDiscountItemsAndDiscountSpu(discount);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteDiscountsAndItemsAndSpuList(Long discountId, Long shopId) {
        int i = discountMapper.deleteDiscounts(discountId, shopId);
        if (i > 0) {
            discountItemMapper.deleteByDiscountId(discountId);
            discountSpuMapper.deleteByDiscountId(discountId);
        }
    }

    @Override
    @Caching(evict = {
            @CacheEvict(cacheNames = CacheNames.DISCOUNT_BY_ID, key = "#discountId"),
            @CacheEvict(cacheNames = CacheNames.DISCOUNT_BY_SHOPID, key = "#shopId")
    })
    public void removeDiscountCache(Long discountId, Long shopId) {
    }

    @Override
    @Cacheable(cacheNames = CacheNames.DISCOUNT_BY_SHOPID, key = "#shopId")
    public List<DiscountOrderVO> listDiscountsAndItemsByShopId(Long shopId) {
        return discountMapper.getDiscountsAndItemsByShopId(shopId);
    }

    @Override
    public List<DiscountVO> spuDiscountList(Long shopId, Long spuId) {
        List<DiscountVO> discountVOList = discountMapper.spuDiscountList(shopId, spuId);
        if (Objects.isNull(discountVOList)) {
            return new ArrayList<>(0);
        }
        return discountVOList;
    }

    @Override
    public PageVO<DiscountVO> getAppDiscountList(PageDTO page) {
        PageVO<DiscountVO> pageVO = PageUtil.doPage(page, () -> discountMapper.getDiscountList());
        Set<Long> shopIds = pageVO.getList().stream().map(DiscountVO::getShopId).collect(Collectors.toSet());
        if (CollUtil.isEmpty(shopIds)) {
            return pageVO;
        }
        ServerResponseEntity<List<ShopDetailVO>> response = shopDetailFeignClient.listByShopIds(new ArrayList<>(shopIds));
        Map<Long, ShopDetailVO> shopMap = response.getData().stream().collect(Collectors.toMap(ShopDetailVO::getShopId, s -> s));
        long now = System.currentTimeMillis();

        for (DiscountVO discountVO : pageVO.getList()) {
            ShopDetailVO shopDetailVO = shopMap.get(discountVO.getShopId());
            discountVO.setShopName(shopDetailVO.getShopName());
            discountVO.setShopLogo(shopDetailVO.getShopLogo());

            // 活动还没开始
            if (discountVO.getStartTime().getTime() > now) {
                // 距离活动开始还有
                discountVO.setStartIn((int) (discountVO.getStartTime().getTime() - now) / 1000);
            }
            // 活动还没结束
            if (discountVO.getEndTime().getTime() > now) {
                // 距离活动开始还有
                discountVO.setExpiresIn((int) (discountVO.getEndTime().getTime() - now) / 1000);
            }
        }
        return pageVO;
    }

    @Override
    public Discount getDiscountByDiscountId(Long discountId) {
        return discountMapper.getDiscountByDiscountId(discountId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<Long> updateDiscountSpuByIds(List<Long> spuIds) {
        // 查询出所有为可用商品类型的满减活动的，包含需要处理商品id，进行删除
        List<DiscountSpu> discountSpu = discountItemMapper.listDiscountBySpuIds(spuIds);
        List<Long> spuIdsDb = new ArrayList<>(Constant.INITIAL_CAPACITY);
        List<Long> ids = new ArrayList<>(Constant.INITIAL_CAPACITY);
        if (CollectionUtil.isNotEmpty(discountSpu)) {
            for (DiscountSpu spu : discountSpu) {
                ids.add(spu.getDiscountId());
                spuIdsDb.add(spu.getSpuId());
            }
            discountSpuMapper.deleteBySpuIds(spuIdsDb);
        }
        return ids;
    }

    @Override
    public PageVO<DiscountVO> page(PageDTO pageDTO, DiscountDTO transportDTO) {
        return PageUtil.doPage(pageDTO, () -> discountMapper.list(transportDTO));
    }

    @Override
    public PageVO<DiscountVO> platformPage(PageDTO pageDTO, DiscountDTO transportDTO) {
        if (StringUtils.isNotBlank(transportDTO.getShopName())) {
            ServerResponseEntity<List<Long>> shopIdsByLikeShopName = shopDetailFeignClient.getShopIdsByLikeShopName(transportDTO.getShopName());
            transportDTO.setShopIds(shopIdsByLikeShopName.getData());
        }
        PageVO<DiscountVO> page = PageUtil.doPage(pageDTO, () -> discountMapper.list(transportDTO));
        Set<Long> shopIdSet = page.getList().stream().map(DiscountVO::getShopId).collect(Collectors.toSet());
        ServerResponseEntity<List<ShopDetailVO>> shopResponse = shopDetailFeignClient.listByShopIds(new ArrayList<>(shopIdSet));
        if (CollUtil.isEmpty(shopResponse.getData())) {
            return page;
        }
        Map<Long, String> shopMap = shopResponse.getData().stream().collect(Collectors.toMap(ShopDetailVO::getShopId, ShopDetailVO::getShopName));
        for (DiscountVO discountVO : page.getList()) {
            discountVO.setShopName(shopMap.get(discountVO.getShopId()));
        }
        return page;
    }

    @Override
    public void changeDiscountStatus(Long discountId, Integer status) {
        DiscountDTO discountDTO = new DiscountDTO();
        discountDTO.setDiscountId(discountId);
        discountDTO.setStatus(status);
        discountMapper.update(discountDTO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    @GlobalTransactional(rollbackFor = Exception.class)
    public void offline(OfflineHandleEventDTO offlineHandleEventDto) {
        OfflineHandleEventDTO offlineHandleEvent = new OfflineHandleEventDTO();
        offlineHandleEvent.setHandleId(offlineHandleEventDto.getHandleId());
        offlineHandleEvent.setHandleType(OfflineHandleEventType.DISCOUNT.getValue());
        offlineHandleEvent.setOfflineReason(offlineHandleEventDto.getOfflineReason());
        ServerResponseEntity<Void> responseEntity = offlineHandleEventFeignClient.save(offlineHandleEvent);
        if (!Objects.equals(responseEntity.getCode(), ResponseEnum.OK.value())) {
            throw new LuckException(responseEntity.getMsg());
        }
        // 更新活动状态为下线状态
        changeDiscountStatus(offlineHandleEvent.getHandleId(), StatusEnum.OFFLINE.value());

        DiscountVO discountVO = getDiscountInfoById(offlineHandleEvent.getHandleId());
        //发送活动下线消息给店铺
        SendNotifyBO sendNotifyBO = new SendNotifyBO();
        sendNotifyBO.setSendType(SendTypeEnum.ACTIVITY_OFFLINE.getValue());
        sendNotifyBO.setShopId(discountVO.getShopId());
        sendNotifyBO.setActivityId(offlineHandleEvent.getHandleId());
        sendNotifyBO.setActivityName(discountVO.getDiscountName());
        SendStatus sendStockStatus = sendActivityOfflineNotifyToShopTemplate.syncSend(RocketMqConstant.SEND_ACTIVITY_OFFLINE_NOTIFY_TO_SHOP_TOPIC, new GenericMessage<>(sendNotifyBO)).getSendStatus();
        if (!Objects.equals(sendStockStatus, SendStatus.SEND_OK)) {
            throw new LuckException(ResponseEnum.EXCEPTION);
        }
    }

    @Override
    public OfflineHandleEventVO getOfflineHandleEvent(Long discountId) {
        ServerResponseEntity<OfflineHandleEventVO> offlineHandleEventResponse =
                offlineHandleEventFeignClient.getProcessingEventByHandleTypeAndHandleId(OfflineHandleEventType.DISCOUNT.getValue(), discountId, null);
        return offlineHandleEventResponse.getData();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    @GlobalTransactional(rollbackFor = Exception.class)
    public void audit(OfflineHandleEventDTO offlineHandleEventDto) {
        ServerResponseEntity<Void> responseEntity = offlineHandleEventFeignClient.auditOfflineEvent(offlineHandleEventDto);
        if (!Objects.equals(responseEntity.getCode(), ResponseEnum.OK.value())) {
            throw new LuckException(responseEntity.getMsg());
        }
        // 审核通过
        if (Objects.equals(offlineHandleEventDto.getStatus(), OfflineHandleEventStatus.AGREE_BY_PLATFORM.getValue())) {
            // 更新活动为等待投放状态、过期状态为未过期
            changeDiscountStatus(offlineHandleEventDto.getHandleId(), StatusEnum.DISABLE.value());
        }
        // 审核不通过
        else if (Objects.equals(offlineHandleEventDto.getStatus(), OfflineHandleEventStatus.DISAGREE_BY_PLATFORM.getValue())) {
            changeDiscountStatus(offlineHandleEventDto.getHandleId(), StatusEnum.OFFLINE.value());
        }
        //发送活动审核结果消息给店铺
        DiscountVO discountVO = getDiscountInfoById(offlineHandleEventDto.getHandleId());
        SendNotifyBO sendNotifyBO = new SendNotifyBO();
        sendNotifyBO.setSendType(SendTypeEnum.ACTIVITY_AUDIT.getValue());
        sendNotifyBO.setShopId(discountVO.getShopId());
        sendNotifyBO.setActivityId(offlineHandleEventDto.getHandleId());
        sendNotifyBO.setActivityName(discountVO.getDiscountName());
        SendStatus sendStockStatus = sendActivityAuditNotifyToShopTemplate.syncSend(RocketMqConstant.SEND_ACTIVITY_AUDIT_NOTIFY_TO_SHOP_TOPIC, new GenericMessage<>(sendNotifyBO)).getSendStatus();
        if (!Objects.equals(sendStockStatus, SendStatus.SEND_OK)) {
            throw new LuckException(ResponseEnum.EXCEPTION);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    @GlobalTransactional(rollbackFor = Exception.class)
    public void auditApply(OfflineHandleEventDTO offlineHandleEventDto) {
        // 更新事件状态
        ServerResponseEntity<Void> responseEntity = offlineHandleEventFeignClient.updateToApply(offlineHandleEventDto);
        if (!Objects.equals(responseEntity.getCode(), ResponseEnum.OK.value())) {
            throw new LuckException(responseEntity.getMsg());
        }
        // 更新活动为待审核状态
        changeDiscountStatus(offlineHandleEventDto.getHandleId(), StatusEnum.WAIT_AUDIT.value());
    }

    @Override
    public void closeDiscountBySetStatus() {
        // 查询时间已到期且未关闭的活动
        List<Discount> discountVOList = discountMapper.endDiscountList();
        if (CollUtil.isEmpty(discountVOList)) {
            return;
        }
        List<Long> discountIdList = new ArrayList<>(Constant.INITIAL_CAPACITY);
        Set<Long> shopSet = new HashSet<>(Constant.INITIAL_CAPACITY);
        // 删除缓存
        discountVOList.forEach((discount) -> {
            discountIdList.add(discount.getDiscountId());
            shopSet.add(discount.getShopId());
        });
        batchRemoveDiscountCache(discountIdList, shopSet);
        discountMapper.closeDiscountBySetStatus();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void handleSpuOffline(List<Long> spuIds, List<Long> shopIds) {
        List<DiscountVO> discountList = discountMapper.discountIdsBySpuIds(spuIds, shopIds);
        if (CollUtil.isEmpty(discountList)) {
            return;
        }
        List<Long> discountIds = new ArrayList<>(Constant.INITIAL_CAPACITY);
        List<Long> offlineList = new ArrayList<>(Constant.INITIAL_CAPACITY);
        Set<Long> shopSet = new HashSet<>(Constant.INITIAL_CAPACITY);
        for (DiscountVO discountVO : discountList) {
            discountIds.add(discountVO.getDiscountId());
            shopSet.add(discountVO.getShopId());
            // 活动不是启动状态，或 适用商品类型为：全部商品，则不进行后面的处理
            if (!Objects.equals(discountVO.getStatus(), StatusEnum.ENABLE.value())
                    || Objects.equals(SuitableProdTypeEnum.ALL_SPU.value(), discountVO.getSuitableSpuType())) {
                continue;
            }
            discountVO.getSpuIds().removeAll(spuIds);
            // 商品列表为空，则把活动添加到下线列表中
            if (CollUtil.isEmpty(discountVO.getSpuIds())) {
                offlineList.add(discountVO.getDiscountId());
            }
        }
        // 删除商品关联信息
        discountSpuMapper.deleteBySpuIds(spuIds);
        // 商品列表为空的活动进行下线
        if (CollUtil.isNotEmpty(offlineList)) {
            discountMapper.batchOfflineByDiscountIds(offlineList);
        }
        // 清除缓存
        batchRemoveDiscountCache(discountIds, shopSet);
    }

    @Override
    public DiscountVO getDiscountInfoById(Long discountId) {
        DiscountVO discount = discountMapper.getDiscountAndSpu(discountId, null);
        ServerResponseEntity<EsShopDetailBO> shopResponEntity = shopDetailFeignClient.getShopByShopId(discount.getShopId());
        EsShopDetailBO shopDetail = shopResponEntity.getData();
        discount.setShopName(shopDetail.getShopName());
        discount.setShopLogo(shopDetail.getShopLogo());

        long now = System.currentTimeMillis();

        // 活动还没开始
        if (discount.getStartTime().getTime() > now) {
            // 距离活动开始还有
            discount.setStartIn((int) (discount.getStartTime().getTime() - now) / 1000);
        }
        // 活动还没结束
        if (discount.getEndTime().getTime() > now) {
            // 距离活动开始还有
            discount.setExpiresIn((int) (discount.getEndTime().getTime() - now) / 1000);
        }
        return discount;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void handleShopOffline(List<Long> shopIds) {
        if (CollUtil.isEmpty(shopIds)) {
            return;
        }
        List<Long> discountIds = discountMapper.listIdByShopIdsAndStatus(shopIds, DiscountStatusEnum.RUN.getValue());
        if (CollUtil.isEmpty(discountIds)) {
            return;
        }
        // 删除商品关联信息
        discountSpuMapper.deleteBatchByDiscountIds(discountIds);
        // 活动下线
        discountMapper.batchOfflineByDiscountIds(discountIds);
        // 清除缓存
        batchRemoveDiscountCache(discountIds, new HashSet<>(shopIds));
    }

    /**
     * 批量清除缓存
     *
     * @param discountIds 活动id列表
     * @param shopIds     店铺id列表
     */
    private void batchRemoveDiscountCache(List<Long> discountIds, Set<Long> shopIds) {
        if (CollUtil.isEmpty(discountIds) || CollUtil.isEmpty(shopIds)) {
            return;
        }
        List<String> keys = new ArrayList<>(Constant.INITIAL_CAPACITY);
        for (Long discountId : discountIds) {
            keys.add(CacheNames.DISCOUNT_BY_ID + CacheNames.UNION + discountId);

        }
        for (Long shopId : shopIds) {
            keys.add(CacheNames.DISCOUNT_BY_SHOPID + CacheNames.UNION + shopId);
        }
        RedisUtil.deleteBatch(keys);
    }


}
