Ver Fonte

大经编机基本信息,经编详情取数方式修改

wukai há 3 semanas atrás
pai
commit
de8bc03d19

+ 61 - 7
jjt-biz/src/main/java/com/jjt/biz/controller/ApiController.java

@@ -22,13 +22,13 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.ParseException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.util.*;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
 import java.util.stream.Collectors;
 
 /**
@@ -83,13 +83,67 @@ public class ApiController extends BaseController {
         if (info == null) {
             return R.fail("该设备未接入");
         }
-        Future<Map<String, Object>> future = asyncService.currData(info);
+        Map<String, Map<String, Object>> curr = redisCache.getCacheObject(CacheConstants.DEVICE_CURRENT);
         Map<String, Object> result = new HashMap<>(16);
-        try {
-            result.put("data", future.get());
-        } catch (InterruptedException | ExecutionException e) {
-            throw new RuntimeException(e);
+        Map<String, Object> map = curr.get(device);
+        if (map == null) {
+            return R.fail("该设备暂无IOT数据");
         }
+        if (device.startsWith("C_")) {
+            float max1 = (float) map.get("Formula_data_26") == 0f ? 20000f : (float) map.get("Formula_data_26");
+            float max2 = (float) map.get("Formula_data_27") == 0f ? 20000f : (float) map.get("Formula_data_27");
+            float max3 = (float) map.get("Formula_data_28") == 0f ? 20000f : (float) map.get("Formula_data_28");
+            float max4 = (float) map.get("Formula_data_29") == 0f ? 20000f : (float) map.get("Formula_data_29");
+            float max5 = (float) map.get("Formula_data_30") == 0f ? 20000f : (float) map.get("Formula_data_30");
+            int q1 = (int) map.get("Capacity_data_15");
+            int q2 = (int) map.get("Capacity_data_16");
+            int q3 = (int) map.get("Capacity_data_17");
+            int q4 = (int) map.get("Capacity_data_18");
+            int q5 = (int) map.get("Capacity_data_19");
+
+            BigDecimal p1 = new BigDecimal(q1 * 100).divide(BigDecimal.valueOf(max1), 2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal p2 = new BigDecimal(q2 * 100).divide(BigDecimal.valueOf(max2), 2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal p3 = new BigDecimal(q3 * 100).divide(BigDecimal.valueOf(max3), 2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal p4 = new BigDecimal(q4 * 100).divide(BigDecimal.valueOf(max4), 2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal p5 = new BigDecimal(q5 * 100).divide(BigDecimal.valueOf(max5), 2, BigDecimal.ROUND_HALF_UP);
+
+
+            map.put("p1", p1.floatValue() + "%");
+            map.put("p2", p2.floatValue() + "%");
+            map.put("p3", p3.floatValue() + "%");
+            map.put("p4", p4.floatValue() + "%");
+            map.put("p5", p5.floatValue() + "%");
+        } else {
+            int index = 10;
+            int[] max = new int[index];
+            float[] t = new float[index];
+            float[] c = new float[index];
+            int[] q = new int[index];
+
+            for (int i = 0; i < index; i++) {
+                max[i] = (int) map.get("Formula_data_" + (31 + i)) == 0 ? 20000 : (int) map.get("Formula_data_" + (31 + i));
+                t[i] = BigDecimal.valueOf((float) map.get("Capacity_data_" + (71 + i))).setScale(2, RoundingMode.HALF_UP).floatValue();
+                c[i] = BigDecimal.valueOf((float) map.get("Capacity_data_" + (3 + i))).setScale(2, RoundingMode.HALF_UP).floatValue();
+                q[i] = (int) map.get("Capacity_data_" + (15 + i));
+            }
+
+            BigDecimal[] p = new BigDecimal[10];
+            for (int i = 0; i < index; i++) {
+                p[i] = new BigDecimal(q[i] * 100).divide(BigDecimal.valueOf(max[i]), 2, RoundingMode.HALF_UP);
+            }
+
+            for (int i = 0; i < 5; i++) {
+                int j = i + 5;
+                map.put("p" + (i + 1), String.format("A: %.2f%%&nbsp;&nbsp;&nbsp;&nbsp;B: %.2f%%", p[i].floatValue(), p[j].floatValue()));
+                map.put("Capacity_data_" + (5 + i), "A: " + t[i] + "&nbsp;&nbsp;&nbsp;&nbsp;B: " + t[j]);
+                map.put("Capacity_data_" + (10 + i), "A: " + c[i] + "&nbsp;&nbsp;&nbsp;&nbsp;B: " + c[j]);
+                map.put("Capacity_data_" + (15 + i), "A: " + q[i] + "&nbsp;&nbsp;&nbsp;&nbsp;B: " + q[j]);
+            }
+
+
+        }
+
+        result.put("data", map);
         if (week != null) {
             //7点前是属于前一生产天,所以这里直接减7小时即可
             LocalDateTime ldt = LocalDateTime.now().minusHours(7);

+ 4 - 0
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiServiceImpl.java

@@ -173,10 +173,13 @@ public class ApiServiceImpl implements IApiService {
         int stop1 = 0, stop2 = 0, stop6 = 0, stop8 = 0, onlineNum = 0, otherStop = 0, stopPan = 0;
         //停机明细
         List<StopDetailVO> stopList = new ArrayList<>();
+        //所有设备当前数据
+        Map<String, Map<String, Object>> currMap = new HashMap<>(16);
         try {
             for (Future<Map<String, Object>> future : futureList) {
                 Map<String, Object> map = future.get();
                 TwinDevice device = (TwinDevice) map.get("device");
+                currMap.put(device.getDeviceCode(), map);
                 StopDetailVO sdVO = new StopDetailVO();
                 sdVO.setDeviceId(device.getDeviceId());
                 sdVO.setDeviceName(device.getDeviceName());
@@ -358,6 +361,7 @@ public class ApiServiceImpl implements IApiService {
             gramMasses.add(total);
         }
 
+        redisCache.setCacheObject(CacheConstants.DEVICE_CURRENT, currMap);
         redisCache.setCacheObject(CacheConstants.INDEX_ALARM, indexData);
         redisCache.setCacheObject(CacheConstants.INDEX_FORMULA_TOTAL, formulaTotal);
         redisCache.setCacheObject(CacheConstants.INDEX_FORMULA_DETAIL, formulaDetail);

+ 4 - 0
jjt-common/src/main/java/com/jjt/common/constant/CacheConstants.java

@@ -91,6 +91,10 @@ public class CacheConstants {
      */
     public static final String INDEX_ALARM = TWIN + "indexAlarm";
     /**
+     * 设备当前数据缓存
+     */
+    public static final String DEVICE_CURRENT = TWIN + "deviceCurrent";
+    /**
      * 送经量数据
      */
     public static final String INDEX_WARP_RUN_IN = TWIN + "indexWarpRunIn";