Sfoglia il codice sorgente

设置默认户号

QAQ 陈 4 mesi fa
parent
commit
90aa89e931

+ 3 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/dao/SwUserManagementDao.java

@@ -29,6 +29,9 @@ public interface SwUserManagementDao extends BaseMapper<SwUserManagementDo> {
     void updateDefaultAccount(@Param("dsKeys") List<String> dsKey,@Param("openId") String openId);
 
     void unbindAccount(@Param("dsKey") String dsKey,@Param("openId") String openId,@Param("userAccount") String userAccount);
+
+    void setDefaultAccount1(@Param("dsKey") String dsKey,@Param("openId") String openId);
+    void setDefaultAccount0(@Param("dsKey") String dsKey,@Param("openId") String openId,@Param("userAccount") String userAccount);
 }
 
 

+ 3 - 1
zhsw-common/src/main/java/com/rongwei/zhsw/system/wechat/AccountService.java

@@ -13,11 +13,13 @@ import com.rongwei.rwcommon.base.R;
 public interface AccountService {
     R bind(AccountBindVo accountBindVo);
 
-    R changeDefaultAccount(AccountBindVo accountBindVo);
 
     R info(String accountNumber);
 
     R list();
 
     R unbind(AccountUnbindVo accountUnbindVo);
+
+    R setDefaultAccount(AccountUnbindVo accountUnbindVo);
+
 }

+ 25 - 11
zhsw-common/src/main/java/com/rongwei/zhsw/system/wechat/impl/AccountServiceImpl.java

@@ -14,6 +14,8 @@ import com.rongwei.rwcommon.base.BaseDo;
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.rwcommon.utils.SecurityUtil;
+import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;
+import com.rongwei.zhsw.system.dao.CommonBusinessDao;
 import com.rongwei.zhsw.system.dao.SwNotificationAnnouncementDao;
 import com.rongwei.zhsw.system.service.impl.SwBillManagementUnpaidServiceImpl;
 import com.rongwei.zhsw.system.service.impl.SwUserManagementServiceImpl;
@@ -30,6 +32,7 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * AccountServiceImpl class
@@ -52,7 +55,8 @@ public class AccountServiceImpl implements AccountService {
     private SwBillManagementUnpaidServiceImpl swBillManagementUnpaidService;
     @Autowired
     private SwNotificationAnnouncementDao swNotificationAnnouncementDao;
-
+    @Autowired
+    private CommonBusinessDao commonBusinessDao;
     @Override
     public R bind(AccountBindVo accountBindVo) {
         log.info("开始执行户号绑定:{}", accountBindVo);
@@ -110,16 +114,6 @@ public class AccountServiceImpl implements AccountService {
         return R.ok(allOwnerByOpenId);
     }
 
-    /**
-     * 切换默认账户
-     *
-     * @param accountBindVo
-     * @return
-     */
-    @Override
-    public R changeDefaultAccount(AccountBindVo accountBindVo) {
-        return null;
-    }
 
     /**
      * 获取当前账户的信息
@@ -176,4 +170,24 @@ public class AccountServiceImpl implements AccountService {
         List<SwUserManagementVo> allOwnerByOpenId = weChatLoginService.getAllOwnerByOpenId(currentWeChatOpenId, otherDsKeys);
         return R.ok(allOwnerByOpenId);
     }
+
+    public R setDefaultAccount(AccountUnbindVo accountUnbindVo){
+        String account = accountUnbindVo.getAccount();
+        String dsKey = accountUnbindVo.getDeKey();
+        if (StringUtils.isBlank(account)) {
+            throw new CustomException("解绑的户号为空");
+        }
+        //获取微信标识
+        String currentWeChatOpenId = WeChatUtils.getCurrentWeChatOpenId();
+        //微信标识下所有用户改为非默认用户
+        swUserManagementService.getBaseMapper().setDefaultAccount1(dsKey, currentWeChatOpenId);
+        //将微信标识下该户号用户设置为默认户号
+        swUserManagementService.getBaseMapper().setDefaultAccount0(dsKey, currentWeChatOpenId, account);
+        //刷新对应水务公司得业主信息
+        List<TenantDo> tenantDos = commonBusinessDao.getById(dsKey);
+        List<String> tenantDsKeys = tenantDos.stream().map(TenantDo::getDskey).collect(Collectors.toList());
+        ownerService.refreshByTenant(tenantDsKeys);
+        return R.ok();
+    }
+
 }

+ 11 - 0
zhsw-common/src/main/resources/mybatis/zhsw/SwUserManagementDao.xml

@@ -57,5 +57,16 @@
             WHERE WECHATSIGN = #{openId}
             and USERNO=#{userAccount}
     </update>
+    <update id="setDefaultAccount1">
+        UPDATE ${dsKey}.sw_user_wechat
+        SET DEFAULTACCOUNT = 1
+        WHERE WECHATSIGN = #{openId}
+    </update>
+    <update id="setDefaultAccount0">
+        UPDATE ${dsKey}.sw_user_wechat
+        SET DEFAULTACCOUNT = 0
+        WHERE WECHATSIGN = #{openId}
+          and USERNO=#{userAccount}
+    </update>
 </mapper>
 

+ 10 - 6
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/weChat/AccountController.java

@@ -35,12 +35,6 @@ public class AccountController {
         return accountService.bind(accountBindVo);
     }
 
-    @PostMapping("/change-default")
-    private R changeDefaultAccount(@RequestBody AccountBindVo accountBindVo) {
-        return accountService.changeDefaultAccount(accountBindVo);
-    }
-
-
     @GetMapping("/info/{accountNumber}")
     private R info(@PathVariable("accountNumber") String accountNumber) {
         return accountService.info(accountNumber);
@@ -61,4 +55,14 @@ public class AccountController {
     private R unbind(@RequestBody AccountUnbindVo accountUnbindVo) {
         return accountService.unbind(accountUnbindVo);
     }
+
+    /**
+     * 户号设置默认方法
+
+     */
+    @PostMapping("/setDefaultAccount")
+    private R setDefaultAccount(@RequestBody AccountUnbindVo accountUnbindVo) {
+        return accountService.setDefaultAccount(accountUnbindVo);
+    }
+
 }

+ 2 - 0
zhsw-server/src/main/resources/bootstrap-dev.yml

@@ -5,8 +5,10 @@ spring:
         file-extension: yaml
         server-addr: 127.0.0.1:8848
         namespace: 9caed6dc-3784-4d73-bd4c-a8e8153bc358
+#        namespace: cd047569-9470-4dfb-8663-b113d01cd30f
         ext-config[0]:
           data-id: common-config.yaml
       discovery:
         server-addr: 127.0.0.1:8848
         namespace: 9caed6dc-3784-4d73-bd4c-a8e8153bc358
+#        namespace: cd047569-9470-4dfb-8663-b113d01cd30f