<?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.hotent.surveyinfo.dao.CostSurveyFdTemplateVersionDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hotent.surveyinfo.model.CostSurveyFdTemplateVersion">
        <id column="id" property="id" />
        <result column="survey_template_id" property="surveyTemplateId" />
        <result column="status" property="status" />
        <result column="version_no" property="versionNo" />
        <result column="survey_template_name" property="surveyTemplateName" />
        <result column="remarks" property="remarks" />
        <result column="create_time" property="createTime" />
        <result column="create_by" property="createBy" />
        <result column="update_time" property="updateTime" />
        <result column="update_by" property="updateBy" />
        <result column="template_type" property="templateType" />
        <result column="order_num" property="orderNum" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, survey_template_id, status, version_no, survey_template_name, remarks, create_time, create_by, update_time, update_by, template_type,order_num
    </sql>

	<select id="selectPage" resultMap="BaseResultMap">
		select 
			<include refid="Base_Column_List"/> 
		from
        cost_survey_fd_template_version
		${ew.customSqlSegment}
	</select>
	
	<select id="selectList" resultMap="BaseResultMap">
		select 
			<include refid="Base_Column_List"/> 
		from
        cost_survey_fd_template_version
		${ew.customSqlSegment}
	</select>
	
	<select id="selectById" resultMap="BaseResultMap">
		select 
			<include refid="Base_Column_List"/> 
		from
        cost_survey_fd_template_version
		where 
		    id = #{id}
	</select>
    <!-- 根据条件查询 -->
    <select id="selectByCondition" parameterType="com.hotent.surveyinfo.model.CostSurveyFdTemplateVersion" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM cost_survey_fd_template_version
        <where>
            <if test="surveyTemplateId != null and surveyTemplateId != ''">
                AND survey_template_id = #{surveyTemplateId}
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
            <if test="versionNo != null and versionNo != ''">
                AND version_no = #{versionNo}
            </if>
            <if test="surveyTemplateName != null and surveyTemplateName != ''">
                AND survey_template_name = #{surveyTemplateName}
            </if>
        </where>
    </select>
    <select id="selectBySurveyTemplateId" resultType="com.hotent.surveyinfo.model.CostSurveyFdTemplateVersion">
        SELECT
           <include refid="Base_Column_List"/>
        FROM
        cost_survey_fd_template_version
        WHERE survey_template_id = #{surveyTemplateId}
        ORDER BY create_time DESC
    </select>
</mapper>
