entrust-mapper.xml 5.76 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 kongmingke -->
<mapper namespace="com.cjs.site.dao.user.ration.EntrustDao">
	<sql id="entrust_field">
		OTC_CODE,OTC_NAME,APPROVAL_COUNT,APPLY_NO,BACK_AMOUNT,APPLY_TYPE,APPLY_DATE,TRUSTEE_FARE,APPLY_COUNT
	</sql>
	<select id="queryEntrust" resultType="map" parameterType="map">	
		SELECT STORELIST.*, NVL(T_EXT.AGGREE_STATUS, -1) AGGREE_STATUS
		FROM (SELECT OTC_CODE,
		             T.APPLY_NO,
		             OTC_NAME,
		             APPROVAL_COUNT,
		             BACK_AMOUNT,
		             REMOVE_WAY,
		             APPLY_TYPE,
		             APPLY_COUNT,
		             RETURNS.RETURN_STATUS,
		             RETURNS.RETURN_TYPE
		        FROM HS_ASSET.TRUSTAPPLY T
		        LEFT JOIN (SELECT APPLY_NO, RETURN_STATUS, T_RELATION.RETURN_TYPE
		                    FROM HS_ASSET.TRUSTAPPLY_RETURN_RELATION T_RELATION
		                    LEFT JOIN HS_ASSET.TRUSTAPPLY_RETURN T_RETURN 
		                    ON T_RETURN.RETURN_NO = T_RELATION.RETURN_NO
		                   WHERE (T_RETURN.RETURN_STATUS != 0 OR T_RETURN.RETURN_STATUS IS NULL)) RETURNS 
		        ON T.APPLY_NO = RETURNS.APPLY_NO
		       WHERE FUND_ACCOUNT = #{fund_account}
		         AND APPLY_TYPE IN (3, 4, 5, 6, 8)
		         AND RETURN_STATUS IS NULL
		         <if test="result == 'entrustStockList.jsp'">
			      AND APPLY_TYPE NOT IN (5,6)
				 </if>
			     <if test="result == 'entrustStockListNow.jsp'">
			     <!-- <![CDATA[ and AUDIT_DATE >= #{auditDate}]]> -->
			       AND REMOVE_WAY != '1' 
			       AND BACK_AMOUNT > 0
				 </if>
				 <if test="result == 'entrustStockListPast.jsp'">
			     <!-- <![CDATA[ AND AUDIT_DATE < #{auditDate}]]> -->
	               AND REMOVE_WAY != '1'
	               AND BACK_AMOUNT > 0
				 </if>
		         AND (RETURN_TYPE != 2 OR RETURN_TYPE IS NULL)
		       ORDER BY T.APPLY_DATE DESC) STORELIST
		LEFT JOIN HS_ASSET.TRUSTAPPLY_EXT T_EXT ON STORELIST.APPLY_NO = T_EXT.APPLY_NO
	</select>

	<select id="queryEntrustReturn" resultType="map" parameterType="map">
		select APPLY_NO
		from hs_asset.trustapply
		where fund_account = #{fund_account}
		and addressx not like '赵涌在线:%'
		and apply_type in(3,4,5,6) 
		and BACK_AMOUNT > 0
		and REMOVE_WAY in('0','-',' ')
		<!-- <if test="result == 'entrustStockListNow.jsp'">
		  <![CDATA[ and AUDIT_DATE >= #{auditDate}]]>
	    </if>
		<if test="result == 'entrustStockListPast.jsp'">
		  <![CDATA[ and AUDIT_DATE < #{auditDate}]]>
	    </if> -->
		and apply_no not in
		(select apply_no
		from hs_asset.trustapply_return t_return,
		hs_asset.trustapply_return_relation t_relation
		where t_return.return_no = t_relation.return_no
		and t_return.client_id = #{fund_account}
		and return_type in (0, 2) and t_return.return_status != 0)
	</select>

	<select id="queryReturnTotal" resultType="int" parameterType="map">
		select nvl(SUM(BACK_AMOUNT),0) back_amount
		from hs_asset.trustapply
		where fund_account = #{fund_account}
		and addressx not like '赵涌在线:%'
		and apply_type in(3,4,5,6) 
		and BACK_AMOUNT > 0
		and remove_way in ('0','-')
		<!-- <if test="result == 'entrustStockListNow.jsp'">
		  <![CDATA[ and AUDIT_DATE >= #{auditDate}]]>
	    </if>
		<if test="result == 'entrustStockListPast.jsp'">
		  <![CDATA[ and AUDIT_DATE < #{auditDate}]]>
	    </if> -->
		and apply_no not in
		(select apply_no
		from hs_asset.trustapply_return t_return,
		hs_asset.trustapply_return_relation t_relation
		where t_return.return_no = t_relation.return_no
		and t_return.client_id = #{fund_account}
		and return_type in (0, 2) and t_return.return_status != 0)
	</select>

	<!-- oracle分页查询 指定用户托管藏品 -->
	<select id="search" parameterType="map" resultType="map">
		<include refid="common.pageStart" />
		select
		<include refid="entrust_field" />
		from hs_asset.trustapply
		where fund_account = #{fund_account}
		order by APPLY_DATE desc, apply_no
		<include refid="common.pageEnd" />
	</select>

	<select id="searchTotal" parameterType="map" resultType="int">
		select
		count(*) from(
		select OTC_CODE,OTC_NAME,APPROVAL_COUNT,APPLY_NO,APPROVAL_COUNT,BACK_AMOUNT
		from hs_asset.trustapply
		where fund_account = #{fund_account}
		)
	</select>



	<select id="searchAgreeRationEntrust" resultType="map"
		parameterType="map">
		select OTC_CODE,OTC_NAME,APPLY_NO,APPROVAL_COUNT,BACK_AMOUNT
		from
		hs_asset.trustapply
		where hs_asset.trustapply .fund_account = #{clientId} and
		hs_asset.trustapply .otc_code = #{otcCode}
		and hs_asset.trustapply .apply_type in (4, 5)
		and hs_asset.trustapply .apply_no not in (select apply_no from
		hs_asset.trustapply_ext)
	</select>

	<!-- 查询直接上市入库藏品 -->
	<select id="queryDirectEntrust" resultType="map" parameterType="map">
		select OTC_CODE, SUM(APPROVAL_COUNT) APPROVAL_COUNT, STORAGE_DATE
		from
		hs_asset.trustapply t
		where t.fund_account = #{clientId}
		and t.apply_type in (5, 6)
		group by OTC_CODE, STORAGE_DATE
	</select>

	<select id="queryUserTrust" parameterType="map" resultType="map">
		SELECT T.OTC_CODE,
		T.OTC_NAME,
		SUM(T.APPROVAL_COUNT) APPROVAL_TOTAL,
		SUM(NVL(TE.AGGREE_STATUS, 0)) AGGREE_STATUS
		FROM HS_ASSET.TRUSTAPPLY T
		LEFT JOIN HS_ASSET.TRUSTAPPLY_EXT TE ON T.APPLY_NO = TE.APPLY_NO
		WHERE T.FUND_ACCOUNT = #{fund_account}
		AND (TE.AGGREE_STATUS != '2' OR TE.AGGREE_STATUS IS NULL)
		AND T.APPLY_TYPE IN (4, 5)
		AND T.OTC_CODE IN
		<foreach collection="otcCodes" item="code" open="(" close=")"
			separator=","> #{code} </foreach>
		GROUP BY T.OTC_CODE, T.OTC_NAME
		ORDER BY T.OTC_CODE
	</select>

	<select id="queryEntrustByApplyNO" resultType="map"
		parameterType="String">
		SELECT
		<include refid="entrust_field" />
		FROM HS_ASSET.TRUSTAPPLY
		WHERE APPLY_NO = #{applyNo}
	</select>

</mapper>