<?xml version="1.0" encoding="UTF-8" ?>    
<!DOCTYPE mapper    
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"    
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">

<mapper namespace="com.platform.dao.PreDataInfoDao">
	<resultMap id="getEntityByText" type="com.platform.entities.PreDataInfo">
		<id property="id" column="id" javaType="int" jdbcType="INTEGER" />
		<result property="areaCode" column="area_code"
			javaType="string" jdbcType="VARCHAR" />
		<result property="cityName" column="city_name" javaType="string"
			jdbcType="VARCHAR" />
		<result property="districtName" column="district_name"
			javaType="string" jdbcType="VARCHAR" />
		<result property="sysCode" column="sys_code" javaType="int"
			jdbcType="INTEGER" />
		<result property="sysName" column="system_name" javaType="string"
			jdbcType="VARCHAR" />
		<result property="areaLevel" column="area_level"
			javaType="string" jdbcType="VARCHAR" />
		<result property="dataVersion" column="data_version" javaType="string"
			jdbcType="VARCHAR" />
		<result property="beginUseTime" column="begin_in_use"
			javaType="string" jdbcType="VARCHAR" />
		<result property="functionDetails" column="function_details" javaType="string"
			jdbcType="VARCHAR" />
		<result property="departmentManager" column="department_manager" javaType="string"
			jdbcType="VARCHAR" />
		<result property="managerContacts" column="manager_contacts"
			javaType="string" jdbcType="VARCHAR" />
		<result property="developerFullName" column="sys_developer_full_name"
			javaType="string" jdbcType="VARCHAR" />
			
		<result property="dataBaseType" column="data_base_type"
			javaType="string" jdbcType="VARCHAR" />
		<result property="dataBaseVersion" column="data_base_version" javaType="string"
			jdbcType="VARCHAR" />
		<result property="budgetExecManage" column="is_budget_exec" javaType="string"
			jdbcType="VARCHAR" />
			
		<result property="budgetQuotaManage" column="is_budget_quota" javaType="string"
			jdbcType="VARCHAR" />
		<result property="collection" column="is_collection" javaType="string"
			jdbcType="VARCHAR" />
		<result property="departmentBudgetManage" column="is_department_budget" javaType="string"
			jdbcType="VARCHAR" />
		<result property="totalBudgetAccount" column="total_budget_account" javaType="string"
			jdbcType="VARCHAR" />
		<result property="finalAccountManage" column="final_account_manage" javaType="string"
			jdbcType="VARCHAR" />
		<result property="reportFormManage" column="report_form_manage" javaType="string"
			jdbcType="VARCHAR" />
		<result property="nonTaxManage" column="non_tax_revenue_manage" javaType="string"
			jdbcType="VARCHAR" />
		<result property="wageSystem" column="wage_system" javaType="string"
			jdbcType="VARCHAR" />
		<result property="analysisOfFinancialEconomicProsperity" column="analysis_of_financial_economic_prosperity" javaType="string"
		jdbcType="VARCHAR" />
		<result property="governmentDebtManage" column="government_debt" javaType="string"
		jdbcType="VARCHAR" />
	</resultMap>
	<sql id="conditionsFilters">
		<if test="cityName!=null">
			AND standard_data_details.city_name=#{cityName}
		</if>
		<if test="districtName!=null">
			AND
			standard_data_details.district_name=#{districtName}
		</if>
		<if test="dataVersion !=null">
			AND standard_data_details.data_version=#{dataVersion}
		</if>
		<if test="systemName !=null">
			AND standard_data_details.system_name=#{systemName}
		</if>
		<if test="array !=null and array.length > 0">
			<foreach collection="array" item="item" index="index">
			AND CONCAT(area_code,city_name,district_name,system_name) LIKE CONCAT('%',CONCAT(#{item},'%'))
			</foreach>
		</if>
	</sql>
	
	<!-- sql txt  Base_Column_List -->
	<sql id="Base_Column_List">
		id,area_code,city_name,district_name,system_name,sys_code,area_level,data_version,begin_in_use,function_details,
		department_manager,manager_contacts,sys_developer_full_name,data_base_type,data_base_version,
		is_budget_exec,is_budget_quota,is_collection,is_department_budget,total_budget_account,
		final_account_manage,report_form_manage,non_tax_revenue_manage,wage_system,
		analysis_of_financial_economic_prosperity,government_debt
	</sql>

	<!-- 获取数据符合筛选条件的全部记录信息 -->
	<select id="getLimitedDataInfoEntities" parameterType="com.platform.entities.PagerOptions"
		resultMap="getEntityByText">
		SELECT
		<include refid="Base_Column_List" />
		FROM standard_data_details
			<where>
				<include refid="conditionsFilters" />
				<choose>
					<when test="offset > 0">
						and standard_data_details.id>= #{offset}
					</when>
					<otherwise>
						and standard_data_details.id>=0
					</otherwise>
				</choose>
			</where>
			
			ORDER BY standard_data_details.area_code,standard_data_details.sys_code
			<if test="limit > 0">
				LIMIT #{limit}
			</if>
	</select>
	
	<!-- 获取数据符合筛选条件的全部记录信息 -->
	

	<!-- 获取数据符合筛选条件的总记录条数 -->
	<select id="getLimitedDataCount" resultType="java.lang.Integer"
		parameterType="com.platform.entities.PagerOptions">
		SELECT COUNT(id) FROM standard_data_details
			<where>
				<include refid="conditionsFilters" />
			</where>

	</select>

	<!-- 获取数据查询的起始di -->
	<select id="getLimitedBeginId" resultType="java.lang.Integer"
		parameterType="com.platform.entities.PagerOptions">
		SELECT MAX(idx) FROM (SELECT id idx FROM standard_data_details 
		ORDER BY id LIMIT 0,#{totalLimit}) AS TEMP
	</select>
	<select id="getIdIsExist" parameterType="java.util.List" resultType="java.lang.String">
		select data_path
		from standard_data_details
		where id in 
		<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
			#{item}
		</foreach>
	</select>
	
	<sql id="Batch_Column_List">
		area_code,sys_code,area_level,data_version,begin_in_use,function_details,
		department_manager,manager_contacts,sys_developer_full_name,data_base_type,data_base_version,
		is_budget_exec,is_budget_quota,is_collection,is_department_budget,total_budget_account,
		final_account_manage,report_form_manage,non_tax_revenue_manage,wage_system,
		analysis_of_financial_economic_prosperity,government_debt,update_time
	</sql>
	
	<!-- 查询所有 -->
	<select id="findAll" resultMap="getEntityByText">
		SELECT
		<include refid="Base_Column_List" />
		FROM standard_data_details
		ORDER BY standard_data_details.area_code,standard_data_details.sys_code
	</select>
	
	<select id="findAllCollect" resultMap="getEntityByText">
		SELECT
		<include refid="Base_Column_List" />
		FROM standard_data_details
		WHERE is_collection='是'
		ORDER BY standard_data_details.area_code,standard_data_details.sys_code
	</select>
	
	<!-- 批量插入 -->
	<select id="insertBatch" parameterType="java.util.List">
	    INSERT INTO default_data_description ( <include refid="Batch_Column_List" /> ) 
	    VALUES 
	    <foreach collection="list" item="item" index="index" separator=",">
	        (#{item.areaCode,jdbcType=VARCHAR},#{item.sysCode,jdbcType=INTEGER},#{item.areaLevel,jdbcType=VARCHAR},#{item.dataVersion,jdbcType=VARCHAR},#{item.beginUseTime},#{item.functionDetails},
	        #{item.departmentManager},#{item.managerContacts,jdbcType=VARCHAR},#{item.developerFullName,jdbcType=VARCHAR},#{item.dataBaseType,jdbcType=VARCHAR},#{item.dataBaseVersion,jdbcType=VARCHAR},
	        #{item.budgetExecManage},#{item.budgetQuotaManage,jdbcType=VARCHAR},#{item.collection,jdbcType=VARCHAR},#{item.departmentBudgetManage,jdbcType=VARCHAR},#{item.totalBudgetAccount,jdbcType=VARCHAR},
	        #{item.finalAccountManage},#{item.reportFormManage,jdbcType=VARCHAR},#{item.nonTaxManage,jdbcType=VARCHAR},#{item.wageSystem,jdbcType=VARCHAR},
	        #{item.analysisOfFinancialEconomicProsperity},#{item.governmentDebtManage},#{item.updateTime})
	    </foreach>
	</select> 
	
	<!-- 更新字段 -->
	<update id="update" parameterType="com.platform.entities.PreDataInfo">
		UPDATE
		default_data_description a
		<set>
			<trim suffixOverrides=",">
				<if test="collection != null and collection != ''">
					a.is_collection= #{collection},
				</if>
				<if test="areaLevel != null and areaLevel != ''">
					a.area_level= #{areaLevel},
				</if>
				<if test="dataVersion != null and dataVersion != ''">
					a.data_version= #{dataVersion},
				</if>
				<if test="beginUseTime != null and beginUseTime != ''">
					a.begin_in_use= #{beginUseTime},
				</if>
				<if test="functionDetails != null and functionDetails != ''">
					a.function_details= #{functionDetails},
				</if>
				<if test="departmentManager != null and departmentManager != ''">
					a.department_manager= #{departmentManager},
				</if>
				<if test="managerContacts != null and managerContacts != ''">
					a.manager_contacts= #{managerContacts},
				</if>
				<if test="developerFullName != null and developerFullName != ''">
					a.sys_developer_full_name= #{developerFullName},
				</if>
				<if test="dataBaseType != null and dataBaseType != ''">
					a.data_base_type= #{dataBaseType},
				</if>
				<if test="dataBaseVersion != null and dataBaseVersion != ''">
					a.data_base_version= #{dataBaseVersion},
				</if>
				<if test="departmentBudgetManage != null and departmentBudgetManage != ''">
					a.is_department_budget= #{departmentBudgetManage},
				</if>
				<if test="budgetQuotaManage != null and budgetQuotaManage != ''">
					a.is_budget_quota= #{budgetQuotaManage},
				</if>
				<if test="budgetExecManage != null and budgetExecManage != ''">
					a.is_budget_exec= #{budgetExecManage},
				</if>
				<if test="totalBudgetAccount != null and totalBudgetAccount != ''">
					a.total_budget_account= #{totalBudgetAccount},
				</if>
				<if test="finalAccountManage != null and finalAccountManage != ''">
					a.final_account_manage= #{finalAccountManage},
				</if>
				<if test="reportFormManage != null and reportFormManage != ''">
					a.report_form_manage= #{reportFormManage},
				</if>
				<if test="nonTaxManage != null and nonTaxManage != ''">
					a.non_tax_revenue_manage= #{nonTaxManage},
				</if>
				<if test="wageSystem != null and wageSystem != ''">
					a.wage_system= #{wageSystem},
				</if>
				<if test="analysisOfFinancialEconomicProsperity != null and analysisOfFinancialEconomicProsperity != ''">
					a.analysis_of_financial_economic_prosperity= #{analysisOfFinancialEconomicProsperity},
				</if>
				<if test="governmentDebtManage != null and governmentDebtManage != ''">
					a.government_debt= #{governmentDebtManage},
				</if>
				<if test="updateTime != null and updateTime != ''">
					a.update_time= #{updateTime},
				</if>
			</trim>
		</set>
		<where>
			a.area_code = #{areaCode}
			AND a.sys_code = #{sysCode}
			AND a.remove ='0'
		</where> 
	</update>
	
	<select id="getAreaSysNameExistByAreaSysName" parameterType="java.util.List" resultType="java.lang.String">
		SELECT
		CONCAT(area_code,',',system_name)
		FROM standard_data_details
		where
			CONCAT(area_code,',',system_name) IN 
		<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
			#{item}
		</foreach>
	</select>
	

</mapper>  