<?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="org.diagbot.nlp.dao.mapper.FeatureMapper">
    <!-- 映射定义列-->
    <resultMap type="org.diagbot.nlp.dao.model.Feature" id="featureMap">
        <id property="id" column="id"/>
        <result property="rdn" column="rdn"/>
        <result property="sex" column="sex"/>
        <result property="age" column="age"/>
        <result property="featureName" column="feature_name"/>
        <result property="featureType" column="feature_type"/>
        <result property="isPush" column="is_push"/>
        <result property="sn" column="sn"/>
        <result property="negative" column="negative"/>
        <result property="threshold" column="threshold"/>
        <result property="tfIdf" column="tf_idf"/>
        <result property="resourceType" column="resource_type"/>
    </resultMap>

    <!-- 映射定义列-->
    <resultMap type="org.diagbot.nlp.dao.model.wrapper.FeatureWrapper" id="featureWrapperMap">
        <id property="id" column="id"/>
        <result property="rdn" column="rdn"/>
        <result property="sex" column="sex"/>
        <result property="age" column="age"/>
        <result property="featureName" column="feature_name"/>
        <result property="featureType" column="feature_type"/>
        <result property="isPush" column="is_push"/>
        <result property="sn" column="sn"/>
        <result property="negative" column="negative"/>
        <result property="threshold" column="threshold"/>
        <result property="tfIdf" column="tf_idf"/>
        <result property="resourceType" column="resource_type"/>
    </resultMap>

    <!-- 通用查询结果列-->
    <sql id="Base_Column_List">
		 t.id,	 t.rdn,	 t.sex,	 t.age,	 t.feature_name,	 t.feature_type,  t.is_push, t.sn,	 t.negative,	 t.threshold,	 t.tf_idf, t.resource_type
	</sql>

    <!-- 查询（根据主键ID查询） -->
    <select id="selectByPrimaryKey" resultMap="featureMap" parameterType="java.lang.Integer">
        SELECT
        <include refid="Base_Column_List"/>
        FROM doc_feature t
        WHERE t.id = #{id}
    </select>

    <!-- 查询（根据主键ID查询） -->
    <select id="selectWrapperByPrimaryKey" resultMap="featureWrapperMap" parameterType="java.lang.Integer">
        SELECT
        <include refid="Base_Column_List"/>
        FROM doc_feature t
        WHERE t.id = #{id}
    </select>

    <!-- 依据Map查询条件返回结果集-->
    <select id="selectList" resultMap="featureMap" parameterType="java.util.Map">
        SELECT
        <include refid="Base_Column_List"/>
        FROM doc_feature t WHERE 1=1
        <if test="id != null and id != ''">
            and t.id = #{id}
        </if>
        <if test="rdn != null and rdn != ''">
            and t.rdn = #{rdn}
        </if>
        <if test="sex != null and sex != ''">
            and t.sex = #{sex}
        </if>
        <if test="age != null and age != ''">
            and t.age = #{age}
        </if>
        <if test="featureName != null and featureName != ''">
            and t.feature_name = #{featureName}
        </if>
        <if test="featureType != null and featureType != ''">
            and t.feature_type = #{featureType}
        </if>
        <if test="isPush != null and isPush != ''">
            and t.is_push = #{isPush}
        </if>
        <if test="negative != null and negative != ''">
            and t.negative = #{negative}
        </if>
        <if test="threshold != null and threshold != ''">
            and t.threshold = #{threshold}
        </if>
        <if test="tfIdf != null and tfIdf != ''">
            and t.tf_idf = #{tfIdf}
        </if>
        <if test="resourceType != null and resourceType != ''">
            and t.resource_type = #{resourceType}
        </if>
        order by rdn, sn
    </select>

    <!-- 依据Map查询条件返回扩展属性结果集-->
    <select id="selectListWrapper" resultMap="featureWrapperMap" parameterType="java.util.Map">
        SELECT
        <include refid="Base_Column_List"/>
        FROM doc_feature t WHERE 1=1
        <if test="id != null and id != ''">
            and t.id = #{id}
        </if>
        <if test="rdn != null and rdn != ''">
            and t.rdn = #{rdn}
        </if>
        <if test="sex != null and sex != ''">
            and t.sex = #{sex}
        </if>
        <if test="age != null and age != ''">
            and t.age = #{age}
        </if>
        <if test="featureName != null and featureName != ''">
            and t.feature_name like concat('%', #{featureName}, '%')
        </if>
        <if test="featureType != null and featureType != ''">
            and t.feature_type = #{featureType}
        </if>
        <if test="isPush != null and isPush != ''">
            and t.is_push = #{isPush}
        </if>
        <if test="negative != null and negative != ''">
            and t.negative = #{negative}
        </if>
        <if test="threshold != null and threshold != ''">
            and t.threshold = #{threshold}
        </if>
        <if test="tfIdf != null and tfIdf != ''">
            and t.tf_idf = #{tfIdf}
        </if>
        <if test="resourceType != null and resourceType != ''">
            and t.resource_type = #{resourceType}
        </if>
        order by rdn, sn
    </select>

    <!-- 依据Map查询条件返回扩展属性结果集-->
    <select id="selectFeatureByTypesWrapper" resultMap="featureWrapperMap">
        select * from doc_feature where negative = '有' and resource_type = #{resourceType} and feature_type in
        <foreach collection="types" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        order by rdn, sn
    </select>

    <!-- 依据Map查询条件返回扩展属性结果集-->
    <select id="selectFeatureByTypesMoreResourceWrapper" resultMap="featureWrapperMap">
        select * from doc_feature where negative = '有' and feature_type in
        <foreach collection="types" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        and resource_type in
        <foreach collection="resourceTypes" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
        order by rdn, sn
    </select>

    <!--删除：根据主键ID删除-->
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
		 DELETE FROM doc_feature
		 WHERE id = #{id}
	</delete>

    <!--条件删除-->
    <delete id="deleteList" parameterType="java.util.Map">
        DELETE FROM doc_feature where 1 = 1
        <if test="resourceType != null and resourceType != ''">
            and t.resource_type = #{resourceType}
        </if>
        and feature_type in
        <foreach collection="featureType" item="item" index="index" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </delete>

    <!-- 添加 -->
    <insert id="insert" parameterType="org.diagbot.nlp.dao.model.Feature">
		 INSERT INTO doc_feature
 		(id,rdn,sex,age,feature_name,feature_type,is_push,sn,negative,threshold,tf_idf, resource_type)
		 VALUES 
 		(#{id},#{rdn},#{sex},#{age},#{featureName},#{featureType},#{isPush},#{sn},#{negative},#{threshold},#{tfIdf},#{resourceType})
	</insert>

    <update id="updateStandardLibrarySynonymInfo" parameterType="java.lang.String">
        UPDATE doc_feature
        SET
        feature_name = #{relationTermName} where feature_name = #{name}
    </update>

    <!-- 修 改-->
    <update id="updateByPrimaryKeySelective" parameterType="org.diagbot.nlp.dao.model.Feature">
        UPDATE doc_feature
        <set>
            <if test="rdn != null">
                rdn = #{rdn},
            </if>
            <if test="sex != null">
                sex = #{sex},
            </if>
            <if test="age != null">
                age = #{age},
            </if>
            <if test="featureName != null">
                feature_name = #{featureName},
            </if>
            <if test="featureType != null">
                feature_type = #{featureType},
            </if>
            <if test="isPush != null">
                is_push = #{isPush},
            </if>
            <if test="negative != null">
                negative = #{negative},
            </if>
            <if test="threshold != null">
                threshold = #{threshold},
            </if>
            <if test="tfIdf != null">
                tf_idf = #{tfIdf},
            </if>
            <if test="resourceType != null and resourceType != ''">
                resource_type = #{resourceType},
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <!-- 修 改-->
    <update id="updateByPrimaryKey" parameterType="org.diagbot.nlp.dao.model.Feature">
		 UPDATE doc_feature
		 SET 
			 rdn = #{rdn},
			 sex = #{sex},
			 age = #{age},
			 feature_name = #{featureName},
			 feature_type = #{featureType},
			 is_push = #{isPush},
			 negative = #{negative},
			 threshold = #{threshold},
			 tf_idf = #{tfIdf},
			 resource_type = #{resourceType}
		 WHERE id = #{id}
	</update>
</mapper>