更改商户信息代码逻辑优化, 解决推送MQ异常
This commit is contained in:
parent
072aa10ccc
commit
4a1a1fe6f3
|
|
@ -39,9 +39,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 商户管理类
|
||||
|
|
@ -115,7 +113,7 @@ public class MchInfoController extends CommonCtrl {
|
|||
public ApiRes delete(@PathVariable("mchNo") String mchNo) {
|
||||
List<Long> userIdList = mchInfoService.removeByMchNo(mchNo);
|
||||
// 推送mq删除redis用户缓存
|
||||
mqQueue4ModifyMchUserRemove.push(StringUtils.join(userIdList, ","));
|
||||
mqQueue4ModifyMchUserRemove.push(userIdList);
|
||||
// 推送mq到目前节点进行更新数据
|
||||
mqTopic4ModifyMchInfo.push(mchNo);
|
||||
return ApiRes.ok();
|
||||
|
|
@ -130,58 +128,50 @@ public class MchInfoController extends CommonCtrl {
|
|||
@MethodLog(remark = "更新商户信息")
|
||||
@RequestMapping(value="/{mchNo}", method = RequestMethod.PUT)
|
||||
public ApiRes update(@PathVariable("mchNo") String mchNo) {
|
||||
|
||||
//获取查询条件
|
||||
MchInfo mchInfo = getObject(MchInfo.class);
|
||||
List<Long> userIdCacheList = new ArrayList<>();
|
||||
mchInfo.setMchNo(mchNo);
|
||||
// 校验该商户是否为特邀商户
|
||||
MchInfo dbMchInfo = mchInfoService.getById(mchNo);
|
||||
if (dbMchInfo == null) {
|
||||
return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_SELETE);
|
||||
}
|
||||
// 如果为特邀商户则不允许修改服务商及商户类型
|
||||
if (dbMchInfo.getType() == CS.MCH_TYPE_ISVSUB) {
|
||||
mchInfo.setType(dbMchInfo.getType());
|
||||
mchInfo.setIsvNo(dbMchInfo.getIsvNo());
|
||||
}
|
||||
mchInfo.setMchNo(mchNo); //设置商户号主键
|
||||
|
||||
mchInfo.setType(null); //防止变更商户类型
|
||||
mchInfo.setIsvNo(null);
|
||||
|
||||
// 待删除用户登录信息的ID list
|
||||
Set<Long> removeCacheUserIdList = new HashSet<>();
|
||||
|
||||
// 如果商户状态为禁用状态,清除该商户用户登录信息
|
||||
if (mchInfo.getState() == CS.NO) {
|
||||
List<SysUser> userList = sysUserService.list(SysUser.gw()
|
||||
.eq(SysUser::getBelongInfoId, mchNo)
|
||||
.eq(SysUser::getSysType, CS.SYS_TYPE.MCH)
|
||||
);
|
||||
if (userList.size() > 0) {
|
||||
for (SysUser user:userList) {
|
||||
userIdCacheList.add(user.getSysUserId());
|
||||
}
|
||||
}
|
||||
sysUserService.list( SysUser.gw().select(SysUser::getSysUserId).eq(SysUser::getBelongInfoId, mchNo).eq(SysUser::getSysType, CS.SYS_TYPE.MCH) )
|
||||
.stream().forEach(u -> removeCacheUserIdList.add(u.getSysUserId()));
|
||||
}
|
||||
|
||||
//判断是否重置密码
|
||||
Boolean resetPass = getReqParamJSON().getBoolean("resetPass");
|
||||
if (resetPass != null && resetPass) {
|
||||
//判断是否重置密码
|
||||
String updatePwd = getReqParamJSON().getBoolean("defaultPass") == false? Base64.decodeStr(getValStringRequired("confirmPwd")):CS.DEFAULT_PWD;
|
||||
if (StringUtils.isNotEmpty(updatePwd)) {
|
||||
// 获取商户最初的用户
|
||||
SysUser sysUser = sysUserService.getOne(SysUser.gw()
|
||||
.eq(SysUser::getBelongInfoId, mchNo)
|
||||
.eq(SysUser::getSysType, CS.SYS_TYPE.MCH)
|
||||
.eq(SysUser::getIsAdmin, CS.YES)
|
||||
);
|
||||
sysUserAuthService.resetAuthInfo(sysUser.getSysUserId(), null, null, updatePwd, CS.SYS_TYPE.MCH);
|
||||
if (mchInfo.getState() == CS.YES) userIdCacheList = Arrays.asList(sysUser.getSysUserId());
|
||||
}
|
||||
if (getReqParamJSON().getBooleanValue("resetPass")) {
|
||||
// 待更新的密码
|
||||
String updatePwd = getReqParamJSON().getBoolean("defaultPass") ? CS.DEFAULT_PWD : Base64.decodeStr(getValStringRequired("confirmPwd")) ;
|
||||
// 获取商户超管
|
||||
Long mchAdminUserId = sysUserService.findMchAdminUserId(mchNo);
|
||||
|
||||
//重置超管密码
|
||||
sysUserAuthService.resetAuthInfo(mchAdminUserId, null, null, updatePwd, CS.SYS_TYPE.MCH);
|
||||
|
||||
//删除超管登录信息
|
||||
removeCacheUserIdList.add(mchAdminUserId);
|
||||
}
|
||||
|
||||
// 商户被禁用、修改密码删除mq用户缓存
|
||||
if (mchInfo.getState() == CS.NO || resetPass) {
|
||||
// 推送mq删除redis用户缓存
|
||||
mqQueue4ModifyMchUserRemove.push(StringUtils.join(Arrays.asList(userIdCacheList), ","));
|
||||
// 推送mq删除redis用户认证信息
|
||||
if (!removeCacheUserIdList.isEmpty()) {
|
||||
mqQueue4ModifyMchUserRemove.push(removeCacheUserIdList);
|
||||
}
|
||||
|
||||
boolean result = mchInfoService.updateById(mchInfo);
|
||||
mqTopic4ModifyMchInfo.push(mchNo); // 推送mq到目前节点进行更新数据
|
||||
if (!result) return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_UPDATE);
|
||||
//更新商户信息
|
||||
if (!mchInfoService.updateById(mchInfo)) {
|
||||
return ApiRes.fail(ApiCodeEnum.SYS_OPERATION_FAIL_UPDATE);
|
||||
}
|
||||
|
||||
// 推送mq到目前节点进行更新数据
|
||||
mqTopic4ModifyMchInfo.push(mchNo);
|
||||
|
||||
return ApiRes.ok();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.jeequan.jeepay.mgr.mq.queue;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.jeequan.jeepay.core.constants.CS;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
|
|
@ -22,6 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 商户用户信息清除
|
||||
*
|
||||
|
|
@ -44,8 +47,11 @@ public class MqQueue4ModifyMchUserRemove extends ActiveMQQueue{
|
|||
* @date: 2021/6/7 16:16
|
||||
* @describe: 推送消息到各个节点
|
||||
*/
|
||||
public void push(String userIdStr) {
|
||||
this.jmsTemplate.convertAndSend(this, userIdStr);
|
||||
public void push(Collection<Long> userIdList) {
|
||||
if(userIdList == null || userIdList.isEmpty()){
|
||||
return ;
|
||||
}
|
||||
this.jmsTemplate.convertAndSend(this,JSONArray.toJSONString(userIdList));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.jeequan.jeepay.mch.mq.queue;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.jeequan.jeepay.core.cache.RedisUtil;
|
||||
import com.jeequan.jeepay.core.constants.CS;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -52,7 +53,7 @@ public class MqQueue4ModifyMchUserRemove extends ActiveMQQueue {
|
|||
|
||||
log.info("成功接收删除商户用户登录的订阅通知, msg={}", userIdStr);
|
||||
// 字符串转List<Long>
|
||||
List<Long> userIdList = Arrays.stream(userIdStr.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
||||
List<Long> userIdList = JSONArray.parseArray(userIdStr, Long.class);
|
||||
// 删除redis用户缓存
|
||||
if(userIdList == null || userIdList.isEmpty()){
|
||||
log.info("用户ID为空");
|
||||
|
|
|
|||
|
|
@ -158,4 +158,16 @@ public class SysUserService extends ServiceImpl<SysUserMapper, SysUser> {
|
|||
// 3.删除用户信息
|
||||
removeById(sysUser.getSysUserId());
|
||||
}
|
||||
|
||||
|
||||
/** 获取到商户的超管用户ID **/
|
||||
public Long findMchAdminUserId(String mchNo){
|
||||
|
||||
return getOne(SysUser.gw().select(SysUser::getSysUserId)
|
||||
.eq(SysUser::getBelongInfoId, mchNo)
|
||||
.eq(SysUser::getSysType, CS.SYS_TYPE.MCH)
|
||||
.eq(SysUser::getIsAdmin, CS.YES)).getSysUserId();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue