otc-entrust-batch-mapper.xml 3.21 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">

<!-- 当天委托交易(hs_otc.otcentrust) @author tongyufu -->
<mapper namespace="com.cjs.cms.dao.trade.OtcEntrustBatchDao">

	<sql id="otc_entrust_field">
		E.OTC_CODE, E.OTC_NAME, E.OTC_PROP, E.ENTRUST_PRICE, E.ENTRUST_AMOUNT, E.ENTRUST_STATUS,
		E.BUSINESS_PRICE, E.BUSINESS_AMOUNT, E.BUSINESS_BALANCE, E.CURR_DATE, E.CURR_TIME,
		E.SUCCESS, E.T2RESULT, E.POSITION_STR, E.OP_STATION, E.FUND_ACCOUNT, E.OTC_ACCOUNT
	</sql>
	
	<insert id="save" parameterType="OtcEntrustBatchInfo">
		INSERT INTO HS_ASSET.OTCENTRUST_BATCH (OTC_CODE, OTC_NAME, OTC_PROP, ENTRUST_PRICE, 
			BUSINESS_PRICE, BUSINESS_AMOUNT, BUSINESS_BALANCE, CURR_DATE, CURR_TIME,
			ENTRUST_AMOUNT, ENTRUST_STATUS, SUCCESS, T2RESULT, POSITION_STR, OP_STATION,
			FUND_ACCOUNT, OTC_ACCOUNT, CLIENT_ID)
		VALUES (#{otcCode}, #{otcName}, #{otcProp}, #{entrustPrice}, #{businessPrice}, 
			#{businessAmount}, #{businessBalance}, #{currDate}, #{currTime}, #{entrustAmount}, 
			#{entrustStatus}, #{success}, #{t2Result}, #{positionStr}, #{opStation},
			#{fundAccount}, #{otcAccount}, #{fundAccount})
	</insert>
	
	<!-- 查询指定op_station的下单日期 -->
	<select id="queryCurrDate" resultType="map" parameterType="map">
		SELECT E.OP_STATION, E.CURR_DATE
		FROM HS_ASSET.OTCENTRUST_BATCH E
		WHERE E.SUCCESS = '1' AND E.OP_STATION IN
		<foreach collection="opStations" item="opStation" open="(" close=")" separator=",">#{opStation}</foreach>
		<![CDATA[AND E.CURR_DATE <= ]]> #{initDate}
	</select>
	
	<sql id="searchCondition">
		where 1 = 1
		<if test="fundAccount != null and fundAccount != ''"> and e.fund_account = #{fundAccount} </if>
		<if test="otcCode != null and otcCode != ''"> and e.otc_code = #{otcCode} </if>
		<if test="success != null and success != ''"> and e.success = #{success} </if>
		<if test="otcProp != null and otcProp != ''"> and e.otc_prop = #{otcProp} </if>
		<if test="startDate != null and startDate != ''">
			<![CDATA[and e.curr_date >= #{startDate}]]>
		</if>
		<if test="endDate != null and endDate != ''">
			<![CDATA[and e.curr_date <= #{endDate}]]>
		</if>
	</sql>
	<select id="search" parameterType="map" resultType="OtcEntrustBatchInfo">
		<include refid="common.pageStart"/>
		SELECT <include refid="otc_entrust_field" />
		FROM (
			SELECT * FROM HS_ASSET.OTCENTRUST_BATCH
			UNION ALL
			SELECT * FROM HS_ASSET.HIS_OTCENTRUST_BATCH) E
		<include refid="searchCondition" />
		ORDER BY E.CURR_DATE DESC, E.CURR_TIME
		<include refid="common.pageEnd"/>
	</select>
	<select id="searchTotal" parameterType="map" resultType="int">
		SELECT COUNT(*)
		FROM (
			SELECT * FROM HS_ASSET.OTCENTRUST_BATCH
			UNION ALL
			SELECT * FROM HS_ASSET.HIS_OTCENTRUST_BATCH) E
		<include refid="searchCondition" />
	</select>
	
	<!-- 备份委托记录 -->
	<insert id="backupsEntrust" parameterType="int">
		INSERT INTO HS_ASSET.HIS_OTCENTRUST_BATCH 
		SELECT * FROM HS_ASSET.OTCENTRUST_BATCH E
		<![CDATA[WHERE E.CURR_DATE <= ]]> #{value}
	</insert>
	
	<!-- 删除已备份数据 -->
	<delete id="deleteToBackups" parameterType="int">
		DELETE HS_ASSET.OTCENTRUST_BATCH E
		<![CDATA[WHERE E.CURR_DATE <= ]]> #{value}
	</delete>
	
</mapper>