From e4c05d381d2dadf129b3a4cb499c8ea67e7fc481 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Mon, 08 Nov 2021 17:19:47 +0800
Subject: [PATCH] fix
---
zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java b/zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java
index 5adb150..8e53584 100644
--- a/zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java
+++ b/zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java
@@ -16,6 +16,7 @@
import com.matrix.system.common.constance.AppConstance;
import com.matrix.system.common.dao.BusParameterSettingsDao;
import com.matrix.system.common.init.LocalCache;
+import com.matrix.system.common.init.UserCacheManager;
import com.matrix.system.common.interceptor.HostInterceptor;
import com.matrix.system.common.service.SysCompanyService;
import com.matrix.system.common.service.SysUsersService;
@@ -77,6 +78,8 @@
@Autowired
WeChatApiTools weChatApiTools;
+ @Autowired
+ private UserCacheManager userCacheManager;
@Value("${file_storage_path}")
private String fileStoragePath;
@@ -303,7 +306,57 @@
}
String openId = json.getString("openid");
- return null;
+ res.setStatus(AjaxResult.STATUS_SUCCESS);
+ res.putInMap("openId", openId);
+ SysUsers hasBind = sysUsersService.findByOpenId(openId, HostInterceptor.getCompanyId());
+ if (hasBind == null) {
+ res.setInfo("未绑定用户");
+ return res;
+ }
+
+ String token = userCacheManager.saveUserInfo(hasBind);
+ LogUtil.info("用户token={}", token);
+ res.putInMap("token", token);
+ res.putInMap("userInfo", hasBind);
+ return res;
+ }
+
+ @ApiOperation(value = "绑定用户")
+ @PostMapping(value = "/bindUser")
+ public AjaxResult bindUser(@RequestBody @Validated LoginDto loginDto) {
+ SysUsers user = new SysUsers();
+ user.setSuAccount(loginDto.getUsername());
+ user.setSuPassword(loginDto.getPassword());
+ LoginStrategy apLogin = new AccountPasswordLogin(user, sysUsersService);
+ user = authorityManager.login(apLogin);
+ user.setSuPassword(null);
+ user.setOpenIds(null);
+ String token = userCacheManager.saveUserInfo(user);
+
+ AjaxResult result = AjaxResult.buildSuccessInstance("登陆成功");
+ authorityManager.initUserPower(result, user);
+ result.putInMap("token", token);
+ result.putInMap("userInfo", user);
+
+ synchronized (this) {
+ SysUsers hasBind = sysUsersService.findByOpenId(loginDto.getOpenId(), HostInterceptor.getCompanyId());
+ if (hasBind != null) {
+ if(StrUtil.isNotBlank(hasBind.getOpenIds())) {
+ List<String> openIds = StrUtil.split(hasBind.getOpenIds(), ',');
+ openIds.remove(loginDto.getOpenId());
+
+ hasBind.setOpenIds(CollUtil.join(openIds, ","));
+ sysUsersService.modifyByModel(hasBind);
+ }
+ }
+
+ List<String> openIds = StrUtil.split(user.getOpenIds(), ',');
+ openIds.add(loginDto.getOpenId());
+ user.setOpenIds(CollUtil.join(openIds, ","));
+ sysUsersService.modifyByModel(user);
+ }
+
+ return result;
}
}
--
Gitblit v1.9.1