From cd40c6f6f3a6138cb70b2e2d017cc7f34a887ef8 Mon Sep 17 00:00:00 2001
From: lgq <1015864684@qq.com>
Date: 星期五, 17 四月 2026 13:59:49 +0800
Subject: [PATCH] 1.更新vf107代码,更新自动上报通行记录接口、人员查询接口、人员添加接口
---
vf107/src/service/accessService.js | 292 +++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 209 insertions(+), 83 deletions(-)
diff --git a/vf107/src/service/accessService.js b/vf107/src/service/accessService.js
index 35ec0a1..09940bc 100644
--- a/vf107/src/service/accessService.js
+++ b/vf107/src/service/accessService.js
@@ -169,7 +169,16 @@
} catch (error) {
logger.error("鏃犺韩浠借瘉鍙锋垨绫诲瀷")
}
- data.extra = { name: res[0].name, idCard: idCard, type: userType }
+ // 鏍规嵁data.type璁剧疆姝g‘鐨勮璇佺被鍨�
+ 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
}
@@ -183,21 +192,39 @@
// 鏌ヨ绗竴鐢ㄦ埛鐨勮缁嗕俊鎭�
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璁剧疆姝g‘鐨勮璇佺被鍨�
+ 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璁剧疆姝g‘鐨勮璇佺被鍨�
+ 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
@@ -206,19 +233,37 @@
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璁剧疆姝g‘鐨勮璇佺被鍨�
+ 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 }
// 瀛樺偍绗簩鐢ㄦ埛鐨勬潈闄怚D锛堣韩浠界被鍨嬶級
- data.permissionId2 = secondUserType.toString()
+ data.permissionId2 = userType2.toString()
} else {
// 濡傛灉娌℃湁鏌ヨ鍒扮浜岀敤鎴蜂俊鎭紝浣跨敤榛樿鍊�
- data.extra2 = { name: data.dualAuthInfo.secondUserName, idCard: "" }
+ // 鏍规嵁data.type璁剧疆姝g‘鐨勮璇佺被鍨�
+ 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 = ""
}
// 澶勭悊绗竴鐢ㄦ埛鐨勪汉鑴稿浘鐗�
@@ -323,6 +368,19 @@
if (authQueue.length === 1) {
// 绗竴鐢ㄦ埛璁よ瘉
logger.info("[access]: 淇濈鍛樻潈闄愶紝闇�瑕佸弻浜鸿璇�")
+ // 纭繚data.extra鍖呭惈accessType瀛楁
+ if (!data.extra.accessType) {
+ // 鏍规嵁data.type璁剧疆姝g‘鐨勮璇佺被鍨�
+ 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
+ }
// 瑙﹀彂绗竴鐢ㄦ埛璁よ瘉鎴愬姛浜嬩欢锛屾洿鏂癠I
bus.fire("accessSuccess", {
data: {
@@ -413,13 +471,19 @@
} catch (error) {
logger.error("鏃犵涓�鐢ㄦ埛韬唤璇佸彿鎴栫被鍨�")
}
- data.extra = { name: userRes[0].name, idCard: idCard1, type: firstUserType }
+ // 纭繚绗竴鐢ㄦ埛鐨勪俊鎭寘鍚玜ccessType瀛楁
+ 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 }
+ // 纭繚绗竴鐢ㄦ埛鐨勪俊鎭寘鍚玜ccessType瀛楁
+ let accessType1 = firstUser.data.extra.accessType || 0
+ data.extra = { name: firstUser.name, idCard: '', type: firstUser.type, accessType: accessType1 }
}
} catch (error) {
logger.error("瑙f瀽绗竴鐢ㄦ埛淇℃伅澶辫触")
- data.extra = { name: firstUser.name, idCard: '', type: firstUser.type }
+ // 纭繚绗竴鐢ㄦ埛鐨勪俊鎭寘鍚玜ccessType瀛楁
+ let accessType1 = firstUser.data.extra.accessType || 0
+ data.extra = { name: firstUser.name, idCard: '', type: firstUser.type, accessType: accessType1 }
}
// 瀛樺偍绗簩鐢ㄦ埛鐨勪汉鑴稿浘鐗�
if (secondUser.fileName) {
@@ -481,7 +545,7 @@
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`)
// 绛夊緟鍦ㄧ嚎楠岃瘉缁撴灉
@@ -504,63 +568,28 @@
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: "*浠撳唴姘斾綋娴撳害涓嶅悎鏍硷紝绂佹閫氳*"
- })
- // 瑙﹀彂閫氳鎴愬姛浜嬩欢锛屾洿鏂扮敤鎴稶I
- 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) {
@@ -771,24 +800,55 @@
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))
+ // 涓嶅啀鐩存帴鍙戦�丮QTT娑堟伅锛岀敱passRecordWorker.js缁熶竴澶勭悊涓婃姤
+ // let payload = mqttService.mqttReply(serialNo, [accessRecord], mqttService.CODE.S_000)
+ // driver.mqtt.send("access_device/v2/event/access", JSON.stringify(payload))
}
// 钃濈墮鍥炲
@@ -801,5 +861,71 @@
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]: 閫氳鎴愬姛")
+
+ // 纭繚绗竴鐢ㄦ埛鐨別xtra鍖呭惈accessType瀛楁
+ if (!data.extra.accessType) {
+ // 鏍规嵁data.type璁剧疆姝g‘鐨勮璇佺被鍨�
+ 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
+ })
+ // 瑙﹀彂閫氳鎴愬姛浜嬩欢锛屾洿鏂扮敤鎴稶I
+ 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
\ No newline at end of file
--
Gitblit v1.9.3