Newspaper 1 year ago
parent
commit
6a3f0e4e6e

+ 4 - 1
huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/config/RestTemplateConfig.java

@@ -13,6 +13,7 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
 import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
 import org.springframework.data.redis.serializer.StringRedisSerializer;
 import org.springframework.data.redis.serializer.StringRedisSerializer;
 import org.springframework.http.client.ClientHttpRequestFactory;
 import org.springframework.http.client.ClientHttpRequestFactory;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
@@ -36,12 +37,14 @@ public class RestTemplateConfig {
     @Bean
     @Bean
     public RedisTemplate<String,Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory){
     public RedisTemplate<String,Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory){
         RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
         RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
+        GenericJackson2JsonRedisSerializer jsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
         //设置String类型的key设置序列化器
         //设置String类型的key设置序列化器
         redisTemplate.setKeySerializer(new StringRedisSerializer());
         redisTemplate.setKeySerializer(new StringRedisSerializer());
 
 
         //设置Hash类型的key设置序列化器
         //设置Hash类型的key设置序列化器
         redisTemplate.setHashKeySerializer(new StringRedisSerializer());
         redisTemplate.setHashKeySerializer(new StringRedisSerializer());
-
+        redisTemplate.setValueSerializer(jsonRedisSerializer);
+        redisTemplate.setHashValueSerializer(jsonRedisSerializer);
         //设置redis链接Lettuce工厂
         //设置redis链接Lettuce工厂
         redisTemplate.setConnectionFactory(lettuceConnectionFactory);
         redisTemplate.setConnectionFactory(lettuceConnectionFactory);
         return redisTemplate;
         return redisTemplate;

+ 5 - 6
huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/impl/EartagServiceImpl.java

@@ -33,6 +33,8 @@ public class EartagServiceImpl implements IEartagService {
     private RedisTemplate redisTemplate;
     private RedisTemplate redisTemplate;
     @Autowired
     @Autowired
     private EartagDataRepo eartagDataRepo;
     private EartagDataRepo eartagDataRepo;
+    @Autowired
+    private EartagData2Mapper eartagData2Mapper;
 
 
     //处理耳标信息
     //处理耳标信息
     @Override
     @Override
@@ -69,9 +71,6 @@ 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 earmark, String nowAct,String farmId) {
     public Integer countAct(String earmark, String nowAct,String farmId) {
 
 
@@ -83,7 +82,7 @@ public class EartagServiceImpl implements IEartagService {
 //        int nowActInt = Integer.parseInt(nowAct);
 //        int nowActInt = Integer.parseInt(nowAct);
 //        return  nowActInt < lastAct ?  nowActInt: nowActInt - lastAct;
 //        return  nowActInt < lastAct ?  nowActInt: nowActInt - lastAct;
 
 
-
+        int nowActInt = Integer.parseInt(nowAct);
         //读取hash
         //读取hash
         Object actObj = redisTemplate.opsForHash().get(earmark, "act");
         Object actObj = redisTemplate.opsForHash().get(earmark, "act");
         if (actObj == null) {
         if (actObj == null) {
@@ -92,11 +91,11 @@ public class EartagServiceImpl implements IEartagService {
             Object lastAct = redisTemplate.opsForHash().get(earmark, "act");
             Object lastAct = redisTemplate.opsForHash().get(earmark, "act");
             if (lastAct == null) {
             if (lastAct == null) {
                 log.error("#--- redis数据库有问题,请检查redis是否能正常连接 ---# ");
                 log.error("#--- redis数据库有问题,请检查redis是否能正常连接 ---# ");
-                return 0;
+                return nowActInt;
             }
             }
         }
         }
         int lastAct = Integer.parseInt(redisTemplate.opsForHash().get(earmark, "act").toString());
         int lastAct = Integer.parseInt(redisTemplate.opsForHash().get(earmark, "act").toString());
-        int nowActInt = Integer.parseInt(nowAct);
+
         return  nowActInt < lastAct ?  nowActInt: nowActInt - lastAct;
         return  nowActInt < lastAct ?  nowActInt: nowActInt - lastAct;