diff --git a/docs/sql/init.sql b/docs/sql/init.sql index 85928cb..2b9bd98 100644 --- a/docs/sql/init.sql +++ b/docs/sql/init.sql @@ -253,7 +253,7 @@ CREATE TABLE `t_mch_pay_passage` ( `created_at` TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', `updated_at` TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间', PRIMARY KEY (`id`), - UNIQUE KEY `Uni_MchNo_WayCode` (`mch_no`,`if_code`, `way_code`) + UNIQUE KEY `Uni_AppId_WayCode` (`app_id`,`if_code`, `way_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商户支付通道表'; @@ -399,12 +399,21 @@ insert into t_sys_entitlement values('ENT_MCH', '商户管理', 'shop', '', 'Rou insert into t_sys_entitlement values('ENT_MCH_INFO_EDIT', '按钮:编辑', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_INFO', '0', 'MGR', now(), now()); insert into t_sys_entitlement values('ENT_MCH_INFO_VIEW', '按钮:详情', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_INFO', '0', 'MGR', now(), now()); insert into t_sys_entitlement values('ENT_MCH_INFO_DEL', '按钮:删除', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_INFO', '0', 'MGR', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_LIST', '商户支付参数配置列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_INFO', '0', 'MGR', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_ADD', '商户支付参数配置', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_CONFIG_LIST', '0', 'MGR', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_VIEW', '商户支付参数配置详情', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_CONFIG_LIST', '0', 'MGR', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_LIST', '商户支付通道配置列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_INFO', '0', 'MGR', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_CONFIG', '商户支付通道配置入口', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_PASSAGE_LIST', '0', 'MGR', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_ADD', '商户支付通道配置保存', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_PASSAGE_LIST', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_CONFIG', '应用配置', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_INFO', '0', 'MGR', now(), now()); + + -- 应用管理 + insert into t_sys_entitlement values('ENT_MCH_APP', '应用列表', 'appstore', '/apps', 'MchAppPage', 'ML', 0, 1, 'ENT_MCH', '20', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_LIST', '页面:应用列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_ADD', '按钮:新增', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_EDIT', '按钮:编辑', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_VIEW', '按钮:详情', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_DEL', '按钮:删除', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_LIST', '应用支付参数配置列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_ADD', '应用支付参数配置', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_CONFIG_LIST', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_VIEW', '应用支付参数配置详情', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_CONFIG_LIST', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_LIST', '应用支付通道配置列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_CONFIG', '应用支付通道配置入口', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_PASSAGE_LIST', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_ADD', '应用支付通道配置保存', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_PASSAGE_LIST', '0', 'MGR', now(), now()); -- 服务商管理 insert into t_sys_entitlement values('ENT_ISV', '服务商管理', 'block', '', 'RouteView', 'ML', 0, 1, 'ROOT', '40', 'MGR', now(), now()); @@ -492,9 +501,20 @@ insert into t_sys_entitlement values('ENT_MCH_MAIN', '主页', 'home', '/main', insert into t_sys_entitlement values('ENT_MCH_MAIN_USER_INFO', '主页用户信息', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_MAIN', '0', 'MCH', now(), now()); -- 【商户系统】 商户中心 --- insert into t_sys_entitlement values('ENT_MCH_CENTER', '商户中心', 'team', '', 'RouteView', 'ML', 0, 'ROOT', '10', 'MCH', now(), now()); --- insert into t_sys_entitlement values('ENT_MCH_INFO', '商户信息', 'user', '/mch', 'MchInfoPage', 'ML', 0, 'ENT_MCH_CENTER', '10', 'MCH', now(), now()); --- insert into t_sys_entitlement values('ENT_MCH_INFO_EDIT', '按钮:修改商户信息', 'no-icon', '', '', 'PB', 0, 'ENT_MCH_INFO', '0', 'MCH', now(), now()); +insert into t_sys_entitlement values('ENT_MCH_CENTER', '商户中心', 'team', '', 'RouteView', 'ML', 0, 1, 'ROOT', '10', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP', '应用管理', 'appstore', '/apps', 'MchAppPage', 'ML', 0, 1, 'ENT_MCH_CENTER', '10', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_LIST', '页面:应用列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_ADD', '按钮:新增', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_EDIT', '按钮:编辑', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_VIEW', '按钮:详情', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_APP_DEL', '按钮:删除', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_LIST', '应用支付参数配置列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_ADD', '应用支付参数配置', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_CONFIG_LIST', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_VIEW', '应用支付参数配置详情', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_CONFIG_LIST', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_LIST', '应用支付通道配置列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_APP', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_CONFIG', '应用支付通道配置入口', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_PASSAGE_LIST', '0', 'MCH', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_ADD', '应用支付通道配置保存', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_PASSAGE_LIST', '0', 'MCH', now(), now()); + -- 【商户系统】 订单管理 insert into t_sys_entitlement values('ENT_ORDER', '订单中心', 'transaction', '', 'RouteView', 'ML', 0, 1, 'ROOT', '20', 'MCH', now(), now()); @@ -505,16 +525,6 @@ insert into t_sys_entitlement values('ENT_ORDER', '订单中心', 'transaction', insert into t_sys_entitlement values('ENT_REFUND_LIST', '页面:退款订单列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_REFUND_ORDER', '0', 'MCH', now(), now()); insert into t_sys_entitlement values('ENT_REFUND_ORDER_VIEW', '按钮:详情', 'no-icon', '', '', 'PB', 0, 1, 'ENT_REFUND_ORDER', '0', 'MCH', now(), now()); --- 【商户系统】 支付配置 -insert into t_sys_entitlement values('ENT_MCH_PC', '支付配置', 'file-done', '', 'RouteView', 'ML', 0, 1, 'ROOT', '30', 'MCH', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_LIST', '支付参数', 'interaction', '/pay/config', 'PayConfigPage', 'ML', 0, 1, 'ENT_MCH_PC', '10', 'MCH', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_ADD', '商户支付参数配置', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_CONFIG_LIST', '0', 'MCH', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_CONFIG_VIEW', '商户支付参数配置详情', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_CONFIG_LIST', '0', 'MCH', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_LIST', '支付通道', 'appstore', '/pay/passage', 'PayPassagePage', 'ML', 0, 1, 'ENT_MCH_PC', '20', 'MCH', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_CONFIG', '商户支付通道配置入口', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_PASSAGE_LIST', '0', 'MCH', now(), now()); - insert into t_sys_entitlement values('ENT_MCH_PAY_PASSAGE_ADD', '商户支付通道配置保存', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_PAY_PASSAGE_LIST', '0', 'MCH', now(), now()); - - -- 【商户系统】 系统管理 insert into t_sys_entitlement values('ENT_SYS_CONFIG', '系统管理', 'setting', '', 'RouteView', 'ML', 0, 1, 'ROOT', '200', 'MCH', now(), now()); insert into t_sys_entitlement values('ENT_UR', '用户角色管理', 'team', '', 'RouteView', 'ML', 0, 1, 'ENT_SYS_CONFIG', '10', 'MCH', now(), now()); diff --git a/jeepay-core/src/main/java/com/jeequan/jeepay/core/entity/MchApp.java b/jeepay-core/src/main/java/com/jeequan/jeepay/core/entity/MchApp.java index 97cb379..358c25f 100644 --- a/jeepay-core/src/main/java/com/jeequan/jeepay/core/entity/MchApp.java +++ b/jeepay-core/src/main/java/com/jeequan/jeepay/core/entity/MchApp.java @@ -1,5 +1,6 @@ package com.jeequan.jeepay.core.entity; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -35,7 +36,7 @@ public class MchApp extends BaseModel { /** * 应用ID */ - @TableId + @TableId(value = "app_id", type = IdType.ASSIGN_UUID) private String appId; /** diff --git a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/isv/IsvPayInterfaceConfigController.java b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/isv/IsvPayInterfaceConfigController.java index 6c6c969..af50a70 100644 --- a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/isv/IsvPayInterfaceConfigController.java +++ b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/isv/IsvPayInterfaceConfigController.java @@ -54,7 +54,7 @@ public class IsvPayInterfaceConfigController extends CommonCtrl { @GetMapping public ApiRes list() { - List list = payInterfaceConfigService.selectAllPayIfConfigListByInfoId(CS.INFO_TYPE_ISV, getValStringRequired("isvNo")); + List list = payInterfaceConfigService.selectAllPayIfConfigListByIsvNo(CS.INFO_TYPE_ISV, getValStringRequired("isvNo")); return ApiRes.ok(list); } diff --git a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchAppController.java b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchAppController.java new file mode 100644 index 0000000..51865a1 --- /dev/null +++ b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchAppController.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com). + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jeequan.jeepay.mgr.ctrl.merchant; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.jeequan.jeepay.core.aop.MethodLog; +import com.jeequan.jeepay.core.constants.ApiCodeEnum; +import com.jeequan.jeepay.core.entity.MchApp; +import com.jeequan.jeepay.core.entity.MchInfo; +import com.jeequan.jeepay.core.entity.PayOrder; +import com.jeequan.jeepay.core.exception.BizException; +import com.jeequan.jeepay.core.model.ApiRes; +import com.jeequan.jeepay.mgr.ctrl.CommonCtrl; +import com.jeequan.jeepay.mgr.mq.queue.MqQueue4ModifyMchUserRemove; +import com.jeequan.jeepay.mgr.mq.topic.MqTopic4ModifyMchApp; +import com.jeequan.jeepay.service.impl.MchAppService; +import com.jeequan.jeepay.service.impl.MchInfoService; +import com.jeequan.jeepay.service.impl.PayOrderService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +/** + * 商户应用管理类 + * + * @author zhuxiao + * @site https://www.jeepay.vip + * @date 2021-06-16 09:15 + */ +@RestController +@RequestMapping("/api/mchApps") +public class MchAppController extends CommonCtrl { + + @Autowired private MchInfoService mchInfoService; + @Autowired private MchAppService mchAppService; + @Autowired private MqTopic4ModifyMchApp mqTopic4ModifyMchApp; + + /** + * @Author: ZhuXiao + * @Description: 应用列表 + * @Date: 9:59 2021/6/16 + */ + @PreAuthorize("hasAuthority('ENT_MCH_APP_LIST')") + @GetMapping + public ApiRes list() { + MchApp mchApp = getObject(MchApp.class); + + LambdaQueryWrapper wrapper = MchApp.gw(); + if (StringUtils.isNotEmpty(mchApp.getMchNo())) wrapper.eq(MchApp::getMchNo, mchApp.getMchNo()); + if (StringUtils.isNotEmpty(mchApp.getAppId())) wrapper.eq(MchApp::getAppId, mchApp.getAppId()); + if (StringUtils.isNotEmpty(mchApp.getAppName())) wrapper.eq(MchApp::getAppName, mchApp.getAppName()); + if (mchApp.getState() != null) wrapper.eq(MchApp::getState, mchApp.getState()); + wrapper.orderByDesc(MchApp::getCreatedAt); + + IPage pages = mchAppService.page(getIPage(), wrapper); + return ApiRes.ok(pages); + } + + /** + * @Author: ZhuXiao + * @Description: 新建应用 + * @Date: 10:05 2021/6/16 + */ + @PreAuthorize("hasAuthority('ENT_MCH_APP_ADD')") + @MethodLog(remark = "新建应用") + @PostMapping + public ApiRes add() { + MchApp mchApp = getObject(MchApp.class); + + if(mchInfoService.getById(mchApp.getMchNo()) == null) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); + } + + boolean result = mchAppService.save(mchApp); + if (!result) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_CREATE); + } + return ApiRes.ok(); + } + + /** + * @Author: ZhuXiao + * @Description: 应用详情 + * @Date: 10:13 2021/6/16 + */ + @PreAuthorize("hasAnyAuthority('ENT_MCH_APP_VIEW', 'ENT_MCH_APP_EDIT')") + @GetMapping("/{appId}") + public ApiRes detail(@PathVariable("appId") String appId) { + MchApp mchApp = mchAppService.getById(appId); + if (mchApp == null) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); + } + + return ApiRes.ok(mchApp); + } + + /** + * @Author: ZhuXiao + * @Description: 更新应用信息 + * @Date: 10:11 2021/6/16 + */ + @PreAuthorize("hasAuthority('ENT_MCH_APP_EDIT')") + @MethodLog(remark = "更新应用信息") + @PutMapping("/{appId}") + public ApiRes update(@PathVariable("appId") String appId) { + MchApp mchApp = getObject(MchApp.class); + mchApp.setAppId(appId); + boolean result = mchAppService.updateById(mchApp); + if (!result) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_UPDATE); + } + // 推送修改应用消息 + mqTopic4ModifyMchApp.push(mchApp.getMchNo(), mchApp.getAppId()); + return ApiRes.ok(); + } + + /** + * @Author: ZhuXiao + * @Description: 删除应用 + * @Date: 10:14 2021/6/16 + */ + @PreAuthorize("hasAuthority('ENT_MCH_APP_DEL')") + @MethodLog(remark = "删除应用") + @DeleteMapping("/{appId}") + public ApiRes delete(@PathVariable("appId") String appId) { + + MchApp mchApp = mchAppService.getById(appId); + mchAppService.removeByAppId(appId); + + // 推送mq到目前节点进行更新数据 + mqTopic4ModifyMchApp.push(mchApp.getMchNo(), appId); + return ApiRes.ok(); + } + +} diff --git a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchPayInterfaceConfigController.java b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchPayInterfaceConfigController.java index 67a7d78..d4b9066 100644 --- a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchPayInterfaceConfigController.java +++ b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchPayInterfaceConfigController.java @@ -18,11 +18,14 @@ package com.jeequan.jeepay.mgr.ctrl.merchant; import com.jeequan.jeepay.core.aop.MethodLog; import com.jeequan.jeepay.core.constants.ApiCodeEnum; import com.jeequan.jeepay.core.constants.CS; +import com.jeequan.jeepay.core.entity.MchApp; import com.jeequan.jeepay.core.entity.PayInterfaceConfig; import com.jeequan.jeepay.core.entity.PayInterfaceDefine; import com.jeequan.jeepay.core.model.ApiRes; import com.jeequan.jeepay.mgr.ctrl.CommonCtrl; +import com.jeequan.jeepay.mgr.mq.topic.MqTopic4ModifyMchApp; import com.jeequan.jeepay.mgr.mq.topic.MqTopic4ModifyMchInfo; +import com.jeequan.jeepay.service.impl.MchAppService; import com.jeequan.jeepay.service.impl.PayInterfaceConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -43,30 +46,31 @@ import java.util.List; public class MchPayInterfaceConfigController extends CommonCtrl { @Autowired private PayInterfaceConfigService payInterfaceConfigService; - @Autowired private MqTopic4ModifyMchInfo mqTopic4ModifyMchInfo; + @Autowired private MqTopic4ModifyMchApp mqTopic4ModifyMchApp; + @Autowired private MchAppService mchAppService; /** * @Author: ZhuXiao - * @Description: 查询商户支付接口配置列表 + * @Description: 查询应用支付接口配置列表 * @Date: 15:50 2021/4/27 */ @PreAuthorize("hasAuthority('ENT_MCH_PAY_CONFIG_LIST')") @GetMapping public ApiRes list() { - List list = payInterfaceConfigService.selectAllPayIfConfigListByInfoId(CS.INFO_TYPE_MCH, getValStringRequired("mchNo")); + List list = payInterfaceConfigService.selectAllPayIfConfigListByAppId(getValStringRequired("appId")); return ApiRes.ok(list); } /** * @Author: ZhuXiao - * @Description: 根据 商户号、接口类型 获取商户参数配置 + * @Description: 根据 appId、接口类型 获取应用参数配置 * @Date: 17:03 2021/4/27 */ @PreAuthorize("hasAuthority('ENT_MCH_PAY_CONFIG_VIEW')") - @GetMapping("/{mchNo}/{ifCode}") - public ApiRes getByMchNo(@PathVariable(value = "mchNo") String mchNo, @PathVariable(value = "ifCode") String ifCode) { - PayInterfaceConfig payInterfaceConfig = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH, mchNo, ifCode); + @GetMapping("/{appId}/{ifCode}") + public ApiRes getByAppId(@PathVariable(value = "appId") String appId, @PathVariable(value = "ifCode") String ifCode) { + PayInterfaceConfig payInterfaceConfig = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH_APP, appId, ifCode); if (payInterfaceConfig != null && payInterfaceConfig.getIfRate() != null) { payInterfaceConfig.setIfRate(payInterfaceConfig.getIfRate().multiply(new BigDecimal("100"))); } @@ -75,19 +79,25 @@ public class MchPayInterfaceConfigController extends CommonCtrl { /** * @Author: ZhuXiao - * @Description: 商户支付接口配置 + * @Description: 应用支付接口配置 * @Date: 16:13 2021/4/27 */ @PreAuthorize("hasAuthority('ENT_MCH_PAY_CONFIG_ADD')") @PostMapping - @MethodLog(remark = "更新商户支付参数") + @MethodLog(remark = "更新应用支付参数") public ApiRes saveOrUpdate() { String infoId = getValStringRequired("infoId"); String ifCode = getValStringRequired("ifCode"); + MchApp mchApp = mchAppService.getById(infoId); + if (mchApp == null || mchApp.getState() != CS.YES) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); + } + PayInterfaceConfig payInterfaceConfig = getObject(PayInterfaceConfig.class); - payInterfaceConfig.setInfoType(CS.INFO_TYPE_MCH); + payInterfaceConfig.setInfoType(CS.INFO_TYPE_MCH_APP); + payInterfaceConfig.setInfoId(infoId); // 存入真实费率 if (payInterfaceConfig.getIfRate() != null) { @@ -101,7 +111,7 @@ public class MchPayInterfaceConfigController extends CommonCtrl { payInterfaceConfig.setUpdatedBy(realName); //根据 商户号、接口类型 获取商户参数配置 - PayInterfaceConfig dbRecoed = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH, infoId, ifCode); + PayInterfaceConfig dbRecoed = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH_APP, infoId, ifCode); //若配置存在,为saveOrUpdate添加ID,第一次配置添加创建者 if (dbRecoed != null) { payInterfaceConfig.setId(dbRecoed.getId()); @@ -115,7 +125,7 @@ public class MchPayInterfaceConfigController extends CommonCtrl { return ApiRes.fail(ApiCodeEnum.SYSTEM_ERROR, "配置失败"); } - mqTopic4ModifyMchInfo.push(infoId); // 推送mq到目前节点进行更新数据 + mqTopic4ModifyMchApp.push(mchApp.getMchNo(), infoId); // 推送mq到目前节点进行更新数据 return ApiRes.ok(); } diff --git a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchPayPassageConfigController.java b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchPayPassageConfigController.java index 92bee72..f7fc672 100644 --- a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchPayPassageConfigController.java +++ b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/merchant/MchPayPassageConfigController.java @@ -23,16 +23,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.jeequan.jeepay.core.aop.MethodLog; import com.jeequan.jeepay.core.constants.ApiCodeEnum; import com.jeequan.jeepay.core.constants.CS; -import com.jeequan.jeepay.core.entity.MchInfo; -import com.jeequan.jeepay.core.entity.MchPayPassage; -import com.jeequan.jeepay.core.entity.PayInterfaceConfig; -import com.jeequan.jeepay.core.entity.PayWay; +import com.jeequan.jeepay.core.entity.*; +import com.jeequan.jeepay.core.exception.BizException; import com.jeequan.jeepay.core.model.ApiRes; import com.jeequan.jeepay.mgr.ctrl.CommonCtrl; -import com.jeequan.jeepay.service.impl.MchInfoService; -import com.jeequan.jeepay.service.impl.MchPayPassageService; -import com.jeequan.jeepay.service.impl.PayInterfaceConfigService; -import com.jeequan.jeepay.service.impl.PayWayService; +import com.jeequan.jeepay.service.impl.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.CollectionUtils; @@ -54,9 +49,9 @@ import java.util.List; public class MchPayPassageConfigController extends CommonCtrl { @Autowired private MchPayPassageService mchPayPassageService; - @Autowired private PayInterfaceConfigService payInterfaceConfigService; @Autowired private PayWayService payWayService; @Autowired private MchInfoService mchInfoService; + @Autowired private MchAppService mchAppService; /** @@ -68,7 +63,7 @@ public class MchPayPassageConfigController extends CommonCtrl { @GetMapping public ApiRes list() { - String mchNo = getValStringRequired("mchNo"); + String appId = getValStringRequired("appId"); String wayCode = getValString("wayCode"); String wayName = getValString("wayName"); @@ -84,10 +79,10 @@ public class MchPayPassageConfigController extends CommonCtrl { List wayCodeList = new LinkedList<>(); payWayPage.getRecords().stream().forEach(payWay -> wayCodeList.add(payWay.getWayCode())); - // 商户支付通道集合 + // 应用支付通道集合 List mchPayPassageList = mchPayPassageService.list(MchPayPassage.gw() .select(MchPayPassage::getWayCode, MchPayPassage::getState) - .eq(MchPayPassage::getMchNo, mchNo) + .eq(MchPayPassage::getAppId, appId) .in(MchPayPassage::getWayCode, wayCodeList)); for (PayWay payWay : payWayPage.getRecords()) { @@ -107,41 +102,32 @@ public class MchPayPassageConfigController extends CommonCtrl { /** * @Author: ZhuXiao - * @Description: 根据商户号、支付方式查询可用的支付接口列表 + * @Description: 根据appId、支付方式查询可用的支付接口列表 * @Date: 17:55 2021/5/8 */ @PreAuthorize("hasAuthority('ENT_MCH_PAY_PASSAGE_CONFIG')") - @GetMapping("/availablePayInterface/{mchNo}/{wayCode}") - public ApiRes availablePayInterface(@PathVariable("mchNo") String mchNo, @PathVariable("wayCode") String wayCode) { + @GetMapping("/availablePayInterface/{appId}/{wayCode}") + public ApiRes availablePayInterface(@PathVariable("appId") String appId, @PathVariable("wayCode") String wayCode) { - MchInfo mchInfo = mchInfoService.getById(mchNo); + MchApp mchApp = mchAppService.getById(appId); + if (mchApp == null || mchApp.getState() != CS.YES) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); + } + + MchInfo mchInfo = mchInfoService.getById(mchApp.getMchNo()); if (mchInfo == null || mchInfo.getState() != CS.YES) { return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); } // 根据支付方式查询可用支付接口列表 - List list = mchPayPassageService.selectAvailablePayInterfaceList(wayCode, mchNo, CS.INFO_TYPE_MCH, mchInfo.getType()); + List list = mchPayPassageService.selectAvailablePayInterfaceList(wayCode, appId, CS.INFO_TYPE_MCH_APP, mchInfo.getType()); return ApiRes.ok(list); } /** * @Author: ZhuXiao - * @Description: 根据 商户号、接口类型 获取商户参数配置 - * @Date: 17:03 2021/4/27 - */ - @GetMapping("/{mchNo}/{ifCode}") - public ApiRes getByMchNo(@PathVariable(value = "mchNo") String mchNo, @PathVariable(value = "ifCode") String ifCode) { - PayInterfaceConfig payInterfaceConfig = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH, mchNo, ifCode); - if (payInterfaceConfig != null && payInterfaceConfig.getIfRate() != null) { - payInterfaceConfig.setIfRate(payInterfaceConfig.getIfRate().multiply(new BigDecimal("100"))); - } - return ApiRes.ok(payInterfaceConfig); - } - - /** - * @Author: ZhuXiao - * @Description: 商户支付通道配置 + * @Description: 应用支付通道配置 * @Date: 17:36 2021/5/8 */ @PreAuthorize("hasAuthority('ENT_MCH_PAY_PASSAGE_ADD')") @@ -153,7 +139,15 @@ public class MchPayPassageConfigController extends CommonCtrl { try { List mchPayPassageList = JSONArray.parseArray(reqParams, MchPayPassage.class); - mchPayPassageService.saveOrUpdateBatchSelf(mchPayPassageList); + if (CollectionUtils.isEmpty(mchPayPassageList)) { + throw new BizException("操作失败"); + } + MchApp mchApp = mchAppService.getById(mchPayPassageList.get(0).getAppId()); + if (mchApp == null || mchApp.getState() != CS.YES) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); + } + + mchPayPassageService.saveOrUpdateBatchSelf(mchPayPassageList, mchApp.getMchNo()); return ApiRes.ok(); }catch (Exception e) { return ApiRes.fail(ApiCodeEnum.SYSTEM_ERROR); diff --git a/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchAppController.java b/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchAppController.java new file mode 100644 index 0000000..c655660 --- /dev/null +++ b/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchAppController.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com). + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jeequan.jeepay.mch.ctrl.merchant; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.jeequan.jeepay.core.aop.MethodLog; +import com.jeequan.jeepay.core.constants.ApiCodeEnum; +import com.jeequan.jeepay.core.entity.MchApp; +import com.jeequan.jeepay.core.exception.BizException; +import com.jeequan.jeepay.core.model.ApiRes; +import com.jeequan.jeepay.mch.ctrl.CommonCtrl; +import com.jeequan.jeepay.mch.mq.topic.MqTopic4ModifyMchApp; +import com.jeequan.jeepay.service.impl.MchAppService; +import com.jeequan.jeepay.service.impl.MchInfoService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +/** + * 商户应用管理类 + * + * @author zhuxiao + * @site https://www.jeepay.vip + * @date 2021-06-16 09:15 + */ +@RestController +@RequestMapping("/api/mchApps") +public class MchAppController extends CommonCtrl { + + @Autowired private MchAppService mchAppService; + @Autowired private MqTopic4ModifyMchApp mqTopic4ModifyMchApp; + + /** + * @Author: ZhuXiao + * @Description: 应用列表 + * @Date: 9:59 2021/6/16 + */ + @PreAuthorize("hasAuthority('ENT_MCH_APP_LIST')") + @GetMapping + public ApiRes list() { + MchApp mchApp = getObject(MchApp.class); + + LambdaQueryWrapper wrapper = MchApp.gw(); + wrapper.eq(MchApp::getMchNo, getCurrentMchNo()); + if (StringUtils.isNotEmpty(mchApp.getAppId())) wrapper.eq(MchApp::getAppId, mchApp.getAppId()); + if (StringUtils.isNotEmpty(mchApp.getAppName())) wrapper.eq(MchApp::getAppName, mchApp.getAppName()); + if (mchApp.getState() != null) wrapper.eq(MchApp::getState, mchApp.getState()); + wrapper.orderByDesc(MchApp::getCreatedAt); + + IPage pages = mchAppService.page(getIPage(), wrapper); + return ApiRes.ok(pages); + } + + /** + * @Author: ZhuXiao + * @Description: 新建应用 + * @Date: 10:05 2021/6/16 + */ + @PreAuthorize("hasAuthority('ENT_MCH_APP_ADD')") + @MethodLog(remark = "新建应用") + @PostMapping + public ApiRes add() { + MchApp mchApp = getObject(MchApp.class); + mchApp.setMchNo(getCurrentMchNo()); + + boolean result = mchAppService.save(mchApp); + if (!result) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_CREATE); + } + return ApiRes.ok(); + } + + /** + * @Author: ZhuXiao + * @Description: 应用详情 + * @Date: 10:13 2021/6/16 + */ + @PreAuthorize("hasAnyAuthority('ENT_MCH_APP_VIEW', 'ENT_MCH_APP_EDIT')") + @GetMapping("/{appId}") + public ApiRes detail(@PathVariable("appId") String appId) { + MchApp mchApp = mchAppService.getById(appId); + + if (mchApp == null || !mchApp.getMchNo().equals(getCurrentMchNo())) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); + } + + return ApiRes.ok(mchApp); + } + + /** + * @Author: ZhuXiao + * @Description: 更新应用信息 + * @Date: 10:11 2021/6/16 + */ + @PreAuthorize("hasAuthority('ENT_MCH_APP_EDIT')") + @MethodLog(remark = "更新应用信息") + @PutMapping("/{appId}") + public ApiRes update(@PathVariable("appId") String appId) { + MchApp mchApp = getObject(MchApp.class); + mchApp.setAppId(appId); + + MchApp dbRecord = mchAppService.getById(appId); + if (!dbRecord.getMchNo().equals(getCurrentMchNo())) { + throw new BizException("无权操作!"); + } + + boolean result = mchAppService.updateById(mchApp); + if (!result) { + return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_UPDATE); + } + // 推送修改应用消息 + mqTopic4ModifyMchApp.push(getCurrentMchNo(), mchApp.getAppId()); + return ApiRes.ok(); + } + + /** + * @Author: ZhuXiao + * @Description: 删除应用 + * @Date: 10:14 2021/6/16 + */ + @PreAuthorize("hasAuthority('ENT_MCH_APP_DEL')") + @MethodLog(remark = "删除应用") + @DeleteMapping("/{appId}") + public ApiRes delete(@PathVariable("appId") String appId) { + MchApp mchApp = mchAppService.getById(appId); + + if (!mchApp.getMchNo().equals(getCurrentMchNo())) { + throw new BizException("无权操作!"); + } + + mchAppService.removeByAppId(appId); + + // 推送mq到目前节点进行更新数据 + mqTopic4ModifyMchApp.push(getCurrentMchNo(), appId); + return ApiRes.ok(); + } + +} diff --git a/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchPayInterfaceConfigController.java b/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchPayInterfaceConfigController.java index e1d1b12..15aa228 100644 --- a/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchPayInterfaceConfigController.java +++ b/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchPayInterfaceConfigController.java @@ -23,6 +23,7 @@ import com.jeequan.jeepay.core.entity.PayInterfaceDefine; import com.jeequan.jeepay.core.exception.BizException; import com.jeequan.jeepay.core.model.ApiRes; import com.jeequan.jeepay.mch.ctrl.CommonCtrl; +import com.jeequan.jeepay.mch.mq.topic.MqTopic4ModifyMchApp; import com.jeequan.jeepay.service.impl.MchInfoService; import com.jeequan.jeepay.service.impl.PayInterfaceConfigService; import org.springframework.beans.factory.annotation.Autowired; @@ -44,6 +45,7 @@ import java.util.List; public class MchPayInterfaceConfigController extends CommonCtrl { @Autowired private PayInterfaceConfigService payInterfaceConfigService; + @Autowired private MqTopic4ModifyMchApp mqTopic4ModifyMchApp; @Autowired private MchInfoService mchInfoService; /** @@ -55,7 +57,7 @@ public class MchPayInterfaceConfigController extends CommonCtrl { @GetMapping public ApiRes list() { MchInfo mchInfo = mchInfoService.getById(getCurrentUser().getSysUser().getBelongInfoId()); - List list = payInterfaceConfigService.selectAllPayIfConfigListByInfoId(CS.INFO_TYPE_MCH, getCurrentUser().getSysUser().getBelongInfoId()); + List list = payInterfaceConfigService.selectAllPayIfConfigListByAppId(getValStringRequired("appId")); for (PayInterfaceDefine define : list) { define.addExt("mchParams", mchInfo.getType() == CS.MCH_TYPE_NORMAL ? define.getNormalMchParams() : define.getIsvsubMchParams()); @@ -71,9 +73,9 @@ public class MchPayInterfaceConfigController extends CommonCtrl { * @Date: 10:54 2021/5/13 */ @PreAuthorize("hasAuthority('ENT_MCH_PAY_CONFIG_VIEW')") - @GetMapping("/{ifCode}") - public ApiRes getByMchNo(@PathVariable(value = "ifCode") String ifCode) { - PayInterfaceConfig payInterfaceConfig = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH, getCurrentUser().getSysUser().getBelongInfoId(), ifCode); + @GetMapping("/{appId}/{ifCode}") + public ApiRes getByMchNo(@PathVariable(value = "appId") String appId, @PathVariable(value = "ifCode") String ifCode) { + PayInterfaceConfig payInterfaceConfig = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH_APP, appId, ifCode); if (payInterfaceConfig != null && payInterfaceConfig.getIfRate() != null) { payInterfaceConfig.setIfRate(payInterfaceConfig.getIfRate().multiply(new BigDecimal("100"))); } @@ -90,12 +92,12 @@ public class MchPayInterfaceConfigController extends CommonCtrl { @MethodLog(remark = "更新商户支付参数") public ApiRes saveOrUpdate() { - String mchNo = getCurrentUser().getSysUser().getBelongInfoId(); String ifCode = getValStringRequired("ifCode"); + String infoId = getValStringRequired("infoId"); PayInterfaceConfig payInterfaceConfig = getObject(PayInterfaceConfig.class); - payInterfaceConfig.setInfoType(CS.INFO_TYPE_MCH); - payInterfaceConfig.setInfoId(mchNo); + payInterfaceConfig.setInfoType(CS.INFO_TYPE_MCH_APP); + payInterfaceConfig.setInfoId(infoId); // 存入真实费率 if (payInterfaceConfig.getIfRate() != null) { @@ -109,7 +111,7 @@ public class MchPayInterfaceConfigController extends CommonCtrl { payInterfaceConfig.setUpdatedBy(realName); //根据 商户号、接口类型 获取商户参数配置 - PayInterfaceConfig dbRecoed = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH, mchNo, ifCode); + PayInterfaceConfig dbRecoed = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH_APP, infoId, ifCode); //若配置存在,为saveOrUpdate添加ID,第一次配置添加创建者 if (dbRecoed != null) { payInterfaceConfig.setId(dbRecoed.getId()); @@ -122,6 +124,9 @@ public class MchPayInterfaceConfigController extends CommonCtrl { if (!result) { throw new BizException("配置失败"); } + + mqTopic4ModifyMchApp.push(getCurrentMchNo(), infoId); // 推送mq到目前节点进行更新数据 + return ApiRes.ok(); } diff --git a/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchPayPassageConfigController.java b/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchPayPassageConfigController.java index 0263011..d7551a9 100644 --- a/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchPayPassageConfigController.java +++ b/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/ctrl/merchant/MchPayPassageConfigController.java @@ -25,13 +25,11 @@ import com.jeequan.jeepay.core.constants.ApiCodeEnum; import com.jeequan.jeepay.core.constants.CS; import com.jeequan.jeepay.core.entity.MchInfo; import com.jeequan.jeepay.core.entity.MchPayPassage; -import com.jeequan.jeepay.core.entity.PayInterfaceConfig; import com.jeequan.jeepay.core.entity.PayWay; import com.jeequan.jeepay.core.model.ApiRes; import com.jeequan.jeepay.mch.ctrl.CommonCtrl; import com.jeequan.jeepay.service.impl.MchInfoService; import com.jeequan.jeepay.service.impl.MchPayPassageService; -import com.jeequan.jeepay.service.impl.PayInterfaceConfigService; import com.jeequan.jeepay.service.impl.PayWayService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -54,7 +52,6 @@ import java.util.List; public class MchPayPassageConfigController extends CommonCtrl { @Autowired private MchPayPassageService mchPayPassageService; - @Autowired private PayInterfaceConfigService payInterfaceConfigService; @Autowired private PayWayService payWayService; @Autowired private MchInfoService mchInfoService; @@ -67,14 +64,14 @@ public class MchPayPassageConfigController extends CommonCtrl { @GetMapping public ApiRes list() { - String mchNo = getCurrentUser().getSysUser().getBelongInfoId(); + String appId = getValStringRequired("appId"); String wayCode = getValString("wayCode"); String wayName = getValString("wayName"); //支付方式集合 LambdaQueryWrapper wrapper = PayWay.gw(); if (StrUtil.isNotBlank(wayCode)) wrapper.eq(PayWay::getWayCode, wayCode); - if (StrUtil.isNotBlank(wayName)) wrapper.like(PayWay::getWayName, "%" + wayName + "%"); + if (StrUtil.isNotBlank(wayName)) wrapper.like(PayWay::getWayName, wayName); IPage payWayPage = payWayService.page(getIPage(), wrapper); if (!CollectionUtils.isEmpty(payWayPage.getRecords())) { @@ -86,7 +83,8 @@ public class MchPayPassageConfigController extends CommonCtrl { // 商户支付通道集合 List mchPayPassageList = mchPayPassageService.list(MchPayPassage.gw() .select(MchPayPassage::getWayCode, MchPayPassage::getState) - .eq(MchPayPassage::getMchNo, mchNo) + .eq(MchPayPassage::getAppId, appId) + .eq(MchPayPassage::getMchNo, getCurrentMchNo()) .in(MchPayPassage::getWayCode, wayCodeList)); for (PayWay payWay : payWayPage.getRecords()) { @@ -106,12 +104,12 @@ public class MchPayPassageConfigController extends CommonCtrl { /** * @Author: ZhuXiao - * @Description: 根据商户号、支付方式查询可用的支付接口列表 + * @Description: 根据appId、支付方式查询可用的支付接口列表 * @Date: 11:05 2021/5/13 */ @PreAuthorize("hasAuthority('ENT_MCH_PAY_PASSAGE_CONFIG')") - @GetMapping("/availablePayInterface/{wayCode}") - public ApiRes availablePayInterface(@PathVariable("wayCode") String wayCode) { + @GetMapping("/availablePayInterface/{appId}/{wayCode}") + public ApiRes availablePayInterface(@PathVariable("appId") String appId, @PathVariable("wayCode") String wayCode) { String mchNo = getCurrentUser().getSysUser().getBelongInfoId(); MchInfo mchInfo = mchInfoService.getById(mchNo); @@ -120,26 +118,11 @@ public class MchPayPassageConfigController extends CommonCtrl { } // 根据支付方式查询可用支付接口列表 - List list = mchPayPassageService.selectAvailablePayInterfaceList(wayCode, mchNo, CS.INFO_TYPE_MCH, mchInfo.getType()); + List list = mchPayPassageService.selectAvailablePayInterfaceList(wayCode, appId, CS.INFO_TYPE_MCH_APP, mchInfo.getType()); return ApiRes.ok(list); } - /** - * @Author: ZhuXiao - * @Description: 根据 商户号、接口类型 获取商户参数配置 - * @Date: 11:05 2021/5/13 - */ - @GetMapping("/{ifCode}") - public ApiRes getByMchNo(@PathVariable(value = "ifCode") String ifCode) { - String mchNo = getCurrentUser().getSysUser().getBelongInfoId(); - PayInterfaceConfig payInterfaceConfig = payInterfaceConfigService.getByInfoIdAndIfCode(CS.INFO_TYPE_MCH, mchNo, ifCode); - if (payInterfaceConfig != null && payInterfaceConfig.getIfRate() != null) { - payInterfaceConfig.setIfRate(payInterfaceConfig.getIfRate().multiply(new BigDecimal("100"))); - } - return ApiRes.ok(payInterfaceConfig); - } - /** * @Author: ZhuXiao * @Description: @@ -156,19 +139,19 @@ public class MchPayPassageConfigController extends CommonCtrl { /** * @Author: ZhuXiao - * @Description: 商户支付通道配置 + * @Description: 应用支付通道配置 * @Date: 11:05 2021/5/13 */ @PreAuthorize("hasAuthority('ENT_MCH_PAY_PASSAGE_ADD')") @PostMapping - @MethodLog(remark = "更新商户支付通道") + @MethodLog(remark = "更新应用支付通道") public ApiRes saveOrUpdate() { String reqParams = getValStringRequired("reqParams"); try { List mchPayPassageList = JSONArray.parseArray(reqParams, MchPayPassage.class); - mchPayPassageService.saveOrUpdateBatchSelf(mchPayPassageList, getCurrentUser().getSysUser().getBelongInfoId()); + mchPayPassageService.saveOrUpdateBatchSelf(mchPayPassageList, getCurrentMchNo()); return ApiRes.ok(); }catch (Exception e) { return ApiRes.fail(ApiCodeEnum.SYSTEM_ERROR); diff --git a/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/mq/topic/MqTopic4ModifyMchApp.java b/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/mq/topic/MqTopic4ModifyMchApp.java new file mode 100644 index 0000000..3ff16ce --- /dev/null +++ b/jeepay-merchant/src/main/java/com/jeequan/jeepay/mch/mq/topic/MqTopic4ModifyMchApp.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com). + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jeequan.jeepay.mch.mq.topic; + +import com.alibaba.fastjson.JSONObject; +import com.jeequan.jeepay.core.constants.CS; +import com.jeequan.jeepay.core.utils.JsonKit; +import lombok.extern.slf4j.Slf4j; +import org.apache.activemq.command.ActiveMQTopic; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jms.core.JmsTemplate; +import org.springframework.stereotype.Component; + +/* +* 更改商户应用信息 +* +* @author terrfly +* @site https://www.jeepay.vip +* @date 2021/6/8 17:10 +*/ +@Slf4j +@Component +public class MqTopic4ModifyMchApp extends ActiveMQTopic{ + + @Autowired private JmsTemplate jmsTemplate; + + public MqTopic4ModifyMchApp(){ + super(CS.MQ.TOPIC_MODIFY_MCH_APP); + } + + /** 推送消息到各个节点 **/ + public void push(String mchNo, String appId) { + JSONObject jsonObject = JsonKit.newJson("mchNo", mchNo); + jsonObject.put("appId", appId); + + this.jmsTemplate.convertAndSend(this, jsonObject.toString()); + } + +} diff --git a/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchAppService.java b/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchAppService.java index 729df7c..efc2186 100644 --- a/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchAppService.java +++ b/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchAppService.java @@ -1,9 +1,17 @@ package com.jeequan.jeepay.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.jeequan.jeepay.core.constants.ApiCodeEnum; +import com.jeequan.jeepay.core.constants.CS; import com.jeequan.jeepay.core.entity.MchApp; +import com.jeequan.jeepay.core.entity.MchPayPassage; +import com.jeequan.jeepay.core.entity.PayInterfaceConfig; +import com.jeequan.jeepay.core.entity.PayOrder; +import com.jeequan.jeepay.core.exception.BizException; import com.jeequan.jeepay.service.mapper.MchAppMapper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; /** *

@@ -16,4 +24,36 @@ import org.springframework.stereotype.Service; @Service public class MchAppService extends ServiceImpl { + @Autowired private PayOrderService payOrderService; + @Autowired private MchPayPassageService mchPayPassageService; + @Autowired private PayInterfaceConfigService payInterfaceConfigService; + + @Transactional(rollbackFor = Exception.class) + public void removeByAppId(String appId) { + + // 1.查看当前应用是否存在交易数据 + int payCount = payOrderService.count(PayOrder.gw().eq(PayOrder::getAppId, appId)); + if (payCount > 0) throw new BizException("该应用已存在交易数据,不可删除"); + + // 2.删除应用关联的支付通道 + boolean result = mchPayPassageService.remove(MchPayPassage.gw().eq(MchPayPassage::getAppId, appId)); + if (!result) { + throw new BizException(ApiCodeEnum.SYS_OPERATION_FAIL_DELETE); + } + + // 3.删除应用配置的支付参数 + result = payInterfaceConfigService.remove(PayInterfaceConfig.gw() + .eq(PayInterfaceConfig::getInfoId, appId) + .eq(PayInterfaceConfig::getInfoType, CS.INFO_TYPE_MCH_APP) + ); + if (!result) { + throw new BizException(ApiCodeEnum.SYS_OPERATION_FAIL_DELETE); + } + + // 4.删除当前应用 + result = removeById(appId); + if (!result) { + throw new BizException(ApiCodeEnum.SYS_OPERATION_FAIL_DELETE); + } + } } diff --git a/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchInfoService.java b/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchInfoService.java index 13f8152..0c1345e 100644 --- a/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchInfoService.java +++ b/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchInfoService.java @@ -29,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; /** @@ -54,6 +55,8 @@ public class MchInfoService extends ServiceImpl { @Autowired private IsvInfoService isvInfoService; + @Autowired private MchAppService mchAppService; + @Transactional(rollbackFor = Exception.class) public void addMch(MchInfo mchInfo, String loginUserName) { @@ -104,9 +107,11 @@ public class MchInfoService extends ServiceImpl { mchPayPassageService.remove(MchPayPassage.gw().eq(MchPayPassage::getMchNo, mchNo)); // 3.删除当前商户支付接口配置参数 + List appIdList = new LinkedList<>(); + mchAppService.list(MchApp.gw().eq(MchApp::getMchNo, mchNo)).forEach(item -> appIdList.add(item.getAppId())); payInterfaceConfigService.remove(PayInterfaceConfig.gw() - .eq(PayInterfaceConfig::getInfoId, mchNo) - .eq(PayInterfaceConfig::getInfoType, CS.INFO_TYPE_MCH) + .in(PayInterfaceConfig::getInfoId, appIdList) + .eq(PayInterfaceConfig::getInfoType, CS.INFO_TYPE_MCH_APP) ); List userList = sysUserService.list(SysUser.gw() diff --git a/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchPayPassageService.java b/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchPayPassageService.java index 13fe93e..cc2861a 100644 --- a/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchPayPassageService.java +++ b/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/MchPayPassageService.java @@ -47,10 +47,10 @@ public class MchPayPassageService extends ServiceImpl selectAvailablePayInterfaceList(String wayCode, String mchNo, Byte infoType, Byte mchType) { + public List selectAvailablePayInterfaceList(String wayCode, String appId, Byte infoType, Byte mchType) { Map params = new HashMap(); params.put("wayCode", wayCode); - params.put("mchNo", mchNo); + params.put("appId", appId); params.put("infoType", infoType); params.put("mchType", mchType); List list = baseMapper.selectAvailablePayInterfaceList(params); @@ -59,7 +59,7 @@ public class MchPayPassageService extends ServiceImpl mchPayPassageList) { - saveOrUpdateBatchSelf(mchPayPassageList, null); - } - @Transactional(rollbackFor = Exception.class) public void saveOrUpdateBatchSelf(List mchPayPassageList, String mchNo) { - if (CollectionUtils.isEmpty(mchPayPassageList)) { - throw new BizException("操作失败"); - } for (MchPayPassage payPassage : mchPayPassageList) { if (payPassage.getState() == CS.NO && payPassage.getId() == null) { continue; diff --git a/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/PayInterfaceConfigService.java b/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/PayInterfaceConfigService.java index 9e14809..29e5b88 100644 --- a/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/PayInterfaceConfigService.java +++ b/jeepay-service/src/main/java/com/jeequan/jeepay/service/impl/PayInterfaceConfigService.java @@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jeequan.jeepay.core.constants.ApiCodeEnum; import com.jeequan.jeepay.core.constants.CS; +import com.jeequan.jeepay.core.entity.MchApp; import com.jeequan.jeepay.core.entity.MchInfo; import com.jeequan.jeepay.core.entity.PayInterfaceConfig; import com.jeequan.jeepay.core.entity.PayInterfaceDefine; @@ -48,6 +49,9 @@ public class PayInterfaceConfigService extends ServiceImpl selectAllPayIfConfigListByInfoId(Byte infoType, String infoId) { + public List selectAllPayIfConfigListByIsvNo(Byte infoType, String infoId) { // 支付定义列表 LambdaQueryWrapper queryWrapper = PayInterfaceDefine.gw(); queryWrapper.eq(PayInterfaceDefine::getState, CS.YES); - - // 根据商户类型,添加接口是否支持该商户类型条件 - MchInfo mchInfo = null; - Map isvPayConfigMap = new HashMap<>(); // 服务商支付参数配置集合 - if (infoType == CS.INFO_TYPE_MCH) { - //商户信息 - mchInfo = mchInfoService.getById(infoId); - if (mchInfo == null || mchInfo.getState() != CS.YES) throw new BizException(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); - - if (mchInfo.getType() == CS.MCH_TYPE_NORMAL) { - queryWrapper.eq(PayInterfaceDefine::getIsMchMode, CS.YES); // 支持普通商户模式 - } - if (mchInfo.getType() == CS.MCH_TYPE_ISVSUB) { - queryWrapper.eq(PayInterfaceDefine::getIsIsvMode, CS.YES); // 支持服务商模式 - // 商户类型为特约商户,服务商应已经配置支付参数 - List isvConfigList = this.list(PayInterfaceConfig.gw() - .eq(PayInterfaceConfig::getInfoId, mchInfo.getIsvNo()) - .eq(PayInterfaceConfig::getInfoType, CS.INFO_TYPE_ISV) - .eq(PayInterfaceConfig::getState, CS.YES) - .ne(PayInterfaceConfig::getIfParams, " ") - .isNotNull(PayInterfaceConfig::getIfParams)); - - for (PayInterfaceConfig config : isvConfigList) { - isvPayConfigMap.put(config.getIfCode(), config); - } - } - } - if (infoType == CS.INFO_TYPE_ISV) { - queryWrapper.eq(PayInterfaceDefine::getIsIsvMode, CS.YES); // 支持服务商模式 - } + queryWrapper.eq(PayInterfaceDefine::getIsIsvMode, CS.YES); // 支持服务商模式 List defineList = payInterfaceDefineService.list(queryWrapper); @@ -116,13 +91,67 @@ public class PayInterfaceConfigService extends ServiceImpl selectAllPayIfConfigListByAppId(String appId) { + + MchApp mchApp = mchAppService.getById(appId); + if (mchApp == null|| mchApp.getState() != CS.YES) { + throw new BizException(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); + } + MchInfo mchInfo = mchInfoService.getById(mchApp.getMchNo()); + if (mchInfo == null || mchInfo.getState() != CS.YES) { + throw new BizException(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); + } + // 支付定义列表 + LambdaQueryWrapper queryWrapper = PayInterfaceDefine.gw(); + queryWrapper.eq(PayInterfaceDefine::getState, CS.YES); + + Map isvPayConfigMap = new HashMap<>(); // 服务商支付参数配置集合 + + // 根据商户类型,添加接口是否支持该商户类型条件 + if (mchInfo.getType() == CS.MCH_TYPE_NORMAL) { + queryWrapper.eq(PayInterfaceDefine::getIsMchMode, CS.YES); // 支持普通商户模式 + } + if (mchInfo.getType() == CS.MCH_TYPE_ISVSUB) { + queryWrapper.eq(PayInterfaceDefine::getIsIsvMode, CS.YES); // 支持服务商模式 + // 商户类型为特约商户,服务商应已经配置支付参数 + List isvConfigList = this.list(PayInterfaceConfig.gw() + .eq(PayInterfaceConfig::getInfoId, mchInfo.getIsvNo()) + .eq(PayInterfaceConfig::getInfoType, CS.INFO_TYPE_ISV) + .eq(PayInterfaceConfig::getState, CS.YES) + .ne(PayInterfaceConfig::getIfParams, "") + .isNotNull(PayInterfaceConfig::getIfParams)); + + for (PayInterfaceConfig config : isvConfigList) { + isvPayConfigMap.put(config.getIfCode(), config); + } + } + + List defineList = payInterfaceDefineService.list(queryWrapper); + + // 支付参数列表 + LambdaQueryWrapper wrapper = PayInterfaceConfig.gw(); + wrapper.eq(PayInterfaceConfig::getInfoId, appId); + wrapper.eq(PayInterfaceConfig::getInfoType, CS.INFO_TYPE_MCH_APP); + List configList = this.list(wrapper); + + for (PayInterfaceDefine define : defineList) { + define.addExt("mchType", mchInfo.getType()); // 所属商户类型 + + for (PayInterfaceConfig config : configList) { + if (define.getIfCode().equals(config.getIfCode())) { + define.addExt("ifConfigState", config.getState()); // 配置状态 + } + } + + if (mchInfo.getType() == CS.MCH_TYPE_ISVSUB && isvPayConfigMap.get(define.getIfCode()) == null) { + define.addExt("subMchIsvConfig", CS.NO); // 特约商户,服务商支付参数的配置状态,0表示未配置 + } + } + return defineList; + } } diff --git a/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchPayPassageMapper.xml b/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchPayPassageMapper.xml index e5e0f56..51b68ae 100644 --- a/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchPayPassageMapper.xml +++ b/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchPayPassageMapper.xml @@ -24,7 +24,7 @@ and pid.state = 1 and pic.state = 1 and pic.info_type = #{infoType} - and pic.info_id = #{mchNo} + and pic.info_id = #{appId} and (pic.if_params is not null and trim(pic.if_params) != '') and pid.is_mch_mode = 1