Helius
2021-06-16 5728be2af515b2200e782aa201ca5d4d67d9ea47
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
package com.ibeetl.admin.console.api;
 
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.ibeetl.admin.console.model.*;
import com.ibeetl.admin.console.service.CuserConsoleService;
import com.ibeetl.admin.console.service.XzxCityPartnerService;
import com.ibeetl.admin.console.service.XzxElectronicFenceService;
import com.ibeetl.admin.console.service.XzxPartnerFenceService;
import com.ibeetl.admin.console.util.PreventManyCommit;
import com.ibeetl.admin.core.entity.XzxCityPartner;
import com.ibeetl.admin.core.entity.XzxElectronicFence;
import com.fasterxml.jackson.core.type.TypeReference;
import com.ibeetl.admin.core.entity.XzxPartnerFence;
import com.ibeetl.admin.core.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import java.text.SimpleDateFormat;
import java.util.*;
 
@RestController
@Api(value = "电子围栏接口类")
public class ElectronicFenceApi {
    private static final String MODEL = "/admin/front/fence";
    @Autowired
    XzxElectronicFenceService service;
    @Autowired
    XzxPartnerFenceService pfService;
 
    @Value("${gaode.fence.url}")
    String FENCE_URL;
    @Autowired
    XzxCityPartnerService cityPartnerService;
    @Autowired
    CuserConsoleService cuserConsoleService;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /**
     * 新增电子围栏
     * @param model
     * @return
     */
    @PostMapping(MODEL + "/addElectronicFenceApi.json")
    @ResponseBody
    @ApiOperation(value="电子围栏管理-新增电子围栏", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "fenceName", value = "名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "fenceType", value = "电子围栏类型,1:POI围栏,2:行政区围栏,3:圆形围栏,4:多边形围栏", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "keyword", value = "关键字:城市或区域名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "latitude", value = "纬度", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "longitude", value = "经度", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "partnerIds", value = "合伙人Id(多个用逗号','隔开)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "radius", value = "半径", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType="query", name = "prohibit", value = "是否启用", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType="query", name = "longLatiArrList", value = "围栏类型为多边形时,传入", required = true, dataType = "List<Map<String,String>")
    })
    public JsonResult<String> addElectronicFenceApi(@RequestBody XzxElectronicFenceModel model){
        String partnerIds = model.getPartnerIds();
        boolean flag = false;
        if(null!=partnerIds&&!"".equals(partnerIds)){
            flag = true;
        }
        if(!flag){
            return JsonResult.failMessage("必须填写关联合伙人!");
        }
        model.setDelFlag(0);
        model.setCreateTime(sdf.format(new Date()));
        //
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        XzxElectronicFence info = objectMapper.convertValue(model, XzxElectronicFence.class);
        if(null!=model.getFenceName()&&!"".equals(model.getFenceName())){
            model.setFenceName(model.getFenceName().trim());
            //是否有重名电子围栏
            XzxElectronicFence oldInfo =service.queryElectronic(model);
            if(null!=oldInfo){
                return JsonResult.failMessage("已经有相同的围栏名称,添加失败!");
 
            }else{
                String longiLatiStr = "";
                String longiLatiStr2 = "";
                if(model.getFenceType().equals("4")){
                    List longLatiArrList = model.getLongLatiArrList();
 
                    if(null!=longLatiArrList&&longLatiArrList.size()>0){
                        ObjectMapper mapper = new ObjectMapper();
                        List<LongiLatiModel> LongiLati = mapper.convertValue(longLatiArrList, new TypeReference<List<LongiLatiModel>>() { });
                        Gson gson = new Gson();
                        String str = gson.toJson(LongiLati);
                        info.setLonglatiarr(str);
                        for (LongiLatiModel lola:LongiLati) {
                            if(null!=longiLatiStr&&!"".equals(longiLatiStr)){
                                longiLatiStr = longiLatiStr+";"+lola.getLongitude()+","+lola.getLatitude();
                                longiLatiStr2 = longiLatiStr2+"|"+lola.getLongitude()+","+lola.getLatitude();
                            }else{
                                longiLatiStr =lola.getLongitude()+","+lola.getLatitude();
                                longiLatiStr2 =lola.getLongitude()+","+lola.getLatitude();
                            }
 
                        }
                    }
                }
 
                info.setDelFlag(0);
                if(null!=info.getKeyword()&&!"".equals(info.getKeyword())){
                    AreaModel areaModel = new AreaModel();
                    areaModel.setName(info.getKeyword());
                    AreaModel map = cityPartnerService.queryAreaLongiLati(areaModel);
                    info.setTownCode(map.getCode());
                    info.setLongitude(map.getLongitude());
                    info.setLatitude(map.getLatitude());
                }
 
                XzxPartnerFence pfInfo = new XzxPartnerFence();
                XzxPartnerFenceModel pfInfo1 = new XzxPartnerFenceModel();
                if(null!=partnerIds&&!"".equals(partnerIds)){
                    //List<XzxPartnerFenceModel> pfInfoList = new ArrayList<>();
                    String partnerId = partnerIds;
                    //for (String partnerId:partnerArr) {
                        if(null!=info.getKeyword()&&!"".equals(info.getKeyword())){
                                //校验该合伙人是否能创建电子围栏
                                String townId = service.queryAreaTownId(info.getKeyword());
                                if(null!=townId&&!"".equals(townId)){
                                    boolean boolflag = service.queryPartnerAreaIds(partnerId,townId);
                                    if(!boolflag){
                                        return JsonResult.failMessage("该合伙人不能创建该地区的电子围栏");
                                    }else{
                                        //判断是否有在该区域建行政区
                                        if(model.getFenceType().equals("2")){
                                            //判断是否有在该区域建行政区
                                            List<String> townList = service.queryTownListByArea(info.getTownCode(),null);
                                            if(townList.size()>0){
                                                return JsonResult.failMessage(info.getKeyword()+" 已经建立行政区围栏,不能在该区域内创建其他围栏");
                                            }
 
                                        }
                                    }
                                }else{
                                    return JsonResult.failMessage("该合伙人不应属于该区域,无法创建电子围栏");
                                }
 
 
 
                        }else{
                            String keyword="";
                            String[] keywordList = new String[20];
                            if(null!=longiLatiStr2&&!"".equals(longiLatiStr2)){
                                String location =info.getLonglatiarr();
                                XzxCityPartner partner = cityPartnerService.queryById(partnerId);
                                 keyword = service.queryLongiLatiForTownName(partner.getPartnerKey(),location,longiLatiStr2);
                                 keywordList = keyword.split(",");
                            }else{
                                XzxCityPartner partner = cityPartnerService.queryById(partnerId);
                                String location = model.getLongitude()+","+model.getLatitude();
                                 keyword = service.queryLongiLatiForTownName(partner.getPartnerKey(),location,null);
 
                            }
                            if(null!=keyword&&!"".equals(keyword)){
                                if(keywordList.length>0){
                                    for (String keywords:keywordList) {
                                        String[] obj = keywords.split("_");
                                        String keyword1 = obj[1];
                                        int num = Integer.parseInt(obj[0]);
                                        String townId = service.queryAreaTownId(keyword1);
                                        AreaModel areaModel1 = new AreaModel();
                                        areaModel1.setName(keyword1);
                                        AreaModel map1 = cityPartnerService.queryAreaLongiLati(areaModel1);
                                        info.setTownCode(map1.getCode());
                                        if(null!=townId&&!"".equals(townId)){
                                            boolean boolflag = service.queryPartnerAreaIds(partnerId,townId);
                                            if(!boolflag){
                                                String[] ll2=  longiLatiStr.split(";");
                                                String errorAddress = ll2[num];
                                                return JsonResult.failMessage("该合伙人不应属于该区域,无法在经纬度为:"+errorAddress+" 创建电子围栏");
                                            }else{
                                                //判断是否有在该区域建行政区
                                                List<String> townList = service.queryTownListByArea(info.getTownCode(),null);
                                                if(townList.size()>0){
                                                    String[] ll2=  longiLatiStr.split(";");
                                                    String errorAddress = ll2[num];
                                                    return JsonResult.failMessage(keyword + " 已经建立行政区围栏,不能在:"+errorAddress+"该区域内创建其他围栏");
                                                }
                                            }
                                        }else{
                                            return JsonResult.failMessage("区域为空,不能创建电子围栏");
                                        }
                                    }
                                }else{
                                    String townId = service.queryAreaTownId(keyword);
                                    AreaModel areaModel1 = new AreaModel();
                                    areaModel1.setName(keyword);
                                    AreaModel map1 = cityPartnerService.queryAreaLongiLati(areaModel1);
                                    info.setTownCode(map1.getCode());
                                    if(null!=townId&&!"".equals(townId)){
                                        boolean boolflag = service.queryPartnerAreaIds(partnerId,townId);
                                        if(!boolflag){
                                            return JsonResult.failMessage("该合伙人不应属于该区域,无法创建电子围栏");
                                        }else{
                                            //判断是否有在该区域建行政区
                                            List<String> townList = service.queryTownListByArea(info.getTownCode(),null);
                                            if(townList.size()>0){
                                                return JsonResult.failMessage(keyword + " 已经建立行政区围栏,不能在该区域内创建其他围栏");
                                            }
                                        }
                                    }else{
                                        return JsonResult.failMessage("区域为空,不能创建电子围栏");
                                    }
                                }
 
                            }else{
                                return JsonResult.failMessage("找不到该区域,不能创建电子围栏");
                            }
 
                        }
 
                        pfInfo.setFenceId(info.getId()+"");
                        pfInfo.setPartnerId(partnerId);
                        pfInfo1.setPartnerId(partnerId);
                       if(model.getFenceType().equals("2")){
                             //判断行政区是否有其他围栏
                           List<String> idsOD = service.queryODByArea(info.getTownCode());
                           if(idsOD.size()>0){
                               return JsonResult.failMessage(info.getKeyword()+"已经建立围栏,不能在该区域内创建行政区围栏!");
                           }
                        }else{
                           String resultJson = service.createGDFence(info,pfInfo1,FENCE_URL,longiLatiStr);
                           System.out.println("==高德返回"+resultJson);
                           Map maps = (Map) JSON.parse(resultJson);
                           String errmsg = maps.get("errmsg").toString();
                           String str2=maps.get("data").toString();
                           Map maps2 = (Map)JSON.parse(str2);
                           String statusGaode = maps2.get("status").toString();
                           String gid="";
                           if(statusGaode.equals("0")){
                               gid = maps2.get("gid").toString();
                           }
                           if(null!=gid&&!"".equals(gid)){
                               info.setGid(gid);
                               service.update(info);
                           }else{
                               return JsonResult.failMessage("高德创建电子围栏失败!");
                           }
                       }
 
                }else{
                    return JsonResult.failMessage("新增电子围栏失败");
                }
 
                info.setLonglatiarr(longiLatiStr);
                boolean bool = service.save(info);
                if(!bool){
                    return JsonResult.failMessage("新增电子围栏失败");
                }else{
                    //是否关联合伙人
                    //修改关联表
                    pfInfo.setFenceId(info.getId()+"");
                    pfInfo.setDelFlag(0);
                    pfInfo.setCreateTime(sdf.format(new Date()));
                    pfService.save(pfInfo);
                    //pfService.saveAllPfInfo(pfInfoList);
                    return JsonResult.success("添加成功!");
                }
            }
        }else{
            return JsonResult.failMessage("电子围栏名称不能为空!");
 
        }
    }
 
 
    @PostMapping(MODEL + "/queryElectronicFence.do")
    @ResponseBody
    @ApiOperation(value="电子围栏管理-按电子围栏查看(城市合伙人查看)", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "围栏ID", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "page", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "limit", value = "每页条数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "fenceType", value = "电子围栏类型,1:POI围栏,2:行政区围栏,3:圆形围栏,4:多边形围栏", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "startTime", value = "开始时间", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "endTime", value = "结束时间", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "name", value = "姓名、手机号、围栏名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "provinceId", value = "省Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "cityId", value = "市Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "townshipId", value = "区Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "prohibit", value = "是否禁用(0:禁用,1:启用)", required = true, dataType = "Integer")
    })
    public JsonResult<Map<String, Object>> queryElectronicFence(@RequestBody XzxCityPartnerModel model){
        Map<String, Object> map =  pfService.queryElectronicFence(model);
        return JsonResult.success(map);
    }
 
 
 
    @PostMapping(MODEL + "/queryFenceList.do")
    @ResponseBody
    @ApiOperation(value="电子围栏管理-查询所有电子围栏", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "fenceType", value = "电子围栏类型,1:POI围栏,2:行政区围栏,3:圆形围栏,4:多边形围栏", required = true, dataType = "String")
    })
    public JsonResult<List<XzxElectronicFenceModel>> queryFenceList(@RequestBody XzxElectronicFenceModel model){
        List<XzxElectronicFenceModel> list =  service.queryFenceList(model);
        return JsonResult.success(list);
    }
 
    /**
     * 删除
     * @param model
     * @return
     */
    @PostMapping(MODEL + "/delElectronicFence.json")
    @PreventManyCommit(time = 10)
    @ResponseBody
    @ApiOperation(value="电子围栏管理-删除电子围栏", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "合伙人Id", required = true, dataType = "Integer")
    })
    public JsonResult<String> delElectronicFence(@RequestBody XzxElectronicFenceModel model){
        XzxElectronicFence info = service.queryById(model.getId());
        info.setDelFlag(1);
        service.update(info);
        XzxCityPartner partner= pfService.queryPartnerIds(model.getId()+"");
        if(null!=partner){
            //删除高德围栏
            String gid = info.getGid();
            if(null!=gid&&!"".equals(gid)){
                String url = "https://restapi.amap.com/v4/geofence/meta";
                String resultJson = service.deleteGDFence(info,url,partner);
            }
 
        }
        //删除管理合伙人
        pfService.deleteByFenceId(model.getId()+"");
 
        return JsonResult.success("删除成功");
    }
 
    /**
     * 删除
     * @param model
     * @return
     */
    @PostMapping(MODEL + "/delPartner.json")
    @PreventManyCommit(time = 10)
    @ResponseBody
    @ApiOperation(value="电子围栏管理-删除合伙人", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "合伙人Id", required = true, dataType = "Integer")
    })
    public JsonResult<String> delPartner(@RequestBody XzxCityPartnerModel model){
        int count = cityPartnerService.queryElectronicFenceByPartner(model.getId());
        if(count>0){
            return JsonResult.failMessage("删除合伙人前,请先删除该合伙人的电子围栏!");
        }else{
            XzxCityPartner partner = cityPartnerService.queryById(model.getId());
            partner.setDelFlag(1);
            if(partner.getPartnerType().equals("2")){
                List<String> partnerIds = cityPartnerService.queryPartnerByCurrent();
                if(null!=partnerIds&&partnerIds.size()>0){
                    return JsonResult.failMessage("合伙人不能删除打包站!");
                }
                cuserConsoleService.delCuserById(partner.getUserId(), partner.getMobilePhone(), "7");
            }else{
                cityPartnerService.deleteServiceByKey(partner);
                cityPartnerService.deleteUserByPartnerId(model.getId(),partner.getAccountNo());
            }
            cityPartnerService.deletePartnerAccount(partner);
            cityPartnerService.update(partner);
 
            return JsonResult.success("删除成功");
        }
 
    }
 
    /**
     * 新增电子围栏
     * @param model
     * @return
     */
    @PostMapping(MODEL + "/updateElectronicFenceApi.json")
    @ResponseBody
    @ApiOperation(value="电子围栏管理-编辑电子围栏", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "主键id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "fenceName", value = "名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "fenceType", value = "电子围栏类型,1:POI围栏,2:行政区围栏,3:圆形围栏,4:多边形围栏", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "keyword", value = "关键字:城市或区域名称", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "latitude", value = "纬度", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "longitude", value = "经度", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "partnerIds", value = "合伙人Id(多个用逗号','隔开)", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "radius", value = "半径", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType="query", name = "longLatiArrList", value = "围栏类型为多边形时,传入", required = true, dataType = "List<Map<String,String>")
    })
    public JsonResult<String> updateElectronicFenceApi(@RequestBody XzxElectronicFenceModel model){
        //
        String partnerIds = model.getPartnerIds();
        boolean flag = false;
        if(null!=partnerIds&&!"".equals(partnerIds)){
            flag = true;
        }
        if(!flag){
            return JsonResult.failMessage("必须填写关联合伙人!");
        }
 
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        XzxElectronicFence info = objectMapper.convertValue(model, XzxElectronicFence.class);
        XzxElectronicFence oldInfo1 =service.queryById(info.getId());
        info.setGid(oldInfo1.getGid());
        //XzxElectronicFence oldInfo = service.queryById(info.getId());
        if(null!=model.getFenceName()&&!"".equals(model.getFenceName())){
            model.setFenceName(model.getFenceName().trim());
            //是否有重名电子围栏
            XzxElectronicFence oldInfo =service.queryElectronic(model);
            if(null!=oldInfo){
                return JsonResult.failMessage("已经有相同的围栏名称,修改失败!");
            }else{
                String longiLatiStr = "";
                String longiLatiStr2 = "";
                if(model.getFenceType().equals("4")){
                    List longLatiArrList = model.getLongLatiArrList();
 
                    if(null!=longLatiArrList&&longLatiArrList.size()>0){
                        ObjectMapper mapper = new ObjectMapper();
                        List<LongiLatiModel> LongiLati = mapper.convertValue(longLatiArrList, new TypeReference<List<LongiLatiModel>>() { });
                        Gson gson = new Gson();
                        String str = gson.toJson(LongiLati);
                        info.setLonglatiarr(str);
                        for (LongiLatiModel lola:LongiLati) {
                            if(null!=longiLatiStr&&!"".equals(longiLatiStr)){
                                longiLatiStr = longiLatiStr+";"+lola.getLongitude()+","+lola.getLatitude();
                                longiLatiStr2 = longiLatiStr2+"|"+lola.getLongitude()+","+lola.getLatitude();
                            }else{
                                longiLatiStr =lola.getLongitude()+","+lola.getLatitude();
                                longiLatiStr2 =lola.getLongitude()+","+lola.getLatitude();
                            }
 
                        }
                    }
                }
                if(model.getFenceType().equals("3")){
                    info.setKeyword("");
                }
                info.setDelFlag(0);
                info.setCreateTime(sdf.format(new Date()));
                if(null!=info.getKeyword()&&!"".equals(info.getKeyword())){
                    AreaModel areaModel = new AreaModel();
                    areaModel.setName(info.getKeyword());
                    AreaModel map = cityPartnerService.queryAreaLongiLati(areaModel);
                    info.setTownCode(map.getCode());
                    info.setLongitude(map.getLongitude());
                    info.setLatitude(map.getLatitude());
                    //该电子围栏是否包含该区域。
                    //String longgiLatiList = service.queryAreaLongiLatiList(city);
                }
                XzxPartnerFence pfInfo = new XzxPartnerFence();
                XzxPartnerFenceModel pfInfo1 = new XzxPartnerFenceModel();
                if(null!=partnerIds&&!"".equals(partnerIds)){
                    //List<XzxPartnerFenceModel> pfInfoList = new ArrayList<>();
                    String partnerId = partnerIds;
                    //for (String partnerId:partnerArr) {
                    if(null!=info.getKeyword()&&!"".equals(info.getKeyword())){
                        //校验该合伙人是否能创建电子围栏
                        String townId = service.queryAreaTownId(info.getKeyword());
                        if(null!=townId&&!"".equals(townId)){
                            boolean boolflag = service.queryPartnerAreaIds(partnerId,townId);
                            if(!boolflag){
                                return JsonResult.failMessage("该合伙人不能创建该地区的电子围栏");
                            }else{
                                //判断是否有在该区域建行政区
                                if(model.getFenceType().equals("2")){
                                    //判断是否有在该区域建行政区
                                    List<String> townList = service.queryTownListByArea(info.getTownCode(),info.getId()+"");
                                    if(townList.size()>0){
                                        return JsonResult.failMessage("该区域不能创建电子围栏");
                                    }
 
                                }
                            }
                        }else{
                            return JsonResult.failMessage("该区域不能创建电子围栏");
                        }
 
                    }else{
                        String keyword="";
                        String[] keywordList = new String[20];
                        if(null!=longiLatiStr2&&!"".equals(longiLatiStr2)){
                            String location =info.getLonglatiarr();
                            XzxCityPartner partner = cityPartnerService.queryById(partnerId);
                            keyword = service.queryLongiLatiForTownName(partner.getPartnerKey(),location,longiLatiStr2);
                            keywordList = keyword.split(",");
                        }else{
                            XzxCityPartner partner = cityPartnerService.queryById(partnerId);
                            String location = model.getLongitude()+","+model.getLatitude();
                            keyword = service.queryLongiLatiForTownName(partner.getPartnerKey(),location,null);
 
                        }
                        if(null!=keyword&&!"".equals(keyword)){
                            if(keywordList.length>0){
                                for (String keywords:keywordList) {
                                    String[] obj = keywords.split("_");
                                    String keyword1 = obj[1];
                                    int num = Integer.parseInt(obj[0]);
                                    String townId = service.queryAreaTownId(keyword1);
                                    AreaModel areaModel1 = new AreaModel();
                                    areaModel1.setName(keyword1);
                                    AreaModel map1 = cityPartnerService.queryAreaLongiLati(areaModel1);
                                    info.setTownCode(map1.getCode());
                                    if(null!=townId&&!"".equals(townId)){
                                        boolean boolflag = service.queryPartnerAreaIds(partnerId,townId);
                                        if(!boolflag){
                                            String[] ll2=  longiLatiStr.split(";");
                                            String errorAddress = ll2[num];
                                            return JsonResult.failMessage("该合伙人不应属于该区域,无法在经纬度为:"+errorAddress+" 创建电子围栏");
                                        }else{
                                            //判断是否有在该区域建行政区
                                            List<String> townList = service.queryTownListByArea(info.getTownCode(),null);
                                            if(townList.size()>0){
                                                String[] ll2=  longiLatiStr.split(";");
                                                String errorAddress = ll2[num];
                                                return JsonResult.failMessage(keyword + " 已经建立行政区围栏,不能在:"+errorAddress+"该区域内创建其他围栏");
                                            }
                                        }
                                    }else{
                                        return JsonResult.failMessage("区域为空,不能创建电子围栏");
                                    }
                                }
                            }else{
                                String townId = service.queryAreaTownId(keyword);
                                if(null!=townId&&!"".equals(townId)){
                                    boolean boolflag = service.queryPartnerAreaIds(partnerId,townId);
                                    if(!boolflag){
                                        return JsonResult.failMessage("该合伙人不能创建该地区的电子围栏");
                                    }else{
                                        //判断是否有在该区域建行政区
                                        List<String> townList = service.queryTownListByArea(info.getTownCode(),info.getId()+"");
                                        if(townList.size()>0){
                                            return JsonResult.failMessage("该区域不能修改电子围栏");
                                        }
                                    }
                                }else{
                                    return JsonResult.failMessage("该区域不能创建电子围栏");
                                }
                            }
 
                        }else{
                            return JsonResult.failMessage("该区域不能创建电子围栏");
                        }
 
                    }
                    pfInfo.setFenceId(info.getId()+"");
                    pfInfo.setPartnerId(partnerId);
                    pfInfo1.setPartnerId(partnerId);
                    if(oldInfo1.getGid()!=null&&!"".equals(oldInfo1.getGid())){
                        String gid = oldInfo1.getGid();
                        String resultJson = service.updateGDFence(info,pfInfo1,longiLatiStr,gid);
                        System.out.println("==高德返回"+resultJson);
                        Map maps = (Map) JSON.parse(resultJson);
 
                        String str2=maps.get("data").toString();
                        Map maps2 = (Map)JSON.parse(str2);
                        String statusGaode = maps2.get("status").toString();
                        if(statusGaode.equals("0")){
 
                        }else{
                            return JsonResult.failMessage("新增电子围栏失败");
                        }
                    }
 
                }else{
                    return JsonResult.failMessage("新增电子围栏失败");
                }
                info.setLonglatiarr(longiLatiStr);
                boolean bool = service.update(info);
                if(!bool){
                    return JsonResult.failMessage("修改电子围栏失败");
                }else{
                    //修改关联表
                    //pfInfo.setPartnerId();
                    pfInfo.setFenceId(info.getId()+"");
                    pfInfo.setDelFlag(0);
                    pfInfo.setUpdateTime(sdf.format(new Date()));
 
                    pfService.updateByFenceId(pfInfo);
                    //pfService.saveAllPfInfo(pfInfoList);
                    return JsonResult.success("修改成功!");
                }
 
            }
        }else{
            return JsonResult.failMessage("电子围栏名称不能为空!");
 
        }
    }
 
 
    @PostMapping(MODEL + "/updateFenceProhibit.json")
    @ResponseBody
    @ApiOperation(value="后台电子围栏是否启用接口", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name ="id", value = "合伙人Id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "prohibit", value = "是否启用(0:禁用,1:启用)", required = true, dataType = "String")
    })
    public JsonResult<String> updateFenceProhibit(@RequestBody XzxElectronicFenceModel model){
        XzxElectronicFence info=service.queryById(model.getId());
        info.setProhibit(model.getProhibit());
        info.setUpdateTime(sdf.format(new Date()));
        service.update(info);
        return JsonResult.success("修改成功");
    }
}