package com.bonus.canteen.core.marketing.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.allocation.api.AllocStallApi;
import com.bonus.canteen.core.allocation.canteen.vo.CanteenStallVO;
import com.bonus.canteen.core.auth.api.MgrAuthApi;
import com.bonus.canteen.core.customer.api.CustInfoApi;
import com.bonus.canteen.core.customer.utils.DelFlagEnum;
import com.bonus.canteen.core.drp.vo.DrpWarehouseAllVO;
import com.bonus.canteen.core.marketing.constants.MktEffTypeEnum;
import com.bonus.canteen.core.marketing.constants.MktUserTypeEnum;
import com.bonus.canteen.core.marketing.dto.MktEffectiveAddDTO;
import com.bonus.canteen.core.marketing.dto.MktEffectiveCanteenDTO;
import com.bonus.canteen.core.marketing.dto.MktEffectiveEditDTO;
import com.bonus.canteen.core.marketing.dto.MktEffectivePageDTO;
import com.bonus.canteen.core.marketing.mapper.MktEffectiveDetailMapper;
import com.bonus.canteen.core.marketing.mapper.MktEffectiveMapper;
import com.bonus.canteen.core.marketing.model.MktEffective;
import com.bonus.canteen.core.marketing.model.MktEffectiveDetail;
import com.bonus.canteen.core.marketing.service.MktEffectiveService;
import com.bonus.canteen.core.marketing.vo.*;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.houqin.constant.LeConstants;
import com.bonus.common.houqin.i18n.I18n;
import com.bonus.common.houqin.utils.CopyListUtil;
import com.bonus.common.houqin.utils.id.Id;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/** @deprecated */
@Deprecated
@Service
public class MktEffectiveServiceImpl extends ServiceImpl<MktEffectiveMapper, MktEffective> implements MktEffectiveService {
   private static final Logger log = LoggerFactory.getLogger(MktEffectiveServiceImpl.class);
   @Autowired
   @Lazy
   private AllocStallApi allocStallApi;
   @Autowired
   @Lazy
   private CustInfoApi custInfoApi;
   @Autowired
   @Lazy
   private MktEffectiveDetailMapper mktEffectiveDetailMapper;
   @Autowired
   @Lazy
   private MgrAuthApi mgrAuthApi;

   @Override
   @Transactional(rollbackFor = {Exception.class})
   public void addMktEffective(MktEffectiveAddDTO effectiveAddDTO) {
      String username = SecurityUtils.getUsername();
      Long effId = Id.next();
      MktEffective effective = new MktEffective();
      BeanUtil.copyProperties(effectiveAddDTO, effective, new String[0]);
      effective.setCrby(username);
      effective.setEffId(effId);
      this.baseMapper.insert(effective);
      Integer effType = effectiveAddDTO.getEffType();
      log.info("***生成限制 : {} 类型的生效范围***********", MktEffTypeEnum.getValue(effType));
      if (MktEffTypeEnum.USER_SORT.key().equals(effType)) {
         this.bindingUser(effectiveAddDTO.getOrgIdList(), effectiveAddDTO.getGradeIdList(), effectiveAddDTO.getPsnTypeList(), effId);
      } else if (MktEffTypeEnum.CANTEEN_SORT.key().equals(effType)) {
         this.bindingCanteen(effectiveAddDTO.getCanteenList(), effId);
      } else if (MktEffTypeEnum.PRODUCT_SORT.key().equals(effType)) {
         this.bindingProduct(effectiveAddDTO.getDishesIdList(), effectiveAddDTO.getPackageIdList(), effectiveAddDTO.getProductIdList(), effId);
      } else {
         if (!MktEffTypeEnum.WAREHOUSE_SORT.key().equals(effType)) {
            log.error("***接收到的生效范围类型 : {} 不太对,没办法新增生效范围***************", effType);
            throw new ServiceException(I18n.getMessage("mkt_error_param", new Object[0]));
         }

         this.bindingWarehouse(effectiveAddDTO.getWarehouseId(), effId);
      }

   }

   @Override
   public Page<MktEffectivePageVO> getMktEffectivePage(String content) {
      Map<String, JSONObject> contentMap = JSON.parseObject(content, Map.class);
      Page<MktEffective> page = (contentMap.get("page")).toJavaObject(Page.class);
      MktEffectivePageDTO effectivePageDTO = (contentMap.get("object")).toJavaObject(MktEffectivePageDTO.class);
      MktEffective effective = new MktEffective();
      BeanUtil.copyProperties(effectivePageDTO, effective, new String[0]);
      effective.setDelFlag(DelFlagEnum.DEL_FALSE.key());
      Page<MktEffective> effectivePage = this.baseMapper.selectPage(page, Wrappers.lambdaQuery(effective)
              .orderByDesc(MktEffective::getId));
      Page<MktEffectivePageVO> effectivePageVoPage = new Page(effectivePage.getCurrent(), effectivePage.getSize(), effectivePage.getTotal());
      List<MktEffective> records = effectivePage.getRecords();
      if (CollUtil.isEmpty(records)) {
         log.info("***查询出来的生效范围列表为空,直接返回前端空列表********************");
         return effectivePageVoPage;
      } else {
         List<MktEffectivePageVO> effectivePageVOList = CopyListUtil.copyListProperties(records, MktEffectivePageVO.class);
         Iterator<MktEffectivePageVO> var10 = effectivePageVOList.iterator();

         while(var10.hasNext()) {
            MktEffectivePageVO effectivePageVO = var10.next();
            Integer effType = effectivePageVO.getEffType();
            List<MktEffectiveDetail> effectiveDetailList;
            List<Long> warehouseIdList;
            List<Integer> packageId;
            if (MktEffTypeEnum.USER_SORT.key().equals(effType)) {
               effectiveDetailList = this.mktEffectiveDetailMapper.selectList(Wrappers.lambdaQuery(MktEffectiveDetail.class).eq(MktEffectiveDetail::getEffId, effectivePageVO.getEffId()));
               warehouseIdList = effectiveDetailList.stream().map(MktEffectiveDetail::getOrgId).filter((orgId) -> {
                  return !orgId.equals(-1L);
               }).collect(Collectors.toList());
               packageId = effectiveDetailList.stream().map(MktEffectiveDetail::getPsnType).filter((psnType) -> {
                  return !psnType.equals(-1);
               }).collect(Collectors.toList());
               effectivePageVO.setOrgIdList(warehouseIdList);
               effectivePageVO.setPsnTypeList(packageId);
            } else if (MktEffTypeEnum.CANTEEN_SORT.key().equals(effType)) {
               effectivePageVO.setCanteenList(this.mktEffectiveDetailMapper.selectCanteenList(effectivePageVO.getEffId()));
            } else if (MktEffTypeEnum.PRODUCT_SORT.key().equals(effType)) {
               effectiveDetailList = this.mktEffectiveDetailMapper.selectList(Wrappers.lambdaQuery(MktEffectiveDetail.class)
                       .eq(MktEffectiveDetail::getEffId, effectivePageVO.getEffId()));
               warehouseIdList = effectiveDetailList.stream().map(MktEffectiveDetail::getDishesId).filter((dishesId) -> {
                  return !dishesId.equals(-1L);
               }).collect(Collectors.toList());
               List<Long> thisPackageId = effectiveDetailList.stream().map(MktEffectiveDetail::getPackageId).filter((id) -> {
                  return !id.equals(-1L);
               }).collect(Collectors.toList());
               List<Long> productIdList = effectiveDetailList.stream().map(MktEffectiveDetail::getProductId).filter((productId) -> {
                  return !productId.equals(-1L);
               }).collect(Collectors.toList());
               effectivePageVO.setDishesIdList(warehouseIdList);
               effectivePageVO.setPackageId(thisPackageId);
               effectivePageVO.setProductIdList(productIdList);
            } else if (MktEffTypeEnum.WAREHOUSE_SORT.key().equals(effType)) {
               effectiveDetailList = this.mktEffectiveDetailMapper.selectList(Wrappers.lambdaQuery(MktEffectiveDetail.class).eq(MktEffectiveDetail::getEffId, effectivePageVO.getEffId()));
               warehouseIdList = effectiveDetailList.stream().map(MktEffectiveDetail::getWarehouseId).collect(Collectors.toList());
               effectivePageVO.setWarehouseId(warehouseIdList);
            }
         }

         return effectivePageVoPage.setRecords(effectivePageVOList);
      }
   }

   @Override
   public void editMktEffective(MktEffectiveEditDTO effectiveEditDTO) {
      String username = SecurityUtils.getUsername();
      Long effId = effectiveEditDTO.getEffId();
      if (effId == null) {
         log.error("***传入的生效范围id为空, 无法编辑******************");
         throw new ServiceException(I18n.getMessage("mkt_error_param", new Object[0]));
      } else {
         MktEffective effective = new MktEffective();
         BeanUtil.copyProperties(effectiveEditDTO, effective, new String[0]);
         effective.setUpby(username);
         this.baseMapper.update(effective, Wrappers.lambdaQuery(MktEffective.class).eq(MktEffective::getEffId, effId));
         this.mktEffectiveDetailMapper.delete(Wrappers.lambdaQuery(MktEffectiveDetail.class).eq(MktEffectiveDetail::getEffId, effId));
         Integer effType = this.baseMapper.selectOne(Wrappers.lambdaQuery(MktEffective.class)
                 .eq(MktEffective::getEffId, effId)).getEffType();
         log.info("***生成限制 : {} 类型的生效范围***********", MktEffTypeEnum.getValue(effType));
         if (MktEffTypeEnum.USER_SORT.key().equals(effType)) {
            this.bindingUser(effectiveEditDTO.getOrgIdList(), effectiveEditDTO.getGradeIdList(), effectiveEditDTO.getPsnTypeList(), effId);
         } else if (MktEffTypeEnum.CANTEEN_SORT.key().equals(effType)) {
            this.bindingCanteen(effectiveEditDTO.getCanteenList(), effId);
         } else if (MktEffTypeEnum.PRODUCT_SORT.key().equals(effType)) {
            this.bindingProduct(effectiveEditDTO.getDishesIdList(), effectiveEditDTO.getPackageIdList(), effectiveEditDTO.getProductIdList(), effId);
         } else {
            if (!MktEffTypeEnum.WAREHOUSE_SORT.key().equals(effType)) {
               log.error("***查询到的生效范围类型 : {} 不太对,没办法新增生效范围***************", effType);
               throw new ServiceException(I18n.getMessage("mkt_error_datasource", new Object[0]));
            }

            this.bindingWarehouse(effectiveEditDTO.getWarehouseId(), effId);
         }

      }
   }

   @Override
   public MktEffectiveByEffIdVO getMktEffectiveByEffId(Long effId) {
      return this.getMktEffectiveByEffIdPre(effId);
   }

   @Override
   public MktEffectiveByEffIdOrgVO getMktEffectiveByEffIdOrgType(Long effId) {
      MktEffective effective = this.baseMapper.selectOne(Wrappers.lambdaQuery(MktEffective.class)
              .eq(MktEffective::getEffId, effId));
      MktEffectiveByEffIdOrgVO effectiveByEffIdOrgVO = new MktEffectiveByEffIdOrgVO();
      if (effective == null) {
         return effectiveByEffIdOrgVO;
      } else {
         Integer effType = effective.getEffType();
         if (!MktEffTypeEnum.USER_SORT.key().equals(effType)) {
            log.error("***获取到的范围类型不是人员类范围,不可调用此接口*******************");
            throw new ServiceException(I18n.getMessage("mkt_error_range", new Object[0]));
         } else {
            List<MktEffectiveDetail> effectiveDetailList = this.mktEffectiveDetailMapper.selectList(Wrappers.lambdaQuery(MktEffectiveDetail.class).eq(MktEffectiveDetail::getEffId, effId));
            List<Long> orgIdList = effectiveDetailList.stream().map(MktEffectiveDetail::getOrgId).filter((orgId) -> {
               return !orgId.equals(-1L);
            }).collect(Collectors.toList());
            List<Integer> psnTypeList = effectiveDetailList.stream().map(MktEffectiveDetail::getPsnType).filter((psnType) -> {
               return !psnType.equals(-1);
            }).collect(Collectors.toList());
            BeanUtil.copyProperties(effective, effectiveByEffIdOrgVO, new String[0]);
            effectiveByEffIdOrgVO.setOrgIdList(orgIdList);
            effectiveByEffIdOrgVO.setPsnTypeList(psnTypeList);
            return effectiveByEffIdOrgVO;
         }
      }
   }

   private MktEffectiveByEffIdVO getMktEffectiveByEffIdPre(Long effId) {
      MktEffective effective = (MktEffective)((MktEffectiveMapper)this.baseMapper).selectOne(Wrappers.lambdaQuery(MktEffective.class).eq(MktEffective::getEffId, effId));
      log.info("[生效范围]_查询生效范围_effId={},effective={}", effId, JSONUtil.toJsonStr(effective));
      MktEffectiveByEffIdVO effectiveByEffIdVO = new MktEffectiveByEffIdVO();
      if (effective == null) {
         return effectiveByEffIdVO;
      } else {
         effectiveByEffIdVO.setEffType(effective.getEffType());
         effectiveByEffIdVO.setEffName(effective.getEffName());
         Integer effType = effective.getEffType();
         List<MktEffectiveDetail> effectiveDetailList;
         List warehouseIdList;
         List effCanteenPageVOList;
         if (MktEffTypeEnum.USER_SORT.key().equals(effType)) {
            effectiveDetailList = this.mktEffectiveDetailMapper.selectList(Wrappers.lambdaQuery(MktEffectiveDetail.class).eq(MktEffectiveDetail::getEffId, effId));
            warehouseIdList = (List)effectiveDetailList.stream().map(MktEffectiveDetail::getOrgId).filter((orgId) -> {
               return !orgId.equals(-1L);
            }).collect(Collectors.toList());
            effCanteenPageVOList = (List)effectiveDetailList.stream().map(MktEffectiveDetail::getPsnType).filter((psnType) -> {
               return !psnType.equals(-1);
            }).collect(Collectors.toList());
            Integer userType = effective.getUserType();
            List<Long> custIdList = new ArrayList();
            if (MktUserTypeEnum.INTERSECTION.key().equals(userType)) {
               custIdList = this.custInfoApi.selectCustIdByCondition(warehouseIdList, effCanteenPageVOList);
            } else if (MktUserTypeEnum.UNION_SET.key().equals(userType)) {
               custIdList = this.custInfoApi.selectCustIdOrCondition(warehouseIdList, effCanteenPageVOList);
            }

            effectiveByEffIdVO.setCustIdList((List)custIdList);
            return effectiveByEffIdVO;
         } else if (!MktEffTypeEnum.CANTEEN_SORT.key().equals(effType)) {
            if (MktEffTypeEnum.PRODUCT_SORT.key().equals(effType)) {
               effectiveDetailList = this.mktEffectiveDetailMapper.selectList(Wrappers.lambdaQuery(MktEffectiveDetail.class).eq(MktEffectiveDetail::getEffId, effId));
               warehouseIdList = (List)effectiveDetailList.stream().map(MktEffectiveDetail::getDishesId).filter((dishesId) -> {
                  return !dishesId.equals(-1L);
               }).collect(Collectors.toList());
               effCanteenPageVOList = (List)effectiveDetailList.stream().map(MktEffectiveDetail::getPackageId).filter((id) -> {
                  return !id.equals(-1L);
               }).collect(Collectors.toList());
               List<Long> productIdList = (List)effectiveDetailList.stream().map(MktEffectiveDetail::getProductId).filter((productId) -> {
                  return !productId.equals(-1L);
               }).collect(Collectors.toList());
               effectiveByEffIdVO.setDishesIdList(warehouseIdList);
               effectiveByEffIdVO.setPackageIdList(effCanteenPageVOList);
               effectiveByEffIdVO.setProductIdList(productIdList);
               return effectiveByEffIdVO;
            } else if (MktEffTypeEnum.WAREHOUSE_SORT.key().equals(effType)) {
               effectiveDetailList = this.mktEffectiveDetailMapper.selectList(Wrappers.lambdaQuery(MktEffectiveDetail.class).eq(MktEffectiveDetail::getEffId, effId));
               warehouseIdList = (List)effectiveDetailList.stream().map(MktEffectiveDetail::getWarehouseId).filter((orgId) -> {
                  return !orgId.equals(-1L);
               }).collect(Collectors.toList());
               effectiveByEffIdVO.setWarehouseIdList(warehouseIdList);
               return effectiveByEffIdVO;
            } else {
               return effectiveByEffIdVO;
            }
         } else {
            effectiveDetailList = this.mktEffectiveDetailMapper.selectList(Wrappers.lambdaQuery(MktEffectiveDetail.class).eq(MktEffectiveDetail::getEffId, effId));
            log.info("***effectiveDetailList : {}", effectiveDetailList);
            if (!CollUtil.isEmpty(effectiveDetailList)) {
               List<MktEffectiveCanteenPageVO> effectiveCanteenPageVOList = new ArrayList<>();
               Iterator<MktEffectiveDetail> var7 = effectiveDetailList.iterator();

               while(var7.hasNext()) {
                  MktEffectiveDetail temp = var7.next();
                  log.info("***temp : {}", temp);
                  if (temp.getShopstallId() == -1L) {
                     List<CanteenStallVO> allShopstall = this.allocStallApi.listStallByCanteenId(temp.getCanteenId());
                     effectiveCanteenPageVOList.addAll(BeanUtil.copyToList(allShopstall, MktEffectiveCanteenPageVO.class));
                  }
               }

               effCanteenPageVOList = CopyListUtil.copyListProperties(effectiveDetailList, MktEffectiveCanteenPageVO.class);
               effectiveCanteenPageVOList.addAll(effCanteenPageVOList);
               effectiveByEffIdVO.setCanteenList(effectiveCanteenPageVOList);
            }

            return effectiveByEffIdVO;
         }
      }
   }

   @Override
   public MktEffectivePermissionVO filterCanteenDataPermission(Long canteenIdDTO, Long shopstallIdDTO, List<MktEffectiveCanteenPageVO> canteenList) {
      if (CollUtil.isEmpty(canteenList)) {
         log.error("***[数据权限]_过滤食堂数据权限_登录用户没有数据权限*******************");
         throw new ServiceException(I18n.getMessage("mkt_no_perm", new Object[0]));
      } else {
         MktEffectivePermissionVO result = new MktEffectivePermissionVO();
         if (canteenIdDTO != null && canteenIdDTO != -1L) {
            if (shopstallIdDTO != null && shopstallIdDTO != -1L) {
               MktEffectiveCanteenPageVO canteenDTO = new MktEffectiveCanteenPageVO();
               canteenDTO.setCanteenId(canteenIdDTO);
               canteenDTO.setStallId(shopstallIdDTO);
               if (!canteenList.contains(canteenDTO)) {
                  log.error("***[数据权限]_过滤食堂数据权限_查询条件不在数据权限中*******************");
                  throw new ServiceException(I18n.getMessage("mkt_not_in_perm", new Object[0]));
               } else {
                  result.setCanteenId(canteenIdDTO);
                  result.setShopstallId(shopstallIdDTO);
                  result.setCanteenList((List)null);
                  return result;
               }
            } else {
               List<CanteenStallVO> canteenStallVOS = this.allocStallApi.listStallByCanteenId(canteenIdDTO);
               List<MktEffectiveCanteenPageVO> canteenListDTO = BeanUtil.copyToList(canteenStallVOS, MktEffectiveCanteenPageVO.class);
               List<MktEffectiveCanteenPageVO> resultList = canteenListDTO.stream().filter((item) -> {
                  List var10000 = canteenList.stream().map((e) -> {
                     Long var100001 = e.getCanteenId();
                     return "" + var100001 + "&" + e.getStallId();
                  }).collect(Collectors.toList());
                  Long var10001 = item.getCanteenId();
                  return var10000.contains("" + var10001 + "&" + item.getStallId());
               }).collect(Collectors.toList());
               result.setCanteenId(null);
               result.setShopstallId(null);
               result.setCanteenList(resultList);
               return result;
            }
         } else {
            result.setCanteenId(null);
            result.setShopstallId(null);
            result.setCanteenList(canteenList);
            return result;
         }
      }
   }

   @Override
   public Boolean checkCustIdEff(Long custId, Long effId) {
      log.info("[校验生效范围]_custId={},effId={}", custId, effId);
      MktEffectiveByEffIdVO effective = this.getMktEffectiveByEffIdPre(effId);
      Integer effType = effective.getEffType();
      if (!MktEffTypeEnum.USER_SORT.key().equals(effType)) {
         log.info("[校验生效范围]_不属于人员类，校验不通过");
         return false;
      } else {
         List<Long> custIdList = effective.getCustIdList();
         if (CollUtil.isEmpty(custIdList)) {
            log.info("[校验生效范围]_人员id集合为空，校验不通过");
            return false;
         } else {
            return custIdList.contains(custId);
         }
      }
   }

   @Override
   public List<Long> getOrgIdListByUser() {
      LoginUser user = SecurityUtils.getLoginUser();
      if (ObjectUtil.isNull(user)) {
         return new ArrayList();
      } else {
         long custId = user.getCustId();
         Long custEffId = ((MktEffectiveMapper)this.baseMapper).getUserEffIdByCustId(custId, LeConstants.COMMON_NO);
         return ((MktEffectiveMapper)this.baseMapper).selectOrgIdListByEffId(custEffId);
      }
   }

   @Override
   public List<DrpWarehouseAllVO> getAllDrpWarehouse() {
      return ((MktEffectiveMapper)this.baseMapper).selectAllWareHouse(LeConstants.COMMON_NO);
   }

   private void bindingUser(List<Long> orgIdList, List<Long> gradeIdList, List<Integer> psnTypeList, Long effId) {
      List<MktEffectiveDetail> effectiveDetailList = new ArrayList();
      Iterator var6;
      Long gradeId;
      MktEffectiveDetail effectiveDetail;
      if (!CollUtil.isEmpty(orgIdList)) {
         var6 = orgIdList.iterator();

         while(var6.hasNext()) {
            gradeId = (Long)var6.next();
            effectiveDetail = new MktEffectiveDetail();
            effectiveDetail.setEffId(effId);
            effectiveDetail.setOrgId(gradeId);
            effectiveDetailList.add(effectiveDetail);
         }
      }

      if (!CollUtil.isEmpty(gradeIdList)) {
         var6 = gradeIdList.iterator();

         while(var6.hasNext()) {
            gradeId = (Long)var6.next();
            effectiveDetail = new MktEffectiveDetail();
            effectiveDetail.setEffId(effId);
            effectiveDetailList.add(effectiveDetail);
         }
      }

      if (!CollUtil.isEmpty(psnTypeList)) {
         var6 = psnTypeList.iterator();

         while(var6.hasNext()) {
            Integer psnType = (Integer)var6.next();
            effectiveDetail = new MktEffectiveDetail();
            effectiveDetail.setEffId(effId);
            effectiveDetail.setPsnType(psnType);
            effectiveDetailList.add(effectiveDetail);
         }
      }

      if (CollUtil.isEmpty(effectiveDetailList)) {
         log.error("***接收到的人员列表为空,不能生成数据*****************");
         throw new ServiceException(I18n.getMessage("mkt_error_param", new Object[0]));
      } else {
         this.mktEffectiveDetailMapper.insertBatch(effectiveDetailList);
      }
   }

   private void bindingCanteen(List<MktEffectiveCanteenDTO> canteenList, Long effId) {
      if (CollUtil.isEmpty(canteenList)) {
         log.error("***接收到的食堂列表为空,不能生成数据*****************");
         throw new ServiceException(I18n.getMessage("mkt_error_param", new Object[0]));
      } else {
         List<MktEffectiveDetail> effectiveDetailList = new ArrayList();
         Iterator var4 = canteenList.iterator();

         while(var4.hasNext()) {
            MktEffectiveCanteenDTO item = (MktEffectiveCanteenDTO)var4.next();
            MktEffectiveDetail effectiveDetail = new MktEffectiveDetail();
            effectiveDetail.setEffId(effId);
            effectiveDetail.setCanteenId(item.getCanteenId());
            effectiveDetail.setShopstallId(item.getShopstallId());
            effectiveDetailList.add(effectiveDetail);
         }

         this.mktEffectiveDetailMapper.insertBatch(effectiveDetailList);
      }
   }

   private void bindingProduct(List<Long> dishesIdList, List<Long> packageIdList, List<Long> productIdList, Long effId) {
      List<MktEffectiveDetail> effectiveDetailList = new ArrayList();
      Iterator var6;
      Long productId;
      MktEffectiveDetail effectiveDetail;
      if (!CollUtil.isEmpty(dishesIdList)) {
         var6 = dishesIdList.iterator();

         while(var6.hasNext()) {
            productId = (Long)var6.next();
            effectiveDetail = new MktEffectiveDetail();
            effectiveDetail.setEffId(effId);
            effectiveDetail.setDishesId(productId);
            effectiveDetailList.add(effectiveDetail);
         }
      }

      if (!CollUtil.isEmpty(packageIdList)) {
         var6 = packageIdList.iterator();

         while(var6.hasNext()) {
            productId = (Long)var6.next();
            effectiveDetail = new MktEffectiveDetail();
            effectiveDetail.setEffId(effId);
            effectiveDetail.setPackageId(productId);
            effectiveDetailList.add(effectiveDetail);
         }
      }

      if (!CollUtil.isEmpty(productIdList)) {
         var6 = productIdList.iterator();

         while(var6.hasNext()) {
            productId = (Long)var6.next();
            effectiveDetail = new MktEffectiveDetail();
            effectiveDetail.setEffId(effId);
            effectiveDetail.setProductId(productId);
            effectiveDetailList.add(effectiveDetail);
         }
      }

      if (CollUtil.isEmpty(effectiveDetailList)) {
         log.error("***接收到的商品列表为空,不能生成数据*****************");
         throw new ServiceException(I18n.getMessage("mkt_error_param", new Object[0]));
      } else {
         this.mktEffectiveDetailMapper.insertBatch(effectiveDetailList);
      }
   }

   private void bindingWarehouse(List<Long> warehouseId, Long effId) {
      if (CollUtil.isEmpty(warehouseId)) {
         log.error("***接收到的仓库列表为空,不能生成数据*****************");
         throw new ServiceException(I18n.getMessage("mkt_error_param", new Object[0]));
      } else {
         List<MktEffectiveDetail> effectiveDetailList = new ArrayList();
         Iterator var4 = warehouseId.iterator();

         while(var4.hasNext()) {
            Long item = (Long)var4.next();
            MktEffectiveDetail effectiveDetail = new MktEffectiveDetail();
            effectiveDetail.setEffId(effId);
            effectiveDetail.setWarehouseId(item);
            effectiveDetailList.add(effectiveDetail);
         }

         this.mktEffectiveDetailMapper.insertBatch(effectiveDetailList);
      }
   }

   @Override
   public List<DrpWarehouseAllVO> getTenantWarehouse() {
      return this.mgrAuthApi.getTenantWarehouse();
   }

}
