user-balance-daily-mapper.xml 3.83 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.user.fund.UserBalanceListDao">

	<sql id="searchCondition">
		where 1=1 
		<if test="queryType != null and queryType != ''">
			<![CDATA[and IFNULL(t.current_balance, 0.00) != IFNULL(r.avl_bal, 0.00) ]]>
		</if>
		<if test="userId != null and userId != ''">
			and t.client_id = #{userId} 
		</if>
	</sql>
	
	<select id="search" parameterType="map" resultType="map">
		select t.client_id,t.current_balance as hundsun,IFNULL(r.avl_bal,0.00) as pnr,t.data_date from 
		(select format(a.current_balance,2) current_balance,a.client_id,a.data_date from fund_real a 
		where a.data_date = #{data_date} and a.current_balance != 0) t 
		left join 
		(select format(b.avl_bal,2) avl_bal, b.user_id, b.data_date from user_balance_huifu_daily b 
		where b.data_date = #{data_date} and b.avl_bal != 0) r 
		on t.client_id = r.user_id 
		<include refid="searchCondition" />
		union 
		select r.user_id,IFNULL(t.current_balance,0.00) as hundsun,r.avl_bal as pnr,r.data_date from 
		(select format(a.current_balance,2) current_balance,a.client_id,a.data_date from fund_real a 
		where a.data_date = #{data_date} and a.current_balance != 0) t 
		right join 
		(select format(b.avl_bal,2) avl_bal, b.user_id, b.data_date from user_balance_huifu_daily b 
		where b.data_date = #{data_date} and b.avl_bal != 0) r 
		on t.client_id = r.user_id 
		<include refid="searchCondition" />
	</select>
	
	<select id="searchTotal" parameterType="map" resultType="int">
		select count(1) from 
		(select t.client_id,t.current_balance as hundsun,IFNULL(r.avl_bal,0.00) as pnr,t.data_date from 
		(select format(a.current_balance,2) current_balance,a.client_id,a.data_date from fund_real a 
		where a.data_date = #{data_date} and a.current_balance != 0) t 
		left join 
		(select format(b.avl_bal,2) avl_bal, b.user_id, b.data_date from user_balance_huifu_daily b 
		where b.data_date = #{data_date} and b.avl_bal != 0) r 
		on t.client_id = r.user_id 
		<include refid="searchCondition" />
		union 
		select r.user_id,IFNULL(t.current_balance,0.00) as hundsun,r.avl_bal as pnr,r.data_date from 
		(select format(a.current_balance,2) current_balance,a.client_id,a.data_date from fund_real a 
		where a.data_date = #{data_date} and a.current_balance != 0) t 
		right join 
		(select format(b.avl_bal,2) avl_bal, b.user_id, b.data_date from user_balance_huifu_daily b 
		where b.data_date = #{data_date} and b.avl_bal != 0) r 
		on t.client_id = r.user_id 
		<include refid="searchCondition" />) t
	</select>
	
	<!-- 定时器执行search无法识别typ,故直接写 -->
	<select id="searchDiff" parameterType="map" resultType="map">
		select t.client_id,t.current_balance as hundsun,IFNULL(r.avl_bal,0.00) as pnr,t.data_date from 
		(select format(a.current_balance,2) current_balance,a.client_id,a.data_date from fund_real a 
		where a.data_date = #{data_date} and a.current_balance != 0) t 
		left join 
		(select format(b.avl_bal,2) avl_bal, b.user_id, b.data_date from user_balance_huifu_daily b 
		where b.data_date = #{data_date} and b.avl_bal != 0) r 
		on t.client_id = r.user_id 
		where IFNULL(t.current_balance, 0.00) != IFNULL(r.avl_bal, 0.00) 
		union 
		select r.user_id,IFNULL(t.current_balance,0.00) as hundsun,r.avl_bal as pnr,r.data_date from 
		(select format(a.current_balance,2) current_balance,a.client_id,a.data_date from fund_real a 
		where a.data_date = #{data_date} and a.current_balance != 0) t 
		right join 
		(select format(b.avl_bal,2) avl_bal, b.user_id, b.data_date from user_balance_huifu_daily b 
		where b.data_date = #{data_date} and b.avl_bal != 0) r 
		on t.client_id = r.user_id 
		where IFNULL(t.current_balance, 0.00) != IFNULL(r.avl_bal, 0.00) 
	</select>
	
</mapper>