From 0b9a27b37cd49ff087541b87bad87b0f9af9e698 Mon Sep 17 00:00:00 2001 From: terrfly Date: Mon, 21 Jun 2021 18:04:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=9C=80=E5=A4=A7=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=AC=A1=E6=95=B0=E6=94=BE=E7=BD=AE=E5=88=B0DB,=20=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=95=86=E6=88=B7=E6=B6=88=E6=81=AF=E9=87=8D=E5=8F=91?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/sql/init.sql | 2 + .../jeepay/core/entity/MchNotifyRecord.java | 5 ++ .../mgr/ctrl/order/MchNotifyController.java | 25 ++++++++++ .../mq/queue/MqQueue4PayOrderMchNotify.java | 47 +++++++++++++++++++ .../mq/queue/MqQueue4PayOrderMchNotify.java | 8 ++-- .../service/mapper/MchNotifyRecordMapper.java | 9 ++++ .../service/mapper/MchNotifyRecordMapper.xml | 10 ++++ 7 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/mq/queue/MqQueue4PayOrderMchNotify.java diff --git a/docs/sql/init.sql b/docs/sql/init.sql index f97e597..9fd480d 100644 --- a/docs/sql/init.sql +++ b/docs/sql/init.sql @@ -315,6 +315,7 @@ CREATE TABLE `t_mch_notify_record` ( `notify_url` TEXT NOT NULL COMMENT '通知地址', `res_result` TEXT DEFAULT NULL COMMENT '通知响应结果', `notify_count` INT(11) NOT NULL DEFAULT '0' COMMENT '通知次数', + `notify_count_limit` INT(11) NOT NULL DEFAULT '6' COMMENT '最大通知次数, 默认6次', `state` TINYINT(6) NOT NULL DEFAULT '1' COMMENT '通知状态,1-通知中,2-通知成功,3-通知失败', `last_notify_time` DATETIME DEFAULT NULL COMMENT '最后一次通知时间', `created_at` TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', @@ -440,6 +441,7 @@ insert into t_sys_entitlement values('ENT_ORDER', '订单管理', 'transaction', insert into t_sys_entitlement values('ENT_MCH_NOTIFY', '商户通知', 'notification', '/notify', 'MchNotifyListPage', 'ML', 0, 1, 'ENT_ORDER', '30', 'MGR', now(), now()); insert into t_sys_entitlement values('ENT_NOTIFY_LIST', '页面:商户通知列表', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_NOTIFY', '0', 'MGR', now(), now()); insert into t_sys_entitlement values('ENT_MCH_NOTIFY_VIEW', '按钮:详情', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_NOTIFY', '0', 'MGR', now(), now()); + insert into t_sys_entitlement values('ENT_MCH_NOTIFY_RESEND', '按钮:重发通知', 'no-icon', '', '', 'PB', 0, 1, 'ENT_MCH_NOTIFY', '0', 'MGR', now(), now()); -- 支付配置菜单 insert into t_sys_entitlement values('ENT_PC', '支付配置', 'file-done', '', 'RouteView', 'ML', 0, 1, 'ROOT', '60', 'MGR', now(), now()); diff --git a/jeepay-core/src/main/java/com/jeequan/jeepay/core/entity/MchNotifyRecord.java b/jeepay-core/src/main/java/com/jeequan/jeepay/core/entity/MchNotifyRecord.java index cb86415..30ca099 100644 --- a/jeepay-core/src/main/java/com/jeequan/jeepay/core/entity/MchNotifyRecord.java +++ b/jeepay-core/src/main/java/com/jeequan/jeepay/core/entity/MchNotifyRecord.java @@ -108,6 +108,11 @@ public class MchNotifyRecord extends BaseModel implements Serializable { */ private Integer notifyCount; + /** + * 最大通知次数, 默认6次 + */ + private Integer notifyCountLimit; + /** * 通知状态,1-通知中,2-通知成功,3-通知失败 */ diff --git a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/order/MchNotifyController.java b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/order/MchNotifyController.java index c293534..51e7730 100644 --- a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/order/MchNotifyController.java +++ b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/ctrl/order/MchNotifyController.java @@ -20,8 +20,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.jeequan.jeepay.core.constants.ApiCodeEnum; import com.jeequan.jeepay.core.entity.MchNotifyRecord; +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.MqQueue4PayOrderMchNotify; import com.jeequan.jeepay.service.impl.MchNotifyRecordService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -43,6 +45,7 @@ import org.springframework.web.bind.annotation.RestController; public class MchNotifyController extends CommonCtrl { @Autowired private MchNotifyRecordService mchNotifyService; + @Autowired private MqQueue4PayOrderMchNotify mqQueue4PayOrderMchNotify; /** * @author: pangxiaoyu @@ -86,4 +89,26 @@ public class MchNotifyController extends CommonCtrl { if (mchNotify == null) return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); return ApiRes.ok(mchNotify); } + + /* + * 功能描述: 商户通知重发操作 + * @Author: terrfly + * @Date: 2021/6/21 17:41 + */ + @PreAuthorize("hasAuthority('ENT_MCH_NOTIFY_RESEND')") + @RequestMapping(value="resend/{notifyId}", method = RequestMethod.POST) + public ApiRes resend(@PathVariable("notifyId") Long notifyId) { + MchNotifyRecord mchNotify = mchNotifyService.getById(notifyId); + if (mchNotify == null) return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE); + if (mchNotify.getState() != MchNotifyRecord.STATE_FAIL) throw new BizException("请选择失败的通知记录"); + + //更新通知中 + mchNotifyService.getBaseMapper().updateIngAndAddNotifyCountLimit(notifyId); + + //调起MQ重发 + mqQueue4PayOrderMchNotify.send(notifyId); + + return ApiRes.ok(mchNotify); + } + } diff --git a/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/mq/queue/MqQueue4PayOrderMchNotify.java b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/mq/queue/MqQueue4PayOrderMchNotify.java new file mode 100644 index 0000000..742e106 --- /dev/null +++ b/jeepay-manager/src/main/java/com/jeequan/jeepay/mgr/mq/queue/MqQueue4PayOrderMchNotify.java @@ -0,0 +1,47 @@ +/* + * 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.mq.queue; + +import com.jeequan.jeepay.core.constants.CS; +import lombok.extern.slf4j.Slf4j; +import org.apache.activemq.command.ActiveMQQueue; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jms.core.JmsTemplate; +import org.springframework.stereotype.Component; + +/** +* 商户订单回调MQ通知 +* +* @author terrfly +* @site https://www.jeepay.vip +* @date 2021/6/21 18:03 +*/ +@Slf4j +@Component +public class MqQueue4PayOrderMchNotify extends ActiveMQQueue{ + + @Autowired private JmsTemplate jmsTemplate; + + public MqQueue4PayOrderMchNotify(){ + super(CS.MQ.QUEUE_PAYORDER_MCH_NOTIFY); + } + + /** 发送MQ消息 **/ + public void send(Long notifyId) { + this.jmsTemplate.convertAndSend(this, notifyId + ""); + } + +} diff --git a/jeepay-payment/src/main/java/com/jeequan/jeepay/pay/mq/queue/MqQueue4PayOrderMchNotify.java b/jeepay-payment/src/main/java/com/jeequan/jeepay/pay/mq/queue/MqQueue4PayOrderMchNotify.java index 7252bdb..65661f6 100644 --- a/jeepay-payment/src/main/java/com/jeequan/jeepay/pay/mq/queue/MqQueue4PayOrderMchNotify.java +++ b/jeepay-payment/src/main/java/com/jeequan/jeepay/pay/mq/queue/MqQueue4PayOrderMchNotify.java @@ -39,7 +39,7 @@ import javax.jms.TextMessage; /* * 商户订单回调MQ通知 -* +* * @author terrfly * @site https://www.jeepay.vip * @date 2021/6/8 17:34 @@ -96,7 +96,7 @@ public class MqQueue4PayOrderMchNotify { log.info("查询通知记录不存在或状态不是通知中"); return ; } - if( record.getNotifyCount() >= 6 ){ + if( record.getNotifyCount() >= record.getNotifyCountLimit() ){ log.info("已达到最大发送次数"); return ; } @@ -122,8 +122,8 @@ public class MqQueue4PayOrderMchNotify { return ; } - //响应结果为异常 - if( currentCount >= 6 ){ + //通知次数 >= 最大通知次数时, 更新响应结果为异常, 不在继续延迟发送消息 + if( currentCount >= record.getNotifyCountLimit() ){ mchNotifyRecordService.updateNotifyResult(notifyId, MchNotifyRecord.STATE_FAIL, res); return ; } diff --git a/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchNotifyRecordMapper.java b/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchNotifyRecordMapper.java index a2d9da1..ace2fd5 100644 --- a/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchNotifyRecordMapper.java +++ b/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchNotifyRecordMapper.java @@ -30,4 +30,13 @@ import org.apache.ibatis.annotations.Param; public interface MchNotifyRecordMapper extends BaseMapper { Integer updateNotifyResult(@Param("notifyId") Long notifyId, @Param("state") Byte state, @Param("resResult") String resResult); + + /* + * 功能描述: 更改为通知中 & 增加允许重发通知次数 + * @param notifyId + * @Author: terrfly + * @Date: 2021/6/21 17:38 + */ + Integer updateIngAndAddNotifyCountLimit(@Param("notifyId") Long notifyId); + } diff --git a/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchNotifyRecordMapper.xml b/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchNotifyRecordMapper.xml index 8eaa56a..929ac03 100644 --- a/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchNotifyRecordMapper.xml +++ b/jeepay-service/src/main/java/com/jeequan/jeepay/service/mapper/MchNotifyRecordMapper.xml @@ -14,6 +14,7 @@ + @@ -32,4 +33,13 @@ + + + + + update t_mch_notify_record + set notify_count_limit = notify_count_limit + 1, state = 1 + where notify_id = #{notifyId} + + -- GitLab