Blame view

src/main/java/com/objecteye/handle/PictureHandle.java 2.39 KB
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
1
2
3
4
  package com.objecteye.handle;
  
  import com.alibaba.fastjson.JSON;
  import com.objecteye.entity.ResponseParam;
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
5
6
  import com.objecteye.entity.UploadVehicleResult;
  import com.objecteye.entity.VpAnalysisParam;
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  import com.objecteye.utils.GlobalUtil;
  import com.objecteye.utils.TimeUtil;
  import org.springframework.amqp.rabbit.core.RabbitTemplate;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.data.redis.core.RedisTemplate;
  import org.springframework.scheduling.annotation.Async;
  import org.springframework.stereotype.Component;
  
  import java.io.File;
  import java.util.Map;
  
  /**
   * @author yumiu
   */
  @Component
  public class PictureHandle {
  
      @Autowired
      private RedisTemplate redisTemplate;
      @Autowired
      private RabbitTemplate rabbitTemplate;
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  
      @Value("${picture.storePath}")
      private String path2;
      @Value("${picture.http}")
      private String http;
      @Value("${requestFile}")
      private String url;
  
      @Async("taskExecutor")
      public void handlePic() {
          String picPath = (String) redisTemplate.opsForList().rightPop("picPath");
          Map<String, Integer> equipmentIpAndId = redisTemplate.opsForHash().entries("equipmentIpAndId");
          if (picPath != null) {
              long timeStamp = TimeUtil.getTimeStamp(picPath);
              String picFile = TimeUtil.getPicFile(picPath);
              String picUrl = http + picPath;
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
              String path = path2 + picPath;
              File file = new File(path);
  
              String body = GlobalUtil.httpExecute(url, file);
  
              ResponseParam responseParam = JSON.parseObject(body, ResponseParam.class);
              String code = responseParam.getCode();
              if ("0".equals(code)) {
                  String s1 = JSON.toJSONString(responseParam.getResult());
                  VpAnalysisParam vpAnalysisParam = JSON.parseObject(s1, VpAnalysisParam.class);
                  UploadVehicleResult uploadVehicleResult = new UploadVehicleResult();
                  uploadVehicleResult.setCount(vpAnalysisParam.getCount());
                  uploadVehicleResult.setInfo(vpAnalysisParam.getInfo());
                  uploadVehicleResult.setPicName(path);
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
59
                  uploadVehicleResult.setImageUrl(picUrl);
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
60
61
                  uploadVehicleResult.setCaptureTime(timeStamp);
                  String s = JSON.toJSONString(uploadVehicleResult);
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
62
63
64
65
              }
          }
      }
  }