|  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; | 
|---|
|  |  |  | import com.ruoyi.device.camera.domain.ArdCameras; | 
|---|
|  |  |  | import com.ruoyi.device.camera.domain.CameraCmd; | 
|---|
|  |  |  | import com.ruoyi.device.camera.service.IArdCamerasService; | 
|---|
|  |  |  | import com.ruoyi.device.hiksdk.service.impl.HikClientServiceImpl; | 
|---|
|  |  |  | import com.ruoyi.common.utils.SecurityUtils; | 
|---|
|  |  |  | import com.ruoyi.common.utils.poi.ExcelUtil; | 
|---|
|  |  |  | import com.ruoyi.inspect.service.IArdVideoInspectTaskService; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.AjaxResult; | 
|---|
|  |  |  | import com.ruoyi.common.enums.BusinessType; | 
|---|
|  |  |  | import com.ruoyi.common.core.page.TableDataInfo; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 相机设备Controller | 
|---|
|  |  |  | 
|---|
|  |  |  | private HikClientServiceImpl sdk; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private IArdCamerasService ardCamerasService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private IArdVideoInspectTaskService ardVideoInspectTaskService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询相机设备列表 | 
|---|
|  |  |  | 
|---|
|  |  |  | //注销 | 
|---|
|  |  |  | sdk.loginOut(camera.getId()); | 
|---|
|  |  |  | //登录 | 
|---|
|  |  |  | camera = sdk.login(camera); | 
|---|
|  |  |  | if (camera.getLoginId() >= 0) { | 
|---|
|  |  |  | log.info("相机" + camera.getIp() + ":" + camera.getPort() + "登录成功:" + camera.getLoginId()); | 
|---|
|  |  |  | camera.setUpdateBy(SecurityUtils.getUsername()); | 
|---|
|  |  |  | ardCamerasService.updateArdCameras(camera); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | log.info("相机" + camera.getIp() + ":" + camera.getPort() + "登录失败:" + camera.getLoginId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | sdk.login(camera); | 
|---|
|  |  |  | return toAjax(ardCamerasService.insertArdCameras(camera)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @PutMapping | 
|---|
|  |  |  | public AjaxResult edit(@RequestBody ArdCameras camera) { | 
|---|
|  |  |  | int i = ardCamerasService.updateArdCameras(camera); | 
|---|
|  |  |  | if(i>0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (i > 0) { | 
|---|
|  |  |  | ArdCameras cameras = ardCamerasService.selectArdCamerasById(camera.getId()); | 
|---|
|  |  |  | sdk.loginOut(cameras.getId()); | 
|---|
|  |  |  | camera = sdk.login(cameras); | 
|---|
|  |  |  | if (camera.getLoginId() >= 0) { | 
|---|
|  |  |  | log.info("相机" + camera.getIp() + ":" + camera.getPort() + "登录成功:" + camera.getLoginId()); | 
|---|
|  |  |  | ardCamerasService.updateArdCameras(camera); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | log.info("相机" + camera.getIp() + ":" + camera.getPort() + "登录失败:" + camera.getLoginId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | sdk.login(cameras); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return toAjax(i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @DeleteMapping("/{ids}") | 
|---|
|  |  |  | public AjaxResult remove(@PathVariable String[] ids) { | 
|---|
|  |  |  | for (String id : ids) { | 
|---|
|  |  |  | sdk.loginOut(id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | sdk.loginOut(id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return toAjax(ardCamerasService.deleteArdCamerasByIds(ids)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/options") | 
|---|
|  |  |  | @ApiOperation("选择相机数据") | 
|---|
|  |  |  | public List options(ArdCameras ardCameras) { | 
|---|
|  |  |  | 
|---|
|  |  |  | Map option = new HashMap(); | 
|---|
|  |  |  | option.put("value", item.getId()); | 
|---|
|  |  |  | option.put("label", item.getName()); | 
|---|
|  |  |  | // option.put("description", item.getOilProduction()); | 
|---|
|  |  |  | option.put("channel", item.getChannel()); | 
|---|
|  |  |  | List timeList = ardVideoInspectTaskService.getCameraIdleTimeList(item.getId()); | 
|---|
|  |  |  | option.put("idleTimeList", timeList);//空闲时间段 | 
|---|
|  |  |  | options.add(option); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return options; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/getDeptAndCamera") | 
|---|
|  |  |  | @ApiOperation("获取部门和相机") | 
|---|
|  |  |  | public AjaxResult getDeptAndCamera() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Map deptAndCamera = ardCamerasService.getChildDeptAndCamera(true); | 
|---|
|  |  |  | return AjaxResult.success(deptAndCamera); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @GetMapping("/getDeptAndCameraWithCheckBox") | 
|---|
|  |  |  | @ApiOperation("获取部门和相机(开启复选框)") | 
|---|
|  |  |  | public AjaxResult getDeptAndCameraWithCheckBox() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Map deptAndCamera = ardCamerasService.getChildDeptAndCamera(false); | 
|---|
|  |  |  | return AjaxResult.success(deptAndCamera); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @PostMapping("/getNearCamerasBycoordinate") | 
|---|
|  |  |  | @ApiOperation("获取附近的相机") | 
|---|
|  |  |  | @ApiOperationSupport(includeParameters = {"targetPosition"}) | 
|---|
|  |  |  | public AjaxResult getNearCamerasBycoordinate(@RequestBody CameraCmd cmd) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | TreeMap nearCamerasBycoordinate = ardCamerasService.getNearCamerasBycoordinate(cmd); | 
|---|
|  |  |  | return AjaxResult.success(nearCamerasBycoordinate); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|