Demo.java 18.8 KB
Newer Older
zhaojg committed
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
package com.example.demo;

import cn.cigem.data.sync.config.CommunicationConfig;
import cn.cigem.data.sync.model.PayloadContent;
import cn.cigem.data.sync.service.IBusinessService;
import cn.cigem.data.sync.service.ICommunicationService;
import cn.cigem.data.sync.service.ISecretService;
import cn.cigem.data.sync.service.IShareService;
import cn.cigem.data.sync.service.impl.*;
import cn.cigem.data.sync.utility.PayloadWrapperUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.brilliance.bo.RspComBo;
import com.brilliance.bo.RspMonitorPointAllBo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;


/**
 * 建立与加解密网关的通讯
 */
@Slf4j
@Service
public class Demo {

    public final IBusinessService _businessService;
    public final EspEncryption _encryption;
    private final IShareService _shareService;


    /*public Demo(IBusinessService iBusinessService, EspEncryption espEncryption ,IShareService iShareService) {
        this.iBusinessService = iBusinessService;
        this.espEncryption = espEncryption;
        this._shareService = iShareService;
    }*/

    public Demo() {
        ICommunicationService iCommunicationService = before();
        IBusinessService iBusinessService = new BusinessService(iCommunicationService);
        ISecretService iSecretService = new SecretService(iCommunicationService);
        EspEncryption espEncryption = new EspEncryption(iSecretService);
        IShareService iShareService = new ShareService(iCommunicationService);
        this._shareService = iShareService;
        this._businessService = iBusinessService;
        this._encryption = espEncryption;
    }






    public static ICommunicationService before(){

        RestTemplate restTemplate = new RestTemplate();
        CommunicationConfig communicationConfig = new CommunicationConfig();
        communicationConfig.setAccessKey("621b965d7ee24dbc");
        communicationConfig.setSecretKey("fb7e13e69b6648d59dcaaf4800d1c349");
        ICommunicationService iCommunicationService = new CommunicationService(restTemplate,communicationConfig);
        return iCommunicationService;
    }

    /**
     * 2.3.5.监测点下设备及传感器列表
     * @param
     * @throws Exception
     */
    public static String getMonitorPointInfo(String payload){

        ICommunicationService iCommunicationService = before();
        IBusinessService iBusinessService = new BusinessService(iCommunicationService);
        return iBusinessService.getMonitorDeviceList(payload);
    }



    //2.3.4.监测点列表
    public void main() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("key", "云岩区黔灵镇");
        p.put("year", "");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .params(p)
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _businessService.getMonitorPointAll(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }

    //2.3.5.监测点详情
    public void getMonitorPointInfo() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("areaCode", "430281");
        p.put("startDate","2024-10-30 15:34:01");
        p.put("endDate","");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .params(p)
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getDataPoint(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }

    //2.3.6.监测点下设备及传感器列表
    public void getMonitorDeviceList() throws Exception {

        Map<String, String> p = new HashMap<>();
        p.put("monitorpointcode", "520102020004");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .params(p)
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _businessService.getMonitorDeviceList(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }

    //2.3.7.监测数据获取
    public void getDBDataPoints() throws Exception {

        Map<String, String> p = new HashMap<>();
        p.put("sensorcode", "4302810000130101YL01");
        p.put("start","2024-10-30 15:34:01");
        p.put("end","");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .params(p)
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _businessService.getDBDataPoints(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }


    //2.3.9.地震速报数据获取
    public void getEarthReport() throws Exception {

        _encryption.initiate();
        Map<String, String> p = new HashMap<>();
        p.put("lon", "102.79");
        p.put("lat", "35.70");
        p.put("time", "2023-12-18 23:59:30");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .body(JSONObject.toJSONString(p))
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getEarthReport(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);

    }

    //2.3.10.重大事件速报数据获取
    public void getImportReport() throws Exception {

        Map<String, String> p = new HashMap<>();
        p.put("eventname", "");
        p.put("period","1");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .body(JSONObject.toJSONString(p))
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getImportReport(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());
    }

    //2.3.11.不同时间段不同地区设备在线率
    public void getAvgOnlineRate() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
216
        p.put("areaCode", "520100");
zhaojg committed
217 218 219 220 221 222 223 224 225 226 227 228 229
        p.put("startDate","2024-10-30");
        p.put("endDate","2024-11-7");
        p.put("manufacturerName", "");
        p.put("typeArr", "");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .params(p)
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getAvgOnlineRate(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
230 231 232
        JSONObject json = JSONObject.parseObject(jsonStr);
        json.getInteger("status");
        log.info("status++++++:" + json.getInteger("status"));
zhaojg committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }

    //2.3.12.各省/厂商设备在线率及排名
    public void getOnlineRateRank() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("type", "2");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .params(p)
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getOnlineRateRank(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }

    //2.3.13.气象速报数据获取
    public void getWeatherReport() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("date", "2024-10-05");
        p.put("period","1");
        p.put("hour","24");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .body(JSONObject.toJSONString(p))
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getWeatherReport(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }

    //2.3.14.地震二期速报未来24小时趋势数据获取
    public void getEarthReportTrendData() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("lon", "102.79");
        p.put("lat", "35.70");
        p.put("time", "2023-12-18 23:59:30");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .body(JSONObject.toJSONString(p))
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getEarthReportTrendData(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }

    /*//2.3.15.不同时间段不同地区设备和传感器类型和个数
    public void getDeviceAndSensorCount() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("startTime", "2023-10-20 00:00:00");
        p.put("endTime", "");
        p.put("areaCode", "630100");
        p.put("deviceType", "");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .body(JSONObject.toJSONString(p))
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getDeviceAndSensorCount(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }

    //2.3.16.不同时间段不同地区预警处置和虚警情况
    public void getWarnMsgDisposeRate() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("startTime", "2024-10-20 00:00:00");
        p.put("endTime", "2024-11-06 23:59:59");
        p.put("areaCode", "");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .body(JSONObject.toJSONString(p))
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getWarnMsgDisposeRate(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }


    //2.3.17.按年统计每月在线率
    public void getOnlineRateOfMonth() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("year", "2023");
        p.put("areaCode", "");
        p.put("typeArr", "设备,地表位移");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .params(p)
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getOnlineRateOfMonth(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }

    //2.3.18.按年统计每月处置率、虚警率
    public void getWarnMsgDisposeRateOfMonth() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("year", "2023");
        p.put("areaCode", "");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .params(p)
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getWarnMsgDisposeRateOfMonth(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<RspMonitorPointAllBo> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<RspMonitorPointAllBo>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }*/

    //2.3.19.关键字查询厂商集合
    public void getManuInfosBySimpleName() throws Exception {
        int cod = _encryption.initiate();
        log.info("建立与加解密网关的通讯结果:",cod);
        Map<String, String> p = new HashMap<>();
        p.put("simplename", "中物");
        byte[] jsonBytes = JSON.toJSONBytes(PayloadContent.builder()
                .params(p)
                .build());
        byte[] encrypt = _encryption.encrypt(jsonBytes);
        String payload = PayloadWrapperUtil.byte2hex(encrypt);
        String result = _shareService.getManuInfosBySimpleName(payload);
        String jsonStr = new String(_encryption.decrypt(PayloadWrapperUtil.hex2byte(result)));
        log.info("jsonstr++++++:" + jsonStr);
        jsonStr = jsonStr.substring(1,jsonStr.length()-1).replace("\\","");
        log.info("jsonstr++++++:" + jsonStr);
        RspComBo<String> rsp = JSONObject.parseObject(jsonStr,  new TypeReference<RspComBo<String>>() {});
        log.info("rsp++++++:" + rsp.toString());

    }
}