Parcourir la source

修改环保接收数据

523096025 il y a 2 semaines
Parent
commit
792acd3b9d
22 fichiers modifiés avec 233 ajouts et 31 suppressions
  1. 1 1
      app-admin/src/main/java/com/ruoyi/RuoYiApplication.java
  2. 2 7
      app-common/src/main/java/com/ruoyi/common/server/EnvInputServer.java
  3. 6 8
      app-common/src/main/java/com/ruoyi/common/server/EnvInputServerHandler.java
  4. 1 1
      app-admin/src/main/java/com/ruoyi/web/v2/v1/controller/JsDistributionController.java
  5. 69 0
      app-admin/src/main/java/com/ruoyi/web/v2/v1/controller/ProtSjController.java
  6. 69 0
      app-admin/src/main/java/com/ruoyi/web/v2/v1/entity/ProtSj.java
  7. 16 0
      app-admin/src/main/java/com/ruoyi/web/v2/v1/mapper/ProtSjMapper.java
  8. 1 1
      app-admin/src/main/java/com/ruoyi/web/v2/v1/service/IJsDistributionService.java
  9. 16 0
      app-admin/src/main/java/com/ruoyi/web/v2/v1/service/IProtSjService.java
  10. 5 2
      app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/JsDeviceMaintenanceServiceImpl.java
  11. 3 3
      app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/JsDistributionServiceImpl.java
  12. 5 2
      app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/JsInstrumentMaintenanceServiceImpl.java
  13. 1 0
      app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/JsPatrolServiceImpl.java
  14. 20 0
      app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/ProtSjServiceImpl.java
  15. 3 1
      app-admin/src/main/resources/application.yml
  16. 6 0
      app-admin/src/main/resources/mapper/ProtSjMapper.xml
  17. 1 1
      app-system/src/main/java/com/ruoyi/app/mapper/EntranceBatchMapper.java
  18. 1 1
      app-system/src/main/java/com/ruoyi/app/mapper/SlaughterBatchMapper.java
  19. 1 0
      app-system/src/main/java/com/ruoyi/app/service/impl/EntranceBatchServiceImpl.java
  20. 1 1
      app-system/src/main/java/com/ruoyi/app/service/impl/ProductTraceServiceImpl.java
  21. 3 2
      app-system/src/main/resources/mapper/app/EntranceBatchMapper.xml
  22. 2 0
      app-system/src/main/resources/mapper/app/SlaughterBatchMapper.xml

+ 1 - 1
app-admin/src/main/java/com/ruoyi/RuoYiApplication.java

@@ -1,6 +1,6 @@
 package com.ruoyi;
 
-import com.ruoyi.common.server.EnvInputServer;
+import com.ruoyi.web.v2.server.EnvInputServer;
 //import com.ruoyi.web.core.nfid.NFIDServer;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;

+ 2 - 7
app-common/src/main/java/com/ruoyi/common/server/EnvInputServer.java

@@ -1,16 +1,13 @@
-package com.ruoyi.common.server;
+package com.ruoyi.web.v2.server;
 
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.*;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
-import io.netty.handler.codec.string.StringDecoder;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.nio.charset.StandardCharsets;
-
 @Component
 public class EnvInputServer {
     @Autowired
@@ -22,9 +19,7 @@ public class EnvInputServer {
     public EnvInputServer(){
     }
 
-    public static void main(String[] args) throws InterruptedException {
-        new EnvInputServer().run();
-    }
+
 /**
  *
  * 功能描述: 启动方法前台多个服务  处理多个线程

+ 6 - 8
app-common/src/main/java/com/ruoyi/common/server/EnvInputServerHandler.java

@@ -1,13 +1,12 @@
-package com.ruoyi.common.server;
+package com.ruoyi.web.v2.server;
 
 
-import cn.hutool.core.util.ObjectUtil;
-import com.ruoyi.common.utils.ModBusUtils;
+import com.ruoyi.web.v2.v1.entity.ProtSj;
+import com.ruoyi.web.v2.v1.service.IProtSjService;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.*;
-import io.netty.util.CharsetUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,14 +15,12 @@ import org.springframework.stereotype.Component;
 
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.ZoneId;
 import java.util.Date;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
 
 import static ch.qos.logback.core.encoder.ByteArrayUtil.hexStringToByteArray;
 
@@ -43,8 +40,7 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
     private StringBuilder askTextSb = null;
 
     @Autowired
-    private RedisTemplate<String,String> redisTemplate;
-
+    private IProtSjService protSjService;
 
     private Map<String, String> channelMap = new ConcurrentHashMap<>();
 
@@ -109,6 +105,8 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
             System.out.println("氨氮: " + ammonia + " mg/L");
             System.out.println("总磷: " + phosphorus + " mg/L");
 
+            protSjService.save(new ProtSj(cod+"",ph+"",flow+"",ammonia+"",phosphorus+"",new Date()));
+
         } finally {
             // 7. 释放 ByteBuf
             byteBuf.release();

+ 1 - 1
app-admin/src/main/java/com/ruoyi/web/v2/v1/controller/JsDistributionController.java

@@ -64,7 +64,7 @@ public class JsDistributionController {
             , @RequestParam(value = "endTime", required = false) String endTime
             , @RequestParam(value = "supplierName", required = false) String supplierName
             , @RequestParam(value = "purchaserName", required = false) String purchaserName
-            , @RequestParam(value = "animalCertNo", required = false) Integer animalCertNo) {
+            , @RequestParam(value = "animalCertNo", required = false) String animalCertNo) {
 
         return distributionService.page(pageNum, pageSize, startTime, endTime, supplierName, purchaserName, animalCertNo);
     }

+ 69 - 0
app-admin/src/main/java/com/ruoyi/web/v2/v1/controller/ProtSjController.java

@@ -0,0 +1,69 @@
+package com.ruoyi.web.v2.v1.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.web.v2.v1.entity.JsWorkshop;
+import com.ruoyi.web.v2.v1.entity.ProtSj;
+import com.ruoyi.web.v2.v1.service.IProtSjService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+import static com.ruoyi.common.core.domain.AjaxResult.success;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author author
+ * @since 2025-08-04
+ */
+@RestController
+@RequestMapping("/prot-sj")
+@Api("环保数据")
+public class ProtSjController {
+    @Autowired
+    private  IProtSjService protSjService;
+
+    @ApiOperation("环保数据分页")
+    @GetMapping("/page")
+    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
+            , @RequestParam(value = "startDate", required = false) String startDate
+            , @RequestParam(value = "endDate", required = false) String endDate) {
+        QueryWrapper<ProtSj> queryWrapper = new QueryWrapper<>();
+        Page<ProtSj> page = new Page<>(pageNum, pageSize);
+        queryWrapper.ge(StringUtils.isNotEmpty(endDate), "create_time", endDate);
+        queryWrapper.ge(StringUtils.isNotEmpty(startDate), "create_time", endDate);
+        queryWrapper.orderByDesc("id");
+        return success(protSjService.page(page,queryWrapper));
+    }
+
+    @ApiOperation("环保数据列表")
+    @PostMapping("/list")
+    public AjaxResult listById(@RequestBody Map<String, String> paramsMap){
+        String startDate = paramsMap.get("startDate");
+        String endDate = paramsMap.get("endDate");
+        QueryWrapper<ProtSj> queryWrapper = new QueryWrapper<>();
+
+        queryWrapper.le(StringUtils.isNotEmpty(endDate), "create_time", endDate);
+        queryWrapper.ge(StringUtils.isNotEmpty(startDate), "create_time", startDate);
+        queryWrapper.orderByDesc("id");
+        return success(protSjService.list(queryWrapper));
+    }
+    @ApiOperation("环保数据最新")
+    @GetMapping("/getOne")
+    public AjaxResult listById(){
+
+        QueryWrapper<ProtSj> queryWrapper = new QueryWrapper<>();
+        queryWrapper.last("limit 1");
+        queryWrapper.orderByDesc("id");
+        return success(protSjService.getOne(queryWrapper));
+    }
+}

+ 69 - 0
app-admin/src/main/java/com/ruoyi/web/v2/v1/entity/ProtSj.java

@@ -0,0 +1,69 @@
+package com.ruoyi.web.v2.v1.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import java.io.Serializable;
+import java.util.Date;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author author
+ * @since 2025-08-04
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("prot_sj")
+
+public class ProtSj implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    private String cod;
+
+    private String ph;
+
+    /**
+     * 流量
+     */
+    private String ll;
+
+    /**
+     * 氨氮
+     */
+    private String ad;
+
+    /**
+     * 总磷
+     */
+    private String zl;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+
+    public ProtSj() {
+    }
+
+    public ProtSj(String cod, String ph, String ll, String ad, String zl, Date createTime) {
+        this.cod = cod;
+        this.ph = ph;
+        this.ll = ll;
+        this.ad = ad;
+        this.zl = zl;
+        this.createTime = createTime;
+    }
+}

+ 16 - 0
app-admin/src/main/java/com/ruoyi/web/v2/v1/mapper/ProtSjMapper.java

@@ -0,0 +1,16 @@
+package com.ruoyi.web.v2.v1.mapper;
+
+import com.ruoyi.web.v2.v1.entity.ProtSj;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author author
+ * @since 2025-08-04
+ */
+public interface ProtSjMapper extends BaseMapper<ProtSj> {
+
+}

+ 1 - 1
app-admin/src/main/java/com/ruoyi/web/v2/v1/service/IJsDistributionService.java

@@ -25,7 +25,7 @@ public interface IJsDistributionService extends IService<JsDistribution> {
 
     AjaxResult delete(String ids);
 
-    AjaxResult page(Integer pageNum, Integer pageSize, String startTime, String endTime, String supplierName, String purchaserName,  Integer animalCertNo);
+    AjaxResult page(Integer pageNum, Integer pageSize, String startTime, String endTime, String supplierName, String purchaserName,  String animalCertNo);
 
     AjaxResult listAll();
 

+ 16 - 0
app-admin/src/main/java/com/ruoyi/web/v2/v1/service/IProtSjService.java

@@ -0,0 +1,16 @@
+package com.ruoyi.web.v2.v1.service;
+
+import com.ruoyi.web.v2.v1.entity.ProtSj;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author author
+ * @since 2025-08-04
+ */
+public interface IProtSjService extends IService<ProtSj> {
+
+}

+ 5 - 2
app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/JsDeviceMaintenanceServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.web.v2.v1.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -39,8 +40,10 @@ public class JsDeviceMaintenanceServiceImpl extends ServiceImpl<JsDeviceMaintena
         QueryWrapper<JsMaintenanceWarning> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("device_num", deviceNum).orderByDesc("maintenance_time").last(" limit 1");
         JsMaintenanceWarning warning = warningMapper.selectOne(queryWrapper);
-        warning.setIsHandle(1);
-        warningMapper.updateById(warning);
+        if (ObjectUtil.isNotEmpty(warning)){
+            warning.setIsHandle(1);
+            warningMapper.updateById(warning);
+        }
         return success();
     }
 

+ 3 - 3
app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/JsDistributionServiceImpl.java

@@ -103,7 +103,7 @@ public class JsDistributionServiceImpl extends ServiceImpl<JsDistributionMapper,
     }
 
     @Override
-    public AjaxResult page(Integer pageNum, Integer pageSize, String startTime, String endTime, String supplierName, String purchaserName, Integer animalCertNo) {
+    public AjaxResult page(Integer pageNum, Integer pageSize, String startTime, String endTime, String supplierName, String purchaserName, String animalCertNo) {
         Page<JsDistribution> page = new Page<>(pageNum, pageSize);
         QueryWrapper<JsDistribution> queryWrapper = new QueryWrapper<>();
         if ("".equals(startTime) || null == startTime) {
@@ -115,8 +115,8 @@ public class JsDistributionServiceImpl extends ServiceImpl<JsDistributionMapper,
         queryWrapper.like(StringUtils.isNotEmpty(supplierName), "supplier_id", supplierName);
         queryWrapper.eq(StringUtils.isNotEmpty(purchaserName), "purchaser_name", purchaserName);
 
-        if (null != animalCertNo) {
-            queryWrapper.eq("animalCert_no", animalCertNo);
+        if (StringUtils.isNotEmpty(animalCertNo)) {
+            queryWrapper.eq("animal_cert_no", animalCertNo);
         }
         queryWrapper.orderByDesc("distribution_time");
         return success(distributionMapper.selectPage(page, queryWrapper));

+ 5 - 2
app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/JsInstrumentMaintenanceServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.web.v2.v1.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -39,8 +40,10 @@ public class JsInstrumentMaintenanceServiceImpl extends ServiceImpl<JsInstrument
         QueryWrapper<JsMaintenanceWarning> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("device_num", deviceNum).orderByDesc("maintenance_time").last(" limit 1");
         JsMaintenanceWarning warning = warningMapper.selectOne(queryWrapper);
-        warning.setIsHandle(1);
-        warningMapper.updateById(warning);
+        if (ObjectUtil.isNotEmpty(warning)){
+            warning.setIsHandle(1);
+            warningMapper.updateById(warning);
+        }
         return success();
     }
 

+ 1 - 0
app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/JsPatrolServiceImpl.java

@@ -56,6 +56,7 @@ public class JsPatrolServiceImpl extends ServiceImpl<JsPatrolMapper, JsPatrol> i
         if ("".equals(startTime) || null == startTime) {
 
         } else {
+            endTime = endTime+" 23:59:59";
             queryWrapper.between("patrol_time", startTime, endTime);
         }
         queryWrapper.orderByDesc("patrol_time");

+ 20 - 0
app-admin/src/main/java/com/ruoyi/web/v2/v1/service/impl/ProtSjServiceImpl.java

@@ -0,0 +1,20 @@
+package com.ruoyi.web.v2.v1.service.impl;
+
+import com.ruoyi.web.v2.v1.entity.ProtSj;
+import com.ruoyi.web.v2.v1.mapper.ProtSjMapper;
+import com.ruoyi.web.v2.v1.service.IProtSjService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author author
+ * @since 2025-08-04
+ */
+@Service
+public class ProtSjServiceImpl extends ServiceImpl<ProtSjMapper, ProtSj> implements IProtSjService {
+
+}

+ 3 - 1
app-admin/src/main/resources/application.yml

@@ -70,13 +70,15 @@ spring:
   # redis 配置
   redis:
     # 地址
-    host: localhost
+#    host: localhost
+    host: 122.112.224.199
     # 端口,默认为6379
     port: 6379
     # 数据库索引
     database: 10
     # 密码
     password: hm123456
+#    password: root
     # 连接超时时间
     timeout: 10s
     lettuce:

+ 6 - 0
app-admin/src/main/resources/mapper/ProtSjMapper.xml

@@ -0,0 +1,6 @@
+<?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">
+<mapper namespace="com.ruoyi.web.v2.v1.mapper.ProtSjMapper">
+
+
+</mapper>

+ 1 - 1
app-system/src/main/java/com/ruoyi/app/mapper/EntranceBatchMapper.java

@@ -190,7 +190,7 @@ public interface EntranceBatchMapper
      *@param productTraceParam 查询条件
      * @return 结果
      */
-    public List<ProductTraceDTO> selectProductTrace(ProductTraceParam productTraceParam);
+    public List<ProductTraceDTO> selectProductTrace(ProductTraceParam SlaughterBatchs);
 
     /**
      * 获取最近一条记录

+ 1 - 1
app-system/src/main/java/com/ruoyi/app/mapper/SlaughterBatchMapper.java

@@ -89,5 +89,5 @@ public interface SlaughterBatchMapper
     public List<SlaughterReportDTO> selectSlaughterReport(ReqSlaughterReport reqSlaughterReport);
 
 
-    List<ProductionVo> getAllList(String purchaserName);
+    List<ProductionVo> getAllList(@Param("animalCertNo")String animalCertNo,@Param("purchaserName")String purchaserName);
 }

+ 1 - 0
app-system/src/main/java/com/ruoyi/app/service/impl/EntranceBatchServiceImpl.java

@@ -160,6 +160,7 @@ public class EntranceBatchServiceImpl implements IEntranceBatchService {
      *
      * @return 结果
      */
+    @Override
     public EntranceBatch selectLatelyEntrance() {
         return entranceBatchMapper.selectLatelyEntrance();
     }

+ 1 - 1
app-system/src/main/java/com/ruoyi/app/service/impl/ProductTraceServiceImpl.java

@@ -41,7 +41,7 @@ public class ProductTraceServiceImpl implements IProductTraceService {
                 .map(item -> {
                     List<SlaughterBatchDTO> slaughterBatchs = item.getSlaughterBatchs();
                     for (SlaughterBatchDTO slaughterBatch : slaughterBatchs) {
-                        List<ProductionVo> allList = slaughterBatchMapper.getAllList(slaughterBatch.getPurchaserName());
+                        List<ProductionVo> allList = slaughterBatchMapper.getAllList(slaughterBatch.getAnimalCertNo(),slaughterBatch.getPurchaserName());
                         Purchaser purchaser = purchaserMapper.getOnePurchaser(slaughterBatch.getPurchaserId());
                         AncimalDTO oneAnimal = purchaserMapper.getOneAnimal(slaughterBatch.getPurchaserId());
                         if (ObjectUtil.isNotEmpty(oneAnimal)) {

+ 3 - 2
app-system/src/main/resources/mapper/app/EntranceBatchMapper.xml

@@ -567,11 +567,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         from entrance_batch as a
         left join (
             select
-                animal_cert_no,
+        DISTINCT    animal_cert_no,
                 purchaser_name,
                 purchaser_id
-            from js_distribution group by purchaser_name
+            from js_distribution
         ) as slaughter_distribute on slaughter_distribute.animal_cert_no = a.animal_cert_no
+        <if test="animalCertNo != null "> and a.animal_cert_no = #{animalCertNo}</if>
         left join entrance_inspection as f on f.entrance_batch_id = a.id and f.del_flag = '0'
         left join harmless_treatment as g on g.entrance_batch_id = a.id and g.del_flag = '0'
         <where>

+ 2 - 0
app-system/src/main/resources/mapper/app/SlaughterBatchMapper.xml

@@ -249,6 +249,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="getAllList" resultType="com.ruoyi.app.DTO.ProductionVo">
         select b.productName produceName,a.afterWeight weight,b.unit unit,a.amount amount FROM
         (select produce_name produceName,SUM(after_weight) afterWeight,SUM(amount) amount FROM js_distribution where purchaser_name=#{purchaserName}
+
+        <if test="animalCertNo != null "> and animal_cert_no = #{animalCertNo}</if>
         GROUP BY produce_name)
         as a right JOIN
         (select product_name productName,unit unit FROM product_category WHERE del_flag='0') AS b