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 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); } } } }