package com.njcn.msgpush.module.system.dal.mysql.dept;

import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX;
import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.njcn.msgpush.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import com.njcn.msgpush.module.system.dal.dataobject.dept.DeptDO;
import org.apache.ibatis.annotations.Mapper;

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

@Mapper
public interface DeptMapper extends BaseMapperX<DeptDO> {

    default List<DeptDO> selectList(DeptListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeptDO>()
                .likeIfPresent(DeptDO::getName, reqVO.getName())
                .eqIfPresent(DeptDO::getOrgType, reqVO.getOrgType())
                .eqIfPresent(DeptDO::getStatus, reqVO.getStatus()));
    }

    default DeptDO selectByParentIdAndName(Long parentId, String name) {
        return selectOne(DeptDO::getParentId, parentId, DeptDO::getName, name);
    }

    default DeptDO selectByCode(String code) {
        return selectOne(DeptDO::getCode, code);
    }

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

    default List<DeptDO> selectListByParentId(Collection<Long> parentIds) {
        return selectList(DeptDO::getParentId, parentIds);
    }

    default List<DeptDO> selectListByPathPrefix(String pathPrefix) {
        return selectList(new LambdaQueryWrapperX<DeptDO>().likeRight(DeptDO::getPath, pathPrefix));
    }

}
