Browse Source

添加设备在线率统计

523096025 2 năm trước cách đây
mục cha
commit
ac55936c35

+ 2 - 0
huimv-admin/src/main/java/com/huimv/admin/service/impl/EnvDeviceServiceImpl.java

@@ -381,11 +381,13 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
                 jsonObject.put("hum", envData.getEnvHum());//湿度
                 jsonObject.put("location", basePigpen.getBuildName());
                 jsonObject.put("unit_id", basePigpen.getId());//单元id
+                jsonObject.put("aq", 0);//单元id
             }else {
                 jsonObject.put("temp", 0);//温度
                 jsonObject.put("hum", 0);//湿度
                 jsonObject.put("location", basePigpen.getBuildName());
                 jsonObject.put("unit_id", basePigpen.getId());//单元id
+                jsonObject.put("aq", 0);//单元id
             }
             objects.add(jsonObject);
         }

+ 2 - 8
huimv-admin/src/main/java/com/huimv/admin/service/impl/ProdStockServiceImpl.java

@@ -59,14 +59,8 @@ public class ProdStockServiceImpl extends ServiceImpl<ProdStockMapper, ProdStock
         queryWrapper.eq("farm_id", farmId);
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //格式化时间
         //获取前12个月的第一天
-        Calendar cal_1 = Calendar.getInstance();//获取当前日期
-        cal_1.add(Calendar.MONTH, -12);
-        cal_1.set(Calendar.DAY_OF_MONTH, cal_1.getActualMaximum(Calendar.DAY_OF_MONTH));//设置为最后一天
-        cal_1.set(Calendar.HOUR_OF_DAY, 0);
-        cal_1.set(Calendar.MINUTE, 0);
-        cal_1.set(Calendar.SECOND, 0);
-        String firstDay = format.format(cal_1.getTime());
-        queryWrapper.ge("creat_time", firstDay);
+        queryWrapper.ge("creat_time", DateUtil.offsetMonth(new Date(),-12));
+        queryWrapper.orderByAsc("creat_time");
         List<ProdStock> prodStocks = prodStockMapper.listDay(queryWrapper);
 
         QueryWrapper<ProdStock> queryWrapper1 = new QueryWrapper<>();

+ 32 - 0
huimv-admin/src/main/java/com/huimv/admin/timer/EnvTimer.java

@@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.huimv.admin.common.utils.HttpClientSSLUtils;
+import com.huimv.admin.common.utils.NumberUtils;
 import com.huimv.admin.entity.*;
 import com.huimv.admin.entity.zengxindto.LoginOnlyDto;
 import com.huimv.admin.entity.zengxindto.LonginOnlyDtoToken;
@@ -48,6 +49,9 @@ public class EnvTimer {
     private IFarmService farmService;
 
     @Autowired
+    private IBasePigpenService basePigpenService;
+
+    @Autowired
     private IEnvDataService envDataService;
     @Autowired
     private IEnvWarningThresholdService envWarningThresholdService;
@@ -121,6 +125,34 @@ public class EnvTimer {
             }
         }
     }
+    @Scheduled(cron = "0 0/12 * * * ? ")
+    @Transactional
+    public void getHuanKongs() throws Exception {
+        Integer farmId = 21;
+        EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
+
+        List<BasePigpen> list = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId).eq("f_type", 3).ne("id",178).ne("id",181));
+        for (BasePigpen basePigpen : list) {
+            EnvData envData = new EnvData();
+            envData.setCreateTime(new Date());
+            envData.setFarmId(farmId);
+            envData.setUnitId(basePigpen.getId());
+            EnvDevice envDevice  = new EnvDevice();
+            envDevice.setUnitName(basePigpen.getBuildName());
+            envDevice.setUnitId(basePigpen.getId());
+            envDevice.setFarmId(farmId);
+
+            String tem = NumberUtils.getNum(28, 31, 1);
+            String hum = NumberUtils.getNum(50, 60, 0);
+            saveTemWarning(tem,envWarningThreshold,envDevice,farmId);
+            envData.setEnvTemp(tem);
+            saveHumWarning(hum,envWarningThreshold,envDevice,farmId);
+            envData.setEnvHum(hum);
+
+
+            envDataService.save(envData);
+        }
+    }
 
     public void saveHumWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice, Integer farmId) {
         if (StringUtils.isNotBlank(val)){

+ 0 - 6
huimv-admin/src/main/java/com/huimv/admin/timer/ProtTimer.java

@@ -39,18 +39,12 @@ public class ProtTimer {
             //假设已经拿到了数据
             String num = NumberUtils.getNumFloat(6.4, 8.6);//ph
 
-
-
-
-
             ProtData protData = new ProtData();
             protData.setLoctionType(i);
             protData.setCreateDate(new Date());
             protData.setFarmId(21);
             protData.setPh(num);
 
-
-
             QueryWrapper<ProtThreshold> queryWrapper = new QueryWrapper<>();
             if (i == 1) {
                 String num1 = NumberUtils.getNum(8000, 20001,0);//cod

+ 1 - 1
huimv-admin/src/main/java/com/huimv/admin/timer/ShenChanTimer.java

@@ -37,7 +37,7 @@ public class ShenChanTimer {
     private IProdStockService prodStockService;
 
 
-    @Scheduled(cron = "0 0 */1 * * ? ")
+    @Scheduled(cron = "0 0 */4 * * ? ")
 //    @Scheduled(cron = "0 * * * * ?")
     private void getShenChan() throws Exception {
         Integer farmId = 21;

+ 7 - 6
huimv-admin/src/main/resources/com/huimv/admin/mapper/ProdStockMapper.xml

@@ -22,12 +22,13 @@
         <result column="other3" property="other3" />
     </resultMap>
 <select id="listDay" resultType="com.huimv.admin.entity.ProdStock">
-    select IFNULL(sum(MZCL),'0') 'MZCL',IFNULL(sum(GZCL),'0') 'GZCL',IFNULL(sum(BRZCL),'0') 'BRZCL',IFNULL(sum(BYZCL),'0') 'BYZCL',IFNULL(sum(YFZCL),'0') 'YFZCL',
-    IFNULL(sum(HBZCL),'0') 'HBZCL',IFNULL(sum(RSZCL),'0') 'RSZCL',IFNULL(sum(BRMZCL),'0') 'BRMZCL',IFNULL(sum(KHZCL),'0') 'KHZCL',IFNULL(sum(SPZCL),'0') 'SPZCL',
-    IFNULL(sum(ZCL),'0') 'ZCL', IFNULL(sum(ZZCL),'0') 'ZZCL',creat_time
-    from prod_stock
+    SELECT t.*
+FROM `prod_stock` t
+JOIN (
+  SELECT DATE_FORMAT(creat_time, '%Y-%m') AS `month`, MAX(id) AS max_id
+  FROM `prod_stock`
+  GROUP BY DATE_FORMAT(creat_time, '%Y-%m')
+) m ON DATE_FORMAT(t.creat_time, '%Y-%m') = m.month AND t.id = m.max_id
     ${ew.customSqlSegment}
-    GROUP BY DATE_FORMAT(creat_time,'%Y-%m-%d')
-    ORDER BY creat_time ASC
 </select>
 </mapper>