diff --git a/docs/sql/init.sql b/docs/sql/init.sql index f97e597c737e168c64f869e76881b0303ca7eb76..9fd480d0f6a837b8c731ac3cffb13d87d202667a 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 cb864153f319a49d0da0d0d55c3947525d9d6154..30ca0992b9903eb50c96a8af6ece0a5b8cc78b4b 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 c2935345b3bcc0c605a513b51a392dcde3f0669e..51e7730b2c7f54bb9c76eb7820bde3ecbbc359aa 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 0000000000000000000000000000000000000000..742e1062d1308a23b90a195bfc4196c0fb0d0d07 --- /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 7252bdba7295d102c339435e2ff42a3b7eaf70fb..65661f6161b98fd5d878941c14b7d35289f53ff6 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 a2d9da1e11c9266d1157e5f33f4b6750887ff839..ace2fd5a879010479fa0d38d247a700eb710d290 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 8eaa56a12d577f2af1ccfc1272fcf080bdde7b1d..929ac033a825388ed02909833d1da8247075c9a0 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} + +