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