| | |
| | | } catch (error) { |
| | | logger.error("无身份证号或类型") |
| | | } |
| | | data.extra = { name: res[0].name, idCard: idCard, type: userType } |
| | | // 根据data.type设置正确的认证类型 |
| | | let accessType = 0 |
| | | if (data.type == "200") { |
| | | accessType = 200 // 刷卡 |
| | | } else if (data.type == "300") { |
| | | accessType = 300 // 人脸 |
| | | } else if (data.type == "500") { |
| | | accessType = 500 // 指纹 |
| | | } |
| | | data.extra = { name: res[0].name, idCard: idCard, card: data.code, type: userType, accessType: accessType } |
| | | data.permissionIds = res[0].permissionIds |
| | | |
| | | } |
| | |
| | | // 查询第一用户的详细信息 |
| | | let res1 = sqliteService.d1_person.findByUserId(firstUserId) |
| | | if (res1.length > 0) { |
| | | // 获取第一用户的姓名、身份证号和身份类型 |
| | | // 获取第一用户的姓名、身份证号 |
| | | let idCard1 |
| | | let firstUserType = 0 |
| | | let userType1 = 0 |
| | | try { |
| | | idCard1 = JSON.parse(res1[0].extra).idCard |
| | | firstUserType = JSON.parse(res1[0].extra).type || 0 |
| | | userType1 = JSON.parse(res1[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("无第一用户身份证号或类型") |
| | | logger.error("无第一用户身份证号") |
| | | } |
| | | // 根据data.type设置正确的认证类型 |
| | | let accessType1 = 0 |
| | | if (data.type == "200") { |
| | | accessType1 = 200 // 刷卡 |
| | | } else if (data.type == "300") { |
| | | accessType1 = 300 // 人脸 |
| | | } else if (data.type == "500") { |
| | | accessType1 = 500 // 指纹 |
| | | } |
| | | data.userId = firstUserId |
| | | data.extra = { name: res1[0].name, idCard: idCard1, type: firstUserType } |
| | | data.extra = { name: res1[0].name, idCard: idCard1, card: data.code, type: userType1, accessType: accessType1 } |
| | | } else { |
| | | // 如果没有查询到第一用户信息,使用默认值 |
| | | data.userId = firstUserId |
| | | data.extra = { name: data.dualAuthInfo.firstUserName, idCard: "", type: 0 } |
| | | // 根据data.type设置正确的认证类型 |
| | | let accessType1 = 0 |
| | | if (data.type == "200") { |
| | | accessType1 = 200 // 刷卡 |
| | | } else if (data.type == "300") { |
| | | accessType1 = 300 // 人脸 |
| | | } else if (data.type == "500") { |
| | | accessType1 = 500 // 指纹 |
| | | } |
| | | data.extra = { name: data.dualAuthInfo.firstUserName, idCard: "", type: 0, accessType: accessType1 } |
| | | } |
| | | // 存储第二用户信息 |
| | | data.userId2 = data.dualAuthInfo.secondUserId |
| | |
| | | if (res2.length > 0) { |
| | | // 获取第二用户的姓名和身份证号 |
| | | let idCard2 |
| | | let secondUserType = 0 |
| | | let userType2 = 0 |
| | | try { |
| | | idCard2 = JSON.parse(res2[0].extra).idCard |
| | | secondUserType = JSON.parse(res2[0].extra).type || 0 |
| | | userType2 = JSON.parse(res2[0].extra).type || 0 |
| | | } catch (error) { |
| | | logger.error("无第二用户身份证号或类型") |
| | | logger.error("无第二用户身份证号") |
| | | } |
| | | data.extra2 = { name: res2[0].name, idCard: idCard2 } |
| | | // 根据data.type设置正确的认证类型 |
| | | let accessType2 = 0 |
| | | if (data.type == "200") { |
| | | accessType2 = 200 // 刷卡 |
| | | } else if (data.type == "300") { |
| | | accessType2 = 300 // 人脸 |
| | | } else if (data.type == "500") { |
| | | accessType2 = 500 // 指纹 |
| | | } |
| | | data.extra2 = { name: res2[0].name, idCard: idCard2, card: data.code2, type: userType2, accessType: accessType2 } |
| | | // 存储第二用户的权限ID(身份类型) |
| | | data.permissionId2 = secondUserType.toString() |
| | | data.permissionId2 = userType2.toString() |
| | | } else { |
| | | // 如果没有查询到第二用户信息,使用默认值 |
| | | data.extra2 = { name: data.dualAuthInfo.secondUserName, idCard: "" } |
| | | // 根据data.type设置正确的认证类型 |
| | | let accessType2 = 0 |
| | | if (data.type == "200") { |
| | | accessType2 = 200 // 刷卡 |
| | | } else if (data.type == "300") { |
| | | accessType2 = 300 // 人脸 |
| | | } else if (data.type == "500") { |
| | | accessType2 = 500 // 指纹 |
| | | } |
| | | data.extra2 = { name: data.dualAuthInfo.secondUserName, idCard: "", type: 0, accessType: accessType2 } |
| | | data.permissionId2 = "" |
| | | } |
| | | // 处理第一用户的人脸图片 |
| | |
| | | if (authQueue.length === 1) { |
| | | // 第一用户认证 |
| | | logger.info("[access]: 保管员权限,需要双人认证") |
| | | // 确保data.extra包含accessType字段 |
| | | if (!data.extra.accessType) { |
| | | // 根据data.type设置正确的认证类型 |
| | | let accessType = 0 |
| | | if (data.type == "200") { |
| | | accessType = 200 // 刷卡 |
| | | } else if (data.type == "300") { |
| | | accessType = 300 // 人脸 |
| | | } else if (data.type == "500") { |
| | | accessType = 500 // 指纹 |
| | | } |
| | | data.extra.accessType = accessType |
| | | } |
| | | // 触发第一用户认证成功事件,更新UI |
| | | bus.fire("accessSuccess", { |
| | | data: { |
| | |
| | | } catch (error) { |
| | | logger.error("无第一用户身份证号或类型") |
| | | } |
| | | data.extra = { name: userRes[0].name, idCard: idCard1, type: firstUserType } |
| | | // 确保第一用户的信息包含accessType字段 |
| | | let accessType1 = firstUser.data.extra.accessType || 0 |
| | | data.extra = { name: userRes[0].name, idCard: idCard1, type: firstUserType, accessType: accessType1 } |
| | | } else { |
| | | data.extra = { name: firstUser.name, idCard: '', type: firstUser.type } |
| | | // 确保第一用户的信息包含accessType字段 |
| | | let accessType1 = firstUser.data.extra.accessType || 0 |
| | | data.extra = { name: firstUser.name, idCard: '', type: firstUser.type, accessType: accessType1 } |
| | | } |
| | | } catch (error) { |
| | | logger.error("解析第一用户信息失败") |
| | | data.extra = { name: firstUser.name, idCard: '', type: firstUser.type } |
| | | // 确保第一用户的信息包含accessType字段 |
| | | let accessType1 = firstUser.data.extra.accessType || 0 |
| | | data.extra = { name: firstUser.name, idCard: '', type: firstUser.type, accessType: accessType1 } |
| | | } |
| | | // 存储第二用户的人脸图片 |
| | | if (secondUser.fileName) { |
| | |
| | | if (!ret && config.get('mqtt.onlinecheck') == 1 && mqtt_map.get("MQTT_STATUS") == "connected") { |
| | | logger.info("[access]: 无权限,走在线验证") |
| | | let serialNo = std.genRandomStr(10) |
| | | driver.mqtt.send("access_device/v2/event/access_online", JSON.stringify(mqttService.mqttReply(serialNo, data, mqttService.CODE.S_000))) |
| | | driver.mqtt.send(`access_device/v2/event/${sn}/access_online`, JSON.stringify(mqttService.mqttReply(serialNo, data, mqttService.CODE.S_000))) |
| | | driver.audio.play(`/app/code/resource/${language}/wav/recg.wav`) |
| | | |
| | | // 等待在线验证结果 |
| | |
| | | bleReply(data, true) |
| | | } |
| | | |
| | | // 验证气体浓度 |
| | | grainService.checkGasConcentration(function() { |
| | | // 从存储的气体数据中获取验证结果 |
| | | const gasData = grainService.getGasData() |
| | | |
| | | if(gasData && gasData.data && gasData.data.status === "0") { |
| | | logger.info("[access]: 气体浓度验证合格") |
| | | // 通行成功处理 |
| | | driver.screen.accessSuccess() |
| | | logger.info("[access]: 通行成功") |
| | | // 检查是否开启气体浓度验证 |
| | | const gasVerificationEnabled = config.get('gas.verification') |
| | | |
| | | if (gasVerificationEnabled) { |
| | | // 验证气体浓度 |
| | | grainService.checkGasConcentration(function() { |
| | | // 从存储的气体数据中获取验证结果 |
| | | const gasData = grainService.getGasData() |
| | | |
| | | // 显示通行成功结果 |
| | | bus.fire("showAccessResult", { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: true, |
| | | message: "*仓内气体浓度合格,允许通行*" |
| | | }) |
| | | |
| | | // 触发通行成功事件,通知UI更新 |
| | | bus.fire("accessSuccess", { data: data, fileName: fileName }) |
| | | driver.audio.play(`/app/code/resource/${language}/wav/access_s.wav`) // 播放语音 |
| | | driver.gpio.open() // 开门 |
| | | savePassPic(data, fileName) // 保存通行图片 |
| | | reply(data, true) // 上报通行记录 |
| | | |
| | | // 60秒后重置用户UI |
| | | std.setTimeout(() => { |
| | | bus.fire("accessUnlockComplete") |
| | | }, 60000) |
| | | } else { |
| | | logger.info("[access]: 气体浓度验证不合格") |
| | | // 通行失败处理 |
| | | driver.screen.accessFail() |
| | | logger.error("[access]: 通行失败") |
| | | // 触发失败弹窗 |
| | | bus.fire("showAccessResult", { |
| | | faceAuth: true, |
| | | gasConcentration: false, |
| | | accessAllowed: false, |
| | | message: "*仓内气体浓度不合格,禁止通行*" |
| | | }) |
| | | // 触发通行成功事件,更新用户UI |
| | | bus.fire("accessSuccess", { data: data, fileName: fileName }) |
| | | if (utils.isEmpty(similarity)) { |
| | | driver.audio.play(`/app/code/resource/${language}/wav/access_f.wav`) |
| | | if(gasData && gasData.data && gasData.data.status === "0") { |
| | | logger.info("[access]: 气体浓度验证合格") |
| | | handleAccessSuccess(data, fileName, similarity, "*仓内气体浓度合格,允许通行*") |
| | | } else { |
| | | logger.info("[access]: 气体浓度验证不合格") |
| | | handleAccessFail(data, fileName, similarity, "*仓内气体浓度不合格,禁止通行*", "气体浓度不合格") |
| | | } |
| | | // 60秒后重置用户UI |
| | | std.setTimeout(() => { |
| | | bus.fire("accessUnlockComplete") |
| | | }, 60000) |
| | | savePassPic(data, fileName) |
| | | // 添加气体浓度失败信息 |
| | | data.message = "气体浓度不合格" |
| | | reply(data, false) // 上报通行记录 |
| | | } |
| | | }) |
| | | }) |
| | | } else { |
| | | // 跳过气体浓度验证,直接通行成功 |
| | | logger.info("[access]: 气体浓度验证已关闭,跳过验证") |
| | | handleAccessSuccess(data, fileName, similarity, "*允许通行*") |
| | | } |
| | | |
| | | } else { |
| | | if (data.type == 500) { |
| | |
| | | sqliteService.d1_pass_record.save(record) |
| | | } |
| | | let accessRecord = { |
| | | userId: record.userId, |
| | | type: record.type, |
| | | result: record.result, |
| | | name: data.extra && data.extra.name ? data.extra.name : "", |
| | | timeStamp: record.timeStamp, |
| | | extra: {}, |
| | | error: record.message |
| | | timeStamp: record.timeStamp || 0, |
| | | result: record.result || 0, |
| | | error: record.message || "", |
| | | permissionId: record.permissionId || "", |
| | | door: record.door || "", |
| | | users: [ |
| | | { |
| | | userId: record.userId || "", |
| | | name: data.extra && data.extra.name ? data.extra.name : "", |
| | | keyId: record.keyId || "", |
| | | userType: data.extra && data.extra.type ? data.extra.type : 0, |
| | | accessType: data.extra && data.extra.accessType || "" |
| | | } |
| | | ] |
| | | } |
| | | |
| | | // 如果是双人认证,添加第二个用户信息 |
| | | if (record.userId2) { |
| | | let extra2 = record.extra2 ? JSON.parse(record.extra2) : "" |
| | | let secondUser = { |
| | | userId: record.userId2 || "", |
| | | name: extra2 && extra2.name ? extra2.name : "", |
| | | userType: extra2 && extra2.type ? extra2.type : 0, |
| | | accessType: extra2.accessType || "" |
| | | } |
| | | // 如果有卡号信息,添加card字段 |
| | | if (extra2 && extra2.card) { |
| | | secondUser.card = extra2.card |
| | | } |
| | | accessRecord.users.push(secondUser) |
| | | } |
| | | |
| | | let serialNo = record.id |
| | | if (record.type == 300) { |
| | | if (config.get('sys.strangerImage') && config.get('access.uploadToCloud')) { |
| | | accessRecord.code = dxCommonUtils.fs.fileToBase64(record.code) |
| | | accessRecord.users[0].code = dxCommonUtils.fs.fileToBase64(record.code) |
| | | } else { |
| | | accessRecord.code = "" |
| | | accessRecord.users[0].code = "" |
| | | } |
| | | |
| | | // 如果有第二个用户的二维码 |
| | | if (record.code2) { |
| | | accessRecord.users[1] = accessRecord.users[1] || {} |
| | | accessRecord.users[1].code = record.code2 |
| | | } |
| | | } |
| | | let payload = mqttService.mqttReply(serialNo, [accessRecord], mqttService.CODE.S_000) |
| | | driver.mqtt.send("access_device/v2/event/access", JSON.stringify(payload)) |
| | | // 不再直接发送MQTT消息,由passRecordWorker.js统一处理上报 |
| | | // let payload = mqttService.mqttReply(serialNo, [accessRecord], mqttService.CODE.S_000) |
| | | // driver.mqtt.send("access_device/v2/event/access", JSON.stringify(payload)) |
| | | } |
| | | |
| | | // 蓝牙回复 |
| | |
| | | driver.uartBle.send("0101" + dxCommonUtils.codec.strToUtf8Hex(replyData)) |
| | | } |
| | | |
| | | function handleAccessSuccess(data, fileName, similarity, message) { |
| | | let language = config.get("base.language") || "CN"; |
| | | driver.screen.accessSuccess() |
| | | logger.info("[access]: 通行成功") |
| | | |
| | | // 确保第一用户的extra包含accessType字段 |
| | | if (!data.extra.accessType) { |
| | | // 根据data.type设置正确的认证类型 |
| | | let accessType = 0 |
| | | if (data.type == "200" || data.type == 200) { |
| | | accessType = 200 // 刷卡 |
| | | } else if (data.type == "300" || data.type == 300) { |
| | | accessType = 300 // 人脸 |
| | | } else if (data.type == "500" || data.type == 500) { |
| | | accessType = 500 // 指纹 |
| | | } |
| | | data.extra.accessType = accessType |
| | | } |
| | | |
| | | // 显示通行成功结果 |
| | | bus.fire("showAccessResult", { |
| | | faceAuth: true, |
| | | gasConcentration: true, |
| | | accessAllowed: true, |
| | | message: message |
| | | }) |
| | | |
| | | // 触发通行成功事件,通知UI更新 |
| | | bus.fire("accessSuccess", { data: data, fileName: fileName }) |
| | | driver.audio.play(`/app/code/resource/${language}/wav/access_s.wav`) // 播放语音 |
| | | driver.gpio.open() // 开门 |
| | | savePassPic(data, fileName) // 保存通行图片 |
| | | reply(data, true) // 上报通行记录 |
| | | |
| | | // 60秒后重置用户UI |
| | | std.setTimeout(() => { |
| | | bus.fire("accessUnlockComplete") |
| | | }, 60000) |
| | | } |
| | | |
| | | function handleAccessFail(data, fileName, similarity, message, errorMessage) { |
| | | let language = config.get("base.language") || "CN"; |
| | | driver.screen.accessFail() |
| | | logger.error("[access]: 通行失败") |
| | | // 触发失败弹窗 |
| | | bus.fire("showAccessResult", { |
| | | faceAuth: true, |
| | | gasConcentration: false, |
| | | accessAllowed: false, |
| | | message: message |
| | | }) |
| | | // 触发通行成功事件,更新用户UI |
| | | bus.fire("accessSuccess", { data: data, fileName: fileName }) |
| | | if (utils.isEmpty(similarity)) { |
| | | driver.audio.play(`/app/code/resource/${language}/wav/access_f.wav`) |
| | | } |
| | | // 60秒后重置用户UI |
| | | std.setTimeout(() => { |
| | | bus.fire("accessUnlockComplete") |
| | | }, 60000) |
| | | savePassPic(data, fileName) |
| | | // 添加失败信息 |
| | | data.message = errorMessage |
| | | reply(data, false) // 上报通行记录 |
| | | } |
| | | |
| | | |
| | | export default accessService |