|
@@ -1,9 +1,9 @@
|
|
|
package com.huimv.apiservice.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.codec.Base64;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -23,9 +23,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Author yinhao
|
|
@@ -39,6 +37,12 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
private PigstyDao pigstyDao;
|
|
|
|
|
|
@Autowired
|
|
|
+ private AnimalHeatDao animalHeatDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EatTimeDao eatTimeDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private YearPigHistoryImgDao yearPigHistoryImgDao;
|
|
|
|
|
|
@Autowired
|
|
@@ -51,38 +55,141 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
private SportTimeDao sportTimeDao;
|
|
|
|
|
|
@Override
|
|
|
- public PigBaseVo getPigInfoByEarTagNo(String pigEarTagNo) {
|
|
|
-
|
|
|
- LambdaQueryWrapper<YearPigBaseEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
- lambdaQueryWrapper.eq(YearPigBaseEntity::getEartag, pigEarTagNo);
|
|
|
-
|
|
|
- YearPigBaseEntity yearPigBaseEntity = baseMapper.selectOne(lambdaQueryWrapper);
|
|
|
+ public Map<String, Object> getPigInfoByEarTagNo(String pigEarTagNo) {
|
|
|
+
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>(16);
|
|
|
+ List<Map<String, Object>> temperature = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> healthStatus = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> feedingStatus = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> sleepStatus = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> sportStatus = new ArrayList<>();
|
|
|
+ result.put("temperature", temperature);
|
|
|
+ result.put("healthStatus", healthStatus);
|
|
|
+ result.put("feedingStatus", feedingStatus);
|
|
|
+ result.put("sleepStatus", sleepStatus);
|
|
|
+ result.put("sportStatus", sportStatus);
|
|
|
+
|
|
|
+ //公用时间 -> 当前日期
|
|
|
+ String today = DateUtil.format(DateUtil.date(), "yyyy-MM-dd");
|
|
|
+
|
|
|
+ //java代码对集合排序
|
|
|
+ //CollectionUtil.sort(animalHeatEntityList,(o1, o2) -> o2.getCollectTime().compareTo(o1.getCollectTime()));
|
|
|
+
|
|
|
+ //体温数据sql构建和查询
|
|
|
+ LambdaQueryWrapper<AnimalHeatEntity> temperatureLambdaQuery = Wrappers.lambdaQuery();
|
|
|
+ temperatureLambdaQuery.eq(AnimalHeatEntity::getEartag, pigEarTagNo)
|
|
|
+ .eq(AnimalHeatEntity::getNowDate, today)
|
|
|
+ .orderByDesc(AnimalHeatEntity::getId);
|
|
|
+ List<AnimalHeatEntity> animalHeatEntityList = animalHeatDao.selectList(temperatureLambdaQuery);
|
|
|
+
|
|
|
+ //体温数据
|
|
|
+ if (CollectionUtil.isNotEmpty(animalHeatEntityList)) {
|
|
|
+ for (AnimalHeatEntity animalHeatEntity : animalHeatEntityList) {
|
|
|
+ Map<String, Object> dataMap = new LinkedHashMap<>(16);
|
|
|
+ dataMap.put("collectTime", DateUtil.format(animalHeatEntity.getCollectTime(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ dataMap.put("temperature", animalHeatEntity.getTemperature());
|
|
|
+ temperature.add(dataMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ //健康状态数据sql构建及查询
|
|
|
+ //TODO 健康状态数据库查询
|
|
|
+ //模拟数据
|
|
|
+ Map<String, Object> healthData1 = new HashMap<>();
|
|
|
+ healthData1.put(DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss"), "健康");
|
|
|
+ Map<String, Object> healthData2 = new HashMap<>();
|
|
|
+ healthData2.put(DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss"), "亚健康");
|
|
|
+ healthStatus.add(healthData1);
|
|
|
+ healthStatus.add(healthData2);
|
|
|
+
|
|
|
+ //采食状态数据sql构建及查询
|
|
|
+ LambdaQueryWrapper<EatTimeEntity> eatTimeLambdaQuery = Wrappers.lambdaQuery();
|
|
|
+ eatTimeLambdaQuery.eq(EatTimeEntity::getEartag, pigEarTagNo)
|
|
|
+ .eq(EatTimeEntity::getNowDate, today)
|
|
|
+ .orderByDesc(EatTimeEntity::getId);
|
|
|
+ List<EatTimeEntity> eatTimeEntityList = eatTimeDao.selectList(eatTimeLambdaQuery);
|
|
|
+
|
|
|
+ //采食状态数据
|
|
|
+ if (CollectionUtil.isNotEmpty(eatTimeEntityList)) {
|
|
|
+ for (EatTimeEntity eatTimeEntity : eatTimeEntityList) {
|
|
|
+ Map<String, Object> dataMap = new LinkedHashMap<>(16);
|
|
|
+ dataMap.put("collectTime", DateUtil.format(eatTimeEntity.getCollectTime(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ dataMap.put("feedCount", eatTimeEntity.getEatCount());
|
|
|
+ feedingStatus.add(dataMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- PigBaseVo pigBaseVo = new PigBaseVo();
|
|
|
-// BeanUtil.copyProperties(yearPigBaseEntity,pigBaseVo);
|
|
|
- if (ObjectUtil.isNotNull(yearPigBaseEntity)) {
|
|
|
- pigBaseVo.setWeight(yearPigBaseEntity.getWeight());
|
|
|
- pigBaseVo.setDayAge(yearPigBaseEntity.getDayAge());
|
|
|
- pigBaseVo.setBreed(yearPigBaseEntity.getBreed());
|
|
|
- //虚拟数据 待填充
|
|
|
- pigBaseVo.setBirthday(new Date());
|
|
|
- Integer unitId = yearPigBaseEntity.getUnitId();
|
|
|
- PigstyEntity pigstyEntity = null;
|
|
|
- if (unitId != null) {
|
|
|
- pigstyEntity = pigstyDao.selectById(unitId);
|
|
|
+ //睡眠状态数据sql构建及查询
|
|
|
+ LambdaQueryWrapper<SleepStatusEntity> sleepStatusLambdaQuery = Wrappers.lambdaQuery();
|
|
|
+ sleepStatusLambdaQuery.eq(SleepStatusEntity::getEartag, pigEarTagNo)
|
|
|
+ .eq(SleepStatusEntity::getNowDate, today)
|
|
|
+ .orderByDesc(SleepStatusEntity::getId);
|
|
|
+ List<SleepStatusEntity> sleepStatusEntityList = sleepStatusDao.selectList(sleepStatusLambdaQuery);
|
|
|
+
|
|
|
+ //睡眠状态数据
|
|
|
+ if (CollectionUtil.isNotEmpty(sleepStatusEntityList)) {
|
|
|
+ for (SleepStatusEntity sleepStatusEntity : sleepStatusEntityList) {
|
|
|
+ Map<String, Object> dataMap = new LinkedHashMap<>(16);
|
|
|
+ dataMap.put("sleepStartTime", sleepStatusEntity.getSleepTime());
|
|
|
+ dataMap.put("duration", sleepStatusEntity.getSleepCount());
|
|
|
+ sleepStatus.add(dataMap);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (ObjectUtil.isNotNull(pigstyEntity)) {
|
|
|
- String number = pigstyEntity.getNumber();
|
|
|
- if (StringUtils.isNotEmpty(number)) {
|
|
|
- pigBaseVo.setPigsty(number);
|
|
|
- }
|
|
|
+ //运动状态数据sql构建及查询
|
|
|
+ LambdaQueryWrapper<SportTimeEntity> sportStatusLambdaQuery = Wrappers.lambdaQuery();
|
|
|
+ sportStatusLambdaQuery.eq(SportTimeEntity::getEartag,pigEarTagNo)
|
|
|
+ .eq(SportTimeEntity::getNowDate,today)
|
|
|
+ .orderByDesc(SportTimeEntity::getId);
|
|
|
+ List<SportTimeEntity> sportTimeEntityList = sportTimeDao.selectList(sportStatusLambdaQuery);
|
|
|
+
|
|
|
+ //运动状态数据
|
|
|
+ if (CollectionUtil.isNotEmpty(sportTimeEntityList)) {
|
|
|
+ for (SportTimeEntity sportTimeEntity : sportTimeEntityList) {
|
|
|
+ Map<String, Object> dataMap = new LinkedHashMap<>(16);
|
|
|
+ dataMap.put("collectTime", sportTimeEntity.getCollectTime());
|
|
|
+ dataMap.put("sportCount", sportTimeEntity.getSportCount());
|
|
|
+ sportStatus.add(dataMap);
|
|
|
}
|
|
|
- //虚拟数据 待填充
|
|
|
- pigBaseVo.setBodyTemperature("100");
|
|
|
}
|
|
|
- return pigBaseVo;
|
|
|
+
|
|
|
+
|
|
|
+// //构建根据耳标查询的表达式
|
|
|
+// LambdaQueryWrapper<YearPigBaseEntity> yearPigLambdaQuery = Wrappers.lambdaQuery();
|
|
|
+// yearPigLambdaQuery.eq(YearPigBaseEntity::getEartag, pigEarTagNo);
|
|
|
+//
|
|
|
+// //根据耳标查询猪的信息
|
|
|
+// YearPigBaseEntity yearPigBaseEntity = baseMapper.selectOne(yearPigLambdaQuery);
|
|
|
+//
|
|
|
+// //构建返回前端的VO对象
|
|
|
+// PigBaseVo pigBaseVo = new PigBaseVo();
|
|
|
+// if (ObjectUtil.isNotNull(yearPigBaseEntity)) {
|
|
|
+// pigBaseVo.setWeight(yearPigBaseEntity.getWeight());
|
|
|
+// pigBaseVo.setDayAge(yearPigBaseEntity.getDayAge());
|
|
|
+// pigBaseVo.setBreed(yearPigBaseEntity.getBreed());
|
|
|
+// pigBaseVo.setBirthday(yearPigBaseEntity.getBirthday());
|
|
|
+//
|
|
|
+// Integer pigstyId = yearPigBaseEntity.getPigstyId();
|
|
|
+// if (pigstyId != null) {
|
|
|
+// String pastureName = baseMapper.selectPastureNameByPigstyId(pigstyId);
|
|
|
+// if (StringUtils.isNotEmpty(pastureName)) {
|
|
|
+// pigBaseVo.setPasture(pastureName);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// LambdaQueryWrapper<AnimalHeatEntity> animalHeatLambdaQuery = Wrappers.lambdaQuery();
|
|
|
+// animalHeatLambdaQuery.eq(AnimalHeatEntity::getEartag, pigEarTagNo).orderByDesc(AnimalHeatEntity::getCollectTime);
|
|
|
+// animalHeatLambdaQuery.last("limit 1");
|
|
|
+// AnimalHeatEntity animalHeatEntity = animalHeatDao.selectOne(animalHeatLambdaQuery);
|
|
|
+// if (ObjectUtil.isNotNull(animalHeatEntity)) {
|
|
|
+// Double temperature = animalHeatEntity.getTemperature();
|
|
|
+// if (temperature != null) {
|
|
|
+// pigBaseVo.setBodyTemperature(temperature);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -91,10 +198,10 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
PigImageVo pigImageVo = new PigImageVo();
|
|
|
|
|
|
pigImageVo.setPigEarTagNo(pigEarTagNo);
|
|
|
- String img = yearPigHistoryImgDao.getLatestImgByPigEarTagNo(pigEarTagNo);
|
|
|
- if (StringUtils.isNotEmpty(img)) {
|
|
|
+ List<String> images = yearPigHistoryImgDao.getLatestImgByPigEarTagNo(pigEarTagNo);
|
|
|
+ if (CollectionUtil.isNotEmpty(images)) {
|
|
|
//String encodeImg = Base64.encode(img);
|
|
|
- pigImageVo.setImageData(img);
|
|
|
+ pigImageVo.setImages(images);
|
|
|
}
|
|
|
return pigImageVo;
|
|
|
}
|
|
@@ -122,11 +229,11 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
if (ObjectUtil.isNotNull(pigstyEntity)) {
|
|
|
String number = pigstyEntity.getNumber();
|
|
|
if (StringUtils.isNotEmpty(number)) {
|
|
|
- pigBaseVo.setPigsty(number);
|
|
|
+// pigBaseVo.setPigsty(number);
|
|
|
}
|
|
|
}
|
|
|
//虚拟数据 待填充
|
|
|
- pigBaseVo.setBodyTemperature("100");
|
|
|
+ pigBaseVo.setBodyTemperature(100D);
|
|
|
pigBaseVoList.add(pigBaseVo);
|
|
|
}
|
|
|
}
|
|
@@ -208,7 +315,7 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
LambdaQueryWrapper<SportTimeEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
|
//虚假数据
|
|
|
- lambdaQueryWrapper.eq(SportTimeEntity::getEartag,pigEarTagNo);
|
|
|
+ lambdaQueryWrapper.eq(SportTimeEntity::getEartag, pigEarTagNo);
|
|
|
SportTimeEntity sportTimeEntity = sportTimeDao.selectOne(lambdaQueryWrapper);
|
|
|
sportVo.setActivityAmount(sportTimeEntity.getSportCount());
|
|
|
sportVo.setPigEartagNo(pigEarTagNo);
|
|
@@ -220,7 +327,7 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
|
|
|
//虚假数据
|
|
|
LambdaQueryWrapper<SleepStatusEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
- lambdaQueryWrapper.eq(SleepStatusEntity::getEartag,pigEarTagNo);
|
|
|
+ lambdaQueryWrapper.eq(SleepStatusEntity::getEartag, pigEarTagNo);
|
|
|
SleepStatusEntity sleepStatusEntity = sleepStatusDao.selectOne(lambdaQueryWrapper);
|
|
|
|
|
|
|