Browse Source

摄像机配置

platform-api
4670101279 2 years ago
parent
commit
b54cc99fd6
  1. 130
      ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/CameraNetFtpController.java
  2. 55
      ruoyi-code/src/main/java/com/ruoyi/code/camera/domain/CameraNetFtp.java
  3. 18
      ruoyi-code/src/main/java/com/ruoyi/code/camera/mapper/CameraNetFtpMapper.java
  4. 4
      ruoyi-code/src/main/java/com/ruoyi/code/camera/scheduled/RegisterServer.java
  5. 25
      ruoyi-code/src/main/java/com/ruoyi/code/camera/service/ICameraNetFtpService.java
  6. 70
      ruoyi-code/src/main/java/com/ruoyi/code/camera/service/impl/CameraNetFtpServiceImpl.java
  7. 34
      ruoyi-code/src/main/java/utils/run_device_cfg.java
  8. 91
      ruoyi-common/src/main/java/com/ruoyi/common/utils/IPUtils.java

130
ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/CameraNetFtpController.java

@ -0,0 +1,130 @@
package com.ruoyi.code.camera.controller;
import java.util.List;
import java.util.Arrays;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.code.camera.service.ICameraService;
import com.ruoyi.common.core.page.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.code.camera.domain.CameraNetFtp;
import com.ruoyi.code.camera.service.ICameraNetFtpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
/**
* 摄像机FTP配置Controller
*
* @author ruoyi
* @date 2022-06-28
*/
@RestController
@RequestMapping("/camera/ftp")
public class CameraNetFtpController extends BaseController
{
@Resource
private ICameraNetFtpService cameraNetFtpService;
@Resource
private ICameraService cameraService;
/**
* 查询列表
*/
@PreAuthorize("@ss.hasPermi('camera:ftp:list')")
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params){
return cameraNetFtpService.queryPage(params);
}
@RequestMapping("/getNetCfg")
public R getNetCfg(Long cameraId){
Camera camera = cameraService.getById(cameraId);
CameraNetFtp cfg = cameraNetFtpService.getNetCfg(camera);
return R.ok().put("data",cfg);
}
@RequestMapping("/editNetCfg")
public R editNetCfg(@RequestBody CameraNetFtp cameraNetFtp){
Camera camera = cameraService.getOne(new QueryWrapper<Camera>().eq("devsn",cameraNetFtp.getDevsn()).eq("status","1"));
if(camera == null){
return R.error("设备未在线");
}
cameraNetFtp.setLoginId(camera.getLoginId());
return cameraNetFtpService.editNetCfg(cameraNetFtp);
}
/**
* 获取详细信息
*/
@RequestMapping("/info/{id}")
@PreAuthorize("@ss.hasPermi('camera:ftp:query')")
public R info(@PathVariable("id") Long id){
CameraNetFtp cameraNetFtp = cameraNetFtpService.getById(id);
return R.ok().put("data", cameraNetFtp);
}
/**
* 导出列表
*/
@PreAuthorize("@ss.hasPermi('camera:ftp:export')")
@Log(title = "列表", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, CameraNetFtp cameraNetFtp)
{
List<CameraNetFtp> list = cameraNetFtpService.list();
ExcelUtil<CameraNetFtp> util = new ExcelUtil<CameraNetFtp>(CameraNetFtp.class);
util.exportExcel(response, list, "列表数据");
}
/**
* 新增
*/
@RequestMapping("/add")
@Log(title = "CameraNetFtp", businessType = BusinessType.INSERT)
@PreAuthorize("@ss.hasPermi('camera:ftp:add')")
public R add(@RequestBody CameraNetFtp cameraNetFtp){
cameraNetFtpService.save(cameraNetFtp);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/edit")
@PreAuthorize("@ss.hasPermi('camera:ftp:edit')")
@Log(title = "CameraNetFtp", businessType = BusinessType.UPDATE)
public R edit(@RequestBody CameraNetFtp cameraNetFtp){
cameraNetFtpService.updateById(cameraNetFtp);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete/{ids}")
@PreAuthorize("@ss.hasPermi('camera:ftp:remove')")
@Log(title = "CameraNetFtp", businessType = BusinessType.DELETE)
public R delete(@PathVariable Long[] ids){
cameraNetFtpService.removeByIds(Arrays.asList(ids));
return R.ok();
}
}

55
ruoyi-code/src/main/java/com/ruoyi/code/camera/domain/CameraNetFtp.java

@ -0,0 +1,55 @@
package com.ruoyi.code.camera.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId;
import com.ruoyi.common.annotation.Excel;
import java.io.Serializable;
import lombok.Data;
/**
* 摄像机FTP配置对象 camera_net_ftp
*
* @author ruoyi
* @date 2022-06-28
*/
@Data
@TableName("camera_net_ftp")
public class CameraNetFtp implements Serializable
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
@TableId(type = IdType.INPUT)
private Long id;
/** 序列号 */
private String devsn;
/** 服务地址 */
private String address;
/** 是否启用 1是0否 */
private Long isEnable;
/** 用户名 */
private String username;
/** 密码 */
private String password;
/** 端口 */
private Long port;
/** 存储路径 */
private String pathRule;
@TableField(exist = false)
private String loginId;
}

18
ruoyi-code/src/main/java/com/ruoyi/code/camera/mapper/CameraNetFtpMapper.java

@ -0,0 +1,18 @@
package com.ruoyi.code.camera.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.ruoyi.code.camera.domain.CameraNetFtp;
/**
* Mapper接口
*
* @author ruoyi
* @date 2022-06-28
*/
@Mapper
public interface CameraNetFtpMapper extends BaseMapper<CameraNetFtp>
{
}

4
ruoyi-code/src/main/java/com/ruoyi/code/camera/scheduled/RegisterServer.java

@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.ruoyi.code.camera.domain.Camera; import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.code.camera.service.ICameraService; import com.ruoyi.code.camera.service.ICameraService;
import com.ruoyi.common.core.page.R; import com.ruoyi.common.core.page.R;
import com.ruoyi.common.utils.IPUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -34,6 +35,8 @@ public class RegisterServer {
} }
private void start(){ private void start(){
String ip = IPUtils.getLocalIpAddress();
if("172.16.46.58".equals(ip)){
R result = cameraService.register(); R result = cameraService.register();
if("0".equals(result.get("code").toString())){ if("0".equals(result.get("code").toString())){
System.out.println("主动注册服务已启动"); System.out.println("主动注册服务已启动");
@ -41,5 +44,6 @@ public class RegisterServer {
System.out.println("主动注册服务启动失败"); System.out.println("主动注册服务启动失败");
} }
} }
}
} }

25
ruoyi-code/src/main/java/com/ruoyi/code/camera/service/ICameraNetFtpService.java

@ -0,0 +1,25 @@
package com.ruoyi.code.camera.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.common.core.page.R;
import java.util.Map;
import com.ruoyi.code.camera.domain.CameraNetFtp;
/**
* Service接口
*
* @author ruoyi
* @date 2022-06-28
*/
public interface ICameraNetFtpService extends IService<CameraNetFtp>
{
/**
* 查询
*/
R queryPage(Map<String, Object> params);
CameraNetFtp getNetCfg(Camera camera);
R editNetCfg(CameraNetFtp netFtp);
}

70
ruoyi-code/src/main/java/com/ruoyi/code/camera/service/impl/CameraNetFtpServiceImpl.java

@ -0,0 +1,70 @@
package com.ruoyi.code.camera.service.impl;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.common.core.page.R;
import com.ruoyi.common.exception.RYException;
import com.ruoyi.common.utils.Query;
import com.ruoyi.common.utils.StringUtils;
import com.sun.jna.NativeLong;
import org.springframework.stereotype.Service;
import com.ruoyi.code.camera.mapper.CameraNetFtpMapper;
import com.ruoyi.code.camera.domain.CameraNetFtp;
import com.ruoyi.code.camera.service.ICameraNetFtpService;
import utils.run_device_cfg;
/**
* Service业务层处理
*
* @author ruoyi
* @date 2022-06-28
*/
@Service("cameraNetFtpService")
public class CameraNetFtpServiceImpl extends ServiceImpl<CameraNetFtpMapper, CameraNetFtp> implements ICameraNetFtpService
{
@Override
public R queryPage(Map<String, Object> params) {
IPage<CameraNetFtp> page = this.page(
new Query<CameraNetFtp>().getPage(params),
new QueryWrapper<CameraNetFtp>()
);
return R.ok().put("count", page.getTotal()).put("data", page.getRecords());
}
@Override
public CameraNetFtp getNetCfg(Camera camera){
run_device_cfg cfg = new run_device_cfg();
if(camera == null || StringUtils.isBlank(camera.getLoginId())){
throw new RYException("设备未在线");
}
CameraNetFtp netFtp = cfg.getCfg(new NativeLong(Long.parseLong(camera.getLoginId())));
netFtp.setDevsn(camera.getDevsn());
CameraNetFtp localCfg = getOne(new QueryWrapper<CameraNetFtp>().eq("devsn",camera.getDevsn()));
if(localCfg != null){
netFtp.setId(localCfg.getId());
updateById(netFtp);
}else{
save(netFtp);
}
return netFtp;
}
@Override
public R editNetCfg(CameraNetFtp netFtp){
run_device_cfg cfg = new run_device_cfg();
int bOfflineEnable = netFtp.getIsEnable().intValue();
boolean result = cfg.setDeviceFtpCfg(new NativeLong(Long.parseLong(netFtp.getLoginId())), netFtp.getIsEnable().intValue(), bOfflineEnable, netFtp.getAddress(),
netFtp.getPort().intValue(), netFtp.getUsername(), netFtp.getPassword());
if(!result){
return R.error();
}
return R.ok();
}
}

34
ruoyi-code/src/main/java/utils/run_device_cfg.java

@ -27,6 +27,8 @@ import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn; import javax.swing.table.TableColumn;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.code.camera.domain.CameraNetFtp;
import com.sun.jna.NativeLong; import com.sun.jna.NativeLong;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
@ -3635,4 +3637,36 @@ public class run_device_cfg implements ActionListener, ListSelectionListener {
DataUtils.sdk_data_structureToPtr(stuCfgNetStorageTrans, ptrInBuffer, 0); DataUtils.sdk_data_structureToPtr(stuCfgNetStorageTrans, ptrInBuffer, 0);
return ptrInBuffer; return ptrInBuffer;
} }
public CameraNetFtp getCfg(NativeLong loginID){
STU_CFG_NET_STORAGE_TRANS stuCfgNetStorageTrans = getStuCfgNetStorageTrans(loginID,EM_DEVICE_CFG_TYPE.DEVICE_CFG_NET_STORAGE_TRANS);
CameraNetFtp ftpCfg = new CameraNetFtp();
for(int i=0; i<stuCfgNetStorageTrans.uItemCount; i++)
{
STU_CFG_NET_STORAGE_TRANS_ITEM stuItem = stuCfgNetStorageTrans.stuItemArray[i];
String ftpValue = DataUtils.sdk_data_byteArrayToString(stuItem.szProtocol, GlobalTool.getEncodeType());
if("ftp".equalsIgnoreCase(ftpValue))
{
String address = DataUtils.sdk_data_byteArrayToString(stuItem.szAddress, GlobalTool.getEncodeType());
ftpCfg.setAddress(address);
STU_CFG_NET_STORAGE_FTP stuCfgNetStorageFtp = stuItem.stuFtpParams;
ftpCfg.setIsEnable((long) stuCfgNetStorageFtp.bRealtimeEnable);
ftpCfg.setPort((long) stuCfgNetStorageFtp.uFtpPort);
String username = DataUtils.sdk_data_byteArrayToString(stuCfgNetStorageFtp.szUserName, GlobalTool.getEncodeType());
ftpCfg.setUsername(username);
String pwd = DataUtils.sdk_data_byteArrayToString(stuCfgNetStorageFtp.szPassword, GlobalTool.getEncodeType());
ftpCfg.setPassword(pwd);
String pathrule = DataUtils.sdk_data_byteArrayToString(stuCfgNetStorageFtp.szPathRule, GlobalTool.getEncodeType());
ftpCfg.setPathRule(pathrule);
}
}
return ftpCfg;
}
} }

91
ruoyi-common/src/main/java/com/ruoyi/common/utils/IPUtils.java

@ -0,0 +1,91 @@
/**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有侵权必究
*/
package com.ruoyi.common.utils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
/**
* IP地址
*
* @author Mark sunlightcs@gmail.com
*/
@Slf4j
public class IPUtils {
private static Logger logger = LoggerFactory.getLogger(IPUtils.class);
/**
* 获取IP地址
*
* 使用Nginx等反向代理软件 则不能通过request.getRemoteAddr()获取IP地址
* 如果使用了多级反向代理的话X-Forwarded-For的值并不止一个而是一串IP地址X-Forwarded-For中第一个非unknown的有效IP字符串则为真实IP地址
*/
public static String getIpAddr(HttpServletRequest request) {
String ip = null;
try {
ip = request.getHeader("x-forwarded-for");
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
} catch (Exception e) {
logger.error("IPUtils ERROR ", e);
}
// //使用代理,则获取第一个IP地址
// if(StringUtils.isEmpty(ip) && ip.length() > 15) {
// if(ip.indexOf(",") > 0) {
// ip = ip.substring(0, ip.indexOf(","));
// }
// }
return ip;
}
public static String getLocalIpAddress() {
try {
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip;
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = allNetInterfaces.nextElement();
if (!netInterface.isLoopback() && !netInterface.isVirtual() && netInterface.isUp()) {
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
ip = addresses.nextElement();
if (ip instanceof Inet4Address) {
return ip.getHostAddress();
}
}
}
}
} catch (Exception e) {
log.error("本地IP地址获取失败", e);
}
return "";
}
}
Loading…
Cancel
Save