From 8047c85ed641e93ffb399c22530a07def6a7a750 Mon Sep 17 00:00:00 2001 From: DaxPay Date: Tue, 7 May 2024 20:31:39 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E8=87=AA=E5=8A=A8=E5=88=86=E8=B4=A6?= =?UTF-8?q?=E8=B0=83=E8=AF=95,=20=E6=95=B0=E6=8D=AE=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E6=94=B9=E4=B8=BA=E7=B1=BB=E5=9E=8B=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=99=A8=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _doc/Task.md | 6 +- .../typehandler/DecryptTypeHandler.java | 83 +++++++++++++++++++ .../common/typehandler/TypeHandlerConfig.java | 22 +++++ .../channel/alipay/entity/AliPayConfig.java | 14 ++-- .../service/AliPayAllocationService.java | 4 +- .../channel/union/entity/UnionPayConfig.java | 11 ++- .../wechat/entity/WeChatPayConfig.java | 14 ++-- .../entity/AllocationOrderDetail.java | 7 +- .../service/AllocationOrderService.java | 10 +-- .../pay/service/PayOrderQueryService.java | 2 +- .../dao/AllocationGroupManager.java | 8 +- .../allocation/entity/AllocationReceiver.java | 6 +- .../allocation/service/AllocationService.java | 4 +- 13 files changed, 146 insertions(+), 45 deletions(-) create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/typehandler/DecryptTypeHandler.java create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/typehandler/TypeHandlerConfig.java diff --git a/_doc/Task.md b/_doc/Task.md index 8759377aa..90154f920 100644 --- a/_doc/Task.md +++ b/_doc/Task.md @@ -35,10 +35,10 @@ - [x] 创建定时任务, 自动对待分账订单进行分账 - [x] 增加定时同步分账状态任务 - [x] 增加自动完结功能 +- [x] 数据加密方式改为类型处理器模式 +- [ ] 页面优化 2.0.7: 分账完善和基础架构优化 - [ ] 资金流水优化 -- [ ] 数据加密方式改为类型处理器模式 -- [ ] - [ ] 支持分账组分账和自己传接收方进行分账 - [ ] DEMO增加获取微信OpenID和支付宝OpenId功能 - [ ] 分账接收方管理提供接口调用 @@ -46,7 +46,7 @@ - [ ] 分账回调处理 - [ ] 分账组管理提供接口调用 - [ ] 分账通知 -- [ ] 增加收银台功能 +- [ ] 增加收单收银台功能 2.0.x 版本内容 - [ ] 对账回退及退款 diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/typehandler/DecryptTypeHandler.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/typehandler/DecryptTypeHandler.java new file mode 100644 index 000000000..030e8dbf3 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/typehandler/DecryptTypeHandler.java @@ -0,0 +1,83 @@ +package cn.bootx.platform.daxpay.service.common.typehandler; + +import cn.bootx.platform.starter.data.perm.configuration.DataPermProperties; +import cn.hutool.core.codec.Base64; +import cn.hutool.core.util.StrUtil; +import cn.hutool.crypto.SecureUtil; +import cn.hutool.crypto.symmetric.AES; +import cn.hutool.extra.spring.SpringUtil; +import lombok.Setter; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +import javax.annotation.PostConstruct; +import java.nio.charset.StandardCharsets; +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * 字段加密处理类 + * @author xxm + * @since 2024/5/7 + */ +public class DecryptTypeHandler extends BaseTypeHandler { + + @Setter + private static DataPermProperties dataPermProperties; + + + /** + * 加密 + */ + @Override + public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, this.encryptValue(parameter)); + } + + /** + * 解密 + */ + @Override + public String getNullableResult(ResultSet rs, String columnName) throws SQLException { + String columnValue = rs.getString(columnName); + return StrUtil.isBlank(columnValue) ? columnValue : this.decryptValue(columnValue); + } + + /** + * 解密 + */ + @Override + public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + String columnValue = rs.getString(columnIndex); + return StrUtil.isBlank(columnValue) ? columnValue : this.decryptValue(columnValue); + } + + /** + * 解密 + */ + @Override + public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + String columnValue = cs.getString(columnIndex); + return StrUtil.isBlank(columnValue) ? columnValue : this.decryptValue(columnValue); + } + + /** + * 对象值加密 + */ + public String encryptValue(String fieldValue) { + AES aes = SecureUtil.aes(dataPermProperties.getFieldDecryptKey().getBytes(StandardCharsets.UTF_8)); + return aes.encryptBase64(fieldValue); + } + + /** + * 对具体的值进行解码 + */ + public String decryptValue(String fieldValue) { + AES aes = SecureUtil.aes(dataPermProperties.getFieldDecryptKey().getBytes(StandardCharsets.UTF_8)); + return new String(aes.decrypt(Base64.decode(fieldValue)), StandardCharsets.UTF_8); + } + + +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/typehandler/TypeHandlerConfig.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/typehandler/TypeHandlerConfig.java new file mode 100644 index 000000000..c022aa578 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/common/typehandler/TypeHandlerConfig.java @@ -0,0 +1,22 @@ +package cn.bootx.platform.daxpay.service.common.typehandler; + +import cn.bootx.platform.starter.data.perm.configuration.DataPermProperties; +import cn.hutool.extra.spring.SpringUtil; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; + +/** + * + * @author xxm + * @since 2024/5/7 + */ +@Configuration +public class TypeHandlerConfig { + + @PostConstruct + public void init(){ + DataPermProperties permProperties = SpringUtil.getBean(DataPermProperties.class); + DecryptTypeHandler.setDataPermProperties(permProperties); + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/entity/AliPayConfig.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/entity/AliPayConfig.java index f1e3eb44f..9d7e655ce 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/entity/AliPayConfig.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/entity/AliPayConfig.java @@ -1,11 +1,11 @@ package cn.bootx.platform.daxpay.service.core.channel.alipay.entity; import cn.bootx.platform.common.core.annotation.BigField; -import cn.bootx.platform.common.core.annotation.EncryptionField; import cn.bootx.platform.common.core.function.EntityBaseFunction; import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity; import cn.bootx.platform.common.mybatisplus.handler.StringListTypeHandler; import cn.bootx.platform.daxpay.service.code.AliPayCode; +import cn.bootx.platform.daxpay.service.common.typehandler.DecryptTypeHandler; import cn.bootx.platform.daxpay.service.core.channel.alipay.convert.AlipayConvert; import cn.bootx.platform.daxpay.service.dto.channel.alipay.AliPayConfigDto; import cn.bootx.table.modify.annotation.DbColumn; @@ -85,41 +85,41 @@ public class AliPayConfig extends MpBaseEntity implements EntityBaseFunction { /** 分账订单ID */ @@ -53,7 +54,7 @@ public class AllocationOrderDetail extends MpBaseEntity implements EntityBaseFun /** 接收方账号 */ @DbColumn(comment = "接收方账号") - @EncryptionField + @TableField(typeHandler = DecryptTypeHandler.class) private String receiverAccount; /** 接收方姓名 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/service/AllocationOrderService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/service/AllocationOrderService.java index be051dbf3..d5faccf52 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/service/AllocationOrderService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/service/AllocationOrderService.java @@ -23,7 +23,6 @@ import cn.bootx.platform.daxpay.service.dto.order.allocation.AllocationOrderDeta import cn.bootx.platform.daxpay.service.dto.order.allocation.AllocationOrderDto; import cn.bootx.platform.daxpay.service.param.order.AllocationOrderQuery; import cn.bootx.platform.daxpay.util.OrderNoGenerateUtil; -import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.IdUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -136,16 +135,9 @@ public class AllocationOrderService { payOrder.setAllocationStatus(PayOrderAllocStatusEnum.ALLOCATION.getCode()); payOrderManager.updateById(payOrder); // 因为加密后字段值会发生变更, 所以在保存前备份一下 - List detailsBack = details.stream() - .map(o -> { - AllocationOrderDetail allocationOrderDetail = new AllocationOrderDetail(); - BeanUtil.copyProperties(o, allocationOrderDetail); - return allocationOrderDetail; - }) - .collect(Collectors.toList()); allocationOrderDetailManager.saveAll(details); allocationOrderManager.save(allocationOrder); - return new OrderAndDetail().setOrder(allocationOrder).setDetails(detailsBack); + return new OrderAndDetail().setOrder(allocationOrder).setDetails(details); } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/service/PayOrderQueryService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/service/PayOrderQueryService.java index 615c8c822..209703d17 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/service/PayOrderQueryService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/service/PayOrderQueryService.java @@ -86,7 +86,7 @@ public class PayOrderQueryService { throw new ValidationFailedException("业务号或支付单ID不能都为空"); } // 查询支付单 - PayOrder payOrder = this.findByBizOrOrderNo(param.getBizOrderNoeNo(), param.getOrderNo()) + PayOrder payOrder = this.findByBizOrOrderNo(param.getOrderNo(), param.getBizOrderNoeNo()) .orElseThrow(() -> new DataNotExistException("未查询到支付订单")); // 查询扩展数据 payOrderExtraManager.findById(payOrder.getId()) diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/dao/AllocationGroupManager.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/dao/AllocationGroupManager.java index 1692d5d7c..a40ae46d7 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/dao/AllocationGroupManager.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/dao/AllocationGroupManager.java @@ -24,6 +24,9 @@ import java.util.Optional; @RequiredArgsConstructor public class AllocationGroupManager extends BaseManager { + /** + * 分页 + */ public Page page(PageParam pageParam, AllocationGroupParam query) { Page mpPage = MpUtil.getMpPage(pageParam, AllocationGroup.class); QueryWrapper generator = QueryGenerator.generator(query); @@ -44,6 +47,9 @@ public class AllocationGroupManager extends BaseManager findDefaultGroup(String channel) { - return findByField(AllocationGroup::getChannel,channel); + return this.lambdaQuery() + .eq(AllocationGroup::getChannel,channel) + .eq(AllocationGroup::isDefaultGroup,true) + .oneOpt(); } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/entity/AllocationReceiver.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/entity/AllocationReceiver.java index 105751240..41fce951c 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/entity/AllocationReceiver.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/entity/AllocationReceiver.java @@ -1,11 +1,11 @@ package cn.bootx.platform.daxpay.service.core.payment.allocation.entity; -import cn.bootx.platform.common.core.annotation.EncryptionField; import cn.bootx.platform.common.core.function.EntityBaseFunction; import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity; import cn.bootx.platform.daxpay.code.AllocReceiverTypeEnum; import cn.bootx.platform.daxpay.code.AllocRelationTypeEnum; import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.service.common.typehandler.DecryptTypeHandler; import cn.bootx.platform.daxpay.service.core.payment.allocation.convert.AllocationReceiverConvert; import cn.bootx.platform.daxpay.service.dto.allocation.AllocationReceiverDto; import cn.bootx.table.modify.annotation.DbColumn; @@ -26,7 +26,7 @@ import lombok.experimental.Accessors; @Data @Accessors(chain = true) @DbTable(comment = "分账接收方") -@TableName("pay_allocation_receiver") +@TableName(value = "pay_allocation_receiver",autoResultMap = true) public class AllocationReceiver extends MpBaseEntity implements EntityBaseFunction { @DbColumn(comment = "账号别名") @@ -48,7 +48,7 @@ public class AllocationReceiver extends MpBaseEntity implements EntityBaseFuncti @DbColumn(comment = "接收方账号") - @EncryptionField + @TableField(typeHandler = DecryptTypeHandler.class) private String receiverAccount; /** 接收方姓名 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationService.java index 73bcf5b10..9f518e863 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationService.java @@ -230,11 +230,11 @@ public class AllocationService { // 获取分账订单 AllocationOrder allocationOrder = null; if (Objects.nonNull(param.getAllocationNo())){ - allocationOrder = allocationOrderManager.findById(param.getBizAllocationNo()) + allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocationNo()) .orElseThrow(() -> new DataNotExistException("分账单不存在")); } if (Objects.isNull(allocationOrder)){ - allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocationNo()) + allocationOrder = allocationOrderManager.findByAllocationNo(param.getBizAllocationNo()) .orElseThrow(() -> new DataNotExistException("分账单不存在")); } this.sync(allocationOrder);