/** * @Author YuanWei * @Date 2021/03/19 14:36:27 * @FileName cellsysSOS.js * @Description: 设备SOS求救mq消息内容实体类 */ class CellsysSOS { constructor(params) { params = params || {} this.macId = params.macId //完整的MacId this.userId = params.userId //与Mac关联的UserId this.isSingleMac = params.isSingleMac //0:Cellsys系统的数据库内存在多个匹配的Mac地址、1:仅存在一个Mac地址 this.longitude = params.longitude //经度 this.latitude = params.latitude //纬度 this.deviceTime = params.deviceTime //int求救发生时间-秒级时间戳。如果获取不到,则传空 this.collectTime = params.collectTime //int 设备采集时间-秒级时间戳 。如果获取不到,则传空 this.serverTime = params.serverTime //int 服务器-秒级时间戳。如果获取不到,则传空 this.deviceType = params.deviceType //int 设备类型 this.voltage = params.voltage //int 设备电压(可变相理解设备电量) this.deviceName = params.deviceName this.realname = params.realname } /** * 解析mqtt接收到的字符内容 */ formatterMsgText(msg) { if (msg) { let str = msg.split(';') this.macId = str[0] !== 'null' ? str[0] : null; this.userId = str[1] !== 'null' ? str[1] : null; this.isSingleMac = str[2] this.longitude = str[3] this.latitude = str[4] this.deviceTime = str[5] !== 'null' ? str[5] : null; this.collectTime = str[6] !== 'null' ? str[6] : null; this.serverTime = str[7] !== 'null' ? str[7] : null; this.deviceType = str[8] this.voltage = str[9] } } /** * 获取坐标 * @returns {*[]} */ getCoordinate() { return [this.longitude, this.latitude] } /** * 获取时间,秒 * @returns {*} */ getTime() { return this.deviceTime || this.collectTime || this.serverTime; } getGeometry() { return { type: 'Point', coordinates: this.getCoordinate() } } } export default CellsysSOS