业务开发记录

篇幅有限

完整内容及源码关注公众号:ReverseCode,发送

支付

单号列表查询所有流水信息

支付单信息表

1
2
3
4
5
6
7
8
9
CREATE TABLE `motor_payment_transfer_serials` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_num` varchar(50) NOT NULL COMMENT '订单号',
`transfer_serials_no` varchar(50) NOT NULL COMMENT '流水号',
`third_type` tinyint(4) NOT NULL COMMENT '第三方平台,1:一麻袋,2:杰税帮',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2936 DEFAULT CHARSET=utf8mb4;

流水信息表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
CREATE TABLE `motor_payment_transfer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`mchid` varchar(50) NOT NULL COMMENT '商户号',
`partner_trade_no` varchar(50) NOT NULL COMMENT '商户订单号',
`amount` decimal(10,2) NOT NULL COMMENT '收款金额,单位元',
`enc_bank_no` varchar(64) NOT NULL COMMENT '收款方银行卡号',
`enc_true_name` varchar(64) NOT NULL COMMENT '收款方用户名',
`bank_code` varchar(64) DEFAULT NULL COMMENT '收款方开户行',
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`payment_no` varchar(50) DEFAULT '' COMMENT '微信企业付款单号,代付成功后,返回的内部业务单号',
`cmms_amt` int(11) DEFAULT '0' COMMENT '手续费金额,单位分',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态,0:待转账,1:已转账,2:转账出错,3:已申请',
`uid` int(11) DEFAULT NULL COMMENT '用户id',
`bill_no` varchar(255) DEFAULT NULL COMMENT '一麻袋平台流水号',
PRIMARY KEY (`id`),
UNIQUE KEY `udx_partner_trade_no` (`partner_trade_no`)
) ENGINE=InnoDB AUTO_INCREMENT=2465 DEFAULT CHARSET=utf8mb4 COMMENT='企业转账记录';

两张表根据流水号进行关联,一个支付单号关联多个流水号。

首先根据实现根据支付单号查询流水,返回Map。其中key为流水号,value为订单号

1
2
3
4
5
6
7
8
9
public Map<String, String> querySerialsEntByOrderNum(List<String> orderNum) {
QueryWrapper<MotorPaymentTransferSerialsENT> ew = new QueryWrapper<>();
ew.in("order_num", orderNum);
List<MotorPaymentTransferSerialsENT> serialsENTS = MotorPaymentTransferSerialsMapper.selectList(ew);
if(HelperUtil.collectionNotEmpty(serialsENTS)) {
return serialsENTS.stream().collect(Collectors.toMap(MotorPaymentTransferSerialsENT::getTransferSerialsNo, MotorPaymentTransferSerialsENT::getOrderNum));
}
return null;
}
  1. 根据订单号列表查询返回Map,其中key流水号,value订单号
  2. 根据所有的key转成list后查询所有流水信息返回list
  3. 遍历流水信息,根据流水中的流水号和之前返回的Map拿到订单号,定义一个新Map,key为订单号,value为流水信息列表,该Map利用computeIfAbsent将订单号作为key返回一个list,并将流水信息赋值到dto填入value中,完成根据单号列表查询返回所有流水信息,并以单号为key,流水列表为value的map返回结果。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public Map<String, List<RpcTransferSerialsDTO>> queryTransferSerialsByOrderNum(List<String> orderNum) {
Map<String, String> serialsOrderNumMap = paymentTransferSerialsService.querySerialsEntByOrderNum(orderNum);
Set<String> serialsNumSet = serialsOrderNumMap.keySet();
List<MotorPaymentTransferENT> paymentTransferENTS = transferService.queryTransferEntByOrderNum(new ArrayList<>(serialsNumSet));

Map<String, List<RpcTransferSerialsDTO>> orderSerialdataMap = new HashMap<>();
for (MotorPaymentTransferENT motorPaymentTransferENT : paymentTransferENTS) {
String ordertNum = serialsOrderNumMap.get(motorPaymentTransferENT.getPartnerTradeNo());
List<RpcTransferSerialsDTO> paymentTransferENTList = orderSerialdataMap.computeIfAbsent(ordertNum, t -> new ArrayList<RpcTransferSerialsDTO>());
RpcTransferSerialsDTO serialsDTO = new RpcTransferSerialsDTO() {{
setTransferSerialsNo(motorPaymentTransferENT.getPartnerTradeNo());
setStatus(motorPaymentTransferENT.getStatus());
setExceptionCause(motorPaymentTransferENT.getRemark());
setCreateTime(motorPaymentTransferENT.getCreateTime());
setUpdateTime(motorPaymentTransferENT.getUpdateTime());
}};
paymentTransferENTList.add(serialsDTO);
}
return orderSerialdataMap;
}
文章作者: J
文章链接: http://onejane.github.io/2021/07/19/业务开发记录/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 万物皆可逆向
支付宝打赏
微信打赏