insert_device_log($param,$ret_device); } } else { // 如果device_log为空,则插入 $this->insert_device_log($param,$ret_device); } }else{ //未发现这个device throw new Exception("设备编码 ".$param['device_code']." 不存在.", 4001); } if(!empty($param['errcode'])){ $sql = "UPDATE hf_mes_device SET msg='".$param['msg']."', errcode='".$errcode."', status='".$param['status']."', last_heartbeat_time=CURRENT_TIMESTAMP(0) WHERE code='".$param['device_code']."';"; }else{ $sql = "UPDATE hf_mes_device SET status='".$param['status']."', last_heartbeat_time=CURRENT_TIMESTAMP(0) WHERE code='".$param['device_code']."';"; } $ret = Db::query($sql); if(is_null($ret)){ throw new Exception("设备编码 ".$param['device_code']." 更新状态失败.", 4001); } }else{ throw new Exception("MES不受理该状态[{$param['status']}]", 4002); } return ''; } /** * 插入device_log接口 */ private function insert_device_log($param,$ret_device) { if(!empty($param['errcode']) && $param['status'] == "TROUBLE" ){ // 如果状态是故障,则插入故障信息 $val = "('{$param['device_code']}','{$param['status']}','{$param['msg']}','{$param['errcode']}',CURRENT_TIMESTAMP(0),{$ret_device['device_category_id']})"; $sql = "INSERT INTO hf_mes_device_log (device_code, status, msg, errcode,create_time,device_category_id) VALUES " . $val; }else{ $val = "('{$param['device_code']}', '{$param['status']}',CURRENT_TIMESTAMP(0),{$ret_device['device_category_id']})"; $sql = "INSERT INTO hf_mes_device_log (device_code, status,create_time,device_category_id) VALUES " . $val; } $ret_insert_device_log = Db::query($sql); if(is_null($ret_insert_device_log)){ throw new Exception("设备编码 ".$param['device_code']." 插入设备状态履历失败.", 4001); } } }