Browse Source

盘头厚度接口和叫料数

wukai 1 year ago
parent
commit
97e6fb16d2

+ 47 - 9
ruoyi-admin/src/main/java/com/ruoyi/biz/controller/ApiController.java

@@ -1,10 +1,7 @@
 package com.ruoyi.biz.controller;
 
 import com.ruoyi.biz.domain.*;
-import com.ruoyi.biz.service.ITwinCalc2hrService;
-import com.ruoyi.biz.service.ITwinCalcDayService;
-import com.ruoyi.biz.service.ITwinDeviceService;
-import com.ruoyi.biz.service.ITwinRecordAlarmsService;
+import com.ruoyi.biz.service.*;
 import com.ruoyi.biz.service.impl.AsyncServiceImpl;
 import com.ruoyi.biz.service.impl.IotTokenServiceImpl;
 import com.ruoyi.biz.tools.Tools;
@@ -12,6 +9,7 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.service.ISysConfigService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -30,6 +28,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.net.URLEncoder;
 import java.text.ParseException;
 import java.time.LocalDate;
@@ -62,6 +61,10 @@ public class ApiController extends BaseController {
     private IotTokenServiceImpl iotTokenService;
     @Resource
     private AsyncServiceImpl asyncService;
+    @Resource
+    private ITwinPanHeadInfoService panHeadInfoService;
+    @Resource
+    private ISysConfigService configService;
     @Value("${excel.template}")
     private String excelTemplate;
 
@@ -109,9 +112,15 @@ public class ApiController extends BaseController {
     public R<IndexData> alarm() {
         IndexData indexData = new IndexData();
         List<IndexAlarm> alarmList = new ArrayList<>();
-        int stop1 = 0, stop2 = 0, stop6 = 0;
+        List<IndexPan> panList = new ArrayList<>();
+        int stop1 = 0, stop2 = 0, stop6 = 0, stop8 = 0;
         iotTokenService.getToken();
         List<TwinDevice> list = deviceService.selectTwinDeviceList(new TwinDevice());
+        Map<String, Long> panMap = new HashMap<>(16);
+        panHeadInfoService.selectTwinPanHeadInfoList(new TwinPanHeadInfo()).forEach(pan -> {
+            String key = pan.getDeviceId() + "_" + pan.getPhNum();
+            panMap.put(key, pan.getPhMax());
+        });
         List<Future<Map<String, Object>>> futureList = new ArrayList<>();
         for (int i = 0; i < list.size(); i++) {
             TwinDevice twinDevice = list.get(i);
@@ -126,7 +135,12 @@ public class ApiController extends BaseController {
                     //可能会出现接口返回无数据的情况
                     continue;
                 }
-
+                int data4 = (int) map.get("Capacity_data_4");
+                if (data4 == 0) {
+                    //Capacity_data_4,如果设定落布米数为0,则证明当前数据无效
+                    //不能跟上面判断合并,不然报空指针
+                    continue;
+                }
                 for (int i = 1; i <= 26; i++) {
                     boolean flag = (boolean) map.get("Alarm_unit_" + i);
                     if (flag) {
@@ -160,6 +174,30 @@ public class ApiController extends BaseController {
                         break;
                     default:
                 }
+
+                int[] curr = new int[5];
+                int[] max = new int[5];
+                float[] panPercent = new float[5];
+                for (int i = 0; i < curr.length; i++) {
+                    int pos = 15 + i;
+                    curr[i] = (int) map.get("Capacity_data_" + pos);
+                    String key = device.getId() + "_" + (i + 1);
+                    max[i] = 15000;
+                    if (panMap.get(key) != null) {
+                        max[i] = Math.toIntExact(panMap.get(key));
+                    }
+
+                    panPercent[i] = BigDecimal.valueOf(curr[i] * 100).divide(BigDecimal.valueOf(max[i]), 2, RoundingMode.HALF_UP).floatValue();
+                    if (panPercent[i] < 20) {
+                        stop8++;
+                    }
+                }
+
+                IndexPan pan = new IndexPan();
+                pan.setCode(device.getDeviceCode());
+                pan.setName(device.getDeviceName());
+                pan.setPanPercent(panPercent);
+                panList.add(pan);
             }
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
@@ -167,14 +205,14 @@ public class ApiController extends BaseController {
             throw new RuntimeException(e);
         }
         indexData.setAlarm(alarmList);
-
+        indexData.setPan(panList);
         IndexDevice device = new IndexDevice();
-        device.setTotal(140);
+        device.setTotal(Integer.parseInt(configService.selectConfigByKey("sys.device.total")));
         device.setOnline(list.size());
         device.setStop1(stop1);
         device.setStop2(stop2);
         device.setStop6(stop6);
-        device.setStop8(new Random().nextInt(5));
+        device.setStop8(stop8);
         device.setAlarm(alarmList.size());
         indexData.setDevice(device);
         return R.ok(indexData);

+ 2 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/IndexData.java

@@ -23,4 +23,6 @@ public class IndexData {
     private List<IndexAlarm> alarm;
     @ApiModelProperty("周曲线数据")
     private List<WeekData> weekData;
+    @ApiModelProperty("盘头数据")
+    private List<IndexPan> pan;
 }

+ 22 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/IndexPan.java

@@ -0,0 +1,22 @@
+package com.ruoyi.biz.domain;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 盘头数据
+ *
+ * @author wukai
+ * @date 2024/5/8 15:50
+ */
+@ApiModel(value = "IndexPan", description = "首页-盘头数据")
+@Data
+public class IndexPan {
+    @ApiModelProperty("设备名称")
+    private String name;
+    @ApiModelProperty("设备编号")
+    private String code;
+    @ApiModelProperty("盘头剩余百分比 0-4 代表1-5盘头")
+    private float[] panPercent;
+}

+ 2 - 17
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/AsyncServiceImpl.java

@@ -7,6 +7,7 @@ import com.ruoyi.biz.domain.TwinDevice;
 import com.ruoyi.biz.domain.TwinPanHeadInfo;
 import com.ruoyi.biz.domain.TwinRecordAlarms;
 import com.ruoyi.biz.service.IIotService;
+import com.ruoyi.biz.tools.Tools;
 import javafx.util.Pair;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Async;
@@ -40,25 +41,9 @@ public class AsyncServiceImpl {
         JSONObject data = jsonObject.getJSONObject("data");
         JSONArray values = data.getJSONArray("values");
 
-        Map<String, Object> dataMap = new HashMap<>(16);
+        Map<String, Object> dataMap = Tools.json2Map(values, table);
         dataMap.put("device", twinDevice);
         dataMap.put("total", values.size());
-        for (int i = 0; i < values.size(); i++) {
-            JSONArray d = values.getJSONArray(i);
-            String key = d.getStr(0).replace(table + ".", "");
-            switch (d.getStr(2)) {
-                case "FLOAT":
-                    dataMap.put(key, d.getFloat(1));
-                    break;
-                case "BOOLEAN":
-                    dataMap.put(key, d.getBool(1));
-                    break;
-                case "INT32":
-                case "INT64":
-                    dataMap.put(key, d.getInt(1));
-                    break;
-            }
-        }
         return new AsyncResult<>(dataMap);
     }
 

+ 1 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/tools/Tools.java

@@ -45,6 +45,7 @@ public class Tools {
 
     public static Map<String, Object> json2Map(JSONArray values, String table) {
         Map<String, Object> dataMap = new HashMap<>(16);
+
         for (int i = 0; i < values.size(); i++) {
             JSONArray d = values.getJSONArray(i);
             String key = d.getStr(0).replace(table + ".", "");

+ 36 - 31
ruoyi-admin/src/main/resources/mapper/biz/TwinPanHeadInfoMapper.xml

@@ -1,46 +1,49 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.biz.mapper.TwinPanHeadInfoMapper">
-    
+
     <resultMap type="TwinPanHeadInfo" id="TwinPanHeadInfoResult">
-        <result property="infoId"    column="INFO_ID"    />
-        <result property="deviceId"    column="DEVICE_ID"    />
-        <result property="phNum"    column="PH_NUM"    />
-        <result property="phMax"    column="PH_MAX"    />
-        <result property="recordTime"    column="RECORD_TIME"    />
-        <result property="createdBy"    column="CREATED_BY"    />
-        <result property="createdTime"    column="CREATED_TIME"    />
-        <result property="updatedBy"    column="UPDATED_BY"    />
-        <result property="updatedTime"    column="UPDATED_TIME"    />
-        <result property="remark"    column="REMARK"    />
+        <result property="infoId" column="INFO_ID"/>
+        <result property="deviceId" column="DEVICE_ID"/>
+        <result property="phNum" column="PH_NUM"/>
+        <result property="phMax" column="PH_MAX"/>
+        <result property="recordTime" column="RECORD_TIME"/>
+        <result property="createdBy" column="CREATED_BY"/>
+        <result property="createdTime" column="CREATED_TIME"/>
+        <result property="updatedBy" column="UPDATED_BY"/>
+        <result property="updatedTime" column="UPDATED_TIME"/>
+        <result property="remark" column="REMARK"/>
     </resultMap>
 
     <sql id="selectTwinPanHeadInfoVo">
-        select INFO_ID, DEVICE_ID, PH_NUM, PH_MAX, RECORD_TIME, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME, REMARK from twin_pan_head_info
+        SELECT INFO_ID, DEVICE_ID, PH_NUM, PH_MAX, RECORD_TIME, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME, REMARK
+        FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY DEVICE_ID,PH_NUM ORDER BY RECORD_TIME DESC) AS RN
+              FROM TWIN_PAN_HEAD_INFO) T
+        WHERE RN = 1 ORDER BY RECORD_TIME DESC
     </sql>
 
     <select id="selectTwinPanHeadInfoList" parameterType="TwinPanHeadInfo" resultMap="TwinPanHeadInfoResult">
         <include refid="selectTwinPanHeadInfoVo"/>
-        <where>  
-            <if test="deviceId != null "> and DEVICE_ID = #{deviceId}</if>
-            <if test="phNum != null "> and PH_NUM = #{phNum}</if>
-            <if test="phMax != null "> and PH_MAX = #{phMax}</if>
-            <if test="recordTime != null "> and RECORD_TIME = #{recordTime}</if>
-            <if test="createdBy != null  and createdBy != ''"> and CREATED_BY = #{createdBy}</if>
-            <if test="createdTime != null "> and CREATED_TIME = #{createdTime}</if>
-            <if test="updatedBy != null  and updatedBy != ''"> and UPDATED_BY = #{updatedBy}</if>
-            <if test="updatedTime != null "> and UPDATED_TIME = #{updatedTime}</if>
-            <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
+        <where>
+            <if test="deviceId != null ">and DEVICE_ID = #{deviceId}</if>
+            <if test="phNum != null ">and PH_NUM = #{phNum}</if>
+            <if test="phMax != null ">and PH_MAX = #{phMax}</if>
+            <if test="recordTime != null ">and RECORD_TIME = #{recordTime}</if>
+            <if test="createdBy != null  and createdBy != ''">and CREATED_BY = #{createdBy}</if>
+            <if test="createdTime != null ">and CREATED_TIME = #{createdTime}</if>
+            <if test="updatedBy != null  and updatedBy != ''">and UPDATED_BY = #{updatedBy}</if>
+            <if test="updatedTime != null ">and UPDATED_TIME = #{updatedTime}</if>
+            <if test="remark != null  and remark != ''">and REMARK = #{remark}</if>
         </where>
     </select>
-    
+
     <select id="selectTwinPanHeadInfoByInfoId" parameterType="Long" resultMap="TwinPanHeadInfoResult">
         <include refid="selectTwinPanHeadInfoVo"/>
         where INFO_ID = #{infoId}
     </select>
-        
+
     <insert id="insertTwinPanHeadInfo" parameterType="TwinPanHeadInfo" useGeneratedKeys="true" keyProperty="infoId">
         insert into twin_pan_head_info
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -53,7 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updatedBy != null">UPDATED_BY,</if>
             <if test="updatedTime != null">UPDATED_TIME,</if>
             <if test="remark != null">REMARK,</if>
-         </trim>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="deviceId != null">#{deviceId},</if>
             <if test="phNum != null">#{phNum},</if>
@@ -64,7 +67,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updatedBy != null">#{updatedBy},</if>
             <if test="updatedTime != null">#{updatedTime},</if>
             <if test="remark != null">#{remark},</if>
-         </trim>
+        </trim>
     </insert>
 
     <update id="updateTwinPanHeadInfo" parameterType="TwinPanHeadInfo">
@@ -84,14 +87,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </update>
 
     <delete id="deleteTwinPanHeadInfoByInfoId" parameterType="Long">
-        delete from twin_pan_head_info where INFO_ID = #{infoId}
+        delete
+        from twin_pan_head_info
+        where INFO_ID = #{infoId}
     </delete>
 
     <delete id="deleteTwinPanHeadInfoByInfoIds" parameterType="String">
-        delete from twin_pan_head_info where INFO_ID in 
+        delete from twin_pan_head_info where INFO_ID in
         <foreach item="infoId" collection="array" open="(" separator="," close=")">
             #{infoId}
         </foreach>
     </delete>
 
-</mapper>
+</mapper>

+ 4 - 4
ruoyi-admin/src/test/java/com/jjt/DataPF.java

@@ -103,13 +103,13 @@ public class DataPF {
     void data() {
 //        taskService.calc("2024-05-15");
 //        taskService.calc("2024-05-21",12);
-//        for (int i = 11; i <= 12; i++) {
-//            taskService.calc("2024-05-26", i);
-//        }
+        for (int i = 1; i <= 11; i++) {
+            taskService.calc("2024-05-29", i);
+        }
 //        for (int i = 23; i <= 27; i++) {
 //            taskService.calc("2024-05-" + i);
 //        }
-        taskService.calc("2024-05-28");
+//        taskService.calc("2024-05-28");
     }
 
     @Test