|
|
@ -4,12 +4,10 @@ import cn.hutool.core.lang.UUID;
|
|
|
|
import cn.teammodel.common.ErrorCode;
|
|
|
|
import cn.teammodel.common.ErrorCode;
|
|
|
|
import cn.teammodel.common.PK;
|
|
|
|
import cn.teammodel.common.PK;
|
|
|
|
import cn.teammodel.config.exception.ServiceException;
|
|
|
|
import cn.teammodel.config.exception.ServiceException;
|
|
|
|
import cn.teammodel.repository.ChatSessionRepository;
|
|
|
|
|
|
|
|
import cn.teammodel.model.dto.ai.UpdateSessionDto;
|
|
|
|
import cn.teammodel.model.dto.ai.UpdateSessionDto;
|
|
|
|
import cn.teammodel.model.entity.User;
|
|
|
|
|
|
|
|
import cn.teammodel.model.entity.ai.ChatSession;
|
|
|
|
import cn.teammodel.model.entity.ai.ChatSession;
|
|
|
|
import cn.teammodel.model.entity.ai.ChatSession.Message;
|
|
|
|
import cn.teammodel.model.entity.ai.ChatSession.Message;
|
|
|
|
import cn.teammodel.security.utils.SecurityUtil;
|
|
|
|
import cn.teammodel.repository.ChatSessionRepository;
|
|
|
|
import cn.teammodel.service.ChatSessionService;
|
|
|
|
import cn.teammodel.service.ChatSessionService;
|
|
|
|
import cn.teammodel.utils.RepositoryUtil;
|
|
|
|
import cn.teammodel.utils.RepositoryUtil;
|
|
|
|
import com.azure.cosmos.models.CosmosPatchOperations;
|
|
|
|
import com.azure.cosmos.models.CosmosPatchOperations;
|
|
|
@ -36,10 +34,11 @@ public class ChatSessionServiceImpl implements ChatSessionService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String createSession() {
|
|
|
|
public String createSession() {
|
|
|
|
User user = SecurityUtil.getLoginUser();
|
|
|
|
// todo User user = SecurityUtil.getLoginUser(); || 2. user.getName()
|
|
|
|
String userId = user.getId();
|
|
|
|
// String userId = user.getId();
|
|
|
|
|
|
|
|
String userId = "1595321354";
|
|
|
|
// 初始化欢迎语
|
|
|
|
// 初始化欢迎语
|
|
|
|
Message message = Message.of("", "你好" + user.getName() + " ,我是你的私人 AI 助手小豆,你可以问我任何包括但不仅限于教育的问题,我会尽力为您解答!");
|
|
|
|
Message message = Message.of("", "你好" + "罗老师" + " ,我是你的私人 AI 助手小豆,你可以问我任何包括但不仅限于教育的问题,我会尽力为您解答!");
|
|
|
|
List<Message> history = Collections.singletonList(message);
|
|
|
|
List<Message> history = Collections.singletonList(message);
|
|
|
|
ChatSession chatSession = new ChatSession();
|
|
|
|
ChatSession chatSession = new ChatSession();
|
|
|
|
chatSession.setId(UUID.randomUUID().toString());
|
|
|
|
chatSession.setId(UUID.randomUUID().toString());
|
|
|
@ -54,7 +53,8 @@ public class ChatSessionServiceImpl implements ChatSessionService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<ChatSession> listMySession() {
|
|
|
|
public List<ChatSession> listMySession() {
|
|
|
|
String userId = SecurityUtil.getUserId();
|
|
|
|
// String userId = SecurityUtil.getUserId();
|
|
|
|
|
|
|
|
String userId = "1595321354";
|
|
|
|
List<ChatSession> sessions = chatSessionRepository.findByUserId(userId);
|
|
|
|
List<ChatSession> sessions = chatSessionRepository.findByUserId(userId);
|
|
|
|
// 按更新时间排序
|
|
|
|
// 按更新时间排序
|
|
|
|
if (ObjectUtils.isNotEmpty(sessions)) {
|
|
|
|
if (ObjectUtils.isNotEmpty(sessions)) {
|
|
|
@ -67,8 +67,9 @@ public class ChatSessionServiceImpl implements ChatSessionService {
|
|
|
|
public ChatSession updateSession(UpdateSessionDto updateSessionDto) {
|
|
|
|
public ChatSession updateSession(UpdateSessionDto updateSessionDto) {
|
|
|
|
String id = updateSessionDto.getId();
|
|
|
|
String id = updateSessionDto.getId();
|
|
|
|
String title = updateSessionDto.getTitle();
|
|
|
|
String title = updateSessionDto.getTitle();
|
|
|
|
User user = SecurityUtil.getLoginUser();
|
|
|
|
// User user = SecurityUtil.getLoginUser();
|
|
|
|
String userId = user.getId();
|
|
|
|
// String userId = user.getId();
|
|
|
|
|
|
|
|
String userId = "1595321354";
|
|
|
|
|
|
|
|
|
|
|
|
ChatSession session = RepositoryUtil.findOne(chatSessionRepository.findBySessionId(id), "");
|
|
|
|
ChatSession session = RepositoryUtil.findOne(chatSessionRepository.findBySessionId(id), "");
|
|
|
|
if (!session.getUserId().equals(userId)) {
|
|
|
|
if (!session.getUserId().equals(userId)) {
|
|
|
@ -82,8 +83,9 @@ public class ChatSessionServiceImpl implements ChatSessionService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteSession(String id) {
|
|
|
|
public void deleteSession(String id) {
|
|
|
|
User user = SecurityUtil.getLoginUser();
|
|
|
|
// User user = SecurityUtil.getLoginUser();
|
|
|
|
String userId = user.getId();
|
|
|
|
// String userId = user.getId();
|
|
|
|
|
|
|
|
String userId = "1595321354";
|
|
|
|
ChatSession session = RepositoryUtil.findOne(chatSessionRepository.findBySessionId(id), "该会话不存在");
|
|
|
|
ChatSession session = RepositoryUtil.findOne(chatSessionRepository.findBySessionId(id), "该会话不存在");
|
|
|
|
// 鉴权
|
|
|
|
// 鉴权
|
|
|
|
if (!session.getUserId().equals(userId)) {
|
|
|
|
if (!session.getUserId().equals(userId)) {
|
|
|
@ -94,8 +96,8 @@ public class ChatSessionServiceImpl implements ChatSessionService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Message> listMyHistory(String sessionId) {
|
|
|
|
public List<Message> listMyHistory(String sessionId) {
|
|
|
|
User user = SecurityUtil.getLoginUser();
|
|
|
|
// User user = SecurityUtil.getLoginUser();
|
|
|
|
String userId = user.getId();
|
|
|
|
String userId = "1595321354";
|
|
|
|
ChatSession session = chatSessionRepository.findChatSessionByIdAndCode(sessionId, PK.CHAT_SESSION);
|
|
|
|
ChatSession session = chatSessionRepository.findChatSessionByIdAndCode(sessionId, PK.CHAT_SESSION);
|
|
|
|
if (!userId.equals(session.getUserId())) {
|
|
|
|
if (!userId.equals(session.getUserId())) {
|
|
|
|
throw new ServiceException(ErrorCode.NO_AUTH_ERROR);
|
|
|
|
throw new ServiceException(ErrorCode.NO_AUTH_ERROR);
|
|
|
|