dongjh пре 1 година
родитељ
комит
36db06c4bb

+ 59 - 1
module-guan/src/main/java/org/jeecg/modules/webaccess/controller/WebAccessController.java

@@ -1,4 +1,62 @@
 package org.jeecg.modules.webaccess.controller;
 
-public class WebAccessController {
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import net.sf.json.JSONObject;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.modules.webaccess.dto.WaLogDTO;
+import org.jeecg.modules.webaccess.service.WebAccessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Api(tags = "webaccess测试")
+@RestController
+@RequestMapping("/datacoll/webaccess")
+@Slf4j
+public class WebAccessController extends JeecgController {
+
+    @Autowired
+    private WebAccessService webAccessService;
+
+    /**
+     * 获取设备参数值(webaccess)
+     */
+    @ApiOperation(value = "获取设备参数值(webaccess)", notes = "获取设备参数值(webaccess)")
+    @GetMapping("/getWATagNameValues")
+    public Result getWATagNameValues(String tagName) {
+        List<WaLogDTO> tags = new ArrayList<>();
+        WaLogDTO tag = new WaLogDTO(tagName);
+        tags.add(tag);
+        JSONObject jsonObject = webAccessService.generateGetObject(tags);
+        // JSONObject rtn = webAccessService.login();
+        String tagValue = webAccessService.getTagNameValues(jsonObject);
+        return Result.OK(tagValue);
+    }
+
+    /**
+     * 设置设备参数值(webaccess)
+     */
+    @ApiOperation(value = "设置设备参数值(webaccess)", notes = "设置设备参数值(webaccess)")
+    @GetMapping("/setWATagNameValues")
+    public Result setTagNameValues(String tagName, Integer tagValue) {
+        List<WaLogDTO> tags = new ArrayList<>();
+        WaLogDTO tag = new WaLogDTO(tagName, new Float(tagValue));
+        tags.add(tag);
+
+        JSONObject jsonObject = webAccessService.generateSetObject(tags);
+        Boolean sendTagValue = null;
+        try {
+            sendTagValue = webAccessService.setTagNameValues(jsonObject, 0);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        return Result.OK(sendTagValue);
+    }
 }

+ 50 - 0
module-guan/src/main/java/org/jeecg/modules/webaccess/dto/WaLogDTO.java

@@ -0,0 +1,50 @@
+package org.jeecg.modules.webaccess.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class WaLogDTO implements Serializable {
+    /** 调节日志ID */
+    private Long logid;
+
+    /** 设备ID */
+    private Long equipmentid;
+
+    /** 设备参数名 */
+    private String tagname;
+
+    /** 参数类型 */
+    private String tagtype;
+
+    /** 日志时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date logtime;
+
+    /** 参数值 */
+    private Float tagvalue;
+
+    /** 日期 */
+    private String day;
+
+    public WaLogDTO(String tagname) {
+        this.tagname = tagname;
+    }
+
+    public WaLogDTO(String tagname, Float tagvalue) {
+        this.tagname = tagname;
+        this.tagvalue = tagvalue;
+    }
+
+    public WaLogDTO(Long logid, Long equipmentid, String tagname, String tagtype, Date logtime, Float tagvalue) {
+        this.logid = logid;
+        this.equipmentid = equipmentid;
+        this.tagname = tagname;
+        this.tagtype = tagtype;
+        this.logtime = logtime;
+        this.tagvalue = tagvalue;
+    }
+}

+ 42 - 41
module-guan/src/main/java/org/jeecg/modules/webaccess/service/WebAccessService.java

@@ -4,6 +4,7 @@ import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.collections.map.HashedMap;
+import org.jeecg.modules.webaccess.dto.WaLogDTO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
@@ -219,45 +220,45 @@ public class WebAccessService {
 
         return result;
     }
-//
-//    /**
-//     * 组成获取参数值的信息
-//     * @param tags 参数名
-//     * @return
-//     */
-//    public JSONObject generateGetObject(List<SysWaLog> tags) {
-//        JSONArray list = new JSONArray();
-//        JSONObject rtn = new JSONObject();
-//
-//        for (SysWaLog tag : tags) {
-//            JSONObject sub = new JSONObject();
-//            sub.put("Name", tag.getTagname());
-//            list.add(sub);
-//        }
-//        rtn.put("Tags", list);
-//
-//        return rtn;
-//    }
-//
-//    /**
-//     * 组成设置参数值的信息
-//     * @param tags 参数列表
-//     * @return
-//     */
-//    public JSONObject generateSetObject(List<SysWaLog> tags) {
-//        JSONArray list = new JSONArray();
-//        JSONObject rtn = new JSONObject();
-//
-//        if (tags != null && tags.size() > 0) {
-//            for (SysWaLog tag : tags) {
-//                JSONObject sub = new JSONObject();
-//                sub.put("Name", tag.getTagname());
-//                sub.put("Value", tag.getTagvalue());
-//                list.add(sub);
-//            }
-//        }
-//        rtn.put("Tags", list);
-//
-//        return rtn;
-//    }
+
+    /**
+     * 组成获取参数值的信息
+     * @param tags 参数名
+     * @return
+     */
+    public JSONObject generateGetObject(List<WaLogDTO> tags) {
+        JSONArray list = new JSONArray();
+        JSONObject rtn = new JSONObject();
+
+        for (WaLogDTO tag : tags) {
+            JSONObject sub = new JSONObject();
+            sub.put("Name", tag.getTagname());
+            list.add(sub);
+        }
+        rtn.put("Tags", list);
+
+        return rtn;
+    }
+
+    /**
+     * 组成设置参数值的信息
+     * @param tags 参数列表
+     * @return
+     */
+    public JSONObject generateSetObject(List<WaLogDTO> tags) {
+        JSONArray list = new JSONArray();
+        JSONObject rtn = new JSONObject();
+
+        if (tags != null && tags.size() > 0) {
+            for (WaLogDTO tag : tags) {
+                JSONObject sub = new JSONObject();
+                sub.put("Name", tag.getTagname());
+                sub.put("Value", tag.getTagvalue());
+                list.add(sub);
+            }
+        }
+        rtn.put("Tags", list);
+
+        return rtn;
+    }
 }