| package com.xzx.gc.order.controller;  | 
|   | 
| import cn.hutool.core.collection.CollUtil;  | 
| import cn.hutool.core.date.DateUtil;  | 
| import cn.hutool.core.util.StrUtil;  | 
| import com.xzx.gc.common.Result;  | 
| import com.xzx.gc.common.constant.CommonEnum;  | 
| import com.xzx.gc.common.constant.Constants;  | 
| import com.xzx.gc.common.constant.OrderEnum;  | 
| import com.xzx.gc.common.constant.SysConfigConstant;  | 
| import com.xzx.gc.common.dto.log.OperationAppLog;  | 
| import com.xzx.gc.common.exception.RestException;  | 
| import com.xzx.gc.common.request.BaseController;  | 
| import com.xzx.gc.entity.AddressInfo;  | 
| import com.xzx.gc.entity.CityPartner;  | 
| import com.xzx.gc.entity.Fence;  | 
| import com.xzx.gc.model.JsonResult;  | 
| import com.xzx.gc.model.admin.XzxCityPartnerModel;  | 
| import com.xzx.gc.model.admin.XzxElectronicFenceModel;  | 
| import com.xzx.gc.model.order.AreaDto;  | 
| import com.xzx.gc.model.order.FenceDto;  | 
| import com.xzx.gc.order.dto.FenceFindDto;  | 
| import com.xzx.gc.order.dto.FenceInDto;  | 
| import com.xzx.gc.order.service.*;  | 
| import com.xzx.gc.util.PreventManyCommit;  | 
| 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.web.bind.annotation.*;  | 
|   | 
| import javax.servlet.http.HttpServletRequest;  | 
| import java.util.Arrays;  | 
| import java.util.List;  | 
| import java.util.Map;  | 
|   | 
| /**  | 
|  * @author :zz  | 
|  */  | 
| @RestController  | 
| @RequestMapping  | 
| @Api(tags = {"围栏管理"})  | 
| public class FenceController extends BaseController {  | 
|   | 
|     @Autowired  | 
|     PartnerFenceService pfService;  | 
|     @Autowired  | 
|     CityPartnerService cityPartnerService;  | 
|   | 
|     @Autowired  | 
|     private FenceService fenceService;  | 
|   | 
|     @Autowired  | 
|     private AddressService addressService;  | 
|   | 
|     @Autowired  | 
|     private OrderService orderService;  | 
|   | 
|     @PostMapping("/fence/byUser")  | 
|     @ApiOperation(value = "根据用户城市查询围栏列表")  | 
|     public Result<List<Fence>> byUser(HttpServletRequest request,@RequestBody AreaDto areaDto){  | 
|         //所有合伙人的围栏  | 
|         List<Fence> byUserId = fenceService.findByUserId(getUserId(request));  | 
| //        if(CollUtil.isNotEmpty(byUserId)){  | 
| //            //根据城市筛选围栏  | 
| //            String areaId = areaDto.getAreaId();  | 
| //            int level = areaDto.getLevel();  | 
| //            for (Iterator<Fence> iterator = byUserId.iterator(); iterator.hasNext(); ) {  | 
| //                Fence next =  iterator.next();  | 
| //                String fenceType = next.getFenceType();  | 
| //                String adcode=null;  | 
| //                if(OrderEnum.行政区围栏.getValue().equals(fenceType)){  | 
| //                    adcode=next.getTownCode();  | 
| //                }else  if(OrderEnum.多边形围栏.getValue().equals(fenceType)){  | 
| //                    //围栏所在地区adcode  | 
| //                    GdReverseGEODto gdReverseGEODto = new GdReverseGEODto();  | 
| //                    gdReverseGEODto.setLocation(next.getLongLatiArr().split(";")[0]);  | 
| //                    Result areaInfo = GdMapUtil.getAreaInfo(gdReverseGEODto, 0);  | 
| //                    if(areaInfo.getCode()==0){  | 
| //                        AddressInfo addressInfo= (AddressInfo) areaInfo.getData();  | 
| //                        adcode=addressInfo.getAdcode();  | 
| //                    }  | 
| //                }else  if(OrderEnum.圆形围栏.getValue().equals(fenceType)){  | 
| //                    //围栏所在地区adcode  | 
| //                    GdReverseGEODto gdReverseGEODto = new GdReverseGEODto();  | 
| //                    gdReverseGEODto.setLocation(next.getLongitude()+","+next.getLatitude());  | 
| //                    Result areaInfo = GdMapUtil.getAreaInfo(gdReverseGEODto, 0);  | 
| //                    if(areaInfo.getCode()==0){  | 
| //                        AddressInfo addressInfo= (AddressInfo) areaInfo.getData();  | 
| //                        adcode=addressInfo.getAdcode();  | 
| //                    }  | 
| //                }  | 
| //  | 
| //                if(adcode!=null){  | 
| //                    AddressLevelInfo byAdcode = addressLevelService.findByAdcode(adcode);  | 
| //                    if(level==2){  | 
| //                        if(!byAdcode.getLevel2Id().equals(areaId)){  | 
| //                            iterator.remove();  | 
| //                        }  | 
| //                    }else if(level==3){  | 
| //                        if(!byAdcode.getLevel3Id().equals(areaId)){  | 
| //                            iterator.remove();  | 
| //                        }  | 
| //                    }  | 
| //                }else {  | 
| //                    iterator.remove();  | 
| //                }  | 
| //            }  | 
| //        }  | 
|         return Result.success(byUserId);  | 
|     }  | 
|   | 
|   | 
|     @PostMapping("/fence/find")  | 
|     @ApiOperation(value = "查看已开通区域")  | 
|     public Result<List<Fence>> find(HttpServletRequest request, @RequestBody FenceFindDto fenceFindDto){  | 
|         String townshipId = fenceFindDto.getTownshipId();  | 
|   | 
|         List<Fence> byAreaId = fenceService.findByAreaId(townshipId);  | 
|   | 
|         return Result.success(byAreaId);  | 
|     }  | 
|   | 
|   | 
|     @PostMapping("/fence/inFence")  | 
|     @ApiOperation(value = "所选位置是否开通服务")  | 
|     public Result inFence(HttpServletRequest request, @RequestBody FenceInDto fenceInDto){  | 
|         String addressId = fenceInDto.getAddressId();  | 
|         if(StrUtil.isBlank(addressId)){  | 
|             return Result.success("0");  | 
|         }  | 
|   | 
|         AddressInfo byId1 = addressService.findById(addressId);  | 
|         FenceDto fenceDto = fenceService.getFence(byId1.getTownshipId(),false,byId1.getLongitude(),byId1.getLatitude(),true);  | 
|         //围栏ID  | 
|         String fenceId = fenceDto.getFenceId();  | 
|         //合伙人ID  | 
|         String partnerId = fenceDto.getPartnerId();  | 
|   | 
|   | 
|         /**  | 
|          * 0代表在围栏内或者当前合伙人无地图展示  | 
|          * 空 代表有地图且不在围栏内  | 
|          */  | 
|         if(StrUtil.isBlank(partnerId)){  | 
|             return Result.success("0");  | 
|         }else {  | 
|             if(StrUtil.isNotBlank(fenceId)){  | 
|                 return Result.success("0");  | 
|             }else {  | 
|                 if(Constants.DEFAULT_PARTNER_ID.equals(partnerId)){  | 
|                     return Result.success("");  | 
|                 }else {  | 
|                     return Result.success("0");  | 
|                 }  | 
|             }  | 
|         }  | 
|     }  | 
|   | 
|   | 
|     @PostMapping("/fence/inFenceForHome")  | 
|     @ApiOperation(value = "所选位置是否开通家电服务")  | 
|     public Result inFenceForHome(HttpServletRequest request, @RequestBody FenceInDto fenceInDto){  | 
|         AddressInfo addressInfo = addressService.findById(fenceInDto.getAddressId());  | 
|         //市ID  | 
|         String townId=addressInfo.getCityId();  | 
|         boolean b = orderService.existExcludeCityId(townId);  | 
|         if(b){  | 
|             return  Result.success("-1");  | 
|         }  | 
|         return Result.success("1");  | 
|     }  | 
|   | 
|   | 
|   | 
|     /**  | 
|      * 新增电子围栏  | 
|      * @param model  | 
|      * @return  | 
|      */  | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/fence/addElectronicFenceApi.json")  | 
|     @ResponseBody  | 
|     @ApiOperation(value="电子围栏管理-新增电子围栏", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "fenceName", value = "名称", required = false, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "fenceType", value = "电子围栏类型,1:POI围栏,2:行政区围栏,3:圆形围栏,4:多边形围栏", required = false, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "keyword", value = "关键字:城市或区域名称", required = false, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "latitude", value = "纬度", required = false, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "longitude", value = "经度", required = false, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "partnerIds", value = "合伙人Id(多个用逗号','隔开)", required = false, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "radius", value = "半径", required = false, dataType = "Integer"),  | 
|             @ApiImplicitParam(paramType="query", name = "prohibit", value = "是否启用", required = false, dataType = "Integer"),  | 
|             @ApiImplicitParam(paramType="query", name = "longLatiArrList", value = "围栏类型为多边形时,传入", required = false, dataType = "List<Map<String,String>")  | 
|     })  | 
|     public JsonResult<String> addElectronicFenceApi(@RequestBody XzxElectronicFenceModel model,HttpServletRequest request){  | 
|   | 
|         JsonResult<String> stringJsonResult = fenceService.addFence(model);  | 
|         if(stringJsonResult.getCode()==0){  | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                     .methodName(Constants.ORDER_MODUL_NAME).operateAction("新增电子围栏-"+stringJsonResult.getData()).build();  | 
|             mqUtil.sendApp(build);  | 
|         }  | 
|         return  stringJsonResult;  | 
|     }  | 
|   | 
|   | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/fence/queryElectronicFence.do")  | 
|     @ResponseBody  | 
|     @ApiOperation(value="电子围栏管理-按电子围栏查看(城市合伙人查看)", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "id", value = "围栏ID",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "page", value = "页码",  dataType = "int"),  | 
|             @ApiImplicitParam(paramType="query", name = "limit", value = "每页条数",  dataType = "int"),  | 
|             @ApiImplicitParam(paramType="query", name = "fenceType", value = "电子围栏类型,1:POI围栏,2:行政区围栏,3:圆形围栏,4:多边形围栏",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "startTime", value = "开始时间",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "endTime", value = "结束时间",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "name", value = "姓名、手机号、围栏名称",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "provinceId", value = "省Id",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "cityId", value = "市Id",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "townshipId", value = "区Id",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "prohibit", value = "是否禁用(0:禁用,1:启用)",  dataType = "Integer")  | 
|     })  | 
|     public JsonResult<Map<String, Object>> queryElectronicFence(@RequestBody XzxCityPartnerModel model){  | 
|         Map<String, Object> map =  pfService.queryElectronicFence(model);  | 
|         return JsonResult.success(map);  | 
|     }  | 
|   | 
|   | 
|   | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/fence/queryFenceList.do")  | 
|     @ResponseBody  | 
|     @ApiOperation(value="电子围栏管理-查询所有电子围栏", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "fenceType", value = "电子围栏类型,1:POI围栏,2:行政区围栏,3:圆形围栏,4:多边形围栏",  dataType = "String")  | 
|     })  | 
|     public JsonResult<List<XzxElectronicFenceModel>> queryFenceList(@RequestBody XzxElectronicFenceModel model){  | 
|         List<XzxElectronicFenceModel> list =  fenceService.queryFenceList(model);  | 
|         return JsonResult.success(list);  | 
|     }  | 
|   | 
|     /**  | 
|      * 删除  | 
|      * @param model  | 
|      * @return  | 
|      */  | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/fence/delElectronicFence.json")  | 
|     @PreventManyCommit(time = 10)  | 
|     @ResponseBody  | 
|     @ApiOperation(value="电子围栏管理-删除电子围栏", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "id", value = "围栏Id",  dataType = "Integer")  | 
|     })  | 
|     public JsonResult<String> delElectronicFence(@RequestBody XzxElectronicFenceModel model,HttpServletRequest request){  | 
|         fenceService.deleteFence(model);  | 
|         OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                 .methodName(Constants.ORDER_MODUL_NAME).operateAction("删除电子围栏-"+model.getId()).build();  | 
|         mqUtil.sendApp(build);  | 
|         return JsonResult.success("删除成功");  | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 新增电子围栏  | 
|      * @param model  | 
|      * @return  | 
|      */  | 
|     @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/fence/updateElectronicFenceApi.json")  | 
|     @ResponseBody  | 
|     @ApiOperation(value="电子围栏管理-编辑电子围栏", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "id", value = "主键id",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "fenceName", value = "名称",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "fenceType", value = "电子围栏类型,1:POI围栏,2:行政区围栏,3:圆形围栏,4:多边形围栏",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "keyword", value = "关键字:城市或区域名称",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "latitude", value = "纬度",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "longitude", value = "经度",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "partnerIds", value = "合伙人Id(多个用逗号','隔开)",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "radius", value = "半径",  dataType = "Integer"),  | 
|             @ApiImplicitParam(paramType="query", name = "longLatiArrList", value = "围栏类型为多边形时,传入",  dataType = "List<Map<String,String>")  | 
|     })  | 
|     public JsonResult<String> updateElectronicFenceApi(@RequestBody XzxElectronicFenceModel model,HttpServletRequest request){  | 
|         //  | 
|         JsonResult<String> stringJsonResult = fenceService.updateFence(model);  | 
|   | 
|         if(stringJsonResult.getCode()==0){  | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                     .methodName(Constants.ORDER_MODUL_NAME).operateAction("修改电子围栏-"+stringJsonResult.getData()).build();  | 
|             mqUtil.sendApp(build);  | 
|         }  | 
|         return  stringJsonResult;  | 
|     }  | 
|   | 
|   | 
|     @PostMapping( "/admin/front/fence/updateFenceProhibit.json")  | 
|     @ApiOperation(value="后台电子围栏是否启用接口", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name ="id", value = "合伙人Id",  dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "prohibit", value = "是否启用(0:启用,1:禁用)",  dataType = "String")  | 
|     })  | 
|     public JsonResult<String> updateFenceProhibit(@RequestBody XzxElectronicFenceModel model){  | 
|         Fence info=fenceService.queryById(model.getId());  | 
|         info.setProhibit(model.getProhibit().equals(0)?false:true);  | 
|         info.setUpdateTime(DateUtil.now());  | 
|         fenceService.update(info);  | 
|         return JsonResult.success("修改成功");  | 
|     }  | 
|   | 
|   | 
|     @PostMapping( "/admin/front/fence/queryPartnerFenceList.do")  | 
|     @ApiOperation(value="新增合伙人-查询所有未绑定的电子围栏", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name ="id", value = "合伙人Id", required = true, dataType = "String")  | 
|     })  | 
|     public JsonResult<List<XzxElectronicFenceModel>> queryPartnerFenceList(@RequestBody XzxCityPartnerModel model){  | 
|         List<XzxElectronicFenceModel> list =  cityPartnerService.queryPartnerFenceList(model);  | 
|         return JsonResult.success(list);  | 
|     }  | 
|   | 
|     @PostMapping ("/admin/front/fence/queryPartnerFenceListByUser.do")  | 
|     @ApiOperation(value="回收员绑定的电子围栏", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name ="id", value = "合伙人Id", required = true, dataType = "String")  | 
|     })  | 
|     public JsonResult<List<XzxElectronicFenceModel>> queryPartnerFenceListByUser(@RequestBody XzxCityPartnerModel model){  | 
|         List<XzxElectronicFenceModel> list =  cityPartnerService.queryPartnerFenceListByUser(model);  | 
|         return JsonResult.success(list);  | 
|     }  | 
|   | 
|   | 
|     @PostMapping("/admin/front/fence/findCascade")  | 
|     @ApiOperation(value="层级查询合伙人对应围栏")  | 
|     public Result<List<CityPartner>> findCascade(){  | 
|         List<CityPartner> byType = cityPartnerService.findByType(OrderEnum.合伙人.getValue());  | 
|         if(CollUtil.isNotEmpty(byType)){  | 
|             for (CityPartner cityPartner : byType) {  | 
|                 cityPartner.setName(cityPartner.getPartnerName());  | 
|                 List<Fence> byPartnerId = fenceService.findByPartnerId(cityPartner.getId().toString());  | 
|                 for (Fence fence : byPartnerId) {  | 
|                     fence.setName(fence.getFenceName());  | 
|                 }  | 
|                 cityPartner.setFences(byPartnerId);  | 
|             }  | 
|         }  | 
|         return Result.success(byType);  | 
|     }  | 
|   | 
| }  |