| | |
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecord;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecords;
|
| | | import com.smtservlet.core.SMTApp;
|
| | | import com.smtservlet.util.SMTJsonWriter;
|
| | | import com.smtservlet.util.SMTStatic;
|
| | |
|
| | |
| | | {
|
| | | db.close();
|
| | | }
|
| | | } |
| | | |
| | | }
|
| | |
|
| | | public ModelAndView addRoleInfo(SMTAIServerRequest tranReq) throws Exception {
|
| | | String roleId = tranReq.convParamToString("role_id", true);
|
| | | String roleTitle = tranReq.convParamToString("role_title", true);
|
| | |
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | |
|
| | | try {
|
| | | // 检查角色ID是否已存在
|
| | | String selectSql = "SELECT * FROM ai_sys.sys_role_info WHERE role_id = ?";
|
| | | Object[] selectParams = {roleId};
|
| | | if (db.querySQL(selectSql, selectParams).getRowCount() > 0) {
|
| | | return tranReq.returnJsonState(false, "角色ID已存在", null);
|
| | | }
|
| | |
|
| | | // 插入新角色
|
| | | String insertSql = "INSERT INTO ai_sys.sys_role_info (role_id, role_title) VALUES (?, ?)";
|
| | | Object[] insertParams = {roleId, roleTitle};
|
| | |
|
| | | db.executeSQL(insertSql, insertParams);
|
| | |
|
| | | // 返回 JSON 结果
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } finally {
|
| | | db.close();
|
| | | } |
| | | }
|
| | |
|
| | | public ModelAndView updateRoleInfo(SMTAIServerRequest tranReq) throws Exception {
|
| | | String roleId = tranReq.convParamToString("role_id", true);
|
| | | String roleTitle = tranReq.convParamToString("role_title", false);
|
| | |
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | |
|
| | | try {
|
| | | // 检查角色ID是否存在
|
| | | String selectSql = "SELECT * FROM ai_sys.sys_role_info WHERE role_id = ?";
|
| | | Object[] selectParams = {roleId};
|
| | | if (db.querySQL(selectSql, selectParams).getRowCount() == 0) {
|
| | | return tranReq.returnJsonState(false, "角色ID不存在", null);
|
| | | }
|
| | |
|
| | | // 更新角色信息
|
| | | String updateSql = "UPDATE ai_sys.sys_role_info SET role_title = ? WHERE role_id = ?";
|
| | | Object[] updateParams = {roleTitle, roleId};
|
| | |
|
| | | db.executeSQL(updateSql, updateParams);
|
| | |
|
| | | // 返回 JSON 结果
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } finally {
|
| | | db.close();
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | public ModelAndView addUserInfo(SMTAIServerRequest tranReq) throws Exception
|
| | | {
|
| | | String userName = tranReq.convParamToString("user_name", true);
|
| | |
| | | db.close();
|
| | | }
|
| | | }
|
| | |
|
| | | public ModelAndView addLLMFactory(SMTAIServerRequest tranReq) throws Exception {
|
| | | // 解析请求参数
|
| | | String factoryId = tranReq.convParamToString("factory_id", true);
|
| | | String factoryTitle = tranReq.convParamToString("factory_title",true);
|
| | | String factoryArgs = tranReq.convParamToString("factory_args",true);
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | | try {
|
| | |
|
| | | String selectSql = "SELECT * FROM ai_llm_factory WHERE factory_id = ?";
|
| | | Object[] params1 = {factoryId};
|
| | | if (db.querySQL(selectSql, params1).getRowCount()>0) {
|
| | | return tranReq.returnJsonState(false, "模型id已存在", null);
|
| | | }
|
| | | // 构建 SQL 语句
|
| | | String sql = "INSERT INTO ai_llm_factory (factory_id, factory_title, factory_args) VALUES (?, ?, ?)";
|
| | | Object[] params2 = {factoryId, factoryTitle, factoryArgs};
|
| | | // 执行插入操作
|
| | | db.executeSQL(sql, params2);
|
| | | // 返回 JSON 结果
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } finally {
|
| | | db.close();
|
| | | }
|
| | | }
|
| | | public ModelAndView addLLMConnect(SMTAIServerRequest tranReq) throws Exception {
|
| | | // 解析请求参数
|
| | | String connectId = tranReq.convParamToString("connect_id", true);
|
| | | String factoryId = tranReq.convParamToString("factory_id", true);
|
| | | String connectTitle = tranReq.convParamToString("connect_title", true);
|
| | | String className = tranReq.convParamToString("class_name", true);
|
| | | String connectArgs = tranReq.convParamToString("connect_args", true);
|
| | |
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | |
|
| | | try {
|
| | | // 首先检查模型id是否存在
|
| | | String selectFactorySql = "SELECT * FROM ai_llm_factory WHERE factory_id = ?";
|
| | | Object[] factoryParams = {factoryId};
|
| | | if (db.querySQL(selectFactorySql, factoryParams).getRowCount() == 0) {
|
| | | return tranReq.returnJsonState(false, "模型id不存在", null);
|
| | | }
|
| | |
|
| | | // 检查连接id是否已存在
|
| | | String selectConnectSql = "SELECT * FROM ai_llm_connect WHERE connect_id = ?";
|
| | | Object[] connectParams = {connectId};
|
| | | if (db.querySQL(selectConnectSql, connectParams).getRowCount() > 0) {
|
| | | return tranReq.returnJsonState(false, "连接id已存在", null);
|
| | | }
|
| | |
|
| | | // 构建 SQL 语句
|
| | | String insertSql = "INSERT INTO ai_llm_connect (connect_id, factory_id, connect_title, class_name, connect_args) VALUES (?, ?, ?, ?, ?)";
|
| | | Object[] insertParams = {connectId, factoryId, connectTitle, className, connectArgs};
|
| | |
|
| | | // 执行插入操作
|
| | | db.executeSQL(insertSql, insertParams);
|
| | |
|
| | | // 返回 JSON 结果
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } finally {
|
| | | db.close();
|
| | | }
|
| | | }
|
| | | public ModelAndView updateLLMFactory(SMTAIServerRequest tranReq) throws Exception {
|
| | | // 解析请求参数
|
| | | String factoryId = tranReq.convParamToString("factory_id", true);
|
| | | String factoryTitle = tranReq.convParamToString("factory_title", true);
|
| | | String factoryArgs = tranReq.convParamToString("factory_args", true);
|
| | |
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | |
|
| | | try {
|
| | | // 检查工厂 ID 是否存在
|
| | | String selectSql = "SELECT * FROM ai_llm_factory WHERE factory_id = ?";
|
| | | Object[] params = {factoryId};
|
| | | if (db.querySQL(selectSql, params).getRowCount() == 0) {
|
| | | return tranReq.returnJsonState(false, "模型id不存在", null);
|
| | | }
|
| | |
|
| | | // 构建 SQL 语句
|
| | | String updateSql = "UPDATE ai_llm_factory SET factory_title = ?, factory_args = ? WHERE factory_id = ?";
|
| | | Object[] updateParams = {factoryTitle, factoryArgs, factoryId};
|
| | |
|
| | | // 执行更新操作
|
| | | db.executeSQL(updateSql, updateParams);
|
| | |
|
| | | // 返回 JSON 结果
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } finally {
|
| | | db.close();
|
| | | }
|
| | | }
|
| | | public ModelAndView updateLLMConnect(SMTAIServerRequest tranReq) throws Exception {
|
| | | // 解析请求参数
|
| | | String connectId = tranReq.convParamToString("connect_id", true);
|
| | | String factoryId = tranReq.convParamToString("factory_id", true);
|
| | | String connectTitle = tranReq.convParamToString("connect_title", true);
|
| | | String className = tranReq.convParamToString("class_name", true);
|
| | | String connectArgs = tranReq.convParamToString("connect_args", true);
|
| | |
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | |
|
| | | try {
|
| | | // 检查连接 ID 是否存在
|
| | | String selectConnectSql = "SELECT * FROM ai_llm_connect WHERE connect_id = ?";
|
| | | Object[] connectParams = {connectId};
|
| | | if (db.querySQL(selectConnectSql, connectParams).getRowCount() == 0) {
|
| | | return tranReq.returnJsonState(false, "连接id不存在", null);
|
| | | }
|
| | |
|
| | | // 检查模型 ID 是否存在
|
| | | String selectFactorySql = "SELECT * FROM ai_llm_factory WHERE factory_id = ?";
|
| | | Object[] factoryParams = {factoryId};
|
| | | if (db.querySQL(selectFactorySql, factoryParams).getRowCount() == 0) {
|
| | | return tranReq.returnJsonState(false, "模型id不存在", null);
|
| | | }
|
| | |
|
| | | // 构建 SQL 语句
|
| | | String updateSql = "UPDATE ai_llm_connect SET factory_id = ?, connect_title = ?, class_name = ?, connect_args = ? WHERE connect_id = ?";
|
| | | Object[] updateParams = {factoryId, connectTitle, className, connectArgs, connectId};
|
| | |
|
| | | // 执行更新操作
|
| | | db.executeSQL(updateSql, updateParams);
|
| | |
|
| | | // 返回 JSON 结果
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } finally {
|
| | | db.close();
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | public ModelAndView clearSystemCache(SMTAIServerRequest tranReq) throws Exception
|
| | | {
|
| | | SMTApp.getThis().clearEhCacheManager();
|
| | | return tranReq.returnJsonState(true, null, null);
|
| | | }
|
| | | |
| | | |
| | | public ModelAndView getQuestionReplaceList(SMTAIServerRequest tranReq) throws Exception
|
| | | {
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | try(SMTDatabase db = SMTAIServerApp.getApp().allocDatabase())
|
| | | {
|
| | | DBRecords recs = db.querySQL("SELECT * FROM ai_question_replace", null);
|
| | | |
| | | jsonWr.beginArray("values");
|
| | | for(DBRecord rec : recs.getRecords())
|
| | | {
|
| | | jsonWr.beginMap(null);
|
| | | {
|
| | | jsonWr.addKeyValue("id", rec.getString("replace_id"));
|
| | | jsonWr.addKeyValue("question", rec.getString("question_text"));
|
| | | jsonWr.addKeyValue("replace", rec.getString("replace_text"));
|
| | | jsonWr.addKeyValue("order", rec.getString("replace_order"));
|
| | | jsonWr.addKeyValue("state", rec.getString("replace_state"));
|
| | | jsonWr.addKeyValue("group", rec.getString("group_type"));
|
| | | jsonWr.addKeyValue("create_time", rec.getString("create_time"));
|
| | | }
|
| | | jsonWr.endMap();
|
| | | }
|
| | | jsonWr.endArray();
|
| | | }
|
| | | return tranReq.returnJson(jsonWr);
|
| | | }
|
| | | public ModelAndView addQuestionReplace(SMTAIServerRequest tranReq) throws Exception {
|
| | | String loginUserId = tranReq.getLoginUserId();
|
| | | // 解析请求参数
|
| | | String replaceId = tranReq.convParamToString("replace_id", true);
|
| | | String questionText = tranReq.convParamToString("question_text", true);
|
| | | String replaceText = tranReq.convParamToString("replace_text", true);
|
| | | int replaceOrder = tranReq.convParamToInteger("replace_order", true);
|
| | | String replaceState = tranReq.convParamToString("replace_state", true);
|
| | | String groupType = tranReq.convParamToString("group_type", true);
|
| | |
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | |
|
| | | try {
|
| | | // 检查替换ID是否已存在
|
| | | String selectSql = "SELECT * FROM ai_question_replace WHERE replace_id = ?";
|
| | | Object[] selectParams = {replaceId};
|
| | | if (db.querySQL(selectSql, selectParams).getRowCount() > 0) {
|
| | | return tranReq.returnJsonState(false, "替换ID已存在", null);
|
| | | }
|
| | |
|
| | | // 构建 SQL 语句
|
| | | String insertSql = "INSERT INTO ai_question_replace (replace_id, question_text, replace_text, replace_order, replace_state, create_user, create_time, group_type) " +
|
| | | "VALUES (?, ?, ?, ?, ?, ?, NOW(), ?)";
|
| | | Object[] insertParams = {
|
| | | replaceId, questionText, replaceText, replaceOrder, replaceState, loginUserId, groupType
|
| | | };
|
| | |
|
| | | // 执行插入操作
|
| | | db.executeSQL(insertSql, insertParams);
|
| | |
|
| | | // 返回 JSON 结果
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } finally {
|
| | | db.close();
|
| | | }
|
| | | }
|
| | | public ModelAndView updateQuestionReplace(SMTAIServerRequest tranReq) throws Exception {
|
| | | // 解析请求参数
|
| | | String replaceId = tranReq.convParamToString("replace_id", true);
|
| | | String questionText = tranReq.convParamToString("question_text", false);
|
| | | String replaceText = tranReq.convParamToString("replace_text", false);
|
| | | int replaceOrder = tranReq.convParamToInteger("replace_order", false);
|
| | | String replaceState = tranReq.convParamToString("replace_state", false);
|
| | | String groupType = tranReq.convParamToString("group_type", false);
|
| | |
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | |
|
| | | try {
|
| | | // 检查替换ID是否存在
|
| | | String selectSql = "SELECT * FROM ai_question_replace WHERE replace_id = ?";
|
| | | Object[] selectParams = {replaceId};
|
| | | if (db.querySQL(selectSql, selectParams).getRowCount() == 0) {
|
| | | return tranReq.returnJsonState(false, "替换ID不存在", null);
|
| | | }
|
| | |
|
| | | // 构建 SQL 语句
|
| | | String updateSql = "UPDATE ai_question_replace SET question_text = ?, replace_text = ?, replace_order = ?, replace_state = ?, group_type = ? " +
|
| | | "WHERE replace_id = ?";
|
| | | Object[] updateParams = {questionText, replaceText, replaceOrder, replaceState, groupType, replaceId};
|
| | |
|
| | | // 执行更新操作
|
| | | db.executeSQL(updateSql, updateParams);
|
| | |
|
| | | // 返回 JSON 结果
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | return tranReq.returnJson(jsonWr);
|
| | | } finally {
|
| | | db.close();
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | }
|