refactor: 将corpid硬编码替换为WeixinConstants常量
将多处硬编码的corpid替换为WeixinConstants.corpid,提高代码的可维护性和可读性。同时在WxLoginController中新增QyUserApplicationService依赖,用于保存汇邦云用户信息。
This commit is contained in:
parent
9a743aadf0
commit
727b892eab
|
@ -2,6 +2,7 @@ package com.agileboot.admin.controller.qywx;
|
||||||
|
|
||||||
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
|
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
|
||||||
import com.agileboot.admin.customize.service.QywxScheduleJob;
|
import com.agileboot.admin.customize.service.QywxScheduleJob;
|
||||||
|
import com.agileboot.common.constant.WeixinConstants;
|
||||||
import com.agileboot.common.core.base.BaseController;
|
import com.agileboot.common.core.base.BaseController;
|
||||||
import com.agileboot.common.core.dto.ResponseDTO;
|
import com.agileboot.common.core.dto.ResponseDTO;
|
||||||
import com.agileboot.common.core.page.PageDTO;
|
import com.agileboot.common.core.page.PageDTO;
|
||||||
|
@ -108,7 +109,7 @@ public class QyDepartmentController extends BaseController {
|
||||||
public ResponseDTO<List<DeptDTO>> depts(@RequestParam String corpid) {
|
public ResponseDTO<List<DeptDTO>> depts(@RequestParam String corpid) {
|
||||||
List<QyDepartmentEntity> qyDepartmentEntityList = departmentApplicationService.getDepartmentList();
|
List<QyDepartmentEntity> qyDepartmentEntityList = departmentApplicationService.getDepartmentList();
|
||||||
if (StringUtils.isBlank(corpid)) {
|
if (StringUtils.isBlank(corpid)) {
|
||||||
corpid = "wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw";
|
corpid = WeixinConstants.corpid;
|
||||||
}
|
}
|
||||||
// 根据corpid过滤部门列表
|
// 根据corpid过滤部门列表
|
||||||
String finalCorpid = corpid;
|
String finalCorpid = corpid;
|
||||||
|
|
|
@ -239,6 +239,9 @@ public class PaymentController {
|
||||||
List<QyUserEntity> qyUserEntityList = new ArrayList<>();
|
List<QyUserEntity> qyUserEntityList = new ArrayList<>();
|
||||||
for (QyAuthCorpInfoEntity qyAuthCorpInfoEntity : qyAuthCorpInfoEntityList) {
|
for (QyAuthCorpInfoEntity qyAuthCorpInfoEntity : qyAuthCorpInfoEntityList) {
|
||||||
String corpid = qyAuthCorpInfoEntity.getCorpid();
|
String corpid = qyAuthCorpInfoEntity.getCorpid();
|
||||||
|
if (!corpid.equals(WeixinConstants.corpid)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
QyAccessTokenEntity accessToken = accessTokenApplicationService.getByAppid(appid, corpid);
|
QyAccessTokenEntity accessToken = accessTokenApplicationService.getByAppid(appid, corpid);
|
||||||
UserIdResponse userIdResponse = QywxApiUtil.convertToUserid(accessToken.getAccessToken(), openid);
|
UserIdResponse userIdResponse = QywxApiUtil.convertToUserid(accessToken.getAccessToken(), openid);
|
||||||
QyUserEntity qyUser = qyUserApplicationService.getUserByUserId(userIdResponse.getUserid(), corpid);
|
QyUserEntity qyUser = qyUserApplicationService.getUserByUserId(userIdResponse.getUserid(), corpid);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.agileboot.common.core.dto.ResponseDTO;
|
||||||
import com.agileboot.common.exception.ApiException;
|
import com.agileboot.common.exception.ApiException;
|
||||||
import com.agileboot.common.exception.error.ErrorCode;
|
import com.agileboot.common.exception.error.ErrorCode;
|
||||||
import com.agileboot.domain.ab98.api.SsoLoginUserinfo;
|
import com.agileboot.domain.ab98.api.SsoLoginUserinfo;
|
||||||
|
import com.agileboot.domain.qywx.user.QyUserApplicationService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
@ -21,6 +22,7 @@ import java.util.Map;
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Api(tags = "微信登录接口")
|
@Api(tags = "微信登录接口")
|
||||||
public class WxLoginController {
|
public class WxLoginController {
|
||||||
|
private final QyUserApplicationService qyUserApplicationService;
|
||||||
|
|
||||||
@PostMapping("/logout")
|
@PostMapping("/logout")
|
||||||
@ApiOperation(value = "用户退出登录")
|
@ApiOperation(value = "用户退出登录")
|
||||||
|
@ -79,7 +81,8 @@ public class WxLoginController {
|
||||||
public ResponseDTO<Ab98ApiUtil.LoginData> verifySms(
|
public ResponseDTO<Ab98ApiUtil.LoginData> verifySms(
|
||||||
@RequestParam String token,
|
@RequestParam String token,
|
||||||
@RequestParam String tel,
|
@RequestParam String tel,
|
||||||
@RequestParam String vcode) {
|
@RequestParam String vcode,
|
||||||
|
@RequestParam(required = false) String userid) {
|
||||||
try {
|
try {
|
||||||
Ab98ApiUtil.LoginResponse loginResponse = Ab98ApiUtil.verifySmsCode(token, tel, vcode);
|
Ab98ApiUtil.LoginResponse loginResponse = Ab98ApiUtil.verifySmsCode(token, tel, vcode);
|
||||||
Ab98ApiUtil.LoginData data = new Ab98ApiUtil.LoginData();
|
Ab98ApiUtil.LoginData data = new Ab98ApiUtil.LoginData();
|
||||||
|
@ -90,6 +93,13 @@ public class WxLoginController {
|
||||||
data.setUserid(loginResponse.getOutputData().getUserid());
|
data.setUserid(loginResponse.getOutputData().getUserid());
|
||||||
data.setRegistered(loginResponse.getOutputData().isRegistered());
|
data.setRegistered(loginResponse.getOutputData().isRegistered());
|
||||||
data.setTel(loginResponse.getOutputData().getTel());
|
data.setTel(loginResponse.getOutputData().getTel());
|
||||||
|
|
||||||
|
try {
|
||||||
|
qyUserApplicationService.saveQyUserInfoByAb98(userid, loginResponse.getOutputData(), null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存汇邦云用户信息失败: ", e);
|
||||||
|
}
|
||||||
|
|
||||||
return ResponseDTO.ok(data);
|
return ResponseDTO.ok(data);
|
||||||
} catch (ApiException e) {
|
} catch (ApiException e) {
|
||||||
log.error("短信验证失败: {}", e.getMessage());
|
log.error("短信验证失败: {}", e.getMessage());
|
||||||
|
@ -99,7 +109,8 @@ public class WxLoginController {
|
||||||
|
|
||||||
@GetMapping("/tokenLogin")
|
@GetMapping("/tokenLogin")
|
||||||
@ApiOperation(value = "通过token登录", notes = "用于快速登录,无需验证码")
|
@ApiOperation(value = "通过token登录", notes = "用于快速登录,无需验证码")
|
||||||
public ResponseDTO<Ab98ApiUtil.LoginData> tokenLogin(@RequestParam String token) {
|
public ResponseDTO<Ab98ApiUtil.LoginData> tokenLogin(@RequestParam String token,
|
||||||
|
@RequestParam(required = false) String userid) {
|
||||||
SsoLoginUserinfo loginUserinfo = Ab98ApiUtil.getLoginUserInfoRemote("wxshop", "34164e41f0c6694be6bbbba0dc50c14a", token, "");
|
SsoLoginUserinfo loginUserinfo = Ab98ApiUtil.getLoginUserInfoRemote("wxshop", "34164e41f0c6694be6bbbba0dc50c14a", token, "");
|
||||||
|
|
||||||
Ab98ApiUtil.LoginData data = new Ab98ApiUtil.LoginData();
|
Ab98ApiUtil.LoginData data = new Ab98ApiUtil.LoginData();
|
||||||
|
@ -114,6 +125,11 @@ public class WxLoginController {
|
||||||
data.setRegistered(true);
|
data.setRegistered(true);
|
||||||
data.setTel(loginUserinfo.getPhone());
|
data.setTel(loginUserinfo.getPhone());
|
||||||
|
|
||||||
|
try {
|
||||||
|
qyUserApplicationService.saveQyUserInfoByAb98(userid, null, loginUserinfo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存汇邦云用户信息失败: ", e);
|
||||||
|
}
|
||||||
return ResponseDTO.ok(data);
|
return ResponseDTO.ok(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.agileboot.domain.qywx.user;
|
package com.agileboot.domain.qywx.user;
|
||||||
|
|
||||||
|
import com.agileboot.common.constant.WeixinConstants;
|
||||||
import com.agileboot.common.core.page.PageDTO;
|
import com.agileboot.common.core.page.PageDTO;
|
||||||
|
import com.agileboot.domain.ab98.api.Ab98ApiUtil;
|
||||||
|
import com.agileboot.domain.ab98.api.SsoLoginUserinfo;
|
||||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||||
import com.agileboot.domain.qywx.user.command.AddQyUserCommand;
|
import com.agileboot.domain.qywx.user.command.AddQyUserCommand;
|
||||||
import com.agileboot.domain.qywx.user.command.UpdateQyUserCommand;
|
import com.agileboot.domain.qywx.user.command.UpdateQyUserCommand;
|
||||||
|
@ -10,17 +13,25 @@ import com.agileboot.domain.qywx.user.dto.QyUserDTO;
|
||||||
import com.agileboot.domain.qywx.user.model.UserModel;
|
import com.agileboot.domain.qywx.user.model.UserModel;
|
||||||
import com.agileboot.domain.qywx.user.model.QyUserModelFactory;
|
import com.agileboot.domain.qywx.user.model.QyUserModelFactory;
|
||||||
import com.agileboot.domain.qywx.user.query.SearchQyUserQuery;
|
import com.agileboot.domain.qywx.user.query.SearchQyUserQuery;
|
||||||
|
import com.agileboot.domain.qywx.userQySys.db.SysUserQyUserEntity;
|
||||||
|
import com.agileboot.domain.qywx.userQySys.db.SysUserQyUserService;
|
||||||
|
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||||
|
import com.agileboot.domain.system.user.db.SysUserService;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class QyUserApplicationService {
|
public class QyUserApplicationService {
|
||||||
private final QyUserService userService;
|
private final QyUserService userService;
|
||||||
private final QyUserModelFactory qyUserModelFactory;
|
private final QyUserModelFactory qyUserModelFactory;
|
||||||
|
private final SysUserQyUserService sysUserQyUserService;
|
||||||
|
private final SysUserService sysUserService;
|
||||||
|
|
||||||
public PageDTO<QyUserDTO> getUserList(SearchQyUserQuery<QyUserEntity> query) {
|
public PageDTO<QyUserDTO> getUserList(SearchQyUserQuery<QyUserEntity> query) {
|
||||||
Page<QyUserEntity> page = userService.getUserList(query);
|
Page<QyUserEntity> page = userService.getUserList(query);
|
||||||
|
@ -56,4 +67,41 @@ public class QyUserApplicationService {
|
||||||
public QyUserEntity getUserByUserId(String userid, String corpid) {
|
public QyUserEntity getUserByUserId(String userid, String corpid) {
|
||||||
return userService.getUserByUserId(userid, corpid);
|
return userService.getUserByUserId(userid, corpid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveQyUserInfoByAb98(String userid, Ab98ApiUtil.LoginData data, SsoLoginUserinfo loginUserinfo) {
|
||||||
|
QyUserEntity qyUser = getUserByUserId(userid, WeixinConstants.corpid);
|
||||||
|
if (qyUser == null) {
|
||||||
|
log.error("saveQyUserInfoByAb98: user not found for userid: {}", userid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SysUserQyUserEntity sysUserQyUser = sysUserQyUserService.getByQyUserId(qyUser.getId());
|
||||||
|
SysUserEntity sysUser = null;
|
||||||
|
if (sysUserQyUser != null) {
|
||||||
|
sysUser = sysUserService.getById(sysUserQyUser.getSysUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data != null) {
|
||||||
|
qyUser.setAvatar(data.getFace_img());
|
||||||
|
qyUser.setGender(data.getSex());
|
||||||
|
qyUser.setMobile(data.getTel());
|
||||||
|
qyUser.updateById();
|
||||||
|
if (sysUser!= null) {
|
||||||
|
sysUser.setAvatar(data.getFace_img());
|
||||||
|
sysUser.setSex(data.getSex().contains("女") ? 0 : 1);
|
||||||
|
sysUser.setPhoneNumber(data.getTel());
|
||||||
|
sysUser.updateById();
|
||||||
|
}
|
||||||
|
} else if (loginUserinfo != null) {
|
||||||
|
qyUser.setAvatar(loginUserinfo.getFace());
|
||||||
|
qyUser.setGender(loginUserinfo.getSex());
|
||||||
|
qyUser.setMobile(loginUserinfo.getPhone());
|
||||||
|
qyUser.updateById();
|
||||||
|
if (sysUser!= null) {
|
||||||
|
sysUser.setAvatar(loginUserinfo.getFace());
|
||||||
|
sysUser.setSex(loginUserinfo.getSex().contains("女")? 0 : 1);
|
||||||
|
sysUser.setPhoneNumber(loginUserinfo.getPhone());
|
||||||
|
sysUser.updateById();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -277,7 +277,7 @@ public class ReturnApprovalApplicationService {
|
||||||
String appid = "QWTONG_YS_WXSHOP";
|
String appid = "QWTONG_YS_WXSHOP";
|
||||||
List<QyAuthCorpInfoEntity> authCorpInfoList = authCorpInfoApplicationService.getByAppid(appid);
|
List<QyAuthCorpInfoEntity> authCorpInfoList = authCorpInfoApplicationService.getByAppid(appid);
|
||||||
QyAuthCorpInfoEntity authCorpInfo = authCorpInfoList.stream()
|
QyAuthCorpInfoEntity authCorpInfo = authCorpInfoList.stream()
|
||||||
.filter(a -> "wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw".equals(a.getCorpid()))
|
.filter(a -> WeixinConstants.corpid.equals(a.getCorpid()))
|
||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
QyAccessTokenEntity accessToken = accessTokenApplicationService.getByAppid(appid, authCorpInfo.getCorpid());
|
QyAccessTokenEntity accessToken = accessTokenApplicationService.getByAppid(appid, authCorpInfo.getCorpid());
|
||||||
// 获取用户ID
|
// 获取用户ID
|
||||||
|
|
Loading…
Reference in New Issue