Explorar el Código

2021/7/12 apiservice和转栏修改

yinhao hace 4 años
padre
commit
14278197be
Se han modificado 24 ficheros con 645 adiciones y 293 borrados
  1. 6 0
      huimv-smart-apiservice/pom.xml
  2. 1 1
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/controller/PigController.java
  3. 24 0
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/dao/EartagDateDao.java
  4. 2 1
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/dao/IndoorEnvironmentDao.java
  5. 116 0
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/EartagDateEntity.java
  6. 4 14
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/IndoorEnvironmentEntity.java
  7. 1 1
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/vo/EnvVo.java
  8. 4 8
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/vo/IndoorEnvVo.java
  9. 27 0
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/vo/ValueVo.java
  10. 98 50
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/service/impl/PigServiceImpl.java
  11. 12 12
      huimv-smart-apiservice/src/main/java/com/huimv/apiservice/task/CreateEverydayDataTask.java
  12. 5 11
      huimv-smart-apiservice/src/main/resources/mapper/apiservice/IndoorEnvironmentDao.xml
  13. 182 182
      huimv-smart-apiservice/src/test/java/com/huimv/apiservice/HuimvSmartApiserviceApplicationTests.java
  14. 5 0
      huimv-smart-datacollection/pom.xml
  15. 1 1
      huimv-smart-datacollection/src/main/java/com/huimv/datacollection/SimpleWeather.java
  16. 1 1
      huimv-smart-datacollection/src/main/java/com/huimv/datacollection/enums/CmdEnum.java
  17. 36 3
      huimv-smart-datacollection/src/main/java/com/huimv/datacollection/service/impl/ClientDataPacketServiceImpl.java
  18. 30 0
      huimv-smart-datacollection/src/main/java/com/huimv/datacollection/tcp/test/ClientDemo.java
  19. 38 0
      huimv-smart-datacollection/src/main/java/com/huimv/datacollection/tcp/test/ServerDemo.java
  20. 22 2
      huimv-smart-datacollection/src/main/java/com/huimv/datacollection/tcp/TcpSendAndRecv.java
  21. 6 0
      huimv-smart-management/pom.xml
  22. 14 5
      huimv-smart-management/src/main/java/com/huimv/management/controller/TransferPeriodLogController.java
  23. 8 0
      huimv-smart-management/src/main/java/com/huimv/management/entity/vo/TransferPeriodLogVo.java
  24. 2 1
      huimv-smart-management/src/main/resources/mapper/management/TransferPeriodLogDao.xml

+ 6 - 0
huimv-smart-apiservice/pom.xml

@@ -23,6 +23,12 @@
             <groupId>com.huimv</groupId>
             <artifactId>huimv-smart-common</artifactId>
             <version>1.0-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.cloud</groupId>
+                    <artifactId>spring-cloud-loadbalancer</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>

+ 1 - 1
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/controller/PigController.java

@@ -38,7 +38,7 @@ public class PigController {
     private HealthMedicalRecordDao healthMedicalRecordDao;
 
     /**
-     * 获取猪基本信息
+     * 获取猪健康状态信息
      *
      * @param accessToken token
      * @param pigEarTagNo 耳标号

+ 24 - 0
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/dao/EartagDateDao.java

@@ -0,0 +1,24 @@
+package com.huimv.apiservice.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.huimv.apiservice.entity.EartagDateEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * 
+ * 
+ * @author yinhao
+ * @email yinhao@163.com
+ * @date 2021-06-21 10:00:18
+ */
+@Mapper
+@Repository
+public interface EartagDateDao extends BaseMapper<EartagDateEntity> {
+
+
+
+
+
+
+}

+ 2 - 1
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/dao/IndoorEnvironmentDao.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.huimv.apiservice.entity.IndoorEnvironmentEntity;
 import com.huimv.apiservice.entity.vo.IndoorEnvVo;
+import com.huimv.apiservice.entity.vo.ValueVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Options;
 import org.apache.ibatis.annotations.Param;
@@ -30,5 +31,5 @@ public interface IndoorEnvironmentDao extends BaseMapper<IndoorEnvironmentEntity
     @Options(statementType = StatementType.CALLABLE)
     void callPigHealthData();
 
-    List<IndoorEnvVo> select(@Param("ew") LambdaQueryWrapper indoorEnvLambdaQuery);
+    List<ValueVo> select(@Param("ew") LambdaQueryWrapper indoorEnvLambdaQuery);
 }

+ 116 - 0
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/EartagDateEntity.java

@@ -0,0 +1,116 @@
+package com.huimv.apiservice.entity;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 
+ * 
+ * @author yinhao
+ * @email yinhao@163.com
+ * @date 2021-06-21 10:00:18
+ */
+@Data
+@TableName("eartag_date")
+public class EartagDateEntity implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 主键
+	 */
+	@TableId
+	private Integer id;
+	/**
+	 * 命令头
+	 */
+	private String messageHead;
+	/**
+	 * 设备id
+	 */
+	private String boxId;
+	/**
+	 * 命令
+	 */
+	private String messageCmd;
+	/**
+	 * 版本号
+	 */
+	private String boxVersion;
+	/**
+	 * 耳标号
+	 */
+	private String eartagId;
+	/**
+	 * 耳标电量
+	 */
+	private Integer eartagPower;
+	/**
+	 * 内部温度
+	 */
+	private Double boxInsideTemp;
+	/**
+	 * 耳标温度
+	 */
+	private Double eartagTemp;
+	/**
+	 * 电阻值
+	 */
+	private Integer ntc;
+	/**
+	 * 运动量
+	 */
+	private Integer countSport;
+	/**
+	 * 区间运动量
+	 */
+	private Integer gapSport;
+	/**
+	 * 重启数
+	 */
+	private Integer retstartTimes;
+	/**
+	 * rssyi
+	 */
+	private Integer rssyi;
+	/**
+	 * 上传时间
+	 */
+	private Date createTime;
+	/**
+	 * 环境温度
+	 */
+	private Double environmentTemp;
+	/**
+	 * 校验码
+	 */
+	private Integer checkNumber;
+	/**
+	 * 命令尾
+	 */
+	private String messageEnd;
+	/**
+	 * 牧场名称
+	 */
+	private Integer farmName;
+	/**
+	 * 备用字段 1
+	 */
+	private String backFirst;
+	/**
+	 * 备用字段2
+	 */
+	private String backSecong;
+	/**
+	 * 备用字段3
+	 */
+	private String backThird;
+	/**
+	 * 备注
+	 */
+	private String remark;
+
+}

+ 4 - 14
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/IndoorEnvironmentEntity.java

@@ -18,7 +18,6 @@ import java.util.Date;
 @TableName("mgt_indoor_environment")
 public class IndoorEnvironmentEntity implements Serializable {
     private static final long serialVersionUID = 1L;
-
     /**
      * id
      */
@@ -34,22 +33,13 @@ public class IndoorEnvironmentEntity implements Serializable {
      */
     private Integer pigstyId;
     /**
-     * 日期
-     */
-    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
-    private Date date;
-    /**
-     * 温度
-     */
-    private Double temperature;
-    /**
-     * 湿度
+     * 类型
      */
-    private Double humidity;
+    private Integer type;
     /**
-     * 气体
+     * 数值
      */
-    private String airQuality;
+    private Double value;
     /**
      * 采集时间
      */

+ 1 - 1
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/vo/EnvVo.java

@@ -28,7 +28,7 @@ public class EnvVo {
     /**
      * 室内环境
      */
-    private List<IndoorEnvVo> indoorEnvList;
+    private IndoorEnvVo indoorEnv;
 
     /**
      * 室外环境

+ 4 - 8
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/vo/IndoorEnvVo.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 
 import java.util.Date;
+import java.util.List;
 
 /**
  * <p>
@@ -17,22 +18,17 @@ import java.util.Date;
 public class IndoorEnvVo {
 
     /**
-     * 采集时间
-     */
-    private Date collectTime;
-
-    /**
      * 温度
      */
-    private Double temperature;
+    private List<ValueVo> temperatureList;
 
     /**
      * 湿度
      */
-    private Double humidity;
+    private List<ValueVo> humidityList;
 
     /**
      * 气体
      */
-    private String gas;
+    private List<ValueVo> gasList;
 }

+ 27 - 0
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/entity/vo/ValueVo.java

@@ -0,0 +1,27 @@
+package com.huimv.apiservice.entity.vo;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * <p>
+ * 室内温度
+ * </p>
+ *
+ * @author yinhao
+ * @date 2021/7/13 9:19
+ */
+@Data
+public class ValueVo {
+
+    /**
+     * 采集时间
+     */
+    private Date collectTime;
+
+    /**
+     * 数据值
+     */
+    private double dataValue;
+}

+ 98 - 50
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/service/impl/PigServiceImpl.java

@@ -1,6 +1,7 @@
 package com.huimv.apiservice.service.impl;
 
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
@@ -38,7 +39,7 @@ import java.util.*;
 public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> implements PigService {
 
     @Autowired
-    private RedisTemplate redisTemplate;
+    private EartagDateDao eartagDateDao;
 
     @Autowired
     private AnimalHeatDao animalHeatDao;
@@ -85,15 +86,39 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
 
         //公用时间 -> 当前日期
         String today = DateUtil.format(currentTime, "yyyy-MM-dd");
-
-        //体温数据sql构建和查询
-        LambdaQueryWrapper<AnimalHeatEntity> temperatureLambdaQuery = Wrappers.lambdaQuery();
-        temperatureLambdaQuery.eq(AnimalHeatEntity::getEartag, pigEarTagNo)
-                .eq(AnimalHeatEntity::getNowDate, today)
-                .eq(AnimalHeatEntity::getDeleted, 0)
-                .orderByDesc(AnimalHeatEntity::getId);
-        List<AnimalHeatVo> animalHeatVoList = animalHeatDao.selectAnimalHeatVoList(temperatureLambdaQuery);
+        LambdaQueryWrapper<EartagDateEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
+        lambdaQueryWrapper.eq(EartagDateEntity::getEartagId, pigEarTagNo)
+                .ge(EartagDateEntity::getCreateTime, DateUtil.offsetDay(new Date(), -1));
+
+
+        List<EartagDateEntity> eartagDateEntityList = eartagDateDao.selectList(lambdaQueryWrapper);
+        List<AnimalHeatVo> animalHeatVoList = new ArrayList<>();
+        List<SportTimeVo> sportTimeVoList = new ArrayList<>();
+        if (CollUtil.isNotEmpty(eartagDateEntityList)) {
+            for (EartagDateEntity eartagDateEntity : eartagDateEntityList) {
+                AnimalHeatVo animalHeatVo = new AnimalHeatVo();
+                Date createTime = eartagDateEntity.getCreateTime();
+                animalHeatVo.setCollectTime(createTime);
+                animalHeatVo.setTemperature(eartagDateEntity.getEartagTemp());
+                animalHeatVoList.add(animalHeatVo);
+
+                SportTimeVo sportTimeVo = new SportTimeVo();
+                sportTimeVo.setCollectTime(createTime);
+                sportTimeVo.setSportCount(eartagDateEntity.getCountSport());
+                sportTimeVoList.add(sportTimeVo);
+            }
+        }
         pigHealthStatusVo.setTemperature(animalHeatVoList);
+        pigHealthStatusVo.setSportStatus(sportTimeVoList);
+
+//        //体温数据sql构建和查询
+//        LambdaQueryWrapper<AnimalHeatEntity> temperatureLambdaQuery = Wrappers.lambdaQuery();
+//        temperatureLambdaQuery.eq(AnimalHeatEntity::getEartag, pigEarTagNo)
+//                .eq(AnimalHeatEntity::getNowDate, today)
+//                .eq(AnimalHeatEntity::getDeleted, 0)
+//                .orderByDesc(AnimalHeatEntity::getId);
+//        List<AnimalHeatVo> animalHeatVoList = animalHeatDao.selectAnimalHeatVoList(temperatureLambdaQuery);
+//        pigHealthStatusVo.setTemperature(animalHeatVoList);
 
         //采食状态数据sql构建及查询
         LambdaQueryWrapper<EatTimeEntity> eatTimeLambdaQuery = Wrappers.lambdaQuery();
@@ -113,14 +138,14 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
         List<SleepStatusVo> sleepStatusVoList = sleepStatusDao.selectSleepStatusVoList(sleepStatusLambdaQuery);
         pigHealthStatusVo.setSleepStatus(sleepStatusVoList);
 
-        //运动状态数据sql构建及查询
-        LambdaQueryWrapper<SportTimeEntity> sportStatusLambdaQuery = Wrappers.lambdaQuery();
-        sportStatusLambdaQuery.eq(SportTimeEntity::getEartag, pigEarTagNo)
-                .eq(SportTimeEntity::getNowDate, today)
-                .eq(SportTimeEntity::getDeleted, 0)
-                .orderByDesc(SportTimeEntity::getId);
-        List<SportTimeVo> sportTimeVoList = sportTimeDao.selectSportTimeVoList(sportStatusLambdaQuery);
-        pigHealthStatusVo.setSportStatus(sportTimeVoList);
+//        //运动状态数据sql构建及查询
+//        LambdaQueryWrapper<SportTimeEntity> sportStatusLambdaQuery = Wrappers.lambdaQuery();
+//        sportStatusLambdaQuery.eq(SportTimeEntity::getEartag, pigEarTagNo)
+//                .eq(SportTimeEntity::getNowDate, today)
+//                .eq(SportTimeEntity::getDeleted, 0)
+//                .orderByDesc(SportTimeEntity::getId);
+//        List<SportTimeVo> sportTimeVoList = sportTimeDao.selectSportTimeVoList(sportStatusLambdaQuery);
+//        pigHealthStatusVo.setSportStatus(sportTimeVoList);
 
         return pigHealthStatusVo;
     }
@@ -178,45 +203,56 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
             throw new RRException("耳标信息不存在,请检查!", 1001);
         }
 
-        EnvVo envVo = new EnvVo();
-        envVo.setPigEarTagNo(pigEarTagNo);
-        envVo.setDate(today);
-
         Integer pigstyId = yearPigBaseEntity.getPigstyId();
-        if (pigstyId != null) {
-            LambdaQueryWrapper<IndoorEnvironmentEntity> indoorEnvLambdaQuery = Wrappers.lambdaQuery();
-            indoorEnvLambdaQuery.eq(IndoorEnvironmentEntity::getPigstyId, pigstyId)
-                    .eq(IndoorEnvironmentEntity::getDate, today)
-                    .le(IndoorEnvironmentEntity::getCollectTime, new Date())
-                    .eq(IndoorEnvironmentEntity::getDeleted, 0)
-                    .orderByDesc(IndoorEnvironmentEntity::getId);
-            List<IndoorEnvVo> indoorEnvVoList = indoorEnvironmentDao.select(indoorEnvLambdaQuery);
-            envVo.setIndoorEnvList(indoorEnvVoList);
+        if (pigstyId == null) {
+            throw new RRException("未查询到对应猪舍,请联系管理员!", 1001);
         }
 
         Integer farmId = yearPigBaseEntity.getFarmId();
-        if (farmId != null) {
-            LambdaQueryWrapper<OutdoorEnvironmentEntity> outdoorEnvLambdaQuery = Wrappers.lambdaQuery();
-            outdoorEnvLambdaQuery.eq(OutdoorEnvironmentEntity::getFarmId, farmId)
-                    .eq(OutdoorEnvironmentEntity::getDate, today)
-                    .le(OutdoorEnvironmentEntity::getCollectTime, new Date())
-                    .eq(OutdoorEnvironmentEntity::getDeleted, 0)
-                    .orderByDesc(OutdoorEnvironmentEntity::getId);
-            List<OutdoorEnvVo> outdoorEnvVoList = outdoorEnvironmentDao.select(outdoorEnvLambdaQuery);
-            envVo.setOutdoorEnvList(outdoorEnvVoList);
+        if (farmId == null) {
+            throw new RRException("未查询到对应牧场,请联系管理员!", 1001);
         }
 
+        EnvVo envVo = new EnvVo();
+        envVo.setPigEarTagNo(pigEarTagNo);
+        envVo.setDate(today);
+
+        List<ValueVo> temperatureVoList = selectIndoorEnvByType(pigstyId, ((short) 1));
+        envVo.getIndoorEnv().setTemperatureList(temperatureVoList);
+        List<ValueVo> humidityVoList = selectIndoorEnvByType(pigstyId, ((short) 2));
+        envVo.getIndoorEnv().setHumidityList(humidityVoList);
+        List<ValueVo> gasVoList = selectIndoorEnvByType(pigstyId, ((short) 3));
+        envVo.getIndoorEnv().setGasList(gasVoList);
+
+        LambdaQueryWrapper<OutdoorEnvironmentEntity> outdoorEnvLambdaQuery = Wrappers.lambdaQuery();
+        outdoorEnvLambdaQuery.eq(OutdoorEnvironmentEntity::getFarmId, farmId)
+                .eq(OutdoorEnvironmentEntity::getDate, today)
+                .le(OutdoorEnvironmentEntity::getCollectTime, new Date())
+                .eq(OutdoorEnvironmentEntity::getDeleted, 0)
+                .orderByDesc(OutdoorEnvironmentEntity::getId);
+        List<OutdoorEnvVo> outdoorEnvVoList = outdoorEnvironmentDao.select(outdoorEnvLambdaQuery);
+        envVo.setOutdoorEnvList(outdoorEnvVoList);
+
         return envVo;
     }
 
+    private List<ValueVo> selectIndoorEnvByType(Integer pigstyId, short type) {
+
+        LambdaQueryWrapper<IndoorEnvironmentEntity> indoorEnvLambdaQuery = Wrappers.lambdaQuery();
+        indoorEnvLambdaQuery.eq(IndoorEnvironmentEntity::getPigstyId, pigstyId)
+                .eq(IndoorEnvironmentEntity::getType, type)
+                .ge(IndoorEnvironmentEntity::getCollectTime, DateUtil.beginOfDay(new Date()))
+                .le(IndoorEnvironmentEntity::getCollectTime, new Date())
+                .eq(IndoorEnvironmentEntity::getDeleted, 0)
+                .orderByDesc(IndoorEnvironmentEntity::getId);
+
+        return indoorEnvironmentDao.select(indoorEnvLambdaQuery);
+    }
+
     @Override
     public void adopt(String pigEarTagNo) {
 
-        LambdaQueryWrapper<YearPigBaseEntity> eq = Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, pigEarTagNo);
-        YearPigBaseEntity yearPigBaseEntity = baseMapper.selectOne(eq);
-        if (yearPigBaseEntity == null) {
-            throw new RRException("耳标信息不存在,请检查!", 1001);
-        }
+        YearPigBaseEntity yearPigBaseEntity = getYearPigBaseEntity(pigEarTagNo);
         if (yearPigBaseEntity.getFosterStatus()) {
             throw new RRException("本猪已被其他人认养!", 1001);
         }
@@ -258,11 +294,9 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
 
     @Override
     public void abandonAdopt(String pigEarTagNo) {
-        LambdaQueryWrapper<YearPigBaseEntity> eq = Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, pigEarTagNo);
-        YearPigBaseEntity yearPigBaseEntity = baseMapper.selectOne(eq);
-        if (yearPigBaseEntity == null) {
-            throw new RRException("耳标信息不存在,请检查!", 1001);
-        }
+
+        YearPigBaseEntity yearPigBaseEntity = getYearPigBaseEntity(pigEarTagNo);
+
         if (!yearPigBaseEntity.getFosterStatus() || yearPigBaseEntity.getOutFenceStatus() != 0) {
             throw new RRException("请检查目前的认养状态或出栏状态!", 1001);
         }
@@ -279,7 +313,7 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
         checkPigEarTagNo(pigEarTagNo);
 
         LambdaQueryWrapper<HealthMedicalRecordEntity> wrapper = Wrappers.lambdaQuery();
-        wrapper.eq(HealthMedicalRecordEntity::getPigId,pigEarTagNo);
+        wrapper.eq(HealthMedicalRecordEntity::getPigId, pigEarTagNo);
         return healthMedicalRecordDao.selectList(wrapper);
     }
 
@@ -300,6 +334,20 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
         }
     }
 
+    /**
+     * 公用获取小猪信息方法
+     *
+     * @param pigEarTagNo
+     * @return
+     */
+    private YearPigBaseEntity getYearPigBaseEntity(String pigEarTagNo) {
+        LambdaQueryWrapper<YearPigBaseEntity> eq = Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, pigEarTagNo);
+        YearPigBaseEntity yearPigBaseEntity = baseMapper.selectOne(eq);
+        if (yearPigBaseEntity == null) {
+            throw new RRException("耳标信息不存在,请检查!", 1001);
+        }
+        return yearPigBaseEntity;
+    }
 
 
 }

+ 12 - 12
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/task/CreateEverydayDataTask.java

@@ -62,18 +62,18 @@ public class CreateEverydayDataTask {
             IndoorEnvironmentEntity entity = new IndoorEnvironmentEntity();
 
             //当前日期
-            entity.setDate(today);
-            //牧场id
-            entity.setFarmId(144);
-            //猪舍id
-            entity.setPigstyId(56);
-            //温度
-            entity.setTemperature(getTemperature());
-            //湿度
-            entity.setHumidity(getHumidity());
-            //空气质量
-            entity.setAirQuality(gas.get(random.nextInt(5)));
-            //采集时间
+//            entity.setDate(today);
+//            //牧场id
+//            entity.setFarmId(144);
+//            //猪舍id
+//            entity.setPigstyId(56);
+//            //温度
+//            entity.setTemperature(getTemperature());
+//            //湿度
+//            entity.setHumidity(getHumidity());
+//            //空气质量
+//            entity.setAirQuality(gas.get(random.nextInt(5)));
+//            //采集时间
             entity.setCollectTime(collectTime);
             collectTime = DateUtil.offsetMinute(collectTime, 5);
             list.add(entity);

+ 5 - 11
huimv-smart-apiservice/src/main/resources/mapper/apiservice/IndoorEnvironmentDao.xml

@@ -7,10 +7,6 @@
     <resultMap type="com.huimv.apiservice.entity.IndoorEnvironmentEntity" id="indoorEnvironmentMap">
         <result property="id" column="id"/>
         <result property="pigstyId" column="pigsty_id"/>
-        <result property="temperature" column="temperature"/>
-        <result property="humidity" column="humidity"/>
-        <result property="airQuality" column="gas"/>
-        <result property="date" column="date"/>
         <result property="collectTime" column="collect_time"/>
         <result property="deleted" column="deleted"/>
         <result property="gmtCreate" column="gmt_create"/>
@@ -21,9 +17,9 @@
         insert into mgt_indoor_environment(pigsty_id,date,temperature,humidity,air_quality,collect_time)
         values
         <foreach collection="list" item="item"  separator="," >
-            #{item.date},
+            (#{item.date},
             #{item.farmId},
-            (#{item.pigstyId},
+            #{item.pigstyId},
             #{item.temperature},
             #{item.humidity},
             #{item.airQuality},
@@ -31,13 +27,11 @@
         </foreach>
     </insert>
 
-    <select id="select" resultType="com.huimv.apiservice.entity.vo.IndoorEnvVo">
+    <select id="select" resultType="com.huimv.apiservice.entity.vo.ValueVo">
         SELECT
           collect_time,
-          temperature,
-          humidity,
-          air_quality
-        FROM mgt_indoor_environment
+           env.value datavalue
+        FROM mgt_indoor_environment env
         ${ew.customSqlSegment}
     </select>
 </mapper>

+ 182 - 182
huimv-smart-apiservice/src/test/java/com/huimv/apiservice/HuimvSmartApiserviceApplicationTests.java

@@ -1,194 +1,194 @@
-package com.huimv.apiservice;
-
-import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUtil;
-import com.huimv.apiservice.dao.IndoorEnvironmentDao;
-import com.huimv.apiservice.dao.OutdoorEnvironmentDao;
-import com.huimv.apiservice.dao.PigDao;
-import com.huimv.apiservice.entity.IndoorEnvironmentEntity;
-import com.huimv.apiservice.entity.OutdoorEnvironmentEntity;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-
-import java.math.BigDecimal;
-import java.util.*;
-
-@SpringBootTest
-class HuimvSmartApiserviceApplicationTests {
-
-    @Autowired
-    private IndoorEnvironmentDao indoorEnvironmentDao;
-
-    @Autowired
-    private OutdoorEnvironmentDao outdoorEnvironmentDao;
-
-    @Autowired
-    private PigDao pigDao;
-
-
-    @Test
-    void contextLoads() {
-
-    }
-
-
-    @Test
-    void createIndoorEnv() {
-
-        DateTime today = DateUtil.beginOfDay(new Date());
-        System.out.println(today);
-//        BigDecimal bigDecimal = new BigDecimal(Math.random() * 8 + 25).setScale(1, BigDecimal.ROUND_HALF_UP);
-//        double temperature = bigDecimal.doubleValue();
-
-//        BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
-//        double humidity = bigDecimal2.doubleValue();
-
-//        System.out.println(temperature + " " + humidity);
-        Date collectTime = today;
-
-        List<String> gas = new ArrayList<>();
-        gas.add("优");
-        gas.add("良");
-        gas.add("轻度");
-        gas.add("中度");
-        gas.add("重度");
-        gas.add("严重");
-
-        Random random = new Random();
-        List<IndoorEnvironmentEntity> list = new ArrayList<>();
-        for (int i = 0; i < 288; i++) {
-            IndoorEnvironmentEntity entity = new IndoorEnvironmentEntity();
-            entity.setDate(today);
-            entity.setPigstyId(1);
-            BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).setScale(1, BigDecimal.ROUND_HALF_UP);
-            double temperature = bigDecimal.doubleValue();
-            entity.setTemperature(temperature);
-            BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
-            double humidity = bigDecimal2.doubleValue();
-            entity.setHumidity(humidity);
-            entity.setAirQuality(gas.get(random.nextInt(5)));
-            entity.setCollectTime(collectTime);
-            collectTime = DateUtil.offsetMinute(collectTime,5);
-//            System.out.println(entity);
-            list.add(entity);
-        }
-
-        indoorEnvironmentDao.batchInsertData(list);
-    }
-
-    @Test
-    void createOutdoorEnv() {
-
-        DateTime today = DateUtil.beginOfDay(new Date());
-        System.out.println(today);
-//        BigDecimal bigDecimal = new BigDecimal(Math.random() * 8 + 25).setScale(1, BigDecimal.ROUND_HALF_UP);
-//        double temperature = bigDecimal.doubleValue();
-
-//        BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
-//        double humidity = bigDecimal2.doubleValue();
-
-//        System.out.println(temperature + " " + humidity);
-        Date collectTime = today;
-
-        List<String> gas = new ArrayList<>();
-        gas.add("优");
-        gas.add("良");
-        gas.add("轻度");
-        gas.add("中度");
-        gas.add("重度");
-        gas.add("严重");
-
-        Random random = new Random();
-        List<OutdoorEnvironmentEntity> list = new ArrayList<>();
-        for (int i = 0; i < 288; i++) {
-            OutdoorEnvironmentEntity entity = new OutdoorEnvironmentEntity();
-            entity.setDate(today);
-            BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).setScale(1, BigDecimal.ROUND_HALF_UP);
-            double temperature = bigDecimal.doubleValue();
-            entity.setTemperature(temperature);
-            BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
-            double humidity = bigDecimal2.doubleValue();
-            entity.setHumidity(humidity);
-            entity.setAirQuality(gas.get(random.nextInt(4)));
-            entity.setCollectTime(collectTime);
-            collectTime = DateUtil.offsetMinute(collectTime,5);
-            list.add(entity);
-        }
-
-        outdoorEnvironmentDao.batchInsertData(list);
-    }
-
-
+//package com.huimv.apiservice;
+//
+//import cn.hutool.core.date.DateTime;
+//import cn.hutool.core.date.DateUtil;
+//import com.huimv.apiservice.dao.IndoorEnvironmentDao;
+//import com.huimv.apiservice.dao.OutdoorEnvironmentDao;
+//import com.huimv.apiservice.dao.PigDao;
+//import com.huimv.apiservice.entity.IndoorEnvironmentEntity;
+//import com.huimv.apiservice.entity.OutdoorEnvironmentEntity;
+//import org.junit.jupiter.api.Test;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.boot.test.context.SpringBootTest;
+//
+//import java.math.BigDecimal;
+//import java.util.*;
+//
+//@SpringBootTest
+//class HuimvSmartApiserviceApplicationTests {
+//
+//    @Autowired
+//    private IndoorEnvironmentDao indoorEnvironmentDao;
+//
+//    @Autowired
+//    private OutdoorEnvironmentDao outdoorEnvironmentDao;
+//
+//    @Autowired
+//    private PigDao pigDao;
+//
+//
 //    @Test
-//    void createPigData() {
+//    void contextLoads() {
 //
-//        String[] breeds = {"黑猪","金华两头乌","杜巴嘉","巴嘉","杜洛克","嘉兴黑猪","大白猪"};
-//        String[] originPlace = {"金华","杭州"};
+//    }
 //
-//        List<YearPigBaseEntity> all = new ArrayList<>();
-//        List<YearPigBaseEntity> mothers = new ArrayList<>();
-//        List<YearPigBaseEntity> fathers = new ArrayList<>();
+//
+//    @Test
+//    void createIndoorEnv() {
+//
+//        DateTime today = DateUtil.beginOfDay(new Date());
+//        System.out.println(today);
+////        BigDecimal bigDecimal = new BigDecimal(Math.random() * 8 + 25).setScale(1, BigDecimal.ROUND_HALF_UP);
+////        double temperature = bigDecimal.doubleValue();
+//
+////        BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
+////        double humidity = bigDecimal2.doubleValue();
+//
+////        System.out.println(temperature + " " + humidity);
+//        Date collectTime = today;
+//
+//        List<String> gas = new ArrayList<>();
+//        gas.add("优");
+//        gas.add("良");
+//        gas.add("轻度");
+//        gas.add("中度");
+//        gas.add("重度");
+//        gas.add("严重");
 //
 //        Random random = new Random();
-//        for (int i = 5; i < 2001; i++) {
-//            YearPigBaseEntity entity = new YearPigBaseEntity();
-//            String number = String.valueOf(i);
-//            String earTag = "N00000".substring(0, 6 - number.length()) + number;
-//            entity.setEartag(earTag);
-//            int dayAge = random.nextInt(200) + 50;
-//            entity.setDayAge(dayAge);
-//            entity.setUnitId(random.nextInt(4) + 1);
-//            BigDecimal bigDecimal = new BigDecimal(dayAge);
-//            BigDecimal weight = bigDecimal.multiply(new BigDecimal(0.8)).setScale(2, BigDecimal.ROUND_HALF_UP);
-//            entity.setWeight(weight.doubleValue());
-//            entity.setBreed(breeds[random.nextInt(breeds.length)]);
-//            String sex = i % 2 == 0 ? "公" : "母";
-//            entity.setSex(sex);
-//            if (dayAge >= 150 && "母".equals(sex)) {
-//                mothers.add(entity);
-//            }
-//            if (dayAge >= 150 && "公".equals(sex)) {
-//                fathers.add(entity);
-//            }
-//            entity.setBirthday(DateUtil.offsetDay(DateUtil.date(),i % 200));
-//            entity.setOriginPlace(originPlace[random.nextInt(2)]);
-//            //System.out.println(entity.getDayAge() + " " + " " + entity.getUnitId() + " " +  entity.getWeight());
-//            entity.setPigstyId(random.nextInt(4) + 1);
-//            entity.setPeriodId(1);
-//            entity.setInFenceTime(DateUtil.offsetDay(DateUtil.parseDate("2021-01-01"),random.nextInt(91) - 30));
-//            all.add(entity);
+//        List<IndoorEnvironmentEntity> list = new ArrayList<>();
+//        for (int i = 0; i < 288; i++) {
+//            IndoorEnvironmentEntity entity = new IndoorEnvironmentEntity();
+////            entity.setDate(today);
+////            entity.setPigstyId(1);
+////            BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).setScale(1, BigDecimal.ROUND_HALF_UP);
+////            double temperature = bigDecimal.doubleValue();
+////            entity.setTemperature(temperature);
+////            BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
+////            double humidity = bigDecimal2.doubleValue();
+////            entity.setHumidity(humidity);
+////            entity.setAirQuality(gas.get(random.nextInt(5)));
+//            entity.setCollectTime(collectTime);
+//            collectTime = DateUtil.offsetMinute(collectTime,5);
+////            System.out.println(entity);
+//            list.add(entity);
 //        }
 //
-//        for (YearPigBaseEntity yearPigBaseEntity : all) {
-//            if (yearPigBaseEntity.getDayAge() < 150) {
-//                yearPigBaseEntity.setMotherEartag(mothers.get(random.nextInt(mothers.size())).getEartag());
-//                yearPigBaseEntity.setFatherEartag(fathers.get(random.nextInt(fathers.size())).getEartag());
-//            }
-//        }
-//        pigDao.batchInsertData(all);
-//
-//        List<SowChildbirthEntity> sowChildbirthEntityList = new ArrayList<>();
-//        for (YearPigBaseEntity mother : mothers) {
-//            SowChildbirthEntity entity = new SowChildbirthEntity();
-//            entity.setEartag(mother.getEartag());
-//            entity.setChildbirthWeight(mother.getWeight());
-//            entity.setPregnancyDate(DateUtil.offsetMonth(mother.getInFenceTime(),3));
-//            entity.setChildbirthCount(random.nextInt(10) + 5);
-//            sowChildbirthEntityList.add(entity);
-//        }
-//        sowChildbirthDao.batchInsertData(sowChildbirthEntityList);
+//        indoorEnvironmentDao.batchInsertData(list);
+//    }
+//
+//    @Test
+//    void createOutdoorEnv() {
 //
+//        DateTime today = DateUtil.beginOfDay(new Date());
+//        System.out.println(today);
+////        BigDecimal bigDecimal = new BigDecimal(Math.random() * 8 + 25).setScale(1, BigDecimal.ROUND_HALF_UP);
+////        double temperature = bigDecimal.doubleValue();
 //
+////        BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
+////        double humidity = bigDecimal2.doubleValue();
 //
+////        System.out.println(temperature + " " + humidity);
+//        Date collectTime = today;
 //
+//        List<String> gas = new ArrayList<>();
+//        gas.add("优");
+//        gas.add("良");
+//        gas.add("轻度");
+//        gas.add("中度");
+//        gas.add("重度");
+//        gas.add("严重");
+//
+//        Random random = new Random();
+//        List<OutdoorEnvironmentEntity> list = new ArrayList<>();
+//        for (int i = 0; i < 288; i++) {
+//            OutdoorEnvironmentEntity entity = new OutdoorEnvironmentEntity();
+//            entity.setDate(today);
+//            BigDecimal bigDecimal = new BigDecimal(Math.random() * 3 + 23).setScale(1, BigDecimal.ROUND_HALF_UP);
+//            double temperature = bigDecimal.doubleValue();
+//            entity.setTemperature(temperature);
+//            BigDecimal bigDecimal2 = new BigDecimal(Math.random() * 0.3 + 0.3).setScale(2, BigDecimal.ROUND_HALF_UP);
+//            double humidity = bigDecimal2.doubleValue();
+//            entity.setHumidity(humidity);
+//            entity.setAirQuality(gas.get(random.nextInt(4)));
+//            entity.setCollectTime(collectTime);
+//            collectTime = DateUtil.offsetMinute(collectTime,5);
+//            list.add(entity);
+//        }
+//
+//        outdoorEnvironmentDao.batchInsertData(list);
 //    }
-
-
-
-
-
-
-
-
-}
+//
+//
+////    @Test
+////    void createPigData() {
+////
+////        String[] breeds = {"黑猪","金华两头乌","杜巴嘉","巴嘉","杜洛克","嘉兴黑猪","大白猪"};
+////        String[] originPlace = {"金华","杭州"};
+////
+////        List<YearPigBaseEntity> all = new ArrayList<>();
+////        List<YearPigBaseEntity> mothers = new ArrayList<>();
+////        List<YearPigBaseEntity> fathers = new ArrayList<>();
+////
+////        Random random = new Random();
+////        for (int i = 5; i < 2001; i++) {
+////            YearPigBaseEntity entity = new YearPigBaseEntity();
+////            String number = String.valueOf(i);
+////            String earTag = "N00000".substring(0, 6 - number.length()) + number;
+////            entity.setEartag(earTag);
+////            int dayAge = random.nextInt(200) + 50;
+////            entity.setDayAge(dayAge);
+////            entity.setUnitId(random.nextInt(4) + 1);
+////            BigDecimal bigDecimal = new BigDecimal(dayAge);
+////            BigDecimal weight = bigDecimal.multiply(new BigDecimal(0.8)).setScale(2, BigDecimal.ROUND_HALF_UP);
+////            entity.setWeight(weight.doubleValue());
+////            entity.setBreed(breeds[random.nextInt(breeds.length)]);
+////            String sex = i % 2 == 0 ? "公" : "母";
+////            entity.setSex(sex);
+////            if (dayAge >= 150 && "母".equals(sex)) {
+////                mothers.add(entity);
+////            }
+////            if (dayAge >= 150 && "公".equals(sex)) {
+////                fathers.add(entity);
+////            }
+////            entity.setBirthday(DateUtil.offsetDay(DateUtil.date(),i % 200));
+////            entity.setOriginPlace(originPlace[random.nextInt(2)]);
+////            //System.out.println(entity.getDayAge() + " " + " " + entity.getUnitId() + " " +  entity.getWeight());
+////            entity.setPigstyId(random.nextInt(4) + 1);
+////            entity.setPeriodId(1);
+////            entity.setInFenceTime(DateUtil.offsetDay(DateUtil.parseDate("2021-01-01"),random.nextInt(91) - 30));
+////            all.add(entity);
+////        }
+////
+////        for (YearPigBaseEntity yearPigBaseEntity : all) {
+////            if (yearPigBaseEntity.getDayAge() < 150) {
+////                yearPigBaseEntity.setMotherEartag(mothers.get(random.nextInt(mothers.size())).getEartag());
+////                yearPigBaseEntity.setFatherEartag(fathers.get(random.nextInt(fathers.size())).getEartag());
+////            }
+////        }
+////        pigDao.batchInsertData(all);
+////
+////        List<SowChildbirthEntity> sowChildbirthEntityList = new ArrayList<>();
+////        for (YearPigBaseEntity mother : mothers) {
+////            SowChildbirthEntity entity = new SowChildbirthEntity();
+////            entity.setEartag(mother.getEartag());
+////            entity.setChildbirthWeight(mother.getWeight());
+////            entity.setPregnancyDate(DateUtil.offsetMonth(mother.getInFenceTime(),3));
+////            entity.setChildbirthCount(random.nextInt(10) + 5);
+////            sowChildbirthEntityList.add(entity);
+////        }
+////        sowChildbirthDao.batchInsertData(sowChildbirthEntityList);
+////
+////
+////
+////
+////    }
+//
+//
+//
+//
+//
+//
+//
+//
+//}

+ 5 - 0
huimv-smart-datacollection/pom.xml

@@ -46,6 +46,11 @@
         </dependency>
 
         <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>net.sf.json-lib</groupId>
             <artifactId>json-lib</artifactId>
             <version>2.2.3</version>

+ 1 - 1
huimv-smart-datacollection/src/main/java/com/huimv/datacollection/SimpleWeather.java

@@ -26,7 +26,7 @@ public class SimpleWeather {
     public static String API_KEY = "108f91d439908e5d2da86cc8881dd3db";
 
     public static void main(String[] args) {
-        String cityName = "常州";
+        String cityName = "嘉兴";
         queryWeather(cityName);
     }
 

+ 1 - 1
huimv-smart-datacollection/src/main/java/com/huimv/datacollection/enums/CmdEnum.java

@@ -23,7 +23,7 @@ public enum CmdEnum {
      */
     GAS("9");
 
-    private String typeNum;
+    private final String typeNum;
 
     CmdEnum(String typeNum) {
         this.typeNum = typeNum;

+ 36 - 3
huimv-smart-datacollection/src/main/java/com/huimv/datacollection/service/impl/ClientDataPacketServiceImpl.java

@@ -290,6 +290,39 @@ public class ClientDataPacketServiceImpl implements IClientDataPacketService {
 
         return rs;
 
+//        //获取设备信息并校验
+//        String deviceJson = JSONObject.toJSONString(managementFeignService.deviceInfo(jqId).get("device"));
+//        DeviceEntity deviceEntity = JSONObject.parseObject(deviceJson, DeviceEntity.class);
+//        if (deviceEntity == null) {
+//            throw new RRException("没有获取到设备信息,请联系管理员!");
+//        }
+//        //保存室内环境数据
+//        IndoorEnvironmentEntity indoorEnvironmentEntity = new IndoorEnvironmentEntity();
+//        Integer farmId = deviceEntity.getFarmId();
+//        indoorEnvironmentEntity.setFarmId(farmId);
+//        Integer pigstyId = deviceEntity.getPigstyId();
+//        indoorEnvironmentEntity.setPigstyId(pigstyId);
+//        indoorEnvironmentEntity.setValue(value);
+//        indoorEnvironmentEntity.setCollectTime(new Date());
+//
+//        Map<String, Double> map = managementFeignService.selectByType((short) 1);
+//        switch (deviceDataEntity.getCmdType()) {
+//            case 7:
+//                indoorEnvironmentEntity.setType(1);
+//                handleDataPackageService.handleTemperature(indoorEnvironmentEntity, value, farmId, pigstyId, map);
+//                return "hm+7+0+7+end";
+//            case 8:
+//                indoorEnvironmentEntity.setType(2);
+//                handleDataPackageService.handleHumidity(indoorEnvironmentEntity, value, farmId, pigstyId, map);
+//                return "hm+8+0+8+end";
+//            case 9:
+//                indoorEnvironmentEntity.setType(3);
+//                handleDataPackageService.handleGas(indoorEnvironmentEntity, value, farmId, pigstyId, map);
+//                return "hm+9+0+8+end";
+//            default:
+//                break;
+//        }
+//        return "";
     }
 
     /**
@@ -647,10 +680,10 @@ public class ClientDataPacketServiceImpl implements IClientDataPacketService {
             }
 
             //2017-9-19
-            //温度
+            //室外温度
             if (cmd.equals(XtAppConstant.SOCKET_SJSC_CMD_46)) {
             }
-            //湿度
+            //室外湿度
             if (cmd.equals(XtAppConstant.SOCKET_SJSC_CMD_47)) {
             }
             //氧气
@@ -1463,7 +1496,7 @@ public class ClientDataPacketServiceImpl implements IClientDataPacketService {
         String gz = String.valueOf(Integer.parseInt(jqid.substring(jqid.length() - 1))
                 + Integer.parseInt(pznr.substring(pznr.length() - 1)) + Integer.parseInt(cmd.substring(cmd.length() - 1)) + Long.parseLong(date) % 10);
         String rs = XtAppConstant.SOCKET_SJSC_START + "+" + result[1] + "+" + cmd + "+";
-        String dbjg = "1";
+        String dbjg = "0";
         if ((gz.substring(gz.length() - 1)).equals(jy)) {
             gz = XtAppConstant.SOCKET_SJSC_GZBZ_0;
             dbjg = XtAppConstant.SOCKET_SJSC_TLGTB_0;

+ 30 - 0
huimv-smart-datacollection/src/main/java/com/huimv/datacollection/tcp/test/ClientDemo.java

@@ -0,0 +1,30 @@
+package com.huimv.datacollection.tcp.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+
+public class ClientDemo {
+
+    public static void main(String[] args) throws IOException {
+
+        Socket socket = new Socket("localhost", 9977);
+
+        OutputStream os = socket.getOutputStream();
+        os.write("hello".getBytes());
+        socket.shutdownOutput();
+
+        InputStream is = socket.getInputStream();
+        int len;
+        byte[] bytes = new byte[1024*8];
+        while ((len = is.read(bytes))!= -1) {
+            System.out.println(new String(bytes,0,len));
+        }
+
+        os.close();
+        is.close();
+        socket.close();
+
+    }
+}

+ 38 - 0
huimv-smart-datacollection/src/main/java/com/huimv/datacollection/tcp/test/ServerDemo.java

@@ -0,0 +1,38 @@
+package com.huimv.datacollection.tcp.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class ServerDemo {
+
+    public static void main(String[] args) throws IOException {
+
+        ServerSocket serverSocket = new ServerSocket(9977);
+
+        Socket accept = serverSocket.accept();
+
+        InputStream is = accept.getInputStream();
+
+        int len;
+        byte[] bytes = new byte[1024*8];
+
+        while ((len = is.read(bytes))!= -1) {
+            System.out.println(new String(bytes,0,len));
+        }
+
+        OutputStream os = accept.getOutputStream();
+        os.write("你谁啊?".getBytes());
+        accept.shutdownOutput();
+
+        is.close();
+        os.close();
+        accept.close();
+        serverSocket.close();
+
+
+
+    }
+}

+ 22 - 2
huimv-smart-datacollection/src/main/java/com/huimv/datacollection/tcp/TcpSendAndRecv.java

@@ -1,4 +1,4 @@
-package com.huimv.datacollection.tcp;
+package com.huimv.datacollection.tcp.test;
 
 import java.io.*;
 import java.net.ServerSocket;
@@ -31,7 +31,7 @@ class TT implements Runnable {
     public void run() {
         try {
             //创建一个socket绑定的端口和地址为:9977,本机。
-            Socket s = new Socket("localhost", 9977);
+            Socket s = new Socket("127.0.0.1", 9977);
             //获取到输出流
             OutputStream oos = s.getOutputStream();
             BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(oos));
@@ -43,9 +43,22 @@ class TT implements Runnable {
                 bw.flush();
                 //将内容写到控制台
             }
+
+            InputStream inputStream = s.getInputStream();
+            byte[] bytes = new byte[1024];
+            inputStream.read(bytes);
+            String str = new String(bytes);
+            System.out.println(str);
+
+            oos.close();
+            inputStream.close();
+            s.close();
+
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
+        } finally {
+
         }
 
 
@@ -72,6 +85,13 @@ class DD implements Runnable {
                 //将接收到的数据在控制台输出
                 System.out.println("接收端" + new String(buf, 0, line));
             }
+
+            s.getOutputStream().write("hm".getBytes());
+            s.shutdownOutput();
+
+            is.close();
+            s.close();
+            ss.close();
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();

+ 6 - 0
huimv-smart-management/pom.xml

@@ -74,6 +74,12 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
+
     </dependencies>
     <dependencyManagement>
         <dependencies>

+ 14 - 5
huimv-smart-management/src/main/java/com/huimv/management/controller/TransferPeriodLogController.java

@@ -1,14 +1,13 @@
  package com.huimv.management.controller;
 
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import com.huimv.management.entity.TransferPeriodLogEntity;
 import com.huimv.management.service.TransferPeriodLogService;
@@ -81,4 +80,14 @@ public class TransferPeriodLogController {
         return R.ok();
     }
 
+    @GetMapping("/findAll")
+    public R findAll(@RequestParam("formFarmId") Integer formFarmId) {
+        LambdaQueryWrapper<TransferPeriodLogEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
+        lambdaQueryWrapper.eq(TransferPeriodLogEntity::getFarmId, formFarmId);
+        List<TransferPeriodLogEntity> list = transferPeriodLogService.list(lambdaQueryWrapper);
+
+        return R.ok().put("data", list);
+
+    }
+
 }

+ 8 - 0
huimv-smart-management/src/main/java/com/huimv/management/entity/vo/TransferPeriodLogVo.java

@@ -1,8 +1,10 @@
 package com.huimv.management.entity.vo;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.util.Date;
 
 /**
  * <p>
@@ -81,4 +83,10 @@ public class TransferPeriodLogVo  implements Serializable {
      * 操作人
      */
     private String operatorUsername;
+
+    /**
+     * 转栏时间
+     */
+    @JsonFormat(pattern = "yyyy/MM/dd",timezone = "GMT+8")
+    private Date transDate;
 }

+ 2 - 1
huimv-smart-management/src/main/resources/mapper/management/TransferPeriodLogDao.xml

@@ -59,7 +59,8 @@
           period1.number old_period_name,
           new_period_id,
           period2.number new_period_name,
-          operator_username
+          operator_username,
+          log.gmt_create trans_date
         FROM mgt_transfer_period_log log
         JOIN mgt_pigsty pigsty1 ON log.old_pigsty_id = pigsty1.id
         JOIN mgt_pigsty pigsty2 ON log.new_pigsty_id = pigsty2.id