feat(用户绑定): 添加企业微信用户与汇邦云用户绑定功能

- 在QyLoginDTO中新增qyUserId和ab98User字段,用于存储绑定信息
- 修改bindQyUser方法返回Ab98UserEntity以便前端展示
- 新增WxLoginController中的bindQyUser接口用于处理绑定请求
- 在PaymentController中完善登录返回信息,包含绑定用户数据
This commit is contained in:
dzq 2025-06-04 09:18:50 +08:00
parent 695e70e7a5
commit 1b057f6615
4 changed files with 34 additions and 4 deletions

View File

@ -10,6 +10,8 @@ import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.common.exception.error.ErrorCode.Client;
import com.agileboot.common.utils.OpenSignUtil;
import com.agileboot.domain.ab98.user.Ab98UserApplicationService;
import com.agileboot.domain.ab98.user.db.Ab98UserEntity;
import com.agileboot.domain.common.dto.QyLoginDTO;
import com.agileboot.domain.qywx.accessToken.AccessTokenApplicationService;
import com.agileboot.domain.qywx.accessToken.db.QyAccessTokenEntity;
@ -68,6 +70,7 @@ public class PaymentController {
private final MenuApplicationService menuApplicationService;
private final PaymentApplicationService paymentApplicationService;
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
private final Ab98UserApplicationService ab98UserApplicationService;
// 新增回调接口
/**
@ -199,8 +202,15 @@ public class PaymentController {
OpenidResponse openidResponse = QywxApiUtil.convertToOpenid(qyAccessToken.getAccessToken(), userid);
QyUserEntity qyUserEntity = qyUserApplicationService.getUserByUserIdAndCorpid(userid, corpid);
Ab98UserEntity ab98User = null;
if (qyUserEntity != null && qyUserEntity.getAb98UserId() != null) {
ab98User = ab98UserApplicationService.getByAb98UserId(qyUserEntity.getAb98UserId());
}
return ResponseDTO.ok(new QyLoginDTO(userid, openidResponse.getOpenid(), isCabinetAdmin, qyUserEntity.getName()));
return ResponseDTO.ok(new QyLoginDTO(userid, openidResponse.getOpenid(), isCabinetAdmin,
qyUserEntity == null ? 0 : qyUserEntity.getId(),
qyUserEntity == null ? "" : qyUserEntity.getName(),
ab98User));
} catch (RestClientException e) {
log.error("qyLogin失败", e);
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "微信服务调用失败"));

View File

@ -5,11 +5,14 @@ import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.ab98.api.SsoLoginUserinfo;
import com.agileboot.domain.ab98.user.Ab98UserApplicationService;
import com.agileboot.domain.ab98.user.command.BindQyUserCommand;
import com.agileboot.domain.ab98.user.db.Ab98UserEntity;
import com.agileboot.domain.qywx.user.QyUserApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.agileboot.domain.ab98.api.Ab98ApiUtil;
@ -25,6 +28,7 @@ import java.util.Map;
public class WxLoginController {
private final QyUserApplicationService qyUserApplicationService;
private final Ab98UserApplicationService ab98UserApplicationService;
private final Ab98UserApplicationService userApplicationService;
@PostMapping("/logout")
@ApiOperation(value = "用户退出登录")
@ -152,4 +156,14 @@ public class WxLoginController {
return ResponseDTO.ok(data);
}
@PostMapping("/bindQyUser")
@ApiOperation(value = "绑定汇邦云", notes = "通过姓名身份证绑定汇邦云")
public ResponseDTO<Ab98UserEntity> bindQyUser(@RequestBody BindQyUserCommand command) {
if (command == null || command.getQyUserId() == null || StringUtils.isBlank(command.getName()) || StringUtils.isBlank(command.getIdNum())) {
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "参数错误"));
}
Ab98UserEntity ab98User = userApplicationService.bindQyUser(command);
return ResponseDTO.ok(ab98User);
}
}

View File

@ -177,7 +177,7 @@ public class Ab98UserApplicationService {
}
}
public void bindQyUser(BindQyUserCommand bindQyUserCommand) {
public Ab98UserEntity bindQyUser(BindQyUserCommand bindQyUserCommand) {
QyUserEntity qyUser = qyUserService.getById(bindQyUserCommand.getQyUserId());
if (qyUser == null) {
throw new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "企业微信用户不存在");
@ -186,7 +186,7 @@ public class Ab98UserApplicationService {
Ab98UserEntity ab98UserEntity = userService.getByIdnum(bindQyUserCommand.getIdNum());
if (ab98UserEntity != null && StringUtils.equals(ab98UserEntity.getName(), bindQyUserCommand.getName())) {
saveQyUserInfoByAb98(qyUser, ab98UserEntity);
return;
return ab98UserEntity;
}
Ab98UserDto ab98UserDto = Ab98ApiUtil.pullUserInfoByIdnum("wxshop", "34164e41f0c6694be6bbbba0dc50c14a", bindQyUserCommand.getIdNum());
@ -201,7 +201,9 @@ public class Ab98UserApplicationService {
Ab98UserModel model = userModelFactory.create();
model.loadAddCommand(addAb98UserCommand);
model.insert();
saveQyUserInfoByAb98(qyUser, model.selectById());
ab98UserEntity = model.selectById();
saveQyUserInfoByAb98(qyUser, ab98UserEntity);
return ab98UserEntity;
}
@NotNull

View File

@ -1,5 +1,6 @@
package com.agileboot.domain.common.dto;
import com.agileboot.domain.ab98.user.db.Ab98UserEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -10,5 +11,8 @@ public class QyLoginDTO {
private String userid;
private String openid;
private Integer isCabinetAdmin;
private Integer qyUserId;
private String name;
private Ab98UserEntity ab98User;
}