Parcourir la source

光伏告警接口

Administrator il y a 3 ans
Parent
commit
02af6c068f

+ 44 - 0
src/main/java/com/gyee/frame/controller/photovoltaic/PhotovoltaicController.java

@@ -0,0 +1,44 @@
+package com.gyee.frame.controller.photovoltaic;
+
+import com.gyee.frame.common.domain.AjaxResult;
+import com.gyee.frame.service.photovoltaic.PhotovoltaicService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+
+@Controller
+@RequestMapping("//photovoltaic")
+public class PhotovoltaicController {
+    @Resource
+    private PhotovoltaicService photovoltaicService;
+
+    @GetMapping("/query")
+    @ResponseBody
+    @ApiOperation(value = "", notes = "")
+    public AjaxResult query(@RequestParam(value = "pagenum")Integer pageNum,
+                            @RequestParam(value = "pagesize")Integer pageSize,
+                            @RequestParam(value = "stationid", required = false) String stId,
+                            @RequestParam(value = "windturbineid",required = false) String wtId,
+                            @RequestParam(value = "category1",required = false) String category1,
+                            @RequestParam(value = "category2",required = false) String category2,
+                            @RequestParam(value = "rank",required = false) String rank,
+                            @RequestParam(value = "modelid",required = false) String modelId,
+                            @RequestParam(value = "snapid",required = false) Long snapId,
+                            @RequestParam(value = "messagetype",required = false) Integer messageType,
+                            @RequestParam(value = "keyword",required = false) String keyWord,
+                            @RequestParam(value = "starttime", required = false) String starttime,
+                            @RequestParam(value = "endtime", required = false) String endtime)
+
+    {
+        List<Map> ph = photovoltaicService.qy(pageNum,pageSize,stId,wtId,category1,category2,rank,modelId,snapId,messageType,keyWord,starttime,endtime);
+
+        return AjaxResult.successData(200, ph);
+    }
+}

+ 92 - 0
src/main/java/com/gyee/frame/service/photovoltaic/PhotovoltaicService.java

@@ -0,0 +1,92 @@
+package com.gyee.frame.service.photovoltaic;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.gyee.frame.common.domain.AjaxResult;
+import com.gyee.frame.common.feign.RemoteServiceBuilder;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.text.DecimalFormat;
+import java.util.*;
+
+@Service
+public class PhotovoltaicService {
+    @Resource
+    private RemoteServiceBuilder remoteService;
+
+    public List<Map> qy(Integer pageNum,Integer pageSize,String stId,String wtId, String category1,String category2,String rank,
+                        String modelId,Long snapId,Integer messageType,String keyWord,String starttime,String endtime) {
+
+        AjaxResult alarm = remoteService.earlyService().getPage(pageNum,pageSize,stId,wtId,category1,category2,rank,
+                modelId,snapId,messageType,keyWord,starttime,endtime);
+        String jsonStr = JSON.toJSONString(alarm);
+        List<Map>cate = page(jsonStr);
+        return cate;
+    }
+
+    public List<Map> page(String jsonData1) {
+        JSONObject cate = JSON.parseObject(jsonData1);
+        JSONObject data = cate.getJSONObject("data");
+
+        JSONArray recordList = data.getJSONArray("records");
+
+        int a = 0;
+        int b = 0;
+        int c = 0;
+        int d = 0;
+        int e = 0;
+
+        for (int i = 0; i < recordList.size(); i++) {
+            JSONObject record = recordList.getJSONObject(i);
+
+            String ranks = record.getString("rank");
+
+            if (StringUtils.isBlank(ranks)) {
+                continue;
+            }
+            switch (ranks) {
+                case "1":
+                    a = a + 1;
+                    break;
+                case "2":
+                    b = b + 1;
+                    break;
+                case "3":
+                    c = c + 1;
+                    break;
+                case "4":
+                    d = d + 1;
+                    break;
+                case "5":
+                    e = e + 1;
+                    break;
+                default:
+            }
+        }
+        double size = a + b + c + d + e;
+
+        List<Map> conver = new ArrayList<>();
+        DecimalFormat df = new DecimalFormat("0.00%");
+        Map<String, String> maps = new LinkedHashMap<>();
+        maps.put("rank1", df.format(a/size));
+        maps.put("rank2", df.format(b/size));
+        maps.put("rank3", df.format(c/size));
+        maps.put("rank4", df.format(d/size));
+        maps.put("rank5", df.format(e/size));
+
+        Map<String, Double> map = new LinkedHashMap<>();
+        map.put("rank1", (double) a);
+        map.put("rank2", (double) b);
+        map.put("rank3", (double) c);
+        map.put("rank4", (double) d);
+        map.put("rank5", (double) e);
+        map.put("size",size);
+        conver.add(maps);
+        conver.add(map);
+        return conver;
+    }
+}
+