AdaKing88
2023-08-21 23258c585a626b15d770459870a8b24763cf540c
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
package com.tairui.app.cim.controller;
 
import com.tairui.app.cim.dao.model.*;
import com.tairui.app.cim.mapper.*;
import com.http.HttpResult;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@RestController
@RequestMapping("/cim/geom")
public class GeomController {
 
    @Autowired
    AlarmPointMapper alarmPointMapper ;
    @Autowired
    CameraMapper cameraMapper ;
    @Autowired
    PersonnelPointMapper personnelPointMapper ;
    @Autowired
    ProductionAreaMapper productionAreaMapper ;
    @Autowired
    ProductionUnitAreaMapper productionUnitAreaMapper ;
    @Autowired
    OperationAreaMapper operationAreaMapper ;
    @Autowired
    InspectionMapper inspectionMapper ;
 
    @Autowired
    ElevationMapper elevationMapper ;
 
 
    @Autowired
    EmergencySuppliesPointMapper emergencySuppliesPointMapper;
    @Autowired
    EntranceGuardPointMapper entranceGuardPointMapper;
    @Autowired
    EvacuationPointMapper evacuationPointMapper ;
    @Autowired
    MajorHazardsPointMapper majorHazardsPointMapper ;
    @Autowired
    ToxicGasPointMapper toxicGasPointMapper;
    @Autowired
    FireEquipmentPointMapper fireEquipmentPointMapper;
    @GetMapping("/queryByID")
    @ApiOperation("table_name:alarm,camera,inspection,production,production_unit,operation," +
            "toxic_gas_point,emergency_supplies_point,major_hazards_point,entrance_guard_point," +
            "evacuation_point,fire_equipment_point")
    public HttpResult queryByID(int gid ,String table_name ){
 
        if( table_name.toLowerCase().equals("alarm")) return HttpResult.ok(alarmPointMapper.query(gid));
        if( table_name.toLowerCase().equals("camera")) return HttpResult.ok(cameraMapper.query(gid));
        if( table_name.toLowerCase().equals("personnel")) return HttpResult.ok(personnelPointMapper.query(gid));
        if( table_name.toLowerCase().equals("inspection")) return HttpResult.ok(inspectionMapper.query(gid));
 
        if( table_name.toLowerCase().equals("production")) return HttpResult.ok(productionAreaMapper.query(gid));
        if( table_name.toLowerCase().equals("production_unit"))return HttpResult.ok(productionUnitAreaMapper.query(gid));
        if( table_name.toLowerCase().equals("operation")) return HttpResult.ok(operationAreaMapper.query(gid));
 
        if( table_name.toLowerCase().equals("toxic_gas_point")) return HttpResult.ok(toxicGasPointMapper.query(gid));
        if( table_name.toLowerCase().equals("emergency_supplies_point")) return HttpResult.ok(emergencySuppliesPointMapper.query(gid));
 
        if( table_name.toLowerCase().equals("major_hazards_point")) return HttpResult.ok(majorHazardsPointMapper.query(gid));
        if( table_name.toLowerCase().equals("entrance_guard_point"))return HttpResult.ok(entranceGuardPointMapper.query(gid));
        if( table_name.toLowerCase().equals("evacuation_point")) return HttpResult.ok(evacuationPointMapper.query(gid));
        if( table_name.toLowerCase().equals("fire_equipment_point")) return HttpResult.ok(fireEquipmentPointMapper.query(gid));
 
        return HttpResult.error("参数错误");
    }
 
    @GetMapping("/update")
    public HttpResult update(int gid , String geom,String table_name){
        if( table_name.toLowerCase().equals("alarm")) {
            AlarmPoint alarmPoint = alarmPointMapper.selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = alarmPointMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("camera")) {
            CameraPoint alarmPoint = cameraMapper.selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = cameraMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("inspection")) {
            Inspection alarmPoint =inspectionMapper .selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = inspectionMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("production")) {
            ProductionArea alarmPoint =productionAreaMapper .selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = productionAreaMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("production_unit")){
            ProductionUnitArea alarmPoint =productionUnitAreaMapper .selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = productionUnitAreaMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("operation")) {
            OperationArea alarmPoint =operationAreaMapper .selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = operationAreaMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
 
 
 
        if( table_name.toLowerCase().equals("toxic_gas_point")){
            ToxicGasPoint alarmPoint =toxicGasPointMapper.selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = toxicGasPointMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("emergency_supplies_point")) {
            EmergencySuppliesPoint alarmPoint =emergencySuppliesPointMapper .selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = emergencySuppliesPointMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("major_hazards_point")){
            MajorHazardsPoint alarmPoint =majorHazardsPointMapper .selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = majorHazardsPointMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("entrance_guard_point")) {
            EntranceGuardPoint alarmPoint =entranceGuardPointMapper .selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = entranceGuardPointMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("evacuation_point")){
            EvacuationPoint alarmPoint =evacuationPointMapper .selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = evacuationPointMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
        if( table_name.toLowerCase().equals("fire_equipment_point")){
            FireEquipmentPoint alarmPoint =fireEquipmentPointMapper .selectById(gid) ;
            if( alarmPoint == null ) return  HttpResult.error("记录不存在!");
            alarmPoint.setGeom(geom);
            int ret = fireEquipmentPointMapper.updateById(alarmPoint);
            return HttpResult.ok(ret);
        }
 
        return HttpResult.error("参数错误");
    }
 
    /**
     * 处理过程,根据楼层得到面数据,判断点是否在面上,如果在,返回 x,y ,coor_z
     * 如果不在面上,获得最近的面,返回  cen_x cen_y coor_z
     * @param x
     * @param y
     * @param
     * @return
     */
    @GetMapping("/queryElevation")
    public HttpResult queryElevation(String floor_num,double x , double y){
        List<Elevation> list = new ArrayList<>();
        //一层不查询
        if( floor_num.equals("1")){
           Elevation e = new Elevation();
           e.setCenx(x);
           e.setCeny(y);
           e.setHigh("0");
            list.add(e);
            return HttpResult.ok(list );
 
        }
        list = elevationMapper.queryFloor(x,y,floor_num) ;
        if( list == null || list.size() == 0 ){
            list = elevationMapper.queryMinDistance(x,y,floor_num);
            return (HttpResult.ok(list));//.stream().filter(p->{System.out.println(p.getCentX());p.setCen_x(p.getCenx());p.setCen_y(p.getCeny());return true;}).collect(Collectors.toList())));
        }else{
            return HttpResult.ok(  list.stream().filter(p->{p.setCenx(x);p.setCeny(y);return true;}).collect(Collectors.toList()));
        }
 
 
    }
}