trust-apply-mapper.xml 13.6 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 仝玉甫 -->
<mapper namespace="com.cjs.cms.dao.ration.TrustApplyDao">
	
	<sql id="querySumCondition">
		<if test="otcCode != null and otcCode != ''">
			and t.otc_code = #{otcCode}
		</if>
		<if test="startDate != null and startDate != ''">
			<if test="applyType == -1">
				<![CDATA[and t.apply_date >= #{startDate}]]>
			</if>
			<if test="applyType == 6">
				<![CDATA[and t.storage_date >= #{startDate}]]>
			</if>
		</if>
		<if test="endDate != null and endDate != ''">
			<if test="applyType == -1">
				<![CDATA[and t.apply_date <= #{endDate}]]>
			</if>
			<if test="applyType == 6">
				<![CDATA[and t.storage_date <= #{endDate}]]>
			</if>
		</if>
	</sql>
	
	<!-- 托管统计 -->
	<select id="querySum" resultType="map" parameterType="map">
		<include refid="common.pageStart"/>
		  SELECT A.*, C.OTC_NAME,
			(SELECT MAX(B.STORAGE_DATE) 
			FROM HS_ASSET.TRUSTAPPLY B 
			WHERE B.OTC_CODE = A.OTC_CODE) AS LAST_STORAGE_DATE
		FROM 
			(SELECT OTC_CODE,
	        SUM(APPLY_COUNT) APPLY_COUNT_SUM, 
	        SUM(APPROVAL_COUNT) APPROVAL_COUNT_SUM,
	        SUM(BACK_AMOUNT) BACK_AMOUNT_SUM, 
	        SUM(PRE_IN_AMOUNT) PRE_IN_AMOUNT_SUM,
	        sum(RETURNS_BACK_AMOUNT)RETURN_BACK_AMOUNT,
	        sum(RETURNS_EXT_APPROVAL_COUNT)RETURN_EXT_APPROVAL_COUNT
	        from(
				select T.APPLY_COUNT, T.APPROVAL_COUNT , T.BACK_AMOUNT, T.PRE_IN_AMOUNT, OTC_CODE, OTC_NAME,
				case when T.remove_way = '1' then T.BACK_AMOUNT else 0 end as RETURNS_BACK_AMOUNT,
				case when t_ext.return_status = '2'then T.BACK_AMOUNT else 0 end as RETURNS_EXT_APPROVAL_COUNT
				FROM HS_ASSET.TRUSTAPPLY T, hs_asset.trustapply_ext t_ext
				WHERE T.apply_no = t_ext.apply_no(+) and
				T.APPLY_TYPE not in ('1', '7')
				<include refid="querySumCondition" />  
		    )GROUP BY OTC_CODE) A, HS_OTC.OTCCODE C
		WHERE A.OTC_CODE = C.OTC_CODE
		<if test="orderBy == 0">
			ORDER BY A.OTC_CODE
		</if>
		<if test="orderBy == 1">
			ORDER BY LAST_STORAGE_DATE DESC
		</if>
		<include refid="common.pageEnd"/>
	</select>
	<select id="querySumTotal" resultType="int" parameterType="map">
		SELECT COUNT(*)
		FROM 
			(SELECT OTC_CODE,OTC_NAME, 
	        SUM(APPLY_COUNT) APPLY_COUNT_SUM, 
	        SUM(APPROVAL_COUNT) APPROVAL_COUNT_SUM,
	        SUM(BACK_AMOUNT) BACK_AMOUNT_SUM, 
	        SUM(PRE_IN_AMOUNT) PRE_IN_AMOUNT_SUM,
	        sum(RETURNS_BACK_AMOUNT)RETURN_BACK_AMOUNT,
	        sum(RETURNS_EXT_APPROVAL_COUNT)RETURN_EXT_APPROVAL_COUNT
	        from(
	        select T.APPLY_COUNT, T.APPROVAL_COUNT , T.BACK_AMOUNT, T.PRE_IN_AMOUNT, OTC_CODE, OTC_NAME,
	        case when T.remove_way = '1' then T.BACK_AMOUNT else 0 end as RETURNS_BACK_AMOUNT,
	        case when t_ext.return_status = '2'then T.BACK_AMOUNT else 0 end as RETURNS_EXT_APPROVAL_COUNT
	      FROM HS_ASSET.TRUSTAPPLY T, hs_asset.trustapply_ext t_ext
	      WHERE T.apply_no = t_ext.apply_no(+) and
	      T.APPLY_TYPE not in ('1','7')
			<include refid="querySumCondition" />  
		)GROUP BY OTC_CODE,OTC_NAME) A, HS_OTC.OTCCODE C
		WHERE A.OTC_CODE = C.OTC_CODE
	</select>
	
	<!-- 托管详情 -->
	<sql id="searchCondition">
		WHERE T.APPLY_TYPE != 1 
		<if test="otcCode != null and otcCode != ''">
			AND INSTR(T.OTC_CODE, #{otcCode}) > 0 
		</if>
		<if test="otcName != null and otcName != ''">
			AND INSTR(T.OTC_NAME, #{otcName}) > 0 
		</if>
		<if test="applyType != null and applyType != ''">
			AND INSTR(#{applyType}, T.APPLY_TYPE) > 0  
		</if>
		<if test="startDate != null and startDate != ''">
			<![CDATA[AND T.CURR_DATE >= #{startDate}]]>
		</if>
		<if test="endDate != null and endDate != ''">
			<![CDATA[AND T.CURR_DATE <= #{endDate}]]>
		</if>
		<if test="innercirculatNo != null and innercirculatNo != ''">
			AND T.INNERCIRCULAT_NO = #{innercirculatNo} 
		</if>
		<if test="fundAccount != null and fundAccount != ''">
			AND T.FUND_ACCOUNT = #{fundAccount}
		</if>
		<if test="telphone != null and telphone != ''">
			AND INSTR(T.TELPHONE, #{telphone}) > 0 
		</if>
		<if test="clientName != null and clientName != ''">
			AND INSTR(T.CLIENT_NAME, #{clientName}) > 0 
		</if>
		<if test="code != null and code != ''">
			AND W.CODE = #{code} 
		</if>
		<if test="name != null and name != ''">
			AND W.NAME = #{name} 
		</if>
		<if test="idNo != null and idNo != ''">
			AND T.ID_NO = #{idNo} 
		</if>
		<if test="applyNo != null and applyNo != ''">
			AND T.APPLY_NO = #{applyNo} 
		</if>
	</sql>
	<select id="search" parameterType="map" resultType="map">
		<include refid="common.pageStart"/>
		SELECT T.*,W.CODE,W.NAME 
		FROM HS_ASSET.TRUSTAPPLY T 
		LEFT JOIN HS_ASSET.WAREHOUSE W ON T.ACCEPT_NO = W.CODE 
		<include refid="searchCondition" />
		ORDER BY T.INNERCIRCULAT_NO DESC
		<include refid="common.pageEnd"/>
	</select>
	<select id="searchTotal" parameterType="map" resultType="int">
		SELECT COUNT(*) 
		FROM HS_ASSET.TRUSTAPPLY T 
		LEFT JOIN HS_ASSET.WAREHOUSE W ON T.ACCEPT_NO = W.CODE 
		<include refid="searchCondition" />
	</select>
	
	
	<sql id="trust_apply_field">
		APPLY_NO,FUND_ACCOUNT,CLIENT_NAME,APPLY_DATE,OTC_CODE,OTC_NAME,APPLY_COUNT,ISSUE_PRICE,APPRAISAL_FARE,TRUSTEE_FARE,REMARK
	</sql>
	<!-- 托管申请查询 -->
	<select id="selectApply" parameterType="Map" resultType="Map">
		<include refid="common.pageStart" /> 
		select <include refid="trust_apply_field" /> from HS_ASSET.TRUSTAPPLY_VIEW 
		where 1=1 and APPLY_TYPE != 1 
		<include refid="selectApplyCondition" /> 
		order by APPLY_NO desc 
		<include refid="common.pageEnd" />
	</select>
	
	<sql id="selectApplyCondition">
		<if test="startDate != null and startDate != ''">
			<![CDATA[and APPLY_DATE >= #{startDate}]]>
		</if>
		<if test="endDate != null and endDate != ''">
			<![CDATA[and APPLY_DATE <= #{endDate}]]>
		</if>
		<if test="otcCode != null and otcCode != ''">
			and otc_code = #{otcCode}
		</if>
		<if test="fundAccount != null and fundAccount != ''">
			and fund_account = #{fundAccount} 
		</if>
	</sql>
	
	<select id="selectApplyTotal" parameterType="Map" resultType="int">
		select count(1) from HS_ASSET.TRUSTAPPLY_VIEW 
		where 1=1  and APPLY_TYPE != 1 
		<include refid="selectApplyCondition" /> 
	</select>
	<!-- 申请数量、鉴定费用、上挂费用汇总 -->
	<select id="selectApplySumTotal"  parameterType="Map" resultType="Map">
		select sum(APPLY_COUNT) as APPLY_COUNT,sum(APPRAISAL_FARE) as APPRAISAL_FARE,
		sum(TRUSTEE_FARE) as TRUSTEE_FARE from HS_ASSET.TRUSTAPPLY_VIEW 
		where 1=1  and APPLY_TYPE != 1 
		<include refid="selectApplyCondition" /> 
	</select>
	
	
	<!-- 托管转赵涌在线数据查询 -->
	<sql id="apply_to_zhaoonline_field">
		INNERCIRCULAT_NO,OTC_CODE,OTC_NAME,FUND_ACCOUNT,CLIENT_NAME,APPLY_COUNT,APPROVAL_COUNT,BACK_AMOUNT,
		STORAGE_DATE,APPLY_TYPE,REMARK,ADDRESSX
	</sql>
	<sql id="apply_to_zhaoonline_field2">
		INNERCIRCULAT_NO,OTC_CODE,OTC_NAME,FUND_ACCOUNT,CLIENT_NAME,ID_NO,TELPHONE, APPLY_COUNT,APPROVAL_COUNT,BACK_AMOUNT,
    STORAGE_DATE,APPLY_TYPE,REMARK,ADDRESSX
	</sql>
	<select id="selectToOnline2" parameterType="Map" resultType="Map">
		<include refid="common.pageStart" /> 
		select <include refid="apply_to_zhaoonline_field2" /> from HS_ASSET.TRUSTAPPLY
		where BACK_AMOUNT > 0 and ADDRESSX like '赵涌在线%' 
		<include refid="selectToOnlineCondition" /> 
		order by INNERCIRCULAT_NO desc 
		<include refid="common.pageEnd" />
	 </select>
	
	<select id="selectToOnline" parameterType="Map" resultType="Map">
		<include refid="common.pageStart" /> 
		select <include refid="apply_to_zhaoonline_field" /> from HS_ASSET.TRUSTAPPLY_VIEW 
		where BACK_AMOUNT > 0 and ADDRESSX like '赵涌在线%' 
		<include refid="selectToOnlineCondition" /> 
		order by INNERCIRCULAT_NO desc 
		<include refid="common.pageEnd" />
	</select>

	<select id="selectToOnlineTotal" parameterType="Map" resultType="int">
		select count(1) from HS_ASSET.TRUSTAPPLY_VIEW 
		where BACK_AMOUNT > 0 and ADDRESSX like '赵涌在线%' 
		<include refid="selectToOnlineCondition" /> 
	</select>
	
	<select id="selectByApplyNo" parameterType="String" resultType="map">
	    select apply_no, fund_account, otc_code, otc_name, apply_count, back_amount
	    from HS_ASSET.TRUSTAPPLY_VIEW 
	    where apply_no = #{applyNo}
	</select>
	
	<select id="queryByApplyNo" parameterType="string" resultType="map">
		SELECT APPLY_NO, FUND_ACCOUNT, OTC_CODE, OTC_NAME, APPLY_COUNT, 
		APPROVAL_COUNT, BACK_AMOUNT, ACCEPT_NO, APPLY_TYPE, APPRAISAL_FARE
		FROM HS_ASSET.TRUSTAPPLY 
		WHERE APPLY_NO = #{applyNo}
	</select>
	
	<!-- 转赵涌在线 -->
	<update id="updateAddressx" parameterType="String" >
	    update HS_ASSET.TRUSTAPPLY set addressx= concat('赵涌在线:',#{online})
	    where INNERCIRCULAT_NO = #{innerNo} 
	</update>
	
	<select id="isOnline" parameterType="Map" resultType="int">
	   select count(1)
	   from HS_ASSET.TRUSTAPPLY_VIEW
	   where addressx like '赵涌在线%' and  innercirculat_no=#{innerNo}
	</select>
	
	<sql id="selectToOnlineCondition">
		<if test="startDate != null and startDate != ''">
			<![CDATA[and STORAGE_DATE >= #{startDate}]]>
		</if>
		<if test="endDate != null and endDate != ''">
			<![CDATA[and STORAGE_DATE <= #{endDate}]]>
		</if>
		<if test="otcCode != null and otcCode != ''">
			and otc_code = #{otcCode}
		</if>
		<if test="fundAccount != null and fundAccount != ''">
			and fund_account = #{fundAccount} 
		</if>
	</sql>
	
	<!-- 导出后变更订单状态 -->
	<update id="exportUpdate" parameterType="map">
		update HS_ASSET.TRUSTAPPLY set CURR_DATE = #{currDate}, CURR_TIME = #{currTime},
			APPLY_TYPE = #{applyType}, REMARK = #{remark} 
		where APPLY_NO = #{applyNo}
	</update>
	
	<!-- 入库数据查询 -->
	<select id="queryStorageInfo" parameterType="map" resultType="map">
		<include refid="common.pageStart" /> 
		select apply_no, innercirculat_no, apply_date, fund_account, otc_code, otc_name, apply_count,
			approval_count, back_amount, apply_type, operator_name, storage_date, remark ,
			APPRAISAL_FARE, TRUSTEE_FARE
		from hs_asset.trustapply 
		<include refid="storageCondition" />
		order by apply_no desc 
		<include refid="common.pageEnd" />
	</select>
	
	<!-- 入库数据条目数查询 -->
	<select id="queryStorageTotal" parameterType="map" resultType="int">
		select count(1) from hs_asset.trustapply 
		<include refid="storageCondition" />
	</select>
	
	<sql id="storageCondition">
		where 1 = 1 
		<if test="otcCode != null and otcCode != ''">
			and otc_code = #{otcCode} 
		</if>
		<if test="otcName != null and otcName != ''">
			and otc_name = #{otcName} 
		</if>
		<if test="fundAccount != null and fundAccount != ''">
			and fund_account = #{fundAccount} 
		</if>
		<if test="innercirculatNo != null and innercirculatNo != ''">
			and innercirculat_no = #{innercirculatNo}
		</if>
		<if test="applyType != null and applyType != ''">
			and apply_type = #{applyType} 
		</if>
		<if test="applyNo != null and applyNo != ''">
			and apply_no = #{applyNo} 
		</if>
	</sql>
	
	<!-- 入库数据导出 -->
	<select id="queryForExport" parameterType="map" resultType="map">
		select otc_code,otc_account,approval_count from hs_asset.trustapply 
		where apply_type = '5' 
		<if test="otcCode != null and otcCode != ''">
			and otc_code = #{otcCode}
		</if>
	</select>
	
	<!-- 入库数据导出变更状态 -->
	<update id="storageExport" parameterType="map">
		update HS_ASSET.TRUSTAPPLY set CURR_DATE = #{currDate}, CURR_TIME = #{currTime},
			APPLY_TYPE = '6', REMARK = '确权文件已导出' 
		<include refid="storageCondition" />
		and APPLY_TYPE = '5' 
	</update>
	
	
	<sql id="queryAgreeSql">
		select a.otc_code,a.otc_name, a.innercirculat_no, a.fund_account, a.client_name,a.apply_no,a.mobile,
			a.telphone, a.approval_count, a.apply_count, a.apply_date,
		case when b.aggree_status is null then '未确认'
			else '同意' end aggree_status,
		case when b.aggree_status is null then ''
			else to_char(b.aggree_date)
		end aggree_date
		from hs_asset.trustapply a ,hs_asset.trustapply_ext b
		where a.apply_no=b.apply_no(+) and a.otc_code in
		<foreach collection="otcCodes" item="otcCode" open="(" close=")"
			separator=","> #{otcCode} </foreach>
		<if test="userId!=null and userId!=''">
			and a.fund_account=#{userId}
		</if>
		<if test="clientName!=null and clientName!=''">
			and a.client_name=#{clientName}
		</if>
		<if test="applyNo!=null and applyNo!=''">
			and a.apply_no=#{applyNo}
		</if>
		<if test="aggreeStatus ==0 and aggreeStatus!=''">
			and b.aggree_status is not null
		</if>
		<if test="aggreeStatus ==1 and aggreeStatus!=''">
			and b.aggree_status is null
		</if>
		<if test="startDate != null and startDate != ''">
			<![CDATA[ and to_date(to_char(b.aggree_date),'yyyyMMdd') >= to_date(#{startDate},'yyyy-MM-dd')]]>
		</if>
		<if test="endDate != null and endDate != ''">
			<![CDATA[ and to_date(to_char(b.aggree_date),'yyyyMMdd') <= to_date(#{endDate},'yyyy-MM-dd')]]>
		</if>
		order by  a.apply_date desc 
	</sql>
	<!-- 查看是否同意配售 -->
	<select id="queryAgree" parameterType="map" resultType="map">
		<include refid="common.pageStart" />
		<include refid="queryAgreeSql" />
		<include refid="common.pageEnd" />
	</select>
	
	<select id="queryAgreeTotal" parameterType="map" resultType="int">
		select count(1) from (
		<include refid="queryAgreeSql" />
		) a
	</select>
	
	<!-- 取消托管单 -->
	<update id="cancelApply" parameterType="string">
		UPDATE HS_ASSET.TRUSTAPPLY T SET T.APPLY_TYPE = '7', T.APPRAISAL_FARE = 0, T.REMARK = '客户取消托管'
		WHERE T.APPLY_NO = #{value} AND T.APPLY_TYPE = '2'
	</update>
	
	<!-- 鉴定否决 -->
	<update id="voteApply">
		UPDATE HS_ASSET.TRUSTAPPLY T SET T.APPLY_TYPE = '3', T.APPROVAL_COUNT = 0, 
			T.BACK_AMOUNT = #{backAmount}, T.REMARK = '鉴定否决'
		WHERE T.APPLY_NO = #{applyNo} AND T.APPLY_TYPE IN ('2', '3', '4')
	</update>
	
</mapper>