liuxiaolong
2019-05-06 0bc4f4c791437b39b8c30624f5c21f8c855dc61d
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
package com.cloud.retrieve.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cloud.common.utils.RestTemplateUtil;
import com.cloud.model.common.Result;
import com.cloud.retrieve.dao.CulOrDevDao;
import com.cloud.retrieve.model.EsDataQueryParam;
import com.cloud.retrieve.service.DeviceService;
import com.cloud.retrieve.service.EsDataService;
import com.cloud.retrieve.service.SearchPhotoService;
import com.cloud.retrieve.service.UserService;
import com.cloud.retrieve.utils.C_Es_Map;
import com.cloud.retrieve.utils.EnumStr;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
@Slf4j
@Service
public class EsDataServiceImpl implements EsDataService {
 
    @Autowired
    private EnumStr enumStr;
    @Autowired
    private CulOrDevDao culOrDevDao;
 
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private UserService userService;
 
    private SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
    private SimpleDateFormat sdfMouth = new SimpleDateFormat("yyyy-MM");
 
    private SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
@Autowired
    private SearchPhotoService searchPhotoService;
 
    /**
     * 首页  全部条件查询数据
     * @param esSearch
     * @return
     */
    public JSONObject getAllDataByMoreParams(EsDataQueryParam esSearch){
        String bsUrl = "http://"+enumStr.getEsHOSTNAME()+":"+enumStr.getEsHTTP_PORT();
        String esBaseUrl = enumStr.getEsIndexUrl()+enumStr.getEsSearch();
       JSONObject respView = new JSONObject();
        String reqJson = changeObjectToJson(esSearch);
        log.info("es 查询json 参数:==>"+reqJson);
        JSONObject dataBaseParams = JSONObject.parseObject(reqJson);
 
        JSONObject respData = null;
        String resp = RestTemplateUtil.post(bsUrl+esBaseUrl,dataBaseParams,MediaType.APPLICATION_JSON_UTF8, false);
        if(StringUtils.isNotEmpty(resp))
            respData = JSONObject.parseObject(resp);
        JSONObject hits = respData.getJSONObject("hits");
        Long total = hits.getLong("total");
        respView.put("total",total);
        JSONArray hits1 = hits.getJSONArray("hits");
            JSONArray jsonArray = new JSONArray();
        if (hits1!=null&& !hits1.isEmpty()){
            for (Object obj : hits1) {
                JSONObject hit = (JSONObject)obj;
                String id = hit.getString("_id");
                JSONObject source = hit.getJSONObject("_source");
                source.put("Id",id);
                // 返回数据处理
                respSource( source);
                jsonArray.add(source);
            }
        }
        // 添加 数据判断  是否添加数据待确认报警
        if (esSearch.getIsAlermSum()!=null && esSearch.getIsAlermSum()){
            if ("1".equals(esSearch.getAck_alarm())){
                respView.put("alarmSum",total);
                esSearch.setAck_alarm("0");
                Long  alarmSum = getIsAckAlarmSum(esSearch);
                respView.put("noAlarmSum",alarmSum);
                respView.put("allAlarmSum",alarmSum+total);
            }else if ("0".equals(esSearch.getAck_alarm())){
                esSearch.setAck_alarm("1");
                Long  alarmSum = getIsAckAlarmSum(esSearch);
                respView.put("alarmSum",alarmSum);
                respView.put("noAlarmSum",total);
                respView.put("allAlarmSum",alarmSum+total);
            }else{
                esSearch.setAck_alarm("1");
                Long  alarmSum = getIsAckAlarmSum(esSearch);
                respView.put("alarmSum",alarmSum);
                respView.put("noAlarmSum",total-alarmSum);
                respView.put("allAlarmSum",total);
            }
        }
        respView.put("esList",jsonArray);
        return respView;
    }
 
    /**
     *  分割 底库 数据条件
     * @param tCluAndBaseNameAndHub
     * @return  cluId baseName hubStatus
     */
    public String[] getCluAndBaseNameAndHub(String tCluAndBaseNameAndHub){
        return tCluAndBaseNameAndHub.split("\\$");
    }
 
    //  获取 待确认报警总数
    private Long getIsAckAlarmSum(EsDataQueryParam esSearch){
 
        String bsUrl = "http://"+enumStr.getEsHOSTNAME()+":"+enumStr.getEsHTTP_PORT();
        String esBaseUrl = enumStr.getEsIndexUrl()+enumStr.getEsSearch();
 
        String reqJson = changeObjectToJson(esSearch);
        log.info("es 查询json 参数:==>"+reqJson);
        JSONObject dataBaseParams = JSONObject.parseObject(reqJson);
        JSONObject respData = null;
        String resp = RestTemplateUtil.post(bsUrl+esBaseUrl,dataBaseParams,MediaType.APPLICATION_JSON_UTF8, false);
        if(StringUtils.isNotEmpty(resp))
            respData = JSONObject.parseObject(resp);
        JSONObject hits = respData.getJSONObject("hits");
        Long total = hits.getLong("total");
        return total;
    }
 
    // 修改确认报警
    @Override
    public JSONObject updateEsDataByEsId(String dataId, String ack_alarm) {
        String bsUrl = "http://"+enumStr.getEsHOSTNAME()+":"+enumStr.getEsHTTP_PORT();
        String esIndexUrl = enumStr.getEsIndexUrl();
        String[] nidexes = esIndexUrl.substring(1).split(",");
            JSONObject respView = new JSONObject();boolean isUpdate = false;
            int in = 0;
        for (String nidex : nidexes){
            String esType = in==0?enumStr.getEsPersonType():enumStr.getEsActionType();
            String esBaseUrl = "/"+nidex+esType+"/"+dataId+enumStr.getEsUpdate();
            String isRefresh = "?refresh=wait_for";   // wait_for 等候默认参数刷新 true 立即刷新
            String reqJson = "{\"doc\":{\"ack_alarm\":\"1\"},\"detect_noop\":false}";
            JSONObject dataBaseParams = JSONObject.parseObject(reqJson);
            log.info("修改url:"+bsUrl+esBaseUrl+isRefresh);
            log.info("修改Params:"+dataBaseParams.toJSONString());
            JSONObject respData = null;
            try {
                String resp = RestTemplateUtil.post(bsUrl+esBaseUrl+isRefresh,dataBaseParams,MediaType.APPLICATION_JSON_UTF8, false);
                if(StringUtils.isNotEmpty(resp))
                    respData = JSONObject.parseObject(resp);
            } catch (HttpClientErrorException e) {
                    log.info("es 修改确认报警信息:"+e.getLocalizedMessage());
//                e.printStackTrace();
            }
            if (respData != null && respData.getInteger("status") == null ){
                respView.put("update",1);
                respView.put("success",true);
                isUpdate = true;
                break;
            }
            in++;
        }
        if (!isUpdate){
            respView.put("update",0);
            respView.put("success",false);
        }
        return respView;
    }
// 查询摄像机报警记录===
    @Override
    public JSONObject findEsPersonAlarmDataByEquPage(Integer page, Integer size,String equId,String personIsHub) {
        String bsUrl = "http://"+enumStr.getEsHOSTNAME()+":"+enumStr.getEsHTTP_PORT();
        String esBaseUrl = enumStr.getEsIndexUrl()+enumStr.getEsSearch();
        JSONObject respView = new JSONObject();
        int from = (page-1)*size;
        String frimJson = allQueryJson.replace("fromNum", "" + from);
        String sizeJson = frimJson.replace("sizeNum", "" + size);
        String queryParams = ""; boolean  isAddParams = false; //  查询 term 拼接  // 是否 term 有内容
       if (personIsHub != null && "1".equals(personIsHub)){
            String hubTerm = term.replace("eqiId","1");
            String isHubTerm = hubTerm.replace("videoReqNum","personIsHub");
           if (isAddParams){queryParams+=",";}else {isAddParams = true; } //  查询条件分隔符
            queryParams+=isHubTerm;
       }
        if(equId!=null &&!equId.isEmpty()){
            String equTerm = term.replace("eqiId",equId);
            if (isAddParams){queryParams+=",";}else {isAddParams = true; } //  查询条件分隔符
            queryParams+=equTerm;
        }else {
            log.info("es 查询条件中equId未知:"+equId);
        }
        if (sizeJson.contains("shouldParams")) sizeJson = sizeJson .replace(",shouldParams","");
//        log.info("es 查询json 待拼接参数:==>"+queryParams);
        String reqJson = sizeJson.replace("addSearchParams", queryParams);
 
 
        reqJson = reqJson.replace("sdkTypes","");
        reqJson = reqJson.replace("scoreSort","");
//        log.info("es 查询json 参数:==>"+reqJson);
        JSONObject dataBaseParams = JSONObject.parseObject(reqJson);
        JSONObject respData = null;
        String resp = RestTemplateUtil.post(bsUrl+esBaseUrl,dataBaseParams,MediaType.APPLICATION_JSON_UTF8,false);
        if(StringUtils.isNotEmpty(resp))
            respData = JSONObject.parseObject(resp);
        JSONObject hits = respData.getJSONObject("hits");
        String total = hits.getString("total");
        respView.put("total",total);
        JSONArray hits1 = hits.getJSONArray("hits");
        JSONArray jsonArray = new JSONArray();
        if (hits1!=null&& !hits1.isEmpty()){
            for (Object obj : hits1) {
                JSONObject hit = (JSONObject)obj;
                String id = hit.getString("_id");
                JSONObject source = hit.getJSONObject("_source");
                source.put("Id",id);
                // 返回数据处理
                respSource( source);
                jsonArray.add(source);
            }
        }
        respView.put("equList",jsonArray);
        return respView;
    }
 
    private  String  allAlarmJson = "{\"from\":page,\"size\":number,\"query\":{\"bool\":{\"must\":[" +
            "{\"terms\":{\"ack_alarm\":[\"0\",\"\"]}},{\"term\":{\"personIsHub\":\"1\"}}daterange]}}," +
            "\"_source\":[\"BaseName\",\"Gender\",\"Id\",\"Race\",\"indeviceid\",\"indevicename\",\"likeDate\"," +
            "\"likePer\",\"personId\",\"personIsHub\",\"personPicUrl\",\"picAddress\",\"picDate\",\"picName\"," +
            "\"picSmUrl\",\"sdkType\",\"videoIp\",\"videoNum\",\"videoReqNum\",\"ack_alarm\",\"imgKey\"],\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]}";
 
//  地图页 全部报警记录
    @Override
    public JSONObject findEsAllAlarmDataByPage(Integer page, Integer size,Date startDate,Date endDate) {
        String bsUrl = "http://"+enumStr.getEsHOSTNAME()+":"+enumStr.getEsHTTP_PORT();
        String esBaseUrl = enumStr.getEsIndexUrl()+enumStr.getEsSearch();
        JSONObject respView = new JSONObject();
        int from = (page-1)*size;
        String frimJson = allAlarmJson.replace("page", "" + from);
        String sizeJson = frimJson.replace("number", "" + size);
        //  时间需要处理
        if (startDate == null && endDate == null){
            sizeJson = sizeJson.replace("daterange","");
        }else{
              String range =  ",{\"range\":{\"picDate\": {\"gt\": \"startDate\"," +
                    "\"lte\": \"now/d\"}}}";
            if (startDate != null){
                range = range.replace("startDate", sdfTime.format(startDate));
            }else {
                range = range.replace("\"gt\": \"startDate\",","");
            }
            if (endDate != null){
                range = range.replace("now/d",sdfTime.format(endDate));
            }
            sizeJson = sizeJson.replace("daterange",range);
        }
        JSONObject dataBaseParams = JSONObject.parseObject(sizeJson);
//        log.info("sizeJson 查询全部报警记录参数:"+sizeJson);
//        log.info("esurl:"+bsUrl+esBaseUrl);
        JSONObject respData = null;
        String resp = RestTemplateUtil.post(bsUrl+esBaseUrl,dataBaseParams,MediaType.APPLICATION_JSON_UTF8,false);
        if(StringUtils.isNotEmpty(resp))
            respData = JSONObject.parseObject(resp);
 
        JSONObject hits = respData.getJSONObject("hits");
        String total = hits.getString("total");
        respView.put("total",total);
        JSONArray hits1 = hits.getJSONArray("hits");
        JSONArray jsonArray = new JSONArray();
        if (hits1!=null&& !hits1.isEmpty()){
            for (Object obj : hits1) {
                JSONObject hit = (JSONObject)obj;
                String id = hit.getString("_id");
                JSONObject source = hit.getJSONObject("_source");
                source.put("Id",id);
                // 返回数据处理
                respSource( source);
                jsonArray.add(source);
            }
        }
        respView.put("equList",jsonArray);
        return respView;
    }
private  String getOneById = "{\"from\":0,\"size\":1,\"query\":{\"bool\":{\"must\":" +
        "[{\"term\":{\"_id\":\"personId\"}}]}}}";
    @Override
    public JSONObject getPersonDetail(String id, String personId) {
        String bsUrl = "http://"+enumStr.getEsHOSTNAME()+":"+enumStr.getEsHTTP_PORT();
        String esBaseUrl = enumStr.getEsIndexUrl()+enumStr.getEsSearch();
        String searchParam = getOneById.replace("personId",id);
        JSONObject dataBaseParams = JSONObject.parseObject(searchParam);
//        log.info("sizeJson 查询单人记录参数:"+searchParam);
        JSONObject respData = null;
        String resp = RestTemplateUtil.post(bsUrl+esBaseUrl,
                dataBaseParams, MediaType.APPLICATION_JSON_UTF8, false);
        if(StringUtils.isNotEmpty(resp))
            respData = JSONObject.parseObject(resp);
 
        JSONObject hits = respData.getJSONObject("hits");
//        String total = hits.getString("total");
        JSONArray hits1 = hits.getJSONArray("hits");
        JSONObject respView = new JSONObject();
        if (hits1!=null&& !hits1.isEmpty()){
                JSONObject hit = (JSONObject)hits1.get(0);
            JSONObject source = hit.getJSONObject("_source");
                source.put("Id",id);
                // 返回数据处理
                respSource( source);
            respView = source;
            log.info(id+"数据id查询返回:"+respView);
        }
        //   name, gender,cardId, phone, numCard, orgName
//        Map<String, Object> personMap = culOrDevDao.selectPersonDetailById(personId);
        Map personMap = userService.queryUserInfoById(personId);
        respView.put("name",personMap.get("name"));
        respView.put("gender",personMap.get("gender"));
        respView.put("cardId",personMap.get("cardId"));
        respView.put("phone",personMap.get("phone"));
        respView.put("no",personMap.get("no"));
        respView.put("orgName",personMap.get("orgName"));
        return respView;
    }
 
 
    private  String personQueryJson = "{" +
            "\"from\": 0," +
            "\"size\": 100," +
            "\"query\": {" +
            "\"bool\": {" +
            "\"must\": [addSearchParams]," +
            "\"must_not\": [{\"term\": {\"personId\":\"perId\"}}]," +
            "\"adjust_pure_negative\": true," +
            "\"boost\": 1" +
            "}" +
            "}," +
            "\"sort\": [{" +
            "\"picDate\": {" +
            "\"order\": \"desc\"" +
            "}" +
            "}]" +
            "}";
    /**
     * 随行人员查询
     * @param videoReqNum
     * @param picDate
     * @return
     */
    @Override
    public JSONObject getAccompanyPerson(String videoReqNum,String personId,String picDate,String Id) throws ParseException {
 
        String bsUrl = "http://"+enumStr.getEsHOSTNAME()+":"+enumStr.getEsHTTP_PORT();
        String esBaseUrl = enumStr.getEsIndexUrl()+enumStr.getEsSearch();
       // 设备 id
        String searchParam1 = term.replace("eqiId",videoReqNum);
       //  sdkType = 1
        String idTerm2 = term.replace("videoReqNum", "sdkType");
        String searchParam2 = idTerm2.replace("eqiId","1");
    // 时间 调整
        String rangeParam3 = "";
        if(picDate!=null && !picDate.isEmpty()){
            Date nowDate = sdfTime.parse(picDate);
            String startDate = range.replace("startDate", sdfTime.format(nowDate.getTime()-2000));
            rangeParam3 = startDate.replace("endDate", sdfTime.format(nowDate.getTime()+2000));
        }else {
            log.info("es 随行人员查询条件中时间未知:"+picDate);
        }
        String queryJson = personQueryJson.replace("addSearchParams", searchParam1+","
                +searchParam2+","+rangeParam3);
        String reqJson = "";
        if (personId !=null && !personId.isEmpty() && !"wait todo".equalsIgnoreCase(personId)){
            reqJson = queryJson.replace("perId", personId);
        }else{
           String personJson =  queryJson.replace("personId", "_id");
            reqJson = personJson.replace("perId", Id);
        }
        JSONObject dataBaseParams = JSONObject.parseObject(reqJson);
//        log.info("sizeJson 查询全部报警记录参数:"+reqJson);
        JSONObject respData = null;
        String resp = RestTemplateUtil.post(bsUrl+esBaseUrl,
                dataBaseParams, MediaType.APPLICATION_JSON_UTF8, false);
        if(StringUtils.isNotEmpty(resp))
            respData = JSONObject.parseObject(resp);
        JSONObject hits = respData.getJSONObject("hits");
        String total = hits.getString("total");
        JSONArray hits1 = hits.getJSONArray("hits");
        JSONObject respView = new JSONObject();
        JSONArray respResult = new JSONArray();
        // 数据 比对结果存储 -------------    AccompanyPersonEsSaveData
//        String path = saveAccompanyEsData(Id, picDate);
        if (hits1!=null&& !hits1.isEmpty()){
            JSONObject hit = (JSONObject)hits1.get(0);
            String id = hit.getString("_id");
//            boolean isContainId = getEsDataById(id,path);
            boolean isContainId = false;
            if (!isContainId){ //  人员去重  true 为存在
                JSONObject source = hit.getJSONObject("_source");
                source.put("Id",id);
                //随行人员去重 --------------------  AccompanyPersonEsGetData
                // 返回数据处理
                respSource(source);
                respResult.add(source);
            }
        }
        respView.put("total",respResult.size());
        respView.put("personList",respResult);
        return respView;
    }
//      从 redis  中查询数据 让后 确认过滤是否存在此数据
    private boolean getEsDataById(String id,String path) {
        String eskey = path+enumStr.getEsListkey();
        log.info("redis中取数据");
        Long  esDataTotle = (Long) redisTemplate.opsForList().size(eskey);
        log.info("es数据总数为"+esDataTotle);
        if (esDataTotle == null || esDataTotle < 1){
            return false;
        }
        List<Map<String,Object>> esList = redisTemplate.opsForList().range(eskey, 0,-1);
        long id1 = esList.parallelStream().filter(map -> (id.equals(map.get("Id")))).count();
        if (id1 > 0){
            return  true;
        }else {
            return false;
        }
    }
 
    // 存储 随行人员 比对数据  未完待续
    private String saveAccompanyEsData(String id, String picDate) throws ParseException {
        Map<String,Object> params = new HashMap<>();
        params.put("page",1);
        params.put("liker",70);
        params.put("length",1000);
        String bsUrl = "http://"+enumStr.getEsHOSTNAME()+":"+enumStr.getEsHTTP_PORT();
        String esBaseUrl = enumStr.getEsIndexUrl().split(",")[0]+enumStr.getEsPersonType();
        // 调用 es 查询路径 path
//        192.168.1.203:9200/videopersons/perVideoPicture/4f510335-3376-45cb-a661-8266c0512e74
        String resp = RestTemplateUtil.get(bsUrl+esBaseUrl+"/"+id,
                new JSONObject(), false);
        JSONObject jsonObject = JSONObject.parseObject(resp);
        Boolean found = jsonObject.getBoolean("found");
        if (found){
            String path = jsonObject.getJSONObject("_source").getString("picSmUrl");
            params.put("path",path);
            Date parse = sdfTime.parse(picDate);
            params.put("startDate",sdfTime.format(parse.getTime()-2000));
            params.put("endDate",sdfTime.format(parse.getTime()+2000));
            Map map = searchPhotoService.findLikerPicsRtnEsData(params);
            return  path;
        }else {
            return  null;
        }
    }
 
    private String personLocusJson = "{\"query\":{\"bool\":{\"must\":[" +
        "{\"term\":{\"personId\":\"personIdValue\"}}," +
        "{\"range\":{\"picDate\":{\"gt\":\"startDate\",\"lt\":\"endDate\"}}}]}}," +
        "\"_source\":[\"videoReqNum\",\"picDate\",\"picAddress\"],\"sort\":[{\"picDate\":{\"order\":\"asc\"}}],\"size\":1000}";
 
    /**
     *  人员轨迹
     * @param personId
     * @param startDate
     * @param endDate
     * @return
     */
    @Override
    public JSONObject getPersonnLocus(String personId, String startDate, String endDate) {
        String bsUrl = "http://"+enumStr.getEsHOSTNAME()+":"+enumStr.getEsHTTP_PORT();
        String esBaseUrl = enumStr.getEsIndexUrl()+enumStr.getEsSearch();
        // 设备 id
        String personParam = personLocusJson.replace("personIdValue",personId);
        // 时间 调整
            String startDateParam = personParam.replace("startDate",startDate);
        String reqJson = startDateParam.replace("endDate", endDate);
        log.info("reqJson 人员轨迹查询参数:"+reqJson);
        JSONObject dataBaseParams = JSONObject.parseObject(reqJson);
        JSONObject respData = null;
        String resp = RestTemplateUtil.post(bsUrl+esBaseUrl,
                dataBaseParams, MediaType.APPLICATION_JSON_UTF8, false);
        if(StringUtils.isNotEmpty(resp))
            respData = JSONObject.parseObject(resp);
        JSONObject hits = respData.getJSONObject("hits");
        String total = hits.getString("total");
        JSONArray hits1 = hits.getJSONArray("hits");
        JSONObject respView = new JSONObject();
        JSONArray respResult = new JSONArray(); List<String> devIds = new ArrayList<>();
        JSONArray devpath = new JSONArray();
        respView.put("total",total);
        if (hits1!=null&& !hits1.isEmpty()){
            String firstDate = null;
            for (Object obj : hits1){
                JSONObject hit = (JSONObject)obj;
                String id = hit.getString("_id");
                JSONObject source = hit.getJSONObject("_source");
                source.put("Id",id);
                //  monthfirst  每月标记  true 是首天  false
                Date picDate = source.getSqlDate("picDate");
                if (picDate!=null&&!sdfMouth.format(picDate).equals(firstDate)){
                    source.put("monthfirst",true);
                    firstDate = sdfMouth.format(picDate);
                }else {
                    source.put("monthfirst",false);
                }
                String videoReqNum = source.getString("videoReqNum");
                if (videoReqNum != null){
                    devpath.add(new String[]{videoReqNum+"_lon",videoReqNum+"_lat"});
                }else {
                    devpath.add(new String[2]);
                }
                devIds.add(source.getString("videoReqNum"));
                respResult.add(source);
            }
            // 处理 路径 轨迹 数据
            changPathByDevId( respView, devpath);
        }
        respView.put("locusList",respResult);
        // 集群信息处理
//        log.info("数据汇总:"+devIds.size());
        JSONArray sumNum = groupByGroupSum(devIds);
        respView.put("sumNum",sumNum);
        return respView;
    }
 
    /**
     * 分组
     * @param demos
     */
    public  JSONArray groupByGroupSum(List<String> demos){
 
        Map<String, Long> collect = demos.parallelStream().collect(Collectors.groupingBy(String::toString,Collectors.counting()));
        JSONArray respDevSum = new JSONArray();
        collect.forEach((key,value)->{
//            System.out.println("分组:"+key+":"+value);
            JSONObject devInfo = new JSONObject();
            devInfo.put("devId",key);
            devInfo.put("decCount",value);
            respDevSum.add(devInfo);
        });
        return respDevSum;
    }
    // 转换 摄像机坐标 path
        public void changPathByDevId(JSONObject respView,JSONArray devpath){
            //  设备id 处理
            Result result = deviceService.findAllDevices();
            if (result.isSuccess() && devpath.size() > 0){
                JSONObject data = (JSONObject) result.getData();
                JSONArray posList = data.getJSONArray("posList");
                String devPathBeforeJson = devpath.toJSONString();
//                log.info("转换前 path 内容:devPathBeforeJson:"+devPathBeforeJson);
                for (Object obj : posList) {
                    JSONObject dev = (JSONObject)obj;
                    String devId = dev.getString("id");
                    String devlat = dev.getString("latitude");
                    String devlon = dev.getString("longitude");
                    devPathBeforeJson = devPathBeforeJson.replaceAll("\""+devId + "_lon\"", devlon);
                    devPathBeforeJson = devPathBeforeJson.replaceAll("\""+devId + "_lat\"", devlat);
                }
                //log.info("设备路径变换后json:"+devPathBeforeJson);
                JSONArray afterPath = JSONArray.parseArray(devPathBeforeJson);
                for (int ap = 0,size = afterPath.size();ap<size; ap++) {
                    JSONArray  devPath= (JSONArray)afterPath.get(ap);
                    if (devPath.size() != 2){
                        afterPath.remove(ap);ap--;size--;
                    }else if (devPath.getString(0).contains("_lon") || devPath.getString(1).contains("_lat")){
                        afterPath.remove(ap);ap--;size--;
                    }
                }
                respView.put("path",afterPath);             // 转换无误
            }else {
                devpath = new JSONArray();
                log.info("设备坐标查询异常。result:"+result);
                respView.put("path",devpath);
            }
        }
 
    @Autowired
    private RedisTemplate redisTemplate;
 
    // 获取es  比对后数据轨迹
    @Override
    public JSONObject getPersonnLocusByRedis(String picId) {
        //  下方 测试 轨迹
     /* if (true){
       return  getPersonnLocus("PSVAD010120181215175357774","2018-12-01","2018-12-31");
      }*/
        // 待 redis 有数据的
        ListOperations opsForList = redisTemplate.opsForList();
        List<Map<String,Object>> range = opsForList.range(picId + enumStr.getEsListkey(), 0, -1);
        //
        JSONObject jsonView = new JSONObject();
        JSONArray devpath = new JSONArray();
        JSONArray devList = new JSONArray();  List<String> devIds = new ArrayList<>();
 
        Collections.sort(range, new Comparator<Map<String,Object>>(){
            public int compare(Map<String,Object> map1, Map<String,Object> map2) {
                int i = (int) (map2.get("picDate")+"").compareTo( map1.get("picDate")+"");
                if(i == 0){
                    return 0;
                }else if(i<0){
                    return -1;
                }else {
                    return 1;
                }
            }
        });
        if (range != null){
            jsonView.put("total",""+range.size());
            SimpleDateFormat sdfDT = new SimpleDateFormat("yyyy年MM月");
            for (Map<String,Object> esMap : range){
                JSONObject source = new JSONObject();
                source.put("picDate",esMap.get("picDate"));
                source.put("videoReqNum",esMap.get("videoReqNum"));
                source.put("picAddress",esMap.get("picAddress"));
                source.put("Id",esMap.get("Id"));
                //  monthfirst  每月标记  true 是首天  false
                Date picDate = source.getSqlDate("picDate");
                source.put("timeDay", sdfDay.format(picDate));
                String videoReqNum = source.getString("videoReqNum");//摄像机id
 
                if (videoReqNum != null){
                    devpath.add(0,new String[]{videoReqNum+"_lon",videoReqNum+"_lat"});
                }else {
                    devpath.add(0,new String[2]);
                }
                devList.add(source);
                devIds.add(source.getString("videoReqNum"));
            }
            //  获取所有 摄像机 信息
            JSONArray posList = new JSONArray();
              Map<String, Object> reqInfosMap = new HashMap<String,Object>();
            Result result = deviceService.findAllDevices();
            if (result.isSuccess() && devpath.size() > 0){
                JSONObject data = (JSONObject) result.getData();
                posList = data.getJSONArray("posList");
                 reqInfosMap = posList.parallelStream().collect(Collectors.toMap(jsonObj->((JSONObject)jsonObj).getString("id"),jsonObj->(jsonObj)));
            }
            // 依据 设备id  分组聚合 数据    devList  数据为空
            Map<String, List<Object>> videoReqNum = devList.parallelStream().collect(Collectors.groupingBy(source -> ((JSONObject) source).getString("videoReqNum")));
            JSONArray devGroupList = new JSONArray();
            JSONArray devInfos = new JSONArray();
            Map<String, Object> finalReqInfosMap = reqInfosMap;
            videoReqNum.forEach((k, v) ->{
                JSONObject reqSource = new JSONObject();
                reqSource.put("videoReqNum",k);
                // 每个 摄像机的数据进行处理
                List soues = (List)v;
                  String firstDate = null;
                    String currDay = "";// timeDay
                  for (int i = 0; i < soues.size(); i++) {
                    JSONObject  sou = (JSONObject)soues.get(i);
                   Date picDate = sou.getSqlDate("picDate");
                    String timeDay = sou.getString("timeDay");
                    if (picDate!=null&&!sdfMouth.format(picDate).equals(firstDate)){
                      JSONObject mouthSource = new JSONObject();
                        mouthSource .put("monthfirst",true);
                        mouthSource.put("Id","jingersong");
                        mouthSource.put("showMonth",sdfDT.format(picDate));
                        mouthSource.put("videoReqNum",k);
                        soues.add(i++,mouthSource);
                        firstDate = sdfMouth.format(picDate);
                        sou.put("monthfirst",false);currDay = timeDay;
                    } else if (timeDay != null&& currDay.equals(timeDay)){
                        soues.remove(i--);
                    }else{
                        currDay = timeDay;
                        sou.put("monthfirst",false);
                    }
                }
                reqSource.put("dateList",soues);
                devGroupList.add(reqSource);
                JSONObject devInfo = new JSONObject();
                devInfo.put("id",k);
                JSONObject dev = (JSONObject) finalReqInfosMap.get(k);
                if (dev != null){
                    devInfo.put("name",dev.getString("name"));
                    devInfo.put("address",dev.getString("address"));
                    devInfos.add(devInfo);
                }
            });
            jsonView.put("locusList",devGroupList);
            jsonView.put("devInfos",devInfos);
        }else{
            jsonView.put("total",0);
            jsonView.put("locusList",new JSONArray());
            jsonView.put("path",new JSONArray());
        }
        // 处理 路径 轨迹 数据
        changPathByDevId(jsonView, devpath);
        // 集群信息处理
//        log.info("数据汇总:"+devIds.size());
        JSONArray sumNum = groupByGroupSum(devIds);
        jsonView.put("sumNum",sumNum);
        return jsonView;
    }
    // 返回数据 source 特殊处理
    private void respSource(JSONObject source){
        String sdkType = source.getString("sdkType");
        // sdkType 类型 进行处理
        String[] sdkTypes = C_Es_Map.esSdkType;
        String[] sdkValues = C_Es_Map.sdkValue;
        if(sdkType!=null&& sdkTypes.length==sdkValues.length){
            for (int i = 0; i < sdkTypes.length; i++){
                if(sdkType.equalsIgnoreCase(sdkTypes[i])){
                    sdkType = sdkValues[i];break;
                }
            }
                if (sdkType.equals("人脸")){
                    sdkType = "1";
                }
            source.put("sdkType",sdkType);
        }
        // personId 'waittodo' 处理
        String personId = (String) source.get("personId");
        if (personId!=null && !personId.isEmpty() ){
            if ( personId.contains("wait todo")){
                source.put("personId","");
            }else {
                // 查询数据库   name, gender, cardId, phone,b.`no` numCard,o.name orgName
//                Map<String, Object> respMap = culOrDevDao.selectPersonDetailById(personId);
                Map respMap = userService.queryUserInfoById(personId);
                if (respMap != null){
                    String name = (String) respMap.get("name");
                    source.put("name",name);
                    source.put("gender",respMap.get("gender"));   //  修改 覆盖es 性别属性
                    source.put("cardId",respMap.get("cardId"));
                    source.put("phone",respMap.get("phone"));
                    source.put("no",respMap.get("no"));
                    source.put("orgName",respMap.get("orgName"));
                }
            }
        }
 
    // 底库名称处理
        String baseName = (String) source.get("BaseName");
        if(baseName!=null && baseName.startsWith("lt_")){
            source.put("BaseName", baseName.substring(3));
        }else if (baseName.contains("wait todo")){
            source.put("BaseName","");
        }
        //  相似值处理 likePer
        Object likePer =null;
        try {
            likePer =  source.get("likePer");
            if(likePer!=null){
//                log.info("float likePer:"+likePer);
//                source.put("likePer",Math.round((Double)likePer*100));
                source.put("likePer",Math.round(Double.parseDouble(likePer.toString())*100));
            }
        }catch (Exception e){
            e.printStackTrace();
            log.info("Id:"+source.get("Id")+"本次查询likePer:"+likePer);
        }
        // Age 处理
        Object age =  source.get("Age");
        if(age!=null){
            int agei = -1;
            try {
                agei = (Integer)age;
            } catch (ClassCastException e){
                agei = Integer.valueOf((String)age);
                log.info(e.getLocalizedMessage());
            }
            if(agei>0 && agei < 7){
                age ="童年";
            }else if(agei>=7 && agei < 18){
                age ="少年";
            }else if(agei>=18 && agei < 40){
                age ="青年";
            }else if(agei>=40 && agei < 65){
                age ="中年";
            }else if(agei>= 65){
                age ="老年";
            }
        }else {age = "";}
        source.put("Age",age);
    }
 
    private  String term = "{" +
                                    "\"term\": {\"videoReqNum\":\"eqiId\"}" +
                                "}";
 
    private String matchJson = "{\"multi_match\":{" +
            "\"query\":\"matchauery\"," +
            "\"fields\": [" +
            "\"Gender^2.0\"," +
            "\"Race^2.0\"," +
            "\"BaseName^1.5\"," +
            "\"content^1.0\"," +
            "\"picAddress^1.0\"" +
            "]," +
            "\"type\":\"cross_fields\"" +
            "}}";
    private String terms =  "{" +
            "\"terms\": {" +
            "\"videoReqNum\": termlist" +
            "}" +
            "}";
    private  String range =      "{" +
            "\"range\": {" +
            "\"picDate\": {" +
            "\"from\": \"startDate\"," +
            "\"to\": \"endDate\"," +
            "\"include_lower\": true," +
            "\"include_upper\": false," +
            "\"boost\": 1" +
            "}}}";
    /**
     *  查询json 转换
     * @param esSearch
     * @return
     */
    public String changeObjectToJson(EsDataQueryParam esSearch){
        String contentes = esSearch.getContent();
        Integer startAge = null,endAge = null;
        log.info("esSearch-->"+esSearch);
        Integer page  = esSearch.getPage();
        Integer size = esSearch.getSize();
        int from = (page-1)*size;
        String frimJson = allQueryJson.replace("fromNum", "" + from);
        String sizeJson = frimJson.replace("sizeNum", "" + size);
        String[] split = null;
        //  content  输入框内容
        boolean isCont = false;
           if (contentes!= null && !contentes.isEmpty()){
                    if(contentes.contains("童")){
                        startAge = 0; endAge = 7;isCont =true;
                    }
                    if(contentes.contains("少")){
                        startAge = 7; endAge = 18;isCont =true;
                    }
                    if(contentes.contains("青")){
                        startAge= 18;endAge = 40;isCont =true;
                    }
                    if(contentes.contains("中")){
                        startAge =40;endAge = 65;isCont =true;
                    }
                    if(contentes.contains("老")){
                        startAge =65;endAge = 200;isCont =true;
                    }
                    if (isCont){
                       contentes = contentes.replaceAll("(童年)|(少年)|(青年)|(中年)|(老年)|(童)|(少)|(青)|(中)|(老)","").trim();
                    }
               split =  contentes.trim().split("\\s+");
             esSearch.setContents(split);
             esSearch.setContent(contentes);  // wp 后加的
           }else {
               esSearch.setContents(null);
           }
        String queryParams = "";boolean isAddParams = false;
        //      时间截取 条件查询
        if(esSearch.getStartDate()!=null && esSearch.getEndDate()!=null){
            String startDate = range.replace("startDate", sdfTime.format(esSearch.getStartDate()));
            String endDate = startDate.replace("endDate", sdfTime.format(esSearch.getEndDate()));
           if (isAddParams){queryParams+=",";}  isAddParams = true;  //  查询条件分隔符
            queryParams+=endDate;
        }else {
            log.info("es 查询条件中时间未知:"+esSearch.getStartDate()+"<====>"+esSearch.getEndDate());
        }
 
        // 是否确认报警
        if(esSearch.getAck_alarm()!=null && !esSearch.getAck_alarm().isEmpty()){
            String ack_alarm = esSearch.getAck_alarm();
            String alarmValue = null;
            if ("1".equalsIgnoreCase(ack_alarm)){
                String personIsHubParam = term.replace("videoReqNum","ack_alarm");
                String endDate = personIsHubParam.replace("eqiId","1");
                if(isAddParams){queryParams+=",";}else {  isAddParams = true; } //  查询条件分隔符
                queryParams+=endDate;
            }else if ("0".equalsIgnoreCase(ack_alarm)){
                alarmValue = "0";
                String personIsHubParam = term.replace("videoReqNum","ack_alarm");
                String endDate = personIsHubParam.replace("eqiId",alarmValue);
                if(isAddParams){queryParams+=",";}else {  isAddParams = true; } //  查询条件分隔符
                queryParams+=endDate;
            }
        }
        // likePer 相似值的处理
        if (esSearch.getLikePer() != null && esSearch.getLikePer()> 0 && esSearch.getLikePer() <= 100){
            String startDate = range.replace("startDate",(esSearch.getLikePer()-0.5)*0.01+"");
            String endDate = startDate.replace("endDate", "1.01");
            endDate =  endDate.replace("picDate","likePer");
            if (isAddParams){queryParams+=",";}  isAddParams = true;  //  查询条件分隔符
            queryParams+=endDate;
        }
       List<String> analyType = esSearch.getSdkType();
        //   sdkType   {"terms":{"sdkType":["1","6","4","7","8"]}},
        if (analyType == null || analyType.isEmpty()){
//            sizeJson = sizeJson.replace("sdkTypes","");
        }else {  //  {"term":{"sdkType":"1"}},
            String analyJson = "";
            if (isAddParams){queryParams+=",";} isAddParams = true;//  查询条件分隔符
            if (analyType.size()>0){
                for (int s=0;s <analyType.size();s++) {
                    for (int i =0;i<C_Es_Map.sdkValue.length;i++){
                        if (analyType.get(s).equalsIgnoreCase(C_Es_Map.sdkValue[i])){
                            analyType.set(s,C_Es_Map.esSdkType[i]);
                        }
                    }
                }
            }
            String terms = C_Es_Map.terms;
            String sdkValueJson = terms.replace("sdkValues", JSONArray.toJSONString(analyType));
            queryParams += sdkValueJson;
        }
 
        String shouldJson = "";   // 多集群整合
        //  是否报警库查询
        if(esSearch.getRecordType()!=null && !esSearch.getRecordType().isEmpty()){
            String recordType = esSearch.getRecordType();
            String personIsHubValue = null;
            if ("alarm".equalsIgnoreCase(recordType)){
                personIsHubValue = "1";
            }else if ("other".equalsIgnoreCase(recordType)){
                personIsHubValue = "0";
            }
            if (personIsHubValue != null){
                String personIsHubParam = term.replace("videoReqNum","personIsHub");
                String endDate = personIsHubParam.replace("eqiId",personIsHubValue);
                if(isAddParams){queryParams+=",";}else {  isAddParams = true; } //  查询条件分隔符
                queryParams+=endDate;
            }
 
        }else {
            //  依据 底库查询
            //  底库 数据记录
            if(esSearch.getDataBaseList()!=null && !esSearch.getDataBaseList().isEmpty()){
                List<String> dataBaseList = esSearch.getDataBaseList();
                // 旧版本  单集群 执行  暂废 wp 19-02-15
              /*  String dbName = terms.replace("indeviceid","BaseName"+C_Es_Map.fieldRaw);
            //            List<String> lists = Arrays.asList(esSearch.getDataBaseList());
                String termlist = dbName.replace("termlist",JSONObject.toJSONString(dataBaseList));  //  String.join(",", esSearch.getDataBaseList())
                if (isAddParams){queryParams+=",";}else{ isAddParams = true;} //  查询条件分隔符
                queryParams+=termlist;*/
                // 新版本 支持 多集群 多底库类型执行   启用 wp 19-02-15
                for (int i = 0; i < dataBaseList.size(); i++) {
                    String dbNameMerge  = dataBaseList.get(i);
                    String[] dbNameMerges = getCluAndBaseNameAndHub(dbNameMerge);
                   if (dbNameMerges.length == 3){
                           if (i != 0){shouldJson += ",";}
                    String boolJson = boolQueryJson.replace("SSS",dbNameMerges[0]);
                    boolJson = boolJson.replace("baseNameValue",dbNameMerges[1]);
                    boolJson = boolJson.replace("hubValue",dbNameMerges[2]);
                       shouldJson += boolJson;
                   }
                }
            }else{
                log.info("es 查询条件中dataBaseList无:"+esSearch.getStartDate()+"<====>"+esSearch.getEndDate());
            }
            log.info("es 查询条件中时间未知:"+esSearch.getStartDate()+"<====>"+esSearch.getEndDate());
        }
 
        //  青年 截取 条件 查询
        if(startAge!=null && endAge!=null){
            String ageField = range.replace("picDate","Age");
            String startage = ageField.replace("startDate",startAge.toString());
            String endage = startage.replace("endDate",endAge.toString());
            if (isAddParams){queryParams+=",";} isAddParams = true;//  查询条件分隔符
            queryParams+=endage;
        }else{
            log.info("es 查询条件中age无:"+esSearch.getStartDate()+"<====>"+esSearch.getEndDate());
        }
 
        //  设备id 集合查询
        if(esSearch.getIndeviceid()!=null && !esSearch.getIndeviceid().isEmpty() && (esSearch.getCluId()==null || esSearch.getCluId().isEmpty())){
            String termlist = terms.replace("termlist",JSONObject.toJSONString(esSearch.getIndeviceid()) );  // String.join(",", esSearch.getIndeviceid())
            if (isAddParams){queryParams+=",";} isAddParams = true; //  查询条件分隔符
            queryParams+=termlist;
        }else if ("monitorTree".equalsIgnoreCase(esSearch.getCluId())){
            String termlist = terms.replace("termlist","[\"monitorTree\"]");  // String.join(",", esSearch.getIndeviceid())
            if (isAddParams){queryParams+=",";} isAddParams = true; //  查询条件分隔符
            queryParams+=termlist;
        }else{
            log.info("es 查询条件中IndeviceidList无:"+esSearch.getStartDate()+"<====>"+esSearch.getEndDate()+"esSearch.getCluId()"+esSearch.getCluId());
        }
        // contents  数据查询
        if (esSearch.getContents()!=null&& esSearch.getContents().length>0
                &&esSearch.getContent() != null && !esSearch.getContent().isEmpty() ){
            List<Object> employerList = userService.getEmployerList(esSearch.getContent());
            List<String> ids = null;
           if (employerList != null){
               ids = employerList.stream()
                       .map(p -> (((JSONObject)p).getString("id")))
                       .collect(Collectors.toList());
           }
            if (!StringUtils.isBlank(shouldJson)){shouldJson+=",";}
            String matchauery = matchJson.replace("matchauery", esSearch.getContent());   //  cont
            shouldJson +=  matchauery;
           if (ids != null && !ids.isEmpty()){
                String personIds = terms.replace("videoReqNum", "personId");
                String personJson = personIds.replace("termlist", JSONObject.toJSONString(ids));
             shouldJson +=  (","+personJson);
           }
        }
        shouldJson = shouldQueryJson.replace("boolQuerys", shouldJson);//  构建 should
       sizeJson = sizeJson .replace("shouldParams",shouldJson);   // 真正 添加 数据库的判断
 
        if (esSearch.getContent()!= null && !esSearch.getContent().isEmpty()){
            String scoreSort = "{\"_score\":{\"order\":\"desc\"}},";
            sizeJson = sizeJson.replace("scoreSort",scoreSort);
        }else {
            sizeJson = sizeJson.replace("scoreSort","");
        }
//        sizeJson = sizeJson.replace("picDate","_score");   // 用来干啥的?
        String queryJson = sizeJson.replace("addSearchParams", queryParams);
        return  queryJson;
    }
    //  设备记录  和 全部查询用到了
    private  String allQueryJson = "{" +
                                        "\"from\": fromNum," +
                                        "\"size\": sizeNum," +
                                        "\"query\": {" +
                                        "\"bool\": {" +
                                        "\"must\": [addSearchParams,shouldParams]," +
                                        "\"adjust_pure_negative\": true," +
                                        "\"boost\": 1" +
                                        "}" +
                                        "}," +
                                        "\"sort\": [" +
                                        "scoreSort"+
                                        "{\"picDate\": {\"order\": \"desc\"}}" +
                                        "]" +
                                        "}";
 
    private String shouldQueryJson = "{\"bool\": {\"should\": [boolQuerys]}}";
 
    private final String boolQueryJson = "{\"bool\":{\"must\":[" +
            "{\"term\":{\"cluster_id\":{\"value\":\"SSS\"}}}," +
            "{\"term\":{\"BaseName.raw\":{\"value\":\"baseNameValue\"}}}," +
            "{\"term\":{\"personIsHub\":{\"value\":\"hubValue\"}}}]}}";
 
}