<?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.testor.module.fives.dao.TFivesSubOptionDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.fives.model.domain.TFivesSubOption">
        <id column="id" property="id"/>
        <id column="ref_id" property="refId"/>
        <id column="parent_id" property="parentId"/>
        <id column="tenant_id" property="tenantId"/>
        <id column="process_id" property="processId"/>
        <id column="process_status" property="processStatus"/>
        <id column="org_id" property="orgId"/>
        <id column="name" property="name"/>
        <id column="content" property="content"/>
        <id column="detail_rules" property="detailRules"/>
        <id column="content_type" property="contentType"/>
        <id column="score" property="score"/>
        <id column="sub_id" property="subId"/>
    </resultMap>

    <!--<if test="query.detailRules!=null and query.detailRules!=''">
        AND ts.detail_rules LIKE CONCAT('%',#{query.detailRules},'%')
    </if>-->
    <!--  AND tf.content_type='1'  -->
    <select id="standardCheck" resultMap="BaseResultMap"
            parameterType="com.testor.module.fives.model.dto.TFivesSubOptionParam">
        SELECT tf.name,ts.content,ts.score,ts.detail_rules,ts.id,ts.create_by,ts.create_date,ts.update_by,ts.update_date
        FROM t_fives_sub_option AS ts LEFT JOIN t_fives_sub_option AS tf ON tf.id=ts.sub_id
        WHERE tf.parent_id = #{query.id} AND ts.status=0 AND tf.status=0
        <if test="query.name!=null and query.name!=''">
            AND tf.name=#{query.name}
        </if>
        <if test="query.content!=null and query.content!=''">
            AND (ts.content LIKE CONCAT('%',#{query.content},'%') OR ts.detail_rules LIKE
            CONCAT('%',#{query.content},'%'))
        </if>
        ORDER BY tf.name, ts.create_date
    </select>

    <select id="standardCheckSum" resultType="string"
            parameterType="com.testor.module.fives.model.dto.TFivesSubOptionParam">
        SELECT ifnull(sum(ts.score),0) as list_total_score
        FROM t_fives_sub_option AS ts LEFT JOIN t_fives_sub_option AS tf ON tf.id=ts.sub_id
        WHERE tf.parent_id = #{query.id} AND ts.status=0 AND tf.status=0
        <if test="query.name!=null and query.name!=''">
            AND tf.name=#{query.name}
        </if>
        <if test="query.content!=null and query.content!=''">
            AND (ts.content LIKE CONCAT('%',#{query.content},'%') OR ts.detail_rules LIKE
            CONCAT('%',#{query.content},'%'))
        </if>
        ORDER BY tf.name, ts.create_date
    </select>

    <select id="getMainContent" resultType="string" parameterType="string">
        SELECT tf.name
        FROM t_fives_sub_option AS tf
        WHERE tf.parent_id = #{id}
          AND tf.content_type = '1'
          AND tf.status = 0
        ORDER BY tf.name;
    </select>


</mapper>