PictureHandle.java
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.objecteye.handle;
import com.alibaba.fastjson.JSON;
import com.objecteye.entity.ResponseParam;
import com.objecteye.entity.UploadVehicleResult;
import com.objecteye.entity.VpAnalysisParam;
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;
@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;
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);
uploadVehicleResult.setImageUrl(picUrl);
uploadVehicleResult.setCaptureTime(timeStamp);
String s = JSON.toJSONString(uploadVehicleResult);
}
}
}
}