feat(登录): 添加Ab98用户信息保存功能

在WxLoginController中新增Ab98UserApplicationService依赖,并在登录和token登录接口中添加对Ab98用户信息的保存逻辑。同时,在Ab98UserApplicationService中实现saveAb98User和saveAb98UserByToken方法,用于根据登录数据或用户信息保存或更新Ab98用户信息。
This commit is contained in:
dzq 2025-05-10 17:16:04 +08:00
parent a53ed61457
commit 4b2eaf7532
2 changed files with 93 additions and 4 deletions

View File

@ -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.ab98.user.Ab98UserApplicationService;
import com.agileboot.domain.qywx.user.QyUserApplicationService; 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;
@ -23,6 +24,7 @@ import java.util.Map;
@Api(tags = "微信登录接口") @Api(tags = "微信登录接口")
public class WxLoginController { public class WxLoginController {
private final QyUserApplicationService qyUserApplicationService; private final QyUserApplicationService qyUserApplicationService;
private final Ab98UserApplicationService ab98UserApplicationService;
@PostMapping("/logout") @PostMapping("/logout")
@ApiOperation(value = "用户退出登录") @ApiOperation(value = "用户退出登录")
@ -83,7 +85,8 @@ public class WxLoginController {
@RequestParam String token, @RequestParam String token,
@RequestParam String tel, @RequestParam String tel,
@RequestParam String vcode, @RequestParam String vcode,
@RequestParam(required = false) String userid) { @RequestParam(required = false) String userid,
@RequestParam(required = false) String openid) {
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();
@ -97,6 +100,12 @@ public class WxLoginController {
try { try {
qyUserApplicationService.saveQyUserInfoByAb98(userid, loginResponse.getOutputData(), null); qyUserApplicationService.saveQyUserInfoByAb98(userid, loginResponse.getOutputData(), null);
} catch (Exception e) {
log.error("保存汇邦云用户信息到企业用户失败: ", e);
}
try {
ab98UserApplicationService.saveAb98User(openid, loginResponse.getOutputData());
} catch (Exception e) { } catch (Exception e) {
log.error("保存汇邦云用户信息失败: ", e); log.error("保存汇邦云用户信息失败: ", e);
} }
@ -111,7 +120,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) { @RequestParam(required = false) String userid,
@RequestParam(required = false) String openid) {
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();
@ -128,9 +138,16 @@ public class WxLoginController {
try { try {
qyUserApplicationService.saveQyUserInfoByAb98(userid, null, loginUserinfo); qyUserApplicationService.saveQyUserInfoByAb98(userid, null, loginUserinfo);
} catch (Exception e) {
log.error("保存汇邦云用户信息到企业用户失败: ", e);
}
try {
ab98UserApplicationService.saveAb98UserByToken(openid, loginUserinfo);
} catch (Exception e) { } catch (Exception e) {
log.error("保存汇邦云用户信息失败: ", e); log.error("保存汇邦云用户信息失败: ", e);
} }
return ResponseDTO.ok(data); return ResponseDTO.ok(data);
} }
} }

View File

@ -1,6 +1,8 @@
package com.agileboot.domain.ab98.user; package com.agileboot.domain.ab98.user;
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.ab98.user.command.AddAb98UserCommand; import com.agileboot.domain.ab98.user.command.AddAb98UserCommand;
import com.agileboot.domain.ab98.user.command.UpdateAb98UserCommand; import com.agileboot.domain.ab98.user.command.UpdateAb98UserCommand;
@ -15,6 +17,7 @@ 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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@ -51,11 +54,80 @@ public class Ab98UserApplicationService {
} }
} }
public Ab98UserEntity getByUserId(Long userId) { public Ab98UserEntity getByUserId(String userId) {
return userService.getById(userId); return userService.getByUserid(userId);
} }
public Ab98UserEntity getByOpenid(String openid) { public Ab98UserEntity getByOpenid(String openid) {
return userService.getByOpenid(openid); return userService.getByOpenid(openid);
} }
public void saveAb98User(String openid, Ab98ApiUtil.LoginData loginData) {
Ab98UserEntity ab98UserEntity = getByUserId(loginData.getUserid());
if (ab98UserEntity != null &&
StringUtils.equals(openid, ab98UserEntity.getOpenid()) &&
StringUtils.equals(loginData.getName(), ab98UserEntity.getName())
) {
UpdateAb98UserCommand command = new UpdateAb98UserCommand();
command.setAb98UserId(ab98UserEntity.getAb98UserId());
command.setTel(loginData.getTel());
command.setSex(loginData.getSex());
command.setIdnum(loginData.getIdnum());
command.setIdcardFront(loginData.getIdcard_front());
command.setIdcardBack(loginData.getIdcard_back());
command.setFaceImg(loginData.getFace_img());
command.setAddress(loginData.getAddress());
command.setRegistered(loginData.isRegistered());
updateUser(command);
} else {
AddAb98UserCommand command = new AddAb98UserCommand();
command.setOpenid(openid);
command.setUserid(loginData.getUserid());
command.setName(loginData.getName());
command.setTel(loginData.getTel());
command.setSex(loginData.getSex());
command.setIdnum(loginData.getIdnum());
command.setIdcardFront(loginData.getIdcard_front());
command.setIdcardBack(loginData.getIdcard_back());
command.setFaceImg(loginData.getFace_img());
command.setAddress(loginData.getAddress());
command.setRegistered(loginData.isRegistered());
addUser(command);
}
}
public void saveAb98UserByToken(String openid, SsoLoginUserinfo loginUserinfo) {
Ab98UserEntity ab98UserEntity = getByUserId(String.valueOf(loginUserinfo.getId()));
if (ab98UserEntity != null &&
StringUtils.equals(openid, ab98UserEntity.getOpenid()) &&
StringUtils.equals(loginUserinfo.getName(), ab98UserEntity.getName())
) {
UpdateAb98UserCommand command = new UpdateAb98UserCommand();
command.setAb98UserId(ab98UserEntity.getAb98UserId());
command.setTel(loginUserinfo.getPhone());
command.setSex(loginUserinfo.getSex());
command.setIdnum(loginUserinfo.getIdCardNo());
command.setIdcardFront(loginUserinfo.getIdCardFront());
command.setIdcardBack(loginUserinfo.getIdCardBack());
command.setFaceImg(loginUserinfo.getFace());
command.setAddress(loginUserinfo.getAddress());
command.setRegistered(true);
updateUser(command);
} else {
AddAb98UserCommand command = new AddAb98UserCommand();
command.setOpenid(openid);
command.setUserid(String.valueOf(loginUserinfo.getId()));
command.setName(loginUserinfo.getName());
command.setTel(loginUserinfo.getPhone());
command.setSex(loginUserinfo.getSex());
command.setIdnum(loginUserinfo.getIdCardNo());
command.setIdcardFront(loginUserinfo.getIdCardFront());
command.setIdcardBack(loginUserinfo.getIdCardBack());
command.setFaceImg(loginUserinfo.getFace());
command.setAddress(loginUserinfo.getAddress());
command.setRegistered(true);
addUser(command);
}
}
} }