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

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.businessindicator.BusinessIndicatorDO;
import org.apache.ibatis.annotations.Mapper;
import com.zt.plat.module.base.controller.admin.businessindicator.vo.*;

/**
 * 经营指标 Mapper
 *
 * @author chengpeng
 */
@Mapper
public interface BusinessIndicatorMapper extends BaseMapperX<BusinessIndicatorDO> {

    default PageResult<BusinessIndicatorDO> selectPage(BusinessIndicatorPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BusinessIndicatorDO>()
                .likeIfPresent(BusinessIndicatorDO::getCode, reqVO.getCode())
                .likeIfPresent(BusinessIndicatorDO::getName, reqVO.getName())
                .eqIfPresent(BusinessIndicatorDO::getDimensionId, reqVO.getDimensionId())
                .eqIfPresent(BusinessIndicatorDO::getId, reqVO.getId())
                .orderByDesc(BusinessIndicatorDO::getId));
    }
    
    default List<BusinessIndicatorDO> selectListByParentId(Long parentId) {
        LambdaQueryWrapperX<BusinessIndicatorDO> queryWrapper = new LambdaQueryWrapperX<BusinessIndicatorDO>()
                .orderByDesc(BusinessIndicatorDO::getId);

        // 如果parentId 是 null，查询根节点（parentId 为 null 的节点）
        if (parentId == null) {
            queryWrapper.isNull(BusinessIndicatorDO::getParentId);
        } else {
            queryWrapper.eq(BusinessIndicatorDO::getParentId, parentId);
        }

        return selectList(queryWrapper);
    }

}