CZT
2023-11-27 68e19f643c315cfd639c8547f349fe2607282604
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
77
78
79
package com.ld.igds.io.notify;
 
import com.ld.igds.constant.Constant;
import com.ld.igds.oa.dto.GpsData;
import com.ld.igds.oa.dto.GpsLocationData;
import com.ld.igds.oa.service.CoreGpsService;
import com.ld.igds.util.ContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
import java.util.Date;
 
@Slf4j
@Repository(NotifyGpsMacService.BEAN_ID)
public class NotifyGpsMacServiceImpl implements NotifyGpsMacService {
 
    @Autowired
    private CoreGpsService coreGpsService;
 
    @Override
    public void registerAndAuthNotify(GpsData data) {
        //判断组织编码是否为空
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getDefaultCompanyId());
        }
        data.setUpdateTime(new Date());
 
        //更新GPS设备到数据库
        data.setStatus(Constant.YN_Y);
        coreGpsService.updateGps(data);
 
        //更新GPS设备信息到缓存
        coreGpsService.updateCacheListGpsData(data);
    }
 
    @Override
    public void locationNotify(GpsLocationData data) {
 
        //设置数据id,更新位置信息到数据库
        data.setRecordId(ContextUtil.getUUID());
        coreGpsService.updateGpsRecord(data);
 
        //更新设备位置信息到缓存
        coreGpsService.updateCacheLocationData(data);
    }
 
    @Override
    public void onCreate(String address, Integer port) {
        // 更新状态
        coreGpsService.updateGpsStatus(address, port, Constant.YN_Y);
    }
 
    @Override
    public void onDestroy(String address, Integer port) {
        // 更新状态
        coreGpsService.updateGpsStatus(address, port, Constant.YN_Y);
    }
 
    @Override
    public boolean authSn(GpsData data) {
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getDefaultCompanyId());
        }
        GpsData gpsData = coreGpsService.getCacheBySerialNum(data.getCompanyId(), data.getSn());
        if (gpsData == null) {
            log.info("GPS设备登录,没有获取到注册信息,拒绝登录,请求信息:" + data.toString());
            return false;
        }
        //更新设备数据到数据库
        coreGpsService.updateGps(data);
 
        //更新缓存信息
        coreGpsService.updateCacheListGpsData(data);
        return true;
    }
 
}