<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.predict.mapper.FormulaMapper">

    <resultMap type="Formula" id="FormulaResult">
        <result property="formulaNo" column="formula_no"/>
        <result property="formulaName" column="formula_name"/>
        <result property="formulaDesc" column="formula_desc"/>
        <result property="period" column="period"/>
        <result property="paraCount" column="para_count"/>
        <result property="ifvalid" column="ifvalid"/>
    </resultMap>

    <sql id="selectFormulaVo">
        select formula_no, formula_name, formula_desc, period, para_count, ifvalid from formula
    </sql>

    <select id="selectFormulaList" parameterType="Formula" resultMap="FormulaResult">
        select
        fo.*,
        emi1.item_name as "periodName",
        emi2.item_name as "ifvalidName"
        from
        formula fo
        left join enum_menu_item emi1 on emi1.item_val = fo.period and emi1.menu_no = 41
        left join enum_menu_item emi2 on emi2.item_val = fo.ifvalid and emi2.menu_no = 10
        <where>
            <if test="formulaNo != null ">and fo.formula_no = #{formulaNo}</if>
            <if test="formulaName != null  and formulaName != ''">and fo.formula_name like concat(concat('%',
                #{formulaName}), '%')
            </if>
            <if test="formulaDesc != null  and formulaDesc != ''">and fo.formula_desc = #{formulaDesc}</if>
            <if test="period != null ">and fo.period = #{period}</if>
            <if test="paraCount != null ">and fo.para_count = #{paraCount}</if>
            <if test="ifvalid != null ">and fo.ifvalid = #{ifvalid}</if>
        </where>
    </select>

    <select id="selectFormulaById" parameterType="Long" resultMap="FormulaResult">
        <include refid="selectFormulaVo"/>
        where formula_no = #{formulaNo}
    </select>

</mapper>