rk
2025-09-24 6c82e309443f491eda73a95c01386becec69224b
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.doumee.service.impl;
 
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.haikang.model.HKTools;
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.model.param.request.EventSubRequest;
import com.doumee.core.haikang.model.param.respose.OrgInfoResponse;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.utils.Constants;
import com.doumee.dao.system.model.SystemDictData;
import com.doumee.service.business.InterfaceLogService;
import com.doumee.service.business.impl.hksync.HkSyncBaseServiceImpl;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.PostConstruct;
import java.util.Date;
 
/**
 * 海康事件订阅表Service实现
 * @author 江蹄蹄
 * @date 2023/11/30 15:33
 */
@Service
public class HkSyncEventServiceImpl extends HkSyncBaseServiceImpl {
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private InterfaceLogService interfaceLogService;
 
    @PostConstruct
    public  int  initHkConfig(){
        //获取根组织编码
        initHkParamConfig();
        getRootOrgCode();
        //开始订阅门禁事件、访客事件、和停车场事件
        startHkEventSub();
        return  0;
    }
 
    public  int  initHkParamConfig(){
        ArtemisConfig.host = systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_HOST).getCode();
        ArtemisConfig.appKey = systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_APPKEY).getCode();
        ArtemisConfig.appSecret = systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_APPSECRET).getCode();
        HKConstants.https = systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_HTTPS).getCode();
        HKTools.interfaceLogService=interfaceLogService;
        return  0;
    }
    /**
     *    获取根组织编码
     */
    private void getRootOrgCode() {
        SystemDictData org =  systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_ROOTORG_CODE);
        if(org!=null){
            SystemDictData orgName =  systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_ROOTORG_NAME);
            String rootOrgId =org.getCode();
            if(StringUtils.isBlank(rootOrgId)){
                BaseResponse<OrgInfoResponse> res = HKService.getRootOrg(null);
                if(res !=null && res.getData()!=null && StringUtils.isNotBlank(res.getData().getOrgIndexCode())){
                    org.setCode(res.getData().getOrgIndexCode());
                    org.setUpdateTime(new Date());
                    systemDictDataBiz.updateById( org);
 
                    orgName.setCode(res.getData().getOrgName());
                    orgName.setUpdateTime(new Date());
                    systemDictDataBiz.updateById( orgName);
                }
            }
        }
    }
 
    /**
     * 订阅门禁事件、访客事件、和停车场事件
     */
    public void startHkEventSub(){
        cancelEventSub();
        EventSubRequest param = new EventSubRequest();
        String path =systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_PUSH_URL).getCode();
        param.setEventDest(path+"/parks");
        param.setEventTypes(new Integer[]{HKConstants.EventTypes.PARK_LINE_IN.getKey()
                ,HKConstants.EventTypes.PARK_LINE_OUT.getKey()
                ,HKConstants.EventTypes.PARK_PASS_IN.getKey()
                ,HKConstants.EventTypes.PARK_PASS_OUT.getKey() });
        HKService.cancelEventSub(param);////先取消
        HKService.eventSub(param);//停车场事件
 
        param.setEventDest(path+"/visit");
        param.setEventTypes(new Integer[]{HKConstants.EventTypes.VISIT_SIGN_IN.getKey()
                ,HKConstants.EventTypes.VISIT_SIGN_OUT.getKey()});
        HKService.cancelEventSub(param);//先取消
        HKService.eventSub(param);//访客事件
 
        param.setEventDest(path+"/acs");
        param.setEventTypes(new Integer[]{HKConstants.EventTypes.DOOR_FACE_AUTH_FAIL.getKey(),HKConstants.EventTypes.DOOR_FACE_AUTH_SUCCESS.getKey()});
        HKService.cancelEventSub(param);//先取消
        HKService.eventSub(param);//门禁事件
 
        param.setEventDest(path+"/visitIccm");
        param.setEventTypes(new Integer[]{HKConstants.EventTypes.VISIT_SIGN_ICCM_IN.getKey()
                ,HKConstants.EventTypes.VISIT_SIGN_ICCM_PASS.getKey()
                ,HKConstants.EventTypes.VISIT_SIGN_ICCM_OUT.getKey()});
        HKService.cancelEventSub(param);//先取消
        HKService.eventSub(param);//访客事件
 
        param.setEventDest(path+"/platform/workstatus");
        param.setEventTypes(new Integer[]{HKConstants.EventTypes.PLATFORM_WORKSTATUS.getKey()});
        HKService.cancelEventSub(param);//先取消
//        HKService.eventSub(param);//月台工作状态事件
 
 
        param.setEventDest(path+"/platform/carstatus");
        param.setEventTypes(new Integer[]{HKConstants.EventTypes.PLATFORM_CAR_STATUS.getKey()});
        HKService.cancelEventSub(param);//先取消
        HKService.eventSub(param);//月台车辆状态事件
 
    }
    /**
     * 取消订阅门禁事件、访客事件、和停车场事件
     */
    @Override
    public void cancelEventSub(){
        EventSubRequest param = new EventSubRequest();
        param.setEventTypes(new Integer[]{HKConstants.EventTypes.PARK_LINE_IN.getKey()
                ,HKConstants.EventTypes.PARK_LINE_OUT.getKey()
                ,HKConstants.EventTypes.PARK_PASS_IN.getKey()
                ,HKConstants.EventTypes.PARK_PASS_OUT.getKey()
                ,HKConstants.EventTypes.VISIT_SIGN_IN.getKey()
                ,HKConstants.EventTypes.VISIT_SIGN_OUT.getKey(),
                HKConstants.EventTypes.DOOR_FACE_AUTH_SUCCESS.getKey()});
        String path =systemDictDataBiz.queryByCode(Constants.HK_PARAM, Constants.HK_PUSH_URL).getCode();
        param.setEventDest(path);
        HKService.cancelEventSub(param);//停车场事件
 
    }
}