CZT
2023-08-31 6b1c7e3fa773aa75ea34b346d4104ba70064f52c
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
66
67
68
69
70
71
72
73
74
75
76
package com.ld.igds.m.manager;
 
 
import com.ld.igds.oa.dto.AssetData;
import com.ld.igds.oa.dto.GpsLocationData;
import com.ld.igds.oa.service.CoreGpsService;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.GpsToBdUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
 
/**
 * 资产定位
 */
@Slf4j
@Component
public class OAManager {
    @Autowired
    private CoreGpsService coreGpsService;
 
    /**
     * 获取
     *
     * @param companyId
     * @return
     */
    public List<AssetData> getGpsLocation(String companyId) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
        //查询固定资产设备(绑定有GPS且状态正常)
        List<AssetData> assetList = coreGpsService.getAsset(companyId);
 
        if (assetList == null) {
            log.debug("没有查到相关固定资产设备信息");
            return null;
        }
 
        //获取缓存中设备位置信息
        Map<String, GpsLocationData> mapLocations = coreGpsService.cacheListLocationData(companyId);
 
        if(mapLocations==null){
            log.debug("没有查到设备位置信息");
            return null;
        }
 
        //遍历资产设备,设置经纬度位置信息
        GpsLocationData gpsLocationData = null;
        for (AssetData assetData : assetList) {
             gpsLocationData = mapLocations.get(assetData.getGpsPhone());
             if(gpsLocationData == null) {
                 continue;
             }
            if(StringUtils.isNotEmpty(gpsLocationData.getLongitude())){
                assetData.setLongitude(gpsLocationData.getLongitude());
            }
            if(StringUtils.isNotEmpty(gpsLocationData.getLatitude())){
                assetData.setLatitude(gpsLocationData.getLatitude());
            }
            assetData.setUpdateTime(gpsLocationData.getUpdateTime());
        }
 
        //转GPS坐标到百度
        for (AssetData assetData : assetList) {
            String[] baiDu = GpsToBdUtil.getBaiDu(assetData.getLatitude(), assetData.getLongitude());
            assetData.setLatitude(baiDu[0]);
            assetData.setLongitude(baiDu[1]);
        }
 
        return assetList;
    }
}