新增抓拍接口,优化。

This commit is contained in:
luoyw 2025-12-15 20:09:18 +08:00
parent 3f3221c028
commit 9a2890b38d
6 changed files with 56 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package com.ruoyi.web.controller.system;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.system.service.DahuaSnapService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
@ -106,12 +107,28 @@ public class NtzyDeviceInfoController extends BaseController
* 立即把 JPG 保存到本地
* 文件访问 URI返回给调用方相当于返回图片链接效果
*/
@GetMapping("/snap")
public AjaxResult snap(@RequestParam String ip,
@GetMapping("/snap2")
public AjaxResult snap2(@RequestParam String ip,
@RequestParam(defaultValue = "37777") int port,
@RequestParam String user,
@RequestParam String pwd){
String url = service.snap(ip, port, user, pwd);
return success(url);
}
/**
* 抓拍成功后保存图片文件(根据相机编码)
* 抓拍成功后
* 立即把 JPG 保存到本地
* 文件访问 URI返回给调用方相当于返回图片链接效果
*/
@GetMapping("/snap")
public AjaxResult snap(@RequestParam String code){
NtzyDeviceInfo info = ntzyDeviceInfoService.selectNtzyDeviceInfoByCode(code);
if (info == null){
return error("照相机未注册!");
}
String url = service.snap(info.getDeviceIpLocation(), 37777, info.getUserName(), info.getPassword());
return success(url);
}
}

View File

@ -26,6 +26,10 @@
<groupId>com.demo</groupId>
<artifactId>dahua-sdk-demo</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -58,4 +58,12 @@ public interface NtzyDeviceInfoMapper
* @return 结果
*/
public int deleteNtzyDeviceInfoByIds(Long[] ids);
/**
* 根据设备编码查询设备信息
*
* @param deviceCode 设备信息主键
* @return 设备信息
*/
public NtzyDeviceInfo selectNtzyDeviceInfoByCode(String deviceCode);
}

View File

@ -58,4 +58,12 @@ public interface INtzyDeviceInfoService
* @return 结果
*/
public int deleteNtzyDeviceInfoById(Long id);
/**
* 查询设备信息
*
* @param deviceCode 设备信息主键
* @return 设备信息
*/
public NtzyDeviceInfo selectNtzyDeviceInfoByCode(String deviceCode);
}

View File

@ -93,4 +93,16 @@ public class NtzyDeviceInfoServiceImpl implements INtzyDeviceInfoService
{
return ntzyDeviceInfoMapper.deleteNtzyDeviceInfoById(id);
}
/**
* 查询设备信息
*
* @param deviceCode 设备信息主键
* @return 设备信息
*/
@Override
public NtzyDeviceInfo selectNtzyDeviceInfoByCode(String deviceCode)
{
return ntzyDeviceInfoMapper.selectNtzyDeviceInfoByCode(deviceCode);
}
}

View File

@ -42,6 +42,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</select>
<select id="selectNtzyDeviceInfoByCode" parameterType="String" resultMap="NtzyDeviceInfoResult">
<include refid="selectNtzyDeviceInfoVo"/>
where device_code = #{deviceCode}
</select>
<insert id="insertNtzyDeviceInfo" parameterType="NtzyDeviceInfo" useGeneratedKeys="true" keyProperty="id">
insert into ntzy_device_info
<trim prefix="(" suffix=")" suffixOverrides=",">