package com.zt.plat.module.qms.common.dic.dal.mapper;

import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.qms.common.dic.controller.vo.*;
import com.zt.plat.module.qms.common.dic.controller.vo.DictionaryBusinessPageReqVO;
import com.zt.plat.module.qms.common.dic.dal.dataobject.DictionaryBusinessDO;
import com.zt.plat.module.qms.core.legend.vo.DictModel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 业务参数字典 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface DictionaryBusinessMapper extends BaseMapperX<DictionaryBusinessDO> {

    default PageResult<DictionaryBusinessDO> selectPage(DictionaryBusinessPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DictionaryBusinessDO>()
                .eqIfPresent(DictionaryBusinessDO::getIdPath, reqVO.getIdPath())
                .eqIfPresent(DictionaryBusinessDO::getParentId, reqVO.getParentId())
                .eqIfPresent(DictionaryBusinessDO::getNodeType, reqVO.getNodeType())
                .likeIfPresent(DictionaryBusinessDO::getName, reqVO.getName())
                .eqIfPresent(DictionaryBusinessDO::getKey, reqVO.getKey())
                .eqIfPresent(DictionaryBusinessDO::getValue, reqVO.getValue())
                .eqIfPresent(DictionaryBusinessDO::getCustomConfig, reqVO.getCustomConfig())
                .eqIfPresent(DictionaryBusinessDO::getSortNo, reqVO.getSortNo())
                .eqIfPresent(DictionaryBusinessDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(DictionaryBusinessDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(DictionaryBusinessDO::getRemark, reqVO.getRemark())
                .orderByAsc(DictionaryBusinessDO::getSortNo));
    }


    /**
     * 查询自定义字典表
     * @param table 表名
     * @param text   显示字段名
     * @param code   存储字段名
     * @param filterSql 条件sql
     * @param keys 存储字段值 作为查询条件in
     */
    List<DictModel> queryTableDictCustom(@Param("table") String table, @Param("text") String text, @Param("code") String code, @Param("filterSql") String filterSql,
                                         @Param("keys") List<String> keys);

    /**
     * 通过字典code获取字典数据
     * @param code
     * @param key
     */
    String queryDictTextByKey(@Param("code") String code, @Param("key") String key);
    String queryDictTextByID(@Param("code") String code, @Param("id") String id);

}