Bläddra i källkod

Merge remote-tracking branch 'origin/master'

ouyj 1 år sedan
förälder
incheckning
6215efc83c
19 ändrade filer med 954 tillägg och 5 borttagningar
  1. 59 0
      src/main/android/com/yw/android/client/action/MiniAppAIDelSessionAction.java
  2. 55 0
      src/main/android/com/yw/android/client/action/MiniAppAIGetHistoryMessage.java
  3. 56 0
      src/main/android/com/yw/android/client/action/MiniAppAIGetHistorySession.java
  4. 103 0
      src/main/android/com/yw/android/client/action/MiniAppAIGetReceiveAction.java
  5. 59 0
      src/main/android/com/yw/android/client/action/MiniAppAISetSessionNameAction.java
  6. 30 1
      src/main/android/com/yw/android/pageflow/tms_recorder.xml
  7. 5 1
      src/main/master1/com/yw/master1/applicationContext_mt_eu.xml
  8. 17 0
      src/main/master1/com/yw/master1/eu/ai/dao/AiMessageDao.java
  9. 21 0
      src/main/master1/com/yw/master1/eu/ai/dao/AiSessionDao.java
  10. 38 0
      src/main/master1/com/yw/master1/eu/ai/dao/impl/AiMessageDaoImpl.java
  11. 48 0
      src/main/master1/com/yw/master1/eu/ai/dao/impl/AiSessionDaoImpl.java
  12. 162 0
      src/main/master1/com/yw/master1/eu/ai/model/AiMessage.java
  13. 116 0
      src/main/master1/com/yw/master1/eu/ai/model/AiSession.java
  14. 21 0
      src/main/master1/com/yw/master1/eu/ai/model/vo/AiMessageVo.java
  15. 49 3
      src/main/master1/com/yw/master1/eu/ai/service/AiApi.java
  16. 16 0
      src/main/master1/com/yw/master1/eu/ai/service/AiMessageService.java
  17. 22 0
      src/main/master1/com/yw/master1/eu/ai/service/AiSessionService.java
  18. 33 0
      src/main/master1/com/yw/master1/eu/ai/service/impl/AiMessageServiceImpl.java
  19. 44 0
      src/main/master1/com/yw/master1/eu/ai/service/impl/AiSessionServiceImpl.java

+ 59 - 0
src/main/android/com/yw/android/client/action/MiniAppAIDelSessionAction.java

@@ -0,0 +1,59 @@
+package com.yw.android.client.action;
+
+import com.yw.core.clientImpl.model.ResultVo;
+import com.yw.core.clientImpl.service.RequestAbs;
+import com.yw.core.session.AppSession;
+import com.yw.master1.eu.ai.model.AiSession;
+import com.yw.master1.eu.ai.service.AiMessageService;
+import com.yw.master1.eu.ai.service.AiSessionService;
+import net.sf.json.JSONObject;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * 小程序删除会话
+ *
+ * @author: LaFantasque
+ * @date: 2025-02-21 16:21
+ */
+public class MiniAppAIDelSessionAction extends RequestAbs {
+    public final String serviceId = "miniapp_ai_delSession";
+    private ApplicationContext cxt = null;
+    @Override
+    public String getResult() {
+        // 获取请求的参数
+        String param = getParameters();
+        JSONObject json = JSONObject.fromObject(param);
+        Long sessionId = Long.valueOf(json.getString("sessionId"));
+        if (null == cxt) {
+            cxt = AppSession.getApplicationContext();
+        }
+        int num = 0;
+        try {
+            AiSessionService aiSessionService = (AiSessionService) cxt.getBean("aiSessionService");
+            AiMessageService aiMessageService = (AiMessageService) cxt.getBean("aiMessageService");
+            AiSession session = new AiSession();
+            session.setSessionId(sessionId);
+            num = aiSessionService.delete(session);
+            aiMessageService.deleteBySessionId(sessionId);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        // 返回数据
+        String returnCode = "-1";
+        String returnMsg = "failed";
+        if (num > 0) {
+            returnCode = "0";
+            returnMsg = "success";
+        }
+        ResultVo rv = new ResultVo();
+        rv.setReturnCode(returnCode);
+        rv.setReturnMsg(returnMsg);
+        rv.setReturnParams(num);
+        return JSONObject.fromObject(rv, config).toString();
+    }
+
+    @Override
+    public String getServiceId() {
+        return serviceId;
+    }
+}

+ 55 - 0
src/main/android/com/yw/android/client/action/MiniAppAIGetHistoryMessage.java

@@ -0,0 +1,55 @@
+package com.yw.android.client.action;
+
+import com.yw.core.clientImpl.model.ResultVo;
+import com.yw.core.clientImpl.service.RequestAbs;
+import com.yw.core.session.AppSession;
+import com.yw.master1.eu.ai.model.AiMessage;
+import com.yw.master1.eu.ai.service.AiMessageService;
+import net.sf.json.JSONObject;
+import org.springframework.context.ApplicationContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 小程序获取历史会话的消息记录
+ *
+ * @author: wangpx
+ * @date: 2025-02-20 16:40
+ */
+public class MiniAppAIGetHistoryMessage extends RequestAbs {
+    public final String serviceId = "miniapp_ai_getHistoryMessage";
+    private ApplicationContext cxt = null;
+    @Override
+    public String getResult() {
+        // 获取请求的参数
+        String param = getParameters();
+        JSONObject json = JSONObject.fromObject(param);
+        Long sessionId = Long.valueOf(json.getString("sessionId"));
+        if (null == cxt) {
+            cxt = AppSession.getApplicationContext();
+        }
+        List<AiMessage> messageList = new ArrayList<>();
+        String returnCode = "-1";
+        String returnMsg = "failed";
+        try {
+            AiMessageService aiMessageService = (AiMessageService) cxt.getBean("aiMessageService");
+            messageList = aiMessageService.selectBySessionId(sessionId);
+            returnCode = "1";
+            returnMsg = "success";
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        // 返回数据
+        ResultVo rv = new ResultVo();
+        rv.setReturnCode(returnCode);
+        rv.setReturnMsg(returnMsg);
+        rv.setReturnParams(messageList);
+        return JSONObject.fromObject(rv, config).toString();
+    }
+
+    @Override
+    public String getServiceId() {
+        return serviceId;
+    }
+}

+ 56 - 0
src/main/android/com/yw/android/client/action/MiniAppAIGetHistorySession.java

@@ -0,0 +1,56 @@
+package com.yw.android.client.action;
+
+import com.yw.core.clientImpl.model.ResultVo;
+import com.yw.core.clientImpl.service.RequestAbs;
+import com.yw.core.session.AppSession;
+import com.yw.master1.eu.ai.model.AiSession;
+import com.yw.master1.eu.ai.service.AiSessionService;
+import net.sf.json.JSONObject;
+import org.springframework.context.ApplicationContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 小程序获取历史会话记录
+ *
+ * @author: wangpx
+ * @date: 2025-02-20 16:38
+ */
+public class MiniAppAIGetHistorySession extends RequestAbs {
+    public final String serviceId = "miniapp_ai_getHistorySession";
+    private ApplicationContext cxt = null;
+
+    @Override
+    public String getResult() {
+        // 获取请求的参数
+        String param = getParameters();
+        JSONObject json = JSONObject.fromObject(param);
+        Long userId = Long.valueOf(json.getString("userId"));
+        if (null == cxt) {
+            cxt = AppSession.getApplicationContext();
+        }
+        List<AiSession> sessionList = new ArrayList<>();
+        String returnCode = "-1";
+        String returnMsg = "failed";
+        try {
+            AiSessionService aiSessionService = (AiSessionService) cxt.getBean("aiSessionService");
+            sessionList = aiSessionService.selectByUserId(userId);
+            returnCode = "1";
+            returnMsg = "success";
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        // 返回数据
+        ResultVo rv = new ResultVo();
+        rv.setReturnCode(returnCode);
+        rv.setReturnMsg(returnMsg);
+        rv.setReturnParams(sessionList);
+        return JSONObject.fromObject(rv, config).toString();
+    }
+
+    @Override
+    public String getServiceId() {
+        return serviceId;
+    }
+}

+ 103 - 0
src/main/android/com/yw/android/client/action/MiniAppAIGetReceiveAction.java

@@ -0,0 +1,103 @@
+package com.yw.android.client.action;
+
+import com.yw.core.clientImpl.model.ResultVo;
+import com.yw.core.clientImpl.service.RequestAbs;
+import com.yw.core.session.AppSession;
+import com.yw.core.utils.StringUtil;
+import com.yw.master1.eu.ai.model.AiMessage;
+import com.yw.master1.eu.ai.model.AiSession;
+import com.yw.master1.eu.ai.model.vo.AiMessageVo;
+import com.yw.master1.eu.ai.service.AiApi;
+import com.yw.master1.eu.ai.service.AiMessageService;
+import com.yw.master1.eu.ai.service.AiSessionService;
+import net.sf.json.JSONObject;
+import org.springframework.context.ApplicationContext;
+import org.springframework.util.ObjectUtils;
+
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * 小程序AI客服接口
+ *
+ * @author: wangpx
+ * @date: 2025-02-19 10:31
+ */
+public class MiniAppAIGetReceiveAction extends RequestAbs {
+    public final String serviceId = "miniapp_ai_getReceive";
+    private ApplicationContext cxt = null;
+
+    @Override
+    public String getResult() {
+        // 获取请求的参数
+        String param = getParameters();
+        JSONObject json = JSONObject.fromObject(param);
+        String prompt = json.getString("prompt");
+        Long sessionId = Long.valueOf(json.getString("sessionId"));
+        Long userId = Long.valueOf(json.getString("userId"));
+        Integer sort = Integer.parseInt(json.getString("sort"));
+
+        if (null == cxt) {
+            cxt = AppSession.getApplicationContext();
+        }
+
+        String receiveContent = null;
+        String returnCode = "-1";
+        String returnMsg = "failed";
+
+        AiMessageVo messageVo = new AiMessageVo();
+        AiMessage message = null;
+        try {
+            AiMessageService aiMessageService = (AiMessageService) cxt.getBean("aiMessageService");
+            AiSessionService aiSessionService = (AiSessionService) cxt.getBean("aiSessionService");
+            String sendContent = prompt;
+
+            // 获取返回消息
+            message = AiApi.sendAsk(sendContent);
+            receiveContent = message.getReceiveContent();
+            
+            AiSession session = new AiSession();
+            if (sessionId == 0) { // 新开会话
+                String sessionName = sendContent;
+                if (sendContent.length() > 20) sessionName = sendContent.substring(0, 20);
+                sessionId = StringUtil.getSeq();
+                session.setSessionId(sessionId);
+                session.setSessionName(sessionName);
+                session.setUserId(userId);
+                aiSessionService.insert(session);
+
+                messageVo.setSessionName(sessionName);
+            } else {
+                session.setSessionId(sessionId);
+                session.setChangeTime(new Date());
+                aiSessionService.updateChangeTime(session);
+            }
+
+            message.setMessageId(StringUtil.getSeq());
+            message.setSendContent(prompt);
+//            message.setReceiveContent(receiveContent);
+            message.setSessionId(sessionId);
+            message.setSort(sort);
+            aiMessageService.insert(message);
+
+            returnCode = "1";
+            returnMsg = "success";
+        } catch (Exception e) {
+            e.printStackTrace();
+            receiveContent = "系统错误,请联系管理员";
+        }
+        messageVo.setReceiveContent(receiveContent);
+        messageVo.setSessionId(sessionId);
+        // 返回数据
+        ResultVo rv = new ResultVo();
+        rv.setReturnCode(returnCode);
+        rv.setReturnMsg(returnMsg);
+        rv.setReturnParams(messageVo);
+        return JSONObject.fromObject(rv, config).toString();
+    }
+
+    @Override
+    public String getServiceId() {
+        return serviceId;
+    }
+}

+ 59 - 0
src/main/android/com/yw/android/client/action/MiniAppAISetSessionNameAction.java

@@ -0,0 +1,59 @@
+package com.yw.android.client.action;
+
+import com.yw.core.clientImpl.model.ResultVo;
+import com.yw.core.clientImpl.service.RequestAbs;
+import com.yw.core.session.AppSession;
+import com.yw.master1.eu.ai.model.AiSession;
+import com.yw.master1.eu.ai.service.AiSessionService;
+import net.sf.json.JSONObject;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * 小程序修改会话名
+ *
+ * @author: LaFantasque
+ * @date: 2025-02-20 16:58
+ */
+public class MiniAppAISetSessionNameAction extends RequestAbs {
+    public final String serviceId = "miniapp_ai_setSessionName";
+    private ApplicationContext cxt = null;
+
+    @Override
+    public String getResult() {
+        // 获取请求的参数
+        String param = getParameters();
+        JSONObject json = JSONObject.fromObject(param);
+        Long sessionId = Long.valueOf(json.getString("sessionId"));
+        String sessionName = json.getString("sessionName");
+        if (null == cxt) {
+            cxt = AppSession.getApplicationContext();
+        }
+        int num = 0;
+        try {
+            AiSessionService aiSessionService = (AiSessionService) cxt.getBean("aiSessionService");
+            AiSession session = new AiSession();
+            session.setSessionId(sessionId);
+            session.setSessionName(sessionName);
+            num =aiSessionService.updateSessionName(session);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        // 返回数据
+        String returnCode = "-1";
+        String returnMsg = "failed";
+        if (num > 0) {
+            returnCode = "0";
+            returnMsg = "success";
+        }
+        ResultVo rv = new ResultVo();
+        rv.setReturnCode(returnCode);
+        rv.setReturnMsg(returnMsg);
+        rv.setReturnParams(num);
+        return JSONObject.fromObject(rv, config).toString();
+    }
+
+    @Override
+    public String getServiceId() {
+        return serviceId;
+    }
+}

+ 30 - 1
src/main/android/com/yw/android/pageflow/tms_recorder.xml

@@ -40,6 +40,35 @@
 		<class name="com.yw.android.client.action.MiniAppGetMyMonthCountAction" needLogin="false" />
 		<param list="" />
 	</action>
-	
+
+	<action>
+		<forward id="/MiniAppAIGetReceiveAction" path="" type="AI" title="发送消息"/>
+		<class name="com.yw.android.client.action.MiniAppAIGetReceiveAction" needLogin="false" />
+		<param list="" />
+	</action>
+
+	<action>
+		<forward id="/MiniAppAIGetHistorySession" path="" type="AI" title="获取历史会话"/>
+		<class name="com.yw.android.client.action.MiniAppAIGetHistorySession" needLogin="false" />
+		<param list="" />
+	</action>
+
+	<action>
+		<forward id="/MiniAppAIGetHistoryMessage" path="" type="AI" title="获取历史消息"/>
+		<class name="com.yw.android.client.action.MiniAppAIGetHistoryMessage" needLogin="false" />
+		<param list="" />
+	</action>
+
+	<action>
+		<forward id="/MiniAppAISetSessionNameAction" path="" type="AI" title="修改会话名"/>
+		<class name="com.yw.android.client.action.MiniAppAISetSessionNameAction" needLogin="false" />
+		<param list="" />
+	</action>
+
+	<action>
+		<forward id="/MiniAppAIDelSessionAction" path="" type="AI" title="删除会话"/>
+		<class name="com.yw.android.client.action.MiniAppAIDelSessionAction" needLogin="false" />
+		<param list="" />
+	</action>
 </pageflow>
 

+ 5 - 1
src/main/master1/com/yw/master1/applicationContext_mt_eu.xml

@@ -11,7 +11,11 @@
 	http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
 	http://www.springframework.org/schema/tx 
 	http://www.springframework.org/schema/tx/spring-tx-3.2.xsd" default-autowire="byType">
-	
+
+	<bean id="aiSessionService" class="com.yw.master1.eu.ai.service.impl.AiSessionServiceImpl"/>
+	<bean id="aiSessionDao" class="com.yw.master1.eu.ai.dao.impl.AiSessionDaoImpl"/>
+	<bean id="aiMessageService" class="com.yw.master1.eu.ai.service.impl.AiMessageServiceImpl"/>
+	<bean id="aiMessageDao" class="com.yw.master1.eu.ai.dao.impl.AiMessageDaoImpl"/>
 	
 	<bean id="euDeskTopService" class="com.yw.master1.common.desktop.DeskTopService" scope="prototype"/>
 	<bean id="euDeskService" class="com.yw.master1.eu.desk.service.DeskSerivceImpl" />

+ 17 - 0
src/main/master1/com/yw/master1/eu/ai/dao/AiMessageDao.java

@@ -0,0 +1,17 @@
+package com.yw.master1.eu.ai.dao;
+
+import com.yw.master1.eu.ai.model.AiMessage;
+
+import java.util.List;
+
+/**
+ * @author wangpx
+ * @version 1.0
+ */
+public interface AiMessageDao {
+    int insert(AiMessage message) throws Exception;
+
+    List<AiMessage> selectBySessionId(Long sessionId) throws Exception;
+
+    int deleteBySessionId(Long sessionId);
+}

+ 21 - 0
src/main/master1/com/yw/master1/eu/ai/dao/AiSessionDao.java

@@ -0,0 +1,21 @@
+package com.yw.master1.eu.ai.dao;
+
+import com.yw.master1.eu.ai.model.AiSession;
+
+import java.util.List;
+
+/**
+ * @author wangpx
+ * @version 1.0
+ */
+public interface AiSessionDao {
+    int insert(AiSession aiSession) throws Exception;
+
+    List<AiSession> selectByUserId(Long userId) throws Exception;
+
+    int updateSessionName(AiSession session);
+
+    int updateChangeTime(AiSession session);
+
+    int delete(AiSession session) throws Exception;
+}

+ 38 - 0
src/main/master1/com/yw/master1/eu/ai/dao/impl/AiMessageDaoImpl.java

@@ -0,0 +1,38 @@
+package com.yw.master1.eu.ai.dao.impl;
+
+import com.yw.core.common.BaseDao;
+import com.yw.master1.eu.ai.dao.AiMessageDao;
+import com.yw.master1.eu.ai.model.AiMessage;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.annotation.Resource;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * @author: wangpx
+ * @date: 2025-02-19 17:15
+ */
+public class AiMessageDaoImpl extends BaseDao implements AiMessageDao {
+    @Resource
+    JdbcTemplate jdbcTemplate;
+
+    @Override
+    public int insert(AiMessage message) throws Exception {
+        return super.insert(message);
+    }
+
+    @Override
+    public List<AiMessage> selectBySessionId(Long sessionId) throws Exception {
+        AiMessage message = new AiMessage();
+        message.setSessionId(sessionId);
+        List<AiMessage> messageList = super.queryByProperty(message);
+        messageList.sort(Comparator.comparing(AiMessage::getSort));
+        return messageList;
+    }
+
+    @Override
+    public int deleteBySessionId(Long sessionId) {
+        return jdbcTemplate.update("delete from ai_message where session_id =?", sessionId);
+    }
+}

+ 48 - 0
src/main/master1/com/yw/master1/eu/ai/dao/impl/AiSessionDaoImpl.java

@@ -0,0 +1,48 @@
+package com.yw.master1.eu.ai.dao.impl;
+
+import com.yw.core.common.BaseDao;
+import com.yw.master1.eu.ai.dao.AiSessionDao;
+import com.yw.master1.eu.ai.model.AiSession;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.annotation.Resource;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * @author: wangpx
+ * @date: 2025-02-19 17:16
+ */
+public class AiSessionDaoImpl extends BaseDao implements AiSessionDao {
+    @Resource
+    JdbcTemplate jdbcTemplate;
+
+    @Override
+    public int insert(AiSession aiSession) throws Exception {
+        return super.insert(aiSession);
+    }
+
+    @Override
+    public List<AiSession> selectByUserId(Long userId) throws Exception {
+        AiSession session = new AiSession();
+        session.setUserId(userId);
+        List<AiSession> sessionList = super.queryByProperty(session);
+        sessionList.sort(Comparator.comparing(AiSession::getChangeTime).reversed());
+        return sessionList;
+    }
+
+    @Override
+    public int updateSessionName(AiSession session) {
+        return jdbcTemplate.update("update ai_session set session_name = ? where session_id = ?", session.getSessionName(), session.getSessionId());
+    }
+
+    @Override
+    public int updateChangeTime(AiSession session) {
+        return jdbcTemplate.update("update ai_session set change_time = ? where session_id = ?", session.getChangeTime(), session.getSessionId());
+    }
+
+    @Override
+    public int delete(AiSession session) throws Exception {
+        return super.deleteByProperty(session);
+    }
+}

+ 162 - 0
src/main/master1/com/yw/master1/eu/ai/model/AiMessage.java

@@ -0,0 +1,162 @@
+package com.yw.master1.eu.ai.model;
+
+import com.yw.core.common.annotation.Column;
+import com.yw.core.common.annotation.Table;
+import org.hsqldb.Types;
+
+import java.io.Serializable;
+
+import java.util.Date;
+
+@Table(name = "ai_message")
+public class AiMessage implements Serializable {
+
+    /**
+    * 消息唯一标识
+    */
+    @Column(name = "message_id", type = Types.BIGINT)
+    private Long messageId;
+    /**
+    * 关联会话ID
+    */
+    @Column(name = "session_id", type = Types.BIGINT)
+    private Long sessionId;
+    /**
+    * 发送消息内容
+    */
+    @Column(name = "send_content", type = Types.VARCHAR)
+    private String sendContent;
+    /**
+    * 接收消息内容
+    */
+    @Column(name = "receive_content", type = Types.VARCHAR)
+    private String receiveContent;
+    /**
+    * 模型名称
+    */
+    @Column(name = "llm", type = Types.VARCHAR)
+    private String llm;
+    /**
+    * 时间戳
+    */
+    @Column(name = "timestamp", type = Types.TIMESTAMP)
+    private Date timestamp;
+    /**
+    * 消息顺序号
+    */
+    @Column(name = "sort", type = Types.INTEGER)
+    private Integer sort;
+
+    public AiMessage() {
+    }
+
+    public AiMessage(Long messageId, Long sessionId, String sendContent, String receiveContent, String llm, Date timestamp, Integer sort) {
+        this.messageId = messageId;
+        this.sessionId = sessionId;
+        this.sendContent = sendContent;
+        this.receiveContent = receiveContent;
+        this.llm = llm;
+        this.timestamp = timestamp;
+        this.sort = sort;
+    }
+
+    /**
+    * 消息唯一标识
+    */
+    public void setMessageId(Long messageId){
+    this.messageId = messageId;
+    }
+
+    /**
+    * 关联会话ID
+    */
+    public void setSessionId(Long sessionId){
+    this.sessionId = sessionId;
+    }
+
+    /**
+    * 发送消息内容
+    */
+    public void setSendContent(String sendContent){
+    this.sendContent = sendContent;
+    }
+
+    /**
+    * 接收消息内容
+    */
+    public void setReceiveContent(String receiveContent){
+    this.receiveContent = receiveContent;
+    }
+
+    /**
+    * 模型名称
+    */
+    public void setLlm(String llm){
+    this.llm = llm;
+    }
+
+    /**
+    * 时间戳
+    */
+    public void setTimestamp(Date timestamp){
+    this.timestamp = timestamp;
+    }
+
+    /**
+    * 消息顺序号
+    */
+    public void setSort(Integer sort){
+    this.sort = sort;
+    }
+
+
+    /**
+    * 消息唯一标识
+    */
+    public Long getMessageId(){
+    return this.messageId;
+    }
+
+    /**
+    * 关联会话ID
+    */
+    public Long getSessionId(){
+    return this.sessionId;
+    }
+
+    /**
+    * 发送消息内容
+    */
+    public String getSendContent(){
+    return this.sendContent;
+    }
+
+    /**
+    * 接收消息内容
+    */
+    public String getReceiveContent(){
+    return this.receiveContent;
+    }
+
+    /**
+    * 模型名称
+    */
+    public String getLlm(){
+    return this.llm;
+    }
+
+    /**
+    * 时间戳
+    */
+    public Date getTimestamp(){
+    return this.timestamp;
+    }
+
+    /**
+    * 消息顺序号
+    */
+    public Integer getSort(){
+    return this.sort;
+    }
+
+}

+ 116 - 0
src/main/master1/com/yw/master1/eu/ai/model/AiSession.java

@@ -0,0 +1,116 @@
+package com.yw.master1.eu.ai.model;
+
+import com.yw.core.common.annotation.Column;
+import com.yw.core.common.annotation.Table;
+import org.hsqldb.Types;
+
+import java.io.Serializable;
+
+import java.util.Date;
+
+@Table(name = "ai_session")
+public class AiSession implements Serializable {
+
+    /**
+     * 会话唯一标识
+     */
+    @Column(name = "session_id", type = Types.BIGINT)
+    private Long sessionId;
+    /**
+     * 用户ID
+     */
+    @Column(name = "user_id", type = Types.BIGINT)
+    private Long userId;
+    /**
+     * 会话名
+     */
+    @Column(name = "session_name", type = Types.VARCHAR)
+    private String sessionName;
+    /**
+     * 会话开始时间
+     */
+    @Column(name = "create_time", type = Types.TIMESTAMP)
+    private Date createTime;
+    /**
+     * 会话修改时间
+     */
+    @Column(name = "change_time", type = Types.TIMESTAMP)
+    private Date changeTime;
+
+    public AiSession() {
+    }
+
+    public AiSession(Long sessionId, Long userId, String sessionName, Date createTime, Date changeTime) {
+        this.sessionId = sessionId;
+        this.userId = userId;
+        this.sessionName = sessionName;
+        this.createTime = createTime;
+        this.changeTime = changeTime;
+    }
+
+    public Date getChangeTime() {
+        return changeTime;
+    }
+
+    public void setChangeTime(Date changeTime) {
+        this.changeTime = changeTime;
+    }
+
+    /**
+     * 会话唯一标识
+     */
+    public void setSessionId(Long sessionId){
+        this.sessionId = sessionId;
+    }
+
+    /**
+     * 用户ID
+     */
+    public void setUserId(Long userId){
+        this.userId = userId;
+    }
+
+    /**
+     * 会话名
+     */
+    public void setSessionName(String sessionName){
+        this.sessionName = sessionName;
+    }
+
+    /**
+     * 会话开始时间
+     */
+    public void setCreateTime(Date createTime){
+        this.createTime = createTime;
+    }
+
+
+    /**
+     * 会话唯一标识
+     */
+    public Long getSessionId(){
+        return this.sessionId;
+    }
+
+    /**
+     * 用户ID
+     */
+    public Long getUserId(){
+        return this.userId;
+    }
+
+    /**
+     * 会话名
+     */
+    public String getSessionName(){
+        return this.sessionName;
+    }
+
+    /**
+     * 会话开始时间
+     */
+    public Date getCreateTime(){
+        return this.createTime;
+    }
+
+}

+ 21 - 0
src/main/master1/com/yw/master1/eu/ai/model/vo/AiMessageVo.java

@@ -0,0 +1,21 @@
+package com.yw.master1.eu.ai.model.vo;
+
+import com.yw.master1.eu.ai.model.AiMessage;
+
+import java.util.Date;
+
+/**
+ * @author: wangpx
+ * @date: 2025-02-20 14:16
+ */
+public class AiMessageVo extends AiMessage {
+    private String SessionName;
+
+    public String getSessionName() {
+        return SessionName;
+    }
+
+    public void setSessionName(String sessionName) {
+        SessionName = sessionName;
+    }
+}

+ 49 - 3
src/main/master1/com/yw/master1/eu/ai/service/AiApi.java

@@ -1,7 +1,11 @@
 package com.yw.master1.eu.ai.service;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
+import com.yw.eu.base.message.model.Message;
+import com.yw.master1.eu.ai.model.AiMessage;
 import org.json.JSONObject;
 
 import okhttp3.MediaType;
@@ -14,7 +18,6 @@ public class AiApi {
 	public static final String API_KEY = "JDAC4Uf4JpVoKnP64do0YRWH";
     public static final String SECRET_KEY = "d2Tx3sG1LVvW2p8SFkJYqfjfV5hpv4E8";
     
-    
     static String getAccessToken() throws IOException {
         OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
         MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
@@ -27,9 +30,52 @@ public class AiApi {
         Response response = HTTP_CLIENT.newCall(request).execute();
         return new JSONObject(response.body().string()).getString("access_token");
     }
+
+    public static AiMessage sendAsk(String str) {
+        return getResult(str, 1);
+    }
+
+    private static AiMessage getResult(String str, int modelNum) {
+        AiMessage message = new AiMessage();
+        String ask;
+        String result;
+        net.sf.json.JSONObject askJson;
+        try {
+            switch (modelNum) {
+                case 1: // Deepseek
+                    ask = deepseek(str);
+                    askJson = net.sf.json.JSONObject.fromObject(ask);
+                    if (!askJson.has("error")) { // Deepseek 调用成功
+                        message.setLlm(askJson.getString("model"));
+                        net.sf.json.JSONArray  choicesJson = askJson.getJSONArray("choices");
+                        net.sf.json.JSONObject choiceJson = choicesJson.getJSONObject(0);
+                        net.sf.json.JSONObject messageJson = choiceJson.getJSONObject("message");
+                        result = messageJson.getString("content");
+                    } else { // Deepseek 调用失败
+                        throw new IOException(ask);
+                    }
+                    break;
+                case 2: // 文心一言 默认模型
+                    ask = yiyan(str);
+                    message.setLlm("yiyan");
+                    askJson = net.sf.json.JSONObject.fromObject(ask);
+                    result = askJson.getString("result");
+                    break;
+                default:
+                    result = "系统出错,请稍后重试";
+                    break;
+            }
+            message.setReceiveContent(result);
+        } catch (IOException e) {
+            e.printStackTrace();
+            modelNum++;
+            message = getResult(str, modelNum);
+        }
+        return message;
+    }
     
     //文心一言
-    public static String sendAsk(String str) throws IOException {
+    public static String yiyan(String str) throws IOException {
     	OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
         MediaType mediaType = MediaType.parse("application/json");
         RequestBody ebRequestBody = RequestBody.create(mediaType, "{\"messages\":[{\"role\":\"user\",\"content\":\""+str+"\"}],\"stream\":false}");
@@ -59,7 +105,7 @@ public class AiApi {
         Response response = HTTP_CLIENT.newCall(request).execute();
         return response.body().string();
     }
-    
+
     public static void main(String []args) throws IOException{
         System.out.println(sendAsk("请说出你的名字"));
     }

+ 16 - 0
src/main/master1/com/yw/master1/eu/ai/service/AiMessageService.java

@@ -0,0 +1,16 @@
+package com.yw.master1.eu.ai.service;
+
+import com.yw.master1.eu.ai.model.AiMessage;
+
+import java.util.List;
+
+/**
+ * @author wangpx
+ * @version 1.0
+ */
+public interface AiMessageService {
+    int insert(AiMessage aiMessage) throws Exception;
+    List<AiMessage> selectBySessionId(Long sessionId) throws Exception;
+
+    int deleteBySessionId(Long sessionId);
+}

+ 22 - 0
src/main/master1/com/yw/master1/eu/ai/service/AiSessionService.java

@@ -0,0 +1,22 @@
+package com.yw.master1.eu.ai.service;
+
+import com.yw.master1.eu.ai.model.AiSession;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author wangpx
+ * @version 1.0
+ */
+public interface AiSessionService {
+    int insert(AiSession session) throws Exception;
+
+    List<AiSession> selectByUserId(Long userId) throws Exception;
+
+    int updateSessionName(AiSession session);
+
+    int updateChangeTime(AiSession session);
+
+    int delete(AiSession session) throws Exception;
+}

+ 33 - 0
src/main/master1/com/yw/master1/eu/ai/service/impl/AiMessageServiceImpl.java

@@ -0,0 +1,33 @@
+package com.yw.master1.eu.ai.service.impl;
+
+import com.yw.master1.eu.ai.dao.AiMessageDao;
+import com.yw.master1.eu.ai.model.AiMessage;
+import com.yw.master1.eu.ai.service.AiMessageService;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @author: wangpx
+ * @date: 2025-02-20 10:04
+ */
+public class AiMessageServiceImpl implements AiMessageService {
+    @Resource
+    private AiMessageDao aiMessageDao;
+
+
+    @Override
+    public int insert(AiMessage message) throws Exception {
+        return aiMessageDao.insert(message);
+    }
+
+    @Override
+    public List<AiMessage> selectBySessionId(Long sessionId) throws Exception {
+        return aiMessageDao.selectBySessionId(sessionId);
+    }
+
+    @Override
+    public int deleteBySessionId(Long sessionId) {
+        return aiMessageDao.deleteBySessionId(sessionId);
+    }
+}

+ 44 - 0
src/main/master1/com/yw/master1/eu/ai/service/impl/AiSessionServiceImpl.java

@@ -0,0 +1,44 @@
+package com.yw.master1.eu.ai.service.impl;
+
+import com.yw.master1.eu.ai.dao.AiSessionDao;
+import com.yw.master1.eu.ai.model.AiSession;
+import com.yw.master1.eu.ai.service.AiSessionService;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @author: wangpx
+ * @date: 2025-02-20 10:04
+ */
+public class AiSessionServiceImpl implements AiSessionService {
+    @Resource
+    private AiSessionDao aiSessionDao;
+
+    @Override
+    public int insert(AiSession session) throws Exception {
+        return aiSessionDao.insert(session);
+    }
+
+    @Override
+    public List<AiSession> selectByUserId(Long userId) throws Exception {
+        return aiSessionDao.selectByUserId(userId);
+    }
+
+    @Override
+    public int updateSessionName(AiSession session) {
+        return aiSessionDao.updateSessionName(session);
+    }
+
+    @Override
+    public int updateChangeTime(AiSession session) {
+        return aiSessionDao.updateChangeTime(session);
+    }
+
+    @Override
+    public int delete(AiSession session) throws Exception {
+        return aiSessionDao.delete(session);
+    }
+
+
+}