package cn.iocoder.yudao.module.system.dal.mysql.deptsaporg;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.deptsaporg.vo.DeptSapOrgPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.deptsaporg.DeptSapOrgDO;
import org.apache.ibatis.annotations.Mapper;

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

/**
 * PMS 组织部门与SAP工厂/成本中心 对应关系 Mapper
 *
 * @author ruiqi
 */
@Mapper
public interface DeptSapOrgMapper extends BaseMapperX<DeptSapOrgDO> {

    default PageResult<DeptSapOrgDO> selectPage(DeptSapOrgPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeptSapOrgDO>()
                .eqIfPresent(DeptSapOrgDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(DeptSapOrgDO::getSapOrgId, reqVO.getSapOrgId())
                .betweenIfPresent(DeptSapOrgDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeptSapOrgDO::getId));
    }

    default List<DeptSapOrgDO> selectListByDeptId(Long deptId) {
        return selectList(DeptSapOrgDO::getDeptId, deptId);
    }

    default List<DeptSapOrgDO> selectListByDeptIds(Collection<Long> deptIds) {
        return selectList(new LambdaQueryWrapperX<DeptSapOrgDO>()
                .inIfPresent(DeptSapOrgDO::getDeptId, deptIds));
    }

    default void deleteByDeptIdAndFactoryId(Long deptId, Collection<Long> factoryIds) {
        delete(new LambdaQueryWrapperX<DeptSapOrgDO>()
                .eq(DeptSapOrgDO::getDeptId, deptId)
                .in(DeptSapOrgDO::getFactoryId, factoryIds));
    }

    default void deleteByDeptIdAndCostCenterId(Long deptId, Collection<Long> costCenterIds) {
        delete(new LambdaQueryWrapperX<DeptSapOrgDO>()
                .eq(DeptSapOrgDO::getDeptId, deptId)
                .in(DeptSapOrgDO::getCostCenterId, costCenterIds));
    }

    default void deleteByDeptIdAndStockLocationId(Long deptId, Collection<Long> stockLocationIds) {
        delete(new LambdaQueryWrapperX<DeptSapOrgDO>()
                .eq(DeptSapOrgDO::getDeptId, deptId)
                .in(DeptSapOrgDO::getStockLocationId, stockLocationIds));
    }

}