<?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.CostSurveyFdTemplateDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hotent.surveyinfo.model.CostSurveyFdTemplate">
        <id column="survey_template_id" property="surveyTemplateId" />
    <result column="survey_template_name" property="surveyTemplateName" />
    <result column="survey_template_name_yw" property="surveyTemplateNameYw" />
    <result column="template_type" property="templateType" />
    <result column="storage_table" property="storageTable" />
    <result column="status" property="status" />
    <result column="catalog_id" property="catalogId" />
    <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="content_type" property="contentType" />
    <result column="type" property="type" />
    <result column="remarks" property="remarks" />
	<result column="is_delete" property="isDelete" />

	<result column="area_code" property="areaCode" />
	<result column="area_level" property="areaLevel" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        survey_template_id, survey_template_name, survey_template_name_yw, template_type, storage_table, status, catalog_id, create_time, create_by, update_time, update_by, content_type, type, remarks,is_delete,area_code,area_level
    </sql>


	<!-- 根据条件查询模板列表 -->
	<select id="selectByCondition" parameterType="com.hotent.surveyinfo.model.CostSurveyFdTemplate" resultMap="BaseResultMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		cost_survey_fd_template
		<where>
			<if test="costSurveyFdTemplate.surveyTemplateId != null and costSurveyFdTemplate.surveyTemplateId != ''">
				AND survey_template_id = #{costSurveyFdTemplate.surveyTemplateId}
			</if>
			<if test="costSurveyFdTemplate.surveyTemplateName != null and costSurveyFdTemplate.surveyTemplateName != ''">
				AND survey_template_name LIKE CONCAT('%', #{costSurveyFdTemplate.surveyTemplateName}, '%')
			</if>
			<if test="costSurveyFdTemplate.surveyTemplateNameYw != null and costSurveyFdTemplate.surveyTemplateNameYw != ''">
				AND survey_template_name_yw = #{costSurveyFdTemplate.surveyTemplateNameYw}
			</if>
			<if test="costSurveyFdTemplate.templateType != null and costSurveyFdTemplate.templateType != ''">
				AND template_type = #{costSurveyFdTemplate.templateType}
			</if>
			<if test="costSurveyFdTemplate.storageTable != null and costSurveyFdTemplate.storageTable != ''">
				AND storage_table = #{costSurveyFdTemplate.storageTable}
			</if>
			<if test="costSurveyFdTemplate.status != null and costSurveyFdTemplate.status != ''">
				AND status = #{costSurveyFdTemplate.status}
			</if>
			<if test="costSurveyFdTemplate.catalogId != null and costSurveyFdTemplate.catalogId != ''">
				AND catalog_id = #{costSurveyFdTemplate.catalogId}
			</if>
			<if test="costSurveyFdTemplate.contentType != null and costSurveyFdTemplate.contentType != ''">
				AND content_type = #{costSurveyFdTemplate.contentType}
			</if>
			<if test="costSurveyFdTemplate.type != null and costSurveyFdTemplate.type != ''">
				AND type = #{costSurveyFdTemplate.type}
			</if>
			AND is_delete = 0
		</where>
	</select>

	<select id="selectPage" resultMap="BaseResultMap">
		select
			<include refid="Base_Column_List"/>
		from
		cost_survey_fd_template
		${ew.customSqlSegment}
	</select>

	<select id="selectList" resultMap="BaseResultMap">
		select
			<include refid="Base_Column_List"/>
		from
		cost_survey_fd_template
		${ew.customSqlSegment}
	</select>



	<select id="selectById" resultMap="BaseResultMap">
		select
			<include refid="Base_Column_List"/>
		from
		cost_survey_fd_template
		where
		    survey_template_id = #{surveyTemplateId}
	</select>



	<select id="getCostSurveyFdTemplatePage" resultMap="BaseResultMap">
		SELECT
		c.*
		FROM
		cost_survey_fd_template c
		<where>
			<if test=" contentType != null and  contentType != ''">
				and c.content_type=#{ contentType}
			</if>
			<if test=" type != null and  type != ''">
				and c.type=#{ type}
			</if>

			<if test=" keyword != null and  keyword != ''">
				and c.survey_template_name LIKE CONCAT('%', #{ keyword}, '%')
			</if>
			<if test=" status != null and  status != ''">
				and c.status=#{ status}
			</if>
			<if test=" dataScope != null and dataScope >= 0">
				<if test=" dataScope ==0">
					and c.area_code= #{provinceCode}
				</if>
				<if test=" dataScope ==1">
					and c.area_code=#{cityCode}
				</if>
				<if test=" dataScope ==2">
					and c.area_code= #{countyCode}
				</if>
			</if>
		</where>
		ORDER BY c.create_time DESC
	</select>


</mapper>
