<?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.ey.biz.module.system.dal.mapper.field.FieldMapper">
    <!-- 自定义ORM映射规则 -->
    <resultMap id="FieldVOWithBelongTo" type="cn.ey.biz.module.system.controller.admin.field.vo.FieldRespVO">
        <result column="id" property="id"/>
        <result column="config_code" property="configCode"/>
        <result column="field_code" property="fieldCode"/>
        <result column="field_name" property="fieldName"/>
        <result column="field_fix" property="fieldFix"/>
        <result column="category" property="category"/>
        <!-- 当关联属性为集合时用collection标签来描述关联属性ofType是关联属性集合中装的实体类的全类名 -->
        <collection property="belongs" ofType="cn.ey.biz.module.system.controller.admin.field.vo.FieldItemRespVO"  >
            <result column="belong_to" property="belongTo"/>
        </collection>
    </resultMap>
    <select id="selectListWithBelongTo" resultMap="FieldVOWithBelongTo">
        SELECT
            f.*,
            fi.belong_to
        FROM
            system_field f,
            system_field_config fc
            LEFT JOIN system_field_item fi ON fi.config_id = fc.id
        WHERE
            f.config_code = fc.config_code
            AND fi.field_code = f.field_code
            AND fc.id = 1
            AND f.deleted = 0
            AND fi.deleted = 0
            AND fc.`enable` = 0
    </select>

    <!-- 自定义ORM映射规则 -->
    <resultMap id="FieldVOBelongTo" type="cn.ey.biz.module.system.controller.admin.field.vo.FieldRespVO">
        <result column="id" property="id"/>
        <result column="config_code" property="configCode"/>
        <result column="field_code" property="fieldCode"/>
        <result column="field_name" property="fieldName"/>
        <result column="field_fix" property="fieldFix"/>
        <result column="category" property="category"/>
        <!-- 当关联属性为集合时用collection标签来描述关联属性ofType是关联属性集合中装的实体类的全类名 -->
        <collection property="belongs" ofType="cn.ey.biz.module.system.controller.admin.field.vo.FieldItemRespVO"  >
            <result column="belong_to" property="belongTo"/>
        </collection>
    </resultMap>
    <select id="getFieldListBelongTo"
            resultMap="FieldVOBelongTo">
         SELECT
            f.*,
            fi.belong_to
        FROM
            system_field f
            LEFT JOIN system_field_config fc ON fc.config_code = f.config_code
            AND fc.`enable` = 0
            LEFT JOIN system_field_item fi ON fi.field_code = f.field_code
            AND fi.config_id = fc.id
            AND fi.deleted = 0
        WHERE
             f.deleted = 0
            and f.config_code = #{configCode}
    </select>
</mapper>

