package com.ningdatech.carapi.open;

import java.sql.Timestamp;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.ningdatech.cache.redis.RedisOps;
import com.ningdatech.cache.repository.CachePlusOps;
import com.ningdatech.carapi.AppTests;
import com.ningdatech.carapi.car.vehicle.model.NdVehicleBaseInfo;
import com.ningdatech.carapi.car.vehicle.service.IVehicleBaseInfoService;
import com.ningdatech.carapi.homepage.entity.model.OnlineNumCnt;
import com.ningdatech.carapi.irs.model.entity.VehicleAccidentIrsData;
import com.ningdatech.carapi.irs.service.IVehicleAccidentIrsDataService;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @Classname OpenApiTest
 * @Description
 * @Date 2022/11/3 10:47
 * @Created by PoffyZhang
 */
@Slf4j
public class OpenApiTest extends AppTests {

    @Autowired
    private IVehicleBaseInfoService vehicleBaseInfoService;
    @Autowired
    private CachePlusOps cachePlusOps;
    @Autowired
    private IVehicleAccidentIrsDataService accidentIrsDataService;

    @Autowired
    private RedisOps redisOps;


    @Test
    public void test(){

        TreeMap<String, String> fieldMap = new TreeMap<>();
        fieldMap.put("appKey","test");
        fieldMap.put("timestamps","1667444946960");
        fieldMap.put("originPicId","0000001");
        fieldMap.put("vehicleIndexCode","10000001");
        fieldMap.put("vehicleSelfNo","20000001");
        fieldMap.put("cameraIndexCode","sssss00001");
        fieldMap.put("cameraName","监控点1");
        fieldMap.put("uploadType","2");
        fieldMap.put("alarmId","300000001");
        fieldMap.put("alarmType","1001");
        fieldMap.put("alarmTypeName","开车接听电话");
        fieldMap.put("captureTime","2022-10-28");
        fieldMap.put("url","https://www.baidu.com");
        fieldMap.put("thumbUrl","1");
        fieldMap.put("parentPicId","1");
        fieldMap.put("faceRect","2");
        fieldMap.put("picType","3");
        fieldMap.put("plateNo","浙Axxxx");
        fieldMap.put("regionIndexCode","330107");
        fieldMap.put("regionName","滨江区");
        fieldMap.put("serialVersionUID","1");
        String appSecret = "test";
        String str = "{\"appKey\":\"test\",\"timestamps\":1667444946960,\"originPicId\":\"0000001\",\"vehicleIndexCode\":\"10000001\",\"vehicleSelfNo\":\"20000001\",\"cameraIndexCode\":\"sssss00001\",\"cameraName\":\"监控点1\",\"uploadType\":2,\n" +
                "    \"alarmId\":\"300000001\",\"alarmType\":\"1001\",\"alarmTypeName\":\"开车接听电话\",\"captureTime\":\"2022-10-28\",\"url\":\"https://www.baidu.com\",\"thumbUrl\":\"1\",\n" +
                "    \"parentPicId\":\"1\",\"faceRect\":\"2\",\"picType\":\"3\",\"plateNo\":\"浙Axxxx\",\"regionIndexCode\":\"330107\",\"regionName\":\"滨江区\"}";
//        TreeMap<String, String> fieldMap = jsonStrToMap(str);
        String paramStr = fieldMap.entrySet().stream()
                .map(w -> w.getKey() + "=" + w.getValue())
                .collect(Collectors.joining("&"));
        String hex = SecureUtil.hmacMd5(appSecret).digestHex(paramStr);
        System.out.println(hex);
    }

    @Test
    public void sysout(){
        System.out.println(System.currentTimeMillis());
    }

    @Test
    public void video(){
        TreeMap<String, String> fieldMap = new TreeMap<>();
        fieldMap.put("appKey","test");
        fieldMap.put("timestamps","1667444946960");
        fieldMap.put("orginVideoId","0000001");
        fieldMap.put("serviceIndexCode","4000001");
        fieldMap.put("recordIndexCode","0001");
        fieldMap.put("vehicleIndexCode","10000001");
        fieldMap.put("vehicleSelfNo","20000001");
        fieldMap.put("cameraIndexCode","sssss00001");
        fieldMap.put("cameraName","监控点1");
        fieldMap.put("alarmId","300000001");
        fieldMap.put("alarmTime","2022-11-06 00:00:00");
        fieldMap.put("alarmType","1001");
        fieldMap.put("alarmTypeName","开车接听电话");
        fieldMap.put("url","https://www.baidu.com");
        fieldMap.put("coverUrl","1");
        fieldMap.put("beginTime","2022-11-02 00:00:00");
        fieldMap.put("endTime","2022-11-02 00:00:00");
        fieldMap.put("streamBeginTime","2022-11-02 00:00:00");
        fieldMap.put("streamEndTime","2022-11-02 00:00:00");
        fieldMap.put("regionIndexCode","330107");
        fieldMap.put("regionName","滨江区");
        fieldMap.put("videoLength","60");
        fieldMap.put("plateNo","浙Axxxx");
        fieldMap.put("serialVersionUID","1");
        String appSecret = "test";
        String str = "{\"appKey\":\"test\",\"timestamps\":1667444946960,\"originPicId\":\"0000001\",\"vehicleIndexCode\":\"10000001\",\"vehicleSelfNo\":\"20000001\",\"cameraIndexCode\":\"sssss00001\",\"cameraName\":\"监控点1\",\"uploadType\":2,\n" +
                "    \"alarmId\":\"300000001\",\"alarmType\":\"1001\",\"alarmTypeName\":\"开车接听电话\",\"captureTime\":\"2022-10-28\",\"url\":\"https://www.baidu.com\",\"thumbUrl\":\"1\",\n" +
                "    \"parentPicId\":\"1\",\"faceRect\":\"2\",\"picType\":\"3\",\"plateNo\":\"浙Axxxx\",\"regionIndexCode\":\"330107\",\"regionName\":\"滨江区\"}";
//        TreeMap<String, String> fieldMap = jsonStrToMap(str);
        String paramStr = fieldMap.entrySet().stream()
                .map(w -> w.getKey() + "=" + w.getValue())
                .collect(Collectors.joining("&"));
        String hex = SecureUtil.hmacMd5(appSecret).digestHex(paramStr);
        System.out.println(hex);
    }

    private final Integer cnt1 = 0;
    @Test
    public void onlineNum(){
        // 获取所有车辆信息
        List<NdVehicleBaseInfo> vehicleBaseInfos = vehicleBaseInfoService.list(Wrappers.lambdaQuery(NdVehicleBaseInfo.class)
                .select(NdVehicleBaseInfo::getCarPlate, NdVehicleBaseInfo::getOperatorId,
                        NdVehicleBaseInfo::getId));

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        Map<String, Integer> onlineMap = redisOps.hGetAll("online_index");
        // 分批
        List<List<NdVehicleBaseInfo>> batchList = new ArrayList<>(ListUtil.partition(new ArrayList<>(vehicleBaseInfos), 5000));
        // 创建线程池 线程数是 分批的数
        ExecutorService executorService = Executors.newFixedThreadPool(batchList.size());
        //线程计数器,就是 分批的数
        CountDownLatch countDownLatch = new CountDownLatch(batchList.size());
        List<OnlineNumCnt> cntList = Lists.newArrayList();
        batchList.forEach(e -> {
            //每个分批用一个线程执行
            executorService.execute(()->{
                List<NdVehicleBaseInfo> result = e.stream().filter(v -> {
                    // 取到每个数据进行业务执行
                    String carPlate = v.getCarPlate();
                    LocalDateTime startTime = LocalDateTime.now();
                    Integer timeStamp = onlineMap.get(carPlate);
                    if (Objects.nonNull(timeStamp)) {
                        // 将时间戳转换为Instant对象
                        Instant instant = Instant.ofEpochSecond(timeStamp);
                        // 将Instant对象转换为LocalDateTime对象
                        LocalDateTime endTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
                        Duration minuteDuration = Duration.between(startTime, endTime);
                        long minute = minuteDuration.toMinutes();
                        // 判断最后一次上传时间距离当前时间是否大于5分钟
                        if (minute <= 5) {
                            return true;
                        }
                    }
                    return false;
                }).collect(Collectors.toList());
                OnlineNumCnt onlineNumCnt = new OnlineNumCnt();
                onlineNumCnt.setCnt(result.size());
                cntList.add(onlineNumCnt);
            });
            countDownLatch.countDown();
        });

        stopWatch.stop();
        log.info("共耗时 {}s", stopWatch.getTotalTimeSeconds());
        int cnt = 0;
        for (OnlineNumCnt onlineNumCnt : cntList) {
            Integer onlineNum = onlineNumCnt.getCnt();
            cnt = cnt + onlineNum;
        }
        log.info("缓存中车辆在线数为：" + cnt);
    }

    @Test
    public void jsonTest(){
        // 获取车牌号的所有事故信息
        //Map<String, List<VehicleAccidentIrsData>> accidentIrsDataMap = accidentIrsDataService.list().stream()
        //        .collect(Collectors.groupingBy(VehicleAccidentIrsData::getCarPlate));

        // 获取车牌号的所有事故信息
        Map<String, List<VehicleAccidentIrsData>> accidentIrsDataMap = null;
        //String dataJsonStr = "{\"code\":\"00\",\"msg\":\"成功\",\"data\":\"\",\"datas\":\"[[{\\\"TJSGBH\\\":null,\\\"LM\\\":\\\"海\n" +
        //        "宁市农丰路\\\",\\\"CLJSG\\\":\\\"6\\\",\\\"SSRS\\\":0,\\\"LWSGLX\\\":null,\\\"BADW\\\":\\\"海宁市公安局交通警察大队\\\",\\\"DCSG\\\":null,\\\"SCSJD\\\":0,\\\"RDYYFL\\\":null,\\\"GLS\\\":1003,\\\"SB\\\":null,\\\"GLBM\\\":\\\"330481006200\\\",\\\"SGFSSJ\\\":1678750636000\n" +
        //        ",\\\"CCLRSJ\\\":1678751217000,\\\"SGRDYY\\\":null,\\\"JBR\\\":\\\"朱洁林\\\",\\\"ZBLX\\\":null,\\\"JYAQ\\\":\\\"2023年03月14日07时37分许，朱晨霓 (驾驶证号:330481198408070022) 驾驶车辆号牌浙F9230F小型汽车，在浙江省嘉兴市海宁市硖石街道农丰\n" +
        //        "路南苑路口 与田夫勇 (驾驶证号:371322197609083813) 驾驶车辆号牌浙FM8761大型汽车发生交通事故。当事人朱晨霓转弯未让直行车辆先行负全责；当事人田夫勇负无责。\\\",\\\"DZZB\\\":\\\"120.700542,30.514331\\\",\\\"SWSG\\\":null,\\\"SJHM1\\\n" +
        //        "\":\\\"13656604531\\\",\\\"SJHM2\\\":null,\\\"MS\\\":0,\\\"GXSJ\\\":1678751230000,\\\"JYW\\\":\\\"59076598972026599116453825079992\\\",\\\"DAH\\\":null,\\\"XC\\\":null,\\\"DJBH\\\":\\\"33048120230011595\\\",\\\"JLLX\\\":null,\\\"SSZD\\\":\\\"330481006200\\\",\\\"GLX\n" +
        //        "ZDJ\\\":null,\\\"XZQH\\\":\\\"330481\\\",\\\"PZFS\\\":null,\\\"SGDD\\\":\\\"海宁市农丰路(南苑路口)\\\",\\\"TJR1\\\":null,\\\"LBQK\\\":null,\\\"DLLX\\\":\\\"22\\\",\\\"SFZMHM1\\\":\\\"330482198203205719\\\",\\\"SGXT\\\":\\\"11\\\",\\\"ZJCCSS\\\":1,\\\"SFZMHM2\\\":null,\\\"XQ\\\n" +
        //        "\":2,\\\"LH\\\":\\\"67014\\\",\\\"SGBH\\\":\\\"330481420230011578\\\",\\\"TQ\\\":\\\"1\\\",\\\"JDWZ\\\":550},{\\\"TJSGBH\\\":null,\\\"LM\\\":\\\"海宁市马桥街道经编四路\\\",\\\"CLJSG\\\":\\\"9\\\",\\\"SSRS\\\":0,\\\"LWSGLX\\\":null,\\\"BADW\\\":\\\"海宁市公安局交通警察大队\\\"\n" +
        //        ",\\\"DCSG\\\":null,\\\"SCSJD\\\":0,\\\"RDYYFL\\\":null,\\\"GLS\\\":1002,\\\"SB\\\":null,\\\"GLBM\\\":\\\"330481005200\\\",\\\"SGFSSJ\\\":1678848921000,\\\"CCLRSJ\\\":1678852288000,\\\"SGRDYY\\\":null,\\\"JBR\\\":\\\"刘晓林\\\",\\\"ZBLX\\\":null,\\\"JYAQ\\\":\\\"2023年0\n" +
        //        "3月15日10时55分许，史帅彪 (驾驶证号:412326199705092718) 驾驶车辆号牌浙F2BL86轻型货车，在浙江省嘉兴市海宁市马桥街道经编四路16号海宁市彩达包装材料有限公司厂内 因操作失误与田夫勇 (驾驶证号:371322197609083813) 驾驶\n" +
        //        "车辆号牌浙FM8761重型货车发生交通事故，造成财产损失，当事人史帅彪负全责，当事人田夫勇负无责；。\\\",\\\"DZZB\\\":\\\"120.678630,30.479932\\\",\\\"SWSG\\\":null,\\\"SJHM1\\\":\\\"15167388545\\\",\\\"SJHM2\\\":null,\\\"MS\\\":0,\\\"GXSJ\\\":1678852\n" +
        //        "301000,\\\"JYW\\\":\\\"99790670379267313188861065794064\\\",\\\"DAH\\\":null,\\\"XC\\\":null,\\\"DJBH\\\":\\\"33048120230011858\\\",\\\"JLLX\\\":null,\\\"SSZD\\\":\\\"330481005200\\\",\\\"GLXZDJ\\\":null,\\\"XZQH\\\":\\\"330481\\\",\\\"PZFS\\\":null,\\\"SGDD\\\":\\\"海\n" +
        //        "宁市马桥街道经编四路(经编三路至新民路)\\\",\\\"TJR1\\\":null,\\\"LBQK\\\":null,\\\"DLLX\\\":\\\"29\\\",\\\"SFZMHM1\\\":\\\"33048119881119501X\\\",\\\"SGXT\\\":\\\"12\\\",\\\"ZJCCSS\\\":1000,\\\"SFZMHM2\\\":null,\\\"XQ\\\":3,\\\"LH\\\":\\\"97010\\\",\\\"SGBH\\\":\\\"33048\n" +
        //        "1420230011840\\\",\\\"TQ\\\":\\\"1\\\",\\\"JDWZ\\\":200},{\\\"TJSGBH\\\":null,\\\"LM\\\":\\\"常海线（G524）\\\",\\\"CLJSG\\\":\\\"7\\\",\\\"SSRS\\\":1,\\\"LWSGLX\\\":null,\\\"BADW\\\":\\\"海宁市公安局交通警察大队\\\",\\\"DCSG\\\":null,\\\"SCSJD\\\":0,\\\"RDYYFL\\\":null,\\\"\n" +
        //        "GLS\\\":180,\\\"SB\\\":\\\"1\\\",\\\"GLBM\\\":\\\"330481000000\\\",\\\"SGFSSJ\\\":1679614140000,\\\"CCLRSJ\\\":1679630991000,\\\"SGRDYY\\\":null,\\\"JBR\\\":\\\"韩家振\\\",\\\"ZBLX\\\":\\\"2\\\",\\\"JYAQ\\\":\\\"    2023年03月24日07时29分，徐银甫(男，65岁)驾驶车\n" +
        //        "牌号为浙FCZ483的普通摩托车，沿常海线（G524）行驶至常海线（G524）185KM+382M海宁市汇浪桥路段时，与田夫勇(男，47岁)驾驶车牌号为浙FM8761的重型货车碰撞运动车辆，致受伤1人，直接财产损失1000元的交通事故。\\\\r\\\\n    当事\n" +
        //        "人徐银甫负全部责任；当事人田夫勇无责任。\\\",\\\"DZZB\\\":null,\\\"SWSG\\\":null,\\\"SJHM1\\\":\\\"13806703150\\\",\\\"SJHM2\\\":null,\\\"MS\\\":10,\\\"GXSJ\\\":1679631053000,\\\"JYW\\\":\\\"07721463458575243981940373724857\\\",\\\"DAH\\\":null,\\\"XC\\\":n\n" +
        //        "ull,\\\"DJBH\\\":\\\"33048120230013692\\\",\\\"JLLX\\\":\\\"1\\\",\\\"SSZD\\\":null,\\\"GLXZDJ\\\":\\\"1\\\",\\\"XZQH\\\":\\\"330481\\\",\\\"PZFS\\\":null,\\\"SGDD\\\":\\\"常海线（G524）185KM+382M海宁市汇浪桥路段\\\",\\\"TJR1\\\":\\\"韩家振\\\",\\\"LBQK\\\":null,\\\"DLLX\\\"\n" +
        //        ":\\\"11\\\",\\\"SFZMHM1\\\":\\\"330419197212202035\\\",\\\"SGXT\\\":\\\"11\\\",\\\"ZJCCSS\\\":1000,\\\"SFZMHM2\\\":null,\\\"XQ\\\":5,\\\"LH\\\":\\\"10524\\\",\\\"SGBH\\\":\\\"330481420230013673\\\",\\\"TQ\\\":\\\"2\\\",\\\"JDWZ\\\":180010},{\\\"TJSGBH\\\":null,\\\"LM\\\":\\\"常海\n" +
        //        "线（G524）\\\",\\\"CLJSG\\\":\\\"9\\\",\\\"SSRS\\\":0,\\\"LWSGLX\\\":null,\\\"BADW\\\":\\\"海宁市公安局交通警察大队\\\",\\\"DCSG\\\":null,\\\"SCSJD\\\":112,\\\"RDYYFL\\\":null,\\\"GLS\\\":200,\\\"SB\\\":\\\"1\\\",\\\"GLBM\\\":\\\"330481000300\\\",\\\"SGFSSJ\\\":16796141400\n" +
        //        "00,\\\"CCLRSJ\\\":1689321834000,\\\"SGRDYY\\\":null,\\\"JBR\\\":\\\"陆远\\\",\\\"ZBLX\\\":\\\"2\\\",\\\"JYAQ\\\":\\\"    2023年03月24日07时29分，徐银甫(男，65岁)，骑其它，沿常海线（G524）行驶至常海线（G524）1公里111米时，与田夫勇(男，47岁)驾\n" +
        //        "驶车牌号为浙FM8761的重型货车碰撞运动车辆，致直接财产损失0元的交通事故。\\\\r\\\\n    当事人徐银甫负全部责任；当事人田夫勇无责任。\\\",\\\"DZZB\\\":null,\\\"SWSG\\\":null,\\\"SJHM1\\\":\\\"18457370603\\\",\\\"SJHM2\\\":\\\"13819319909\\\",\\\"M\n" +
        //        "S\\\":111,\\\"GXSJ\\\":1689321834000,\\\"JYW\\\":\\\"05491240436273013758918071494634\\\",\\\"DAH\\\":null,\\\"XC\\\":null,\\\"DJBH\\\":\\\"33048120230037409\\\",\\\"JLLX\\\":\\\"1\\\",\\\"SSZD\\\":\\\"330481005000\\\",\\\"GLXZDJ\\\":\\\"1\\\",\\\"XZQH\\\":\\\"330481\\\",\\\n" +
        //        "\"PZFS\\\":null,\\\"SGDD\\\":\\\"常海线（G524）1公里111米\\\",\\\"TJR1\\\":\\\"陆远\\\",\\\"LBQK\\\":null,\\\"DLLX\\\":\\\"11\\\",\\\"SFZMHM1\\\":\\\"330481199506031216\\\",\\\"SGXT\\\":\\\"11\\\",\\\"ZJCCSS\\\":0,\\\"SFZMHM2\\\":\\\"362426198008191311\\\",\\\"XQ\\\":5,\\\"LH\n" +
        //        "\\\":\\\"10524\\\",\\\"SGBH\\\":\\\"330481420230037382\\\",\\\"TQ\\\":\\\"1\\\",\\\"JDWZ\\\":200111}]]\",\"requestId\":\"60fb9ddf73b5ce135647e724e62428ae\",\"dataCount\":1,\"totalDataCount\":0,\"totalPage\":1}";

        String dataJsonStr = "{\"code\":\"00\",\"msg\":\"成功\",\"data\":\"\",\"datas\":\"[[{\\\"TJSGBH\\\":null,\\\"LM\\\":\\\"海\n" +
                "宁市俞家桥路\\\",\\\"CLJSG\\\":\\\"1\\\",\\\"SSRS\\\":0,\\\"LWSGLX\\\":null,\\\"BADW\\\":\\\"海宁市公安局交通警察大队\\\",\\\"DCSG\\\":null,\\\"SCSJD\\\":0,\\\"RDYYFL\\\":null,\\\"GLS\\\":1007,\\\"SB\\\":null,\\\"GLBM\\\":\\\"330481006200\\\",\\\"SGFSSJ\\\":16874026470\n" +
                "00,\\\"CCLRSJ\\\":1687403022000,\\\"SGRDYY\\\":null,\\\"JBR\\\":\\\"朱洁林\\\",\\\"ZBLX\\\":null,\\\"JYAQ\\\":\\\"2023年06月22日10时57分许，刘刚 (驾驶证号:341223198107042130) 驾驶车辆号牌浙F3KH62小型汽车，在浙江省嘉兴市海宁市硖石街道俞家\n" +
                "桥路东山公园 与代伟 (驾驶证号:510525199401023015) 驾驶车辆号牌浙FM9199小型汽车发生交通事故，造成两车损坏。当事人刘刚负无责；当事人代伟的行为违反在同车道行驶中，不按规定与前车保持必要的安全距离的 ，负全责。\\\",\\\"D\n" +
                "ZZB\\\":\\\"120.699347,30.531393\\\",\\\"SWSG\\\":null,\\\"SJHM1\\\":\\\"13656604531\\\",\\\"SJHM2\\\":null,\\\"MS\\\":0,\\\"GXSJ\\\":1687403047000,\\\"JYW\\\":\\\"85919282240453431800722251912676\\\",\\\"DAH\\\":null,\\\"XC\\\":null,\\\"DJBH\\\":\\\"330481202300\n" +
                "32093\\\",\\\"JLLX\\\":null,\\\"SSZD\\\":\\\"330481006200\\\",\\\"GLXZDJ\\\":null,\\\"XZQH\\\":\\\"330481\\\",\\\"PZFS\\\":null,\\\"SGDD\\\":\\\"海宁市俞家桥路(北关桥路口)\\\",\\\"TJR1\\\":null,\\\"LBQK\\\":null,\\\"DLLX\\\":\\\"22\\\",\\\"SFZMHM1\\\":\\\"330482198203205\n" +
                "719\\\",\\\"SGXT\\\":\\\"11\\\",\\\"ZJCCSS\\\":1,\\\"SFZMHM2\\\":null,\\\"XQ\\\":4,\\\"LH\\\":\\\"67012\\\",\\\"SGBH\\\":\\\"330481420230032068\\\",\\\"TQ\\\":\\\"2\\\",\\\"JDWZ\\\":860}]]\",\"requestId\":\"4b54394e5e7ec319ee991add8f9f69b9\",\"dataCount\":1,\"totalData\n" +
                "Count\":0,\"totalPage\":1}";

        JSONObject object = JSON.parseObject(dataJsonStr, JSONObject.class);
        String data = object.getString("datas");
        List<String> array = JSON.parseArray(data, String.class);
        if (CollUtil.isEmpty(array)) {
            log.info("该车牌号没有事故信息!");
            return;
        }
        String carPlate = "浙FM8761";
        if (CollUtil.isEmpty(array)) {
            log.info("该车牌号没有事故信息!");
            return;
        }
        for (String datas : array) {
            if (StrUtil.isNotBlank(datas)) {
                List<JSONObject> accidentArray = JSON.parseArray(datas, JSONObject.class);
                if (CollUtil.isEmpty(accidentArray)) {
                    log.info("该车牌号没有事故信息!");
                    continue;
                }

                for (JSONObject jsonObject : accidentArray) {
                    VehicleAccidentIrsData accidentIrsData = new VehicleAccidentIrsData();
                    accidentIrsData.setCarPlate(carPlate);
                    String jsonString = jsonObject.toJSONString();
                    accidentIrsData.setJsonStrData(jsonString);
                    // 获取事故日期
                    Timestamp sgfssj = jsonObject.getTimestamp("SGFSSJ");
                    LocalDateTime accidentTime = LocalDateTimeUtil.of(sgfssj);
                    if (accidentIrsDataMap.containsKey(carPlate)) {
                        List<VehicleAccidentIrsData> dataList = accidentIrsDataMap.get(carPlate);
                        Map<LocalDateTime, VehicleAccidentIrsData> dataMap = dataList.stream()
                                .collect(Collectors.toMap(VehicleAccidentIrsData::getAccidentTime, v -> v));
                        if (dataMap.containsKey(accidentTime)) {
                            VehicleAccidentIrsData irsData = dataMap.get(accidentTime);
                            // 数据已经存在
                            accidentIrsData.setId(irsData.getId());
                        }
                    }
                    accidentIrsData.setAccidentTime(accidentTime);
                    accidentIrsData.setCreateOn(LocalDateTime.now());
                    accidentIrsData.setUpdateOn(LocalDateTime.now());
                    accidentIrsDataService.saveOrUpdate(accidentIrsData);
                }
            }
        }
    }

    public TreeMap<String, String> jsonStrToMap(String jsonstr){
        TreeMap<String, String> map = new TreeMap();
        String[] split = jsonstr.split("&");
        for (String s : split) {
            String[] string = s.split("=");
            map.put(string[0],string[1]);
        }
        return map;
    }
}
