Browse Source

环保定时器模拟数据

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

+ 6 - 0
huimv-admin/src/main/java/com/huimv/admin/controller/ProdSaleController.java

@@ -40,4 +40,10 @@ public class ProdSaleController {
     public Result list(HttpServletRequest httpServletRequest, @RequestBody ProdSale prodSale) {
         return prodSaleService.add(httpServletRequest,prodSale);
     }
+
+
+    @RequestMapping("/listScreen")
+    public Result listScreen(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
+        return prodSaleService.listScreen(httpServletRequest,paramsMap);
+    }
 }

+ 9 - 0
huimv-admin/src/main/java/com/huimv/admin/mapper/ProdSaleMapper.java

@@ -1,7 +1,13 @@
 package com.huimv.admin.mapper;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.huimv.admin.entity.ProdSale;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
 
 /**
  * <p>
@@ -11,6 +17,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author author
  * @since 2023-02-22
  */
+@Repository
 public interface ProdSaleMapper extends BaseMapper<ProdSale> {
+    List<ProdSale> listMonth(@Param(Constants.WRAPPER)QueryWrapper<ProdSale> queryWrapper);
 
+    List<ProdSale> listYear(@Param(Constants.WRAPPER)QueryWrapper<ProdSale> queryWrapper);
 }

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

@@ -19,4 +19,6 @@ public interface IProdSaleService extends IService<ProdSale> {
     Result list(HttpServletRequest httpServletRequest, Map<String,String> paramsMap);
 
     Result add(HttpServletRequest httpServletRequest,ProdSale prodSale);
+
+    Result listScreen(HttpServletRequest httpServletRequest, Map<String,String> paramsMap);
 }

+ 20 - 0
huimv-admin/src/main/java/com/huimv/admin/service/impl/ProdSaleServiceImpl.java

@@ -131,4 +131,24 @@ public class ProdSaleServiceImpl extends ServiceImpl<ProdSaleMapper, ProdSale> i
         saleMapper.insert(prodSale);
         return new Result(ResultCode.SUCCESS,"添加成功");
     }
+
+    @Override
+    public Result listScreen(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
+        String farmId = paramsMap.get("farmId");
+        String type = paramsMap.get("type");
+        QueryWrapper<ProdSale> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("farm_id", farmId);
+        if (type == null || type == "") {
+            type = "1";
+        }
+
+        if ("1".equals(type)) {
+            List<ProdSale> prodSales = saleMapper.listMonth(queryWrapper);
+            return new Result(ResultCode.SUCCESS,prodSales);
+        } else {
+            List<ProdSale> prodSales = saleMapper.listYear(queryWrapper);
+            return new Result(ResultCode.SUCCESS,prodSales);
+        }
+
+    }
 }

+ 1 - 1
huimv-admin/src/main/java/com/huimv/admin/service/impl/ProtWarningInfoServiceImpl.java

@@ -41,7 +41,7 @@ public class ProtWarningInfoServiceImpl extends ServiceImpl<ProtWarningInfoMappe
             pageNo = "1";
         }
         QueryWrapper<ProtWarningInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("farm_id", farmId);
+        queryWrapper.eq("farm_id", farmId).orderByDesc("date");
         Page<ProtWarningInfo> page = new Page(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
         return new Result(ResultCode.SUCCESS,protWarningInfoMapper.selectPage(page,queryWrapper));
     }

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

@@ -0,0 +1,183 @@
+package com.huimv.admin.timer;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.common.utils.NumberUtils;
+import com.huimv.admin.entity.ProtData;
+import com.huimv.admin.entity.ProtThreshold;
+import com.huimv.admin.entity.ProtWarningInfo;
+import com.huimv.admin.mapper.ProtDataMapper;
+import com.huimv.admin.mapper.ProtThresholdMapper;
+import com.huimv.admin.mapper.ProtWarningInfoMapper;
+import com.huimv.admin.service.IProtDataService;
+import com.huimv.admin.service.IProtThresholdService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.text.NumberFormat;
+import java.util.Date;
+
+@Configuration
+@EnableScheduling
+public class ProtTimer {
+
+    @Autowired
+    private ProtThresholdMapper protThresholdMapper;
+    @Autowired
+    private ProtDataMapper protDataMapper;
+    @Autowired
+    private ProtWarningInfoMapper warningInfoMapper;
+
+    //    环保数据
+    @Scheduled(cron = "0 * * * * ? ")
+    private void getShenChan() throws Exception {
+
+        //假设已经拿到了数据
+        String num = NumberUtils.getNum(1, 14, 1);//ph
+        String num1 = NumberUtils.getNum(30, 60, 1);//cod
+        String num2 = NumberUtils.getNum(15, 35, 1);//nh3n
+        String num3 = NumberUtils.getNum(65, 85, 1);//tp
+        String num4 = NumberUtils.getNum(65, 85, 1);//tn
+        String num5 = NumberUtils.getNum(90, 210, 0);//flow
+        String num6 = NumberUtils.getNum(1, 3, 0);//loc_type
+
+        ProtWarningInfo protWarningInfo = new ProtWarningInfo();
+
+        ProtData protData = new ProtData();
+        protData.setLoctionType(Integer.parseInt(num6));
+        protData.setCreateDate(new Date());
+        protData.setFarmId(21);
+        protData.setCod(num1);
+        protData.setPh(num);
+        protData.setNh3n(num2);
+        protData.setTp(num3);
+        protData.setTn(num4);
+        protData.setFlow(num5);
+        protDataMapper.insert(protData);
+
+        QueryWrapper<ProtThreshold> queryWrapper = new QueryWrapper<>();
+        if ("1".equals(num6)) {
+            queryWrapper.eq("farm_id", 21).eq("prot_type", 1);
+            ProtThreshold protThreshold = protThresholdMapper.selectOne(queryWrapper);//进污口
+            if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh2())) {
+                protWarningInfo.setWarningContent("进污口ph值为" + num + "达到红色预警");
+            } else if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh1())) {
+                protWarningInfo.setWarningContent("进污口ph值为" + num + "达到橙色预警");
+            }
+            if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod2())) {
+                protWarningInfo.setWarningContent("进污口cod值为" + num1 + "达到红色预警");
+            } else if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod1())) {
+                protWarningInfo.setWarningContent("进污口cod值为" + num1 + "达到橙色预警");
+            }
+            if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n2())) {
+                protWarningInfo.setWarningContent("进污口NH3N值为" + num2 + "达到红色预警");
+            } else if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n1())) {
+                protWarningInfo.setWarningContent("进污口NH3N值为" + num2 + "达到橙色预警");
+            }
+            if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp2())) {
+                protWarningInfo.setWarningContent("进污口TP值为" + num3 + "达到红色预警");
+            } else if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp1())) {
+                protWarningInfo.setWarningContent("进污口TP值为" + num3 + "达到橙色预警");
+            }
+            if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn2())) {
+                protWarningInfo.setWarningContent("进污口TN值为" + num4 + "达到红色预警");
+            } else if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn1())) {
+                protWarningInfo.setWarningContent("进污口TN值为" + num4+ "达到橙色预警");
+            }
+            if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow2())) {
+                protWarningInfo.setWarningContent("进污口累计流量值为" + num5 + "达到红色预警");
+            } else if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow1())) {
+                protWarningInfo.setWarningContent("进污口累计流量值为" + num5 + "达到橙色预警");
+            }
+            protWarningInfo.setFarmId(21);
+            protWarningInfo.setWarningType(Integer.parseInt(num6));
+            protWarningInfo.setDate(new Date());
+            protWarningInfo.setUserIds("1,2");
+            protWarningInfo.setDeviceId(Integer.parseInt(num6));
+            protWarningInfo.setBuildLocation("进污口");
+            warningInfoMapper.insert(protWarningInfo);
+        } else if ("2".equals(num6)) {
+            queryWrapper.eq("farm_id", 21).eq("prot_type", 2);
+            ProtThreshold protThreshold = protThresholdMapper.selectOne(queryWrapper);//污口
+            if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh2())) {
+                protWarningInfo.setWarningContent("处理口ph值为" + num + "达到红色预警");
+            } else if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh1())) {
+                protWarningInfo.setWarningContent("处理口ph值为" + num + "达到橙色预警");
+            }
+            if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod2())) {
+                protWarningInfo.setWarningContent("处理口cod值为" + num1 + "达到红色预警");
+            } else if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod1())) {
+                protWarningInfo.setWarningContent("处理口cod值为" + num1 + "达到橙色预警");
+            }
+            if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n2())) {
+                protWarningInfo.setWarningContent("处理口NH3N值为" + num2 + "达到红色预警");
+            } else if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n1())) {
+                protWarningInfo.setWarningContent("处理口NH3N值为" + num2 + "达到橙色预警");
+            }
+            if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp2())) {
+                protWarningInfo.setWarningContent("处理口TP值为" + num3 + "达到红色预警");
+            } else if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp1())) {
+                protWarningInfo.setWarningContent("处理口TP值为" + num3 + "达到橙色预警");
+            }
+            if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn2())) {
+                protWarningInfo.setWarningContent("处理口TN值为" + num4 + "达到红色预警");
+            } else if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn1())) {
+                protWarningInfo.setWarningContent("处理口TN值为" + num4+ "达到橙色预警");
+            }
+            if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow2())) {
+                protWarningInfo.setWarningContent("处理口累计流量值为" + num5 + "达到红色预警");
+            } else if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow1())) {
+                protWarningInfo.setWarningContent("处理口累计流量值为" + num5 + "达到橙色预警");
+            }
+            protWarningInfo.setFarmId(21);
+            protWarningInfo.setWarningType(Integer.parseInt(num6));
+            protWarningInfo.setDate(new Date());
+            protWarningInfo.setUserIds("1,2");
+            protWarningInfo.setDeviceId(Integer.parseInt(num6));
+            protWarningInfo.setBuildLocation("处理口");
+            warningInfoMapper.insert(protWarningInfo);
+        } else if ("3".equals(num6)) {
+            queryWrapper.eq("farm_id", 21).eq("prot_type", 3);
+            ProtThreshold protThreshold = protThresholdMapper.selectOne(queryWrapper);//进污口
+            if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh2())) {
+                protWarningInfo.setWarningContent("排污口ph值为" + num + "达到红色预警");
+            } else if (Double.parseDouble(num) > Double.parseDouble(protThreshold.getPh1())) {
+                protWarningInfo.setWarningContent("排污口ph值为" + num + "达到橙色预警");
+            }
+            if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod2())) {
+                protWarningInfo.setWarningContent("排污口cod值为" + num1 + "达到红色预警");
+            } else if (Double.parseDouble(num1) > Double.parseDouble(protThreshold.getCod1())) {
+                protWarningInfo.setWarningContent("排污口cod值为" + num1 + "达到橙色预警");
+            }
+            if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n2())) {
+                protWarningInfo.setWarningContent("排污口NH3N值为" + num2 + "达到红色预警");
+            } else if (Double.parseDouble(num2) > Double.parseDouble(protThreshold.getNh3n1())) {
+                protWarningInfo.setWarningContent("排污口NH3N值为" + num2 + "达到橙色预警");
+            }
+            if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp2())) {
+                protWarningInfo.setWarningContent("排污口TP值为" + num3 + "达到红色预警");
+            } else if (Double.parseDouble(num3) > Double.parseDouble(protThreshold.getTp1())) {
+                protWarningInfo.setWarningContent("排污口TP值为" + num3 + "达到橙色预警");
+            }
+            if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn2())) {
+                protWarningInfo.setWarningContent("排污口TN值为" + num4 + "达到红色预警");
+            } else if (Double.parseDouble(num4) > Double.parseDouble(protThreshold.getTn1())) {
+                protWarningInfo.setWarningContent("排污口TN值为" + num4+ "达到橙色预警");
+            }
+            if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow2())) {
+                protWarningInfo.setWarningContent("排污口累计流量值为" + num5 + "达到红色预警");
+            } else if (Double.parseDouble(num5) > Double.parseDouble(protThreshold.getFlow1())) {
+                protWarningInfo.setWarningContent("排污口累计流量值为" + num5 + "达到橙色预警");
+            }
+            protWarningInfo.setFarmId(21);
+            protWarningInfo.setWarningType(Integer.parseInt(num6));
+            protWarningInfo.setDate(new Date());
+            protWarningInfo.setUserIds("1,2");
+            protWarningInfo.setDeviceId(Integer.parseInt(num6));
+            protWarningInfo.setBuildLocation("排污口");
+            warningInfoMapper.insert(protWarningInfo);
+        }
+    }
+}

+ 23 - 8
huimv-admin/src/main/resources/com/huimv/admin/mapper/ProdSaleMapper.xml

@@ -4,14 +4,29 @@
 
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.huimv.admin.entity.ProdSale">
-        <id column="id" property="id" />
-        <result column="sale_money" property="saleMoney" />
-        <result column="sale_quantity" property="saleQuantity" />
-        <result column="creat_time" property="creatTime" />
-        <result column="farm_id" property="farmId" />
-        <result column="other1" property="other1" />
-        <result column="other2" property="other2" />
-        <result column="other3" property="other3" />
+        <id column="id" property="id"/>
+        <result column="sale_money" property="saleMoney"/>
+        <result column="sale_quantity" property="saleQuantity"/>
+        <result column="creat_time" property="creatTime"/>
+        <result column="farm_id" property="farmId"/>
+        <result column="other1" property="other1"/>
+        <result column="other2" property="other2"/>
+        <result column="other3" property="other3"/>
     </resultMap>
 
+    <select id="listMonth" resultType="com.huimv.admin.entity.ProdSale">
+
+select IFNULL(SUM(sale_quantity),'0') 'saleQuantity',creat_time FROM prod_sale
+     ${ew.customSqlSegment}
+GROUP BY DATE_FORMAT(creat_time,'%Y-%m')
+ORDER BY creat_time ASC
+    </select>
+
+    <select id="listYear" resultType="com.huimv.admin.entity.ProdSale">
+
+select IFNULL(SUM(sale_quantity),'0') 'saleQuantity',creat_time FROM prod_sale
+     ${ew.customSqlSegment}
+GROUP BY DATE_FORMAT(creat_time,'%Y')
+ORDER BY creat_time ASC
+    </select>
 </mapper>