import { CellsysType, EditTask, EditType, Operator, Query, QueryTask, QueryType, } from './cellsysUtil.js'; import { CellsysMarkerStyle } from './cellsysStyle'; import { PublishTarget } from './cellsysEnum'; import CellsysElementType from './cellsysElementType'; import CellsysEvent from './cellsysEvent'; class CellsysEventType extends CellsysElementType { constructor(params) { super(params); this.cellsysType = CellsysType.EventType; if (!params) { params = {}; } this.id = params.id; this.name = params.name; this.description = params.description; this.style = params.style ? params.style : CellsysMarkerStyle.getDefaultStyle(); if (this.style && !this.style.data) { //坐标数据不存在则替换为默认图标数据 let _style = CellsysMarkerStyle.getDefaultStyle(); for (let item in _style) { if (!this.style[item]) { this.style[item] = _style[item]; } } } this.updater = params.updater; this.typeCount = params.type_count; this.updateTime = params.update_time; } setId(value) { this.id = value; } setName(value) { this.name = value; } setDescription(value) { this.description = value; } setStyle(value) { this.style = value ? value : {}; } getIcon() { return this.style ? this.style.icon : null1; } getColor() { return this.style ? this.style.color : '#000000'; } getIconUrl() { return this.style ? this.style.path : null; } queryEvents(pageInfo, filters, order) { let query = new Query(); if (pageInfo) { query.setCurrPage(pageInfo.currPage); query.setPageSize(pageInfo.pageSize); } query.addFilter('type', Operator.Equals, this.id); if (filters && filters.length > 0) { filters.forEach((item) => { if (item['type']) { query.addFilter(item['name'], item['operator'], item['value'], item['type']); } else { query.addFilter(item['name'], item['operator'], item['value']); } }); } let queryType = QueryType.Event; if (order) { query.setOrder(order); } else { query.setOrder({ datetime: 'asc' }); } let queryTask = new QueryTask(queryType, !!pageInfo); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { if (pageInfo) { if (res.data) { res.data = res.data.map((item) => { return new CellsysEvent(item); }); resolve(res); } } else { let resArr = res.map((item) => { return new CellsysEvent(item); }); resolve(resArr); } }) .catch((err) => { reject(err); }); }); } //发布功能 setPublish(publishStatus, range, ids, isEditable, remark) { let editTask = new EditTask(EditType.EventPublish); editTask.addParam('_id', this.id); editTask.addParam('_event_type_name', this.name); editTask.addParam('_is_publish', PublishTarget[publishStatus]); editTask.addParam('_remark', remark); if (publishStatus !== 'noPublish') { if (range === 1) { //发布到组织 editTask.addParam('_publish_org', ids); } else { editTask.addParam('_publish_group', ids); } editTask.addParam('_publish_range', range); } if (isEditable) { editTask.addParam('_is_update', 1); } else { editTask.addParam('_is_update', 0); } return editTask.execute(); } //查询协同数据发布记录列表 synergyDataPublishRecord(dataId, type) { let query = new Query(); query.setOrder({ create_time: 'desc' }); query.addFilter('data_type', '=', 5); query.setCurrPage(1); query.setPageSize(1); if (dataId) { query.addFilter('data_id', '=', dataId); } if (type) { query.addFilter('type', '=', type); } let queryTask = new QueryTask(QueryType.synergyDataPublishRecord, true); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { resolve(res); }) .catch((err) => { reject(err); }); }); } //锁定/解锁 setLock(params) { let editTask = new EditTask(EditType.eventTypeLock); editTask.addParam('_id', params.id); editTask.addParam('_is_unlock', params.isUnlock); return editTask.execute(); } } export default CellsysEventType;