import { CellsysType, EditTask, EditType, Operator, Query, QueryTask, QueryType } from './cellsysUtil.js'; import {PublishTarget} from './cellsysEnum'; import CellsysEquipmentMonitor from "./cellsysEquipmentMonitor"; import CellsysEquipment from "./cellsysEquipment"; class CellsysEquipmentType { constructor(params) { this.cellsysType = CellsysType.EquipmentType params = params || {} this.orgId = params.org_id this.orgName = params.org_name this.id = params.id this.type = params.type this.typeCount = params.type_count this.name = params.name this.description = params.description this.style = params.style || {} this.createBy = params.create_by; this.createTime = params.create_time; this.updateBy = params.update_by; this.updateTime = params.update_time; this.tags = []; if (params.tag_name) { this.tags = params.tag_name.map(name => { return {"name": name} }) } this.isPublish = params.is_publish || 0 this.publishRange = params.publish_range; //发布范围 0-群组 1-组织 this.publishGroup = params.publish_group ? params.publish_group : []; //发布的群组 this.isEditable = params.is_update === 1; //is_update表示是否允许其他人编辑 0-不允许 1-允许 this.isUnlock = params.is_unlock;//是否未锁定,0-已锁定,1-未锁定 let creator = params.creator; this.creator = { memberId: null, name: null } if (creator) { this.creator = { memberId: creator.member_id, name: creator.name } } let updater = params.updater; this.updater = { memberId: null, name: null } if (updater) { this.updater = { memberId: updater.member_id, name: updater.name } } } setId(value) { this.id = value } setName(value) { this.name = value } getIcon() { return this.style } /** * 查询监控量 */ queryMonitorList(filters) { let query = new Query(); query.addFilter('equipment_type_id', Operator.Equals, this.type); query.setOrder({ create_time: 'desc' }); let queryTask = new QueryTask(QueryType.EquipmentTypeMonitors, false); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { let resArr = res.map((item) => { return new CellsysEquipmentMonitor(item); }); resolve(resArr); }) .catch((err) => { reject(err); }); }); } /*查询设备类型下所有设备*/ queryEquipments(){ let query = new Query(); query.addFilter('type_id', Operator.Equals, this.id); let queryType = QueryType.Equipment; query.setOrder({ id: 'desc' }); let queryTask = new QueryTask(queryType, false); return new Promise((resolve, reject) => { queryTask .execute(query) .then((res) => { let resArr = res.map((item) => { return new CellsysEquipment(item); }); resolve(resArr); }) .catch((err) => { reject(err); }); }); } // EquipmentTypePublish //发布功能 setPublish(publishStatus, range, ids, isEditable, remark) { let editTask = new EditTask(EditType.EquipmentTypePublish); editTask.addParam('_id', this.id); editTask.addParam('_equipment_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', '=', 6); 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); }); }); } } export default CellsysEquipmentType