创建表、增加网关
<h6>创建表</h6>
<pre><code>CREATE TABLE "public"."BasicInspectionTask" (
"uuid" text NOT NULL,
"name" text,
"createTime" text,
"updateTime" text,
"state" int4,
"inspectionTemplateId" text,
"inspectorId" text,
"handlerUserId" text,
"taskState" text,
"jiguiCount" text,
"inspectionCount" text,
"overtimeState" text,
"startTime" text,
"endTime" text,
"abnormal" text,
"ordernum" text,
PRIMARY KEY ("uuid")
);
</code></pre>
<pre><code>CREATE TABLE "public"."BasicInspectionContentDetails" (
"uuid" text NOT NULL,
"name" text,
"createTime" text,
"updateTime" text,
"state" int4,
"mast" text,
"isnormalphoto" text,
"explain" text,
"inspectionItemName" text,
"inspectionItemId" text,
"type" text,
"exemptstate" text,
"inspectionTaskId" text,
"normalPhotoList" text,
"inspectionContentName" text,
"inspectionContentId" text,
"result" text,
"value" text,
"ordernum" text,
"isExemptState" text,
PRIMARY KEY ("uuid")
);
</code></pre>
<pre><code>CREATE TABLE "public"."InspectionContentAbnormal" (
"uuid" text NOT NULL,
"name" text,
"createTime" text,
"updateTime" text,
"state" int4,
"contentDetailsId" text,
"imgId" text,
"describe" text,
PRIMARY KEY ("uuid")
);
</code></pre>
<pre><code>CREATE TABLE "public"."InspectionJiguiAbnormal" (
"uuid" text NOT NULL,
"name" text,
"createTime" text,
"updateTime" text,
"state" int4,
"instanceId" text,
"imgId" text,
"jiguiDetailsId" text,
"describe" text,
"jiguiInfo" text,
PRIMARY KEY ("uuid")
);
</code></pre>
<pre><code>CREATE TABLE "public"."BasicInspectionAbnormalImg" (
"uuid" text NOT NULL,
"name" text,
"createTime" text,
"updateTime" text,
"state" int4,
"mapPath" text,
"path" text,
PRIMARY KEY ("uuid")
);
</code></pre>
<h5>增加网关</h5>
<pre><code>INSERT INTO "public"."BasicGatewayRoute" ("uuid", "name", "sourcepath", "module", "targeturl", "targetpath", "logtype", "logcontent", "param", "responsebody", "remark", "createTime", "state", "updateTime", "verify", "type", "moduleId") VALUES ('83b6a398-df3f-469b-9444-94c86d711829', '巡检列表树', '/ops/itsm/inspection/task/getInspTreeList', NULL, NULL, '/itsm/inspection/task/getInspTreeList', '查询', '', '', '', '', '2022-01-11 11:34:41', 0, '2022-01-11 11:34:41', 't', 'normal', 'fc956e4f5af54ad2af454ec352cea19b');
INSERT INTO "public"."BasicGatewayRoute" ("uuid", "name", "sourcepath", "module", "targeturl", "targetpath", "logtype", "logcontent", "param", "responsebody", "remark", "createTime", "state", "updateTime", "verify", "type", "moduleId") VALUES ('2b2d15db-cc3c-43bb-9281-039ab3c7af9e', '巡检列表', '/ops/itsm/inspection/task/getAllTask', NULL, NULL, '/itsm/inspection/task/getAllTask', '查询', '', '', '', '', '2022-01-11 11:35:19', 0, '2022-01-11 11:35:19', 't', 'normal', 'fc956e4f5af54ad2af454ec352cea19b');
INSERT INTO "public"."BasicGatewayRoute" ("uuid", "name", "sourcepath", "module", "targeturl", "targetpath", "logtype", "logcontent", "param", "responsebody", "remark", "createTime", "state", "updateTime", "verify", "type", "moduleId") VALUES ('f6b18ba4-0f6b-4f02-9496-56f7df05c27f', '开始巡检任务', '/ops/itsm/inspection/task/start', NULL, NULL, '/itsm/inspection/task/start', '操作', '', '', '', '', '2022-01-11 11:35:58', 0, '2022-01-11 11:35:58', 't', 'normal', 'fc956e4f5af54ad2af454ec352cea19b');
INSERT INTO "public"."BasicGatewayRoute" ("uuid", "name", "sourcepath", "module", "targeturl", "targetpath", "logtype", "logcontent", "param", "responsebody", "remark", "createTime", "state", "updateTime", "verify", "type", "moduleId") VALUES ('35d2d0ab-2132-41a9-a803-8f333b4d96f3', '通过Id查询巡检任务详情', '/ops/itsm/inspection/task/getTaskDetails', NULL, NULL, '/itsm/inspection/task/getTaskDetails', '查询', '', '', '', '', '2022-01-11 11:36:28', 0, '2022-01-11 11:36:28', 't', 'normal', 'fc956e4f5af54ad2af454ec352cea19b');
INSERT INTO "public"."BasicGatewayRoute" ("uuid", "name", "sourcepath", "module", "targeturl", "targetpath", "logtype", "logcontent", "param", "responsebody", "remark", "createTime", "state", "updateTime", "verify", "type", "moduleId") VALUES ('d942dc92-7cf7-42ec-8af5-7502b43c6523', '巡检查询机柜上的设备', '/ops/itsm/inspection/getInstanceByCabinetId', NULL, NULL, '/itsm/inspection/getInstanceByCabinetId', '查询', '', '', '', '', '2022-01-11 11:37:13', 0, '2022-01-11 11:37:13', 't', 'normal', 'fc956e4f5af54ad2af454ec352cea19b');
INSERT INTO "public"."BasicGatewayRoute" ("uuid", "name", "sourcepath", "module", "targeturl", "targetpath", "logtype", "logcontent", "param", "responsebody", "remark", "createTime", "state", "updateTime", "verify", "type", "moduleId") VALUES ('64115f52-4db3-4d4a-b1ac-96d10e05643c', '巡检查询异常设备列表', '/ops/itsm/inspection/task/getListErrDeviceByTaskId', NULL, NULL, '/itsm/inspection/task/getListErrDeviceByTaskId', '查询', '', '', '', '', '2022-01-11 11:38:01', 0, '2022-01-11 11:38:01', 't', 'normal', 'fc956e4f5af54ad2af454ec352cea19b');
INSERT INTO "public"."BasicGatewayRoute" ("uuid", "name", "sourcepath", "module", "targeturl", "targetpath", "logtype", "logcontent", "param", "responsebody", "remark", "createTime", "state", "updateTime", "verify", "type", "moduleId") VALUES ('7b9e4ae6-a1b7-47e2-9458-ccf58c80aa2c', '暂存、保存巡检任务', '/ops/itsm/inspection/task/add', NULL, NULL, '/itsm/inspection/task/add', '操作', '', '', '', '', '2022-01-11 11:38:32', 0, '2022-01-11 11:38:32', 't', 'normal', 'fc956e4f5af54ad2af454ec352cea19b');
添加网关后执行:http://ip:8080/ops/route/init
</code></pre>
<h5>增加脚本</h5>
<pre><code>INSERT INTO "public"."bee_idx_comm" ("id", "name", "status", "path", "val", "time") VALUES ('1cd1cb330e5e1d1b', 'InspectionScript', '0', 'root/script/InspectionScript', '{"param":"{}","name":"InspectionScript","publicClass":"com.kingsware.fun.InspectionScript","script":"package com.kingsware.fun;\r\n\r\nimport com.alibaba.fastjson.JSON;\r\nimport com.alibaba.fastjson.JSONObject;\r\nimport com.kingsware.env.pojo.CollectResult;\r\nimport com.kingsware.env.script.KBaseMain;\r\nimport com.kingsware.env.util.odb.dao.BasicQueryDao;\r\nimport com.kingsware.env.util.odb.dao.impl.OrientQueryDaoImpl;\r\nimport com.kingsware.env.util.odb.pojo.Node;\r\nimport com.kingsware.env.util.odb.pojo.Relationship;\r\nimport com.kingsware.socket.client.KEnvClient;\r\nimport org.apache.commons.collections4.map.HashedMap;\r\nimport org.apache.commons.lang3.StringUtils;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\nimport java.util.Map;\r\n\r\n/**\r\n * 巡检脚本\r\n *\r\n * @author qy\r\n * @Date 2022/1/10 14:35\r\n */\r\npublic class InspectionScript extends KBaseMain {\r\n //OrientDB\r\n //OrientDB连接model\r\n private static String ORIENTDB_MODEL;\r\n //OrientDB连接url\r\n private static String ORIENTDB_URL;\r\n //OrientDB连接库\r\n private static String ORIENTDB_DATABASE;\r\n //OrientDB连接用户\r\n private static String ORIENTDB_USERNAME;\r\n //OrientDB连接密码\r\n private static String ORIENTDB_PASSWORD;\r\n //OrientDB连接maxPool\r\n private static String ORIENTDB_MAX_POOL;\r\n\r\n private static BasicQueryDao queryDao;\r\n\r\n\r\n //数据库连接初始化\r\n @Override\r\n public void beforeRun(KEnvClient kEnvClient) throws Exception {\r\n ORIENTDB_MODEL = kEnvClient.getVariableVal(\"orientDB_model\");\r\n ORIENTDB_URL = kEnvClient.getVariableVal(\"orientDB_url\");\r\n ORIENTDB_DATABASE = kEnvClient.getVariableVal(\"orientDB_database\");\r\n ORIENTDB_USERNAME = kEnvClient.getVariableVal(\"orientDB_username\");\r\n ORIENTDB_PASSWORD = kEnvClient.getVariableVal(\"orientDB_password\");\r\n ORIENTDB_MAX_POOL = kEnvClient.getVariableVal(\"orientDB_maxPool\");\r\n\r\n queryDao = OrientQueryDaoImpl.getInstance(ORIENTDB_MODEL, ORIENTDB_URL, ORIENTDB_DATABASE, ORIENTDB_USERNAME, ORIENTDB_PASSWORD, Integer.parseInt(ORIENTDB_MAX_POOL));\r\n }\r\n\r\n public CollectResult mainEx(Object param, KEnvClient kEnvClient) throws Exception {\r\n JSONObject paramObj = JSONObject.parseObject(param.toString());\r\n String publicClass = paramObj.getString(\"publicClass\");\r\n if (StringUtils.isEmpty(publicClass)) {\r\n throw new RuntimeException(\"publicClass参数为空!\");\r\n }\r\n Object result = null;\r\n switch (publicClass) {\r\n case \"getCiBasicByUuid\":\r\n if (StringUtils.isEmpty(paramObj.getString(\"uuid\"))) {\r\n throw new RuntimeException(\"uuid参数为空!\");\r\n }\r\n result = getCiBasicByUuid(paramObj.getString(\"uuid\"));\r\n break;\r\n case \"getInstallByTabAndUuid\":\r\n if (StringUtils.isEmpty(paramObj.getString(\"tabName\"))) {\r\n throw new RuntimeException(\"tabName参数为空!\");\r\n }\r\n if (StringUtils.isEmpty(paramObj.getString(\"uuid\"))) {\r\n throw new RuntimeException(\"uuid参数为空!\");\r\n }\r\n result = getInstallByTabAndUuid(paramObj.getString(\"tabName\"), paramObj.getString(\"uuid\"));\r\n break;\r\n case \"getJiguiInfoByUuid\":\r\n List<String> jiguiIdList = (List<String>) paramObj.get(\"jiguiIdList\");\r\n if (jiguiIdList.size() == 0) {\r\n throw new RuntimeException(\"jiguiIdList参数为空!\");\r\n }\r\n result = getJiguiInfoByUuid(jiguiIdList);\r\n break;\r\n case \"getPicRelationship\":\r\n if (StringUtils.isEmpty(paramObj.getString(\"outUuid\"))) {\r\n throw new RuntimeException(\"outUuid参数为空!\");\r\n }\r\n result = getPicRelationship(paramObj.getString(\"outUuid\"));\r\n break;\r\n case \"getRelationshipGroup\":\r\n if(StringUtils.isEmpty(paramObj.getString(\"name\"))){\r\n throw new RuntimeException(\"name参数为空!\");\r\n }\r\n result = getRelationshipGroup(paramObj.getString(\"name\"));\r\n break;\r\n case \"getInRelationshipListBySourceUuid\":\r\n if (StringUtils.isEmpty(paramObj.getString(\"tabName\"))) {\r\n throw new RuntimeException(\"tabName参数为空!\");\r\n }\r\n if (StringUtils.isEmpty(paramObj.getString(\"uuid\"))) {\r\n throw new RuntimeException(\"uuid参数为空!\");\r\n }\r\n result = getInRelationshipListBySourceUuid(paramObj.getString(\"tabName\"), paramObj.getString(\"uuid\"));\r\n break;\r\n case \"getAllRelationshipBySourceUuid\":\r\n if (StringUtils.isEmpty(paramObj.getString(\"tabName\"))) {\r\n throw new RuntimeException(\"tabName参数为空!\");\r\n }\r\n if (StringUtils.isEmpty(paramObj.getString(\"uuid\"))) {\r\n throw new RuntimeException(\"uuid参数为空!\");\r\n }\r\n result = getAllRelationshipBySourceUuid(paramObj.getString(\"tabName\"), paramObj.getString(\"uuid\"));\r\n break;\r\n default:\r\n throw new IllegalStateException(\"Unexpected value: \" + publicClass);\r\n }\r\n\r\n CollectResult collectResult = new CollectResult();\r\n collectResult.setResult(result);\r\n return collectResult;\r\n }\r\n\r\n /**\r\n * 返回实例的对象\r\n */\r\n private Map<String, Object> getCiBasicByUuid(String uuid) {\r\n String sql = \"select ip,name,in_BasicModelInstanceRelationship.out.name[0] as category,\" +\r\n \"in_BasicModelInstanceRelationship.out.fieldName[0] as tabName from CIBase where uuid=''\" + uuid + \"''\";\r\n List<Map<String, Object>> listMapObj = queryDao.getBySql(sql, false);\r\n if (listMapObj != null && listMapObj.size() > 0) {\r\n return listMapObj.get(0);\r\n }\r\n return new HashedMap<>();\r\n }\r\n\r\n /**\r\n * 根据表名和设备uuid,返回实例对象\r\n */\r\n private Map<String, Object> getInstallByTabAndUuid(String table, String uuid) {\r\n String sql = \"select uuid,use as purpose,out_CustomerPicRelationship.in.name as users,qishiuwei,zhanyonguwei from \" + table + \" where uuid=''\" + uuid + \"''\";\r\n List<Map<String, Object>> listMapObj = queryDao.getBySql(sql, false);\r\n if (listMapObj != null && listMapObj.size() > 0) {\r\n return listMapObj.get(0);\r\n }\r\n return new HashedMap<>();\r\n }\r\n\r\n /**\r\n * 查询机柜信息\r\n */\r\n private List<Node> getJiguiInfoByUuid(List<String> jiguiIdList) {\r\n String sql = \" select * from Jigui where state = 0 and uuid in \" + JSON.toJSONString(jiguiIdList);\r\n List<Node> nodeList = queryDao.getNodeListBySql(sql, false);\r\n if (nodeList != null && nodeList.size() > 0) {\r\n return nodeList;\r\n }\r\n return new ArrayList<>();\r\n }\r\n\r\n /**\r\n * 获取机柜关系分组\r\n */\r\n private List<Node> getRelationshipGroup(String name) {\r\n JSONObject paramObj = new JSONObject();\r\n paramObj.put(\"name\", name);\r\n List<Node> nodeList = queryDao.getNodeListByLabelAndProperty(\"BasicRelationshipGroup\", paramObj, false);\r\n if (nodeList != null && nodeList.size() > 0) {\r\n return nodeList;\r\n }\r\n return new ArrayList<>();\r\n }\r\n\r\n private List<Relationship> getPicRelationship(String outUuid) {\r\n String sql = \"select * from CustomerPicRelationship where out.uuid = ''\" + outUuid + \"''\";\r\n List<Relationship> relationshipList = queryDao.getRelationshipListBySql(sql, false);\r\n if (relationshipList != null && relationshipList.size() > 0) {\r\n return relationshipList;\r\n }\r\n return new ArrayList<>();\r\n }\r\n\r\n private List<Relationship> getInRelationshipListBySourceUuid(String tabName,String uuid){\r\n List<Relationship> relationshipList = queryDao.getInRelationshipListBySourceUuid(uuid, tabName, false);\r\n if (relationshipList != null && relationshipList.size() > 0) {\r\n return relationshipList;\r\n }\r\n return new ArrayList<>();\r\n }\r\n\r\n private List<Relationship> getAllRelationshipBySourceUuid(String tabName,String uuid){\r\n List<Relationship> relationshipList = queryDao.getAllRelationshipBySourceUuid(uuid, tabName, false);\r\n if (relationshipList != null && relationshipList.size() > 0) {\r\n return relationshipList;\r\n }\r\n return new ArrayList<>();\r\n }\r\n}\r\n"}', '2022-01-11 09:37:45.534');
</code></pre>