From 3b9be77e437edce281d4a4b7e228763e0b89721f Mon Sep 17 00:00:00 2001 From: anlicheng Date: Tue, 20 Jun 2023 18:07:17 +0800 Subject: [PATCH] feedback step --- apps/iot/src/database/scene_feedback_step.erl | 17 +++++++++++++++++ apps/iot/src/iot_host.erl | 9 +++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 apps/iot/src/database/scene_feedback_step.erl diff --git a/apps/iot/src/database/scene_feedback_step.erl b/apps/iot/src/database/scene_feedback_step.erl new file mode 100644 index 0000000..548d551 --- /dev/null +++ b/apps/iot/src/database/scene_feedback_step.erl @@ -0,0 +1,17 @@ +%%%------------------------------------------------------------------- +%%% @author aresei +%%% @copyright (C) 2023, +%%% @doc +%%% +%%% @end +%%% Created : 16. 5月 2023 12:48 +%%%------------------------------------------------------------------- +-module(scene_feedback_step). +-author("aresei"). +-include("iot.hrl"). + +%% API +-export([insert/1]). + +insert(Fields) when is_map(Fields) -> + mysql_client:insert(<<"scene_feedback_step">>, Fields, true). \ No newline at end of file diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index 3c857ae..f2e0d91 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -314,8 +314,13 @@ handle_event(cast, {handle, <>}, session, State handle_event(cast, {handle, <>}, session, State = #state{aes = AES}) -> Info = iot_cipher_aes:decrypt(AES, Info0), case catch jiffy:decode(Info, [return_maps]) of - Data when is_map(Data) -> - lager:warning("[iot_host] feedback_step info: ~p", [Data]); + Data = #{<<"task_id">> := TaskId, <<"code">> := Code} -> + Result = scene_feedback:insert(#{ + <<"task_id">> => TaskId, + <<"code">> => Code, + <<"created_at">> => iot_util:current_time() + }), + lager:warning("[iot_host] feedback_step info: ~p, insert result: ~p", [Data, Result]); Other -> lager:warning("[iot_host] feedback_step error: ~p", [Other]) end,