ssts-hospital-web-master项目实战记录四十六:项目迁移-业务模块实现(useBusiness-基础部分)

记录时间:2024-03-19

一、base-data.ts

// 基础数据
const BaseData = {
  // timeNames(按医院修改午别编码对应关系)
  // 上午,下午,全天
  timeNames: {
    上午: '1',
    下午: '2',
    全天: '0'
  },

  // sexList(性别,按医院修改性别编码对应关系)
  sexList: {
    男: '1',
    女: '2'
  },

  // nationList(民族)
  nationList: {
    '01': '汉族',
    '02': '蒙古族',
    '03': '回族',
    '04': '藏族',
    '05': '维吾尔族',
    '06': '苗族',
    '07': '彝族',
    '08': '壮族',
    '09': '布依族',
    '10': '朝鲜族',
    '11': '满族',
    '12': '侗族',
    '13': '瑶族',
    '14': '白族',
    '15': '土家族',
    '16': '哈尼族',
    '17': '哈萨克族',
    '18': '傣族',
    '19': '黎族',
    '20': '傈僳族',
    '21': '佤族',
    '22': '畲族',
    '23': '高山族',
    '24': '拉祜族',
    '25': '水族',
    '26': '东乡族',
    '27': '纳西族',
    '28': '景颇族',
    '29': '柯尔克孜族',
    '30': '土族',
    '31': '达斡尔族',
    '32': '仫佬族',
    '33': '羌族',
    '34': '布朗族',
    '35': '撒拉族',
    '36': '毛南族',
    '37': '仡佬族',
    '38': '锡伯族',
    '39': '阿昌族',
    '40': '普米族',
    '41': '塔吉克族',
    '42': '怒族',
    '43': '乌孜别克族',
    '44': '俄罗斯族',
    '45': '鄂温克族',
    '46': '保安族',
    '47': '裕固族',
    '48': '裕固族',
    '49': '京族',
    '50': '塔塔尔族',
    '51': '独龙族',
    '52': '鄂伦春族',
    '53': '赫哲族',
    '54': '门巴族',
    '55': '珞巴族',
    '56': '基诺族',
    '97': '其他',
    '98': '外国血统'
  }
}

export { BaseData }
 

二、base-config.ts

import { GetAppSetting, serveFile } from '@/common'

// 项目资源文件路径
const BizPageDir = '/Web/Biz_GYSRMYY/BizPage/'
const BizCodeDir = '/Web/Biz_GYSRMYY/BizCode/'
const FlowDir = '/Web/Biz_GYSRMYY/Flow/'
const PageStyle = 'basic'

// 基础配置
const BaseConfig = {
  // 就诊方式菜单列表
  CardTypeMenuList: [
    {
      idcardtype: 'PCD',
      name: '就诊卡',
      img: '../../../Inc/images/' + PageStyle + '/Menu/IdentityWay/就诊卡.png',
      page: 'ReadIDCard.html'
    },
    {
      idcardtype: 'PNO',
      name: '门诊号',
      img: '../../../Inc/images/' + PageStyle + '/Menu/IdentityWay/门诊号.png',
      page: 'ReadIDCard.html'
    },
    {
      idcardtype: 'IDC',
      name: '身份证',
      img: '../../../Inc/images/' + PageStyle + '/Menu/IdentityWay/身份证.png',
      page: 'ReadIDCard.html'
    },
    {
      idcardtype: 'EHC',
      name: '电子健康卡',
      img:
        '../../../Inc/images/' + PageStyle + '/Menu/IdentityWay/电子健康卡.png',
      page: 'ReadIDCard.html'
    },
    {
      idcardtype: 'SSC',
      name: '医保卡',
      img: '../../../Inc/images/' + PageStyle + '/Menu/IdentityWay/社保卡.png',
      page: 'ReadIDCardYB.html'
    },
    {
      idcardtype: 'EVC',
      name: '医保电子凭证',
      img:
        '../../../Inc/images/' +
        PageStyle +
        '/Menu/IdentityWay/医保电子凭证.png',
      page: 'ReadIDCardYB.html'
    },
    {
      idcardtype: 'ApplyNo',
      name: '申请单条码',
      img:
        '../../../Inc/images/' + PageStyle + '/Menu/IdentityWay/申请单条码.png',
      page: 'ReadIDCard.html'
    }
  ],

  // 支付方式菜单列表
  PayWayMenuList: [
    {
      name: '微信支付',
      img: '../../../Inc/images/' + PageStyle + '/Menu/PayWay/微信支付.png',
      page: 'SelectWXPay',
      payway: 'WxPay'
    },
    {
      name: '支付宝支付',
      img: '../../../Inc/images/' + PageStyle + '/Menu/PayWay/支付宝支付.png',
      page: 'SelectAliPay',
      payway: 'AliPay'
    },
    {
      name: '银联云闪付支付',
      img: '../../../Inc/images/' + PageStyle + '/Menu/PayWay/云闪付支付.png',
      page: 'SelectUnionPay',
      payway: 'UnionPay'
    },
    {
      name: '银行卡支付',
      img: '../../../Inc/images/' + PageStyle + '/Menu/PayWay/银行卡支付.png',
      page: 'SelectBankCard',
      payway: 'BankCard'
    },
    {
      name: '现金支付',
      img: '../../../Inc/images/' + PageStyle + '/Menu/PayWay/现金支付.png',
      page: 'SelectCash',
      payway: 'CashPay'
    },
    {
      name: '刷脸付',
      img: '../../../Inc/images/' + PageStyle + '/Menu/PayWay/刷脸付.png',
      page: 'SelectFacePay',
      payway: 'FacePay'
    }
  ],

  // 交易类型列表(银医系统记账)
  // 就诊卡支付,微信支付,支付宝支付,银联云闪付支付,银行卡支付,现金支付,刷脸付
  ModeTypeList: {
    就诊卡支付: '1',
    微信支付: '2',
    支付宝支付: '3',
    银联云闪付支付: '4',
    银行卡支付: '5',
    现金支付: '6',
    刷脸付: '7'
  },

  // 数据字典配置
  GetDataItems: async function (DataType: string) {
    let result = null

    const filePath = GetAppSetting('ConfigDir') + 'JsonDataItems.json'
    const data = await serveFile(filePath)
    if (data != undefined) {
      result = data[DataType]
    }
    return result
  },

  // SIU配置
  GetSIU: async function (TerminalType: string) {
    let result = null

    const filePath = GetAppSetting('ConfigDir') + 'JsonSIU.json'
    const data = await serveFile(filePath)
    if (data != undefined) {
      result = data[TerminalType]
    }
    return result
  },

  // 根据流程键获取业务类型
  GetBusinessTypeByFlowKey: async function (flowKey: string, flowName: string) {
    const data = await BaseConfig.GetDataItems('BusinessType')
    const BusinessType = { code: '', name: '' }
    for (const i in data) {
      for (const j in data[i]['flowKey']) {
        if (flowKey == data[i]['flowKey'][j]) {
          BusinessType['code'] = data[i]['code']
          BusinessType['name'] = data[i]['name']
        }
      }
      if (BusinessType['code'] != '0') {
        break
      }
    }
    if (BusinessType['code'] == '') {
      BusinessType['code'] = flowKey
      BusinessType['name'] = flowName
    }
    return BusinessType
  }
}

export { BizPageDir, BizCodeDir, FlowDir, PageStyle, BaseConfig }

 

三、base-handler

index.ts

// 通用操作类
export * from './common-handler'
// 配置操作类
export * from './config-handler'
// 业务操作类
export * from './business-handler'
// 数据操作类
export * from './data-handler'
// 日志操作类
export * from './log-handler'
// 设备操作类
export * from './device-handler'
 

common-handler.ts

import { GetAppSetting, serveFile } from '@/common'

// 根据另一个数组按顺序对数组进行排序
const SortArrayByOrderArray = function (
  array: any,
  orderArray: any,
  keyName: string
) {
  const sortArray = array.concat() //深复制(可以完全拷贝一个数组,即使嵌套了对象或者数组,两者也不会互相影响)
  return sortArray.sort(function (a: string, b: string) {
    const result =
      orderArray.indexOf(a[keyName]) - orderArray.indexOf(b[keyName])
    return result
  })
}
// 获取两个数组差集
const GetDifferentArray = function (
  array: any,
  partArray: any,
  keyName: string
) {
  const diffArray = array.concat() //深复制(可以完全拷贝一个数组,即使嵌套了对象或者数组,两者也不会互相影响)
  for (let i = diffArray.length - 1; i >= 0; i--) {
    for (let j = 0; j < partArray.length; j++) {
      if (diffArray[i][keyName] === partArray[j][keyName]) {
        diffArray.splice(i, 1)
        break
      }
    }
  }
  return diffArray
}
// 获取Json配置
const GetJsonConfig = async function (fileName: string) {
  let result = null

  const filePath = (await GetAppSetting('ConfigDir')) + fileName
  const data = await serveFile(filePath)
  if (data != undefined) {
    result = data
  }
  return result
}
// 按配置排序
const GetOrderItemsByConfig = function (
  items: any,
  configItems: any,
  keyName: string
) {
  if (items.length > 0 && configItems.length > 0) {
    const lastItems = []
    let orderItems = []
    let leftItems = []

    const orderNames = []
    for (const i in configItems) {
      orderNames.push(configItems[i][keyName])
    }

    items = SortArrayByOrderArray(items, orderNames, keyName)
    leftItems = GetDifferentArray(items, configItems, keyName)
    orderItems = GetDifferentArray(items, leftItems, keyName)

    //先添加排序项,再排序其他项
    for (const i in orderItems) {
      lastItems.push(orderItems[i])
    }
    for (const i in leftItems) {
      lastItems.push(leftItems[i])
    }
    items = lastItems
  }
  return items
}
// 自定义处理DataSet转Json对象,按级别依次(目前支持3~5级)
const GetJsonFormDataSet = function (jsonDataSet: any, tbNameArray: any) {
  const tbResult = {}
  {
    const tbName0 = tbNameArray[0]
    const tbName1 = tbNameArray[1]
    const tbName2 = tbNameArray[2]
    const tbName3 = tbNameArray[3]
    const tbName4 = tbNameArray[4]
    const tbData0 = jsonDataSet[tbName0]
    const tbData1 = jsonDataSet[tbName1]
    const tbData2 = jsonDataSet[tbName2]
    const tbData3 = tbNameArray.length > 3 ? jsonDataSet[tbName3] : []
    const tbData4 = tbNameArray.length > 4 ? jsonDataSet[tbName4] : []

    tbResult[tbName0] = []
    const index0 = 0
    for (let i = 0; i < tbData0.length; i++) {
      const tbTemp0 = tbData0[i]
      tbResult[tbName0][index0] = tbTemp0
      tbResult[tbName0][index0][tbName1] = []
      let index1 = 0
      for (let j = 0; j < tbData1.length; j++) {
        const tbTemp1 = tbData1[j]
        if (tbData0[i][tbName0 + '_Id'] == tbData1[j][tbName0 + '_Id']) {
          tbResult[tbName0][index0][tbName1][index1] = tbTemp1
          tbResult[tbName0][index0][tbName1][index1][tbName2] = []
          let index2 = 0
          for (let k = 0; k < tbData2.length; k++) {
            const tbTemp2 = tbData2[k]
            if (tbData1[j][tbName1 + '_Id'] == tbData2[k][tbName1 + '_Id']) {
              tbResult[tbName0][index0][tbName1][index1][tbName2][index2] =
                tbTemp2
              tbResult[tbName0][index0][tbName1][index1][tbName2][index2][
                tbName3
              ] = []
              let index3 = 0
              for (let l = 0; l < tbData3.length; l++) {
                const tbTemp3 = tbData3[l]
                if (
                  tbData2[k][tbName2 + '_Id'] == tbData3[l][tbName2 + '_Id']
                ) {
                  tbResult[tbName0][index0][tbName1][index1][tbName2][index2][
                    tbName3
                  ][index3] = tbTemp3
                  tbResult[tbName0][index0][tbName1][index1][tbName2][index2][
                    tbName3
                  ][index3][tbName4] = []
                  let index4 = 0
                  for (let m = 0; m < tbData4.length; m++) {
                    const tbTemp4 = tbData4[m]
                    if (
                      tbData3[k][tbName3 + '_Id'] == tbData4[m][tbName3 + '_Id']
                    ) {
                      tbResult[tbName0][index0][tbName1][index1][tbName2][
                        index2
                      ][tbName3][index3][tbName4][index4] = tbTemp4
                      index4++
                    }
                  }
                  index3++
                }
              }
              index2++
            }
          }
          index1++
        }
      }
    }
  }
  return tbResult
}
// 随机抽取算法
const RandomlySelected = function (arr: any) {
  const array = []
  while (arr.length) {
    const randomIndex = Math.floor(Math.random() * arr.length)
    array.push(arr[randomIndex])
    arr.splice(randomIndex, 1)
    //console.log(array);
  }
  return array
}

export {
  SortArrayByOrderArray,
  GetDifferentArray,
  GetJsonConfig,
  GetOrderItemsByConfig,
  GetJsonFormDataSet,
  RandomlySelected
}
 

common-handler.ts

import { FlowConfig } from '@/types'
import { GetAppSetting, hydate } from '@/common'

// 检查流程服务时间
const CheckFlowServerTime = async function (currentFlow: FlowConfig) {
  let msg = null
  {
    const FlowStopServerSpanTimes = await GetAppSetting(
      'FlowStopServerSpanTimes'
    ) //RealTimeRegister^11:15-14:00;
    if (
      FlowStopServerSpanTimes != undefined &&
      FlowStopServerSpanTimes.indexOf(currentFlow.key) > -1
    ) {
      let timeValue = ''
      const flowList = FlowStopServerSpanTimes.split(';')
      for (const i in flowList) {
        const flowConfig = flowList[i].trim()
        if (flowConfig != '') {
          const config = flowConfig.split('^')
          const flowKey = config[0] //RealTimeRegister
          if (flowKey == currentFlow.key) {
            const value = config[1] //11:15-14:00
            const spanTimes = value.split(',')
            for (const j in spanTimes) {
              const spanTime = spanTimes[j]
              const startTime = spanTime.split('-')[0]
              const endTime = spanTime.split('-')[1]
              const nowTime = hydate(new Date()).format('HH:mm')

              if (nowTime >= startTime && nowTime < endTime) {
                timeValue = value
                break
              }
            }
            break
          }
        }
      }
      if (timeValue != '') {
        msg = `【${currentFlow.name}】暂停服务:${timeValue}`
      }
    }
  }
  return msg
}
// 检查选择就诊方式页面
const CheckSelectCardPage = function (url: string) {
  console.log(url)
  // 暂未实现
  return url
}

export { CheckFlowServerTime, CheckSelectCardPage }
 

business-handler.ts

import { hydate } from '@/common'
import { useSystemStore } from '@/store'
import { useFlowPage } from '@/service/flow-page'
import { FlowDir } from '../base-config'
import { FlowConfig } from '@/types'

// 清理功能业务
const ClearBusiness = function () {
  const systemStore = useSystemStore()
  systemStore.setDictFlowKey('')
  systemStore.initDictFlow()
  systemStore.setDictLinkFlowKey('')
  systemStore.setDictLinkFlowPage('')
  systemStore.setDictBusinessTrace('')
  systemStore.setDictTradeId('')
  systemStore.intDictPage()
  systemStore.initDictDevice()
  systemStore.initDictSystem()
  systemStore.initDictStaticValue()
  systemStore.initDictNullValue()
  systemStore.initDictOut()
  systemStore.initDictConfig()
  systemStore.initDictManage()
  systemStore.setDictReceiptList([])
  systemStore.setMessageMsg('')
  systemStore.setMessageError('')
  systemStore.setMessageVoice('')
}

// 初始化功能业务
const InitBusiness = async function (flowDir: string, flowKey: string) {
  ClearBusiness()
  // 解析流程配置
  const flowPage = useFlowPage()
  const flowFileName = flowKey
  const flow =
    (await flowPage.getFlowConfigInUse(flowDir, flowFileName, flowKey)) ||
    ({} as FlowConfig)

  // 初始化业务参数
  const systemStore = useSystemStore()
  systemStore.setDictFlowKey(flowKey)
  systemStore.setDictFlow(flow)
  systemStore.setDictOperatorId(systemStore.dictTerminal.EmpNo)
  systemStore.setDictBusinessTrace(
    `${systemStore.dictTerminal.TerminalNo}-${hydate(new Date()).format('YYYYMMDDHHmmssSSS')}-${flowKey}`
  )
  return systemStore.dictFlow
}

// 初始化链接功能业务
const InitLinkBusiness = async function (flowDir: string, flowKey: string) {
  // 解析流程配置
  const flowPage = useFlowPage()
  const flowFileName = flowKey
  const flow =
    (await flowPage.getFlowConfigInUse(flowDir, flowFileName, flowKey)) ||
    ({} as FlowConfig)

  // 初始化业务参数
  const systemStore = useSystemStore()
  systemStore.setDictFlowKey(flowKey)
  systemStore.setDictFlow(flow)
  systemStore.setDictOperatorId(systemStore.dictTerminal.EmpNo)
  systemStore.setDictBusinessTrace(
    `${systemStore.dictTerminal.TerminalNo}-${hydate(new Date()).format('YYYYMMDDHHmmssSSS')}-${flowKey}`
  )
  systemStore.setDictReceiptList([])
  systemStore.setMessageMsg('')
  systemStore.setMessageError('')
  systemStore.setMessageVoice('')

  return systemStore.dictFlow
}

// 创建链接业务
const CreateLinkBusiness = async function (flowKey: string) {
  const systemStore = useSystemStore()
  systemStore.setDictLinkFlowKey('')
  systemStore.setDictLinkFlowKey('')
  systemStore.setDictTradeId('')
  systemStore.setDictFlow(await InitLinkBusiness(FlowDir, flowKey))
}

export { InitBusiness, CreateLinkBusiness }
 

data-handler.ts

import { hydate } from '@/common'
import { useSystemStore } from '@/store'
import { useSystemUtil } from '@/utils/system'
import { BaseConfig } from '../base-config'
import { BaseData } from '../base-data'

const systemUtil = useSystemUtil()

// 根据性别名称获取性别编码
const GetSexCodeByName = function (sexName: string) {
  return systemUtil.getValueFromKeyValueArray(BaseData.sexList, sexName)
}
// 根据身份证号获取出生日期
const GetBirthDateByIdCardNo = function (IdCardNo: string) {
  const date = systemUtil.getBirthDateByIdCardNo(IdCardNo)
  // return hydate(date).format('YYYYMMDD')
  return hydate(date).format('YYYY-MM-DD')
}
// 根据民族编码获取民族名称
const GetNationNameByCode = function (nationCode: string) {
  return systemUtil.getValueFromKeyValueArray(BaseData.nationList, nationCode)
}
// 根据民族名称获取民族编码
const GetNationCodeByName = function (nationName: string) {
  return systemUtil.getKeyFromKeyValueArray(BaseData.nationList, nationName)
}
// 获取当前就诊方式
const GetCurrentIdCardType = function () {
  const systemStore = useSystemStore()
  return systemStore.dictSystem['IdCardType']
}
// 获取当前就诊方式名称
const GetCurrentIdCardTypeName = function () {
  const systemStore = useSystemStore()
  return systemStore.dictSystem['IdCardTypeName']
}
// 获取当前支付方式
const GetCurrentPayWay = function () {
  const systemStore = useSystemStore()
  return systemStore.dictSystem['payWay']
}
// 获取当前支付方式名称
const GetCurrentPayWayName = function () {
  const systemStore = useSystemStore()
  return systemStore.dictSystem['payWayName']
}
// 获取当前交易类型(银医系统参数)
const GetCurrentModeType = function () {
  return systemUtil.getValueFromKeyValueArray(
    BaseConfig.ModeTypeList,
    GetCurrentPayWayName()
  )
}
// 通过Item数据和Item模板获取Html
const GetHtmlByItemDataAndTemplate = function (
  items: any,
  itemTemplate: string
) {
  let itemsHtml = ''
  for (let i = 0; i < items.length; i++) {
    const item = items[i]
    let itemHtml = itemTemplate
    itemHtml = itemHtml.replaceAll('{itemIndex}', i.toString())
    for (const key in item) {
      itemHtml = itemHtml.replaceAll('{' + key + '}', item[key])
    }
    itemsHtml += itemHtml
  }

  return itemsHtml
}
// 把Item数据填充到Item模版
const FillItemDataToItemTemplate = function (
  items: any,
  everyRow: number,
  rowCount: number,
  itemTemplate: string,
  Id_divItems: string,
  Id_divItem: string,
  isInPager: boolean,
  isCheckAll: boolean
) {
  let itemsHtml = ''
  for (let i = 0; i < items.length; i++) {
    const item = items[i]
    const pageIndex = Math.floor(i / (everyRow * rowCount)) // 分页
    let itemHtml = itemTemplate
    itemHtml = itemHtml.replaceAll('{pageIndex}', pageIndex.toString())
    itemHtml = itemHtml.replaceAll('{rowNo}', (i + 1).toString())
    itemHtml = itemHtml.replaceAll('{itemIndex}', i.toString())
    if (isCheckAll != undefined && isCheckAll == true) {
      itemHtml = itemHtml.replaceAll('{checked}', '_ax')
    } else {
      itemHtml = itemHtml.replaceAll('{checked}', '')
    }
    for (const key in item) {
      itemHtml = itemHtml.replaceAll('{' + key + '}', item[key])
    }
    itemsHtml += itemHtml
  }

  console.log(Id_divItems, Id_divItem, isInPager, itemsHtml)
  // 需要考虑如何替代
  // $(Id_divItems).html(itemsHtml)
  // if (isInPager != undefined && isInPager == true) {
  //   system.inpager.set(Id_divItem, items.length, everyRow, rowCount)
  // } else {
  //   system.pager.set(Id_divItem, items.length, everyRow, rowCount)
  // }
}

export {
  GetSexCodeByName,
  GetBirthDateByIdCardNo,
  GetNationNameByCode,
  GetNationCodeByName,
  GetCurrentIdCardType,
  GetCurrentIdCardTypeName,
  GetCurrentPayWay,
  GetCurrentPayWayName,
  GetCurrentModeType,
  GetHtmlByItemDataAndTemplate,
  FillItemDataToItemTemplate
}
 

log-handler.ts

// 日志操作类

import { useSystemStore } from '@/store'
import { useSystemService } from '@/service'
import { useSystemUtil } from '@/utils/system'
import { GetCurrentModeType } from './data-handler'
import { BaseConfig } from '../base-config'

const systemUtil = useSystemUtil()

// 获取终端交易流水号
const GetTerimnalTrace = function () {
  const systemStore = useSystemStore()
  return systemUtil.getTerimnalTrace(systemStore.dictTerminal['TerminalNo'])
}
// 记录业务流水(初始化)
const InitTraceInfo = async function () {
  const systemStore = useSystemStore()
  const systemService = useSystemService()
  const BusinessType = BaseConfig.GetBusinessTypeByFlowKey(
    systemStore.dictFlow.key,
    systemStore.dictFlow.name
  )
  systemStore.setDictTradeId(
    await systemService.addOrUpdateTradeInfo(
      '', //TradeID
      systemStore.dictTerminal['TerminalNo'], //TerminalNo
      systemStore.dictTerminal['TerminalIp'], //TerminalIP
      systemStore.dictTerminal['TellerNo'], //TellerNo
      '', //PatientCardID
      '', //PatientID
      '', //PatientName
      '0303', //TradeState
      '', //IdCardNo
      '0', //CurrentMoney
      '0', //TradeMoney
      '', //TradeTypeID
      BusinessType['name'], //TradeNameID
      systemStore.dictFlowKey, //ProcessKey
      BusinessType['code'], //TradeType
      '', //ApiState
      systemStore.dictTerminal['OrgId'], //Hospital_No
      '', //BusinessOrderNo
      systemStore.dictBusinessTrace //ProcessId
    )
  )
}
// 记录业务流水(插入数据|更新数据)
const LogBusinessTrace = async function () {
  const systemStore = useSystemStore()
  const systemService = useSystemService()

  let cardBalance = '0.00'
  if (
    systemStore.dictSystem['cardBalance'] != undefined &&
    systemStore.dictSystem['cardBalance'] != '' &&
    systemStore.dictSystem['cardBalance'] != 'NaN'
  ) {
    cardBalance = systemStore.dictSystem['cardBalance']
  }

  await systemService.logBusinessTrace(
    systemStore.dictBusinessTrace,
    systemStore.dictFlowKey,
    systemStore.dictTerminal['TerminalIp'],
    systemStore.dictTerminal['OrgId'],
    systemStore.dictTerminal['TerminalNo'],
    systemStore.dictSystem['IdCardNo'],
    systemStore.dictSystem['cardNo'],
    systemStore.dictSystem['bankCardNo'],
    systemStore.dictSystem['patientId'],
    systemStore.dictSystem['patientName'],
    systemStore.dictSystem['telephone']
  )

  let traceId = ''
  if (systemStore.dictTradeId == null) {
    traceId = ''
  } else {
    traceId = systemStore.dictTradeId
    const BusinessType = BaseConfig.GetBusinessTypeByFlowKey(
      systemStore.dictFlow.key,
      systemStore.dictFlow.name
    )
    systemStore.setDictTradeId(
      await systemService.addOrUpdateTradeInfo(
        traceId, //TradeID
        systemStore.dictTerminal['TerminalNo'], //TerminalNo
        systemStore.dictTerminal['TerminalIp'], //TerminalIP
        systemStore.dictTerminal['TellerNo'], //TellerNo
        systemStore.dictSystem['cardNo'], //PatientCardID
        systemStore.dictSystem['patientId'], //PatientID
        systemStore.dictSystem['patientName'], //PatientName
        '0303', //TradeState
        systemStore.dictSystem['IdCardNo'], //IdCardNo
        cardBalance, //CurrentMoney
        '0', //TradeMoney
        '', //TradeTypeID
        BusinessType['name'], //TradeNameID
        systemStore.dictFlowKey, //ProcessKey
        BusinessType['code'], //TradeType
        '', //ApiState
        systemStore.dictTerminal['OrgId'], //Hospital_No
        '', //BusinessOrderNo
        systemStore.dictBusinessTrace //ProcessId
      )
    )
  }
}
// 记录业务结果(更新数据)
const LogBusinessResult = async function (
  trace: string,
  tradeAmt: string,
  resultCodeMsg: string,
  refundMsg: string
) {
  const systemStore = useSystemStore()
  const systemService = useSystemService()
  const systemUtil = useSystemUtil()

  const result = systemUtil.parseTradeResult(resultCodeMsg)
  const tradeResult = result['tradeResult'].toString()
  // const tradeResultMsg = result['tradeResultMsg']
  const flag = result['flag']
  const tradeLastMsg = systemUtil.getTradeLastMsg(resultCodeMsg, refundMsg)
  const handleInfo = ''

  await systemService.logBusinessResult(
    systemStore.dictBusinessTrace,
    systemStore.dictTerminal['TerminalNo'],
    systemStore.dictSystem['patientName'],
    trace,
    tradeAmt,
    tradeResult,
    tradeLastMsg,
    flag,
    handleInfo
  )

  let tradeState = ''
  if (flag == '0') {
    tradeState = '0301'
  } else if (flag == '1') {
    tradeState = '0302'
  } else {
    tradeState = '0300'
  }
  systemService.updateTradeInfo(
    systemStore.dictTradeId, //TradeID
    tradeState, //TradeState
    tradeAmt, //TradeMoney
    trace //BusinessOrderNo
  )
}
// 记录账户明细
// tradeType:交易类型(1-充值、转账或支付,2-退款,3-冲正,4-消费余额)
const LogAccountDetail = async function (
  trace: string,
  tradeAmt: string,
  tradeType: string
) {
  const systemStore = useSystemStore()
  const systemService = useSystemService()

  const modeType = GetCurrentModeType()
  await systemService.logAccountDetail(
    systemStore.dictBusinessTrace,
    systemStore.dictTerminal['TerminalNo'],
    trace,
    modeType,
    tradeType,
    systemStore.dictTerminal['EmpNo'],
    tradeAmt,
    systemStore.dictSystem['cardNo'],
    systemStore.dictSystem['patientId'],
    systemStore.dictSystem['patientName'],
    '',
    '',
    '',
    '',
    '',
    '',
    ''
  )
}
// 记录账户明细结果
const LogAccountDetailResult = async function (
  trace: string,
  tradeAmt: string,
  resultCodeMsg: string,
  iSTrace: string,
  iSTradeDate: string
) {
  const systemService = useSystemService()
  const systemUtil = useSystemUtil()

  const result = systemUtil.parseTradeResult(resultCodeMsg)
  const tradeResult = result['tradeResult'].toString()
  // const tradeResultMsg = result['tradeResultMsg']
  // const flag = result['flag']

  console.log('LogAccountDetailResult', trace, tradeAmt, resultCodeMsg)
  await systemService.logAccountDetailResult(
    trace,
    tradeResult,
    iSTrace,
    iSTradeDate
  )
}
// 记录业务消息
const LogBusinessMsg = async function (msgValue: string, msgInfo: string) {
  const systemStore = useSystemStore()
  const systemService = useSystemService()
  await systemService.logBusinessMsg(
    systemStore.dictBusinessTrace,
    msgValue,
    msgInfo
  )

  //debugger
  if (systemStore.dictTradeId != null) {
    const tradeId = systemStore.dictTradeId
    if (window.location.href.indexOf('Successful.html') > -1) {
      await systemService.updateTradeInfoStatus(tradeId, '0301')
    } else if (window.location.href.indexOf('Failure.html') > -1) {
      await systemService.updateTradeInfoStatus(tradeId, '0302')
    } else if (window.location.href.indexOf('Error.html') > -1) {
      await systemService.updateTradeInfoStatus(tradeId, '0303')
    }
  }
}

export {
  GetTerimnalTrace,
  InitTraceInfo,
  LogBusinessTrace,
  LogBusinessResult,
  LogAccountDetail,
  LogAccountDetailResult,
  LogBusinessMsg
}
 

device-handler.ts

import { LogTerminalInfo } from '@/common'
import { useSystemStore } from '@/store'
import { useDeviceDriver } from '@/service'
import { BaseConfig } from '../base-config'

// 获取设备类型名称
const GetTerminalTypeName = function () {
  const systemStore = useSystemStore()
  let typeName = systemStore.dictTerminal.TypeName
  if (typeName.indexOf('-') > -1) {
    typeName = typeName.split('-')[0]
  }
  return typeName
}
// 获取指示灯列表
const GetLightNoList = function (name: string) {
  const lightNoList = []

  const SetLight = BaseConfig.GetSIU('SetLight')
  if (SetLight != null) {
    const terminalType = GetTerminalTypeName()
    for (const i in SetLight) {
      const data = SetLight[i]
      if (data['name'] == terminalType) {
        if (name == 'lighton') {
          const light = data['lighton']
          for (const j in light) {
            const lightlist = light[j]['lightlist'].split(',')
            for (const k in lightlist) {
              if (lightlist[k] != null && lightlist[k].trim() != '') {
                lightNoList.push(lightlist[k].trim())
              }
            }
          }
        } else if (name == 'EleLock1' || name == 'EleLock2') {
          const light = data['door']
          for (const j in light) {
            if (name == light[j]['device']) {
              const lightlist = light[j]['lightlist'].split(',')
              for (const k in lightlist) {
                if (lightlist[k] != null && lightlist[k].trim() != '') {
                  lightNoList.push(lightlist[k].trim())
                }
              }
              break
            }
          }
        } else {
          const light = data['sp']
          for (const j in light) {
            if (name == light[j]['device']) {
              const lightlist = light[j]['lightlist'].split(',')
              for (const k in lightlist) {
                if (lightlist[k] != null && lightlist[k].trim() != '') {
                  lightNoList.push(lightlist[k].trim())
                }
              }
              break
            }
          }
        }
        break
      }
    }
  }

  return lightNoList
}
// 设置灯亮
// command:4-慢速闪,8-中速闪,16-快速闪,128-常亮
const SetLightOn = function (name: string, command: string) {
  const dd = useDeviceDriver()

  const lightNoList = GetLightNoList(name)
  LogTerminalInfo(
    `SetLightOn() command=[${command}],lights=[${lightNoList.join(',')}]`
  )

  if (GetTerminalTypeName() == 'MST301') {
    for (const i in lightNoList) {
      //MST301:调用彩控板OUT6、OUT7,SP会卡死,此处跳过
      if (lightNoList[i] == '6' || lightNoList[i] == '7') {
        continue
      }
      if (name == 'ssCardReader' && command == '16') {
        command = '128'
      }
      dd.siu.setGuidLight(lightNoList[i], command)
    }
  } else {
    for (const i in lightNoList) {
      dd.siu.setGuidLight(lightNoList[i], command)
    }
  }
}
// 设置灯灭
const SetLightOff = function (name: string) {
  const dd = useDeviceDriver()

  const lightNoList = GetLightNoList(name)
  LogTerminalInfo(`SetLightOff() lights=[${lightNoList.join(',')}]`)

  if (GetTerminalTypeName() == 'MST301') {
    for (const i in lightNoList) {
      //MST301:调用彩控板OUT6、OUT7,SP会卡死,此处跳过
      if (lightNoList[i] == '6' || lightNoList[i] == '7') {
        continue
      }
      dd.siu.setGuidLight(lightNoList[i], '0')
    }
  } else {
    for (const i in lightNoList) {
      dd.siu.setGuidLight(lightNoList[i], '0')
    }
  }
}
// 检测退卡
const CheckEjectCard = function () {
  const dd = useDeviceDriver()
  dd.ssCardReader.ejectCard()
}

export {
  GetTerminalTypeName,
  GetLightNoList,
  SetLightOn,
  SetLightOff,
  CheckEjectCard
}

 

 

posted @ 2024-03-19 09:14  lizhigang  阅读(1)  评论(0编辑  收藏  举报