客户余额记录

This commit is contained in:
luojiaquan
2026-09-14 11:51:54 +08:00
parent 4cc20386d9
commit 18f01d1b33
16 changed files with 2349 additions and 43 deletions
@@ -36,41 +36,50 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="delFlag" column="del_flag" />
</resultMap>
<!-- 账户余额/外币余额统一取 customer_account 余额表(CNY 为本币,其余为外币),不取 bms_customer 冗余列 -->
<sql id="selectBmsCustomerVo">
select customer_id, customer_code, customer_name, customer_code_dw, credit_code, customer_type, is_enable, sales_user_id, sales_user, ed, zq, settlement_user_id, settlement_user, service_user_id, service_user, settlement_type, temp_ed, account_balance, foreign_currency_balance, weight_threshold, throw_ratio, credit_ed, product_ids, remark, create_by, create_time, update_by, update_time, del_flag from bms_customer
select c.customer_id, c.customer_code, c.customer_name, c.customer_code_dw, c.credit_code, c.customer_type,
c.is_enable, c.sales_user_id, c.sales_user, c.ed, c.zq, c.settlement_user_id, c.settlement_user,
c.service_user_id, c.service_user, c.settlement_type, c.temp_ed,
(select coalesce(sum(ca.balance), 0) from customer_account ca
where ca.customer_id = c.customer_id and ca.currency = 'CNY' and ca.del_flag = '0') as account_balance,
(select coalesce(sum(ca.balance), 0) from customer_account ca
where ca.customer_id = c.customer_id and ca.currency != 'CNY' and ca.del_flag = '0') as foreign_currency_balance,
c.weight_threshold, c.throw_ratio, c.credit_ed, c.product_ids, c.remark,
c.create_by, c.create_time, c.update_by, c.update_time, c.del_flag
from bms_customer c
</sql>
<select id="selectBmsCustomerList" parameterType="BmsCustomer" resultMap="BmsCustomerResult">
<include refid="selectBmsCustomerVo"/>
<where>
<if test="customerCode != null and customerCode != ''"> and customer_code = #{customerCode}</if>
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
<if test="customerCodeDw != null and customerCodeDw != ''"> and customer_code_dw = #{customerCodeDw}</if>
<if test="creditCode != null and creditCode != ''"> and credit_code = #{creditCode}</if>
<if test="customerType != null and customerType != ''"> and customer_type = #{customerType}</if>
<if test="isEnable != null and isEnable != ''"> and is_enable = #{isEnable}</if>
<if test="salesUserId != null and salesUserId != ''"> and sales_user_id = #{salesUserId}</if>
<if test="salesUser != null and salesUser != ''"> and sales_user = #{salesUser}</if>
<if test="ed != null "> and ed = #{ed}</if>
<if test="zq != null "> and zq = #{zq}</if>
<if test="settlementUserId != null and settlementUserId != ''"> and settlement_user_id = #{settlementUserId}</if>
<if test="settlementUser != null and settlementUser != ''"> and settlement_user = #{settlementUser}</if>
<if test="serviceUserId != null and serviceUserId != ''"> and service_user_id = #{serviceUserId}</if>
<if test="serviceUser != null and serviceUser != ''"> and service_user = #{serviceUser}</if>
<if test="settlementType != null and settlementType != ''"> and settlement_type = #{settlementType}</if>
<if test="tempEd != null "> and temp_ed = #{tempEd}</if>
<if test="accountBalance != null "> and account_balance = #{accountBalance}</if>
<if test="foreignCurrencyBalance != null "> and foreign_currency_balance = #{foreignCurrencyBalance}</if>
<if test="weightThreshold != null "> and weight_threshold = #{weightThreshold}</if>
<if test="throwRatio != null "> and throw_ratio = #{throwRatio}</if>
<if test="creditEd != null "> and credit_ed = #{creditEd}</if>
<if test="productIds != null and productIds != ''"> and product_ids = #{productIds}</if>
<where>
<if test="customerCode != null and customerCode != ''"> and c.customer_code = #{customerCode}</if>
<if test="customerName != null and customerName != ''"> and c.customer_name like concat('%', #{customerName}, '%')</if>
<if test="customerCodeDw != null and customerCodeDw != ''"> and c.customer_code_dw = #{customerCodeDw}</if>
<if test="creditCode != null and creditCode != ''"> and c.credit_code = #{creditCode}</if>
<if test="customerType != null and customerType != ''"> and c.customer_type = #{customerType}</if>
<if test="isEnable != null and isEnable != ''"> and c.is_enable = #{isEnable}</if>
<if test="salesUserId != null and salesUserId != ''"> and c.sales_user_id = #{salesUserId}</if>
<if test="salesUser != null and salesUser != ''"> and c.sales_user = #{salesUser}</if>
<if test="ed != null "> and c.ed = #{ed}</if>
<if test="zq != null "> and c.zq = #{zq}</if>
<if test="settlementUserId != null and settlementUserId != ''"> and c.settlement_user_id = #{settlementUserId}</if>
<if test="settlementUser != null and settlementUser != ''"> and c.settlement_user = #{settlementUser}</if>
<if test="serviceUserId != null and serviceUserId != ''"> and c.service_user_id = #{serviceUserId}</if>
<if test="serviceUser != null and serviceUser != ''"> and c.service_user = #{serviceUser}</if>
<if test="settlementType != null and settlementType != ''"> and c.settlement_type = #{settlementType}</if>
<if test="tempEd != null "> and c.temp_ed = #{tempEd}</if>
<if test="weightThreshold != null "> and c.weight_threshold = #{weightThreshold}</if>
<if test="throwRatio != null "> and c.throw_ratio = #{throwRatio}</if>
<if test="creditEd != null "> and c.credit_ed = #{creditEd}</if>
<if test="productIds != null and productIds != ''"> and c.product_ids = #{productIds}</if>
</where>
order by c.customer_id desc
</select>
<select id="selectBmsCustomerByCustomerId" parameterType="Long" resultMap="BmsCustomerResult">
<include refid="selectBmsCustomerVo"/>
where customer_id = #{customerId} and del_flag = '0'
where c.customer_id = #{customerId} and c.del_flag = '0'
</select>
<resultMap type="com.ruoyi.customer.customerinfo.domain.BmsCustomerAttachment" id="BmsCustomerAttachmentResult">
@@ -82,6 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="fileType" column="file_type" />
<result property="fileExtension" column="file_extension" />
<result property="attachmentType" column="attachment_type" />
<result property="bizId" column="biz_id" />
<result property="isLogo" column="is_logo" />
<result property="sortOrder" column="sort_order" />
<result property="remark" column="remark" />
@@ -93,7 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectBmsCustomerAttachmentVo">
select attachment_id, customer_id, file_name, file_path, file_size, file_type, file_extension, attachment_type, is_logo, sort_order, remark, create_by, create_time, update_by, update_time, del_flag from bms_customer_attachment
select attachment_id, customer_id, file_name, file_path, file_size, file_type, file_extension, attachment_type, biz_id, is_logo, sort_order, remark, create_by, create_time, update_by, update_time, del_flag from bms_customer_attachment
</sql>
<select id="selectBmsCustomerAttachmentList" parameterType="com.ruoyi.customer.customerinfo.domain.BmsCustomerAttachment" resultMap="BmsCustomerAttachmentResult">
@@ -102,6 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="customerId != null "> and customer_id = #{customerId}</if>
<if test="fileName != null and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
<if test="attachmentType != null and attachmentType != ''"> and attachment_type = #{attachmentType}</if>
<if test="bizId != null"> and biz_id = #{bizId}</if>
<if test="isLogo != null and isLogo != ''"> and is_logo = #{isLogo}</if>
and del_flag = '0'
</where>
@@ -118,6 +129,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="fileType != null">file_type,</if>
<if test="fileExtension != null">file_extension,</if>
<if test="attachmentType != null">attachment_type,</if>
<if test="bizId != null">biz_id,</if>
<if test="isLogo != null">is_logo,</if>
<if test="sortOrder != null">sort_order,</if>
<if test="remark != null">remark,</if>
@@ -133,6 +145,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="fileType != null">#{fileType},</if>
<if test="fileExtension != null">#{fileExtension},</if>
<if test="attachmentType != null">#{attachmentType},</if>
<if test="bizId != null">#{bizId},</if>
<if test="isLogo != null">#{isLogo},</if>
<if test="sortOrder != null">#{sortOrder},</if>
<if test="remark != null">#{remark},</if>
@@ -152,6 +165,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="fileType != null">file_type = #{fileType},</if>
<if test="fileExtension != null">file_extension = #{fileExtension},</if>
<if test="attachmentType != null">attachment_type = #{attachmentType},</if>
<if test="bizId != null">biz_id = #{bizId},</if>
<if test="isLogo != null">is_logo = #{isLogo},</if>
<if test="sortOrder != null">sort_order = #{sortOrder},</if>
<if test="remark != null">remark = #{remark},</if>
@@ -0,0 +1,322 @@
<?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="extraCredit" column="extra_credit" />
<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, extra_credit, 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>
<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>
<!-- ================= 客户收款 ================= -->
<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="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.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="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="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="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, 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="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="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>