From 904d3f36dcc02467fb355dd93092a0e3b1d1c66d Mon Sep 17 00:00:00 2001 From: Angel <1050374295@qq.com> Date: Fri, 29 Dec 2023 16:41:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=B8=80=E9=94=AE=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=8B=86=E8=BF=87=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/DevopsVideoInfoController.java | 58 +++++ .../domain/DevopsVideoInfo0.java | 150 +++++++++++ .../domain/DevopsVideoStatus.java | 93 +++++++ .../domain/dto/DevopsVideoInfoDto.java | 144 +++++++++++ .../domain/vo/DevopsVideoInfoVo.java | 140 +++++++++++ .../exception/ServiceException.java | 74 ++++++ .../mapper/DevopsVideoInfoMapper.java | 26 ++ .../service/DevopsVideoInfoService0.java | 39 +++ .../service/DevopsVideoStatusService.java | 35 +++ .../impl/DevopsVideoInfoServiceImpl.java | 233 ++++++++++++++++++ .../ssf/mysqloracletest/utils/JsoupUtils.java | 188 ++++++++++++++ 11 files changed, 1180 insertions(+) create mode 100644 src/main/java/com/ssf/mysqloracletest/Controller/DevopsVideoInfoController.java create mode 100644 src/main/java/com/ssf/mysqloracletest/domain/DevopsVideoInfo0.java create mode 100644 src/main/java/com/ssf/mysqloracletest/domain/DevopsVideoStatus.java create mode 100644 src/main/java/com/ssf/mysqloracletest/domain/dto/DevopsVideoInfoDto.java create mode 100644 src/main/java/com/ssf/mysqloracletest/domain/vo/DevopsVideoInfoVo.java create mode 100644 src/main/java/com/ssf/mysqloracletest/exception/ServiceException.java create mode 100644 src/main/java/com/ssf/mysqloracletest/mapper/DevopsVideoInfoMapper.java create mode 100644 src/main/java/com/ssf/mysqloracletest/service/DevopsVideoInfoService0.java create mode 100644 src/main/java/com/ssf/mysqloracletest/service/DevopsVideoStatusService.java create mode 100644 src/main/java/com/ssf/mysqloracletest/service/impl/DevopsVideoInfoServiceImpl.java create mode 100644 src/main/java/com/ssf/mysqloracletest/utils/JsoupUtils.java diff --git a/src/main/java/com/ssf/mysqloracletest/Controller/DevopsVideoInfoController.java b/src/main/java/com/ssf/mysqloracletest/Controller/DevopsVideoInfoController.java new file mode 100644 index 0000000..aef6ea9 --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/Controller/DevopsVideoInfoController.java @@ -0,0 +1,58 @@ +package com.ssf.mysqloracletest.Controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.ssf.mysqloracletest.domain.dto.DevopsVideoInfoDto; +import com.ssf.mysqloracletest.service.DevopsVideoInfoService0; +import com.ssf.mysqloracletest.task.AlarmInfoTask; +import com.ssf.mysqloracletest.utils.ConfigParam; +import com.ssf.mysqloracletest.utils.StringKit; +import lombok.RequiredArgsConstructor; +import lombok.extern.java.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 视频监控设备表(DevopsVideoInfo)Controller + * + * @author makejava + * @since 2023-11-29 09:34:46 + */ + +@RequiredArgsConstructor +@Component +public class DevopsVideoInfoController { + private static final Logger logger = LoggerFactory.getLogger(DevopsVideoInfoController.class); + private final DevopsVideoInfoService0 devopsVideoInfoService; + + /** + * 一键导入 + */ + @Scheduled(initialDelay = 100, fixedDelay = 3000) + public void yjdr(DevopsVideoInfoDto villageDeviceInfo) { + + if (!"true".equals(ConfigParam.DevopeVideoInfoSwitch)) { + return; + } + + String res = "error"; + try { + res = devopsVideoInfoService.yjdr(villageDeviceInfo); + if (res.contains("success")) { + logger.info("导入成功"); + } else { + logger.info("导入失败"); + } + } catch (Exception e) { + logger.error(StringKit.getTrace(e) + "导入出现错误"); + } + } + +} diff --git a/src/main/java/com/ssf/mysqloracletest/domain/DevopsVideoInfo0.java b/src/main/java/com/ssf/mysqloracletest/domain/DevopsVideoInfo0.java new file mode 100644 index 0000000..64b85d6 --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/domain/DevopsVideoInfo0.java @@ -0,0 +1,150 @@ +package com.ssf.mysqloracletest.domain; + +import com.baomidou.mybatisplus.annotation.*; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * 视频监控设备表(DevopsVideoInfo)Domain + * + * @author makejava + * @since 2023-12-01 20:06:03 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName(value = "devops_video_info") +public class DevopsVideoInfo0 implements Serializable { + + /** + * 主键 + */ + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 场所编码 + */ + private String placeCode; + + /** + * 场所名称 + */ + private String placeName; + + /** + * 设备编码 + */ + private String deviceCode; + + /** + * 设备名称 + */ + @TableField(condition = SqlCondition.LIKE) + private String deviceName; + + /** + * 监控类型 + */ + private Integer monitoringType; + @TableField(exist = false) + private String monitoringTypeCn; + + /** + * 安装位置 + */ + private String deviceAddress; + + /** + * 设备方位 + */ + private Integer orientation; + + @TableField(exist = false) + private String orientationCn; + + /** + * 设备SN编号 + */ + private String deviceSn; + + /** + * 设备品牌 + */ + private String deviceBrand; + + /** + * 设备ip + */ + private String deviceIp; + + /** + * 设备端口 + */ + private Integer devicePort; + + /** + * 设备MAC + */ + private String deviceMac; + + /** + * 设备经度 + */ + private Double longitude; + + /** + * 设备纬度 + */ + private Double latitude; + + /** + * U3D经度 + */ + private Double u3dLongitude; + + /** + * U3D纬度 + */ + private Double u3dLatitude; + + /** + * 设备高度 + */ + private String deviceHeight; + + /** + * 设备厂家 + */ + private String manufactor; + + /** + * 登陆帐号 + */ + private String account; + + /** + * 登陆密码 + */ + private String password; + + /** + * 通道国标编码 + */ + @TableField(condition = SqlCondition.LIKE) + private String gbsChannelNo; + + /** + * NVR设备编码 + */ + private String gbsNvrNo; + + /** + * 通道号 + */ + private Integer channelNo; + +} diff --git a/src/main/java/com/ssf/mysqloracletest/domain/DevopsVideoStatus.java b/src/main/java/com/ssf/mysqloracletest/domain/DevopsVideoStatus.java new file mode 100644 index 0000000..e79d25b --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/domain/DevopsVideoStatus.java @@ -0,0 +1,93 @@ +package com.ssf.mysqloracletest.domain; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * 视频监控状态表(DevopsVideoStatus)Domain + * + * @author makejava + * @since 2023-12-01 20:06:03 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName(value = "devops_video_status") +public class DevopsVideoStatus implements Serializable { + + /** + * 主键 + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 场所编码 + */ + private String placeCode; + + /** + * 场所名称 + */ + private String placeName; + + /** + * 设备编码 + */ + private String deviceCode; + + /** + * NVR设备编码 + */ + private String gbsNvrNo; + + /** + * 通道国标编码 + */ + @TableField(condition = SqlCondition.LIKE) + private String gbsChannelNo; + + /** + * 设备名称 + */ + @TableField(condition = SqlCondition.LIKE) + private String deviceName; + + /** + * 设备ip + */ + private String deviceIp; + + /** + * 监控类型 + */ + private Integer monitoringType; + @TableField(exist = false) + private String monitoringTypeCn; + + /** + * 心跳时间 + */ + private Long heartbeatTime; + + /** + * 是否在线 + */ + private Integer isOnline; + + @TableField(exist = false) + private String isOnlineCn; + + /** + * 设备经度 + */ + private Double longitude; + + /** + * 设备纬度 + */ + private Double latitude; + +} diff --git a/src/main/java/com/ssf/mysqloracletest/domain/dto/DevopsVideoInfoDto.java b/src/main/java/com/ssf/mysqloracletest/domain/dto/DevopsVideoInfoDto.java new file mode 100644 index 0000000..b58437f --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/domain/dto/DevopsVideoInfoDto.java @@ -0,0 +1,144 @@ +package com.ssf.mysqloracletest.domain.dto; + + +import lombok.Data; + +import java.io.Serializable; + +/** + * 视频监控设备表(DevopsVideoInfo)Domain + * + * @author makejava + * @since 2023-09-15 17:30:11 + */ +@Data +public class DevopsVideoInfoDto implements Serializable { + + /** + * 主键 + */ + private Long id; + + /** + * 场所编码 + */ + private String placeCode; + + /** + * 场所名称 + */ + private String placeName; + + /** + * 设备名称 + */ + private String deviceName; + + /** + * 监控类型 + */ + private Integer monitoringType; + + private String monitoringTypeCn; + + /** + * 安装位置 + */ + private String deviceAddress; + + /** + * 通道国标编码 + */ + private String gbsChannelNo; + + /** + * NVR设备编码 + */ + private String gbsNvrNo; + + /** + * 设备ip + */ + private String deviceIp; + + /** + * 设备经度 + */ + private Double longitude; + + /** + * 设备纬度 + */ + private Double latitude; + + /** + * 设备高度 + */ + private String deviceHeight; + + /** + * 设备方位 + */ + private Integer orientation; + + private String orientationCn; + + /** + * 通道号 + */ + private Integer channelNo; + + /** + * U3D经度 + */ + private Double u3dLongitude; + + /** + * U3D纬度 + */ + private Double u3dLatitude; + + /** + * 登陆帐号 + */ + private String account; + + /** + * 登陆密码 + */ + private String password; + + /** + * 设备厂家 + */ + private String manufactor; + + /** + * 设备品牌 + */ + private String deviceBrand; + + /** + * 设备SN编号 + */ + private String deviceSn; + + /** + * 设备端口 + */ + private Integer devicePort; + + /** + * 设备MAC + */ + private String deviceMac; + + + /** + * 设备编码 + */ + private String deviceCode; + + + private String type; +} diff --git a/src/main/java/com/ssf/mysqloracletest/domain/vo/DevopsVideoInfoVo.java b/src/main/java/com/ssf/mysqloracletest/domain/vo/DevopsVideoInfoVo.java new file mode 100644 index 0000000..0030fbc --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/domain/vo/DevopsVideoInfoVo.java @@ -0,0 +1,140 @@ +package com.ssf.mysqloracletest.domain.vo; + +import com.ruoyi.common.core.domain.BaseEntity; +import lombok.Data; + +/** + * 视频监控设备表(DevopsVideoInfo)Domain + * + * @author makejava + * @since 2023-12-01 20:06:03 + */ +@Data +public class DevopsVideoInfoVo extends BaseEntity { + + /** + * 主键 + */ + private Long id; + + /** + * 场所编码 + */ + private String placeCode; + + /** + * 场所名称 + */ + private String placeName; + + /** + * 设备编码 + */ + private String deviceCode; + + /** + * 设备名称 + */ + private String deviceName; + + /** + * 监控类型 + */ + private Integer monitoringType; + + /** + * 安装位置 + */ + private String deviceAddress; + + /** + * 设备方位 + */ + private Integer orientation; + + /** + * 设备SN编号 + */ + private String deviceSn; + + /** + * 设备品牌 + */ + private String deviceBrand; + + /** + * 设备ip + */ + private String deviceIp; + + /** + * 设备端口 + */ + private Integer devicePort; + + /** + * 设备MAC + */ + private String deviceMac; + + /** + * 设备经度 + */ + private Double longitude; + + /** + * 设备纬度 + */ + private Double latitude; + + /** + * U3D经度 + */ + private Double u3dLongitude; + + /** + * U3D纬度 + */ + private Double u3dLatitude; + + /** + * 设备高度 + */ + private String deviceHeight; + + /** + * 设备厂家 + */ + private String manufactor; + + /** + * 登陆帐号 + */ + private String account; + + /** + * 登陆密码 + */ + private String password; + + /** + * 通道国标编码 + */ + private String gbsChannelNo; + + /** + * NVR设备编码 + */ + private String gbsNvrNo; + + /** + * 通道号 + */ + private Integer channelNo; + + private String plateNo; + + + + +} diff --git a/src/main/java/com/ssf/mysqloracletest/exception/ServiceException.java b/src/main/java/com/ssf/mysqloracletest/exception/ServiceException.java new file mode 100644 index 0000000..b30040d --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/exception/ServiceException.java @@ -0,0 +1,74 @@ +package com.ssf.mysqloracletest.exception; + +/** + * 业务异常 + * + * @author ruoyi + */ +public final class ServiceException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + /** + * 错误码 + */ + private Integer code; + + /** + * 错误提示 + */ + private String message; + + /** + * 错误明细,内部调试错误 + * + * 和 + */ + private String detailMessage; + + /** + * 空构造方法,避免反序列化问题 + */ + public ServiceException() + { + } + + public ServiceException(String message) + { + this.message = message; + } + + public ServiceException(String message, Integer code) + { + this.message = message; + this.code = code; + } + + public String getDetailMessage() + { + return detailMessage; + } + + @Override + public String getMessage() + { + return message; + } + + public Integer getCode() + { + return code; + } + + public ServiceException setMessage(String message) + { + this.message = message; + return this; + } + + public ServiceException setDetailMessage(String detailMessage) + { + this.detailMessage = detailMessage; + return this; + } +} \ No newline at end of file diff --git a/src/main/java/com/ssf/mysqloracletest/mapper/DevopsVideoInfoMapper.java b/src/main/java/com/ssf/mysqloracletest/mapper/DevopsVideoInfoMapper.java new file mode 100644 index 0000000..8b43001 --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/mapper/DevopsVideoInfoMapper.java @@ -0,0 +1,26 @@ +package com.ssf.mysqloracletest.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ssf.mysqloracletest.domain.DevopsVideoInfo0; +import com.ssf.mysqloracletest.domain.vo.DevopsVideoInfoVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * 视频监控设备表(DevopsVideoInfo)Mapper + * + * @author makejava + * @since 2023-11-29 09:33:21 + */ +@Mapper +public interface DevopsVideoInfoMapper extends BaseMapper { + + @Select(" select " + + " *, " + + " CONCAT('苏',SUBSTRING_INDEX(SUBSTRING_INDEX(device_name, '苏', -1), ' ', 1) ) AS plate_no " + + " from devops_video_info where device_name like '%苏J%' ") + public List listPoliceVehicle(DevopsVideoInfo0 bean) ; + +} diff --git a/src/main/java/com/ssf/mysqloracletest/service/DevopsVideoInfoService0.java b/src/main/java/com/ssf/mysqloracletest/service/DevopsVideoInfoService0.java new file mode 100644 index 0000000..4e6bdd0 --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/service/DevopsVideoInfoService0.java @@ -0,0 +1,39 @@ +package com.ssf.mysqloracletest.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ssf.mysqloracletest.domain.DevopsVideoInfo0; +import com.ssf.mysqloracletest.domain.dto.DevopsVideoInfoDto; +import com.ssf.mysqloracletest.domain.vo.DevopsVideoInfoVo; + + +import java.util.List; + +/** + * 视频监控设备表(DevopsVideoInfo)Service + * + * @author makejava + * @since 2023-11-29 09:33:20 + */ +public interface DevopsVideoInfoService0 extends IService { + + /** + * 新增或者更新视频监控设备表 + * + * @param devopsVideoInfo 视频监控设备表对象 + * @return 结果 + */ + boolean insertOrUpdate(DevopsVideoInfo0 devopsVideoInfo); + + /** + * 导入视频监控设备表 + * + * @param list 视频监控设备表列表 + * @return 结果 + */ + Object importData(List list); + + public String yjdr(DevopsVideoInfoDto bean); + + public List listPoliceVehicle(DevopsVideoInfo0 bean); +} diff --git a/src/main/java/com/ssf/mysqloracletest/service/DevopsVideoStatusService.java b/src/main/java/com/ssf/mysqloracletest/service/DevopsVideoStatusService.java new file mode 100644 index 0000000..bec7d25 --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/service/DevopsVideoStatusService.java @@ -0,0 +1,35 @@ +package com.ssf.mysqloracletest.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ssf.mysqloracletest.domain.DevopsVideoStatus; + + +import java.util.List; + +/** + * 视频监控状态表(DevopsVideoStatus)Service + * + * @author makejava + * @since 2023-11-29 09:33:21 + */ +public interface DevopsVideoStatusService extends IService { + + /** + * 新增或者更新视频监控状态表 + * + * @param devopsVideoStatus 视频监控状态表对象 + * @return 结果 + */ + boolean insertOrUpdate(DevopsVideoStatus devopsVideoStatus); + + /** + * 导入视频监控状态表 + * + * @param list 视频监控状态表列表 + * @return 结果 + */ + Object importData(List list); + + int getGbsListOnline(); +} diff --git a/src/main/java/com/ssf/mysqloracletest/service/impl/DevopsVideoInfoServiceImpl.java b/src/main/java/com/ssf/mysqloracletest/service/impl/DevopsVideoInfoServiceImpl.java new file mode 100644 index 0000000..9824b3c --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/service/impl/DevopsVideoInfoServiceImpl.java @@ -0,0 +1,233 @@ +package com.ssf.mysqloracletest.service.impl; + + +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ssf.mysqloracletest.domain.DevopsVideoInfo0; +import com.ssf.mysqloracletest.domain.DevopsVideoStatus; +import com.ssf.mysqloracletest.domain.dto.DevopsVideoInfoDto; +import com.ssf.mysqloracletest.domain.vo.DevopsVideoInfoVo; +import com.ssf.mysqloracletest.exception.ServiceException; +import com.ssf.mysqloracletest.mapper.DevopsVideoInfoMapper; +import com.ssf.mysqloracletest.service.DevopsVideoInfoService0; +import com.ssf.mysqloracletest.service.DevopsVideoStatusService; +import com.ssf.mysqloracletest.utils.JsoupUtils; +import com.ssf.mysqloracletest.utils.NumKit; +import com.ssf.mysqloracletest.utils.PropertiesUtil; +import com.ssf.mysqloracletest.utils.StringKit; +import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 视频监控设备表(DevopsVideoInfo)ServiceImpl + * + * @author makejava + * @since 2023-11-29 09:33:20 + */ +@Service +@RequiredArgsConstructor +public class DevopsVideoInfoServiceImpl extends ServiceImpl implements DevopsVideoInfoService0 { + + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + + + private final DevopsVideoInfoMapper videoInfoMapper; + private final DevopsVideoStatusService videoStatusService; + + + @Override + public boolean insertOrUpdate(DevopsVideoInfo0 devopsVideoInfo) { + return false; + } + + @Override + public Object importData(List list) { + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + + for (DevopsVideoInfo0 devopsVideoInfo : list) { + try { + insertOrUpdate(devopsVideoInfo); + successNum++; + successMsg.append(StrUtil.format("
{}、待替换 {} 导入成功", successNum, "待替换")); + } catch (Exception e) { + failureNum++; + failureMsg.append(StrUtil.format("
{}、待替换 {} 导入失败:{}", failureNum, "待替换", e.getMessage())); + } + } + + if (failureNum > 0) { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new ServiceException(failureMsg.toString()); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + return successMsg.toString(); + } + } + + + @Override + public String yjdr(DevopsVideoInfoDto bean) { + String type = StringKit.toString(bean.getType()); + if ("".equals(type)) { + return "error-导入类型未设置"; + } + + if ("gbs".equals(type)) { + int count = 0; + String gbsip = PropertiesUtil.queryPropertiesByKey("gbsIp"); + String gbsport = PropertiesUtil.queryPropertiesByKey("gbsPort"); + + String loginurl = "http://" + gbsip + ":" + gbsport + "/api/v1/login?username=admin&password=af7548eedff8e737c0e4b2a669497290#&url_token_only=true"; + + String res = JsoupUtils.getJsoupDocGet(loginurl); + JSONObject loginResJson = JSON.parseObject(res); + String urlToken = ""; + if (loginResJson != null) { + urlToken = StringKit.toString(loginResJson.get("URLToken")); + } + //如果urltoken获取失败直接结束方法 + if ("".equals(urlToken)) { + return "urltoken 获取失败!请检查配置文件是否正确"; + } + String channellistUrl = "http://" + gbsip + ":" + gbsport + "/api/v1/device/channellist?token=" + urlToken + "&url_token_only=true&start=0&limit=20000"; + + logger.info("channellistUrl:"+ channellistUrl); + + String channellistRes = JsoupUtils.getJsoupDocGet(channellistUrl); + if ("".equals(StringKit.toString(channellistRes))) { + return "调用设备列表失败!请检查配置文件是否正确"; + } + JSONObject channelObj = JSONObject.parseObject(channellistRes); + String channelJsonArrStr = StringKit.toString(channelObj.get("ChannelList")); + JSONArray channelJsonArr = JSONArray.parseArray(channelJsonArrStr); + if (channelJsonArr != null && channelJsonArr.size() > 0) { + + logger.info("channelJsonArr size = " + channelJsonArr.size()); + + for (Object o : channelJsonArr) { + try { + bean = new DevopsVideoInfoDto(); + count = 1; + String channelStr = StringKit.toString(o); + JSONObject channelJson = JSONObject.parseObject(channelStr); + + String Name = StringKit.toString(channelJson.get("Name")); + if (Name.contains("GB")) { + logger.info("过滤包含GB的数据:"); + continue; + } + + String villageName = ""; + String villageCode = ""; + + + String code = StringKit.toString(channelJson.get("ID")); + //在线离线 ON在线 OFF离线 + String Status = StringKit.toString(channelJson.get("Status")); + bean.setGbsChannelNo(code); + + String name = StringKit.toString(channelJson.get("CustomName")); + if ("".equals(name)) { + name = StringKit.toString(channelJson.get("Name")); + } + + String deviceip = StringKit.toString(channelJson.get("CustomIPAddress")); + if ("".equals(StringKit.toString(name))) { + logger.info("地址数据为空:" + deviceip + ",code:" + code); + continue; + } + + bean.setDeviceName(name); + //默认公共区域 + if (code.contains("151")) { + bean.setMonitoringType(5); + } else { + bean.setMonitoringType(1); + } + bean.setPlaceCode(villageCode); + bean.setPlaceName(villageName); + bean.setDeviceIp(deviceip); + String address = name; + bean.setDeviceAddress(address); + String manufacturer = StringKit.toString(channelJson.get("Manufacturer")); + bean.setManufactor(manufacturer); + String port = StringKit.toString(channelJson.get("Port")); + bean.setDevicePort(NumKit.checkInt(port)); + String latitude = StringKit.toString(channelJson.get("Latitude")); + bean.setLatitude(NumKit.checkDouble(latitude)); + String longitude = StringKit.toString(channelJson.get("Longitude")); + bean.setLongitude(NumKit.checkDouble(longitude)); + String channel = StringKit.toString(channelJson.get("Channel")); + bean.setChannelNo(NumKit.checkInt(channel)); + String gbsNvrNo = StringKit.toString(channelJson.get("DeviceId")); + bean.setGbsNvrNo(StringKit.toString(gbsNvrNo)); + + if (!"".equals(StringKit.toString(bean.getGbsChannelNo()))) { + List checklists = videoInfoMapper.selectList(new LambdaQueryWrapper() + .eq(DevopsVideoInfo0::getGbsChannelNo, bean.getGbsChannelNo())); + if (checklists != null && checklists.size() > 0) { + logger.info("设备国标已存在:" + bean.getGbsChannelNo()); + continue; + } + } else { + logger.info("国标编码为空:" + bean.getGbsChannelNo()); + continue; + } + + + DevopsVideoInfo0 videoInfo = new DevopsVideoInfo0(); + BeanUtils.copyProperties(bean, videoInfo); + int b = videoInfoMapper.insert(videoInfo); + //默认离线 + int isOnline = 2; + if ("ON".equals(Status)) { + isOnline = 1; + } + + //如果设备插入成功 + DevopsVideoStatus videoStatus = new DevopsVideoStatus(); + videoStatus.setGbsNvrNo(StringKit.toString(videoInfo.getGbsNvrNo())); + videoStatus.setGbsChannelNo(StringKit.toString(videoInfo.getGbsChannelNo())); + videoStatus.setDeviceName(StringKit.toString(videoInfo.getDeviceName())); + videoStatus.setDeviceIp(StringKit.toString(videoInfo.getDeviceIp())); + videoStatus.setMonitoringType(videoInfo.getMonitoringType()); + videoStatus.setHeartbeatTime(System.currentTimeMillis() / 1000); + videoStatus.setIsOnline(isOnline); + videoStatusService.save(videoStatus); + logger.info("保存成功:" + videoInfo.getGbsChannelNo()); + } catch (Exception e) { + logger.info("保存失败," + StringKit.getTrace(e)); + continue; + } + } + } else { + return "结果集为空,请检查gbs是否配置。"; + } + return "success-" + count; + } else if ("nvr".equals(type)) { + //调用nvr插入设备 + } else { + return "error-类型不正确"; + } + return "error-未知错误"; + } + + @Override + public List listPoliceVehicle(DevopsVideoInfo0 bean) { + return videoInfoMapper.listPoliceVehicle(bean); + } + + +} diff --git a/src/main/java/com/ssf/mysqloracletest/utils/JsoupUtils.java b/src/main/java/com/ssf/mysqloracletest/utils/JsoupUtils.java new file mode 100644 index 0000000..1947d14 --- /dev/null +++ b/src/main/java/com/ssf/mysqloracletest/utils/JsoupUtils.java @@ -0,0 +1,188 @@ +package com.ssf.mysqloracletest.utils; + + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.jsoup.Connection; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; + +import java.io.InputStream; +import java.util.Map; +import java.util.Set; + +public class JsoupUtils { + + private static final Logger log = LoggerFactory.getLogger(JsoupUtils.class); + + public static String getJsoupDocGet(String url) { + //三次试错 + final int MAX = 10; + int time = 0; + Document doc = null; + while (time < MAX) { + try { + doc = Jsoup + .connect(url) + .ignoreContentType(true) + .ignoreHttpErrors(true) + .timeout(1000 * 30) + .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36") + .header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") + .header("accept-encoding", "gzip, deflate, br") + .header("accept-language", "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7") + .maxBodySize(0) + .get(); + String text = doc.text(); + if (text.contains("illegal")) { + return ""; + } else { + return doc.text(); + } + } catch (Exception e) { + log.info(StringKit.getTrace(e)); + } finally { + time++; + } + } + return ""; + } + + //将文件传入 post请求中 + public static String doPostFileRequest(String url, Map param, InputStream fis, String fileName) throws Exception { + try { + Connection conn = Jsoup.connect(url); + if (param != null) { + conn.data(param); + } + conn.data("imagefile", fileName, fis); + Connection.Response response = conn.timeout(50000) + .ignoreContentType(true) + .maxBodySize(0) + .followRedirects(true) + .method(Connection.Method.POST).execute(); + return response.body(); + } catch (Exception e) { + throw new Exception(e); + } + } + + + /** + * post 请求通用入口 + * + * @param url + * @param map + * @return + */ + public static String jsoupPost(String url, Map map, String json) { + String res = ""; + try { + Connection con = Jsoup.connect(url); + con.requestBody(json); + con.header("Content-Type", "application/json"); + con.ignoreContentType(true); + Document doc = con.timeout(50000).post(); + res = doc.text(); + } catch (Exception e) { + log.info(StringKit.getTrace(e)); + } + return res; + } + + public static String jsoupPost(String url, Map map) { + String res = ""; + try { + Connection con = Jsoup.connect(url); + if (map != null && map.size() > 0) { + Set sets = map.keySet(); + for (String s : sets) { + con.data(s, StringKit.toString(map.get(s))); + } + } + con.ignoreContentType(true); + Document doc = + con.timeout(50000) + .post(); + res = doc.text(); + } catch (Exception e) { + log.info(StringKit.getTrace(e)); + } + return res; + } + + /** + * 获取Gbs平台token + * + * @return + */ + public static String getGbsToken() { + String urlToken = ""; + try { + String gbsIp = PropertiesUtil.queryPropertiesByKey("gbsIp"); + if (StringUtils.isBlank(gbsIp)) { + gbsIp = "127.0.0.1"; + } + String gbsPort = PropertiesUtil.queryPropertiesByKey("gbsPort"); + String url = "http://" + gbsIp + ":" + gbsPort + "/api/v1/login?username=admin&password=af7548eedff8e737c0e4b2a669497290&url_token_only=true"; + String res = JsoupUtils.getJsoupDocGet(url); + JSONObject loginResJson = JSON.parseObject(res); + if (loginResJson != null) { + urlToken = StringKit.toString(loginResJson.get("URLToken")); + } + } catch (Exception e) { + log.info(StringKit.getTrace(e)); + } + return urlToken; + } + + public static String getGbsToken(String ip) { + String urlToken = ""; + try { + String gbsIp = PropertiesUtil.queryPropertiesByKey("gbsIp"); + if (StringUtils.isBlank(gbsIp)) { + gbsIp = ip; + } + String gbsPort = PropertiesUtil.queryPropertiesByKey("gbsPort"); + String url = "http://" + gbsIp + ":" + gbsPort + "/api/v1/login?username=admin&password=af7548eedff8e737c0e4b2a669497290&url_token_only=true"; + String res = JsoupUtils.getJsoupDocGet(url); + JSONObject loginResJson = JSON.parseObject(res); + if (loginResJson != null) { + urlToken = StringKit.toString(loginResJson.get("URLToken")); + } + } catch (Exception e) { + + } + return urlToken; + } + + /** + * 获取NVR平台token + * + * @return + */ + public static String getNvrToken() { + String urlToken = ""; + try { + String nvrIp = PropertiesUtil.queryPropertiesByKey("nvrIp"); + String nvrPort = PropertiesUtil.queryPropertiesByKey("nvrPort"); + String url = "http://" + nvrIp + ":" + nvrPort + "/api/v1/login?username=admin&password=af7548eedff8e737c0e4b2a669497290&url_token_only=true"; + String res = JsoupUtils.getJsoupDocGet(url); + JSONObject loginResJson = JSON.parseObject(res); + JSONObject liveQing = JSON.parseObject(StringKit.toString(loginResJson.get("LiveQing"))); + JSONObject body = JSON.parseObject(StringKit.toString(liveQing.get("Body"))); + urlToken = StringKit.toString(body.get("URLToken")); + if (StringUtils.isNotBlank(urlToken)) { + System.out.println("urlToken:" + urlToken); + } + } catch (Exception e) { + + } + return urlToken; + } + + +}