feat:第三方用户查询
This commit is contained in:
1 parent
5a041ecaf5
commit
5be5a6da83
12 files changed
+352
-29
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package com.bx.implatform.controller.third;
|
||||
|
||||
import com.bx.implatform.dto.third.ThirdCreateOrUpdateUserDTO;
|
||||
import com.bx.implatform.dto.third.ThirdGetUserByUserIdDTO;
|
||||
import com.bx.implatform.dto.third.ThirdLoginDTO;
|
||||
import com.bx.implatform.result.Result;
|
||||
import com.bx.implatform.result.ResultUtils;
|
||||
import com.bx.implatform.service.third.ThirdUserService;
|
||||
import com.bx.implatform.vo.third.ThirdGetUserByUserIdVo;
|
||||
import com.bx.implatform.vo.third.ThirdLoginVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "第三方/用户")
|
||||
@RequiredArgsConstructor
|
||||
public class ThirdUserController {
|
||||
|
||||
private final ThirdUserService thirdUserService;
|
||||
|
||||
@PostMapping("/login")
|
||||
@Operation(summary = "用户登录", description = "用户登录")
|
||||
public Result<ThirdLoginVO> login(@Valid @RequestBody ThirdLoginDTO dto) {
|
||||
ThirdLoginVO vo = thirdUserService.login(dto);
|
||||
return ResultUtils.success(vo);
|
||||
}
|
||||
|
||||
@PostMapping("/getUserByUserId")
|
||||
@Operation(summary = "根据userId查询用户详情", description = "根据userId查询用户详情")
|
||||
public Result<ThirdGetUserByUserIdVo> getUserByUserId(@Valid @RequestBody ThirdGetUserByUserIdDTO dto) {
|
||||
return ResultUtils.success(thirdUserService.getUserByUserId(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/createOrUpdate")
|
||||
@Operation(summary = "创建或者更新用户", description = "创建或者更新用户")
|
||||
public Result createOrUpdate(@Valid @RequestBody ThirdCreateOrUpdateUserDTO dto) {
|
||||
thirdUserService.createOrUpdate(dto);
|
||||
return ResultUtils.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.bx.implatform.dto.third;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
@Data
|
||||
@Schema(description = "third用户注册DTO")
|
||||
public class ThirdCreateOrUpdateUserDTO {
|
||||
|
||||
@NotEmpty(message = "用户id不可为空")
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Length(max = 20, message = "用户名不能大于20字符")
|
||||
@NotEmpty(message = "用户名不可为空")
|
||||
@Schema(description = "用户名")
|
||||
private String userName;
|
||||
|
||||
@NotEmpty(message = "用户手机号不可为空")
|
||||
@Schema(description = "用户手机号")
|
||||
private String phone;
|
||||
|
||||
@Length(min = 5, max = 20, message = "密码长度必须在5-20个字符之间")
|
||||
@NotEmpty(message = "用户密码不可为空")
|
||||
@Schema(description = "用户密码")
|
||||
private String password;
|
||||
|
||||
@Length(max = 20, message = "昵称不能大于20字符")
|
||||
@Schema(description = "用户昵称")
|
||||
private String nickName;
|
||||
|
||||
@Schema(description = "用户头像")
|
||||
private String avatar;
|
||||
|
||||
public String generatePassword() {
|
||||
return phone + "_123";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.bx.implatform.dto.third;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "根据userId查询用户详情")
|
||||
public class ThirdGetUserByUserIdDTO {
|
||||
|
||||
@NotNull(message = "用户id不能为空")
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.bx.implatform.dto.third;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "third用户登录DTO")
|
||||
public class ThirdLoginDTO {
|
||||
|
||||
@Max(value = 2, message = "登录终端类型取值范围:0,2")
|
||||
@Min(value = 0, message = "登录终端类型取值范围:0,2")
|
||||
@NotNull(message = "登录终端类型不可为空")
|
||||
@Schema(description = "登录终端 0:web 1:app 2:pc")
|
||||
private Integer terminal;
|
||||
|
||||
@NotEmpty(message = "用户id不存在")
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.bx.implatform.service.third;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bx.implatform.dto.third.ThirdCreateOrUpdateUserDTO;
|
||||
import com.bx.implatform.dto.third.ThirdGetUserByUserIdDTO;
|
||||
import com.bx.implatform.dto.third.ThirdLoginDTO;
|
||||
import com.bx.implatform.entity.User;
|
||||
import com.bx.implatform.vo.third.ThirdGetUserByUserIdVo;
|
||||
import com.bx.implatform.vo.third.ThirdLoginVO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
public interface ThirdUserService extends IService<User> {
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
ThirdLoginVO login(@Valid ThirdLoginDTO dto);
|
||||
|
||||
/**
|
||||
* 创建或者更新用户
|
||||
*/
|
||||
void createOrUpdate(@Valid ThirdCreateOrUpdateUserDTO dto);
|
||||
|
||||
/**
|
||||
* 根据userId查询用户详情
|
||||
*/
|
||||
ThirdGetUserByUserIdVo getUserByUserId(@Valid ThirdGetUserByUserIdDTO dto);
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.bx.implatform.service.third.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bx.imcommon.util.JwtUtil;
|
||||
import com.bx.implatform.config.props.JwtProperties;
|
||||
import com.bx.implatform.dto.third.ThirdCreateOrUpdateUserDTO;
|
||||
import com.bx.implatform.dto.third.ThirdGetUserByUserIdDTO;
|
||||
import com.bx.implatform.dto.third.ThirdLoginDTO;
|
||||
import com.bx.implatform.entity.User;
|
||||
import com.bx.implatform.exception.GlobalException;
|
||||
import com.bx.implatform.mapper.UserMapper;
|
||||
import com.bx.implatform.service.third.ThirdUserService;
|
||||
import com.bx.implatform.session.UserSession;
|
||||
import com.bx.implatform.util.BeanUtils;
|
||||
import com.bx.implatform.vo.third.ThirdGetUserByUserIdVo;
|
||||
import com.bx.implatform.vo.third.ThirdLoginVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 第三方用户
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ThirdUserServiceImpl extends ServiceImpl<UserMapper, User> implements ThirdUserService {
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtProperties jwtProperties;
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
@Override
|
||||
public ThirdLoginVO login(ThirdLoginDTO dto) {
|
||||
User user = baseMapper.selectById(dto.getUserId());
|
||||
if (ObjectUtil.isEmpty(user)) {
|
||||
throw new GlobalException("用户不存在");
|
||||
}
|
||||
// 生成token
|
||||
UserSession session = BeanUtils.copyProperties(user, UserSession.class);
|
||||
session.setUserId(user.getId());
|
||||
session.setTerminal(dto.getTerminal());
|
||||
String strJson = JSON.toJSONString(session);
|
||||
String accessToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getAccessTokenExpireIn(),
|
||||
jwtProperties.getAccessTokenSecret());
|
||||
String refreshToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getRefreshTokenExpireIn(),
|
||||
jwtProperties.getRefreshTokenSecret());
|
||||
ThirdLoginVO vo = new ThirdLoginVO();
|
||||
vo.setAccessToken(accessToken);
|
||||
vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn());
|
||||
vo.setRefreshToken(refreshToken);
|
||||
vo.setRefreshTokenExpiresIn(jwtProperties.getRefreshTokenExpireIn());
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建或者更新用户
|
||||
*/
|
||||
@Override
|
||||
public void createOrUpdate(ThirdCreateOrUpdateUserDTO dto) {
|
||||
// 查询用户
|
||||
User user = baseMapper.selectById(dto.getUserId());
|
||||
User saveObjUser = new User();
|
||||
saveObjUser.setId(dto.getUserId());
|
||||
saveObjUser.setUserName(dto.getUserName());
|
||||
saveObjUser.setNickName(dto.getNickName());
|
||||
saveObjUser.setHeadImage(dto.getAvatar());
|
||||
saveObjUser.setHeadImageThumb(dto.getAvatar());
|
||||
if (ObjectUtil.isEmpty(user)) {
|
||||
// 创建用户
|
||||
saveObjUser.setPassword(passwordEncoder.encode(dto.getPassword()));
|
||||
baseMapper.insert(saveObjUser);
|
||||
} else {
|
||||
// 更新用户
|
||||
baseMapper.updateById(saveObjUser);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据userId查询用户详情
|
||||
*/
|
||||
@Override
|
||||
public ThirdGetUserByUserIdVo getUserByUserId(ThirdGetUserByUserIdDTO dto) {
|
||||
User user = baseMapper.selectById(dto.getUserId());
|
||||
return BeanUtils.copyProperties(user, ThirdGetUserByUserIdVo.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.bx.implatform.vo.third;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
@Data
|
||||
@Schema(description = "third根据userId查询用户详情VO")
|
||||
public class ThirdGetUserByUserIdVo {
|
||||
|
||||
@NotNull(message = "用户id不能为空")
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@NotEmpty(message = "用户名不能为空")
|
||||
@Length(max = 20, message = "用户名不能大于20字符")
|
||||
@Schema(description = "用户名")
|
||||
private String userName;
|
||||
|
||||
@NotEmpty(message = "用户昵称不能为空")
|
||||
@Length(max = 20, message = "昵称不能大于20字符")
|
||||
@Schema(description = "用户昵称")
|
||||
private String nickName;
|
||||
|
||||
@Schema(description = "性别")
|
||||
private Integer sex;
|
||||
|
||||
@Schema(description = "用户类型 1:普通用户 2:审核账户")
|
||||
private Integer type;
|
||||
|
||||
@Length(max = 128, message = "个性签名不能大于128个字符")
|
||||
@Schema(description = "个性签名")
|
||||
private String signature;
|
||||
|
||||
@Schema(description = "头像")
|
||||
private String headImage;
|
||||
|
||||
@Schema(description = "头像缩略图")
|
||||
private String headImageThumb;
|
||||
|
||||
@Schema(description = "是否在线")
|
||||
private Boolean online;
|
||||
|
||||
@Schema(description = "账号是否被封禁")
|
||||
private Boolean isBanned;
|
||||
|
||||
@Schema(description = "被封禁原因")
|
||||
private String reason;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.bx.implatform.vo.third;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "third用户登录VO")
|
||||
public class ThirdLoginVO {
|
||||
|
||||
@Schema(description = "每次请求都必须在header中携带accessToken")
|
||||
private String accessToken;
|
||||
|
||||
@Schema(description = "accessToken过期时间(秒)")
|
||||
private Integer accessTokenExpiresIn;
|
||||
|
||||
@Schema(description = "accessToken过期后,通过refreshToken换取新的token")
|
||||
private String refreshToken;
|
||||
|
||||
@Schema(description = "refreshToken过期时间(秒)")
|
||||
private Integer refreshTokenExpiresIn;
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ server:
|
||||
port: 8888
|
||||
spring:
|
||||
profiles:
|
||||
active: prod # 环境 dev|test|prod
|
||||
active: dev # 环境 dev|test|prod
|
||||
application:
|
||||
name: im-platform
|
||||
mvc:
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: prod
|
||||
active: dev
|
||||
application:
|
||||
name: im-server
|
||||
|
||||
websocket:
|
||||
enable: true
|
||||
port: 8878
|
||||
port: 8876
|
||||
# port: 8878
|
||||
|
||||
tcpsocket:
|
||||
enable: false # 暂时不开启
|
||||
|
||||
+26
-26
@@ -1,27 +1,27 @@
|
||||
//设置环境(打包前修改此变量)
|
||||
const ENV = "DEV";
|
||||
const UNI_APP = {}
|
||||
// 表情包路径
|
||||
UNI_APP.EMO_URL = "/static/emoji/";
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序的本地表情包经常莫名失效,建议将表情放到服务器中
|
||||
// UNI_APP.EMO_URL = "https://www.boxim.online/emoji/";
|
||||
// #endif
|
||||
|
||||
if(ENV=="DEV"){
|
||||
// UNI_APP.BASE_URL = "http://127.0.0.1:8888";
|
||||
// UNI_APP.WS_URL = "ws://127.0.0.1:8878/im";
|
||||
|
||||
UNI_APP.BASE_URL = "http://chatsever.zianxin.com"
|
||||
UNI_APP.WS_URL = "ws://chatapp.zianxin.com/im"
|
||||
|
||||
// H5 走本地代理解决跨域问题
|
||||
// #ifdef H5
|
||||
UNI_APP.BASE_URL = "/api";
|
||||
// #endif
|
||||
}
|
||||
if(ENV=="PROD"){
|
||||
UNI_APP.BASE_URL = "https://www.boxim.online/api";
|
||||
UNI_APP.WS_URL = "wss://www.boxim.online/im";
|
||||
}
|
||||
//设置环境(打包前修改此变量)
|
||||
const ENV = "DEV";
|
||||
const UNI_APP = {}
|
||||
// 表情包路径
|
||||
UNI_APP.EMO_URL = "/static/emoji/";
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序的本地表情包经常莫名失效,建议将表情放到服务器中
|
||||
// UNI_APP.EMO_URL = "https://www.boxim.online/emoji/";
|
||||
// #endif
|
||||
|
||||
if (ENV == "DEV") {
|
||||
// UNI_APP.BASE_URL = "http://127.0.0.1:8888";
|
||||
|
||||
UNI_APP.BASE_URL = "http://chatsever.zianxin.com"
|
||||
// UNI_APP.WS_URL = "ws://chatapp.zianxin.com/im"
|
||||
UNI_APP.WS_URL = "ws://127.0.0.1:8876/im";
|
||||
|
||||
// H5 走本地代理解决跨域问题
|
||||
// #ifdef H5
|
||||
UNI_APP.BASE_URL = "/api";
|
||||
// #endif
|
||||
}
|
||||
if (ENV == "PROD") {
|
||||
UNI_APP.BASE_URL = "https://www.boxim.online/api";
|
||||
UNI_APP.WS_URL = "wss://www.boxim.online/im";
|
||||
}
|
||||
export default UNI_APP
|
||||
@@ -471,6 +471,7 @@ export default defineStore('chatStore', {
|
||||
chatsData.chats.push(chat);
|
||||
})
|
||||
}
|
||||
console.log("chatsData:",chatsData);
|
||||
this.initChats(chatsData);
|
||||
}
|
||||
resolve()
|
||||
|
||||
Reference in new issue
Block a user