添加对话消息记录
This commit is contained in:
@@ -1,13 +1,18 @@
|
|||||||
package org.jiayunet.controller;
|
package org.jiayunet.controller;
|
||||||
|
|
||||||
|
import org.jiayunet.pojo.dto.jobAgent.ChatMessageDto;
|
||||||
import org.jiayunet.pojo.dto.jobAgent.JobAgentConfigDto;
|
import org.jiayunet.pojo.dto.jobAgent.JobAgentConfigDto;
|
||||||
|
import org.jiayunet.pojo.param.jobAgent.ChatMessageParam;
|
||||||
import org.jiayunet.pojo.param.jobAgent.JobAgentConfigParam;
|
import org.jiayunet.pojo.param.jobAgent.JobAgentConfigParam;
|
||||||
import org.jiayunet.service.JobAgentConfigService;
|
import org.jiayunet.service.JobAgentConfigService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 求职助手配置接口
|
* 求职助手接口
|
||||||
*
|
*
|
||||||
* @author zk
|
* @author zk
|
||||||
*/
|
*/
|
||||||
@@ -33,4 +38,20 @@ public class JobAgentConfigController {
|
|||||||
public void saveConfig(@RequestBody JobAgentConfigParam param) {
|
public void saveConfig(@RequestBody JobAgentConfigParam param) {
|
||||||
configService.saveConfig(param);
|
configService.saveConfig(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加对话消息
|
||||||
|
*/
|
||||||
|
@PostMapping("/chat/message")
|
||||||
|
public void addMessage(@Validated @RequestBody ChatMessageParam param) {
|
||||||
|
configService.addMessage(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询对话消息(最近N条,按时间正序)
|
||||||
|
*/
|
||||||
|
@GetMapping("/chat/messages")
|
||||||
|
public List<ChatMessageDto> listMessages(@RequestParam(defaultValue = "50") Integer limit) {
|
||||||
|
return configService.listMessages(limit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.jiayunet.pojo.dto.jobAgent;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对话消息出参
|
||||||
|
*
|
||||||
|
* @author zk
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatMessageDto {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 消息类型:user / assistant / recommend / apply_progress */
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/** 文本内容 */
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/** 附加数据JSON */
|
||||||
|
private String extra;
|
||||||
|
|
||||||
|
/** 创建时间 */
|
||||||
|
private Instant createTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.jiayunet.pojo.param.jobAgent;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对话消息添加入参
|
||||||
|
*
|
||||||
|
* @author zk
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatMessageParam {
|
||||||
|
|
||||||
|
/** 消息类型:user / assistant / recommend / apply_progress */
|
||||||
|
@NotBlank(message = "消息类型不能为空")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/** 文本内容 */
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/** 附加数据JSON */
|
||||||
|
private String extra;
|
||||||
|
}
|
||||||
@@ -1,21 +1,28 @@
|
|||||||
package org.jiayunet.service;
|
package org.jiayunet.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import org.jiayunet.mapper.JobAgentConfigMapper;
|
import org.jiayunet.mapper.JobAgentConfigMapper;
|
||||||
|
import org.jiayunet.mapper.JobAgentChatMessageMapper;
|
||||||
import org.jiayunet.pojo.dto.jobAgent.JobAgentConfigDto;
|
import org.jiayunet.pojo.dto.jobAgent.JobAgentConfigDto;
|
||||||
|
import org.jiayunet.pojo.dto.jobAgent.ChatMessageDto;
|
||||||
import org.jiayunet.pojo.param.jobAgent.JobAgentConfigParam;
|
import org.jiayunet.pojo.param.jobAgent.JobAgentConfigParam;
|
||||||
|
import org.jiayunet.pojo.param.jobAgent.ChatMessageParam;
|
||||||
import org.jiayunet.pojo.po.JobAgentConfig;
|
import org.jiayunet.pojo.po.JobAgentConfig;
|
||||||
|
import org.jiayunet.pojo.po.JobAgentChatMessage;
|
||||||
import org.jiayunet.tool.UserSecurityTool;
|
import org.jiayunet.tool.UserSecurityTool;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 求职助手配置服务
|
* 求职助手配置服务
|
||||||
* <p>主要功能:求职助手配置的查询和保存</p>
|
* <p>主要功能:求职助手配置的查询和保存、对话消息的添加和查询</p>
|
||||||
* <p>使用表:bg_job_agent_config(查询/新增/更新)</p>
|
* <p>使用表:bg_job_agent_config(查询/新增/更新)、bg_job_agent_chat_message(添加/查询)</p>
|
||||||
*
|
*
|
||||||
* @author zk
|
* @author zk
|
||||||
*/
|
*/
|
||||||
@@ -25,6 +32,9 @@ public class JobAgentConfigService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private JobAgentConfigMapper configMapper;
|
private JobAgentConfigMapper configMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JobAgentChatMessageMapper messageMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询当前用户的求职助手配置
|
* 查询当前用户的求职助手配置
|
||||||
* <p>根据userId查询,不存在返回null</p>
|
* <p>根据userId查询,不存在返回null</p>
|
||||||
@@ -62,4 +72,35 @@ public class JobAgentConfigService {
|
|||||||
configMapper.updateById(po);
|
configMapper.updateById(po);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加对话消息
|
||||||
|
*/
|
||||||
|
public void addMessage(ChatMessageParam param) {
|
||||||
|
Long userId = UserSecurityTool.getUserId();
|
||||||
|
JobAgentChatMessage po = new JobAgentChatMessage();
|
||||||
|
po.setUserId(userId);
|
||||||
|
po.setType(param.getType());
|
||||||
|
po.setContent(param.getContent());
|
||||||
|
po.setExtra(param.getExtra());
|
||||||
|
po.setCreateTime(Instant.now());
|
||||||
|
messageMapper.insert(po);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询对话消息(最近N条,按时间正序)
|
||||||
|
*/
|
||||||
|
public List<ChatMessageDto> listMessages(Integer limit) {
|
||||||
|
Long userId = UserSecurityTool.getUserId();
|
||||||
|
if (limit == null || limit <= 0) limit = 50;
|
||||||
|
Page<JobAgentChatMessage> page = new Page<>(1, limit);
|
||||||
|
Page<JobAgentChatMessage> result = messageMapper.selectPage(page, new LambdaQueryWrapper<JobAgentChatMessage>().eq(JobAgentChatMessage::getUserId, userId).orderByDesc(JobAgentChatMessage::getCreateTime));
|
||||||
|
List<JobAgentChatMessage> records = result.getRecords();
|
||||||
|
java.util.Collections.reverse(records);
|
||||||
|
return records.stream().map(po -> {
|
||||||
|
ChatMessageDto dto = new ChatMessageDto();
|
||||||
|
BeanUtils.copyProperties(po, dto);
|
||||||
|
return dto;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.jiayunet.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.jiayunet.pojo.po.JobAgentChatMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 求职助手对话消息Mapper
|
||||||
|
*
|
||||||
|
* @author zk
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface JobAgentChatMessageMapper extends CommonMapper<JobAgentChatMessage> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package org.jiayunet.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 求职助手对话消息表(bg_job_agent_chat_message)
|
||||||
|
* <p>记录用户与求职助手的完整对话流,含文本消息和前端维护的JSON数据</p>
|
||||||
|
*
|
||||||
|
* @author zk
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName(value = "bg_job_agent_chat_message")
|
||||||
|
public class JobAgentChatMessage {
|
||||||
|
|
||||||
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 用户ID */
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/** 消息类型:user=用户提问 assistant=AI回复 recommend=岗位推荐 apply_progress=投递进度 */
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/** 文本内容。user=用户提问,assistant=AI回复,recommend=AI推荐描述,apply_progress为null */
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/** 附加数据JSON。recommend=岗位推荐列表,apply_progress=投递进度,user/assistant为null */
|
||||||
|
private String extra;
|
||||||
|
|
||||||
|
/** 创建时间 */
|
||||||
|
private Instant createTime;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user