package com.hzs.system.base.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.domain.system.base.BdStorehouse;
import com.hzs.common.domain.system.base.BdStorehouseAreaMiddle;
import com.hzs.system.base.mapper.BdStorehouseAreaMiddleMapper;
import com.hzs.system.base.service.IBdStorehouseAreaMiddleService;
import com.hzs.system.base.vo.BdStorehouseAreaMiddleVO;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 仓库地区中间表 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2023-05-05
 */
@Service
public class BdStorehouseAreaMiddleServiceImpl extends ServiceImpl<BdStorehouseAreaMiddleMapper, BdStorehouseAreaMiddle> implements IBdStorehouseAreaMiddleService {

    /**
     * @description: 查询地区绑定仓库列表
     * @author: zhang jing
     * @date: 2023/5/5 20:09
     * @param: [storehouseAreaMiddleVO]
     * @return: java.util.List<com.hzs.system.base.vo.BdStorehouseAreaMiddleVO>
     **/
    @Override
    public List<BdStorehouseAreaMiddleVO> getBdStorehouseAreaMiddleList(BdStorehouseAreaMiddleVO storehouseAreaMiddleVO) {
        return baseMapper.getBdStorehouseAreaMiddleList(storehouseAreaMiddleVO);
    }

    /**
     * @description: 新增地区仓库
     * @author: zhang jing
     * @date: 2023/5/5 20:37
     * @param: [storehouseAreaMiddleVO]
     * @return: boolean
     **/
    @Override
    public boolean intStoArMiddle(BdStorehouseAreaMiddleVO storehouseAreaMiddleVO) {
        BdStorehouseAreaMiddle sto= BeanUtil.copyProperties(storehouseAreaMiddleVO, BdStorehouseAreaMiddle.class);
        for(Integer i: storehouseAreaMiddleVO.getProvinceList()){
            sto.setProvince(i);
            baseMapper.insert(sto);
        }
        return true;
    }

    /**
     * @description: 修改地区仓库
     * @author: zhang jing
     * @date: 2023/5/5 20:37
     * @param: [storehouseAreaMiddleVO]
     * @return: boolean
     **/
    @Override
    public boolean upStoArMiddle(BdStorehouseAreaMiddleVO storehouseAreaMiddleVO) {
        BdStorehouseAreaMiddle sto= BeanUtil.copyProperties(storehouseAreaMiddleVO, BdStorehouseAreaMiddle.class);
        sto.setPkStorehouse(storehouseAreaMiddleVO.getPkStorehouse());
        for(Integer i: storehouseAreaMiddleVO.getProvinceList()){
            sto.setProvince(i);
            baseMapper.updateById(sto);
        }
        return true;
    }

    @Override
    public BdStorehouse queryBdStorehouseByProvince(Integer province, Integer type) {
        List<BdStorehouse> bdStorehouseList = baseMapper.queryBdStorehouseByProvince(province, type);
        if(CollectionUtil.isNotEmpty(bdStorehouseList)){
            return bdStorehouseList.get(0);
        }
        return null;
    }

    @Override
    public List<BdStorehouse> queryStorehouseListByProvince(Collection<Integer> provinceList) {
        return baseMapper.queryStorehouseListByProvince(provinceList);
    }

}
