提交 0b9a27b3 编写于 作者: terrfly's avatar terrfly

将最大通知次数放置到DB, 完成商户消息重发功能

上级 97725978
......@@ -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());
......
......@@ -108,6 +108,11 @@ public class MchNotifyRecord extends BaseModel implements Serializable {
*/
private Integer notifyCount;
/**
* 最大通知次数, 默认6次
*/
private Integer notifyCountLimit;
/**
* 通知状态,1-通知中,2-通知成功,3-通知失败
*/
......
......@@ -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);
}
}
/*
* Copyright (c) 2021-2031, 河北计全科技有限公司 (https://www.jeequan.com & jeequan@126.com).
* <p>
* 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
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 + "");
}
}
......@@ -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 ;
}
......
......@@ -30,4 +30,13 @@ import org.apache.ibatis.annotations.Param;
public interface MchNotifyRecordMapper extends BaseMapper<MchNotifyRecord> {
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);
}
......@@ -14,6 +14,7 @@
<result column="notify_url" property="notifyUrl" />
<result column="res_result" property="resResult" />
<result column="notify_count" property="notifyCount" />
<result column="notify_count_limit" property="notifyCountLimit" />
<result column="state" property="state" />
<result column="last_notify_time" property="lastNotifyTime" />
<result column="created_at" property="createdAt" />
......@@ -32,4 +33,13 @@
</update>
<!-- 更改为通知中 & 增加允许重发通知次数 -->
<update id="updateIngAndAddNotifyCountLimit">
update t_mch_notify_record
set notify_count_limit = notify_count_limit + 1, state = 1
where notify_id = #{notifyId}
</update>
</mapper>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册