package com.yhy.module.core.dal.mysql.workbench;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yhy.module.core.dal.dataobject.workbench.WbBoqMarketMaterialDO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 工作台市场主材设备消耗 Mapper
 *
 * @author yhy
 */
@Mapper
public interface WbBoqMarketMaterialMapper extends BaseMapperX<WbBoqMarketMaterialDO> {

    /**
     * 根据分部分项ID查询市场主材设备列表
     */
    default List<WbBoqMarketMaterialDO> selectListByDivisionId(Long divisionId) {
        return selectList(new LambdaQueryWrapperX<WbBoqMarketMaterialDO>()
                .eq(WbBoqMarketMaterialDO::getDivisionId, divisionId)
                .orderByAsc(WbBoqMarketMaterialDO::getSortOrder)
                .orderByAsc(WbBoqMarketMaterialDO::getCreateTime));
    }

    /**
     * 根据分部分项ID列表批量查询
     */
    default List<WbBoqMarketMaterialDO> selectListByDivisionIds(List<Long> divisionIds) {
        return selectList(WbBoqMarketMaterialDO::getDivisionId, divisionIds);
    }

    /**
     * 根据父工料机ID查询子工料机列表
     */
    default List<WbBoqMarketMaterialDO> selectListByParentId(Long parentId) {
        return selectList(new LambdaQueryWrapperX<WbBoqMarketMaterialDO>()
                .eq(WbBoqMarketMaterialDO::getParentId, parentId)
                .orderByAsc(WbBoqMarketMaterialDO::getSortOrder));
    }

    /**
     * 删除分部分项下的所有市场主材设备
     */
    default int deleteByDivisionId(Long divisionId) {
        return delete(WbBoqMarketMaterialDO::getDivisionId, divisionId);
    }

    /**
     * 批量删除分部分项下的所有市场主材设备
     */
    default int deleteByDivisionIds(List<Long> divisionIds) {
        if (divisionIds == null || divisionIds.isEmpty()) {
            return 0;
        }
        return delete(new LambdaQueryWrapperX<WbBoqMarketMaterialDO>()
                .in(WbBoqMarketMaterialDO::getDivisionId, divisionIds));
    }

    /**
     * 批量插入市场主材设备
     */
    default void insertBatch(List<WbBoqMarketMaterialDO> list) {
        list.forEach(this::insert);
    }
}
