RemoveRecordWorker.js 1.07 KB
import { serializeIfObject } from '@/utils/utils.js'
export default class RemoveRecordWorker {
  constructor() {}
  async work(deviceId, data, ws) {
    const recordId = data.id
    if (!recordId) {
      const msg = `删除接待记录,缺少记录id`
      uni.$logger.local.info(msg)
      ws.send({ error: msg })
      return
    }
    const unlock = await uni.$recordManager.lock()
    try {
      const records = uni.$recordManager.getRecords()
      const record = records.find(item => item.id === recordId)
      if (!record) {
        const msg = `记录不存在 id -> ${recordId}`
        uni.$logger.local.info(msg)
        ws.send({ error: msg })
        return
      }
      uni.$recordManager.removeRecord(recordId)
      const msg = `记录删除成功 id -> ${recordId}`
      uni.$logger.local.info(msg)
      ws.send({ code: 200, msg })
    } catch (error) {
      const msg = `记录删除异常 id -> ${recordId} error -> ${serializeIfObject(error)}`
      uni.$logger.local.error(msg)
      ws.send({ error: error,recordId })
    } finally {
      unlock()
    }
  }
}