TdCAcctPayoutSMapper.xml 7.13 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.TdCAcctPayoutSMapper" >
	<resultMap id="BaseResultMap" type="com.zteits.pay.domain.TdCAcctPayout">
		<id column="id" jdbcType="BIGINT" property="id" />
		<result column="payout_bill_id" jdbcType="VARCHAR" property="payoutBillId" />
		<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="trade_type" jdbcType="INTEGER" property="tradeType" />
		<result column="trade_detial_type" jdbcType="INTEGER" property="tradeDetialType" />
		<result column="trade_fee" jdbcType="DECIMAL" property="tradeFee" />
		<result column="trade_balance" jdbcType="DECIMAL" property="tradeBalance" />
		<result column="trader_id" jdbcType="VARCHAR" property="traderId" />
		<result column="trader_name" jdbcType="VARCHAR" property="traderName" />
		<result column="trade_time" jdbcType="TIMESTAMP" property="tradeTime" />
		<result column="rlt_payorder_id" jdbcType="VARCHAR" property="rltPayorderId" />
		<result column="rlt_order_id" jdbcType="VARCHAR" property="rltOrderId" />
		<result column="rlt_order_type" jdbcType="VARCHAR" property="rltOrderType" />
		<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, payout_bill_id, acct_id, cust_id, acct_type, trade_type, trade_detial_type, trade_fee,
    trade_balance, trader_id, trader_name, trade_time, rlt_payorder_id, rlt_order_id,
    rlt_order_type, acct_upt_state, data_state, create_empid, create_date, modfiy_empid,
    modfiy_date, org_id, org_name
  </sql>
	<select id="getAcctPayout" resultMap="BaseResultMap"
		parameterType="com.zteits.clouds.api.dto.pay.param.AcctPayoutForPageRequest">
		select
		<include refid="Base_Column_List" />
		from td_c_acct_payout
	   	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="acctId != null">
			and acct_id = #{acctId,jdbcType=VARCHAR}
		</if>
		<if test="custId != null">
			and cust_id = #{custId,jdbcType=VARCHAR}
		</if>
		<if test="acctTypeList != null and acctTypeList.size >0">
			and acct_type in
			<foreach collection="acctTypeList" item="acctType" open="(" close=")" separator=",">
				#{acctType}
			</foreach>
		</if>
		<if test="tradeTypeList != null and tradeTypeList.size >0">
			and trade_type in
			<foreach collection="tradeTypeList" item="tradeType" open="(" close=")" separator=",">
				#{tradeType}
			</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 trade_time >= #{beginTime}  ]]>
        </if>
        <if test="endTime != null ">
            <![CDATA[ and trade_time <= #{endTime}  ]]>
        </if> 
		<if test="rltPayorderId != null">
			and rlt_payorder_id = #{rltPayorderId,jdbcType=VARCHAR}
		</if>
		<if test="rltOrderId != null">
			and rlt_order_id = #{rltOrderId,jdbcType=VARCHAR}
		</if>
		<if test="rltOrderType != null">
			and rlt_order_type = #{rltOrderType,jdbcType=VARCHAR}
		</if>
		<if test="orgId != null">
			and org_id = #{orgId,jdbcType=BIGINT}
		</if>
	   	order by trade_time desc
	</select>
    <select id="statisticAcctPayOut" resultType="com.zteits.clouds.api.dto.pay.AcctRechargeStatisticDTO">
		select
		ifnull(sum(CASE WHEN trade_fee > 0
		THEN trade_fee
		ELSE 0 END), 0) positiveFee,
		ifnull(sum(CASE WHEN trade_fee > 0
		THEN 1
		ELSE 0 END), 0) positiveNum,
		ifnull(sum(CASE WHEN trade_fee &lt;= 0
		THEN trade_fee
		ELSE 0 END), 0) negativeFee,
		ifnull(sum(CASE WHEN trade_fee &lt;= 0
		THEN 1
		ELSE 0 END), 0) negativeNum


		from td_c_acct_payout
		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="acctId != null">
			and acct_id = #{acctId,jdbcType=VARCHAR}
		</if>
		<if test="custId != null">
			and cust_id = #{custId,jdbcType=VARCHAR}
		</if>
		<if test="acctTypeList != null and acctTypeList.size >0">
			and acct_type in
			<foreach collection="acctTypeList" item="acctType" open="(" close=")" separator=",">
				#{acctType}
			</foreach>
		</if>
		<if test="tradeTypeList != null and tradeTypeList.size >0">
			and trade_type in
			<foreach collection="tradeTypeList" item="tradeType" open="(" close=")" separator=",">
				#{tradeType}
			</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 trade_time >= #{beginTime}  ]]>
		</if>
		<if test="endTime != null ">
			<![CDATA[ and trade_time <= #{endTime}  ]]>
		</if>
		<if test="rltPayorderId != null">
			and rlt_payorder_id = #{rltPayorderId,jdbcType=VARCHAR}
		</if>
		<if test="rltOrderId != null">
			and rlt_order_id = #{rltOrderId,jdbcType=VARCHAR}
		</if>
		<if test="rltOrderType != null">
			and rlt_order_type = #{rltOrderType,jdbcType=VARCHAR}
		</if>
		<if test="orgId != null">
			and org_id = #{orgId,jdbcType=BIGINT}
		</if>



	</select>
	
	<!-- 查询车主每月消费金额 -->
    <select id="queryOwnerPayOutByMonth" resultType="com.zteits.clouds.api.dto.owner.dto.OwnerPayOutDTO"
            parameterType="com.zteits.clouds.api.dto.owner.param.OwnerRequest">
            select
		        IFNULL(SUM(trade_fee),0) AS fee,
					DATE_FORMAT(create_date,'%Y-%m') dateStr
		        from td_c_acct_payout 
		        where 1=1
		        and cust_id =#{custId}
		        and data_state = 1
		        
		        and create_date BETWEEN #{beginTime} AND #{endTime}
		        group by dateStr
    </select>
    <!--根据充值时间查找最新的一条订单 ID-->
	<select id="queryAcctPayoutRltOrderId" resultMap="BaseResultMap">
		SELECT
		  id, payout_bill_id, acct_id, cust_id, acct_type, trade_type, trade_detial_type, trade_fee,
    trade_balance, trader_id, trader_name, trade_time, rlt_payorder_id, rlt_order_id,
    rlt_order_type, acct_upt_state, data_state, create_empid, create_date, modfiy_empid,
    modfiy_date, org_id, org_name
		FROM
		td_c_acct_payout
		WHERE 1=1
		and acct_id = #{acctId}
		<![CDATA[and trade_time <=#{rechargeTime}]]>
		order by id desc
		limit 1
	</select>

    
</mapper>