客户余额记录

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
@@ -47,6 +47,9 @@ public class BmsCustomerAttachment extends BaseEntity
@Excel(name = "附件类型", readConverterExp = "0=附件资料,1=客户Logo,2=合同文件,3=其他")
private String attachmentType;
/** 关联业务ID(如收款单ID,attachment_type=3 时使用) */
private Long bizId;
/** 是否Logo(0否 1是) */
private String isLogo;
@@ -0,0 +1,52 @@
package com.ruoyi.customer.customermoney.domain;
import java.math.BigDecimal;
import com.ruoyi.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 客户余额账户 customer_account
*
* @author ruoyi
* @date 2026-09-11
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CustomerAccount extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 客户ID */
private Long customerId;
/** 币种,如 CNY/USD */
private String currency;
/** 账户余额 */
private BigDecimal balance;
/** 冻结余额 */
private BigDecimal frozenBalance;
/** 总额度 */
private BigDecimal totalCredit;
/** 额外额度 */
private BigDecimal extraCredit;
/** 已用额度 */
private BigDecimal usedCredit;
/** 税金 */
private BigDecimal tax;
/** 乐观锁版本号 */
private Integer version;
/** 删除标志(0存在 1删除) */
private String delFlag;
}
@@ -0,0 +1,80 @@
package com.ruoyi.customer.customermoney.domain;
import java.math.BigDecimal;
import com.ruoyi.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 客户余额流水 customer_balance_flow
*
* @author ruoyi
* @date 2026-09-11
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CustomerBalanceFlow extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 业务类型:收款 */
public static final String BIZ_RECEIPT = "RECEIPT";
/** 业务类型:账单支付 */
public static final String BIZ_BILL_PAY = "BILL_PAY";
/** 业务类型:退款 */
public static final String BIZ_REFUND = "REFUND";
/** 业务类型:手工调整 */
public static final String BIZ_ADJUST = "ADJUST";
/** 业务类型:冻结 */
public static final String BIZ_FREEZE = "FREEZE";
/** 业务类型:解冻 */
public static final String BIZ_UNFREEZE = "UNFREEZE";
/** 主键 */
private Long id;
/** 流水号 */
private String flowNo;
/** 客户ID */
private Long customerId;
/** 客户账户ID */
private Long accountId;
/** 币种 */
private String currency;
/** 业务类型:RECEIPT/BILL_PAY/REFUND/ADJUST/FREEZE/UNFREEZE */
private String bizType;
/** 关联业务ID */
private Long bizId;
/** 关联业务单号 */
private String bizNo;
/** 变动方向:1增加,-1减少 */
private Integer direction;
/** 变动金额 */
private BigDecimal amount;
/** 变动前余额 */
private BigDecimal beforeBalance;
/** 变动后余额 */
private BigDecimal afterBalance;
/** 变动前冻结余额 */
private BigDecimal beforeFrozenBalance;
/** 变动后冻结余额 */
private BigDecimal afterFrozenBalance;
/** 操作人ID */
private Long operatorId;
/** 删除标志(0存在 1删除) */
private String delFlag;
}
@@ -0,0 +1,99 @@
package com.ruoyi.customer.customermoney.domain;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.customer.customerinfo.domain.BmsCustomerAttachment;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 客户收款 customer_receipt
*
* @author ruoyi
* @date 2026-09-11
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CustomerReceipt extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 状态:待确认 */
public static final String STATUS_PENDING = "PENDING";
/** 状态:已确认 */
public static final String STATUS_CONFIRMED = "CONFIRMED";
/** 状态:已取消 */
public static final String STATUS_CANCELLED = "CANCELLED";
/** 收款类型:预充值 */
public static final String TYPE_PREPAY = "PREPAY";
/** 收款类型:还款核销 */
public static final String TYPE_REPAY = "REPAY";
/** 收款类型:混合 */
public static final String TYPE_MIXED = "MIXED";
/** 主键 */
private Long id;
/** 收款单号 */
private String receiptNo;
/** 客户ID */
private Long customerId;
/** 客户账户ID(预留) */
private Long accountId;
/** 收款类型:PREPAY预充值/REPAY还款核销/MIXED混合 */
private String receiptType;
/** 收款金额 */
private BigDecimal amount;
/** 已核销金额 */
private BigDecimal allocatedAmount;
/** 待核销金额 */
private BigDecimal unallocatedAmount;
/** 币种 */
private String currency;
/** 收款方式:BANK_TRANSFER/ALIPAY/WECHAT/CASH/OTHER */
private String payMethod;
/** 银行流水号/支付平台流水号 */
private String bankTransactionNo;
/** 收款日期 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date receivedAt;
/** 状态:PENDING待确认/CONFIRMED已确认/CANCELLED已取消 */
private String status;
/** 确认时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date confirmedAt;
/** 确认人 */
private Long confirmedBy;
/** 开票状态:NONE未开/PART部分/ALL全部 */
private String invoiceStatus;
/** 乐观锁版本号 */
private Integer version;
/** 删除标志(0存在 1删除) */
private String delFlag;
/** 收款附件列表(存 bms_customer_attachment,attachment_type='3',biz_id 关联本单) */
private List<BmsCustomerAttachment> attachmentList;
/** 收款附件数量(列表查询统计) */
private Integer attachmentCount;
}
@@ -0,0 +1,60 @@
package com.ruoyi.customer.customermoney.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.customer.customermoney.domain.CustomerAccount;
import com.ruoyi.customer.customermoney.domain.CustomerBalanceFlow;
import com.ruoyi.customer.customermoney.domain.CustomerReceipt;
/**
* 客户余额/收款/流水 Mapper
*
* @author ruoyi
* @date 2026-09-11
*/
public interface CustomerMoneyMapper
{
/* ================= 客户余额账户 ================= */
/** 按客户+币种查询账户 */
CustomerAccount selectAccountByCustomerCurrency(@Param("customerId") Long customerId,
@Param("currency") String currency);
/** 按客户+币种查询账户(行锁,审核事务内使用) */
CustomerAccount selectAccountForUpdate(@Param("customerId") Long customerId,
@Param("currency") String currency);
/** 查询客户全部币种账户 */
List<CustomerAccount> selectAccountListByCustomerId(@Param("customerId") Long customerId);
/** 新增账户 */
int insertAccount(CustomerAccount account);
/** 乐观锁更新余额 */
int updateAccountBalance(CustomerAccount account);
/* ================= 客户收款 ================= */
/** 查询收款单列表 */
List<CustomerReceipt> selectReceiptList(CustomerReceipt query);
/** 按ID查询收款单 */
CustomerReceipt selectReceiptById(@Param("id") Long id);
/** 新增收款单 */
int insertReceipt(CustomerReceipt receipt);
/** 审核通过:PENDING -> CONFIRMED(带状态+乐观锁条件) */
int confirmReceipt(CustomerReceipt receipt);
/** 取消收款单:PENDING -> CANCELLED */
int cancelReceipt(@Param("id") Long id, @Param("updateBy") String updateBy);
/* ================= 余额流水 ================= */
/** 查询流水列表 */
List<CustomerBalanceFlow> selectFlowList(CustomerBalanceFlow query);
/** 新增流水 */
int insertFlow(CustomerBalanceFlow flow);
}
@@ -0,0 +1,39 @@
package com.ruoyi.customer.customermoney.service;
import java.util.List;
import com.ruoyi.customer.customermoney.domain.CustomerAccount;
import com.ruoyi.customer.customermoney.domain.CustomerBalanceFlow;
import com.ruoyi.customer.customermoney.domain.CustomerReceipt;
/**
* 客户余额/收款/流水 Service接口
*
* @author ruoyi
* @date 2026-09-11
*/
public interface ICustomerMoneyService
{
/** 查询客户各币种账户 */
List<CustomerAccount> selectAccountList(Long customerId);
/** 查询收款单列表 */
List<CustomerReceipt> selectReceiptList(CustomerReceipt query);
/** 查询收款单详情(含附件) */
CustomerReceipt selectReceiptById(Long id);
/** 登记收款(状态默认 PENDING,同时保存附件) */
int insertReceipt(CustomerReceipt receipt);
/**
* 审核通过收款单:PENDING -> CONFIRMED
* 事务内:锁定账户(不存在则初始化)-> 变动余额/已用额度 -> 写余额流水
*/
int confirmReceipt(Long id);
/** 取消收款单(仅待确认可取消) */
int cancelReceipt(Long id);
/** 查询余额流水列表 */
List<CustomerBalanceFlow> selectFlowList(CustomerBalanceFlow query);
}
@@ -0,0 +1,253 @@
package com.ruoyi.customer.customermoney.service.impl;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.customer.customerinfo.domain.BmsCustomerAttachment;
import com.ruoyi.customer.customerinfo.mapper.BmsCustomerMapper;
import com.ruoyi.customer.customermoney.domain.CustomerAccount;
import com.ruoyi.customer.customermoney.domain.CustomerBalanceFlow;
import com.ruoyi.customer.customermoney.domain.CustomerReceipt;
import com.ruoyi.customer.customermoney.mapper.CustomerMoneyMapper;
import com.ruoyi.customer.customermoney.service.ICustomerMoneyService;
/**
* 客户余额/收款/流水 Service实现
*
* @author ruoyi
* @date 2026-09-11
*/
@Service
public class CustomerMoneyServiceImpl implements ICustomerMoneyService
{
private static final DateTimeFormatter NO_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
@Autowired
private CustomerMoneyMapper customerMoneyMapper;
@Autowired
private BmsCustomerMapper bmsCustomerMapper;
@Override
public List<CustomerAccount> selectAccountList(Long customerId)
{
return customerMoneyMapper.selectAccountListByCustomerId(customerId);
}
@Override
public List<CustomerReceipt> selectReceiptList(CustomerReceipt query)
{
return customerMoneyMapper.selectReceiptList(query);
}
@Override
public CustomerReceipt selectReceiptById(Long id)
{
CustomerReceipt receipt = customerMoneyMapper.selectReceiptById(id);
if (receipt != null)
{
BmsCustomerAttachment query = new BmsCustomerAttachment();
query.setBizId(id);
receipt.setAttachmentList(bmsCustomerMapper.selectBmsCustomerAttachmentList(query));
}
return receipt;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int insertReceipt(CustomerReceipt receipt)
{
if (receipt.getCustomerId() == null)
{
throw new ServiceException("客户ID不能为空");
}
if (receipt.getAmount() == null || receipt.getAmount().compareTo(BigDecimal.ZERO) <= 0)
{
throw new ServiceException("收款金额必须大于0");
}
if (!StringUtils.hasText(receipt.getReceiptType()))
{
receipt.setReceiptType(CustomerReceipt.TYPE_PREPAY);
}
if (!StringUtils.hasText(receipt.getCurrency()))
{
receipt.setCurrency("CNY");
}
receipt.setReceiptNo(generateNo("SK"));
receipt.setStatus(CustomerReceipt.STATUS_PENDING);
receipt.setAllocatedAmount(BigDecimal.ZERO);
receipt.setUnallocatedAmount(receipt.getAmount());
if (!StringUtils.hasText(receipt.getInvoiceStatus()))
{
receipt.setInvoiceStatus("NONE");
}
receipt.setVersion(0);
customerMoneyMapper.insertReceipt(receipt);
// 收款附件:复用客户附件表,类型挂"其他(3)",biz_id 关联收款单
saveReceiptAttachments(receipt);
return 1;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int confirmReceipt(Long id)
{
CustomerReceipt receipt = customerMoneyMapper.selectReceiptById(id);
if (receipt == null)
{
throw new ServiceException("收款单不存在");
}
if (!CustomerReceipt.STATUS_PENDING.equals(receipt.getStatus()))
{
throw new ServiceException("仅待确认的收款单可以审核");
}
String currency = StringUtils.hasText(receipt.getCurrency()) ? receipt.getCurrency() : "CNY";
String username = SecurityUtils.getUsername();
Long userId = SecurityUtils.getUserId();
// 1. 行锁锁定客户币种账户,不存在则自动初始化
CustomerAccount account = customerMoneyMapper.selectAccountForUpdate(receipt.getCustomerId(), currency);
if (account == null)
{
account = new CustomerAccount();
account.setCustomerId(receipt.getCustomerId());
account.setCurrency(currency);
account.setBalance(BigDecimal.ZERO);
account.setFrozenBalance(BigDecimal.ZERO);
account.setTotalCredit(BigDecimal.ZERO);
account.setExtraCredit(BigDecimal.ZERO);
account.setUsedCredit(BigDecimal.ZERO);
account.setTax(BigDecimal.ZERO);
account.setVersion(0);
account.setCreateBy(username);
customerMoneyMapper.insertAccount(account);
}
// 2. 变动余额(预充值/混合增加余额;还款核销释放已用额度)
BigDecimal amount = nz(receipt.getAmount());
BigDecimal beforeBalance = nz(account.getBalance());
BigDecimal afterBalance = beforeBalance.add(amount);
BigDecimal frozenBalance = nz(account.getFrozenBalance());
account.setBalance(afterBalance);
if (CustomerReceipt.TYPE_REPAY.equals(receipt.getReceiptType()))
{
account.setUsedCredit(nz(account.getUsedCredit()).subtract(amount).max(BigDecimal.ZERO));
}
account.setUpdateBy(username);
int accountRows = customerMoneyMapper.updateAccountBalance(account);
if (accountRows == 0)
{
throw new ServiceException("账户余额已被其他操作变动,请刷新后重试");
}
// 3. 写余额流水
CustomerBalanceFlow flow = new CustomerBalanceFlow();
flow.setFlowNo(generateNo("LS"));
flow.setCustomerId(receipt.getCustomerId());
flow.setAccountId(account.getId());
flow.setCurrency(currency);
flow.setBizType(CustomerBalanceFlow.BIZ_RECEIPT);
flow.setBizId(receipt.getId());
flow.setBizNo(receipt.getReceiptNo());
flow.setDirection(1);
flow.setAmount(amount);
flow.setBeforeBalance(beforeBalance);
flow.setAfterBalance(afterBalance);
flow.setBeforeFrozenBalance(frozenBalance);
flow.setAfterFrozenBalance(frozenBalance);
flow.setOperatorId(userId);
flow.setCreateBy(username);
flow.setRemark("收款单审核通过:" + receipt.getReceiptNo());
customerMoneyMapper.insertFlow(flow);
// 4. 收款单置为已确认
receipt.setStatus(CustomerReceipt.STATUS_CONFIRMED);
receipt.setConfirmedAt(new Date());
receipt.setConfirmedBy(userId);
receipt.setUpdateBy(username);
int receiptRows = customerMoneyMapper.confirmReceipt(receipt);
if (receiptRows == 0)
{
throw new ServiceException("收款单状态已变更,请刷新后重试");
}
return receiptRows;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int cancelReceipt(Long id)
{
CustomerReceipt receipt = customerMoneyMapper.selectReceiptById(id);
if (receipt == null)
{
throw new ServiceException("收款单不存在");
}
if (!CustomerReceipt.STATUS_PENDING.equals(receipt.getStatus()))
{
throw new ServiceException("仅待确认的收款单可以取消");
}
return customerMoneyMapper.cancelReceipt(id, SecurityUtils.getUsername());
}
@Override
public List<CustomerBalanceFlow> selectFlowList(CustomerBalanceFlow query)
{
return customerMoneyMapper.selectFlowList(query);
}
/* ================= 私有方法 ================= */
/** 保存收款附件到客户附件表 */
private void saveReceiptAttachments(CustomerReceipt receipt)
{
if (CollectionUtils.isEmpty(receipt.getAttachmentList()))
{
return;
}
int sort = 0;
for (BmsCustomerAttachment attachment : receipt.getAttachmentList())
{
attachment.setAttachmentId(null);
attachment.setCustomerId(receipt.getCustomerId());
attachment.setBizId(receipt.getId());
attachment.setAttachmentType("3");
if (!StringUtils.hasText(attachment.getIsLogo()))
{
attachment.setIsLogo("0");
}
if (attachment.getSortOrder() == null)
{
attachment.setSortOrder(sort);
}
attachment.setDelFlag("0");
bmsCustomerMapper.insertBmsCustomerAttachment(attachment);
sort++;
}
}
/** 生成业务单号:前缀 + 时间戳(毫秒) + 3位随机数 */
private String generateNo(String prefix)
{
return prefix + LocalDateTime.now().format(NO_FORMATTER)
+ ThreadLocalRandom.current().nextInt(100, 1000);
}
private BigDecimal nz(BigDecimal value)
{
return value == null ? BigDecimal.ZERO : value;
}
}
@@ -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>