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
package com.cloud.retrieve.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.cloud.model.common.Result;
import com.cloud.retrieve.model.EsDataQueryParam;
import com.cloud.retrieve.service.EsDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
 
@Slf4j
@RestController
@Api(value = "EsDataBaseController",description = "es数据查询")
@RequestMapping("/data/api-r/es")
public class EsDataController  {
 
    @Autowired
    private EsDataService esDataService;
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
 
    @ApiOperation(value = "findEsData",notes = "查询es检索数据",httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("findEsData")
    public Result findEsData(@RequestBody EsDataQueryParam esSearch){
//        log.info(sdf.format(new Date())+"查询es检索数据前");
        JSONObject allDataByMoreParams = esDataService.getAllDataByMoreParams(esSearch);
//        log.info(sdf.format(new Date())+"查询es检索数据返回");
        return  Result.ok("查询es检索数据成功。",allDataByMoreParams);
    }
 
    @ApiOperation(value = "updateEsToAlarm",notes = "修改为已确认报警 {\"id\":\"dc6e4b7b-08ad-4ba2-b1f0-4bbc5ace7c43\",\"ack_alarm\":\"1\"}",httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("updateEsToAlarm")
    public Result updateEsToAlarm(@RequestBody Map reqMap){
        String  dataId = (String) reqMap.get("id");
        String ack_alarm = (String) reqMap.get("ack_alarm");
        if (dataId == null || dataId.isEmpty() || ack_alarm == null || ack_alarm .isEmpty()){
            throw new RuntimeException("dataId或ack_alarm 参数为空"+dataId+ack_alarm);
        }
        log.info(sdf.format(new Date())+"修改为已确认前");
        JSONObject respupdate = esDataService.updateEsDataByEsId(dataId,ack_alarm);
        log.info(sdf.format(new Date())+"修改为已确认后");
            if (respupdate.getBoolean("success")){
                return  Result.ok("修改为已确认报警成功。",respupdate);
            }else {
                return  Result.error(new RuntimeException("操作过于频繁,报警确认失败,请稍后再试。"));
            }
    }
 
    @ApiOperation(value = "cameraRecord",notes = "地图某摄像机报警记录或抓拍分页数据 " +
            "{\"videoReqNum\":\"d820807a-5b83-4321-9b43-e0129102a9ff\",\"page\":1,\"size\":6,\"personIsHub\":\"\"}",
            httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("cameraRecord")
    public Result findEsAlarmDataByEquPage(@RequestBody Map reqMap){
        Integer  page = (Integer) reqMap.get("page");
        Integer size = (Integer) reqMap.get("size");
        String equId = (String) reqMap.get("videoReqNum");
        String personIsHub = (String) reqMap.get("personIsHub");  //
        if (page == null || size == null ){
           page = 1;size = 8;
        }
//        log.info("某摄像机报警记录查询参数page:"+page+"size:"+size+"equId:"+equId);
        JSONObject respupdate = esDataService.findEsPersonAlarmDataByEquPage(page,size,equId,personIsHub);
            return  Result.ok("设备记录查询成功。",respupdate);
    }
 
    @ApiOperation(value = "alarmRecord",notes = "地图全部报警记录分页数据 {\"page\":1,\"size\":8}",
            httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("alarmRecord")
    public Result findEsAllAlarmDataByPage(@RequestBody Map reqMap) throws ParseException {
        Integer  page = (Integer) reqMap.get("page");
        Integer size = (Integer) reqMap.get("size");
        Date startDate = reqMap.get("startDate")== null?null:sdf.parse(reqMap.get("startDate").toString());
        Date endDate = reqMap.get("endDate")== null?null:sdf.parse(reqMap.get("endDate").toString());
        if (page == null || size == null ){
            page = 1;size = 6;
        }
        log.info("某摄像机报警记录查询参数page:"+page+"size:"+size);
        JSONObject respView = esDataService.findEsAllAlarmDataByPage(page,size,startDate,endDate);
        return  Result.ok("全部报警记录查询成功。",respView);
    }
 
 
    @ApiOperation(value = "personDetail",notes =
            "单人报警记录详情{\"id\":\"d820807a-5b83-4321-9b43-e0129102a9ff\",\"personId\":\"psv\"}",
            httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("personDetail")
    public Result findEsDataByPerson(@RequestBody Map reqMap){
        String  id = (String) reqMap.get("id");
        String personId = (String) reqMap.get("personId");
        if (id == null ||id.isEmpty()|| personId == null|| personId.isEmpty()){
           throw new RuntimeException("数据id,人员personId:"+id+personId+"为空。");
        }
        log.info("单人报警记录详情查询参数id:"+id+"personId:"+personId);
        JSONObject respView = esDataService.getPersonDetail(id,personId);
        return  Result.ok("全部报警记录查询成功。",respView);
    }
 
    @ApiOperation(value = "accompanyPerson",notes =
            "随行人员查询 {\"videoReqNum\":\"reqNum\",\"picDate\":\"2019-01-03 12:12:12\",\"personId\":\"perId\",\"Id\":\"Id\"}",
            httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("accompanyPerson")
    public Result accompanyPerson(@RequestBody Map reqMap) throws ParseException {
        String  videoReqNum = (String) reqMap.get("videoReqNum");
        String picDate = (String) reqMap.get("picDate");
        String  personId = (String) reqMap.get("personId");
        String id = (String) reqMap.get("Id");
        if (videoReqNum == null ||videoReqNum.isEmpty()|| picDate == null|| picDate.isEmpty()||
                ((personId == null || personId.isEmpty())&&(id == null || id.isEmpty()))){
            throw new RuntimeException("随行人员查询 videoReqNum,picDate:"+videoReqNum+picDate+"personId:"+personId+"为空。");
        }
        log.info("随行人员查询参数videoReqNum:"+videoReqNum+"picDate:"+picDate);
        JSONObject respView = esDataService.getAccompanyPerson(videoReqNum,personId,picDate,id);
        return  Result.ok("随行人员记录查询成功。",respView);
    }
 
    @ApiOperation(value = "getPersonnLocus",notes =
            "人员轨迹查询 {\"personId\":\"PSVAD010120181215175357774\"," +
                    "\"startDate\":\"2018-12-01\",\"endDate\":\"2018-12-31\"}",
            httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("getPersonnLocus")
    public Result getPersonnLocus(@RequestBody Map reqMap) throws ParseException {
        String  personId = (String) reqMap.get("personId");
        String startDate = (String) reqMap.get("startDate");
        String endDate = (String) reqMap.get("endDate");
        if (personId == null ||personId.isEmpty()|| startDate == null|| startDate.isEmpty()|| endDate == null|| endDate.isEmpty()){
            throw new RuntimeException("人员轨迹查询参数 personId,startDate:"+personId+startDate+"endDate"+endDate+"为空。");
        }
        log.info("人员轨迹查询参数personId:"+personId+"startDate:"+startDate+startDate+"endDate:"+endDate);
        JSONObject respView = esDataService.getPersonnLocus(personId,startDate,endDate);
        return  Result.ok("人员轨迹查询成功。",respView);
    }
 
    @ApiOperation(value = "getPersonnLocusByJni",notes =
            "人员轨迹查询 {\"picId\":\"PSVAD010120181215175357.jpg\"}",
            httpMethod = "POST",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping("getPersonnLocusByJni")
    public Result getPersonnLocusByJni(@RequestBody Map reqMap) throws ParseException {
        String  picId = (String) reqMap.get("picId");
        if (picId == null ||picId.isEmpty()){
            throw new RuntimeException("人员轨迹查询参数 picId:"+picId+"为空。");
        }
        log.info("人员轨迹查询参数picId:"+picId);
        JSONObject respView = esDataService.getPersonnLocusByRedis(picId);
        return  Result.ok("人员轨迹查询成功。",respView);
    }
 
}