ssts-hospital-web-master项目实战记录十九:项目迁移-基础模块实现(log-db)

记录时间:2024-02-26

一、log-db模块实现

 framework/utils/log-db.ts

import { ajaxWebApi } from './ajax-util'

//记录业务流水号为终端ip的终端流水日志
const LogTerminalBusinessTrace = function (
  terminalIp: string,
  orgId: string,
  terminalNo: string
) {
  ajaxWebApi(
    '/api/System/AddTerminalBusinessTrace',
    true,
    JSON.stringify({
      terminalIp: terminalIp,
      orgId: orgId,
      terminalNo: terminalNo
    })
  )
}

//记录终端设备状态信息
const LogTerminalDeviceStatusInfo = function (
  deviceName: string,
  statusId: string,
  currentStatus: string
) {
  const terminalValue = localStorage.getItem('terminal')
  const DeviceInitFlagValue = localStorage.getItem('DeviceInitFlag')
  const DeviceIdListValue = localStorage.getItem('DeviceIdList')
  const DeviceNameListValue = localStorage.getItem('DeviceNameList')

  if (
    terminalValue == null ||
    DeviceIdListValue == null ||
    DeviceNameListValue == null
  ) {
    return
  } else {
    const terminal = JSON.parse(terminalValue)
    const terminalNo: string = terminal.TerminalNo

    const DeviceInitFlag: boolean = DeviceInitFlagValue
      ? JSON.parse(DeviceInitFlagValue)
      : false
    const deviceIdList: string[] = JSON.parse(DeviceIdListValue)
    const deviceNameList: string[] = JSON.parse(DeviceNameListValue)
    const deviceId = deviceIdList[deviceNameList.indexOf(deviceName)]

    if (DeviceInitFlag == false) {
      //初次加载
      ajaxWebApi(
        '/api/Terminal/UpdateLogDeviceStatus',
        true,
        JSON.stringify({
          terminalNo: terminalNo,
          deviceId: deviceId,
          statusId: statusId
        })
      )
    } else if (DeviceInitFlag == true && currentStatus != statusId) {
      //状态变更
      ajaxWebApi(
        '/api/Terminal/UpdateLogDeviceStatus',
        true,
        JSON.stringify({
          terminalNo: terminalNo,
          deviceId: deviceId,
          statusId: statusId
        })
      )
    }
  }
}

//记录终端设备函数数据
const LogTerminalDeviceFunctionData = function (
  terminalIp: string,
  businessTrace: string,
  devPageName: string,
  devName: string,
  devFunctionName: string,
  devFunctionParams: string,
  devResult: string,
  devOutMsg: string,
  async: boolean
) {
  async = async == undefined || async == true ? true : false

  ajaxWebApi(
    '/api/Terminal/AddLogDeviceData',
    async,
    JSON.stringify({
      terminalIp: terminalIp,
      businessTrace: businessTrace,
      devPageName: devPageName,
      devName: devName,
      devFunctionName: devFunctionName,
      devFunctionParams: devFunctionParams,
      devResult: devResult,
      devOutMsg: devOutMsg
    })
  )
}

//记录终端设备事件数据
const LogTerminalDeviceEventData = function (
  terminalIp: string,
  businessTrace: string,
  devPageName: string,
  devName: string,
  devEventName: string,
  devEventParam: string,
  async?: boolean
) {
  async = async == undefined || async == true ? true : false

  ajaxWebApi(
    '/api/Terminal/AddLogDeviceData',
    async,
    JSON.stringify({
      terminalIp: terminalIp,
      businessTrace: businessTrace,
      devPageName: devPageName,
      devName: devName,
      devEventName: devEventName,
      devEventParam: devEventParam
    })
  )
}

export {
  LogTerminalBusinessTrace,
  LogTerminalDeviceStatusInfo,
  LogTerminalDeviceFunctionData,
  LogTerminalDeviceEventData
}
 

二、调用示例

test-framework-log-db.vue

<script setup lang="ts">
import { onMounted } from 'vue'
import { hydate } from '@/common'
import {
  LogTerminalBusinessTrace,
  LogTerminalDeviceStatusInfo,
  LogTerminalDeviceFunctionData,
  LogTerminalDeviceEventData
} from '@/framework/utils/log-db.ts'

const TestLogDB = function () {
  console.log('TestLogDB begin')

  let terminalIp = ''
  let terminal: any = {}
  let orgId = ''
  let terminalNo = ''
  const devName = 'Barcode'

  let terminalIpValue = localStorage.getItem('terminalIp')
  if (terminalIpValue !== null) {
    terminalIp = terminalIpValue
  }
  const terminalValue = localStorage.getItem('terminal')
  if (terminalValue !== null) {
    terminal = JSON.parse(terminalValue)
  }

  const businessTrace = `Test-${hydate(new Date()).format('YYYYMMDDHHmmss')}`
  const devPageName = window.location.href
  orgId = terminal['OrgId']
  terminalNo = terminal['TerminalNo']

  LogTerminalBusinessTrace(terminalIp, orgId, terminalNo)

  LogTerminalDeviceEventData(
    terminalIp,
    businessTrace,
    devPageName,
    devName,
    'devEventName',
    'devEventParam',
    true
  )

  localStorage.setItem('DeviceInitFlag', JSON.stringify(false))
  localStorage.setItem('DeviceIdList', JSON.stringify(['14']))
  localStorage.setItem('DeviceNameList', JSON.stringify(['Barcode']))
  LogTerminalDeviceStatusInfo('Barcode', '0', '1')

  LogTerminalDeviceFunctionData(
    terminalIp,
    businessTrace,
    devPageName,
    devName,
    'devFunctionName',
    'devFunctionParams',
    'devResult',
    'devOutMsg',
    true
  )

  LogTerminalDeviceEventData(
    terminalIp,
    businessTrace,
    devPageName,
    devName,
    'devEventName',
    'devEventParam',
    true
  )

  console.log('TestLogDB end')
}

onMounted(() => {
  console.log('test-framework.vue', 'mounted')

  TestLogDB()
})
</script>

<template>
  <div>
    <title>测试框架</title>
  </div>
</template>

<style scoped></style>

 
 

三、运行测试

 

 

 

 

 

posted @ 2024-02-26 08:38  lizhigang  阅读(2)  评论(0编辑  收藏  举报