From 7356e2d19954e31aaa94edc375c9bc37220b928f Mon Sep 17 00:00:00 2001 From: wyw <373811525@qq.com> Date: Wed, 14 Aug 2024 15:47:24 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=AE=BE=E5=A4=87=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=AE=89=E9=98=B2=E9=A1=B5=E9=9D=A2=E6=95=B0=E6=8D=AE=E7=AC=AC?= =?UTF-8?q?=E4=BA=8C=E7=89=88=202=E3=80=81=E5=A2=9E=E5=8A=A0=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E8=8E=B7=E5=8F=96=E8=BF=9E=E6=8E=A5=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/controller/DeviceController.java | 116 +++++++-------- .../fastbee/data/domain/vo/AnfangInfoVo.java | 12 +- .../impl/DeviceDetailServiceImpl.java | 34 ++++- .../iot/domain/JiankongDeviceParam.java | 50 +++++++ .../iot/haikang/HaikangYingshiApi.java | 132 ++++++++++++++++++ .../com/fastbee/iot/haikang/UrlConstant.java | 28 ++++ .../fastbee/iot/service/IDeviceService.java | 3 +- .../iot/service/impl/DeviceServiceImpl.java | 78 ++++++++++- 8 files changed, 382 insertions(+), 71 deletions(-) create mode 100644 fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/domain/JiankongDeviceParam.java create mode 100644 fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/haikang/HaikangYingshiApi.java create mode 100644 fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/haikang/UrlConstant.java diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceController.java b/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceController.java index d62a924..a50c480 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceController.java +++ b/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceController.java @@ -14,6 +14,7 @@ import com.fastbee.common.utils.SecurityUtils; import com.fastbee.common.utils.StringUtils; import com.fastbee.common.utils.poi.ExcelUtil; import com.fastbee.iot.domain.Device; +import com.fastbee.iot.domain.JiankongDeviceParam; import com.fastbee.iot.model.DeviceAssignmentVO; import com.fastbee.iot.model.DeviceImportVO; import com.fastbee.iot.model.DeviceRelateUserInput; @@ -48,8 +49,7 @@ import java.util.stream.Collectors; @Api(tags = "设备管理") @RestController @RequestMapping("/iot/device") -public class DeviceController extends BaseController -{ +public class DeviceController extends BaseController { @Autowired private IDeviceService deviceService; @@ -63,8 +63,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:list')") @GetMapping("/list") @ApiOperation("设备分页列表") - public TableDataInfo list(Device device) - { + public TableDataInfo list(Device device) { startPage(); // 限制当前用户机构 if (null == device.getDeptId()) { @@ -79,8 +78,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:list')") @GetMapping("/unAuthlist") @ApiOperation("设备分页列表") - public TableDataInfo unAuthlist(Device device) - { + public TableDataInfo unAuthlist(Device device) { startPage(); if (null == device.getDeptId()) { device.setDeptId(getLoginUser().getDeptId()); @@ -94,8 +92,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:list')") @GetMapping("/listByGroup") @ApiOperation("查询分组可添加设备分页列表") - public TableDataInfo listByGroup(Device device) - { + public TableDataInfo listByGroup(Device device) { startPage(); LoginUser loginUser = getLoginUser(); if (null == loginUser.getDeptId()) { @@ -114,8 +111,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:list')") @GetMapping("/shortList") @ApiOperation("设备分页简短列表") - public TableDataInfo shortList(Device device) - { + public TableDataInfo shortList(Device device) { startPage(); LoginUser loginUser = getLoginUser(); if (null == loginUser.getDeptId()) { @@ -126,7 +122,7 @@ public class DeviceController extends BaseController if (null == device.getDeptId()) { device.setDeptId(getLoginUser().getDeptId()); } - if (Objects.isNull(device.getTenantId())){ + if (Objects.isNull(device.getTenantId())) { device.setTenantId(getLoginUser().getUserId()); } if (null == device.getShowChild()) { @@ -141,8 +137,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:list')") @GetMapping("/all") @ApiOperation("查询所有设备简短列表") - public TableDataInfo allShortList() - { + public TableDataInfo allShortList() { Device device = new Device(); device.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId()); device.setShowChild(true); @@ -156,8 +151,7 @@ public class DeviceController extends BaseController @Log(title = "设备", businessType = BusinessType.EXPORT) @PostMapping("/export") @ApiOperation("导出设备") - public void export(HttpServletResponse response, Device device) - { + public void export(HttpServletResponse response, Device device) { List list = deviceService.selectDeviceList(device); ExcelUtil util = new ExcelUtil(Device.class); util.exportExcel(response, list, "设备数据"); @@ -169,20 +163,19 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:query')") @GetMapping(value = "/{deviceId}") @ApiOperation("获取设备详情") - public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) - { + public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) { Device device = deviceService.selectDeviceByDeviceId(deviceId); // 判断当前用户是否有设备分享权限 (设备所属机构管理员和设备所属用户有权限) LoginUser loginUser = getLoginUser(); List roles = loginUser.getUser().getRoles(); //判断当前用户是否为设备所属机构管理员 - if(roles.stream().anyMatch(a-> "admin".equals(a.getRoleKey()))){ + if (roles.stream().anyMatch(a -> "admin".equals(a.getRoleKey()))) { device.setIsOwner(1); } else { //判断当前用户是否是设备所属用户 - if (Objects.equals(device.getTenantId(), loginUser.getUserId())){ + if (Objects.equals(device.getTenantId(), loginUser.getUserId())) { device.setIsOwner(1); - }else { + } else { device.setIsOwner(0); } } @@ -195,8 +188,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:query')") @GetMapping(value = "/synchronization/{serialNumber}") @ApiOperation("设备数据同步") - public AjaxResult deviceSynchronization(@PathVariable("serialNumber") String serialNumber) - { + public AjaxResult deviceSynchronization(@PathVariable("serialNumber") String serialNumber) { return AjaxResult.success(messagePublish.deviceSynchronization(serialNumber)); } @@ -206,8 +198,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:query')") @GetMapping(value = "/getDeviceBySerialNumber/{serialNumber}") @ApiOperation("根据设备编号获取设备详情") - public AjaxResult getInfoBySerialNumber(@PathVariable("serialNumber") String serialNumber) - { + public AjaxResult getInfoBySerialNumber(@PathVariable("serialNumber") String serialNumber) { return AjaxResult.success(deviceService.selectDeviceBySerialNumber(serialNumber)); } @@ -217,8 +208,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:query')") @GetMapping(value = "/statistic") @ApiOperation("获取设备统计信息") - public AjaxResult getDeviceStatistic() - { + public AjaxResult getDeviceStatistic() { return AjaxResult.success(deviceService.selectDeviceStatistic()); } @@ -228,8 +218,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:query')") @GetMapping(value = "/runningStatus") @ApiOperation("获取设备详情和运行状态") - public AjaxResult getRunningStatusInfo(Long deviceId) - { + public AjaxResult getRunningStatusInfo(Long deviceId) { return AjaxResult.success(deviceService.selectDeviceRunningStatusByDeviceId(deviceId)); } @@ -240,8 +229,7 @@ public class DeviceController extends BaseController @Log(title = "添加设备", businessType = BusinessType.INSERT) @PostMapping @ApiOperation("添加设备") - public AjaxResult add(@RequestBody Device device) - { + public AjaxResult add(@RequestBody Device device) { return AjaxResult.success(deviceService.insertDevice(device)); } @@ -253,12 +241,11 @@ public class DeviceController extends BaseController @Log(title = "设备关联用户", businessType = BusinessType.UPDATE) @PostMapping("/relateUser") @ApiOperation("终端-设备关联用户") - public AjaxResult relateUser(@RequestBody DeviceRelateUserInput deviceRelateUserInput) - { - if(deviceRelateUserInput.getUserId()==0 || deviceRelateUserInput.getUserId()==null){ + public AjaxResult relateUser(@RequestBody DeviceRelateUserInput deviceRelateUserInput) { + if (deviceRelateUserInput.getUserId() == 0 || deviceRelateUserInput.getUserId() == null) { return AjaxResult.error(MessageUtils.message("device.user.id.null")); } - if(deviceRelateUserInput.getDeviceNumberAndProductIds()==null || deviceRelateUserInput.getDeviceNumberAndProductIds().size()==0){ + if (deviceRelateUserInput.getDeviceNumberAndProductIds() == null || deviceRelateUserInput.getDeviceNumberAndProductIds().size() == 0) { return AjaxResult.error(MessageUtils.message("device.product.id.null")); } return deviceService.deviceRelateUser(deviceRelateUserInput); @@ -271,8 +258,7 @@ public class DeviceController extends BaseController @Log(title = "修改设备", businessType = BusinessType.UPDATE) @PutMapping @ApiOperation("修改设备") - public AjaxResult edit(@RequestBody Device device) - { + public AjaxResult edit(@RequestBody Device device) { return deviceService.updateDevice(device); } @@ -283,9 +269,8 @@ public class DeviceController extends BaseController @Log(title = "重置设备状态", businessType = BusinessType.UPDATE) @PutMapping("/reset/{serialNumber}") @ApiOperation("重置设备状态") - public AjaxResult resetDeviceStatus(@PathVariable String serialNumber) - { - Device device=new Device(); + public AjaxResult resetDeviceStatus(@PathVariable String serialNumber) { + Device device = new Device(); device.setSerialNumber(serialNumber); return toAjax(deviceService.resetDeviceStatus(device.getSerialNumber())); } @@ -295,7 +280,7 @@ public class DeviceController extends BaseController */ @PreAuthorize("@ss.hasPermi('iot:device:remove')") @Log(title = "删除设备", businessType = BusinessType.DELETE) - @DeleteMapping("/{deviceIds}") + @DeleteMapping("/{deviceIds}") @ApiOperation("批量删除设备") public AjaxResult remove(@PathVariable Long[] deviceIds) throws SchedulerException { return deviceService.deleteDeviceByDeviceId(deviceIds[0]); @@ -307,27 +292,27 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:add')") @GetMapping("/generator") @ApiOperation("生成设备编号") - public AjaxResult generatorDeviceNum(Integer type){ - return AjaxResult.success(MessageUtils.message("operate.success"),deviceService.generationDeviceNum(type)); + public AjaxResult generatorDeviceNum(Integer type) { + return AjaxResult.success(MessageUtils.message("operate.success"), deviceService.generationDeviceNum(type)); } /** * 获取设备MQTT连接参数 + * * @param deviceId 设备主键id * @return */ @PreAuthorize("@ss.hasPermi('iot:device:query')") @GetMapping("/getMqttConnectData") @ApiOperation("获取设备MQTT连接参数") - public AjaxResult getMqttConnectData(Long deviceId){ + public AjaxResult getMqttConnectData(Long deviceId) { return AjaxResult.success(deviceService.getMqttConnectData(deviceId)); } @PreAuthorize("@ss.hasPermi('iot:device:add')") @ApiOperation("下载设备导入模板") @PostMapping("/uploadTemplate") - public void uploadTemplate(HttpServletResponse response, @RequestParam(name = "type") Integer type) - { + public void uploadTemplate(HttpServletResponse response, @RequestParam(name = "type") Integer type) { // 1-设备导入;2-设备分配 if (1 == type) { ExcelUtil util = new ExcelUtil<>(DeviceImportVO.class); @@ -342,8 +327,7 @@ public class DeviceController extends BaseController @ApiOperation("批量导入设备") @Log(title = "用户管理", businessType = BusinessType.IMPORT) @PostMapping("/importData") - public AjaxResult importData(@RequestParam("file") MultipartFile file, @RequestParam("productId") Long productId) throws Exception - { + public AjaxResult importData(@RequestParam("file") MultipartFile file, @RequestParam("productId") Long productId) throws Exception { if (null == file) { return error(MessageUtils.message("import.failed.file.null")); } @@ -364,10 +348,7 @@ public class DeviceController extends BaseController @ApiOperation("批量导入分配设备") @Log(title = "用户管理", businessType = BusinessType.IMPORT) @PostMapping("/importAssignmentData") - public AjaxResult importAssignmentData(@RequestParam("file") MultipartFile file, - @RequestParam("productId") Long productId, - @RequestParam("deptId") Long deptId) throws Exception - { + public AjaxResult importAssignmentData(@RequestParam("file") MultipartFile file, @RequestParam("productId") Long productId, @RequestParam("deptId") Long deptId) throws Exception { if (null == file) { return error(MessageUtils.message("import.failed.file.null")); } @@ -386,15 +367,15 @@ public class DeviceController extends BaseController /** * 分配设备 + * * @param deptId 机构id - * @param: deviceIds 设备id字符串 * @return com.fastbee.common.core.domain.AjaxResult + * @param: deviceIds 设备id字符串 */ @PreAuthorize("@ss.hasPermi('iot:device:assignment')") @ApiOperation("分配设备") @PostMapping("/assignment") - public AjaxResult assignment(@RequestParam("deptId") Long deptId, - @RequestParam("deviceIds") String deviceIds) { + public AjaxResult assignment(@RequestParam("deptId") Long deptId, @RequestParam("deviceIds") String deviceIds) { if (null == deptId) { return error(MessageUtils.message("device.dept.id.null")); } @@ -406,14 +387,14 @@ public class DeviceController extends BaseController /** * 回收设备 - * @param: deviceIds 设备id字符串 + * * @return com.fastbee.common.core.domain.AjaxResult + * @param: deviceIds 设备id字符串 */ @PreAuthorize("@ss.hasPermi('iot:device:recovery')") @ApiOperation("回收设备") @PostMapping("/recovery") - public AjaxResult recovery(@RequestParam("deviceIds") String deviceIds, - @RequestParam("recoveryDeptId") Long recoveryDeptId) { + public AjaxResult recovery(@RequestParam("deviceIds") String deviceIds, @RequestParam("recoveryDeptId") Long recoveryDeptId) { if (StringUtils.isEmpty(deviceIds)) { return error("请选择设备"); } @@ -426,8 +407,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:batchGenerator')") @PostMapping("/batchGenerator") @ApiOperation("批量生成设备编号") - public void batchGeneratorDeviceNum(HttpServletResponse response, - @RequestParam("count") Integer count){ + public void batchGeneratorDeviceNum(HttpServletResponse response, @RequestParam("count") Integer count) { if (count > 200) { throw new ServiceException("最多只能生成200个!"); } @@ -448,8 +428,7 @@ public class DeviceController extends BaseController @PreAuthorize("@ss.hasPermi('iot:device:query')") @GetMapping("/listThingsModel") @ApiOperation("查询变量概况") - public TableDataInfo listThingsModel(Integer pageNum, Integer pageSize, Long deviceId, String modelName, Integer type) - { + public TableDataInfo listThingsModel(Integer pageNum, Integer pageSize, Long deviceId, String modelName, Integer type) { TableDataInfo rspData = new TableDataInfo(); rspData.setCode(HttpStatus.SUCCESS); rspData.setMsg("查询成功"); @@ -497,9 +476,20 @@ public class DeviceController extends BaseController */ @GetMapping("/getDeviceLogAllCurves") @ApiOperation("查询设备历史数据曲线图") - public AjaxResult getDeviceLogAllCurves(Long deviceId,String beginTime ,String endTime) { - ArrayList data = deviceService.getDeviceLogAllCurves(deviceId,beginTime ,endTime); + public AjaxResult getDeviceLogAllCurves(Long deviceId, String beginTime, String endTime) { + ArrayList data = deviceService.getDeviceLogAllCurves(deviceId, beginTime, endTime); return success(data); } + /** + * 获取视频监控 + * + * @param + * @return + */ + @GetMapping("/getvideourl") + public AjaxResult getvideourl(JiankongDeviceParam baseGet) throws Exception { + return AjaxResult.success(deviceService.getvideourl(baseGet)); + } + } diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/domain/vo/AnfangInfoVo.java b/fastbee-open-api/src/main/java/com/fastbee/data/domain/vo/AnfangInfoVo.java index ba7982b..92cbdf9 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/data/domain/vo/AnfangInfoVo.java +++ b/fastbee-open-api/src/main/java/com/fastbee/data/domain/vo/AnfangInfoVo.java @@ -1,14 +1,24 @@ package com.fastbee.data.domain.vo; import com.fastbee.iot.domain.Device; +import com.fastbee.iot.model.anfang.UploadedPhotos; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.List; + /** * 安防信息 */ @Data public class AnfangInfoVo { - + @ApiModelProperty("监控设备") private Device jiankongDevice; + @ApiModelProperty("门状态:0=正常,1=箱门振动,2=箱门打开") + private Integer doorStatus; + @ApiModelProperty("柜门ID,控制柜门开启的设备ID") + private String guimenId; + @ApiModelProperty("安防告警列表") + private ListanfangList; } diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/service/devicedetail/impl/DeviceDetailServiceImpl.java b/fastbee-open-api/src/main/java/com/fastbee/data/service/devicedetail/impl/DeviceDetailServiceImpl.java index d5827ad..7c261ca 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/data/service/devicedetail/impl/DeviceDetailServiceImpl.java +++ b/fastbee-open-api/src/main/java/com/fastbee/data/service/devicedetail/impl/DeviceDetailServiceImpl.java @@ -7,9 +7,11 @@ import com.fastbee.common.utils.StringUtils; import com.fastbee.common.utils.StringUtils; import com.fastbee.data.domain.vo.AnfangInfoVo; import com.fastbee.data.service.devicedetail.IDeviceDetailService; +import com.fastbee.iot.anfang.service.IUploadedPhotosService; import com.fastbee.iot.domain.Device; import com.fastbee.iot.haiwei.service.HaiWeiService; import com.fastbee.iot.mapper.DeviceMapper; +import com.fastbee.iot.model.anfang.UploadedPhotos; import com.fastbee.iot.model.haiwei.CmdHaiWeiVo; import com.fastbee.iot.model.haiwei.dto.CmdHaiWeiDto; import com.fastbee.iot.service.IDeviceService; @@ -24,6 +26,7 @@ import com.fastbee.xunjian.mapper.XjInspectionRoutesMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.xml.crypto.Data; import java.util.*; @Service @@ -41,6 +44,9 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService { private XjInspectionRecordsMapper xjInspectionRecordsMapper; @Autowired private HaiWeiService haiWeiService; + + @Autowired + private IUploadedPhotosService uploadedPhotosService; public DeviceDetailServiceImpl(DeviceMapper deviceMapper) { this.deviceMapper = deviceMapper; } @@ -140,9 +146,33 @@ public class DeviceDetailServiceImpl implements IDeviceDetailService { if(StringUtils.isNotEmpty(anfangIds)){ Device anfangDevice = iDeviceService.selectDeviceByDeviceId(Long.parseLong(anfangIds)); //获取当前安防告警状态 + UploadedPhotos uploadedPhotos = new UploadedPhotos(); + uploadedPhotos.setSn(anfangDevice.getSerialNumber()); + List uploadedPhotos1 = uploadedPhotosService.selectUploadedPhotosList(uploadedPhotos); + int doorStatus = 0;//0=正常,1=箱门振动,2=箱门打开 + if(uploadedPhotos1.size() > 0){ + UploadedPhotos temp = uploadedPhotos1.get(0); + if(new Date().getTime() - temp.getUploadTime().getTime() < 36000000){ + if(temp.getShakeState().equals("1")){ + doorStatus = 1; + } + if(temp.getDoorState().equals("1")){ + doorStatus = 2; + } + } + } + if(uploadedPhotos1.size() > 5){ + uploadedPhotos1 = uploadedPhotos1.subList(0,5); + } + anfangInfoVo.setDoorStatus(doorStatus); + anfangInfoVo.setAnfangList(uploadedPhotos1); } - //获取安防历史记录 - return null; + //安防设备 + String guimenIds = devParams.get("guimenIds").toString(); + if(StringUtils.isNotEmpty(guimenIds)){ + anfangInfoVo.setGuimenId(devParams.get("guimenIds").toString()); + } + return anfangInfoVo; } @Override public CommonResult cmdDevices(CmdHaiWeiDto cmdHaiWeiDto) { diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/domain/JiankongDeviceParam.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/domain/JiankongDeviceParam.java new file mode 100644 index 0000000..12cf7d3 --- /dev/null +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/domain/JiankongDeviceParam.java @@ -0,0 +1,50 @@ +package com.fastbee.iot.domain; + +import lombok.Data; + +/** + * 设备参数设置对象 device_param_config + * + * @author mafa + * @date 2023-08-22 + */ +@Data +public class JiankongDeviceParam +{ + private static final long serialVersionUID = 1L; + + + /** 设备id */ + private Long deviceId; + /** ezopen协议地址的本地录像/云存储录像回放开始时间,示例:2019-12-01 00:00:00 */ + private String startTime; + /** ezopen协议地址的本地录像/云存储录像回放开始时间,示例:2019-12-01 00:00:00 */ + private String stopTime; + /** ezopen协议地址的类型,1-预览,2-本地录像回放,3-云存储录像回放,非必选,默认为1 */ + private String type; + /** ezopen协议地址的设备的视频加密密码 */ + private String code; + /** 流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1 */ + private String protocol; + + /** 视频清晰度,1-高清(主码流)、2-流畅(子码流) */ + private String quality; + + /** 云台操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距 */ + private String direction; + /** 云台操作命令:速度 */ + private String speed; + + /** 云台操作命令:传了一直动 不传移动一格 */ + private String notStop; + + + + + + + + + + +} diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/haikang/HaikangYingshiApi.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/haikang/HaikangYingshiApi.java new file mode 100644 index 0000000..77a34a8 --- /dev/null +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/haikang/HaikangYingshiApi.java @@ -0,0 +1,132 @@ +package com.fastbee.iot.haikang; + +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; + +import java.util.HashMap; +import java.util.Map; + +/** + * 点点控api界面 + */ +public class HaikangYingshiApi { + /** + * @return + */ + public static JSONObject getToken(Map params) { + String url = UrlConstant.getToken;//指定URL + + HashMap headers = new HashMap<>();//存放请求头,可以存放多个请求头 + headers.put("Content-Type", "application/x-www-form-urlencoded"); + String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body(); + JSONObject jsonObject = new JSONObject(result); +// System.out.println("jsonObject = " + jsonObject); +// Map data =null; +// if (jsonObject.get("code").equals("200")) { +// data= (Map) jsonObject.get("data"); +// } + return jsonObject; + } + + /** + * @param params accessToken String 授权过程获取的access_token Y + * deviceSerial String 直播源,例如427734222,均采用英文符号,限制50个 Y + * channelNo Integer 通道号,,非必选,默认为1 N + * code String ezopen协议地址的设备的视频加密密码 N + * expireTime Integer 过期时长,单位秒;针对hls/rtmp设置有效期,相对时间;30秒-720天 N + * protocol Integer 流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1 N + * quality Integer 视频清晰度,1-高清(主码流)、2-流畅(子码流) N + * startTime String ezopen协议地址的本地录像/云存储录像回放开始时间,示例:2019-12-01 00:00:00 N + * stopTime String ezopen协议地址的本地录像/云存储录像回放开始时间,示例:2019-12-01 00:00:00 N + * type String ezopen协议地址的类型,1-预览,2-本地录像回放,3-云存储录像回放,非必选,默认为1 N + * supportH265 Integer 是否要求播放视频为H265编码格式,1表示需要,0表示不要求 N + * gbchannel String 国标设备的通道编号,视频通道编号ID N + * @return + */ + public static JSONObject getAddress(Map params) { +// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1 + String url = UrlConstant.address;//指定URL + HashMap headers = new HashMap<>();//存放请求头,可以存放多个请求头 + headers.put("Content-Type", "application/x-www-form-urlencoded"); + String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body(); + JSONObject jsonObject = new JSONObject(result); +// System.out.println("result = " + result); +// Map data =(Map) jsonObject.get("data"); + return jsonObject; + } + + /** + * @param params accessToken String 授权过程获取的access_token Y + * deviceSerial String 设备序列号,存在英文字母的设备序列号,字母需为大写 Y + * channelNo int 通道号 Y + * direction int 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距 Y + * speed int 云台速度:0-慢,1-适中,2-快,海康设备参数不可为0 + * @return + */ + public static JSONObject startMove(Map params) { +// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1 + String url = UrlConstant.startyuntai;//指定URL + HashMap headers = new HashMap<>();//存放请求头,可以存放多个请求头 + headers.put("Content-Type", "application/x-www-form-urlencoded"); + String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body(); + JSONObject jsonObject = new JSONObject(result); + + return jsonObject; + } + + /** + * @param params accessToken String 授权过程获取的access_token Y + * deviceSerial String 设备序列号,存在英文字母的设备序列号,字母需为大写 Y + * channelNo int 通道号 Y + * direction int 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距 Y + * @return + */ + public static JSONObject stopMove(Map params) { +// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1 + String url = UrlConstant.stopyuntai;//指定URL + HashMap headers = new HashMap<>();//存放请求头,可以存放多个请求头 + headers.put("Content-Type", "application/x-www-form-urlencoded"); + String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body(); + JSONObject jsonObject = new JSONObject(result); + + return jsonObject; + } + + + /** + * @param params accessToken String 授权过程获取的access_token Y + * deviceSerial String 设备序列号,存在英文字母的设备序列号,字母需为大写 Y + * channelNo int 通道号 Y + * direction int 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距 Y + * @return + */ + public static JSONObject getDeviceInfo(Map params) { +// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1 + String url = UrlConstant.deviceInfo;//指定URL + HashMap headers = new HashMap<>();//存放请求头,可以存放多个请求头 + headers.put("Content-Type", "application/x-www-form-urlencoded"); + String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body(); + JSONObject jsonObject = new JSONObject(result); + + return jsonObject; + } + + /** + * @param params accessToken String 授权过程获取的access_token Y + * deviceSerial String 直播源,例如427734222,均采用英文符号,限制50个 Y + * channelNo Integer 通道号,,非必选,默认为1 N + * @return + */ + public static JSONObject capture(Map params) { +// accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1 + String url = UrlConstant.capture;//指定URL + HashMap headers = new HashMap<>();//存放请求头,可以存放多个请求头 + headers.put("Content-Type", "application/x-www-form-urlencoded"); + String result = HttpUtil.createPost(url).addHeaders(headers).form(params).execute().body(); + JSONObject jsonObject = new JSONObject(result); +// System.out.println("result = " + result); +// Map data =(Map) jsonObject.get("data"); + return jsonObject; + } + +} diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/haikang/UrlConstant.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/haikang/UrlConstant.java new file mode 100644 index 0000000..b2c3907 --- /dev/null +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/haikang/UrlConstant.java @@ -0,0 +1,28 @@ +package com.fastbee.iot.haikang; + +/** + * 点点控 + */ +public class UrlConstant { + + public static String appKey = "be85054cf4504710861fad77ec4e4af9"; + public static String appSecret = "104f39e29f9847e5d819a99c1c32fc88"; + + //获取 token + public static String getToken = "https://open.ys7.com/api/lapp/token/get"; + //获取 直播地址 + public static String address = "https://open.ys7.com/api/lapp/v2/live/address/get"; + //开始云台 + public static String startyuntai = "https://open.ys7.com/api/lapp/device/ptz/start"; + //停止云台 + public static String stopyuntai = "https://open.ys7.com/api/lapp/device/ptz/stop"; + //设备信息 + public static String deviceInfo = "https://open.ys7.com/api/lapp/device/info"; + //设备抓拍图片 + public static String capture = "https://open.ys7.com/api/lapp/device/capture"; + //关闭设备视频加密 + public static String deviceEncryptOff = "https://open.ys7.com/api/lapp/device/encrypt/off"; + + +} + diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/IDeviceService.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/IDeviceService.java index 8602997..13efba3 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/IDeviceService.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/IDeviceService.java @@ -6,6 +6,7 @@ import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem; import com.fastbee.common.enums.DeviceStatus; import com.fastbee.iot.domain.Device; import com.fastbee.iot.domain.DeviceGroup; +import com.fastbee.iot.domain.JiankongDeviceParam; import com.fastbee.iot.model.*; import com.fastbee.iot.model.ThingsModels.ThingsModelShadow; import com.fastbee.iot.model.ThingsModels.ThingsModelValueItem; @@ -334,5 +335,5 @@ public interface IDeviceService ArrayList getDeviceLogAllCurves(Long deviceId, String beginTime, String endTime); - + Map getvideourl(JiankongDeviceParam jiankongDeviceParam); } diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceServiceImpl.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceServiceImpl.java index 7b17d0e..0d86811 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceServiceImpl.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceServiceImpl.java @@ -16,15 +16,13 @@ import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem; import com.fastbee.common.core.thingsModel.ThingsModelValuesInput; import com.fastbee.common.enums.*; import com.fastbee.common.exception.ServiceException; -import com.fastbee.common.utils.CaculateUtils; -import com.fastbee.common.utils.DateUtils; -import com.fastbee.common.utils.SecurityUtils; -import com.fastbee.common.utils.StringUtils; +import com.fastbee.common.utils.*; import com.fastbee.common.utils.http.HttpUtils; import com.fastbee.common.utils.ip.IpUtils; import com.fastbee.common.utils.json.JsonUtils; import com.fastbee.iot.cache.ITSLCache; import com.fastbee.iot.domain.*; +import com.fastbee.iot.haikang.HaikangYingshiApi; import com.fastbee.iot.mapper.*; import com.fastbee.iot.model.*; import com.fastbee.iot.model.ThingsModelItem.Datatype; @@ -1668,4 +1666,76 @@ public class DeviceServiceImpl implements IDeviceService { } + @Override + public Map getvideourl(JiankongDeviceParam jiankongDeviceParam) { + if (jiankongDeviceParam.getDeviceId() == null) { + throw new RuntimeException("请上传设备id"); + } + Device device = selectDeviceByDeviceId(jiankongDeviceParam.getDeviceId()); + + if (device == null) { + throw new RuntimeException("设备未找到"); + } + Map devData = DevParamsUtils.getDevParams(device.getDevParams()); + if (devData.get("appKey") == null) { + throw new RuntimeException("未绑定设备参数appKey"); + } + if (devData.get("appSecret") == null) { + throw new RuntimeException("未绑定设备参数appSecret"); + } + if (devData.get("channelNo") == null) { + throw new RuntimeException("未绑定设备参数channelNo"); + } + Map map = new HashMap<>();//存放参数 + map.put("appKey", devData.get("appKey")); + map.put("appSecret", devData.get("appSecret")); + cn.hutool.json.JSONObject token = HaikangYingshiApi.getToken(map); + if (token != null && token.get("code").equals("200")) { + Map params = new HashMap<>(); + // accessToken=at.dunwhxt2azk02hcn7phqygsybbw0wv6p&deviceSerial=C78957921&channelNo=1 + token = (cn.hutool.json.JSONObject) token.get("data"); + params.put("accessToken", token.get("accessToken")); + params.put("deviceSerial", device.getSerialNumber()); + + if (StringUtils.isNotEmpty(jiankongDeviceParam.getStartTime())) { + params.put("startTime", jiankongDeviceParam.getStartTime()); + } + if (StringUtils.isNotEmpty(jiankongDeviceParam.getStopTime())) { + params.put("stopTime", jiankongDeviceParam.getStopTime()); + } + if (StringUtils.isNotEmpty(jiankongDeviceParam.getType())) { + params.put("type", jiankongDeviceParam.getType()); + } + if (StringUtils.isNotEmpty(jiankongDeviceParam.getCode())) { + params.put("code", jiankongDeviceParam.getCode()); + } + if (StringUtils.isNotEmpty(jiankongDeviceParam.getProtocol())) { + params.put("protocol", jiankongDeviceParam.getProtocol()); + } + if (StringUtils.isNotEmpty(jiankongDeviceParam.getQuality())) { + params.put("quality", jiankongDeviceParam.getQuality()); + } + + cn.hutool.json.JSONObject response = HaikangYingshiApi.getAddress(params); + if (response != null && response.get("code").equals("200")) { + Map data = (cn.hutool.json.JSONObject) response.get("data"); + Map reMap = new HashMap<>(); + reMap.put("url", data.get("url")); + reMap.put("devName", device.getDeviceName()); + reMap.put("accessToken", token.get("accessToken")); + reMap.put("id", device.getDeviceId()); + reMap.put("status", device.getStatus() == null || device.getStatus() == 4 ? "离线" : "在线"); + return reMap; + } else { + throw new RuntimeException(response.get("msg").toString()); + } + + } else { + } + + return null; + } + + + }