| | |
| | |
|
| | | <dependencies>
|
| | | <dependency>
|
| | | <groupId>org.apache.pdfbox</groupId>
|
| | | <artifactId>pdfbox</artifactId>
|
| | | <version>2.0.27</version>
|
| | | </dependency>
|
| | |
|
| | | <dependency>
|
| | | <groupId>org.apache.poi</groupId>
|
| | | <artifactId>poi-scratchpad</artifactId>
|
| | | <version>5.2.2</version>
|
| | | </dependency>
|
| | | <dependency>
|
| | | <groupId>org.apache.poi</groupId>
|
| | | <artifactId>poi-ooxml</artifactId>
|
| | | <version>5.2.2</version>
|
| | | </dependency>
|
| | |
|
| | | <dependency>
|
| | | <groupId>com.smtservlet</groupId>
|
| | | <artifactId>SMTServlet</artifactId>
|
| | | <version>0.0.1-SNAPSHOT</version>
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public void queryValueToJson(Date startTime, Date endTime, Json jsonQuotaKey, SMTJsonWriter jsonWr) throws Exception
|
| | | public void queryValueToJson(Date startTime, Date endTime, Json jsonQuotaKey, SMTJsonWriter jsonWr,Integer limit) throws Exception
|
| | | {
|
| | | try(ASTDBMap dbMap = new ASTDBMap())
|
| | | {
|
| | | Map<String, String> mapArgs = new HashMap<>();
|
| | | mapArgs.put("start_time", SMTStatic.toString(startTime));
|
| | | mapArgs.put("end_time", SMTStatic.toString(endTime));
|
| | | |
| | | mapArgs.put("limit", SMTStatic.toString(limit));
|
| | |
|
| | | for(Entry<String, Json> entry : jsonQuotaKey.asJsonMap().entrySet())
|
| | | {
|
| | | mapArgs.put(entry.getKey(), entry.getValue().asString());
|
| | |
| | | return _group;
|
| | | }
|
| | |
|
| | | public void queryRecordsToJson(Json jsonFilter, Json jsonOrder, SMTJsonWriter jsonWr) throws Exception
|
| | | public void queryRecordsToJson(Json jsonFilter, Json jsonOrder, SMTJsonWriter jsonWr,Integer limit) throws Exception
|
| | | {
|
| | | try(ASTDBMap dbMap = new ASTDBMap())
|
| | | {
|
| | | _sqlXml.querySQLToJson(dbMap, jsonFilter, jsonOrder, this, jsonWr);
|
| | | _sqlXml.querySQLToJson(dbMap, jsonFilter, jsonOrder, this, jsonWr,limit);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | _SQLXMLNode = createSQLXMLNode(rootElement);
|
| | | }
|
| | |
|
| | | public String createSQL(Map<String, String> mapArgs) throws Exception |
| | | public String createSQL(Map<String, String> mapArgs) throws Exception
|
| | | {
|
| | | // çæåå§SQL
|
| | | SQLXMLExecArg execArg = new SQLXMLExecArg(mapArgs);
|
| | | _SQLXMLNode.execute(execArg);
|
| | | |
| | | return execArg._sbSQLText.toString();
|
| | |
|
| | | String sql = execArg._sbSQLText.toString();
|
| | | if (mapArgs!=null){
|
| | | sql = sql.replace("LIMIT\n" +
|
| | | " 100", "LIMIT " + mapArgs.get("limit"));
|
| | | }
|
| | | return sql;
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | _SQLXMLNode = createSQLXMLNode(rootElement);
|
| | | }
|
| | |
|
| | | public void querySQLToJson(ASTDBMap dbMap, Json jsonFilters, Json jsonOrders, SMTAIAttachTableDef attachTableDef, SMTJsonWriter jsonWr) throws Exception |
| | | public void querySQLToJson(ASTDBMap dbMap, Json jsonFilters, Json jsonOrders, SMTAIAttachTableDef attachTableDef, SMTJsonWriter jsonWr,Integer limit) throws Exception
|
| | | {
|
| | | // çæåå§SQL
|
| | | SQLXMLExecArg execArg = new SQLXMLExecArg();
|
| | |
| | |
|
| | | SMTDatabase db = dbMap.getDatabase(_dsId);
|
| | | DBRecords recs = db.querySQL(
|
| | | "SELECT * FROM (" + execArg._sbSQLText.toString() + ") T " + sbWHERE.toString() + " " + sbORDER.toString() + " LIMIT 100", |
| | | execArg._sqlParams.size() == 0 ? null : execArg._sqlParams.toArray(new Object[] {execArg._sqlParams.size()})
|
| | | "SELECT * FROM (" + execArg._sbSQLText.toString() + ") T " + sbWHERE.toString() + " " + sbORDER.toString() + " LIMIT "+limit,
|
| | | execArg._sqlParams.isEmpty() ? null : execArg._sqlParams.toArray()
|
| | | );
|
| | |
|
| | |
|
| | | jsonWr.beginArray("columns");
|
| | | for(SMTAIAttachTableColumn column : attachTableDef.getColumnList())
|
| | |
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import org.springframework.web.bind.annotation.RequestParam;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.springframework.web.servlet.ModelAndView;
|
| | |
| | | tranReq.setAttachTables(jsonTables);
|
| | | _mustRawMode = true;
|
| | | }
|
| | | |
| | | Json jsonMetrics = tranReq.convParamToJson("metrics", false);
|
| | | if(jsonMetrics != null)
|
| | | {
|
| | | tranReq.setJsonAttachMetrics(jsonMetrics);
|
| | | _mustRawMode = true;
|
| | | }
|
| | |
|
| | | _tranReq = tranReq;
|
| | | _tranReq.setChunkedMode(true);
|
| | | }
|
| | |
| | | String attachTableId = tranReq.convParamToString("id", true);
|
| | | Json jsonFilters = tranReq.convParamToJson("filter", false);
|
| | | Json jsonOrders = tranReq.convParamToJson("order", false);
|
| | | Integer limit = tranReq.convParamToInteger("limit", false);
|
| | | SMTAIAttachTableDef attachTableDef = (SMTAIAttachTableDef) SMTAIServerApp.getApp().getAttachTableDef(attachTableId);
|
| | | |
| | | if (limit==null)
|
| | | limit=100;
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | attachTableDef.queryRecordsToJson(jsonFilters, jsonOrders, jsonWr);
|
| | | attachTableDef.queryRecordsToJson(jsonFilters, jsonOrders, jsonWr,limit);
|
| | |
|
| | | return tranReq.returnJson(jsonWr);
|
| | |
|
| | |
| | | Date startTime = tranReq.convParamToDate("start_time", true);
|
| | | Date endTime = tranReq.convParamToDate("end_time", true);
|
| | | Json jsonQuotaKeys = tranReq.convParamToJson("quota_keys", true);
|
| | | |
| | | Integer limit = tranReq.convParamToInteger("limit", false);
|
| | | if (limit==null)
|
| | | limit=100;
|
| | | SMTAIAttachMetricDef attachMetricDef = SMTAIServerApp.getApp().getAttachMetricDef(attachMetricId);
|
| | |
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | attachMetricDef.queryValueToJson(startTime, endTime, jsonQuotaKeys, jsonWr);
|
| | | attachMetricDef.queryValueToJson(startTime, endTime, jsonQuotaKeys, jsonWr,limit);
|
| | |
|
| | | return tranReq.returnJson(jsonWr);
|
| | | }
|
| | |
| | |
|
| | | return tranReq.returnJson(jsonWr);
|
| | | }
|
| | |
|
| | | public void downloadFileByFileId(SMTAIServerRequest tranReq, HttpServletResponse response) throws Exception {
|
| | | String fileId = tranReq.convParamToString("file_id", true); // è·å请æ±ä¸çfile_id
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | |
|
| | | try {
|
| | | // æ¥è¯¢æå®file_idçæä»¶è®°å½
|
| | | DBRecords dbRecords = db.querySQL("SELECT * FROM ai_times.chat_history_attach WHERE attach_id=?", new Object[]{fileId});
|
| | | if (dbRecords.getRecords().isEmpty()) {
|
| | | throw new Exception("æä»¶ä¸åå¨");
|
| | | }
|
| | |
|
| | | // è·åæä»¶ä¿¡æ¯
|
| | | DBRecord fileRecord = dbRecords.getRecords().get(0);
|
| | | String attachTitle = fileRecord.getString("attach_title"); // è·åæä»¶æ é¢
|
| | | String attachBytes = fileRecord.getString("attach_bytes");
|
| | | byte[] bytes = attachBytes.getBytes();
|
| | | // 设置ååºå¤´åæä»¶å
|
| | | String fileName = attachTitle != null ? attachTitle : "downloaded_file";
|
| | | response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
| | | response.setContentType("application/octet-stream");
|
| | | response.getOutputStream().write(bytes);
|
| | | response.getOutputStream().flush();
|
| | | } catch (Exception e) {
|
| | | throw new Exception("Error processing file download: " + e.getMessage());
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | package com.smtaiserver.smtaiserver.core;
|
| | |
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.io.InputStream;
|
| | | import java.io.*;
|
| | | import java.sql.Connection;
|
| | | import java.sql.DriverManager;
|
| | | import java.util.ArrayList;
|
| | |
| | |
|
| | | import org.apache.logging.log4j.LogManager;
|
| | | import org.apache.logging.log4j.Logger;
|
| | | import org.apache.pdfbox.pdmodel.PDDocument;
|
| | | import org.apache.pdfbox.text.PDFTextStripper;
|
| | | import org.apache.poi.hwpf.HWPFDocument;
|
| | | import org.apache.poi.hwpf.extractor.WordExtractor;
|
| | | import org.apache.poi.poifs.filesystem.FileMagic;
|
| | | import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
| | | import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
| | | import org.dom4j.Document;
|
| | | import org.dom4j.io.OutputFormat;
|
| | | import org.dom4j.io.XMLWriter;
|
| | |
| | | import net.sf.ehcache.CacheManager;
|
| | |
|
| | | import com.smtservlet.core.SMTApp.SMTEhCacheManagerInitialize;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | |
|
| | |
|
| | | public class SMTAIServerApp extends SMTApp implements SMTEhCacheManagerInitialize,SMTApp.SMTSessionListenerEvent
|
| | |
| | |
|
| | | return attachMetricDef;
|
| | | }
|
| | |
|
| | | /**
|
| | | * æä»¶(wordãpdf)转txt
|
| | | */
|
| | | public String fileTranslTxt(MultipartFile file) throws Exception {
|
| | | InputStream inputStream = file.getInputStream();
|
| | | try (BufferedInputStream bis = new BufferedInputStream(file.getInputStream())) {
|
| | | String mimeType = file.getContentType();
|
| | | if (mimeType != null) {
|
| | | switch (mimeType) {
|
| | | case "application/pdf":
|
| | | _logger.info("æä»¶ç±»åæ¯ PDF");
|
| | | PDDocument document = PDDocument.load(inputStream);
|
| | | PDFTextStripper stripper = new PDFTextStripper();
|
| | | return stripper.getText(document);
|
| | | case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
| | | _logger.info("æä»¶ç±»åæ¯ Word (DOCX)");
|
| | | try (XWPFDocument docx = new XWPFDocument(bis)) {
|
| | | XWPFWordExtractor docxExtractor = new XWPFWordExtractor(docx);
|
| | | return docxExtractor.getText();
|
| | | }
|
| | | case "application/msword":
|
| | | _logger.info("æä»¶ç±»åæ¯ Word (DOC)");
|
| | | try (HWPFDocument doc = new HWPFDocument(bis)) {
|
| | | WordExtractor wordExtractor = new WordExtractor(doc);
|
| | | return wordExtractor.getText();
|
| | | }
|
| | | default:
|
| | | _logger.info("æªç¥æä»¶ç±»å: " + mimeType);
|
| | | break;
|
| | | }
|
| | | } else {
|
| | | _logger.info("æ æ³è·åæä»¶ç±»å");
|
| | | }
|
| | | } catch (Exception e) {
|
| | | _logger.error("æä»¶å¤ç失败: " + e.getMessage());
|
| | | throw new Exception("æä»¶å¤ç失败: " + e.getMessage());
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | private boolean _disableConclusion = false;
|
| | | private List<AIAttachFile> _listAttchFile = null;
|
| | | private Json _jsonAttachTables = null;
|
| | | private Json _jsonAttachMetrics = null;
|
| | | private boolean _sendStarStream = false; // å°è¾åºæååæ*
|
| | |
|
| | |
|
| | |
| | | {
|
| | | _jsonAttachTables = jsonTables;
|
| | | }
|
| | | |
| | |
|
| | | public void setJsonAttachMetrics(Json attachMetrics)
|
| | | {
|
| | | _jsonAttachMetrics = attachMetrics;
|
| | | }
|
| | | public String[] getAttachMessage()
|
| | | {
|
| | | List<String> list = new ArrayList<>();
|
| | |
| | | {
|
| | | jsonResult.set("attach_tables", _jsonAttachTables);
|
| | | }
|
| | | if(_jsonAttachMetrics != null)
|
| | | {
|
| | | jsonResult.set("attach_metrics", _jsonAttachMetrics);
|
| | | }
|
| | | }
|
| | |
|
| | | public void addAttachFile(AIAttachFile attachFile)
|
| | |
| | | {"name":"group_type", "title":"é®é¢åç±»", "default":"ä¸å¡åºæ¯", "required":false},
|
| | | {"name":"cur_pos", "title":"å½åä½ç½®", "required":false},
|
| | | {"name":"files", "title":"éä»¶æä»¶", "required":false, "type":"file"},
|
| | | {"name":"tables", "title":"é件表记å½[{title:䏿å, columns:[åæ®µ1ï¼å段2...],values:[[å¼1ï¼å¼2...]]}]", "required":false}
|
| | | {"name":"tables", "title":"é件表记å½[{title:䏿å, columns:[åæ®µ1ï¼å段2...],values:[[å¼1ï¼å¼2...]]}]", "required":false},
|
| | | {"name":"metrics", "title":"éä»¶ææ è®°å½[{title:䏿å, columns:[åæ®µ1ï¼å段2...],values:[[å¼1ï¼å¼2...]]}]", "required":false}
|
| | | ]
|
| | | }
|
| | | ]
|
| | |
| | | "parameters" : [
|
| | | {"name":"id", "title":"æ¥è¯¢è¡¨id", "required":true},
|
| | | {"name":"filter", "title":"è¿æ»¤æ¡ä»¶[{col:åæ®µå, filter:è¿æ»¤æ¡ä»¶, values:[å¼1ï¼å¼2...]},...]", "required":false},
|
| | | {"name":"order", "title":"æåºæ¡ä»¶[{col:åæ®µå, order:ASC/DESC", "required":false}
|
| | | {"name":"order", "title":"æåºæ¡ä»¶[{col:åæ®µå, order:ASC/DESC", "required":false},
|
| | | {"name":"limit", "title":"æ¥è¯¢é¡µæ°ï¼é»è®¤100", "required":false}
|
| | | ]
|
| | | }
|
| | | ]
|
| | |
| | | {"name":"id", "title":"æ¥è¯¢ææ id", "required":true},
|
| | | {"name":"start_time", "title":"èµ·å§æ¶é´", "required":true},
|
| | | {"name":"end_time", "title":"ç»ææ¶é´", "required":true},
|
| | | {"name":"quota_keys", "title":"query_attach_metric_namesè¿åå端çjson", "required":true}
|
| | | {"name":"quota_keys", "title":"query_attach_metric_namesè¿åå端çjson", "required":true},
|
| | | {"name":"limit", "title":"æ¥è¯¢é¡µæ°ï¼é»è®¤100", "required":false}
|
| | | ]
|
| | | }
|
| | | ]
|
| | | },
|
| | | "file/download_file":{"map":{"class":"#SMTJavaAIControl", "method":"downloadFileByFileId"},
|
| | | "swaggers":[
|
| | | { "tags" : ["æä»¶ä¸è½½"],
|
| | | "title" : "æä»¶ä¸è½½",
|
| | | "parameters" : [
|
| | | {"name":"file_id", "title":"æä»¶id", "required":true}
|
| | | ]
|
| | | }
|
| | | ]
|
¶Ô±ÈÐÂÎļþ |
| | |
| | | # é»è®¤å¿½ç¥çæä»¶ |
| | | /shelf/ |
| | | /workspace.xml |
| | | # åºäºç¼è¾å¨ç HTTP 客æ·ç«¯è¯·æ± |
| | | /httpRequests/ |
| | | # Datasource local storage ignored files |
| | | /dataSources/ |
| | | /dataSources.local.xml |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project version="4"> |
| | | <component name="CompilerConfiguration"> |
| | | <annotationProcessing> |
| | | <profile default="true" name="Default" enabled="true" /> |
| | | <profile name="Maven default annotation processors profile" enabled="true"> |
| | | <sourceOutputDir name="target/generated-sources/annotations" /> |
| | | <sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> |
| | | <outputRelativeToContentRoot value="true" /> |
| | | <module name="SMTAIServerVer" /> |
| | | <module name="SMTAIServer" /> |
| | | <module name="SMTServlet" /> |
| | | </profile> |
| | | </annotationProcessing> |
| | | </component> |
| | | <component name="JavacSettings"> |
| | | <option name="ADDITIONAL_OPTIONS_OVERRIDE"> |
| | | <module name="SMTAIServer" options="-parameters" /> |
| | | <module name="SMTServlet" options="-parameters" /> |
| | | </option> |
| | | </component> |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project version="4"> |
| | | <component name="Encoding"> |
| | | <file url="file://$PROJECT_DIR$/../SMTAIServer/src/main/java" charset="UTF-8" /> |
| | | <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> |
| | | <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" /> |
| | | <file url="file://$PROJECT_DIR$/../SMTServlet/src/main/java" charset="UTF-8" /> |
| | | </component> |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project version="4"> |
| | | <component name="GoogleJavaFormatSettings"> |
| | | <option name="enabled" value="true" /> |
| | | </component> |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <component name="InspectionProjectProfileManager"> |
| | | <profile version="1.0"> |
| | | <option name="myName" value="Project Default" /> |
| | | <inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true"> |
| | | <option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,com.smtaiserver.smtaiserver.core.SMTAIServerApp,allocDatabase" /> |
| | | </inspection_tool> |
| | | </profile> |
| | | </component> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project version="4"> |
| | | <component name="RemoteRepositoriesConfiguration"> |
| | | <remote-repository> |
| | | <option name="id" value="central" /> |
| | | <option name="name" value="Central Repository" /> |
| | | <option name="url" value="https://repo.maven.apache.org/maven2" /> |
| | | </remote-repository> |
| | | <remote-repository> |
| | | <option name="id" value="central" /> |
| | | <option name="name" value="Maven Central repository" /> |
| | | <option name="url" value="https://repo1.maven.org/maven2" /> |
| | | </remote-repository> |
| | | <remote-repository> |
| | | <option name="id" value="jboss.community" /> |
| | | <option name="name" value="JBoss Community repository" /> |
| | | <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> |
| | | </remote-repository> |
| | | </component> |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project version="4"> |
| | | <component name="ExternalStorageConfigurationManager" enabled="true" /> |
| | | <component name="MavenProjectsManager"> |
| | | <option name="originalFiles"> |
| | | <list> |
| | | <option value="$PROJECT_DIR$/pom.xml" /> |
| | | <option value="$PROJECT_DIR$/../SMTAIServer/pom.xml" /> |
| | | </list> |
| | | </option> |
| | | </component> |
| | | <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK" /> |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <project version="4"> |
| | | <component name="VcsDirectoryMappings"> |
| | | <mapping directory="$PROJECT_DIR$/../.." vcs="Git" /> |
| | | </component> |
| | | </project> |