|
@@ -1,7 +1,11 @@
|
|
package com.huimv.eartag2.service.impl;
|
|
package com.huimv.eartag2.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.huimv.eartag2.common.dao.entity.EartagDataEntity;
|
|
import com.huimv.eartag2.common.dao.entity.EartagDataEntity;
|
|
import com.huimv.eartag2.common.dao.repo.EartagDataRepo;
|
|
import com.huimv.eartag2.common.dao.repo.EartagDataRepo;
|
|
|
|
+import com.huimv.eartag2.mapper.EartagData2Mapper;
|
|
|
|
+import com.huimv.eartag2.pojo.EartagData;
|
|
import com.huimv.eartag2.service.IEartagService;
|
|
import com.huimv.eartag2.service.IEartagService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
@@ -65,26 +69,43 @@ public class EartagServiceImpl implements IEartagService {
|
|
* @Date : 2022/1/18
|
|
* @Date : 2022/1/18
|
|
* @Time : 15:25
|
|
* @Time : 15:25
|
|
*/
|
|
*/
|
|
|
|
+ @Autowired
|
|
|
|
+ private EartagData2Mapper eartagData2Mapper;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public Integer countAct(String deviceCode, String nowAct) {
|
|
|
|
- //读取hash
|
|
|
|
- Object actObj = redisTemplate.opsForHash().get(deviceCode, "act");
|
|
|
|
- if (actObj == null) {
|
|
|
|
- //--初始化最新的redis记录
|
|
|
|
- initRedisObj(deviceCode);
|
|
|
|
- Object lastAct = redisTemplate.opsForHash().get(deviceCode, "act");
|
|
|
|
- if (lastAct == null) {
|
|
|
|
- log.error("#--- redis数据库有问题,请检查redis是否能正常连接 ---# ");
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
|
|
+ public Integer countAct(String earmark, String nowAct,String farmId) {
|
|
|
|
+
|
|
|
|
+ EartagData eartagData = eartagData2Mapper.selectOne(new QueryWrapper<EartagData>().eq("farm_id", farmId).eq("earmark", earmark).orderByDesc("ask_time").last("limit 1"));
|
|
|
|
+ Integer lastAct = 0;
|
|
|
|
+ if (ObjectUtil.isNotEmpty(eartagData)){
|
|
|
|
+ lastAct = eartagData.getAct();
|
|
}
|
|
}
|
|
- Object lastAct = redisTemplate.opsForHash().get(deviceCode, "act");
|
|
|
|
- Integer act1 = Integer.parseInt(nowAct) - Integer.parseInt(lastAct.toString());
|
|
|
|
-// redisTemplate.opsForHash().put(deviceCode, "act1", act1);
|
|
|
|
- if(act1<0){
|
|
|
|
- return Integer.parseInt(nowAct);
|
|
|
|
|
|
+ int nowActInt = Integer.parseInt(nowAct);
|
|
|
|
+
|
|
|
|
+ if (lastAct <nowActInt ){
|
|
|
|
+ return nowActInt - lastAct;
|
|
|
|
+ }else {
|
|
|
|
+ return nowActInt;
|
|
}
|
|
}
|
|
- return act1;
|
|
|
|
|
|
+
|
|
|
|
+ //读取hash
|
|
|
|
+// Object actObj = redisTemplate.opsForHash().get(deviceCode, "act");
|
|
|
|
+// if (actObj == null) {
|
|
|
|
+// //--初始化最新的redis记录
|
|
|
|
+// initRedisObj(deviceCode);
|
|
|
|
+// Object lastAct = redisTemplate.opsForHash().get(deviceCode, "act");
|
|
|
|
+// if (lastAct == null) {
|
|
|
|
+// log.error("#--- redis数据库有问题,请检查redis是否能正常连接 ---# ");
|
|
|
|
+// return 0;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// Object lastAct = redisTemplate.opsForHash().get(deviceCode, "act");
|
|
|
|
+// Integer act1 = Integer.parseInt(nowAct) - Integer.parseInt(lastAct.toString());
|
|
|
|
+//// redisTemplate.opsForHash().put(deviceCode, "act1", act1);
|
|
|
|
+// if(act1<0){
|
|
|
|
+// return Integer.parseInt(nowAct);
|
|
|
|
+// }
|
|
|
|
+// return act1;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|