QAQ 陈 před 4 měsíci
rodič
revize
6062df1ef6

+ 33 - 2
zhsw-common/src/main/java/com/rongwei/zhsw/system/wechat/impl/AccountServiceImpl.java

@@ -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)) {

+ 1 - 1
zhsw-common/src/main/java/com/rongwei/zhsw/system/wechat/impl/RegistrationServiceImpl.java

@@ -128,7 +128,7 @@ public class RegistrationServiceImpl implements RegistrationService {
         String filePath="/upload_files/"+pathSuffix+"/";
         // 微信临时文件的目录
         String tempFilePath = weChatUploadVo.getTempFilePath();
-        String fileName = tempFilePath.substring(tempFilePath.lastIndexOf("tmp/") + 4);
+        String fileName = tempFilePath.substring(tempFilePath.lastIndexOf("/") + 4);
         ImageScaleDto scaleDto = ImageScaleDto.builder().scaleFlag(false).build();
         FileUtil.uploadFile(Base64.getDecoder().decode(base64),filePath , fileName, scaleDto);
 

+ 1 - 1
zhsw-entity/src/main/java/com/rongwe/zhsw/system/domain/SwUserWechatDo.java

@@ -62,4 +62,4 @@ public class SwUserWechatDo  extends BaseDo {
      * 当前户主所属的分组(,逗号分隔)
      */
     private String groupname;
-}
+}