<?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="cn.cecep.talroad.mapper.PcLabelMapper">

    <resultMap type="cn.cecep.talroad.domain.PcLabel" id="PcLabelResult">
        <result property="id"    column="id"    />
        <result property="labelType"    column="label_type"    />
        <result property="labelCategory"    column="label_category"    />
        <result property="labelCode"    column="label_code"    />
        <result property="labelVal"    column="label_val"    />
        <result property="labelLevel"    column="label_level"    />
        <result property="labelParamid"    column="label_paramid"    />
        <result property="labelMultipleChoice"    column="label_multiple_choice"    />
        <result property="updateTimes"    column="update_times"    />
    </resultMap>

    <resultMap type="cn.cecep.talroad.vo.PcLabelVo" id="PcLabelResultTreeVo">
        <result property="id"    column="id"    />
        <result property="labelVal"    column="label_val"    />
        <result property="labelLevel"    column="label_level"    />
        <result property="labelParamid"    column="label_paramid"    />
        <result property="factoryId" column="factory_id" />
        <result property="orderNum" column="order_num" />
        <result property="labelMultipleChoice"    column="label_multiple_choice"    />
        <collection property="pcLabelValueVos" ofType="cn.cecep.talroad.vo.PcLabelValueVo">
            <id property="id" column="param_id" />
            <result property="argumentsCode" column="arguments_code" />
            <result property="argumentsName" column="arguments_name" />
        </collection>
    </resultMap>


    <sql id="selectPcLabelVo">
        select id, label_type, label_category, label_code, label_val, label_level, label_paramid from pc_label
    </sql>

    <select id="selectPcLabelList" parameterType="cn.cecep.talroad.domain.PcLabel" resultMap="PcLabelResult">
        <include refid="selectPcLabelVo"/>
        <where>
            <if test="labelType != null  and labelType != ''"> and label_type = #{labelType}</if>
            <if test="labelCategory != null  and labelCategory != ''"> and label_category = #{labelCategory}</if>
            <if test="labelCode != null  and labelCode != ''"> and label_code = #{labelCode}</if>
            <if test="labelVal != null  and labelVal != ''"> and label_val = #{labelVal}</if>
            <if test="labelLevel != null  and labelLevel != ''"> and label_level = #{labelLevel}</if>
            <if test="labelParamid != null  and labelParamid != ''"> and label_paramid = #{labelParamid}</if>
        </where>
    </select>

    <select id="selectTreeList" resultMap="PcLabelResultTreeVo">
        SELECT
            pl."id", pl.label_val, pl.label_level, pl.label_paramid, pl.label_multiple_choice, plv."id" AS param_id, plv.arguments_code, plv.arguments_name, plf.factory_id, pl.order_num, plv.order_num
        FROM
            pc_label pl
                LEFT JOIN pc_label_value plv ON pl."id" = plv."label_id"
                LEFT JOIN pc_label_factory plf ON pl."id" = plf."label_id"
        <where>
            pl.label_paramid = #{id}
            <if test="factoryId != null and factoryId != ''">
                AND factory_id = #{factoryId}
            </if>
        </where>
        ORDER BY pl.order_num, plv.order_num
    </select>
</mapper>
