|
@@ -57,6 +57,7 @@ public class AccountServiceImpl implements AccountService {
|
|
|
private SwNotificationAnnouncementDao swNotificationAnnouncementDao;
|
|
|
@Autowired
|
|
|
private CommonBusinessDao commonBusinessDao;
|
|
|
+
|
|
|
@Override
|
|
|
public R bind(AccountBindVo accountBindVo) {
|
|
|
log.info("开始执行户号绑定:{}", accountBindVo);
|
|
@@ -82,7 +83,12 @@ public class AccountServiceImpl implements AccountService {
|
|
|
SwUserWechatDo swUserWechat = new SwUserWechatDo();
|
|
|
swUserWechat.setId(SecurityUtil.getUUID());
|
|
|
|
|
|
- swUserWechat.setDefaultaccount(accountBindVo.getDefaultAccount());
|
|
|
+ // 根据 openId 查询是否存在绑定记录
|
|
|
+ boolean exists = swUserWechatService.count(new LambdaQueryWrapper<SwUserWechatDo>()
|
|
|
+ .eq(SwUserWechatDo::getWechatsign, openId)
|
|
|
+ .eq(SwUserWechatDo::getDeleted, 0)) > 0;
|
|
|
+ // 如果不存在数据设置为默认账户(0),存在数据设置为非默认账户(1)
|
|
|
+ swUserWechat.setDefaultaccount(exists);
|
|
|
swUserWechat.setGroupname(accountBindVo.getGroupType());
|
|
|
// swUserWechat.setPhone(accountBindVo.getPhone());
|
|
|
swUserWechat.setUserno(swUserManagementVo.getUsernumber());
|
|
@@ -157,8 +163,33 @@ public class AccountServiceImpl implements AccountService {
|
|
|
throw new CustomException("解绑的户号为空");
|
|
|
}
|
|
|
String currentWeChatOpenId = WeChatUtils.getCurrentWeChatOpenId();
|
|
|
+ // OpenId 下的所有绑定记录
|
|
|
+ List<SwUserWechatDo> bindRecords = swUserWechatService.list(new LambdaQueryWrapper<SwUserWechatDo>()
|
|
|
+ .eq(SwUserWechatDo::getWechatsign, currentWeChatOpenId));
|
|
|
+ // 判断是否需要更新默认账户
|
|
|
+ if (bindRecords.size() >= 2) {
|
|
|
+ // 查询当前解绑的账户是否是默认账户
|
|
|
+ SwUserWechatDo currentAccount = swUserWechatService.getOne(new LambdaQueryWrapper<SwUserWechatDo>()
|
|
|
+ .eq(SwUserWechatDo::getWechatsign, currentWeChatOpenId)
|
|
|
+ .eq(SwUserWechatDo::getUserno, account));
|
|
|
+ if (currentAccount != null && !currentAccount.getDefaultaccount()) {
|
|
|
+ // 当前解绑的是默认账户,需要将下一条数据设置为默认账户
|
|
|
+ SwUserWechatDo nextAccount = bindRecords.stream()
|
|
|
+ .filter(record -> !record.getUserno().equals(account)) // 排除当前解绑的账户
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+
|
|
|
+ if (nextAccount != null) {
|
|
|
+ // 更新下一条数据为默认账户
|
|
|
+ nextAccount.setDefaultaccount(false); // 设置为默认账户
|
|
|
+ swUserWechatService.updateById(nextAccount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
// 删除绑定关系
|
|
|
swUserManagementService.getBaseMapper().unbindAccount(dsKey, currentWeChatOpenId, account);
|
|
|
+
|
|
|
// 默认不刷新直接返回
|
|
|
if (!accountUnbindVo.getRefresh()) {
|
|
|
return R.ok();
|
|
@@ -171,7 +202,7 @@ public class AccountServiceImpl implements AccountService {
|
|
|
return R.ok(allOwnerByOpenId);
|
|
|
}
|
|
|
|
|
|
- public R setDefaultAccount(AccountUnbindVo accountUnbindVo){
|
|
|
+ public R setDefaultAccount(AccountUnbindVo accountUnbindVo) {
|
|
|
String account = accountUnbindVo.getAccount();
|
|
|
String dsKey = accountUnbindVo.getDeKey();
|
|
|
if (StringUtils.isBlank(account)) {
|