package com.sunyard.ssp.modules.sysconf.dict.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sunyard.ssp.modules.sysconf.dict.entity.ScDictData;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author fyc
 * @since 2020-03-13
 */
@Repository
public interface ScDictDataMapper extends BaseMapper<ScDictData> {

    /**
     * 按条件查询数据字典
     * @param iPage 分页
     * @param scDictData 条件参数
     * @return
     */
    @Select("<script>" +
            "  select * from Sc_DICT_DATA\n" +
            "        <where>\n" +
            "            <if test=\"scDictData.dictId != null\">\n" +
            "               and DICT_ID = #{scDictData.dictId}\n" +
            "            </if>\n" +
            "            <if test=\"scDictData.title != null and scDictData.title != ''\">\n" +
            "               and TITLE like '%${scDictData.title}%'\n" +
            "            </if>\n" +
            "            <if test=\"scDictData.status != null\">\n" +
            "               and STATUS = #{scDictData.status}\n" +
            "            </if>\n" +
            "        </where>\n" +
            "        order by ${scDictData.sort} ${scDictData.order} ,CREATE_TIME desc"+
            "</script>")
    List<ScDictData> queryList(IPage<ScDictData> iPage,@Param("scDictData") ScDictData scDictData);

    /**
     * 根据字典id 获取字典数据
     * @param scDictId 字典边ID
     * @return
     */
    @Select("<script>"+
             "select * from Sc_DICT_DATA where DICT_ID = #{ scDictId } and STATUS = 0 order by SORT_ORDER asc"+
            "</script>")
    List<ScDictData> selectByDictId(@Param("scDictId") Long scDictId);


    @Delete("<script>"+
            "delete from Sc_DICT_DATA where DICT_ID = #{ scDictId }"+
            "</script>")
    void deleteByDictId(@Param("scDictId") Long scDictId);
}
