1、简化接口地址
2、增加账号密码登录功能 3、增加退出账号功能 4、其他优化
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
package com.hula.service;
|
package com.hula.service;
|
||||||
|
|
||||||
import com.hula.annotation.SecureInvoke;
|
import com.hula.annotation.SecureInvoke;
|
||||||
import org.springframework.messaging.Message;
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.support.MessageBuilder;
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23,11 +23,14 @@ public class InterceptorConfig implements WebMvcConfigurer {
|
|||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
registry.addInterceptor(tokenInterceptor)
|
registry.addInterceptor(tokenInterceptor)
|
||||||
.addPathPatterns("/api/**");
|
.addPathPatterns("/**")
|
||||||
|
.excludePathPatterns("/wx/**");
|
||||||
registry.addInterceptor(collectorInterceptor)
|
registry.addInterceptor(collectorInterceptor)
|
||||||
.addPathPatterns("/api/**");
|
.addPathPatterns("/**")
|
||||||
|
.excludePathPatterns("/wx/**");
|
||||||
registry.addInterceptor(blackInterceptor)
|
registry.addInterceptor(blackInterceptor)
|
||||||
.addPathPatterns("/api/**");
|
.addPathPatterns("/**")
|
||||||
|
.excludePathPatterns("/wx/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.hula.common.interceptor;
|
package com.hula.common.interceptor;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.hula.domain.dto.RequestInfo;
|
|
||||||
import com.hula.utils.RequestHolder;
|
|
||||||
import com.hula.core.user.domain.enums.BlackTypeEnum;
|
import com.hula.core.user.domain.enums.BlackTypeEnum;
|
||||||
import com.hula.core.user.service.cache.UserCache;
|
import com.hula.core.user.service.cache.UserCache;
|
||||||
|
import com.hula.domain.dto.RequestInfo;
|
||||||
import com.hula.enums.HttpErrorEnum;
|
import com.hula.enums.HttpErrorEnum;
|
||||||
|
import com.hula.utils.RequestHolder;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ import com.hula.core.chat.service.cache.HotRoomCache;
|
|||||||
import com.hula.core.chat.service.cache.RoomCache;
|
import com.hula.core.chat.service.cache.RoomCache;
|
||||||
import com.hula.core.user.service.adapter.WSAdapter;
|
import com.hula.core.user.service.adapter.WSAdapter;
|
||||||
import com.hula.core.user.service.impl.PushService;
|
import com.hula.core.user.service.impl.PushService;
|
||||||
|
import com.hula.utils.RequestHolder;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.apache.rocketmq.spring.annotation.MessageModel;
|
||||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||||
import org.apache.rocketmq.spring.core.RocketMQListener;
|
import org.apache.rocketmq.spring.core.RocketMQListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -32,14 +34,14 @@ import java.util.Objects;
|
|||||||
* 发送消息更新房间收信箱,并同步给房间成员信箱
|
* 发送消息更新房间收信箱,并同步给房间成员信箱
|
||||||
* @author nyh
|
* @author nyh
|
||||||
*/
|
*/
|
||||||
@RocketMQMessageListener(consumerGroup = MQConstant.SEND_MSG_GROUP, topic = MQConstant.SEND_MSG_TOPIC)
|
@RocketMQMessageListener(consumerGroup = MQConstant.SEND_MSG_GROUP, topic = MQConstant.SEND_MSG_TOPIC, messageModel = MessageModel.BROADCASTING)
|
||||||
@Component
|
@Component
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class MsgSendConsumer implements RocketMQListener<MsgSendMessageDTO> {
|
public class MsgSendConsumer implements RocketMQListener<MsgSendMessageDTO> {
|
||||||
|
|
||||||
private ChatService chatService;
|
private ChatService chatService;
|
||||||
private MessageDao messageDao;
|
private MessageDao messageDao;
|
||||||
WeChatMsgOperationService weChatMsgOperationService;
|
private WeChatMsgOperationService weChatMsgOperationService;
|
||||||
private RoomCache roomCache;
|
private RoomCache roomCache;
|
||||||
private RoomDao roomDao;
|
private RoomDao roomDao;
|
||||||
private GroupMemberCache groupMemberCache;
|
private GroupMemberCache groupMemberCache;
|
||||||
@@ -51,6 +53,9 @@ public class MsgSendConsumer implements RocketMQListener<MsgSendMessageDTO> {
|
|||||||
@Override
|
@Override
|
||||||
public void onMessage(MsgSendMessageDTO dto) {
|
public void onMessage(MsgSendMessageDTO dto) {
|
||||||
Message message = messageDao.getById(dto.getMsgId());
|
Message message = messageDao.getById(dto.getMsgId());
|
||||||
|
if (Objects.isNull(message)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Room room = roomCache.get(message.getRoomId());
|
Room room = roomCache.get(message.getRoomId());
|
||||||
ChatMessageResp msgResp = chatService.getMsgResp(message, null);
|
ChatMessageResp msgResp = chatService.getMsgResp(message, null);
|
||||||
//所有房间更新房间最新消息
|
//所有房间更新房间最新消息
|
||||||
@@ -65,8 +70,8 @@ public class MsgSendConsumer implements RocketMQListener<MsgSendMessageDTO> {
|
|||||||
} else {
|
} else {
|
||||||
List<Long> memberUidList = new ArrayList<>();
|
List<Long> memberUidList = new ArrayList<>();
|
||||||
if (Objects.equals(room.getType(), RoomTypeEnum.GROUP.getType())) {
|
if (Objects.equals(room.getType(), RoomTypeEnum.GROUP.getType())) {
|
||||||
//普通群聊推送所有群成员
|
// 普通群聊推送所有群成员,过滤掉当前用户
|
||||||
memberUidList = groupMemberCache.getMemberUidList(room.getId());
|
memberUidList = groupMemberCache.getMemberUidList(room.getId()).stream().filter(uid->!RequestHolder.get().getUid().equals(uid)).toList();
|
||||||
} else if (Objects.equals(room.getType(), RoomTypeEnum.FRIEND.getType())) {
|
} else if (Objects.equals(room.getType(), RoomTypeEnum.FRIEND.getType())) {
|
||||||
//单聊对象
|
//单聊对象
|
||||||
//对单人推送
|
//对单人推送
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import java.util.Set;
|
|||||||
* @author nyh
|
* @author nyh
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/chat")
|
@RequestMapping("/chat")
|
||||||
@Tag(name = "聊天室相关接口")
|
@Tag(name = "聊天室相关接口")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ChatController {
|
public class ChatController {
|
||||||
@@ -56,6 +56,7 @@ public class ChatController {
|
|||||||
|
|
||||||
@PostMapping("/msg")
|
@PostMapping("/msg")
|
||||||
@Operation(summary ="发送消息")
|
@Operation(summary ="发送消息")
|
||||||
|
//@FrequencyControl(target = FrequencyControl.Target.UID, time = 1, count = 2)
|
||||||
public ApiResult<ChatMessageResp> sendMsg(@Valid @RequestBody ChatMessageReq request) {
|
public ApiResult<ChatMessageResp> sendMsg(@Valid @RequestBody ChatMessageReq request) {
|
||||||
Long msgId = chatService.sendMsg(request, RequestHolder.get().getUid());
|
Long msgId = chatService.sendMsg(request, RequestHolder.get().getUid());
|
||||||
//返回完整消息格式,方便前端展示
|
//返回完整消息格式,方便前端展示
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
* @author nyh
|
* @author nyh
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/chat")
|
@RequestMapping("/chat")
|
||||||
@Tag(name = "聊天室相关接口")
|
@Tag(name = "聊天室相关接口")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ContactController {
|
public class ContactController {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import java.util.List;
|
|||||||
* @author nyh
|
* @author nyh
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/room")
|
@RequestMapping("/room")
|
||||||
@Tag(name = "聊天室相关接口")
|
@Tag(name = "聊天室相关接口")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RoomController {
|
public class RoomController {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
check(request, uid);
|
check(request, uid);
|
||||||
AbstractMsgHandler<?> msgHandler = MsgHandlerFactory.getStrategyNoNull(request.getMsgType());
|
AbstractMsgHandler<?> msgHandler = MsgHandlerFactory.getStrategyNoNull(request.getMsgType());
|
||||||
Long msgId = msgHandler.checkAndSaveMsg(request, uid);
|
Long msgId = msgHandler.checkAndSaveMsg(request, uid);
|
||||||
//发布消息发送事件
|
// 发布消息发送事件
|
||||||
applicationEventPublisher.publishEvent(new MessageSendEvent(this, msgId));
|
applicationEventPublisher.publishEvent(new MessageSendEvent(this, msgId));
|
||||||
return msgId;
|
return msgId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class RoomAppServiceImpl implements RoomAppService {
|
|||||||
public ChatRoomResp getContactDetailByFriend(Long uid, Long friendUid) {
|
public ChatRoomResp getContactDetailByFriend(Long uid, Long friendUid) {
|
||||||
RoomFriend friendRoom = roomService.getFriendRoom(uid, friendUid);
|
RoomFriend friendRoom = roomService.getFriendRoom(uid, friendUid);
|
||||||
AssertUtil.isNotEmpty(friendRoom, "他不是您的好友");
|
AssertUtil.isNotEmpty(friendRoom, "他不是您的好友");
|
||||||
return buildContactResp(uid, Collections.singletonList(friendRoom.getRoomId())).get(0);
|
return buildContactResp(uid, Collections.singletonList(friendRoom.getRoomId())).getFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
* @author nyh
|
* @author nyh
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/user/friend")
|
@RequestMapping("/user/friend")
|
||||||
@Tag(name = "好友相关接口")
|
@Tag(name = "好友相关接口")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class FriendController {
|
public class FriendController {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
* @author nyh
|
* @author nyh
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/oss")
|
@RequestMapping("/oss")
|
||||||
@Api(tags = "oss相关接口")
|
@Api(tags = "oss相关接口")
|
||||||
public class OssController {
|
public class OssController {
|
||||||
@Resource
|
@Resource
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.hula.core.user.controller;
|
|||||||
|
|
||||||
import com.hula.core.user.domain.entity.User;
|
import com.hula.core.user.domain.entity.User;
|
||||||
import com.hula.core.user.domain.vo.req.user.LoginReq;
|
import com.hula.core.user.domain.vo.req.user.LoginReq;
|
||||||
|
import com.hula.core.user.domain.vo.req.user.RegisterReq;
|
||||||
import com.hula.core.user.service.LoginService;
|
import com.hula.core.user.service.LoginService;
|
||||||
import com.hula.core.user.service.UserService;
|
import com.hula.core.user.service.UserService;
|
||||||
import com.hula.domain.vo.res.ApiResult;
|
import com.hula.domain.vo.res.ApiResult;
|
||||||
@@ -10,7 +11,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -30,14 +31,39 @@ public class TokenController {
|
|||||||
@Resource
|
@Resource
|
||||||
private LoginService loginService;
|
private LoginService loginService;
|
||||||
|
|
||||||
@GetMapping("/login")
|
@PostMapping("/login")
|
||||||
@Operation(summary ="用户详情")
|
@Operation(summary ="用户登录")
|
||||||
public ApiResult<String> login(@Valid @RequestBody LoginReq loginReq) {
|
public ApiResult<String> login(@Valid @RequestBody LoginReq loginReq) {
|
||||||
User user = userService.login(loginReq);
|
User user = userService.login(loginReq);
|
||||||
String token = loginService.login(user.getId());
|
String token = loginService.login(user.getId());
|
||||||
return ApiResult.success(token);
|
return ApiResult.success(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/logout")
|
||||||
|
@Operation(summary ="用户登录")
|
||||||
|
public ApiResult<Boolean> logout() {
|
||||||
|
loginService.logout();
|
||||||
|
return ApiResult.success(Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/register")
|
||||||
|
@Operation(summary ="用户注册")
|
||||||
|
public ApiResult<String> register(@Valid @RequestBody RegisterReq registerReq) {
|
||||||
|
userService.register(User.builder()
|
||||||
|
.account(registerReq.getAccount())
|
||||||
|
.password(registerReq.getPassword())
|
||||||
|
.name(registerReq.getName()).build());
|
||||||
|
return ApiResult.success(registerReq.getAccount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/check")
|
||||||
|
@Operation(summary ="用户验证是否过期")
|
||||||
|
public ApiResult<Boolean> check() {
|
||||||
|
// 延长token时间
|
||||||
|
loginService.refreshToken();
|
||||||
|
return ApiResult.success(Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import java.util.List;
|
|||||||
* @author nyh
|
* @author nyh
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/user")
|
@RequestMapping("/user")
|
||||||
@Tag(name = "用户管理")
|
@Tag(name = "用户管理")
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import java.util.List;
|
|||||||
* @author nyh
|
* @author nyh
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/user/emoji")
|
@RequestMapping("/user/emoji")
|
||||||
@Api(tags = "用户表情包管理相关接口")
|
@Api(tags = "用户表情包管理相关接口")
|
||||||
public class UserEmojiController {
|
public class UserEmojiController {
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,16 @@ import lombok.NoArgsConstructor;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class ItemInfoDTO {
|
public class ItemInfoDTO {
|
||||||
|
|
||||||
@ApiModelProperty(value = "徽章id")
|
@ApiModelProperty(value = "徽章id")
|
||||||
private Long itemId;
|
private Long itemId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "是否需要刷新")
|
@ApiModelProperty(value = "是否需要刷新")
|
||||||
private Boolean needRefresh = Boolean.TRUE;
|
private Boolean needRefresh = Boolean.TRUE;
|
||||||
|
|
||||||
@ApiModelProperty("徽章图像")
|
@ApiModelProperty("徽章图像")
|
||||||
private String img;
|
private String img;
|
||||||
|
|
||||||
@ApiModelProperty("徽章说明")
|
@ApiModelProperty("徽章说明")
|
||||||
private String describe;
|
private String describe;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.hula.core.user.domain.dto;
|
package com.hula.core.user.domain.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -13,6 +12,7 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户名
|
* 修改用户名
|
||||||
|
*
|
||||||
* @author nyh
|
* @author nyh
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@@ -21,6 +21,8 @@ import java.util.List;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class SummeryInfoDTO {
|
public class SummeryInfoDTO {
|
||||||
|
@Schema(description = "用户拥有的徽章id列表")
|
||||||
|
List<Long> itemIds;
|
||||||
@Schema(description = "用户id")
|
@Schema(description = "用户id")
|
||||||
private Long uid;
|
private Long uid;
|
||||||
@Schema(description = "是否需要刷新")
|
@Schema(description = "是否需要刷新")
|
||||||
@@ -31,10 +33,8 @@ public class SummeryInfoDTO {
|
|||||||
private String avatar;
|
private String avatar;
|
||||||
@Schema(description = "归属地")
|
@Schema(description = "归属地")
|
||||||
private String locPlace;
|
private String locPlace;
|
||||||
@Schema(description ="佩戴的徽章id")
|
@Schema(description = "佩戴的徽章id")
|
||||||
private Long wearingItemId;
|
private Long wearingItemId;
|
||||||
@Schema(description = "用户拥有的徽章id列表")
|
|
||||||
List<Long> itemIds;
|
|
||||||
|
|
||||||
public static SummeryInfoDTO skip(Long uid) {
|
public static SummeryInfoDTO skip(Long uid) {
|
||||||
SummeryInfoDTO dto = new SummeryInfoDTO();
|
SummeryInfoDTO dto = new SummeryInfoDTO();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ import java.util.Date;
|
|||||||
@Schema(description = "用户表")
|
@Schema(description = "用户表")
|
||||||
public class User implements Serializable {
|
public class User implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static Long UID_SYSTEM = 1L;//系统uid
|
public static Long UID_SYSTEM = 1L;//系统uid
|
||||||
@@ -34,6 +36,18 @@ public class User implements Serializable {
|
|||||||
@TableId(value = "id", type = IdType.AUTO)
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账号
|
||||||
|
*/
|
||||||
|
@TableField("account")
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户密码
|
||||||
|
*/
|
||||||
|
@TableField("password")
|
||||||
|
private String password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户昵称
|
* 用户昵称
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public enum WSPushTypeEnum {
|
|||||||
private final Integer type;
|
private final Integer type;
|
||||||
private final String desc;
|
private final String desc;
|
||||||
|
|
||||||
private static Map<Integer, WSPushTypeEnum> cache;
|
private static final Map<Integer, WSPushTypeEnum> cache;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
cache = Arrays.stream(WSPushTypeEnum.values()).collect(Collectors.toMap(WSPushTypeEnum::getType, Function.identity()));
|
cache = Arrays.stream(WSPushTypeEnum.values()).collect(Collectors.toMap(WSPushTypeEnum::getType, Function.identity()));
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import lombok.Data;
|
|||||||
public class LoginReq {
|
public class LoginReq {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String name;
|
private String account;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String password;
|
private String password;
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.hula.core.user.domain.vo.req.user;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ZOL
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class RegisterReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户昵称
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账号
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户密码
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,14 +8,25 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class UserInfoResp {
|
public class UserInfoResp {
|
||||||
|
|
||||||
@Schema(description = "用户id")
|
@Schema(description = "用户id")
|
||||||
private Long id;
|
private Long id;
|
||||||
@Schema(description = "用户名")
|
|
||||||
|
@Schema(description = "用户账号")
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
@Schema(description = "用户密码")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Schema(description = "用户昵称")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "头像")
|
@Schema(description = "头像")
|
||||||
private String avatar;
|
private String avatar;
|
||||||
|
|
||||||
@Schema(description = "性别 1男 2女")
|
@Schema(description = "性别 1男 2女")
|
||||||
private Integer sex;
|
private Integer sex;
|
||||||
|
|
||||||
@Schema(description = "修改昵称次数")
|
@Schema(description = "修改昵称次数")
|
||||||
private Integer modifyNameChance;
|
private Integer modifyNameChance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,14 @@ public interface LoginService {
|
|||||||
* 如果token有效,返回uid
|
* 如果token有效,返回uid
|
||||||
*/
|
*/
|
||||||
Long getValidUid(String token);
|
Long getValidUid(String token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 延长token有效期
|
||||||
|
*/
|
||||||
|
void refreshToken();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出登录
|
||||||
|
*/
|
||||||
|
void logout();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.hula.common.constant.RedisKey;
|
|||||||
import com.hula.core.user.service.LoginService;
|
import com.hula.core.user.service.LoginService;
|
||||||
import com.hula.utils.JwtUtils;
|
import com.hula.utils.JwtUtils;
|
||||||
import com.hula.utils.RedisUtils;
|
import com.hula.utils.RedisUtils;
|
||||||
|
import com.hula.utils.RequestHolder;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -76,4 +77,14 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
boolean verify = verify(token);
|
boolean verify = verify(token);
|
||||||
return verify ? jwtUtils.getUidOrNull(token) : null;
|
return verify ? jwtUtils.getUidOrNull(token) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshToken() {
|
||||||
|
RedisUtils.expire(RedisKey.getKey(RedisKey.USER_TOKEN_STRING, RequestHolder.get().getUid()), TOKEN_EXPIRE_DAYS, TimeUnit.DAYS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logout() {
|
||||||
|
RedisUtils.del(RedisKey.getKey(RedisKey.USER_TOKEN_STRING, RequestHolder.get().getUid()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,9 +111,24 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void register(User user) {
|
public void register(User user) {
|
||||||
userDao.save(user);
|
|
||||||
applicationEventPublisher.publishEvent(new UserRegisterEvent(this, user));
|
if (Objects.nonNull(user.getAccount())) {
|
||||||
|
AssertUtil.isTrue(userDao.count(new QueryWrapper<User>().lambda()
|
||||||
|
.eq(User::getAccount, user.getAccount())) <= 0, "账号已注册");
|
||||||
|
} else if(Objects.nonNull(user.getOpenId())) {
|
||||||
|
AssertUtil.isTrue(userDao.count(new QueryWrapper<User>().lambda()
|
||||||
|
.eq(User::getOpenId, user.getOpenId())) <= 0, "微信号已绑定其他账号");
|
||||||
|
}
|
||||||
|
final User newUser = User.builder()
|
||||||
|
.account(user.getAccount())
|
||||||
|
.password(user.getPassword())
|
||||||
|
.name(user.getName())
|
||||||
|
.openId(user.getOpenId())
|
||||||
|
.build();
|
||||||
|
userDao.save(newUser);
|
||||||
|
applicationEventPublisher.publishEvent(new UserRegisterEvent(this, newUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -159,7 +174,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User login(LoginReq loginReq) {
|
public User login(LoginReq loginReq) {
|
||||||
User user = userDao.getOne(new QueryWrapper<User>().lambda().eq(User::getName, loginReq.getName()));
|
User user = userDao.getOne(new QueryWrapper<User>().lambda().eq(User::getAccount, loginReq.getAccount()).eq(User::getPassword, loginReq.getPassword()));
|
||||||
AssertUtil.isNotEmpty(user, "账号或密码错误");
|
AssertUtil.isNotEmpty(user, "账号或密码错误");
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
server:
|
server:
|
||||||
port: 9190
|
port: 9190
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
org.springframework.web: INFO
|
|
||||||
com.github.binarywang.demo.wx.mp: DEBUG
|
|
||||||
me.chanjar.weixin: DEBUG
|
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
# 使用的配置文件
|
# 使用的配置文件
|
||||||
@@ -122,13 +118,5 @@ rocketmq:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
urls:
|
urls:
|
||||||
- /api/chat/public/contact/page
|
- /token/login
|
||||||
- /api/chat/public/contact/detail
|
- /token/register
|
||||||
- /api/chat/public/contact/detail/friend
|
|
||||||
- /api/chat/public/msg/page
|
|
||||||
- /api/room/public/group
|
|
||||||
- /api/room/public/group/member/page
|
|
||||||
- /api/user/public/summary/userInfo/batch
|
|
||||||
- /api/user/public/badges/batch
|
|
||||||
- /wx/portal/public/
|
|
||||||
- /wx/portal/public/callBack
|
|
||||||
|
|||||||
@@ -290,6 +290,8 @@ INSERT INTO `sensitive_word` VALUES ('tmd');
|
|||||||
DROP TABLE IF EXISTS `user`;
|
DROP TABLE IF EXISTS `user`;
|
||||||
CREATE TABLE `user` (
|
CREATE TABLE `user` (
|
||||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '用户id',
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '用户id',
|
||||||
|
`account` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '用户账号',
|
||||||
|
`password` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '用户密码',
|
||||||
`name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '用户昵称',
|
`name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '用户昵称',
|
||||||
`avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '用户头像',
|
`avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '用户头像',
|
||||||
`sex` int NULL DEFAULT NULL COMMENT '性别 1为男性,2为女性',
|
`sex` int NULL DEFAULT NULL COMMENT '性别 1为男性,2为女性',
|
||||||
@@ -302,8 +304,7 @@ CREATE TABLE `user` (
|
|||||||
`create_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
`create_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
||||||
`update_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '修改时间',
|
`update_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '修改时间',
|
||||||
PRIMARY KEY (`id`) USING BTREE,
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
UNIQUE INDEX `uniq_open_id`(`open_id` ASC) USING BTREE,
|
UNIQUE INDEX `uniq_account`(`account` ASC) USING BTREE,
|
||||||
UNIQUE INDEX `uniq_name`(`name` ASC) USING BTREE,
|
|
||||||
INDEX `idx_create_time`(`create_time` ASC) USING BTREE,
|
INDEX `idx_create_time`(`create_time` ASC) USING BTREE,
|
||||||
INDEX `idx_update_time`(`update_time` ASC) USING BTREE,
|
INDEX `idx_update_time`(`update_time` ASC) USING BTREE,
|
||||||
INDEX `idx_active_status_last_opt_time`(`active_status` ASC, `last_opt_time` ASC) USING BTREE
|
INDEX `idx_active_status_last_opt_time`(`active_status` ASC, `last_opt_time` ASC) USING BTREE
|
||||||
@@ -312,10 +313,10 @@ CREATE TABLE `user` (
|
|||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Records of user
|
-- Records of user
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
INSERT INTO `user` VALUES (1, '系统消息', 'http://mms1.baidu.com/it/u=1979830414,2984779047&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=500&h=500', NULL, '0', 2, '2023-07-01 11:58:24.605', NULL, NULL, 0, '2023-07-01 11:58:24.605', '2023-07-01 12:02:56.900');
|
INSERT INTO `user` VALUES (1, 'admin','admin','系统消息', 'http://mms1.baidu.com/it/u=1979830414,2984779047&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=500&h=500', NULL, '0', 2, '2023-07-01 11:58:24.605', NULL, NULL, 0, '2023-07-01 11:58:24.605', '2023-07-01 12:02:56.900');
|
||||||
INSERT INTO `user` VALUES (10001, 'ChatGPT', 'https://img1.baidu.com/it/u=3613958228,3522035000&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500', 0, '??', 2, '2023-06-29 17:03:03.357', NULL, NULL, 0, '2023-06-29 17:03:03.357', '2023-07-01 14:56:10.271');
|
INSERT INTO `user` VALUES (10001,'hula1','hula1', 'ChatGPT', 'https://img1.baidu.com/it/u=3613958228,3522035000&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500', 0, '??', 2, '2023-06-29 17:03:03.357', NULL, NULL, 0, '2023-06-29 17:03:03.357', '2023-07-01 14:56:10.271');
|
||||||
INSERT INTO `user` VALUES (10002, 'ChatGLM2', 'http://mms1.baidu.com/it/u=1979830414,2984779047&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=500&h=500', NULL, '450', 2, '2023-07-01 11:58:24.605', NULL, NULL, 0, '2023-07-01 11:58:24.605', '2023-07-01 12:02:56.900');
|
INSERT INTO `user` VALUES (10002,'hula2','hula2', 'ChatGLM2', 'http://mms1.baidu.com/it/u=1979830414,2984779047&fm=253&app=138&f=JPEG&fmt=auto&q=75?w=500&h=500', NULL, '450', 2, '2023-07-01 11:58:24.605', NULL, NULL, 0, '2023-07-01 11:58:24.605', '2023-07-01 12:02:56.900');
|
||||||
INSERT INTO `user` VALUES (20000, 'Dawn', 'https://thirdwx.qlogo.cn/mmopen/vi_32/PiajxSqBRaEL7OpdTZYkEeE9oTmZFKL4gIzCr1ibf38OiaPqqcmqlLxTxvw3gskZV5uTma7NSQzCk8yVbIiaN6FV3kmicBWg2CLOKicysib6mDFGEPprQxfUYEupA/132', 0, 'obxlc6xY1EsMyHbbRAAgWDCnOFHE', 1, '2024-07-10 15:09:09.086', '{\"createIp\": \"127.0.0.1\", \"updateIp\": \"127.0.0.1\", \"createIpDetail\": null, \"updateIpDetail\": null}', NULL, 0, '2024-07-10 15:08:00.607', '2024-07-10 15:09:09.096');
|
INSERT INTO `user` VALUES (20000,'hula3','hula3', 'Dawn', 'https://thirdwx.qlogo.cn/mmopen/vi_32/PiajxSqBRaEL7OpdTZYkEeE9oTmZFKL4gIzCr1ibf38OiaPqqcmqlLxTxvw3gskZV5uTma7NSQzCk8yVbIiaN6FV3kmicBWg2CLOKicysib6mDFGEPprQxfUYEupA/132', 0, 'obxlc6xY1EsMyHbbRAAgWDCnOFHE', 1, '2024-07-10 15:09:09.086', '{\"createIp\": \"127.0.0.1\", \"updateIp\": \"127.0.0.1\", \"createIpDetail\": null, \"updateIpDetail\": null}', NULL, 0, '2024-07-10 15:08:00.607', '2024-07-10 15:09:09.096');
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for user_apply
|
-- Table structure for user_apply
|
||||||
|
|||||||
Reference in New Issue
Block a user