人脸识别与大模型问答

This commit is contained in:
jiang 2024-08-24 16:17:11 +08:00
parent a94dd76e9d
commit cf9abe48d5
9 changed files with 45 additions and 37 deletions

View File

@ -11,6 +11,8 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import com.bonus.system.api.RemoteFileService;
/** /**
* @author bonus * @author bonus
* 人脸识别控制层 * 人脸识别控制层

View File

@ -36,7 +36,7 @@ public class KnowledgeController {
* @return 集合 * @return 集合
*/ */
@PostMapping("/insertChatWindow") @PostMapping("/insertChatWindow")
public AjaxResult insertChatWindow(@RequestBody KnowledgeChatWindowVo knowledgeChatWindowVo) { public AjaxResult insertChatWindow(@RequestBody KnowledgeChatWindowVo knowledgeChatWindowVo) {
return knowledgeService.insertChatWindow(knowledgeChatWindowVo); return knowledgeService.insertChatWindow(knowledgeChatWindowVo);
} }
@ -58,7 +58,7 @@ public class KnowledgeController {
* @return 受影响的行数 * @return 受影响的行数
*/ */
@PostMapping("/deleteChatWindow/{windowId}") @PostMapping("/deleteChatWindow/{windowId}")
public AjaxResult deleteChatWindow(@PathVariable Long windowId) { public AjaxResult deleteChatWindow(@PathVariable String windowId) {
return knowledgeService.deleteChatWindow(windowId); return knowledgeService.deleteChatWindow(windowId);
} }
@ -70,7 +70,7 @@ public class KnowledgeController {
* @return 受影响的行数 * @return 受影响的行数
*/ */
@PostMapping("/getAllByWindowId/{windowId}") @PostMapping("/getAllByWindowId/{windowId}")
public AjaxResult getAllByWindowId(@PathVariable Long windowId) { public AjaxResult getAllByWindowId(@PathVariable String windowId) {
return knowledgeService.getAllByWindowId(windowId); return knowledgeService.getAllByWindowId(windowId);
} }
@ -81,7 +81,7 @@ public class KnowledgeController {
* @return 受影响的行数 * @return 受影响的行数
*/ */
@PostMapping("/insertQuestionAnswer") @PostMapping("/insertQuestionAnswer")
public AjaxResult insertQuestionAnswer(AiQuestionAnswer aiQuestionAnswer) { public AjaxResult insertQuestionAnswer(@RequestBody AiQuestionAnswer aiQuestionAnswer) {
return knowledgeService.insertQuestionAnswer(aiQuestionAnswer); return knowledgeService.insertQuestionAnswer(aiQuestionAnswer);
} }

View File

@ -13,7 +13,7 @@ public class KnowledgeChatWindowVo {
/** /**
* 窗口id * 窗口id
*/ */
private Long windowId; private String windowId;
/** /**
* 知识库id * 知识库id
*/ */

View File

@ -16,7 +16,7 @@ public class AiQuestionAnswer {
/** /**
* 窗口ID可为空 * 窗口ID可为空
*/ */
private Long windowId; private String windowId;
/** /**
* 问题内容使用长文本 * 问题内容使用长文本
*/ */
@ -36,7 +36,7 @@ public class AiQuestionAnswer {
/** /**
* 客户ID不可为空 * 客户ID不可为空
*/ */
private String customerId; private Long customerId;
/** /**
* 更新时间 * 更新时间
*/ */

View File

@ -2,6 +2,7 @@ package com.bonus.ai.mapper;
import com.bonus.ai.domain.KnowledgeChatWindowVo; import com.bonus.ai.domain.KnowledgeChatWindowVo;
import com.bonus.ai.domain.vo.AiQuestionAnswer; import com.bonus.ai.domain.vo.AiQuestionAnswer;
import org.apache.ibatis.annotations.Options;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@ -27,9 +28,10 @@ public interface KnowledgeMapper {
* 新增窗口 * 新增窗口
* *
* @param knowledgeChatWindowVo 聊天窗口信息 * @param knowledgeChatWindowVo 聊天窗口信息
* @return 受影响的行数 * @return 新增的聊天窗口对象包含生成的 windowId
*/ */
int insertChatWindow(KnowledgeChatWindowVo knowledgeChatWindowVo); Long insertChatWindow(KnowledgeChatWindowVo knowledgeChatWindowVo);
/** /**
* 更新聊天窗口信息 * 更新聊天窗口信息
@ -45,7 +47,7 @@ public interface KnowledgeMapper {
* @param windowId 窗口ID * @param windowId 窗口ID
* @return 受影响的行数 * @return 受影响的行数
*/ */
int deleteChatWindow(Long windowId); int deleteChatWindow(String windowId);
/** /**
@ -53,7 +55,7 @@ public interface KnowledgeMapper {
* *
* @return 所有问答记录的列表 * @return 所有问答记录的列表
*/ */
List<AiQuestionAnswer> getAllByWindowId(Long windowId); List<AiQuestionAnswer> getAllByWindowId(String windowId);
/** /**
* 插入问答信息 * 插入问答信息
@ -61,6 +63,6 @@ public interface KnowledgeMapper {
* @param aiQuestionAnswer 问答信息 * @param aiQuestionAnswer 问答信息
* @return 生成的窗口ID * @return 生成的窗口ID
*/ */
Long insertQuestionAnswer(AiQuestionAnswer aiQuestionAnswer); int insertQuestionAnswer(AiQuestionAnswer aiQuestionAnswer);
} }

View File

@ -39,7 +39,7 @@ public interface KnowledgeService {
* @param windowId 窗口ID * @param windowId 窗口ID
* @return 受影响的行数 * @return 受影响的行数
*/ */
AjaxResult deleteChatWindow(Long windowId); AjaxResult deleteChatWindow(String windowId);
/** /**
@ -47,7 +47,7 @@ public interface KnowledgeService {
* *
* @return 所有问答记录的列表 * @return 所有问答记录的列表
*/ */
AjaxResult getAllByWindowId(Long windowId); AjaxResult getAllByWindowId(String windowId);
/** /**
* 插入问答信息 * 插入问答信息

View File

@ -7,8 +7,11 @@ import com.bonus.ai.domain.vo.FaceVo;
import com.bonus.ai.mapper.FaceMapper; import com.bonus.ai.mapper.FaceMapper;
import com.bonus.ai.service.FaceService; import com.bonus.ai.service.FaceService;
import com.bonus.ai.utils.FaceUtils; import com.bonus.ai.utils.FaceUtils;
import com.bonus.common.core.domain.R;
import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils; import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.system.api.RemoteFileService;
import com.bonus.system.api.domain.SysFile;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -29,6 +32,8 @@ public class FaceServiceImpl implements FaceService {
@Resource @Resource
private FaceMapper faceMapper; private FaceMapper faceMapper;
@Resource
private RemoteFileService remoteFileService;
/** /**
* 查询全部人脸信息 * 查询全部人脸信息
@ -136,22 +141,17 @@ public class FaceServiceImpl implements FaceService {
face.setUpdateBy(SecurityUtils.getUsername()); face.setUpdateBy(SecurityUtils.getUsername());
face.setUpdateTime(new Date()); face.setUpdateTime(new Date());
try { try {
// 设置保存文件的目录这里假设是在应用程序的根目录下的uploads文件夹 R<SysFile> upload = remoteFileService.upload(file);
String uploadDir = "uploads"; if (upload.getCode() == 200) {
Path uploadPath = Paths.get(uploadDir); face.setFaceAddress(upload.getData().getUrl().replaceFirst("http://[^/]+", ""));
// 如果目录不存在则创建 return faceMapper.insertFace(face) > 0 ? AjaxResult.success() : AjaxResult.error();
if (!Files.exists(uploadPath)) { } else {
Files.createDirectories(uploadPath); return AjaxResult.error();
} }
byte[] bytes = file.getBytes();
String fileName = UUID.randomUUID() + file.getOriginalFilename();
String filePath = Paths.get("uploads").toAbsolutePath().normalize().toString() + File.separator + fileName;
java.nio.file.Files.write(java.nio.file.Paths.get(filePath), bytes);
face.setFaceAddress(filePath);
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(); return AjaxResult.error();
} }
return faceMapper.insertFace(face) > 0 ? AjaxResult.success() : AjaxResult.error();
case "30006": case "30006":
return AjaxResult.error("文件类型不支持"); return AjaxResult.error("文件类型不支持");
case "30007": case "30007":

View File

@ -9,6 +9,7 @@ import com.bonus.common.security.utils.SecurityUtils;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
@ -51,12 +52,13 @@ public class KnowledgeServiceImpl implements KnowledgeService {
knowledgeChatWindowVo.setCustomerId(SecurityUtils.getUserId()); knowledgeChatWindowVo.setCustomerId(SecurityUtils.getUserId());
knowledgeChatWindowVo.setCreateTime(new Date()); knowledgeChatWindowVo.setCreateTime(new Date());
knowledgeChatWindowVo.setUpdateTime(new Date()); knowledgeChatWindowVo.setUpdateTime(new Date());
int l = knowledgeMapper.insertChatWindow(knowledgeChatWindowVo); Long l = knowledgeMapper.insertChatWindow(knowledgeChatWindowVo);
if (l > 0) { if (l > 0) {
return AjaxResult.success(); return AjaxResult.success();
} else { } else {
return AjaxResult.error(); return AjaxResult.error();
} }
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(); return AjaxResult.error();
} }
@ -89,7 +91,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
* @return 受影响的行数 * @return 受影响的行数
*/ */
@Override @Override
public AjaxResult deleteChatWindow(Long windowId) { public AjaxResult deleteChatWindow(String windowId) {
try { try {
int i = knowledgeMapper.deleteChatWindow(windowId); int i = knowledgeMapper.deleteChatWindow(windowId);
if (i > 0) { if (i > 0) {
@ -110,7 +112,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
* @return 所有问答记录的列表 * @return 所有问答记录的列表
*/ */
@Override @Override
public AjaxResult getAllByWindowId(Long windowId) { public AjaxResult getAllByWindowId(String windowId) {
try { try {
List<AiQuestionAnswer> allByWindowId = knowledgeMapper.getAllByWindowId(windowId); List<AiQuestionAnswer> allByWindowId = knowledgeMapper.getAllByWindowId(windowId);
return AjaxResult.success(allByWindowId); return AjaxResult.success(allByWindowId);
@ -128,11 +130,13 @@ public class KnowledgeServiceImpl implements KnowledgeService {
@Override @Override
public AjaxResult insertQuestionAnswer(AiQuestionAnswer aiQuestionAnswer) { public AjaxResult insertQuestionAnswer(AiQuestionAnswer aiQuestionAnswer) {
try { try {
Long l = knowledgeMapper.insertQuestionAnswer(aiQuestionAnswer); aiQuestionAnswer.setCustomerId(SecurityUtils.getUserId());
if (ObjectUtils.isEmpty(l)) { aiQuestionAnswer.setUpdateTime(new Date());
return AjaxResult.error(); int num = knowledgeMapper.insertQuestionAnswer(aiQuestionAnswer);
if (num > 0) {
return AjaxResult.success();
} else { } else {
return AjaxResult.success(l); return AjaxResult.error();
} }
} catch (Exception e) { } catch (Exception e) {
return AjaxResult.error(); return AjaxResult.error();

View File

@ -4,14 +4,14 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.ai.mapper.KnowledgeMapper"> <mapper namespace="com.bonus.ai.mapper.KnowledgeMapper">
<insert id="insertChatWindow"> <insert id="insertChatWindow">
insert into ai_chat_window (knowledge_id, window_name, chat_type, customer_id, create_time, INSERT INTO ai_chat_window (window_id, knowledge_id, window_name, chat_type, customer_id, create_time,
update_time, remark) update_time, remark)
values (#{knowledgeId}, #{windowName}, #{chatType}, #{customerId}, now(), now(), #{remark}); VALUES (#{windowId}, #{knowledgeId}, #{windowName}, #{chatType}, #{customerId}, NOW(), NOW(), #{remark});
</insert> </insert>
<insert id="insertQuestionAnswer" useGeneratedKeys="true" keyProperty="recordId"> <insert id="insertQuestionAnswer">
INSERT INTO ai_question_answer INSERT INTO ai_question_answer
(window_id, question, answer, knowledge, del_flag, customer_id, update_time, remark) (window_id, question, answer, knowledge, del_flag, customer_id, update_time, remark)
VALUES (#{windowId}, #{question}, #{answer}, #{knowledge}, #{delFlag}, #{customerId}, #{updateTime}, #{remark}); VALUES (#{windowId}, #{question}, #{answer}, #{knowledge}, '0', #{customerId}, #{updateTime}, #{remark});
</insert> </insert>
<select id="getList" resultType="com.bonus.ai.domain.KnowledgeChatWindowVo"> <select id="getList" resultType="com.bonus.ai.domain.KnowledgeChatWindowVo">