¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smtaiserver.smtaiserver.attach;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | | import java.util.Map.Entry;
|
| | |
|
| | | import org.dom4j.Document;
|
| | | import org.dom4j.Element;
|
| | |
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecord;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecords;
|
| | | import com.smtaiserver.smtaiserver.javaai.ast.ASTDBMap;
|
| | | import com.smtservlet.util.Json;
|
| | | import com.smtservlet.util.SMTJsonWriter;
|
| | | import com.smtservlet.util.SMTStatic;
|
| | |
|
| | | public class SMTAIAttachMetricDef |
| | | {
|
| | | private String _id;
|
| | | private String _title;
|
| | | private String _group;
|
| | | private SMTAttachMetricSqlXml _sqlxmlName;
|
| | | private SMTAttachMetricSqlXml _sqlxmlValue;
|
| | | |
| | | public SMTAIAttachMetricDef(DBRecord rec) throws Exception
|
| | | {
|
| | | _id = rec.getString("metric_id");
|
| | | _title = rec.getString("metric_title");
|
| | | _group = rec.getString("metric_group");
|
| | | Document doc = SMTStatic.convStrToXmlDoc("<ROOT>" + rec.getString("metric_config") + "</ROOT>");
|
| | | Element xmlNameSql = (Element) doc.selectSingleNode("ROOT/NAME_SQL");
|
| | | _sqlxmlName = new SMTAttachMetricSqlXml(xmlNameSql);
|
| | | |
| | | Element xmValueSql = (Element) doc.selectSingleNode("ROOT/VALUE_SQL");
|
| | | _sqlxmlValue = new SMTAttachMetricSqlXml(xmValueSql);
|
| | |
|
| | | }
|
| | | |
| | | public String getId()
|
| | | {
|
| | | return _id;
|
| | | }
|
| | | |
| | | public String getTitle()
|
| | | {
|
| | | return _title;
|
| | | }
|
| | | |
| | | public String getGroup()
|
| | | {
|
| | | return _group;
|
| | | }
|
| | | |
| | | public void queryNameToJson(String name, SMTJsonWriter jsonWr) throws Exception
|
| | | {
|
| | | try(ASTDBMap dbMap = new ASTDBMap())
|
| | | {
|
| | | SMTDatabase db = dbMap.getDatabase(_sqlxmlName.getDSId());
|
| | | String sql = _sqlxmlName.createSQL(null);
|
| | | DBRecords recs = db.querySQL("SELECT * FROM (" + sql + ") T WHERE title ILIKE ? LIMIT 5", new Object[] {"%" + name + "%"});
|
| | | for(DBRecord rec : recs.getRecords())
|
| | | {
|
| | | jsonWr.beginMap(null);
|
| | | for(Entry<String, Integer> entry : rec.getFieldMap().entrySet())
|
| | | {
|
| | | jsonWr.addKeyValue(entry.getKey(), rec.getString(entry.getValue()));
|
| | | }
|
| | | jsonWr.endMap();
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | public void queryValueToJson(Date startTime, Date endTime, Json jsonQuotaKey, SMTJsonWriter jsonWr) 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));
|
| | | |
| | | for(Entry<String, Json> entry : jsonQuotaKey.asJsonMap().entrySet())
|
| | | {
|
| | | mapArgs.put(entry.getKey(), entry.getValue().asString());
|
| | | }
|
| | | |
| | | SMTDatabase db = dbMap.getDatabase(_sqlxmlName.getDSId());
|
| | | String sql = _sqlxmlValue.createSQL(mapArgs);
|
| | | DBRecords recs = db.querySQL(sql, null);
|
| | | for(DBRecord rec : recs.getRecords())
|
| | | {
|
| | | jsonWr.beginMap(null);
|
| | | for(Entry<String, Integer> entry : rec.getFieldMap().entrySet())
|
| | | {
|
| | | jsonWr.addKeyValue(entry.getKey(), rec.getString(entry.getValue()));
|
| | | }
|
| | | jsonWr.endMap();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smtaiserver.smtaiserver.attach;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.dom4j.Element;
|
| | | import org.dom4j.Node;
|
| | | import org.dom4j.tree.DefaultText;
|
| | |
|
| | | import com.smtservlet.util.SMTStatic;
|
| | |
|
| | | public class SMTAttachMetricSqlXml |
| | | {
|
| | | ///////////////////////////////////////////////////////////////////////////////////////
|
| | | private static class SQLXMLExecArg
|
| | | {
|
| | | public StringBuilder _sbSQLText = new StringBuilder();
|
| | | public List<Object> _sqlParams = new ArrayList<>();
|
| | | public Map<String, String> _mapArgs;
|
| | | |
| | | public SQLXMLExecArg(Map<String, String> mapArgs)
|
| | | {
|
| | | _mapArgs = mapArgs;
|
| | | }
|
| | | |
| | | public Object getArgValue(String key) throws Exception
|
| | | {
|
| | | String value = _mapArgs.get(key);
|
| | | if(value == null)
|
| | | throw new Exception("can't find arg : " + key);
|
| | | return value;
|
| | | }
|
| | | }
|
| | | |
| | | ///////////////////////////////////////////////////////////////////////////////////////
|
| | | private static abstract class SQLXMLNode
|
| | | {
|
| | | public abstract void execute(SQLXMLExecArg execArg) throws Exception;
|
| | | }
|
| | | |
| | | |
| | | ///////////////////////////////////////////////////////////////////////////////////////
|
| | | private static class SQLXMLNodeSQL extends SQLXMLNode
|
| | | {
|
| | | private List<Object> _listChildren = new ArrayList<>();
|
| | | |
| | | public SQLXMLNodeSQL(Element xmlRoot) throws Exception
|
| | | {
|
| | | for (Iterator<Node> iterInner = xmlRoot.nodeIterator(); iterInner.hasNext();)
|
| | | { |
| | | Node nodeInner = iterInner.next();
|
| | | if(nodeInner.getNodeType() == Node.TEXT_NODE)
|
| | | {
|
| | | String text = ((DefaultText)nodeInner).getText();
|
| | | int lastPos = _listChildren.size() - 1;
|
| | | if(lastPos >= 0 && _listChildren.get(lastPos) instanceof String)
|
| | | {
|
| | | _listChildren.set(lastPos, (String)_listChildren.get(lastPos) + text);
|
| | | }
|
| | | else
|
| | | {
|
| | | _listChildren.add(text);
|
| | | }
|
| | | } |
| | | else
|
| | | {
|
| | | _listChildren.add(createSQLXMLNode((Element)nodeInner));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void execute(SQLXMLExecArg execArg) throws Exception
|
| | | {
|
| | | for(Object oxmlNode : _listChildren)
|
| | | {
|
| | | if(oxmlNode instanceof String)
|
| | | {
|
| | | execArg._sbSQLText.append(oxmlNode);
|
| | | }
|
| | | else if(oxmlNode instanceof SQLXMLNode)
|
| | | {
|
| | | ((SQLXMLNode)oxmlNode).execute(execArg);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | ///////////////////////////////////////////////////////////////////////////////////////
|
| | | private static class SQLXMLNodePARAM extends SQLXMLNode
|
| | | {
|
| | | private String _key;
|
| | | |
| | | public SQLXMLNodePARAM(Element xmlRoot) throws Exception
|
| | | {
|
| | | _key = SMTStatic.getXmlAttr(xmlRoot, "key");
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void execute(SQLXMLExecArg execArg) throws Exception |
| | | {
|
| | | execArg._sbSQLText.append("'" + SMTStatic.toString(execArg.getArgValue(_key)).replace("'", "''") + "'");
|
| | | }
|
| | | }
|
| | | ///////////////////////////////////////////////////////////////////////////////////////
|
| | | private String _dsId;
|
| | | private SQLXMLNode _SQLXMLNode;
|
| | | |
| | | private static SQLXMLNode createSQLXMLNode(Element xmlRoot) throws Exception
|
| | | {
|
| | | String name = xmlRoot.getName().toUpperCase();
|
| | | if( "NAME_SQL".equals(name)
|
| | | || "VALUE_SQL".equals(name))
|
| | | return new SQLXMLNodeSQL(xmlRoot);
|
| | | else if("PARAM".equals(name))
|
| | | return new SQLXMLNodePARAM(xmlRoot);
|
| | | else
|
| | | throw new Exception("unknow SQLXML : " + name);
|
| | | }
|
| | | |
| | | public String getDSId()
|
| | | {
|
| | | return _dsId;
|
| | | }
|
| | |
|
| | | public SMTAttachMetricSqlXml(Element rootElement) throws Exception
|
| | | {
|
| | | _dsId = SMTStatic.getXmlAttr(rootElement, "ds_id", null);
|
| | | |
| | | _SQLXMLNode = createSQLXMLNode(rootElement);
|
| | | }
|
| | |
|
| | | public String createSQL(Map<String, String> mapArgs) throws Exception |
| | | {
|
| | | // çæåå§SQL
|
| | | SQLXMLExecArg execArg = new SQLXMLExecArg(mapArgs);
|
| | | _SQLXMLNode.execute(execArg);
|
| | | |
| | | return execArg._sbSQLText.toString();
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | import org.springframework.web.servlet.View;
|
| | | import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
| | |
|
| | | import com.smtaiserver.smtaiserver.attach.SMTAIAttachMetricDef;
|
| | | import com.smtaiserver.smtaiserver.attach.SMTAIAttachTableDef;
|
| | | import com.smtaiserver.smtaiserver.attach.SMTAIAttachTableDef.SMTAIAttachTableColumn;
|
| | | import com.smtaiserver.smtaiserver.core.SMTAIServerApp;
|
| | |
| | | return tranReq.returnJson(jsonWr);
|
| | |
|
| | | }
|
| | | |
| | | public ModelAndView getAttachMetricList(SMTAIServerRequest tranReq) throws Exception |
| | | {
|
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | jsonWr.beginArray("metrics");
|
| | | for(SMTAIAttachMetricDef attachMetricDef : SMTAIServerApp.getApp().getAttachMetricDefMap().values())
|
| | | {
|
| | | jsonWr.beginMap(null);
|
| | | {
|
| | | jsonWr.addKeyValue("id", attachMetricDef.getId());
|
| | | jsonWr.addKeyValue("title", attachMetricDef.getTitle());
|
| | | jsonWr.addKeyValue("group", attachMetricDef.getGroup());
|
| | |
|
| | | }
|
| | | jsonWr.endMap();
|
| | | }
|
| | | jsonWr.endArray();
|
| | | |
| | | return tranReq.returnJson(jsonWr); |
| | | }
|
| | | |
| | | public ModelAndView queryAttachMetricNames(SMTAIServerRequest tranReq) throws Exception |
| | | {
|
| | | String attachMetricId = tranReq.convParamToString("id", true);
|
| | | String queryName = tranReq.convParamToString("name", true);
|
| | | SMTAIAttachMetricDef attachMetricDef = SMTAIServerApp.getApp().getAttachMetricDef(attachMetricId);
|
| | | |
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | jsonWr.beginArray("values");
|
| | | attachMetricDef.queryNameToJson(queryName, jsonWr);
|
| | | jsonWr.endArray();
|
| | | |
| | | return tranReq.returnJson(jsonWr);
|
| | | }
|
| | | |
| | | public ModelAndView queryAttachMetricValues(SMTAIServerRequest tranReq) throws Exception |
| | | {
|
| | | String attachMetricId = tranReq.convParamToString("id", true);
|
| | | Date startTime = tranReq.convParamToDate("start_time", true);
|
| | | Date endTime = tranReq.convParamToDate("end_time", true);
|
| | | Json jsonQuotaKeys = tranReq.convParamToJson("quota_keys", true);
|
| | | |
| | | SMTAIAttachMetricDef attachMetricDef = SMTAIServerApp.getApp().getAttachMetricDef(attachMetricId);
|
| | | |
| | | SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null);
|
| | | jsonWr.beginArray("values");
|
| | | attachMetricDef.queryValueToJson(startTime, endTime, jsonQuotaKeys, jsonWr);
|
| | | jsonWr.endArray();
|
| | | |
| | | return tranReq.returnJson(jsonWr);
|
| | | }
|
| | | }
|
| | |
| | | import org.springframework.web.context.WebApplicationContext;
|
| | |
|
| | | import com.alibaba.druid.pool.DruidDataSource;
|
| | | import com.smtaiserver.smtaiserver.attach.SMTAIAttachMetricDef;
|
| | | import com.smtaiserver.smtaiserver.attach.SMTAIAttachTableDef;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase;
|
| | | import com.smtaiserver.smtaiserver.gismap.SMTGisMapLayerDef;
|
| | |
| | | "getMapVPropDefMap",
|
| | | "getMapThemeTableDefMap",
|
| | | "getMapThemeDefMap",
|
| | | "getAttachTableDefMap"
|
| | | "getAttachTableDefMap",
|
| | | "getAttachMetricDefMap"
|
| | | };
|
| | |
|
| | | public static SMTAIServerApp getApp()
|
| | |
| | | _serverEncache.getMapThemeTableDefMap();
|
| | | _serverEncache.getMapThemeDefMap();
|
| | | _serverEncache.getAttachTableDefMap();
|
| | | _serverEncache.getAttachMetricDefMap();
|
| | | }
|
| | |
|
| | | public SMTMapTableDef getMapTableDef(String tableId) throws Exception
|
| | |
| | |
|
| | | return attachTableDef;
|
| | | }
|
| | | |
| | | public Map<String, SMTAIAttachMetricDef> getAttachMetricDefMap() throws Exception
|
| | | {
|
| | | return _serverEncache.getAttachMetricDefMap();
|
| | | }
|
| | | |
| | | public SMTAIAttachMetricDef getAttachMetricDef(String id) throws Exception
|
| | | {
|
| | | SMTAIAttachMetricDef attachMetricDef = _serverEncache.getAttachMetricDefMap().get(id);
|
| | | if(attachMetricDef == null)
|
| | | throw new Exception("can't find attach metric def : " + id);
|
| | | |
| | | return attachMetricDef;
|
| | | }
|
| | | }
|
| | |
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.cache.annotation.Cacheable;
|
| | |
|
| | | import com.smtaiserver.smtaiserver.attach.SMTAIAttachMetricDef;
|
| | | import com.smtaiserver.smtaiserver.attach.SMTAIAttachTableDef;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase;
|
| | | import com.smtaiserver.smtaiserver.database.SMTDatabase.DBQueryNotify;
|
| | |
| | | }
|
| | | return mapResult;
|
| | | }
|
| | | |
| | | @Cacheable(value="getAttachMetricDefMap")
|
| | | public Map<String, SMTAIAttachMetricDef> getAttachMetricDefMap() throws Exception
|
| | | {
|
| | | Map<String, SMTAIAttachMetricDef> mapResult = new HashMap<>();
|
| | | SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
|
| | | try
|
| | | {
|
| | | DBRecords recs;
|
| | | |
| | | recs = db.querySQL("SELECT * FROM ai_attach_metric", null);
|
| | | for(DBRecord rec : recs.getRecords())
|
| | | {
|
| | | SMTAIAttachMetricDef attachMetricDef = new SMTAIAttachMetricDef(rec);
|
| | | mapResult.put(attachMetricDef.getId(), attachMetricDef);
|
| | | }
|
| | |
|
| | | }
|
| | | finally
|
| | | {
|
| | | db.close();
|
| | | }
|
| | | return mapResult; |
| | | }
|
| | |
|
| | | }
|
| | |
| | | ]
|
| | | }
|
| | | ]
|
| | | },
|
| | | |
| | | "attach/get_attach_metric_list":{"map":{"class":"#SMTJavaAIControl", "method":"getAttachMetricList"},
|
| | | "swaggers":[
|
| | | { "tags" : ["éä»¶æä½"],
|
| | | "title" : "è·åéä»¶ææ å®ä¹å表",
|
| | | "parameters" : [
|
| | | ]
|
| | | }
|
| | | ]
|
| | | },
|
| | | |
| | | "attach/query_attach_metric_names":{"map":{"class":"#SMTJavaAIControl", "method":"queryAttachMetricNames"},
|
| | | "swaggers":[
|
| | | { "tags" : ["éä»¶æä½"],
|
| | | "title" : "æ¥è¯¢éä»¶ææ åç§°",
|
| | | "parameters" : [
|
| | | {"name":"id", "title":"æ¥è¯¢ææ id", "required":true},
|
| | | {"name":"name", "title":"æ¥è¯¢ææ åç§°", "required":true}
|
| | | ]
|
| | | }
|
| | | ]
|
| | | },
|
| | | |
| | | "attach/query_attach_metric_values":{"map":{"class":"#SMTJavaAIControl", "method":"queryAttachMetricValues"},
|
| | | "swaggers":[
|
| | | { "tags" : ["éä»¶æä½"],
|
| | | "title" : "æ¥è¯¢éä»¶ææ å¼",
|
| | | "parameters" : [
|
| | | {"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}
|
| | | ]
|
| | | }
|
| | | ]
|
| | | }
|
| | | } |