package com.zt.plat.module.base.dal.dao.materialhasproperties;

import java.util.*;

import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.module.base.dal.dataobject.materialhasproperties.MaterialHasPropertiesDO;
import org.apache.ibatis.annotations.Mapper;
import com.zt.plat.module.base.controller.admin.materialhasproperties.vo.*;

/**
 * 物料持有属性 Mapper
 *
 * @author 后台管理-1
 */
@Mapper
public interface MaterialHasPropertiesMapper extends BaseMapperX<MaterialHasPropertiesDO> {

    default PageResult<MaterialHasPropertiesDO> selectPage(MaterialHasPropertiesPageReqVO reqVO) {
        LambdaQueryWrapperX<MaterialHasPropertiesDO> query = new LambdaQueryWrapperX<MaterialHasPropertiesDO>()
                .eqIfPresent(MaterialHasPropertiesDO::getInfomationId, reqVO.getInfomationId())
                .eqIfPresent(MaterialHasPropertiesDO::getPropertiesId, reqVO.getPropertiesId())
                .eqIfPresent(MaterialHasPropertiesDO::getUnitId, reqVO.getUnitId())
                .eqIfPresent(MaterialHasPropertiesDO::getValue, reqVO.getValue())
                .eqIfPresent(MaterialHasPropertiesDO::getIsKey, reqVO.getIsKey())
                .eqIfPresent(MaterialHasPropertiesDO::getIsMetering, reqVO.getIsMetering())
                .eqIfPresent(MaterialHasPropertiesDO::getSort, reqVO.getSort())
                .betweenIfPresent(MaterialHasPropertiesDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MaterialHasPropertiesDO::getId);
        if (reqVO.getDeptId() == null) {
            query.isNull(MaterialHasPropertiesDO::getDeptId);
        } else {
            query.eq(MaterialHasPropertiesDO::getDeptId, reqVO.getDeptId());
        }
        return selectPage(reqVO, query);
    }

    default List<MaterialHasPropertiesDO> selectByInfoIdsAndPropertyIds(Collection<Long> infoIds, Collection<Long> propertyIds) {
        if (infoIds == null || infoIds.isEmpty() || propertyIds == null || propertyIds.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<MaterialHasPropertiesDO>()
                .in(MaterialHasPropertiesDO::getInfomationId, infoIds)
                .in(MaterialHasPropertiesDO::getPropertiesId, propertyIds));
    }

}