Files
BMS/bms-back/ruoyi-system/src/main/resources/mapper/customer/CustomerMoneyMapper.xml
T
2026-09-20 10:26:30 +08:00

485 lines
27 KiB
XML

<?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.ruoyi.customer.customermoney.mapper.CustomerMoneyMapper">
<!-- ================= 客户余额账户 ================= -->
<resultMap type="com.ruoyi.customer.customermoney.domain.CustomerAccount" id="CustomerAccountResult">
<id property="id" column="id" />
<result property="customerId" column="customer_id" />
<result property="currency" column="currency" />
<result property="balance" column="balance" />
<result property="frozenBalance" column="frozen_balance" />
<result property="totalCredit" column="total_credit" />
<result property="creditEffectiveDate" column="credit_effective_date" />
<result property="creditExpireDate" column="credit_expire_date" />
<result property="extraCredit" column="extra_credit" />
<result property="extraEffectiveDate" column="extra_effective_date" />
<result property="extraExpireDate" column="extra_expire_date" />
<result property="usedCredit" column="used_credit" />
<result property="tax" column="tax" />
<result property="version" column="version" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="delFlag" column="del_flag" />
</resultMap>
<sql id="selectCustomerAccountVo">
select id, customer_id, currency, balance, frozen_balance, total_credit,
credit_effective_date, credit_expire_date, extra_credit,
extra_effective_date, extra_expire_date, used_credit,
tax, version, create_by, create_time, update_by, update_time, remark, del_flag
from customer_account
</sql>
<select id="selectAccountByCustomerCurrency" resultMap="CustomerAccountResult">
<include refid="selectCustomerAccountVo"/>
where customer_id = #{customerId} and currency = #{currency} and del_flag = '0'
</select>
<select id="selectAccountForUpdate" resultMap="CustomerAccountResult">
<include refid="selectCustomerAccountVo"/>
where customer_id = #{customerId} and currency = #{currency} and del_flag = '0'
for update
</select>
<select id="selectAccountListByCustomerId" resultMap="CustomerAccountResult">
<include refid="selectCustomerAccountVo"/>
where customer_id = #{customerId} and del_flag = '0'
</select>
<!-- 扫描已到期授信的CNY账户(信用或临时额度失效日早于今天;失效日当天仍有效,故严格小于今天) -->
<select id="selectExpiredCreditCustomerIds" resultType="java.lang.Long">
select distinct customer_id
from customer_account
where del_flag = '0'
and currency = 'CNY'
and (
(total_credit &gt; 0 and credit_expire_date is not null and credit_expire_date &lt; CURDATE())
or
(extra_credit &gt; 0 and extra_expire_date is not null and extra_expire_date &lt; CURDATE())
)
</select>
<insert id="insertAccount" parameterType="com.ruoyi.customer.customermoney.domain.CustomerAccount"
useGeneratedKeys="true" keyProperty="id">
insert into customer_account
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="customerId != null">customer_id,</if>
<if test="currency != null">currency,</if>
<if test="balance != null">balance,</if>
<if test="frozenBalance != null">frozen_balance,</if>
<if test="totalCredit != null">total_credit,</if>
<if test="extraCredit != null">extra_credit,</if>
<if test="usedCredit != null">used_credit,</if>
<if test="tax != null">tax,</if>
<if test="version != null">version,</if>
<if test="createBy != null">create_by,</if>
<if test="remark != null">remark,</if>
del_flag,
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="customerId != null">#{customerId},</if>
<if test="currency != null">#{currency},</if>
<if test="balance != null">#{balance},</if>
<if test="frozenBalance != null">#{frozenBalance},</if>
<if test="totalCredit != null">#{totalCredit},</if>
<if test="extraCredit != null">#{extraCredit},</if>
<if test="usedCredit != null">#{usedCredit},</if>
<if test="tax != null">#{tax},</if>
<if test="version != null">#{version},</if>
<if test="createBy != null">#{createBy},</if>
<if test="remark != null">#{remark},</if>
'0',
</trim>
</insert>
<update id="updateAccountBalance">
update customer_account
set balance = #{balance},
frozen_balance = #{frozenBalance},
used_credit = #{usedCredit},
version = version + 1,
update_by = #{updateBy},
update_time = now()
where id = #{id} and version = #{version} and del_flag = '0'
</update>
<!-- 乐观锁更新额度(信用/临时额度及各自有效期) -->
<update id="updateAccountCredit">
update customer_account
set total_credit = #{totalCredit},
credit_effective_date = #{creditEffectiveDate},
credit_expire_date = #{creditExpireDate},
extra_credit = #{extraCredit},
extra_effective_date = #{extraEffectiveDate},
extra_expire_date = #{extraExpireDate},
version = version + 1,
update_by = #{updateBy},
update_time = now()
where id = #{id} and version = #{version} and del_flag = '0'
</update>
<!-- ================= 客户额度流水 ================= -->
<resultMap type="com.ruoyi.customer.customermoney.domain.CustomerCreditFlow" id="CustomerCreditFlowResult">
<id property="id" column="id" />
<result property="flowNo" column="flow_no" />
<result property="customerId" column="customer_id" />
<result property="accountId" column="account_id" />
<result property="creditType" column="credit_type" />
<result property="changeType" column="change_type" />
<result property="bizType" column="biz_type" />
<result property="bizId" column="biz_id" />
<result property="bizNo" column="biz_no" />
<result property="direction" column="direction" />
<result property="beforeAmount" column="before_amount" />
<result property="changeAmount" column="change_amount" />
<result property="afterAmount" column="after_amount" />
<result property="usedCredit" column="used_credit" />
<result property="effectiveDate" column="effective_date" />
<result property="expireDate" column="expire_date" />
<result property="reason" column="reason" />
<result property="adjustMode" column="adjust_mode" />
<result property="operatorId" column="operator_id" />
<result property="roleId" column="role_id" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="delFlag" column="del_flag" />
</resultMap>
<sql id="selectCustomerCreditFlowVo">
select id, flow_no, customer_id, account_id, credit_type, change_type, biz_type, biz_id, biz_no, direction,
before_amount, change_amount, after_amount, used_credit,
effective_date, expire_date, reason, adjust_mode, operator_id, role_id,
create_by, create_time, update_by, update_time, remark, del_flag
from customer_credit_flow
</sql>
<select id="selectCreditFlowList" parameterType="com.ruoyi.customer.customermoney.domain.CustomerCreditFlow"
resultMap="CustomerCreditFlowResult">
<include refid="selectCustomerCreditFlowVo"/>
<where>
<if test="customerId != null"> and customer_id = #{customerId}</if>
<if test="creditType != null and creditType != ''"> and credit_type = #{creditType}</if>
<if test="changeType != null and changeType != ''"> and change_type = #{changeType}</if>
<if test="bizType != null and bizType != ''"> and biz_type = #{bizType}</if>
<if test="bizId != null"> and biz_id = #{bizId}</if>
<if test="params.beginTime != null and params.beginTime != ''"> and date(create_time) &gt;= #{params.beginTime}</if>
<if test="params.endTime != null and params.endTime != ''"> and date(create_time) &lt;= #{params.endTime}</if>
and del_flag = '0'
</where>
order by create_time desc, id desc
</select>
<insert id="insertCreditFlow" parameterType="com.ruoyi.customer.customermoney.domain.CustomerCreditFlow"
useGeneratedKeys="true" keyProperty="id">
insert into customer_credit_flow
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="flowNo != null">flow_no,</if>
<if test="customerId != null">customer_id,</if>
<if test="accountId != null">account_id,</if>
<if test="creditType != null">credit_type,</if>
<if test="changeType != null">change_type,</if>
<if test="bizType != null">biz_type,</if>
<if test="bizId != null">biz_id,</if>
<if test="bizNo != null">biz_no,</if>
<if test="direction != null">direction,</if>
<if test="beforeAmount != null">before_amount,</if>
<if test="changeAmount != null">change_amount,</if>
<if test="afterAmount != null">after_amount,</if>
<if test="usedCredit != null">used_credit,</if>
<if test="effectiveDate != null">effective_date,</if>
<if test="expireDate != null">expire_date,</if>
<if test="reason != null">reason,</if>
<if test="adjustMode != null">adjust_mode,</if>
<if test="operatorId != null">operator_id,</if>
<if test="roleId != null">role_id,</if>
<if test="createBy != null">create_by,</if>
<if test="remark != null">remark,</if>
<if test="delFlag != null">del_flag,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="flowNo != null">#{flowNo},</if>
<if test="customerId != null">#{customerId},</if>
<if test="accountId != null">#{accountId},</if>
<if test="creditType != null">#{creditType},</if>
<if test="changeType != null">#{changeType},</if>
<if test="bizType != null">#{bizType},</if>
<if test="bizId != null">#{bizId},</if>
<if test="bizNo != null">#{bizNo},</if>
<if test="direction != null">#{direction},</if>
<if test="beforeAmount != null">#{beforeAmount},</if>
<if test="changeAmount != null">#{changeAmount},</if>
<if test="afterAmount != null">#{afterAmount},</if>
<if test="usedCredit != null">#{usedCredit},</if>
<if test="effectiveDate != null">#{effectiveDate},</if>
<if test="expireDate != null">#{expireDate},</if>
<if test="reason != null">#{reason},</if>
<if test="adjustMode != null">#{adjustMode},</if>
<if test="operatorId != null">#{operatorId},</if>
<if test="roleId != null">#{roleId},</if>
<if test="createBy != null">#{createBy},</if>
<if test="remark != null">#{remark},</if>
<if test="delFlag != null">#{delFlag},</if>
</trim>
</insert>
<!-- ================= 客户收款 ================= -->
<resultMap type="com.ruoyi.customer.customermoney.domain.CustomerReceipt" id="CustomerReceiptResult">
<id property="id" column="id" />
<result property="receiptNo" column="receipt_no" />
<result property="customerId" column="customer_id" />
<result property="accountId" column="account_id" />
<result property="receiptType" column="receipt_type" />
<result property="amount" column="amount" />
<result property="allocatedAmount" column="allocated_amount" />
<result property="unallocatedAmount" column="unallocated_amount" />
<result property="currency" column="currency" />
<result property="exchangeRate" column="exchange_rate" />
<result property="rateSource" column="rate_source" />
<result property="rateSourceDesc" column="rate_source_desc" />
<result property="baseAmount" column="base_amount" />
<result property="payMethod" column="pay_method" />
<result property="bankTransactionNo" column="bank_transaction_no" />
<result property="receivedAt" column="received_at" />
<result property="status" column="status" />
<result property="confirmedAt" column="confirmed_at" />
<result property="confirmedBy" column="confirmed_by" />
<result property="invoiceStatus" column="invoice_status" />
<result property="version" column="version" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="delFlag" column="del_flag" />
<result property="attachmentCount" column="attachment_count" />
</resultMap>
<sql id="selectCustomerReceiptVo">
select r.id, r.receipt_no, r.customer_id, r.account_id, r.receipt_type, r.amount, r.allocated_amount,
r.unallocated_amount, r.currency, r.exchange_rate, r.rate_source, r.rate_source_desc,
r.base_amount, r.pay_method, r.bank_transaction_no,
r.received_at, r.status,
r.confirmed_at, r.confirmed_by, r.invoice_status, r.version, r.create_by, r.create_time,
r.update_by, r.update_time, r.remark, r.del_flag,
(select count(1) from bms_customer_attachment a
where a.biz_id = r.id and a.attachment_type = '3' and a.del_flag = '0') as attachment_count
from customer_receipt r
</sql>
<select id="selectReceiptList" parameterType="com.ruoyi.customer.customermoney.domain.CustomerReceipt"
resultMap="CustomerReceiptResult">
<include refid="selectCustomerReceiptVo"/>
<where>
r.del_flag = '0'
<if test="customerId != null"> and r.customer_id = #{customerId}</if>
<if test="receiptNo != null and receiptNo != ''"> and r.receipt_no like concat('%', #{receiptNo}, '%')</if>
<if test="receiptType != null and receiptType != ''"> and r.receipt_type = #{receiptType}</if>
<if test="status != null and status != ''"> and r.status = #{status}</if>
<if test="currency != null and currency != ''"> and r.currency = #{currency}</if>
<if test="payMethod != null and payMethod != ''"> and r.pay_method = #{payMethod}</if>
<if test="bankTransactionNo != null and bankTransactionNo != ''">
and r.bank_transaction_no like concat('%', #{bankTransactionNo}, '%')
</if>
<if test="params != null and params.beginTime != null and params.beginTime != ''">
and date_format(r.received_at,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params != null and params.endTime != null and params.endTime != ''">
and date_format(r.received_at,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
order by r.received_at desc, r.id desc
</select>
<select id="selectReceiptById" resultMap="CustomerReceiptResult">
<include refid="selectCustomerReceiptVo"/>
where r.id = #{id} and r.del_flag = '0'
</select>
<insert id="insertReceipt" parameterType="com.ruoyi.customer.customermoney.domain.CustomerReceipt"
useGeneratedKeys="true" keyProperty="id">
insert into customer_receipt
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="receiptNo != null">receipt_no,</if>
<if test="customerId != null">customer_id,</if>
<if test="accountId != null">account_id,</if>
<if test="receiptType != null">receipt_type,</if>
<if test="amount != null">amount,</if>
<if test="allocatedAmount != null">allocated_amount,</if>
<if test="unallocatedAmount != null">unallocated_amount,</if>
<if test="currency != null">currency,</if>
<if test="exchangeRate != null">exchange_rate,</if>
<if test="rateSource != null">rate_source,</if>
<if test="rateSourceDesc != null">rate_source_desc,</if>
<if test="baseAmount != null">base_amount,</if>
<if test="payMethod != null">pay_method,</if>
<if test="bankTransactionNo != null">bank_transaction_no,</if>
<if test="receivedAt != null">received_at,</if>
<if test="status != null">status,</if>
<if test="confirmedAt != null">confirmed_at,</if>
<if test="confirmedBy != null">confirmed_by,</if>
<if test="invoiceStatus != null">invoice_status,</if>
<if test="version != null">version,</if>
<if test="createBy != null">create_by,</if>
<if test="remark != null">remark,</if>
del_flag,
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="receiptNo != null">#{receiptNo},</if>
<if test="customerId != null">#{customerId},</if>
<if test="accountId != null">#{accountId},</if>
<if test="receiptType != null">#{receiptType},</if>
<if test="amount != null">#{amount},</if>
<if test="allocatedAmount != null">#{allocatedAmount},</if>
<if test="unallocatedAmount != null">#{unallocatedAmount},</if>
<if test="currency != null">#{currency},</if>
<if test="exchangeRate != null">#{exchangeRate},</if>
<if test="rateSource != null">#{rateSource},</if>
<if test="rateSourceDesc != null">#{rateSourceDesc},</if>
<if test="baseAmount != null">#{baseAmount},</if>
<if test="payMethod != null">#{payMethod},</if>
<if test="bankTransactionNo != null">#{bankTransactionNo},</if>
<if test="receivedAt != null">#{receivedAt},</if>
<if test="status != null">#{status},</if>
<if test="confirmedAt != null">#{confirmedAt},</if>
<if test="confirmedBy != null">#{confirmedBy},</if>
<if test="invoiceStatus != null">#{invoiceStatus},</if>
<if test="version != null">#{version},</if>
<if test="createBy != null">#{createBy},</if>
<if test="remark != null">#{remark},</if>
'0',
</trim>
</insert>
<update id="confirmReceipt" parameterType="com.ruoyi.customer.customermoney.domain.CustomerReceipt">
update customer_receipt
set status = 'CONFIRMED',
confirmed_at = #{confirmedAt},
confirmed_by = #{confirmedBy},
version = version + 1,
update_by = #{updateBy},
update_time = now()
where id = #{id} and status = 'PENDING' and version = #{version} and del_flag = '0'
</update>
<update id="cancelReceipt">
update customer_receipt
set status = 'CANCELLED',
update_by = #{updateBy},
update_time = now()
where id = #{id} and status = 'PENDING' and del_flag = '0'
</update>
<!-- ================= 余额流水 ================= -->
<resultMap type="com.ruoyi.customer.customermoney.domain.CustomerBalanceFlow" id="CustomerBalanceFlowResult">
<id property="id" column="id" />
<result property="flowNo" column="flow_no" />
<result property="customerId" column="customer_id" />
<result property="accountId" column="account_id" />
<result property="currency" column="currency" />
<result property="exchangeRate" column="exchange_rate" />
<result property="baseAmount" column="base_amount" />
<result property="bizType" column="biz_type" />
<result property="bizId" column="biz_id" />
<result property="bizNo" column="biz_no" />
<result property="direction" column="direction" />
<result property="amount" column="amount" />
<result property="beforeBalance" column="before_balance" />
<result property="afterBalance" column="after_balance" />
<result property="beforeFrozenBalance" column="before_frozen_balance" />
<result property="afterFrozenBalance" column="after_frozen_balance" />
<result property="operatorId" column="operator_id" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="delFlag" column="del_flag" />
</resultMap>
<sql id="selectCustomerBalanceFlowVo">
select id, flow_no, customer_id, account_id, currency, exchange_rate, base_amount, biz_type, biz_id, biz_no,
direction, amount,
before_balance, after_balance, before_frozen_balance, after_frozen_balance, operator_id,
create_by, create_time, update_by, update_time, remark, del_flag
from customer_balance_flow
</sql>
<select id="selectFlowList" parameterType="com.ruoyi.customer.customermoney.domain.CustomerBalanceFlow"
resultMap="CustomerBalanceFlowResult">
<include refid="selectCustomerBalanceFlowVo"/>
<where>
del_flag = '0'
<if test="customerId != null"> and customer_id = #{customerId}</if>
<if test="accountId != null"> and account_id = #{accountId}</if>
<if test="bizType != null and bizType != ''"> and biz_type = #{bizType}</if>
<if test="direction != null"> and direction = #{direction}</if>
<if test="currency != null and currency != ''"> and currency = #{currency}</if>
<if test="bizNo != null and bizNo != ''"> and biz_no like concat('%', #{bizNo}, '%')</if>
<if test="params != null and params.beginTime != null and params.beginTime != ''">
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params != null and params.endTime != null and params.endTime != ''">
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
order by create_time desc, id desc
</select>
<insert id="insertFlow" parameterType="com.ruoyi.customer.customermoney.domain.CustomerBalanceFlow"
useGeneratedKeys="true" keyProperty="id">
insert into customer_balance_flow
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="flowNo != null">flow_no,</if>
<if test="customerId != null">customer_id,</if>
<if test="accountId != null">account_id,</if>
<if test="currency != null">currency,</if>
<if test="exchangeRate != null">exchange_rate,</if>
<if test="baseAmount != null">base_amount,</if>
<if test="bizType != null">biz_type,</if>
<if test="bizId != null">biz_id,</if>
<if test="bizNo != null">biz_no,</if>
<if test="direction != null">direction,</if>
<if test="amount != null">amount,</if>
<if test="beforeBalance != null">before_balance,</if>
<if test="afterBalance != null">after_balance,</if>
<if test="beforeFrozenBalance != null">before_frozen_balance,</if>
<if test="afterFrozenBalance != null">after_frozen_balance,</if>
<if test="operatorId != null">operator_id,</if>
<if test="createBy != null">create_by,</if>
<if test="remark != null">remark,</if>
del_flag,
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="flowNo != null">#{flowNo},</if>
<if test="customerId != null">#{customerId},</if>
<if test="accountId != null">#{accountId},</if>
<if test="currency != null">#{currency},</if>
<if test="exchangeRate != null">#{exchangeRate},</if>
<if test="baseAmount != null">#{baseAmount},</if>
<if test="bizType != null">#{bizType},</if>
<if test="bizId != null">#{bizId},</if>
<if test="bizNo != null">#{bizNo},</if>
<if test="direction != null">#{direction},</if>
<if test="amount != null">#{amount},</if>
<if test="beforeBalance != null">#{beforeBalance},</if>
<if test="afterBalance != null">#{afterBalance},</if>
<if test="beforeFrozenBalance != null">#{beforeFrozenBalance},</if>
<if test="afterFrozenBalance != null">#{afterFrozenBalance},</if>
<if test="operatorId != null">#{operatorId},</if>
<if test="createBy != null">#{createBy},</if>
<if test="remark != null">#{remark},</if>
'0',
</trim>
</insert>
</mapper>