|
@@ -2,6 +2,7 @@ package com.huimv.apiservice.service.impl;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
@@ -20,6 +21,7 @@ import com.huimv.common.exception.RRException;
|
|
|
import com.huimv.common.utils.PageUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
@@ -36,6 +38,9 @@ import java.util.*;
|
|
|
public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> implements PigService {
|
|
|
|
|
|
@Autowired
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private AnimalHeatDao animalHeatDao;
|
|
|
|
|
|
@Autowired
|
|
@@ -60,110 +65,61 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
private SportTimeDao sportTimeDao;
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> getPigInfoByEarTagNo(String pigEarTagNo) {
|
|
|
+ public PigHealthStatusVo getPigInfoByEarTagNo(String pigEarTagNo) {
|
|
|
|
|
|
+ //耳标检查
|
|
|
checkPigEarTagNo(pigEarTagNo);
|
|
|
|
|
|
- Map<String, Object> result = new LinkedHashMap<>(16);
|
|
|
- List<Map<String, Object>> temperature = 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("feedingStatus", feedingStatus);
|
|
|
+ //当前时间节点
|
|
|
+ DateTime currentTime = DateUtil.date();
|
|
|
|
|
|
- boolean health = baseMapper.selectHealthStatus(pigEarTagNo);
|
|
|
- result.put("healthStatus", health ? "健康" : "不健康");
|
|
|
- result.put("sleepStatus", sleepStatus);
|
|
|
- result.put("sportStatus", sportStatus);
|
|
|
+// String lastGetDataTime = (String) redisTemplate.opsForHash().get("offset_record", "getPigInfo");
|
|
|
+// redisTemplate.opsForHash().put("offset_record", "getPigInfo",currentTime.toString());
|
|
|
|
|
|
+ PigHealthStatusVo pigHealthStatusVo = new PigHealthStatusVo();
|
|
|
+ boolean health = baseMapper.selectHealthStatus(pigEarTagNo);
|
|
|
+ pigHealthStatusVo.setHealthStatus(health ? "健康" : "不健康");
|
|
|
|
|
|
//公用时间 -> 当前日期
|
|
|
- String today = DateUtil.format(DateUtil.date(), "yyyy-MM-dd");
|
|
|
-
|
|
|
-
|
|
|
- //java代码对集合排序
|
|
|
- //CollectionUtil.sort(animalHeatEntityList,(o1, o2) -> o2.getCollectTime().compareTo(o1.getCollectTime()));
|
|
|
+ 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<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);
|
|
|
+ List<AnimalHeatVo> animalHeatVoList = animalHeatDao.selectAnimalHeatVoList(temperatureLambdaQuery);
|
|
|
+ pigHealthStatusVo.setTemperature(animalHeatVoList);
|
|
|
|
|
|
//采食状态数据sql构建及查询
|
|
|
LambdaQueryWrapper<EatTimeEntity> eatTimeLambdaQuery = Wrappers.lambdaQuery();
|
|
|
eatTimeLambdaQuery.eq(EatTimeEntity::getEartag, pigEarTagNo)
|
|
|
.eq(EatTimeEntity::getNowDate, today)
|
|
|
+ .eq(EatTimeEntity::getDeleted, 0)
|
|
|
.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);
|
|
|
- }
|
|
|
- }
|
|
|
+ List<EatTimeVo> eatTimeVoList = eatTimeDao.selectEatTimeVoList(eatTimeLambdaQuery);
|
|
|
+ pigHealthStatusVo.setFeedingStatus(eatTimeVoList);
|
|
|
|
|
|
//睡眠状态数据sql构建及查询
|
|
|
LambdaQueryWrapper<SleepStatusEntity> sleepStatusLambdaQuery = Wrappers.lambdaQuery();
|
|
|
sleepStatusLambdaQuery.eq(SleepStatusEntity::getEartag, pigEarTagNo)
|
|
|
.eq(SleepStatusEntity::getNowDate, today)
|
|
|
+ .eq(SleepStatusEntity::getDeleted, 0)
|
|
|
.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);
|
|
|
- }
|
|
|
- }
|
|
|
+ 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<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);
|
|
|
- }
|
|
|
- }
|
|
|
+ List<SportTimeVo> sportTimeVoList = sportTimeDao.selectSportTimeVoList(sportStatusLambdaQuery);
|
|
|
+ pigHealthStatusVo.setSportStatus(sportTimeVoList);
|
|
|
|
|
|
- return result;
|
|
|
+ return pigHealthStatusVo;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -187,10 +143,6 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
@Override
|
|
|
public PageUtils getPageByBreedAndFence(String breedName, Integer currentPage, Integer pageSize, String period) {
|
|
|
|
|
|
-// if (StringUtils.isEmpty(breedName)) {
|
|
|
-// throw new RRException("品种名称不能为空!", 1001);
|
|
|
-// }
|
|
|
-
|
|
|
Integer count = baseMapper.selectCount(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getBreed, breedName));
|
|
|
if (count <= 0) {
|
|
|
throw new RRException("品种名称不存在,请检查!", 1001);
|
|
@@ -236,7 +188,7 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
LambdaQueryWrapper<IndoorEnvironmentEntity> indoorEnvLambdaQuery = Wrappers.lambdaQuery();
|
|
|
indoorEnvLambdaQuery.eq(IndoorEnvironmentEntity::getPigstyId, pigstyId)
|
|
|
.eq(IndoorEnvironmentEntity::getDate, today)
|
|
|
- .le(IndoorEnvironmentEntity::getCollectTime,new Date())
|
|
|
+ .le(IndoorEnvironmentEntity::getCollectTime, new Date())
|
|
|
.orderByDesc(IndoorEnvironmentEntity::getId);
|
|
|
List<IndoorEnvironmentEntity> indoorEnvironmentEntityList = indoorEnvironmentDao.selectList(indoorEnvLambdaQuery);
|
|
|
|
|
@@ -254,7 +206,7 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
|
|
|
LambdaQueryWrapper<OutdoorEnvironmentEntity> outdoorEnvLambdaQuery = Wrappers.lambdaQuery();
|
|
|
outdoorEnvLambdaQuery.eq(OutdoorEnvironmentEntity::getDate, today)
|
|
|
- .le(OutdoorEnvironmentEntity::getCollectTime,new Date())
|
|
|
+ .le(OutdoorEnvironmentEntity::getCollectTime, new Date())
|
|
|
.orderByDesc(OutdoorEnvironmentEntity::getId);
|
|
|
List<OutdoorEnvironmentEntity> outdoorEnvironmentEntityList = outdoorEnvironmentDao.selectList(outdoorEnvLambdaQuery);
|
|
|
if (CollectionUtil.isNotEmpty(outdoorEnvironmentEntityList)) {
|
|
@@ -310,7 +262,7 @@ public class PigServiceImpl extends ServiceImpl<PigDao, YearPigBaseEntity> imple
|
|
|
pigBaseLambdaUpdate.eq(YearPigBaseEntity::getEartag, pigEarTagNo)
|
|
|
.set(YearPigBaseEntity::getDeleted, System.currentTimeMillis())
|
|
|
.set(YearPigBaseEntity::getFosterStatus, false)
|
|
|
- .set(YearPigBaseEntity::getOutFenceTime,new Date())
|
|
|
+ .set(YearPigBaseEntity::getOutFenceTime, new Date())
|
|
|
.set(YearPigBaseEntity::getOutFenceStatus, status);
|
|
|
|
|
|
update(pigBaseLambdaUpdate);
|