ration-broker-record-mapper.xml 3.79 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.ration.RationBrokerRecordDao">

	<sql id="ration_broker_record_field">
		t.id, ration_broker_config_id, ration_broker_user_id, matched, sell_user_id, sell_otc_account, 
		buy_user_id, buy_otc_account, fund, stock_amount, t.ration_status, cost_price_status, remark, t.create_at, t.create_by
	</sql>

	<insert id="save" parameterType="RationBrokerRecordInfo" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		insert into ration_broker_record(ration_broker_config_id, ration_broker_user_id, matched, sell_user_id, sell_otc_account, 
			buy_user_id, buy_otc_account, fund, stock_amount, ration_status, cost_price_status, remark, create_at, create_by) 
		values(#{rationBrokerConfigId}, #{rationBrokerUserId}, #{matched}, #{sellUserId}, #{sellOtcAccount}, #{buyUserId}, 
			#{buyOtcAccount}, #{fund}, #{stockAmount}, #{rationStatus}, '0', #{remark}, now(), #{createBy})
	</insert>
	
	<sql id="searchCondition">
		where 1 = 1 
		<if test="rationBrokerConfigId != null and rationBrokerConfigId != ''">
			and ration_broker_config_id = #{rationBrokerConfigId} 
		</if>
		<if test="sellUserId != null and sellUserId != ''">
			and sell_user_id = #{sellUserId} 
		</if>
		<if test="buyUserId != null and buyUserId != ''">
			and buy_user_id = #{buyUserId} 
		</if>
		<if test="rationStatus != null and rationStatus != ''">
			and t.ration_status = #{rationStatus} 
		</if>
		<if test="matched != null and matched != ''">
			and matched = #{matched} 
		</if>
		<if test="confirmStartDate != null and confirmStartDate != ''">
			<![CDATA[and t.create_at >= #{confirmStartDate} ]]>
		</if>
		<if test="confirmEndDate != null and confirmEndDate != ''">
			<![CDATA[and t.create_at <= #{confirmEndDate} ]]>
		</if>
	</sql>
	
	<select id="search" parameterType="map" resultType="map">
		select <include refid="ration_broker_record_field" />, r.otc_code, r.otc_name 
		from ration_broker_record t 
		inner join ration_broker_config r 
		on r.id = t.ration_broker_config_id 
		<include refid="searchCondition" />
		<if test="otcCode != null and otcCode != ''">
			and r.otc_code = #{otcCode} 
		</if>
		order by t.id desc 
		<include refid="common.pageLimit" />
	</select>
	
	<select id="searchTotal" parameterType="map" resultType="int">
		select count(1) from ration_broker_record t 
		<include refid="searchCondition" />
	</select>
	
	<select id="searchFooter" parameterType="map" resultType="map">
		select sum(fund) fund, sum(stock_amount) stock_amount 
		from ration_broker_record t 
		<include refid="searchCondition" /> 
	</select>
	
	<update id="updateStatus" parameterType="RationBrokerRecordInfo">
		update ration_broker_record set ration_status = #{rationStatus} 
		where id = #{id}
	</update>
	
	<select id="queryFailed" parameterType="int" resultType="int">
		select count(1) from ration_broker_record 
		where ration_broker_config_id = #{rationBrokerRecordId} and remark = '可用资金不足'
	</select>
	
	<update id="updateRemark" parameterType="RationBrokerRecordInfo">
		update ration_broker_record set remark = #{remark} 
		where id = #{id}
	</update>
	
	<select id="queryForCostPrice" parameterType="int" resultType="map">
		select t.id,r.otc_code otcCode,r.price,t.buy_user_id userId,t.stock_amount stockAmount 
		from ration_broker_record t 
		inner join ration_broker_config r 
		on t.ration_broker_config_id = r.id 
		where cost_price_status = '0' 
		and t.ration_status = '1' and t.ration_broker_config_id = #{rationBrokerConfigId}
	</select>
	
	<update id="updateCostPriceStatus" parameterType="int">
		update ration_broker_record set cost_price_status = '1' 
		where id = #{id} and cost_price_status = '0'
	</update>
</mapper>