Browse Source

重启和日志

platform-api
yx 2 years ago
parent
commit
741f935609
  1. 52
      ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/CameraController.java
  2. 40
      ruoyi-code/src/main/java/com/ruoyi/code/camera/domain/LogInfo.java
  3. 2
      ruoyi-code/src/main/java/utils/CameraUtil.java
  4. 73
      ruoyi-code/src/main/java/utils/run_device_cfg.java
  5. 477
      ruoyi-code/src/main/java/utils/run_device_log_search.java

52
ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/CameraController.java

@ -10,11 +10,16 @@ import com.ruoyi.common.utils.poi.ExcelUtil; @@ -10,11 +10,16 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.code.camera.service.ICameraService;
import com.sun.jna.NativeLong;
import com.sun.jna.ptr.IntByReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import sdk.java.lib.netmanager.NetEnums;
import sdk.java.lib.netmanager.NetLib;
import utils.CameraUtil;
import utils.RegisterUtil;
import utils.run_device_cfg;
import utils.run_device_log_search;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@ -183,4 +188,51 @@ public class CameraController extends BaseController @@ -183,4 +188,51 @@ public class CameraController extends BaseController
cameraService.updateById(c);
return R.ok();
}
/**
* 查询摄像头重启数据
*/
@RequestMapping("/getautocfg/{id}")
public R getAutoCfg(@PathVariable("id") Long id){
int nCommand = NetEnums.EM_DEVICE_CFG_TYPE.DEVICE_CFG_AUTO_MAINTAIN;
Camera camera = cameraService.getCameraBySid(id);
IntByReference nError = new IntByReference(0);
NativeLong loginID = NetLib.instance.Net_LoginDevice(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword(), null,nError);
run_device_cfg cfg = new run_device_cfg();
cfg.getAutoCfg(loginID,nCommand);
return R.ok();
}
/**
* 设置摄像头重启
*/
@RequestMapping("/setautocfg/")
public R setAutoCfg(@RequestParam Map<String, Object> params){
Camera camera = cameraService.getCameraBySid((Long) params.get("sid"));
IntByReference nError = new IntByReference(0);
NativeLong loginID = NetLib.instance.Net_LoginDevice(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword(), null,nError);
run_device_cfg cfg = new run_device_cfg();
cfg.setAutoFtpCfg(loginID,(int)params.get("benable"),(int)params.get("uHour"),(int)params.get("uWeekDay"));
return R.ok();
}
/**
* 获取日志
*/
@RequestMapping("/getloginfo/")
public R getloginfo(@RequestParam Map<String, Object> params){
Camera camera = cameraService.getCameraBySid((Long) params.get("sid"));
IntByReference nError = new IntByReference(0);
NativeLong loginID = NetLib.instance.Net_LoginDevice(camera.getIp(), camera.getPort(), camera.getUsername(), camera.getPassword(), null,nError);
run_device_log_search logSearch = new run_device_log_search();
logSearch.logInfoSearchByTime(loginID,(String) params.get("strStartTime"),(String) params.get("strEndTime"));
return R.ok();
}
}

40
ruoyi-code/src/main/java/com/ruoyi/code/camera/domain/LogInfo.java

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
package com.ruoyi.code.camera.domain;
import lombok.Data;
import java.io.Serializable;
import java.util.*;
@Data
public class LogInfo implements Serializable{
private static final long serialVersionUID = 1L;
/** 记录时间 */
private String cLogTime;
/** 用户名 */
private String cOperUserName;
/** 主类型 */
private String cMainType;
/** 次类型 */
private String cSubType;
/** 远程ip */
private String cRemoteIP;
/** 通道号 */
private String iChannel;
/** 配置名称 */
private String cConfigName;
/** 网络适配 */
private String cNetAdapter;
/** 客户端类型 */
private String cClientType;
}

2
ruoyi-code/src/main/java/utils/CameraUtil.java

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
package utils;
import com.alibaba.fastjson.JSON;
import com.ruoyi.code.camera.domain.LogInfo;
import com.ruoyi.common.utils.DateUtils;
import com.sun.jna.NativeLong;
import com.sun.jna.ptr.IntByReference;
@ -9,6 +10,7 @@ import sdk.java.lib.netmanager.NetLib; @@ -9,6 +10,7 @@ import sdk.java.lib.netmanager.NetLib;
import sdk.java.lib.netmanager.NetStructs;
import java.util.Date;
import java.util.List;
public class CameraUtil {
public static void main(String[] args) {

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

@ -3669,4 +3669,77 @@ public class run_device_cfg implements ActionListener, ListSelectionListener { @@ -3669,4 +3669,77 @@ public class run_device_cfg implements ActionListener, ListSelectionListener {
return ftpCfg;
}
//获取自动重启配置
public STU_CFG_AUTO_MAINTAIN getAutoCfg(NativeLong loginID ,int nCommand){
IntByReference outBufferSize = new IntByReference(0);
IntByReference nReturnSize = new IntByReference(0);
Pointer ptrOutBuffer = initStuData(nCommand, outBufferSize);
boolean bResult = NetLib.instance.Net_GetDeviceCfg(
loginID,
nCommand,
0,
ptrOutBuffer,
outBufferSize.getValue(),
nReturnSize,
6000);
STU_CFG_AUTO_MAINTAIN stuCfgAutoMaintain = new STU_CFG_AUTO_MAINTAIN();
DataUtils.sdk_data_ptrToStructure(ptrOutBuffer, stuCfgAutoMaintain);
System.out.println(stuCfgAutoMaintain);
return stuCfgAutoMaintain;
}
//设置自动重启
/**
*
* @param bEnable 使能 0- 1-
* @param uHour 几点重启
* @param uWeekDay 周几重启
* @return
*/
public STU_CFG_AUTO_MAINTAIN setAutoFtpCfg(NativeLong loginID, int bEnable,int uHour,int uWeekDay){
// 句柄 - 网络存储传输配置
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_AUTO_MAINTAIN;
STU_CFG_AUTO_MAINTAIN stuCfgAutoMaintain = getAutoCfg(loginID, nCommand);
IntByReference inBufferSize = new IntByReference(0);
stuCfgAutoMaintain.bEnable=bEnable;
stuCfgAutoMaintain.uHour=uHour;
stuCfgAutoMaintain.uWeekDay=uWeekDay;
inBufferSize.setValue(stuCfgAutoMaintain.size());
Pointer ptrInBuffer = DataUtils.sdk_data_createPtr(inBufferSize.getValue());
DataUtils.sdk_data_structureToPtr(stuCfgAutoMaintain, ptrInBuffer, 0);
if(null == ptrInBuffer)
return null;
boolean bResult2 = NetLib.instance.Net_SetDeviceCfg(
loginID,
nCommand,
0,
ptrInBuffer,
inBufferSize.getValue(),
6000);
if(!bResult2)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_SetDeviceCfg fail, command = %d, errorCode = %d", nCommand, error);
return null;
}
System.out.println(stuCfgAutoMaintain);
return stuCfgAutoMaintain;
}
}

477
ruoyi-code/src/main/java/utils/run_device_log_search.java

@ -0,0 +1,477 @@ @@ -0,0 +1,477 @@
package utils;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import com.alibaba.fastjson.JSON;
import com.ruoyi.code.camera.domain.LogInfo;
import com.ruoyi.common.utils.StringUtils;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import sdk.java.common.GlobalTool;
import sdk.java.lib.DataUtils;
import sdk.java.lib.netmanager.NetDefs;
import sdk.java.lib.netmanager.NetLib;
import sdk.java.lib.netmanager.NetEnums.EM_DEVICE_CFG_TYPE;
import sdk.java.lib.netmanager.NetStructs;
import sdk.java.lib.netmanager.NetStructs.STU_CFG_LOG;
import sdk.java.lib.netmanager.NetStructs.STU_CFG_LOG_INFO;
import javax.swing.JButton;
import javax.swing.JTable;
public class run_device_log_search implements ActionListener {
private JFrame m_frame;
private JTextField m_jtf_ip;
private JTextField m_jtf_port;
private JTextField m_jtf_username;
private JTextField m_jtf_password;
private JTable m_table_log_info;
private DefaultTableModel m_tableModel;
private JButton m_btn_login;
private JButton m_btn_logout;
private NativeLong m_loginID = new NativeLong(0);
private JButton m_btn_refresh;
////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Create the application.
*/
public run_device_log_search()
{
initialize();
initilizeRyNetLib();
}
/**
* Initialize the contents of the frame.
*/
private void initialize()
{
m_frame = new JFrame();
m_frame.setBounds(100, 100, 562, 457);
Toolkit kit = Toolkit.getDefaultToolkit();
int x = kit.getScreenSize().width/2 - this.m_frame.getWidth()/2;
int y = kit.getScreenSize().height/2 - this.m_frame.getHeight()/2;
m_frame.setLocation(x, y);
m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m_frame.getContentPane().setLayout(null);
JLabel label = new JLabel("IP:");
label.setBounds(10, 13, 79, 15);
m_frame.getContentPane().add(label);
m_jtf_ip = new JTextField();
m_jtf_ip.setColumns(10);
m_jtf_ip.setBounds(82, 10, 178, 21);
m_frame.getContentPane().add(m_jtf_ip);
JLabel label_1 = new JLabel("Port:");
label_1.setBounds(280, 13, 79, 15);
m_frame.getContentPane().add(label_1);
m_jtf_port = new JTextField();
m_jtf_port.setColumns(10);
m_jtf_port.setBounds(358, 10, 178, 21);
m_frame.getContentPane().add(m_jtf_port);
JLabel label_2 = new JLabel("Username:");
label_2.setBounds(10, 38, 79, 15);
m_frame.getContentPane().add(label_2);
m_jtf_username = new JTextField();
m_jtf_username.setColumns(10);
m_jtf_username.setBounds(81, 35, 179, 21);
m_frame.getContentPane().add(m_jtf_username);
JLabel label_3 = new JLabel("Password:");
label_3.setBounds(280, 38, 79, 15);
m_frame.getContentPane().add(label_3);
m_jtf_password = new JTextField();
m_jtf_password.setColumns(10);
m_jtf_password.setBounds(358, 35, 178, 21);
m_frame.getContentPane().add(m_jtf_password);
m_btn_login = new JButton("登陆");
m_btn_login.addActionListener(this);
m_btn_login.setBounds(340, 66, 93, 23);
m_frame.getContentPane().add(m_btn_login);
m_btn_logout = new JButton("登出");
m_btn_logout.addActionListener(this);
m_btn_logout.setEnabled(false);
m_btn_logout.setBounds(443, 66, 93, 23);
m_frame.getContentPane().add(m_btn_logout);
Vector<String> columTitle = new Vector<String>();
columTitle.addElement("记录时间");
columTitle.addElement("操作用户名");
columTitle.addElement("主日志类型");
columTitle.addElement("次日志类型");
columTitle.addElement("远程IP");
columTitle.addElement("通道号");
columTitle.addElement("配置名称");
columTitle.addElement("网络适配器");
columTitle.addElement("客户端类型");
Vector<Vector<String>> data = new Vector<Vector<String>>();
m_tableModel = new DefaultTableModel(data, columTitle);
m_table_log_info = new JTable(m_tableModel);
m_table_log_info.setBounds(10, 99, 474, 309);
JScrollPane jspLogInfo = new JScrollPane(m_table_log_info);
jspLogInfo.setBounds(10, 99, 526, 276);
m_frame.getContentPane().add(jspLogInfo);
m_btn_refresh = new JButton("刷新");
m_btn_refresh.addActionListener(this);
m_btn_refresh.setBounds(443, 385, 93, 23);
m_frame.getContentPane().add(m_btn_refresh);
refreshEnables();
}
private void initilizeRyNetLib()
{
NetLib.instance.Net_Init(null, null);
NetLib.instance.Net_SetLogOption(3);
}
protected void finalize()
{
NetLib.instance.Net_Exit();
}
private boolean checkParams()
{
String tmp = this.m_jtf_ip.getText().trim();
if(tmp.isEmpty())
{
return false;
}
tmp = this.m_jtf_port.getText().trim();
if(tmp.isEmpty())
{
return false;
}
tmp = this.m_jtf_username.getText().trim();
if(tmp.isEmpty())
{
return false;
}
tmp = this.m_jtf_password.getText().trim();
if(tmp.isEmpty())
{
return false;
}
return true;
}
private void refreshEnables()
{
boolean bLogin = this.m_loginID.longValue() != 0;
this.m_btn_login.setEnabled(!bLogin);
this.m_btn_logout.setEnabled(bLogin);
this.m_btn_refresh.setEnabled(bLogin);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
private boolean onBtnLogin()
{
if(checkParams())
{
int nPort = Integer.parseInt(m_jtf_port.getText());
IntByReference nError = new IntByReference(0);
this.m_loginID = NetLib.instance.Net_LoginDevice(m_jtf_ip.getText(), nPort, m_jtf_username.getText(), m_jtf_password.getText(), null, nError);
if(0 == this.m_loginID.longValue())
{
JOptionPane.showMessageDialog(null, "登陆失败", "提示", JOptionPane.ERROR_MESSAGE);
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_LoginDevice fail, errorCode = %d", error);
System.out.println(strError);
return false;
}
else
{
logInfoSearch();
}
refreshEnables();
}
return true;
}
private void onBtnLogout()
{
if(0 != this.m_loginID.longValue())
{
boolean bResult = NetLib.instance.Net_LogoutDevice(this.m_loginID);
if(!bResult)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_GetAllFaceGroups fail, errorCode = %d", error);
System.out.println(strError);
return;
}
this.m_loginID = new NativeLong(0);
refreshEnables();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
private void onBtnRefresh()
{
logInfoSearch();
}
private void logInfoSearch()
{
this.m_tableModel.setRowCount(0);
STU_CFG_LOG stuLogSearch = new STU_CFG_LOG();
String strStartTime = "2000-01-01 00:00:00";
byte[] tmpByArr = DataUtils.sdk_data_stringToByteArray(strStartTime, GlobalTool.getEncodeType());
System.arraycopy(tmpByArr, 0, stuLogSearch.stuSearchCondition.cStartTime, 0, tmpByArr.length);
Calendar cal = Calendar.getInstance();
String strEndTime = String.format("%04d-%02d-%02d %02d:%02d:%02d",
cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
tmpByArr = DataUtils.sdk_data_stringToByteArray(strEndTime, GlobalTool.getEncodeType());
System.arraycopy(tmpByArr, 0, stuLogSearch.stuSearchCondition.cEndTime, 0, tmpByArr.length);
int nBufferSize = stuLogSearch.size();
Pointer pBuffer = DataUtils.sdk_data_createPtr(nBufferSize);
DataUtils.sdk_data_structureToPtr(stuLogSearch, pBuffer, 0);
IntByReference nReturnSize = new IntByReference(0);
while(true)
{
// 循环重复调用,获取日志信息,直到获取到最新的一条
boolean bResult = NetLib.instance.Net_GetDeviceCfg(
m_loginID,
EM_DEVICE_CFG_TYPE.DEVICE_CFG_LOGSEARCH,
0,
pBuffer,
nBufferSize,
nReturnSize,
6000);
if(!bResult)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_GetDeviceCfg fail, errorCode = %d", error);
System.out.println(strError);
break;
}
else
{
DataUtils.sdk_data_ptrToStructure(pBuffer, stuLogSearch);
ui_showLogInfo(stuLogSearch);
if(NetDefs.MAX_LOG_AMOUNT > stuLogSearch.stuLogResult.uCurAmount)
{
// 此处判断成立,则表示已查完所有日志
break;
}
}
}
}
private void ui_showLogInfo(STU_CFG_LOG stuLogSearch)
{
for(int i=0; i<stuLogSearch.stuLogResult.uCurAmount; i++)
{
Vector<String> rowData = new Vector<String>();
STU_CFG_LOG_INFO stuLogInfo = stuLogSearch.stuLogResult.stuResult[i];
String value = DataUtils.sdk_data_byteArrayToString(stuLogInfo.cLogTime, GlobalTool.getEncodeType());
rowData.addElement(value);
value = DataUtils.sdk_data_byteArrayToString(stuLogInfo.cOperUserName, GlobalTool.getEncodeType());
rowData.addElement(value);
value = DataUtils.sdk_data_byteArrayToString(stuLogInfo.cMainType, GlobalTool.getEncodeType());
rowData.addElement(value);
value = DataUtils.sdk_data_byteArrayToString(stuLogInfo.cSubType, GlobalTool.getEncodeType());
rowData.addElement(value);
value = DataUtils.sdk_data_byteArrayToString(stuLogInfo.stuLogDetail.cRemoteIP, GlobalTool.getEncodeType());
rowData.addElement(value);
value = String.format("%d", stuLogInfo.stuLogDetail.iChannel);
rowData.addElement(value);
value = DataUtils.sdk_data_byteArrayToString(stuLogInfo.stuLogDetail.cConfigName, GlobalTool.getEncodeType());
rowData.addElement(value);
value = DataUtils.sdk_data_byteArrayToString(stuLogInfo.stuLogDetail.cNetAdapter, GlobalTool.getEncodeType());
rowData.addElement(value);
value = DataUtils.sdk_data_byteArrayToString(stuLogInfo.stuLogDetail.cClientType, GlobalTool.getEncodeType());
rowData.addElement(value);
this.m_tableModel.addRow(rowData);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public void actionPerformed(ActionEvent e)
{
Object obj = e.getSource();
if(obj == this.m_btn_login)
{
onBtnLogin();
}
else if(obj == this.m_btn_logout)
{
onBtnLogout();
}
else if(obj == this.m_btn_refresh)
{
onBtnRefresh();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
run_device_log_search window = new run_device_log_search();
window.m_frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
public List<LogInfo> logInfoSearchByTime(NativeLong loginID , String strStartTime, String strEndTime)
{
STU_CFG_LOG stuLogSearch = new STU_CFG_LOG();
if(StringUtils.isEmpty(strStartTime))
strStartTime = "2000-01-01 00:00:00";
byte[] tmpByArr = DataUtils.sdk_data_stringToByteArray(strStartTime, GlobalTool.getEncodeType());
System.arraycopy(tmpByArr, 0, stuLogSearch.stuSearchCondition.cStartTime, 0, tmpByArr.length);
Calendar cal = Calendar.getInstance();
if (StringUtils.isEmpty(strEndTime))
strEndTime = String.format("%04d-%02d-%02d %02d:%02d:%02d",
cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
tmpByArr = DataUtils.sdk_data_stringToByteArray(strEndTime, GlobalTool.getEncodeType());
System.arraycopy(tmpByArr, 0, stuLogSearch.stuSearchCondition.cEndTime, 0, tmpByArr.length);
int nBufferSize = stuLogSearch.size();
Pointer pBuffer = DataUtils.sdk_data_createPtr(nBufferSize);
DataUtils.sdk_data_structureToPtr(stuLogSearch, pBuffer, 0);
IntByReference nReturnSize = new IntByReference(0);
List<LogInfo> logInfoList=new ArrayList<>();
while(true)
{
// 循环重复调用,获取日志信息,直到获取到最新的一条
boolean bResult = NetLib.instance.Net_GetDeviceCfg(
loginID,
EM_DEVICE_CFG_TYPE.DEVICE_CFG_LOGSEARCH,
0,
pBuffer,
nBufferSize,
nReturnSize,
6000);
if(!bResult)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_GetDeviceCfg fail, errorCode = %d", error);
System.out.println(strError);
break;
}
else
{
DataUtils.sdk_data_ptrToStructure(pBuffer, stuLogSearch);
LogInfo logInfo = new LogInfo();
for(int i=0; i<stuLogSearch.stuLogResult.uCurAmount; i++)
{
STU_CFG_LOG_INFO stuLogInfo = stuLogSearch.stuLogResult.stuResult[i];
String cLogTime = DataUtils.sdk_data_byteArrayToString(stuLogInfo.cLogTime, GlobalTool.getEncodeType());
logInfo.setCLogTime(cLogTime);
String cOperUserName = DataUtils.sdk_data_byteArrayToString(stuLogInfo.cOperUserName, GlobalTool.getEncodeType());
logInfo.setCOperUserName(cOperUserName);
String cMainType = DataUtils.sdk_data_byteArrayToString(stuLogInfo.cMainType, GlobalTool.getEncodeType());
logInfo.setCMainType(cMainType);
String cSubType = DataUtils.sdk_data_byteArrayToString(stuLogInfo.cSubType, GlobalTool.getEncodeType());
logInfo.setCSubType(cSubType);
String cRemoteIP = DataUtils.sdk_data_byteArrayToString(stuLogInfo.stuLogDetail.cRemoteIP, GlobalTool.getEncodeType());
logInfo.setCRemoteIP(cRemoteIP);
String cClientType = DataUtils.sdk_data_byteArrayToString(stuLogInfo.stuLogDetail.cClientType, GlobalTool.getEncodeType());
logInfo.setCClientType(cClientType);
System.out.println(JSON.toJSON(logInfo));
logInfoList.add(logInfo);
}
if(NetDefs.MAX_LOG_AMOUNT > stuLogSearch.stuLogResult.uCurAmount)
{
// 此处判断成立,则表示已查完所有日志
break;
}
}
}
return logInfoList;
}
}
Loading…
Cancel
Save