TdCAcctSourceSMapper.xml 13.2 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" >
<mapper namespace="com.zteits.pay.mapper.smapper.TdCAcctSourceSMapper" >
	<resultMap id="BaseResultMap" type="com.zteits.pay.domain.TdCAcctSource">
		<id column="id" jdbcType="BIGINT" property="id" />
		<result column="source_bill_id" jdbcType="VARCHAR" property="sourceBillId" />
		<result column="acct_id" jdbcType="VARCHAR" property="acctId" />
		<result column="cust_id" jdbcType="VARCHAR" property="custId" />
		<result column="acct_type" jdbcType="INTEGER" property="acctType" />
		<result column="terminal_source" jdbcType="INTEGER" property="terminalSource" />
		<result column="pl_no" jdbcType="VARCHAR" property="plNo" />
		<result column="berth_no" jdbcType="VARCHAR" property="berthNo" />
		<result column="recharge_type" jdbcType="INTEGER" property="rechargeType" />
		<result column="recharge_remark" jdbcType="VARCHAR" property="rechargeRemark" />
		<result column="recharge_fee" jdbcType="DECIMAL" property="rechargeFee" />
		<result column="recharge_balance" jdbcType="DECIMAL" property="rechargeBalance" />
		<result column="recharge_ID" jdbcType="VARCHAR" property="rechargeId" />
		<result column="recharge_name" jdbcType="VARCHAR" property="rechargeName" />
		<result column="recharge_time" jdbcType="TIMESTAMP" property="rechargeTime" />
		<result column="rlt_order_id" jdbcType="VARCHAR" property="rltOrderId" />
		<result column="rlt_payorder_id" jdbcType="VARCHAR" property="rltPayorderId" />
		<result column="qeual_type" jdbcType="INTEGER" property="qeualType" />
		<result column="other_service_fee" jdbcType="DECIMAL" property="otherServiceFee" />
		<result column="rnt_service_fee" jdbcType="DECIMAL" property="rntServiceFee" />
		<result column="acct_upt_state" jdbcType="INTEGER" property="acctUptState" />
		<result column="data_state" jdbcType="INTEGER" property="dataState" />
		<result column="create_empid" jdbcType="VARCHAR" property="createEmpid" />
		<result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
		<result column="modfiy_empid" jdbcType="VARCHAR" property="modfiyEmpid" />
		<result column="modfiy_date" jdbcType="TIMESTAMP" property="modfiyDate" />
		<result column="org_id" jdbcType="BIGINT" property="orgId" />
		<result column="org_name" jdbcType="VARCHAR" property="orgName" />
	</resultMap>
	<sql id="Base_Column_List">
		id, source_bill_id, acct_id, cust_id, acct_type, terminal_source, pl_no, berth_no,
		recharge_type,recharge_remark, recharge_fee, recharge_balance, recharge_ID, recharge_name, recharge_time,
		rlt_order_id, rlt_payorder_id, qeual_type, other_service_fee, rnt_service_fee, acct_upt_state,
		data_state, create_empid, create_date, modfiy_empid, modfiy_date, org_id, org_name
	</sql>


	<select id="getAcctSource" resultMap="BaseResultMap"
		parameterType="com.zteits.pay.domain.TdCAcctSource">
	  select
		<include refid="Base_Column_List" />
	  from td_c_acct_source
	  where data_state = 1
		<if test="sourceBillId != null">
			and source_bill_id = #{sourceBillId,jdbcType=VARCHAR}
		</if>
		<if test="acctId != null">
			and acct_id = #{acctId,jdbcType=VARCHAR}
		</if>
		<if test="custId != null">
			and cust_id = #{custId,jdbcType=VARCHAR}
		</if>
		<if test="acctType != null">
			and acct_type = #{acctType,jdbcType=INTEGER}
		</if>
		<if test="terminalSource != null">
			and terminal_source = #{terminalSource,jdbcType=INTEGER}
		</if>
		<if test="plNo != null">
			and pl_no = #{plNo,jdbcType=VARCHAR}
		</if>
		<if test="berthNo != null">
			and berth_no = #{berthNo,jdbcType=VARCHAR}
		</if>
		<if test="rechargeType != null">
			and recharge_type = #{rechargeType,jdbcType=INTEGER}
		</if>

		<if test="rechargeRemark != null">
			and recharge_remark = #{rechargeRemark,jdbcType=VARCHAR}
		</if>

		<if test="rechargeFee != null">
			and recharge_fee = #{rechargeFee,jdbcType=DECIMAL}
		</if>
		<if test="rechargeBalance != null">
			and recharge_balance = #{rechargeBalance,jdbcType=DECIMAL}
		</if>
		<if test="rechargeId != null">
			and recharge_ID = #{rechargeId,jdbcType=VARCHAR}
		</if>
		<if test="rechargeName != null">
			and recharge_name = #{rechargeName,jdbcType=VARCHAR}
		</if>
		<if test="rechargeTime != null">
			and recharge_time = #{rechargeTime,jdbcType=TIMESTAMP}
		</if>
		<if test="rltOrderId != null">
			and rlt_order_id = #{rltOrderId,jdbcType=VARCHAR}
		</if>
		<if test="rltPayorderId != null">
			and rlt_payorder_id = #{rltPayorderId,jdbcType=VARCHAR}
		</if>
		<if test="qeualType != null">
			and qeual_type = #{qeualType,jdbcType=INTEGER}
		</if>
		<if test="otherServiceFee != null">
			and other_service_fee = #{otherServiceFee,jdbcType=DECIMAL}
		</if>
		<if test="rntServiceFee != null">
			and rnt_service_fee = #{rntServiceFee,jdbcType=DECIMAL}
		</if>
		<if test="acctUptState != null">
			and acct_upt_state = #{acctUptState,jdbcType=INTEGER}
		</if>
		<if test="dataState != null">
			and data_state = #{dataState,jdbcType=INTEGER}
		</if>
		<if test="orgId != null">
			and org_id = #{orgId,jdbcType=BIGINT}
		</if>
	    order by create_date desc
	</select>

	<!-- 查询共享车位的总收入 -->
	<select id="queryShareBerthActFee" resultType="java.lang.Long"
			parameterType="com.zteits.pay.domain.TdCAcctSource">
		select
		IFNULL(sum(recharge_fee),0)
		from td_c_acct_source
		where data_state=1
		and cust_id = #{custId,jdbcType=VARCHAR}
		and pl_no = #{plNo,jdbcType=VARCHAR}
		and berth_no = #{berthNo,jdbcType=VARCHAR}
		and acct_type = #{acctType,jdbcType=INTEGER}

	</select>


	<!-- 查询车主收费端每日充值的收入 third:第三方农行掌银,other:农行补贴-->
	<select id="queryCustRechargeFeeStatic" resultType="com.zteits.clouds.api.dto.pay.AcctSourceQueryRechargeStaticDTO"
			parameterType="com.zteits.clouds.api.dto.pay.param.QueryAcctSourceStaticRequest">
		select
		date(recharge_time)                                                               rechargeTime,
		IFNULL(count(case when recharge_type in (1, 2, 21,34) and acct_type in (1,11)  then recharge_fee end), 0)   totalNum,
		IFNULL(sum(case when recharge_type in (1, 2, 21,34) and acct_type in (1,11) then recharge_fee end), 0)     total,
		IFNULL(count(case when recharge_type = 1 and acct_type = 1 then recharge_fee end), 0)               zfbNum,
		IFNULL(sum(case when recharge_type = 1 and acct_type = 1 then recharge_fee end), 0)                 zfb,
		IFNULL(count(case when recharge_type = 2 and acct_type = 1 then recharge_fee end), 0)               wxNum,
		IFNULL(sum(case when recharge_type = 2 and acct_type = 1 then recharge_fee end), 0)                 wx,
		IFNULL(count(case when recharge_type = 21  and acct_type = 1 then recharge_fee end), 0)              chuzkNum,
		IFNULL(sum(case when recharge_type = 21 and acct_type = 1 then recharge_fee end), 0)                chuzk,
		IFNULL(count(case when recharge_type = 34 and acct_type = 11 then recharge_fee end), 0) otherNum,
		IFNULL(sum(case when recharge_type = 34 and acct_type = 11 then recharge_fee end), 0)   other,
		IFNULL(count(case when recharge_type = 34 and acct_type = 1  then recharge_fee end), 0)              thirdNum,
		IFNULL(sum(case when recharge_type = 34  and acct_type = 1  then recharge_fee end), 0)                third
		from td_c_acct_source
		where data_state=1
		<if test="userPhone != null and userPhone != ''">
			and cust_id in (
				select cust_id from td_c_cust_person
				where user_phone = #{userPhone}
			)
		</if>
		<if test="payTypeList != null and payTypeList.size > 0">
			and recharge_type in
			<foreach collection="payTypeList" open="(" close=")" item="payType" separator=",">
				#{payType}
			</foreach>
		</if>
		and org_id=#{orgId}
		and recharge_time &gt;= #{startTime} AND recharge_time &lt;=#{endTime}
		group by date(recharge_time) desc
	</select>
	<!-- 查询车主收费端每日充值的收入详情 -->
	<select id="queryCustRechargeFeeStaticMsg" resultType="com.zteits.clouds.api.dto.pay.AcctSourceQueryRechargeDetailDTO"
			parameterType="com.zteits.clouds.api.dto.pay.param.QueryAcctSourceStaticRequest">
		select
		tp.user_phone userPhone,
		ts.recharge_type rechargeType,
		ts.recharge_fee rechargeFee,
		ts.recharge_balance rechargeBalance,
		ts.recharge_time rechargeTime,
		ts.acct_type acctType
		from
		(select cust_id,acct_type,recharge_type ,recharge_fee ,recharge_balance ,recharge_time
		from td_c_acct_source
		where data_state = 1 AND acct_type in (1,7,11)
		<if test="custId != null and custId != ''">
			and cust_id = #{custId}
		</if>
		<if test="userPhone != null and userPhone != ''">
			and cust_id in (
					select cust_id from td_c_cust_person
					where user_phone = #{userPhone}
				)
		</if>
		<if test="orgId != null and orgId != ''">
			and org_id=#{orgId}
		</if>
		<if test="startTime != null and endTime != null">
			and recharge_time &gt;= #{startTime} AND recharge_time &lt;=#{endTime}
		</if>
		<if test="payTypeList != null and payTypeList.size > 0">
			and recharge_type in
			<foreach collection="payTypeList" open="(" close=")" item="payType" separator=",">
				#{payType}
			</foreach>
		</if>
		)ts,td_c_cust_person tp
		where  tp.cust_id = ts.cust_id
		order by ts.recharge_time desc
	</select>

	<!-- 按客户id查询账户充值记录 -->
	<select id="queryAcctRechargeForPage" resultMap="BaseResultMap"
			parameterType="com.zteits.clouds.api.dto.pay.param.AcctPayoutForPageRequest">
		select
		<include refid="Base_Column_List" />
			from td_c_acct_source
			where data_state = 1
			<if test="acctId != null">
				and acct_id = #{acctId,jdbcType=VARCHAR}
			</if>
			<if test="custId != null and custId != ''">
				and cust_id =#{custId}
			</if>
			<if test="acctTypeList != null and acctTypeList.size > 0">
	          and acct_type in
	            <foreach collection="acctTypeList" open="(" close=")" item="acctType" separator=",">
	                #{acctType}
	            </foreach>
	        </if>
	        <if test="custIds != null and custIds.size >0">
				and cust_id in
				<foreach collection="custIds" item="cust_id" open="(" close=")" separator=",">
					#{cust_id}
				</foreach>
			</if>
			<if test="beginTime != null ">
	            <![CDATA[ and recharge_time >= #{beginTime}  ]]>
	        </if>
	        <if test="endTime != null ">
	            <![CDATA[ and recharge_time <= #{endTime}  ]]>
	        </if>
			<if test="rechargeType != null and rechargeType == 20">
				and recharge_fee > 0
			</if>

			<if test="rechargeType != null and rechargeType == 30">
				and recharge_fee &lt;= 0
			</if>
			order by (recharge_time) desc
	</select>
	<select id="statisticAcctRecharge" resultType="com.zteits.clouds.api.dto.pay.AcctRechargeStatisticDTO">

		select

		ifnull(sum(CASE WHEN recharge_fee > 0
		THEN recharge_fee
		ELSE 0 END), 0) positiveFee,
		ifnull(sum(CASE WHEN recharge_fee > 0
		THEN 1
		ELSE 0 END), 0) positiveNum,
		ifnull(sum(CASE WHEN recharge_fee &lt;= 0
		THEN recharge_fee
		ELSE 0 END), 0) negativeFee,
		ifnull(sum(CASE WHEN recharge_fee &lt;= 0
		THEN 1
		ELSE 0 END), 0) negativeNum

		from td_c_acct_source
		where data_state = 1
		<if test="custId != null and custId != ''">
			and cust_id =#{custId}
		</if>
		<if test="acctTypeList != null and acctTypeList.size > 0">
			and acct_type in
			<foreach collection="acctTypeList" open="(" close=")" item="acctType" separator=",">
				#{acctType}
			</foreach>
		</if>
		<if test="custIds != null and custIds.size >0">
			and cust_id in
			<foreach collection="custIds" item="cust_id" open="(" close=")" separator=",">
				#{cust_id}
			</foreach>
		</if>
		<if test="beginTime != null ">
			<![CDATA[ and recharge_time >= #{beginTime}  ]]>
		</if>
		<if test="endTime != null ">
			<![CDATA[ and recharge_time <= #{endTime}  ]]>
		</if>


	</select>

    <!--通过手机号、cust_id 查询用户充值明细记录-->
	<select id="queryCustRechargeByPhoneNumOrCustId" resultType="com.zteits.clouds.api.dto.pay.QueryRechargeByPhoneNumOrCustIdDTO"
			parameterType="com.zteits.clouds.api.dto.pay.param.QueryRechargeByPhoneNumOrCustIdReq">
                SELECT
						b.cust_id as custId,
						b.user_phone as userPhone,
						a.rlt_payorder_id as rltPayorderId,
						IFNULL(sum(case when a.acct_type =1 then
							IFNULL(a.recharge_fee,0)
						 end),0) as rechargeFee,
						 IFNULL(sum(case when a.acct_type =1 then
							IFNULL(a.recharge_balance,0)
						 end),0) as rechargeBalance,
					   IFNULL(sum(case when a.acct_type =7 then
							IFNULL(a.recharge_fee,0)
						 end),0) as giveRechargeFee,
					IFNULL(sum(case when a.acct_type =7 then
							IFNULL(a.recharge_balance,0)
						 end),0) as giveRechargeBalance,
						recharge_name as rechargeName,
						recharge_time as rechargeTime
					FROM td_c_cust_person b  left join td_c_acct_source a on  a.cust_id=b.cust_id
					where 1=1
						  and b.data_state=1
                          and b.org_id=#{orgId}
						  and a.acct_type in(1,7)
						<if test="custId != null ">
							and a.cust_id=#{custId}
						</if>
						<if test="userPhone != null ">
							and b.user_phone=#{userPhone}
						</if>
						<if test="rechargeBeginTime != null ">
							<![CDATA[ and a.recharge_time >=#{rechargeBeginTime} ]]>
						</if>
						<if test="rechargeEndTime != null ">
							<![CDATA[ and a.recharge_time <=#{rechargeEndTime} ]]>
						</if>
					group by b.cust_id,
						b.user_phone,
					b.cust_id,
						b.user_phone,
						a.rlt_payorder_id
		order by a.acct_id asc,a.id desc
	</select>


</mapper>