|
|
|
|
|
|
|
|
|
|
|
package com.taauav.admin.job; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
|
import com.drew.imaging.ImageMetadataReader; |
|
|
|
|
|
import com.drew.metadata.Directory; |
|
|
|
|
|
import com.drew.metadata.Metadata; |
|
|
|
|
|
import com.drew.metadata.Tag; |
|
|
|
|
|
import com.taauav.admin.entity.TauvInspectFile; |
|
|
|
|
|
import com.taauav.admin.service.IMapService; |
|
|
|
|
|
import com.taauav.admin.service.ITauvInspectFileService; |
|
|
|
|
|
import com.taauav.common.util.FunctionUtils; |
|
|
|
|
|
import com.taauav.common.util.RedisUtils; |
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* <p>GPS </p> |
|
|
|
|
|
* |
|
|
|
|
|
* @author : dyg |
|
|
|
|
|
* @date : 2019-12-17 15:12 |
|
|
|
|
|
**/ |
|
|
|
|
|
@Component |
|
|
|
|
|
public class GpsController { |
|
|
|
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(GpsController.class); |
|
|
|
|
|
|
|
|
|
|
|
@Value("${file.uploadFolder}") |
|
|
|
|
|
private String fileFolder; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
@Qualifier("baiduMap") |
|
|
|
|
|
private IMapService baiduMap; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
@Qualifier("gaodeMap") |
|
|
|
|
|
private IMapService gaodeMap; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ITauvInspectFileService iTauvInspectFileService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
@Scheduled(fixedRate = 40000) |
|
|
|
|
|
public void run() { |
|
|
|
|
|
QueryWrapper<TauvInspectFile> wrapper = new QueryWrapper<>(); |
|
|
|
|
|
wrapper.eq("check_status",2); |
|
|
|
|
|
wrapper.eq("mark", 1); |
|
|
|
|
|
wrapper.isNotNull("original_img"); |
|
|
|
|
|
wrapper.last("limit 10"); |
|
|
|
|
|
List<TauvInspectFile> list = iTauvInspectFileService.list(wrapper); |
|
|
|
|
|
if (list!= null) { |
|
|
|
|
|
list.forEach(info->{ |
|
|
|
|
|
String file = fileFolder+info.getOriginalImg(); |
|
|
|
|
|
Map<String,String> gpsInfo = getGpsInfo(file); |
|
|
|
|
|
String baiduAddress = ""; |
|
|
|
|
|
String gaodeAddress = ""; |
|
|
|
|
|
String gaodeLat = ""; |
|
|
|
|
|
String gaodeLon = ""; |
|
|
|
|
|
String baiduLat = ""; |
|
|
|
|
|
String baiduLon = ""; |
|
|
|
|
|
if (gpsInfo != null) { |
|
|
|
|
|
String latitude = FunctionUtils.Dms2D(gpsInfo.get("GPS Latitude"));//纬度 |
|
|
|
|
|
String longitude = FunctionUtils.Dms2D(gpsInfo.get("GPS Longitude"));//经度 |
|
|
|
|
|
//获取百度坐标 |
|
|
|
|
|
List<Map<String,String>> gpsList = baiduMap.getGpsList(longitude+","+latitude); |
|
|
|
|
|
if (!StringUtils.isEmpty(gpsList) && gpsList.size()>0) { |
|
|
|
|
|
Map<String,String> gpsData = gpsList.get(0); |
|
|
|
|
|
baiduLat = gpsData.get("lat"); |
|
|
|
|
|
baiduLon = gpsData.get("lon"); |
|
|
|
|
|
baiduAddress = baiduMap.getMapInfo(baiduLon,baiduLat); |
|
|
|
|
|
} |
|
|
|
|
|
//获取高德地图坐标 |
|
|
|
|
|
List<Map<String,String>> gpsGaodeList = gaodeMap.getGpsList(longitude+","+latitude); |
|
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(gpsGaodeList) && gpsGaodeList.size()>0) { |
|
|
|
|
|
Map<String,String> gpsGdData = gpsGaodeList.get(0); |
|
|
|
|
|
gaodeLat = gpsGdData.get("lat"); |
|
|
|
|
|
gaodeLon = gpsGdData.get("lon"); |
|
|
|
|
|
gaodeAddress = gaodeMap.getMapInfo(gaodeLon, gaodeLat); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TauvInspectFile inspectFile = new TauvInspectFile(); |
|
|
|
|
|
inspectFile.setId(info.getId()); |
|
|
|
|
|
if (StringUtils.isEmpty(latitude) || StringUtils.isEmpty(longitude)) { |
|
|
|
|
|
inspectFile.setCheckStatus(3); |
|
|
|
|
|
} else { |
|
|
|
|
|
inspectFile.setLatitude(latitude); |
|
|
|
|
|
inspectFile.setLongitude(longitude); |
|
|
|
|
|
|
|
|
|
|
|
inspectFile.setBaiduLatitude(baiduLat); |
|
|
|
|
|
inspectFile.setBaiduLongitude(baiduLon); |
|
|
|
|
|
inspectFile.setBaiduAddress(baiduAddress); |
|
|
|
|
|
|
|
|
|
|
|
inspectFile.setGaodeLatitude(gaodeLat); |
|
|
|
|
|
inspectFile.setGaodeLongitude(gaodeLon); |
|
|
|
|
|
inspectFile.setGaodeAddress(gaodeAddress); |
|
|
|
|
|
|
|
|
|
|
|
inspectFile.setCheckStatus(1); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//iTauvInspectFileService.updateData(inspectFile); |
|
|
|
|
|
iTauvInspectFileService.updateById(inspectFile); |
|
|
|
|
|
}else { |
|
|
|
|
|
TauvInspectFile inspectFile = new TauvInspectFile(); |
|
|
|
|
|
inspectFile.setId(info.getId()); |
|
|
|
|
|
inspectFile.setCheckStatus(1); |
|
|
|
|
|
iTauvInspectFileService.updateById(inspectFile); |
|
|
|
|
|
} |
|
|
|
|
|
String key = "HK_InspectFile_info_"+info.getId(); |
|
|
|
|
|
redisUtils.del(key); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map<String,String> getGpsInfo(String fileStr) |
|
|
|
|
|
{ |
|
|
|
|
|
File file = new File(fileStr); |
|
|
|
|
|
if (!file.exists()) { |
|
|
|
|
|
System.out.println("文件"+fileStr+"不存在"); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
Map<String,String> mapInfo = new HashMap<>(); |
|
|
|
|
|
try{ |
|
|
|
|
|
Metadata metadata = ImageMetadataReader.readMetadata(file); |
|
|
|
|
|
for (Directory directory : metadata.getDirectories()) { |
|
|
|
|
|
for (Tag tag : directory.getTags()) { |
|
|
|
|
|
String name = tag.getTagName(); |
|
|
|
|
|
if (name.contains("GPS")) { |
|
|
|
|
|
String value = tag.getDescription(); |
|
|
|
|
|
mapInfo.put(name,value); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}catch (Exception e) { |
|
|
|
|
|
logger.info(e.getMessage()); |
|
|
|
|
|
return mapInfo; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mapInfo; |
|
|
|
|
|
} |
|
|
|
|
|
} |