|
|
@@ -0,0 +1,73 @@
|
|
|
+package com.yunfei.adapter.accept;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.yunfei.adapter.http.uniagro.UniagroHttp;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Function(name = "uniagro")
|
|
|
+public class UniagroFunction {
|
|
|
+ @Resource
|
|
|
+ private UniagroHttp uniagroHttp;
|
|
|
+ @Function
|
|
|
+ public void buttonCommand(String msg) {
|
|
|
+ JSONObject obj = JSON.parseObject(msg);
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
+ JSONArray inputs = obj.getJSONArray("inputs");
|
|
|
+ if (obj.getString("functionId").equals("buttonCommand")) {
|
|
|
+ params.put("type", "Button");
|
|
|
+ for (int i = 0; i < inputs.size(); i++) {
|
|
|
+ if (inputs.getJSONObject(i).get("name").equals("commandName")) {
|
|
|
+ JSONObject parameter = new JSONObject();
|
|
|
+ parameter.put("commandName", inputs.getJSONObject(i).get("value"));
|
|
|
+ params.put("parameter", parameter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String write = uniagroHttp.write(obj.getString("deviceId"), params);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Function
|
|
|
+ public void switchCommand(String msg){
|
|
|
+ JSONObject obj = JSON.parseObject(msg);
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
+ JSONArray inputs = obj.getJSONArray("inputs");
|
|
|
+ params.put("type", "Switch");
|
|
|
+ JSONObject parameter = new JSONObject();
|
|
|
+ for (int i = 0; i < inputs.size(); i++) {
|
|
|
+ if (inputs.getJSONObject(i).getString("name").equals("commandName")) {
|
|
|
+ parameter.put("commandName", inputs.getJSONObject(i).get("value"));
|
|
|
+ }
|
|
|
+ if (inputs.getJSONObject(i).getString("name").equals("value")) {
|
|
|
+ parameter.put("state", inputs.getJSONObject(i).get("value"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ params.put("parameter", parameter);
|
|
|
+ String write = uniagroHttp.write(obj.getString("deviceId"), params);
|
|
|
+ System.err.println(write);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Function
|
|
|
+ public void SetValue(String msg){
|
|
|
+ JSONObject obj = JSON.parseObject(msg);
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
+ JSONArray inputs = obj.getJSONArray("inputs");
|
|
|
+ params.put("type", "SetValue");
|
|
|
+ JSONObject parameter = new JSONObject();
|
|
|
+ for (int i = 0; i < inputs.size(); i++) {
|
|
|
+ if (inputs.getJSONObject(i).getString("name").equals("commandName")) {
|
|
|
+ parameter.put("commandName", inputs.getJSONObject(i).get("value"));
|
|
|
+ }
|
|
|
+ if (inputs.getJSONObject(i).getString("name").equals("value")) {
|
|
|
+ parameter.put("state", inputs.getJSONObject(i).get("value"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ params.put("parameter", parameter);
|
|
|
+ String write = uniagroHttp.write(obj.getString("deviceId"), params);
|
|
|
+ }
|
|
|
+}
|