package com.jojubanking.boot.module.system.dal.mysql.building;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jojubanking.boot.framework.common.pojo.PageResult;
import com.jojubanking.boot.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.jojubanking.boot.framework.mybatis.core.mapper.BaseMapperX;
import com.jojubanking.boot.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import com.jojubanking.boot.module.system.dal.dataobject.building.BuildingDO;
import com.jojubanking.boot.module.system.dal.dataobject.dept.DeptDO;
import org.apache.ibatis.annotations.Mapper;
import com.jojubanking.boot.module.system.controller.admin.building.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 楼层导视 Mapper
 *
 * @author admin
 */
@Mapper
public interface BuildingMapper extends BaseMapperX<BuildingDO> {

    default PageResult<BuildingDO> selectPage(BuildingPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BuildingDO>()
                .likeIfPresent(BuildingDO::getName, reqVO.getName())
                .eqIfPresent(BuildingDO::getParentId, reqVO.getParentId())
                .eqIfPresent(BuildingDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BuildingDO::getFid, reqVO.getFid())
                .betweenIfPresent(BuildingDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BuildingDO::getId));
    }

    default List<BuildingDO> selectList(BuildingExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BuildingDO>()
                .likeIfPresent(BuildingDO::getName, reqVO.getName())
                .eqIfPresent(BuildingDO::getParentId, reqVO.getParentId())
                .eqIfPresent(BuildingDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BuildingDO::getFid, reqVO.getFid())
                .betweenIfPresent(BuildingDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BuildingDO::getId));
    }

    default List<BuildingDO> selectList01(BuildingListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BuildingDO>()
                .likeIfPresent(BuildingDO::getName, reqVO.getName())
                .eqIfPresent(BuildingDO::getStatus, reqVO.getStatus()));
    }

    default BuildingDO selectByParentIdAndName(Long parentId, String name) {
        return selectOne(new LambdaQueryWrapper<BuildingDO>()
                .eq(BuildingDO::getParentId, parentId)
                .eq(BuildingDO::getName, name));
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(BuildingDO::getParentId, parentId);
    }

    @Select("SELECT COUNT(*) FROM hnwj_buiding WHERE update_time > #{maxUpdateTime}")
    Long selectCountByUpdateTimeGt(Date maxUpdateTime);

}
