quota-config-mapper.xml 4.75 KB
<?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">

<!-- 权益分配 @author tongxiaochuan -->
<mapper namespace="com.cjs.cms.dao.quota.QuotaConfigDao">

	<sql id="quota_config_field">
		id,otc_code,otc_name,trust_otc_code,trust_otc_name,percent,valid_start_date,valid_end_date,trade_start_date,trade_end_date,allot,update_at,update_by 
	</sql>
	
	<insert id="insertQuotaConfig" parameterType="QuotaConfigInfo">
		insert into quota_config(otc_code,otc_name,trust_otc_code,trust_otc_name,percent,valid_start_date,valid_end_date,trade_start_date,trade_end_date,create_at,create_by,update_at,update_by) 
		values(#{otcCode},#{otcName},#{trustOtcCode},#{trustOtcName},#{percent},#{validStartDate},#{validEndDate},#{tradeStartDate},#{tradeEndDate},CURRENT_TIMESTAMP,#{createBy},CURRENT_TIMESTAMP,#{createBy})
	</insert>
	
	<select id="search" parameterType="java.util.Map" resultType="QuotaConfigInfo">
		select <include refid="quota_config_field" />
		from quota_config where 1=1 
		<include refid="searchCondition"/> 
		order by id desc 
		<include refid="common.pageLimit" />
	</select>
	
	<select id="searchTotal" parameterType="java.util.Map" resultType="java.lang.Integer">
		select count(1) from quota_config where 1=1 
		<include refid="searchCondition"/>
	</select>
	
	<sql id="searchCondition">
		<if test="otcCode != null and otcCode != ''">
			and otc_code = #{otcCode} 
		</if>
		<if test="trustOtcCode != null and trustOtcCode != ''">
			and trust_otc_code = #{trustOtcCode} 
		</if>
		<if test="otcName != null and otcName != ''">
			and instr(otc_name, #{otcName}) > 0 
		</if>
		<if test="validStartDate != null and validStartDate != ''">
			<![CDATA[and valid_start_date >= #{validStartDate} ]]>
		</if>
		<if test="validEndDate != null and validEndDate != ''">
			<![CDATA[and valid_end_date <= #{validEndDate} ]]>
		</if>
		<if test="tradeStartDate != null and tradeStartDate != ''">
			<![CDATA[and trade_start_date >= #{tradeStartDate} ]]>
		</if>
		<if test="tradeEndDate != null and tradeEndDate != ''">
			<![CDATA[and trade_end_date <= #{tradeEndDate} ]]>
		</if>
	</sql>
	
	<!-- 更新分配状态 -->
	<update id="updateAllotById" parameterType="Map">
		update quota_config set allot = #{allot}, update_by = #{updateBy}, update_at = CURRENT_TIMESTAMP 
			where id = #{id}
	</update>
	
	<update id="updateConfig" parameterType="QuotaConfigInfo">
		update quota_config set otc_code = #{otcCode}, otc_name = #{otcName}, trust_otc_code = #{trustOtcCode}, trust_otc_name = #{trustOtcName}, 
			percent = #{percent}, valid_start_date = #{validStartDate}, valid_end_date = #{validEndDate},trade_start_date = #{tradeStartDate}, 
			trade_end_date = #{tradeEndDate}, update_at = CURRENT_TIMESTAMP, update_by = #{updateBy} 
		where id = #{id}
	</update>
	
	<!-- 根据id查询信息 -->
	<select id="getConfigById" parameterType="int" resultType="QuotaConfigInfo">
		select <include refid="quota_config_field" /> from quota_config where id=#{id}
	</select>
	
	<!-- 查询最后一次单品的托管结束时间 -->
	<select id="queryByOtcCode" parameterType="String" resultType="QuotaConfigInfo">
		select <include refid="quota_config_field" /> from quota_config 
		where otc_code = #{otcCode} and allot != 2 
		order by valid_end_date desc 
		 limit 0,1
	</select>
	
	<!-- 获取上一次分配信息 -->
	<select id="queryByOtcCode2" parameterType="String" resultType="QuotaConfigInfo">
		select <include refid="quota_config_field" /> from quota_config 
		where otc_code = #{otcCode} and allot = 1 
		order by valid_end_date desc 
		 limit 0,1
	</select>
	
	<select id="queryValidDate" resultType="map">
	    select trust_otc_code,  valid_start_date from 
	    quota_config where allot = 1 
	    and  now() between valid_start_date and valid_end_date 
	</select>
	
	<!-- 查询过期持仓藏品代码 -->
	<select id="queryPositionPast"  resultType="QuotaConfigInfo">
	    select id, otc_code, trade_end_date from quota_config  
        where  quota_config.allot = 1 and now()  >= trade_end_date and canceled_position = 0
	</select>
	
	<!-- 查询过期额度藏品代码 -->
	<select id="queryQuotaPast"  resultType="QuotaConfigInfo">
	    select id, otc_code, valid_end_date from quota_config  
        where  quota_config.allot = 1 and now()  >= valid_end_date and canceled_quota = 0
	</select>
	
	
	<update id="updateCanceledPosition" parameterType="int">
	    update quota_config set canceled_position = 1 where id = #{id}
	</update>
	
	<update id="updateCanceledQuota" parameterType="int">
	    update quota_config set canceled_quota = 1 where id = #{id}
	</update>
	
	<select id="queryOtcCode" parameterType="String" resultType="String">
	    select distinct otc_code from quota_config where trust_otc_code = #{otcCode}
	</select>
</mapper>