4670101279
2 years ago
8 changed files with 432 additions and 5 deletions
@ -0,0 +1,130 @@
@@ -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(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,55 @@
@@ -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; |
||||
|
||||
|
||||
} |
@ -0,0 +1,18 @@
@@ -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> |
||||
{ |
||||
|
||||
} |
@ -0,0 +1,25 @@
@@ -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); |
||||
} |
@ -0,0 +1,70 @@
@@ -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(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,91 @@
@@ -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…
Reference in new issue