Skip to content

Commit a1d0c36

Browse files
author
潘卓然Y7000P
committed
【SDK】【新增】【新增DataStore的ElasticSearch的通用服务】
1 parent ce21f2d commit a1d0c36

8 files changed

Lines changed: 437 additions & 39 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import Qs from 'qs';
2+
3+
import { ServiceBase } from '../ServiceBase';
4+
import { IgsServiceBase } from '../baseserver/IServiceBase';
5+
6+
/**
7+
* @class module:DataStore.DataStoreService
8+
* @description DataStore的基础服务
9+
* @author 基础平台-潘卓然
10+
*/
11+
export class DataStoreService extends ServiceBase {
12+
constructor(options) {
13+
super(options);
14+
this.fixParams(options);
15+
}
16+
17+
fixParams(option) {
18+
this.params = option;
19+
delete this.params.url;
20+
delete this.params.ip;
21+
delete this.params.port;
22+
delete this.params.domain;
23+
delete this.params.baseUrl;
24+
delete this.params.networkProtocol;
25+
delete this.params.partUrl;
26+
}
27+
28+
/**
29+
* @function module:DataStore服务.DataStoreService.prototype.getBaseUrl
30+
* @description 获取基地址url
31+
*/
32+
getBaseUrl() {
33+
let url = '';
34+
const { baseUrl, ip, port, domain, networkProtocol } = this;
35+
if (baseUrl) {
36+
url = baseUrl;
37+
} else if (domain) {
38+
url = domain;
39+
} else if (networkProtocol && ip && port) {
40+
url = `${networkProtocol}://${ip}:${port}`;
41+
}
42+
return url;
43+
}
44+
45+
/**
46+
* @function module:DataStore服务.DataStoreService.prototype.getFullUrl
47+
* @description 获取完整的url地址
48+
* @param {String}
49+
* @param {Object}
50+
* 可以使用SpaceTimeQueryByAgg.query方法,也可以使用axios,jquery进行请求
51+
*/
52+
getFullUrl(serviceurl, options) {
53+
let baseurl = this.getBaseUrl();
54+
let url = baseurl + serviceurl + '?' + Qs.stringify(options);
55+
return url;
56+
}
57+
58+
/**
59+
* @description 向服务器发送GET请求
60+
* @function module:DataStore服务.DataStoreService.prototype.get
61+
* @param {String} url 完整的请求地址。
62+
* @param {Function} onSuccess 查询成功回调函数。
63+
* @param {Function} onError 查询失败回调函数。
64+
*/
65+
get(url, onSuccess, onError) {
66+
var me = this;
67+
var service = new IgsServiceBase(url, {
68+
eventListeners: {
69+
scope: me,
70+
processCompleted: onSuccess,
71+
processFailed: onError
72+
}
73+
});
74+
service.processAsync();
75+
}
76+
77+
/**
78+
* @description 向服务器发送POST请求
79+
* @function module:DataStore服务.DataStoreService.prototype.post
80+
* @param {String} url 完整的请求地址。
81+
* @param {Function} onSuccess 查询成功回调函数。
82+
* @param {Function} onError 查询失败回调函数。
83+
*/
84+
post(url, param, onSuccess, onError) {
85+
var me = this;
86+
var service = new IgsServiceBase(url, {
87+
eventListeners: {
88+
scope: me,
89+
processCompleted: onSuccess,
90+
processFailed: onError
91+
}
92+
});
93+
service.processAsync({
94+
method: 'POST',
95+
data: JSON.stringify(param),
96+
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }
97+
});
98+
}
99+
}
100+
101+
export default DataStoreService;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* ElasticSearch数据库类型
3+
* @author 基础平台-潘卓然
4+
* @description ElasticSearch数据库类型
5+
* @readonly
6+
* @enum {String}
7+
*/
8+
let EsCatlogType = {
9+
/**时空库 */
10+
SpaceTime: 'spacetime_db',
11+
/**地址库 */
12+
Addredd: 'address_db'
13+
};
14+
15+
/**
16+
* ElasticSearch数据库名称
17+
* @author 基础平台-潘卓然
18+
* @description ElasticSearch数据库名称
19+
* @readonly
20+
* @enum {String}
21+
*/
22+
let EsCatlogName = {
23+
/**时空库 */
24+
SpaceTime: '时空库',
25+
/**地址库 */
26+
Addredd: '地址库'
27+
};
28+
29+
export { EsCatlogType, EsCatlogName };
30+
Zondy.Enum.EsCatlogType = EsCatlogType;
31+
Zondy.Enum.EsCatlogName = EsCatlogName;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { EsCatlogType } from './Enum';
2+
import { Zondy } from '../../common/Base';
3+
import { DataStoreService } from '../ServiceBase';
4+
5+
/**
6+
* @author 基础平台-潘卓然
7+
* @class module:弹性搜索服务.EsCatlogService
8+
* @classdesc 枚举目录树结果
9+
* @description Zondy.DataStore.ElasticSearch.EsCatlogService-根据数据库结构枚举目录,枚举库列表、表列表
10+
* @param {Object} option 属性键值对
11+
* @param {String} [option.indexName] 库名称
12+
* @param {EsCatlogType} [option.classify] 类别,地址库、时空库等
13+
* @param {String} [option.keyWords] 关键字
14+
* @param {Number} [option.pageSize = 100] 每页大小
15+
* @param {Number} [option.pageNo = 1] 页码,从1开始
16+
* @see https://shimo.im/docs/1d579d6a082a4631
17+
* @example http://192.168.96.101:9091/datastore/rest/catalog/es/services/?
18+
* indexName=sp_taxibj_200_2
19+
* &classify=sptype
20+
* &keyWords='出租车'
21+
* &pageSize=0
22+
* &pageNo=4
23+
*/
24+
export default class EsCatlogService extends DataStoreService {
25+
constructor(option) {
26+
let options = option || {};
27+
super(options);
28+
29+
/**
30+
* @member module:弹性搜索服务.EsCatlogService.prototype.serviceUrl
31+
* @type {String}
32+
* @description 时空聚类查询地址
33+
* @default /datastore/rest/catalog/es/services/
34+
*/
35+
this.serviceUrl = '/datastore/rest/catalog/es/services/';
36+
37+
/**
38+
* @member module:弹性搜索服务.EsCatlogService.prototype.indexName
39+
* @type {String}
40+
* @description 库名称
41+
* @default null
42+
*/
43+
this.indexName = options.indexName !== undefined ? options.indexName : null;
44+
45+
/**
46+
* @member module:弹性搜索服务.EsCatlogService.prototype.classify
47+
* @type {String}
48+
* @description 类别,地址库、时空库等
49+
* @default null
50+
*/
51+
this.classify = options.classify !== undefined ? options.classify : null;
52+
53+
/**
54+
* @member module:弹性搜索服务.EsCatlogService.prototype.keyWords
55+
* @type {String}
56+
* @description 关键字
57+
* @default null
58+
*/
59+
this.keyWords = options.keyWords !== undefined ? options.keyWords : null;
60+
61+
/**
62+
* @member module:弹性搜索服务.EsCatlogService.prototype.pageSize
63+
* @type {Number}
64+
* @description 每页大小
65+
* @default null
66+
*/
67+
this.pageSize = options.pageSize !== undefined ? options.pageSize : 100;
68+
69+
/**
70+
* @member module:弹性搜索服务.EsCatlogService.prototype.pageNo
71+
* @type {Number}
72+
* @description 页码,从1开始
73+
* @default null
74+
*/
75+
this.pageNo = options.pageNo !== undefined ? options.pageNo : 1;
76+
}
77+
78+
/**
79+
* @description 查询函数,向服务器发送请求,返回geosjon格式数据
80+
* @function module:弹性搜索服务.EsCatlogService.prototype.query
81+
* @param {Function} onSuccess 查询成功回调函数。
82+
* @param {Function} onError 查询失败回调函数。
83+
*/
84+
query(onSuccess, onError) {
85+
let { serviceUrl, params } = this;
86+
let url = this.getFullUrl(serviceUrl, params);
87+
this.get(url, onSuccess, onError);
88+
}
89+
}
90+
export { EsCatlogService };
91+
Zondy.DataStore.ElasticSearch.EsCatlogService = EsCatlogService;
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { Zondy } from '../../common/Base';
2+
import { DataStoreService } from '../ServiceBase';
3+
4+
/**
5+
* @author 基础平台-潘卓然
6+
* @class module:弹性搜索服务.EsSpaceTimeQueryByAgg
7+
* @classdesc 时空聚类服务
8+
* @description Zondy.DataStore.ElasticSearch.EsSpaceTimeQueryByAgg-获取指定范围内的指定时间段的聚类情况
9+
* @param {Object} option 属性键值对
10+
* @param {String} option.indexName 地址库名称
11+
* @param {String} [option.typeName=sptype] Es中type名称,DataStore中为时空库
12+
* @param {String} option.aggfield 聚合的几何字段
13+
* @param {String} option.spatialCondition 空间范围
14+
* @param {String} option.timefield 时间字段
15+
* @param {String} option.timeCondition 时间范围
16+
* @param {Number} option.aggGeoFormat 聚合返回格式
17+
* @param {Number} option.percision 查询精度/对应elasticsearch的percision
18+
* @see https://shimo.im/docs/1d579d6a082a4631
19+
* @example http://192.168.91.125:9093/es/stGeoHashQueryByAgg?
20+
* indexName=sp_taxibj_200_2
21+
* &typeName=sptype
22+
* &aggfield=geometry
23+
* &spatialCondition=polygon:29.843798,121.58775;29.843746,121.586464;29.845467,121.5646
24+
* &timefield=GPS_DateTime
25+
* &timeCondition=1351737960000,1351738020000
26+
* &aggGeoFormat=0
27+
* &percision=4
28+
*/
29+
export default class EsSpaceTimeQueryByAgg extends DataStoreService {
30+
constructor(option) {
31+
let options = option || {};
32+
super(options);
33+
34+
/**
35+
* @private
36+
*/
37+
this.options = option;
38+
39+
/**
40+
* @member module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.serviceUrl
41+
* @type {String}
42+
* @description 时空聚类查询地址
43+
* @default /es/stQueryByAgg
44+
*/
45+
this.serviceUrl = '/es/stQueryByAgg';
46+
47+
/**
48+
* @member module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.indexName
49+
* @type {String}
50+
* @description 地址库名称
51+
* @default null
52+
*/
53+
this.indexName = options.indexName !== undefined ? options.indexName : null;
54+
55+
/**
56+
* @member module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.typeName
57+
* @type {String}
58+
* @description Es中type名称,DataStore中为时空库
59+
* @default null
60+
*/
61+
this.typeName = options.typeName !== undefined ? options.typeName : null;
62+
63+
/**
64+
* @member module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.aggfield
65+
* @type {String}
66+
* @description 空间字段
67+
* @default null
68+
*/
69+
this.aggfield = options.aggfield !== undefined ? options.aggfield : null;
70+
71+
/**
72+
* @member module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.spatialCondition
73+
* @type {String}
74+
* @description 空间状态
75+
* @default null
76+
*/
77+
this.spatialCondition = options.spatialCondition !== undefined ? options.spatialCondition : null;
78+
79+
/**
80+
* @member module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.timefield
81+
* @type {String}
82+
* @description 时间字段
83+
* @default null
84+
*/
85+
this.timefield = options.timefield !== undefined ? options.timefield : null;
86+
87+
/**
88+
* @member module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.timeCondition
89+
* @type {String}
90+
* @description 时间状态
91+
* @default null
92+
*/
93+
this.timeCondition = options.timeCondition !== undefined ? options.timeCondition : null;
94+
95+
/**
96+
* @member module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.aggGeoFormat
97+
* @type {Number}
98+
* @description 返回格式
99+
* @default null
100+
*/
101+
this.aggGeoFormat = options.aggGeoFormat !== undefined ? options.aggGeoFormat : null;
102+
103+
/**
104+
* @member module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.percision
105+
* @type {Number}
106+
* @description 聚类精度
107+
* @default null
108+
*/
109+
this.percision = options.percision !== undefined ? options.percision : 8;
110+
}
111+
112+
/**
113+
* @description 查询函数,向服务器发送请求,返回geosjon格式数据
114+
* @function module:弹性搜索服务.EsSpaceTimeQueryByAgg.prototype.query
115+
* @param {Function} onSuccess 查询成功回调函数。
116+
* @param {Function} onError 查询失败回调函数。
117+
*/
118+
query(onSuccess, onError) {
119+
let { serviceUrl, options } = this;
120+
let url = this.getFullUrl(serviceUrl, options);
121+
this.get(url, onSuccess, onError);
122+
}
123+
}
124+
export { EsSpaceTimeQueryByAgg };
125+
Zondy.DataStore.ElasticSearch.EsSpaceTimeQueryByAgg = EsSpaceTimeQueryByAgg;

0 commit comments

Comments
 (0)