package cn.ey.biz.module.system.dal.mapper.field;

import cn.ey.biz.common.pojo.PageResult;
import cn.ey.biz.framework.mybatis.core.mapper.BaseMapperX;
import cn.ey.biz.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ey.biz.module.system.controller.admin.field.vo.FieldExportReqVO;
import cn.ey.biz.module.system.controller.admin.field.vo.FieldPageReqVO;
import cn.ey.biz.module.system.controller.admin.field.vo.FieldRespVO;
import cn.ey.biz.module.system.dal.dataobject.field.FieldDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 字段权限-字段列表 Mapper
 *
 */
@Mapper
public interface FieldMapper extends BaseMapperX<FieldDO> {

    default PageResult<FieldDO> selectPage(FieldPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<FieldDO>()
                .eqIfPresent(FieldDO::getConfigCode, reqVO.getConfigCode())
                .eqIfPresent(FieldDO::getFieldCode, reqVO.getFieldCode())
                .likeIfPresent(FieldDO::getFieldName, reqVO.getFieldName())
                .eqIfPresent(FieldDO::getFieldFix, reqVO.getFieldFix())
                .eqIfPresent(FieldDO::getCategory, reqVO.getCategory())
                .betweenIfPresent(FieldDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(FieldDO::getId));
    }

    default List<FieldDO> selectList(FieldExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<FieldDO>()
                .eqIfPresent(FieldDO::getConfigCode, reqVO.getConfigCode())
                .eqIfPresent(FieldDO::getFieldCode, reqVO.getFieldCode())
                .likeIfPresent(FieldDO::getFieldName, reqVO.getFieldName())
                .eqIfPresent(FieldDO::getFieldFix, reqVO.getFieldFix())
                .eqIfPresent(FieldDO::getCategory, reqVO.getCategory())
                .betweenIfPresent(FieldDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(FieldDO::getId));
    }

    List<FieldRespVO> selectListWithBelongTo(FieldExportReqVO reqVO);

    List<FieldRespVO> getFieldListBelongTo(@Param("configCode") String configCode);
}
