package com.zhgd.mqtt.server; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.zhgd.xmgl.modules.worker.service.IUfaceDevService; import com.zhgd.xmgl.modules.worker.service.IWorkerAttendanceService; import com.zhgd.xmgl.modules.xz.service.IXzHikvisionSyncService; import net.sf.jsqlparser.statement.select.PlainSelect; import org.springframework.messaging.Message; import org.springframework.stereotype.Component; import javax.annotation.Resource; @Component public class DispatchHandler { @Resource private IXzHikvisionSyncService xzHikvisionSyncService; @Resource private IWorkerAttendanceService workerAttendanceService; @Resource private IUfaceDevService ufaceDevService; public void message(String topic, Object payLoad) { // 下发人脸返回 if (topic.contains("mqtt/face/") && topic.contains("/Ack")) { JSONObject jsonObject = JSONObject.parseObject(payLoad.toString()); if (jsonObject.getString("code").equals("200")) { JSONArray jsonArray = jsonObject.getJSONObject("info").getJSONArray("AddSucInfo"); xzHikvisionSyncService.mqttAck(topic.split("/")[2], jsonArray, 1); JSONArray errorArray = jsonObject.getJSONObject("info").getJSONArray("AddErrInfo"); xzHikvisionSyncService.mqttAck(topic.split("/")[2], errorArray, 0); } } // 人脸识别推送 if (topic.contains("mqtt/face/") && topic.contains("/Rec")) { JSONObject jsonObject = JSONObject.parseObject(payLoad.toString()); workerAttendanceService.mqttRec(topic.split("/")[2], jsonObject); } //正赢人脸下发返回 if (topic.equals("face/createFace/response")) { JSONObject jsonObject = JSONObject.parseObject(payLoad.toString()); if (jsonObject.getString("code").equals("0")) { xzHikvisionSyncService.zyMqttAck(jsonObject.getString("sn"), jsonObject.getString("pers_id"), 1); } else { xzHikvisionSyncService.zyMqttAck(jsonObject.getString("sn"), jsonObject.getString("pers_id"), 0); } } //正赢删除人脸下发返回 if (topic.equals("face/deleteFace/response")) { JSONObject jsonObject = JSONObject.parseObject(payLoad.toString()); if (jsonObject.getString("code").equals("0")) { xzHikvisionSyncService.zyDelMqttAck(jsonObject.getString("sn"), jsonObject.getString("pers_id")); } } // 正赢人脸识别推送 if (topic.equals("face/response")) { JSONObject jsonObject = JSONObject.parseObject(payLoad.toString()); JSONObject body = jsonObject.getJSONObject("body"); workerAttendanceService.zyMqttRec(body); } // 正赢人脸设备心跳推送 if (topic.equals("heartbeat/response")) { JSONObject jsonObject = JSONObject.parseObject(payLoad.toString()); ufaceDevService.online(jsonObject.getString("sn")); } } }