TdCAcctPersonSMapper.xml 10.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.TdCAcctPersonSMapper" >
	<resultMap id="BaseResultMap" type="com.zteits.pay.domain.TdCAcctPerson">
		<id column="id" jdbcType="BIGINT" property="id" />
		<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="acct_balance" jdbcType="DECIMAL" property="acctBalance" />
		<result column="acct_default_balance" jdbcType="DECIMAL" property="acctDefaultBalance" />
		<result column="acct_name" jdbcType="VARCHAR" property="acctName" />
		<result column="acct_type_unit" jdbcType="INTEGER" property="acctTypeUnit" />
		<result column="acct_order" jdbcType="INTEGER" property="acctOrder" />
		<result column="main_flg" jdbcType="INTEGER" property="mainFlg" />
		<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, acct_id, cust_id, acct_type, acct_balance, acct_default_balance, acct_name, acct_type_unit,
    acct_order, main_flg, data_state, create_empid, create_date, modfiy_empid, modfiy_date,
    org_id, org_name
  </sql>

    <!-- 修改账户 -->
	<update id="updateAcctPerson"  parameterType="com.zteits.pay.domain.TdCAcctPerson">
	    update td_c_acct_person
	    <set>
			<if test="acctId != null">
				acct_id = #{acctId,jdbcType=VARCHAR},
			</if>
			<if test="custId != null">
				cust_id = #{custId,jdbcType=VARCHAR},
			</if>
			<if test="acctType != null">
				acct_type = #{acctType,jdbcType=INTEGER},
			</if>
			<if test="acctBalance != null">
				acct_balance = #{acctBalance,jdbcType=DECIMAL},
			</if>
			<if test="acctDefaultBalance != null">
				acct_default_balance = #{acctDefaultBalance,jdbcType=DECIMAL},
			</if>
			<if test="acctName != null">
				acct_name = #{acctName,jdbcType=VARCHAR},
			</if>
			<if test="acctTypeUnit != null">
				acct_type_unit = #{acctTypeUnit,jdbcType=INTEGER},
			</if>
			<if test="acctOrder != null">
				acct_order = #{acctOrder,jdbcType=INTEGER},
			</if>
			<if test="mainFlg != null">
				main_flg = #{mainFlg,jdbcType=INTEGER},
			</if>
			<if test="dataState != null">
				data_state = #{dataState,jdbcType=INTEGER},
			</if>
			<if test="createEmpid != null">
				create_empid = #{createEmpid,jdbcType=VARCHAR},
			</if>
			<if test="createDate != null">
				create_date = #{createDate,jdbcType=TIMESTAMP},
			</if>
			<if test="modfiyEmpid != null">
				modfiy_empid = #{modfiyEmpid,jdbcType=VARCHAR},
			</if>
			<if test="modfiyDate != null">
				modfiy_date = #{modfiyDate,jdbcType=TIMESTAMP},
			</if>
			<if test="orgId != null">
				org_id = #{orgId,jdbcType=BIGINT},
			</if>
			<if test="orgName != null">
				org_name = #{orgName,jdbcType=VARCHAR},
			</if>
		</set>
	    where data_state = 1
		and cust_id = #{custId} and acct_type = #{acctType}
		and org_id = #{orgId}
	</update>

	<select id="getAcctPerson" resultMap="BaseResultMap"
		parameterType="com.zteits.pay.domain.TdCAcctPerson">
		select
		<include refid="Base_Column_List" />
		from td_c_acct_person
	   where data_state = 1
		and cust_id = #{custId} and acct_type = #{acctType} and org_id = #{orgId}
	</select>

	<!--  通过custId和账户类型查询个人账户信息-->
	<select id="queryAcctPersonByCustIdAndAcctType" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from td_c_acct_person
		where data_state = 1
		<if test="custId != null and  custId != ''">
			and cust_id = #{custId,jdbcType=VARCHAR}
		</if>
		<if test="custIds != null and custIds.size >0">
			and cust_id  in
			<foreach collection="custIds" item="custId" open="(" close=")" separator=",">
				 #{custId}
			</foreach>
		</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="orgId != null">
			and org_id = #{orgId,jdbcType=BIGINT}
		</if>
	</select>

	<select id="getAcctPersonGroupByOrgId" resultType="com.zteits.clouds.api.dto.pay.AcctPersonDTO" parameterType="com.zteits.clouds.api.dto.pay.param.QueryAcctPersonByCustIdsAndAcctTypeReq">
		SELECT
			org_id 																			orgId,
			sum( acct_balance ) 															acctBalance,
			sum(case when acct_type in (1,4,7) then ifnull(acct_balance, 0) else 0 end) 	rechargeAccount,
			sum(case when acct_type = 8 then ifnull(acct_balance, 0) else 0 end) 			giftAccount
		FROM
			td_c_acct_person
		WHERE
			data_state = 1
			and cust_id =  #{custId}
			<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="orgId != null">
				and org_id = #{orgId,jdbcType=BIGINT}
			</if>
		GROUP BY
			orgId
	</select>

	<select id="getAcctPersonGroupByAcctType" resultType="com.zteits.pay.domain.TdCAcctPerson" parameterType="com.zteits.clouds.api.dto.pay.param.QueryAcctPersonByCustIdsAndAcctTypeReq">
		SELECT
		org_id orgId,
		acct_type acctType,
		sum(acct_balance) acctBalance
		FROM
		td_c_acct_person
		WHERE
		data_state = 1
		and cust_id =  #{custId}
		<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="orgId != null">
			and org_id = #{orgId,jdbcType=BIGINT}
		</if>
		GROUP BY
		orgId,
		acctType
	</select>

	<!-- 账单充值和支出明细-分页查询 -->
	<select id="queryAccountInOutDetailsForPage" resultType="com.zteits.clouds.api.dto.pay.account.dto.AccountInOutDetailForPageDTO"
			parameterType="com.zteits.clouds.api.dto.pay.account.param.AcctInOutDetailForPageRequest">
		<if test="detailType == 1">
			select 1 as type, b.acct_type  acctType,b.recharge_type payType,b.recharge_fee changeFee,b.create_date createDate,b.rlt_order_id orderId
			from td_c_acct_source b
			where b.cust_id  =  #{custId}
			<if test="orgId != null">
				and org_id = #{orgId,jdbcType=BIGINT}
			</if>
			order by b.create_date desc
		</if>
		<if test="detailType == 2">
			select type,acctType,payType,changeFee,createDate,orderId
			from
				(select 2 as type, a.acct_type acctType,a.trade_type payType,sum(a.trade_fee) changeFee,a.create_date  createDate,a.rlt_order_id orderId
				from td_c_acct_payout a
				where a.cust_id =  #{custId}
				<if test="orgId != null">
					and org_id = #{orgId,jdbcType=BIGINT}
				</if>
				group by a.rlt_order_id) b
			order by b.createDate desc
		</if>
		<if test="detailType == null || detailType == ''">
			select * from
		  		(select 2 as type, a.acct_type acctType,a.trade_type payType,sum(a.trade_fee) changeFee,a.create_date  createDate,a.rlt_order_id orderId
			from td_c_acct_payout a
			where a.cust_id =  #{custId}
			<if test="orgId != null">
				and org_id = #{orgId,jdbcType=BIGINT}
			</if>
			group by a.rlt_order_id
			union
			select 1 as type, b.acct_type  acctType,b.recharge_type payType,b.recharge_fee changeFee,b.create_date createDate,b.rlt_order_id orderId
			from td_c_acct_source b
			where b.cust_id  =  #{custId}
			<if test="orgId != null">
				and org_id = #{orgId,jdbcType=BIGINT}
			</if>
		  	)c
			order by c.createDate desc
		</if>
	</select>

	<!-- 个人账户金额加或者减操作-->
	<update id="addOrsubAcctPersonFeeByAcctId" parameterType="com.zteits.clouds.api.dto.pay.param.AddOrsubAcctPersonFeeByAcctIdReq">
        UPDATE td_c_acct_person a
           <if test="addOrSubType == 1">
			   SET a.acct_balance = a.acct_balance + #{acctFee}
		   </if>
			<if test="addOrSubType == 2">
				SET a.acct_balance = a.acct_balance - #{acctFee}
			</if>

			WHERE
				1 = 1
			AND a.data_state = 1
			and a.acct_id = #{acctId}

	</update>

	<!-- 分页查询储值车账户 -->
	<select id="queryAcctPersonStoreCarForPage" resultType="com.zteits.clouds.api.dto.pay.dto.AcctPersonForStoreCarDTO"
			parameterType="com.zteits.clouds.api.dto.pay.param.QueryAcctPersonForPageReq">
		select
	   a.cust_id custId,
       a.user_phone userPhone,
	   b.acct_id acctId,
       b.acct_type acctType,
       b.acct_name acctName,
       ifnull(b.acct_balance,0) acctBalance,
       case when ifnull(b.cust_id,'0') = '0' then 0 else 1 end isOpen
		from td_c_cust_person a
       left join td_c_acct_person b on a.cust_id = b.cust_id and b.data_state = 1 and b.acct_type = #{acctType} and b.org_id = #{orgId}
       left join td_c_store_car c on a.cust_id = c.cust_id and c.data_state = 1
		where a.data_state = 1
        <if test="userPhone != null and userPhone != ''">
            and a.user_phone = #{userPhone}
        </if>
        <if test="carNumber != null and carNumber != ''">
            and c.car_number = #{carNumber}
        </if>
        <if test="acctName != null and acctName != ''">
            and b.acct_name like concat('%',#{acctName},'%')
        </if>
		group by a.cust_id
		order by isOpen desc , userPhone
	</select>

	<!-- 账单充值和支出明细-分页查询 -->
	<select id="queryAccountRecordDetails" resultType="com.zteits.clouds.api.dto.pay.account.dto.AccountInOutDetailForPageDTO"
			parameterType="com.zteits.clouds.api.dto.pay.account.param.AccoutRecordDetailRequest">
			select 2 as type,
				a.acct_type 			acctType,
				a.trade_type 			payType,
				a.trade_fee 			changeFee,
				a.create_date  			createDate,
				a.rlt_order_id 			orderId,
				a.trade_time			tradeTime,
				a.trade_type			tradeType
			from td_c_acct_payout a
			where a.cust_id =  #{custId}
			and a.rlt_order_id = #{orderId}
		<if test="orgId != null">
				and org_id = #{orgId,jdbcType=BIGINT}
			</if>
			order by createDate desc

	</select>

</mapper>