作者 钟来

模块整理

... ... @@ -4,7 +4,10 @@ import com.ruoyi.common.utils.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
/**
* 获取IP方法
... ... @@ -211,6 +214,33 @@ public class IpUtils
return "127.0.0.1";
}
public static String getLocalHost()
{
StringBuffer stringBuffer = new StringBuffer();
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) {
if(stringBuffer.length() != 0 )
{
stringBuffer.append(":");
}
stringBuffer.append(address.getHostAddress());
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return stringBuffer.toString();
}
public static void main(String[] args) {
System.out.println(getLocalHost());
}
/**
* 获取主机名
*
... ...
... ... @@ -63,7 +63,6 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
... ... @@ -47,8 +47,16 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal>
@Override
public boolean checkValue() {
BigDecimal bigDecimal = getValue();
if(null != bigDecimal && bigDecimal.compareTo(min)>=0 && bigDecimal.compareTo(max)<=0)
if(null != bigDecimal)
{
if(null != min && bigDecimal.compareTo(min)<0)
{
return false;
}
if(null != max && bigDecimal.compareTo(max)>0)
{
return false;
}
return true;
}
return false;
... ...
... ... @@ -64,11 +64,18 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer>
{
BigDecimal bigDecimal = new BigDecimal(getValue());
if(bigDecimal.compareTo(min)>=0 && bigDecimal.compareTo(max)<=0)
if(null != bigDecimal)
{
if(null != min && bigDecimal.compareTo(min)<0)
{
return false;
}
if(null != max && bigDecimal.compareTo(max)>0)
{
return false;
}
return true;
}
}
return false;
}
... ...
... ... @@ -130,6 +130,8 @@ public class BusinessDataUpdateService {
device.setSummary(summaryObjec.toString());
}
if(null != jsData && jsData.size() != 0)
{
SaveDataDto saveDataDto = dataModeAnalysisService.analysisThingsModelValue( olddevice.getClient_id(),olddevice.getMqtt_username(),jsData,serverDto);
//更新数据
if(null != olddevice && ("ADD".equals(type.name())|| "READ".equals(type.name())))
... ... @@ -144,6 +146,7 @@ public class BusinessDataUpdateService {
String str = (null!=olddevice?olddevice.getThings_model_config():null);
String newStr = deviceService.getNewAdddate(device.getClient_id(),str,saveDataDto.getConfig(),serverDto.getLogDeviceOperationList(),operationType,isLog).toJSONString();
device.setThings_model_config(newStr);
}
return device;
}
... ...
#!/bin/bash
# 如果编码格式有问题执行:sed -i 's/\r$//' guard.sh
# 执行脚本: nohup /bin/bash /opt/lh-smart-feeder/lh-smart-feeder/guard.sh >/dev/null 2>&1 &
# 定义要检查的 JAR 文件名和启动命令
JAR_FILE="lh-smart-feeder.jar"
START_COMMAND="java -jar $JAR_FILE"
... ... @@ -11,14 +12,23 @@ is_running() {
# 启动 JAR 程序
start_program() {
/opt/lh-smart-feeder/lh-smart-feeder/start.sh
cd /opt/lh-smart-feeder/lh-smart-feeder/
./start.sh
}
# 检查 JAR 程序是否在运行
if ! is_running; then
stop=0
trap "stop=1" SIGINT SIGTERM
while [ $stop -eq 0 ]; do
# 检查 JAR 程序是否在运行
if ! is_running; then
echo "JAR程序未启动,将在3秒后自动启动..."
sleep 3
start_program
else
else
echo "JAR程序已启动"
fi
fi
sleep 5
done
... ...
... ... @@ -127,6 +127,20 @@ public class CameraService {
logger.info("关闭摄像头");
}
/**
* 释放资源
*/
public void clean()
{
if(videoIsOpen)
{
videoIsOpen = false;
// 释放资源
videoCapture.release();
}
}
public VideoCapture getVideoCapture() {
return videoCapture;
}
... ...
... ... @@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
... ... @@ -147,11 +148,22 @@ public class FishGroupImageRecognitionService {
// 逐帧处理视频
Mat frame = new Mat();
scheduledExecutorService.scheduleWithFixedDelay(() -> {
logger.info("逐帧处理视频");
if (((Boolean)configurationParameterService.getConfig(ConfigurationParameter.FishGroupImageRecognition)) && videoCapture.read(frame)) {
logger.info("开始逐帧处理视频");
Boolean fishGroupImageRecognition = ((Boolean)configurationParameterService.getConfig(ConfigurationParameter.FishGroupImageRecognition));
Boolean isread = videoCapture.read(frame);
logger.info("逐帧处理视频,开始处理的判断参数:鱼群图像识别是否开启 {}、摄像头是否可读取 {}",fishGroupImageRecognition,isread);
if(!isread )
{
logger.info("摄像头不可读取");
if(cameraService.getVideoIsOpen())
{
logger.info("重新初始化");
cameraService.clean();
}
return;
}
if (fishGroupImageRecognition && isread) {
identify(frame,largestContour);
logger.info("结束逐帧处理视频");
}
},0,time, TimeUnit.MILLISECONDS);
... ...
... ... @@ -22,9 +22,6 @@ public class InitService {
private DeviceService deviceService;
@Autowired
private EhCacheService ehCacheService;
@Autowired
private FishGroupImageRecognitionService fishGroupImageRecognitionService;
@Autowired
... ...
... ... @@ -7,6 +7,7 @@ import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommd06Response;
import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommdDto;
import com.zhonglai.luhui.smart.feeder.dto.commd.FeederTimer;
import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil;
import com.zhonglai.luhui.smart.feeder.util.PenetrateUtil;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
import org.eclipse.paho.client.mqttv3.MqttException;
... ... @@ -84,9 +85,32 @@ public class MqttCallback implements MqttCallbackExtended {
}
}
}
else if(jsonObject.has("armbian"))
{
JsonObject armbian = jsonObject.get("armbian").getAsJsonObject();
for (String key:armbian.keySet())
{
switch (key)
{
case "penetrate":
int penetrate = armbian.get("penetrate").getAsInt();
switch (penetrate)
{
case 0:
PenetrateUtil.stop();
break;
case 1:
PenetrateUtil.start();
break;
}
break;
}
}
}
}
}
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
... ...
... ... @@ -58,7 +58,7 @@ public class TerminalService {
Map<String,Object> dmap = new HashMap<>();
Map<String,Object> map = new HashMap<>();
dmap.put("summary",map);
map.put("localhostIp",IpUtils.getHostIp());
map.put("localhostIp",IpUtils.getLocalHost());
JSONObject jsonObject = new JSONObject();
jsonObject.put("0",dmap);
String topic = "ADD_POST";
... ...
package com.zhonglai.luhui.smart.feeder.util;
import cn.hutool.core.util.RuntimeUtil;
public class PenetrateUtil {
public static void start()
{
RuntimeUtil.execForStr("/bin/sh","-c","cd /opt/lh-smart-feeder/frp_0.51.0_linux_arm64;./frpc -c ./frpc.ini");
System.out.println("frpc已启动");
}
public static void stop()
{
String checkCommand = "ps -ef | grep frpc";
String checkResult = RuntimeUtil.execForStr("/bin/sh","-c",checkCommand);
if (checkResult.contains("frpc")) {
String killCommand = "kill -9 $(ps -ef | grep frpc | grep -v grep | awk '{print $2}')";
RuntimeUtil.execForStr("/bin/sh","-c",killCommand);
System.out.println("frpc进程已被杀死");
} else {
System.out.println("frpc未在运行");
}
}
}
... ...
# 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8064 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* sys: staticPath: "file:/opt/lh-smart-feeder/lh-smart-feeder/html/" cacheFilePath: "E:/opt/lh-smart-feeder/lh-smart-feeder/cache/" # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # 数据源配置 spring: # autoconfigure: # exclude: org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: org.sqlite.JDBC druid: # 主库数据源 master: url: jdbc:sqlite:db/my.db username: password: # 从库数据源 slave: # 从数据源开关/默认关闭 enabled: false url: username: password: # 初始连接数 initialSize: 5 # 最小连接池数量 minIdle: 10 # 最大连接池数量 maxActive: 20 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最大生存的时间,单位是毫秒 maxEvictableIdleTimeMillis: 900000 # 配置检测连接是否有效 validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: false testOnReturn: false webStatFilter: enabled: true statViewServlet: enabled: true # 设置白名单,不填则允许所有访问 allow: url-pattern: /druid/* # 控制台管理用户名和密码 login-username: ruoyi login-password: 123456 filter: stat: enabled: true # 慢SQL记录 log-slow-sql: true slow-sql-millis: 1000 merge-sql: true wall: config: multi-statement-allow: true ## 数据源配置 #spring: # datasource: # type: com.alibaba.druid.pool.DruidDataSource # driverClassName: com.mysql.cj.jdbc.Driver # druid: # # 主库数据源 # master: # url: jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/mqtt_broker?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # username: luhui # password: Luhui586 # # 从库数据源 # slave: # # 从数据源开关/默认关闭 # enabled: true # url: jdbc:mysql://119.23.218.181:3306/lh-server-ops?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # username: luhui # password: Luhui586 # # 初始连接数 # initialSize: 5 # # 最小连接池数量 # minIdle: 10 # # 最大连接池数量 # maxActive: 20 # # 配置获取连接等待超时的时间 # maxWait: 60000 # # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 # timeBetweenEvictionRunsMillis: 60000 # # 配置一个连接在池中最小生存的时间,单位是毫秒 # minEvictableIdleTimeMillis: 300000 # # 配置一个连接在池中最大生存的时间,单位是毫秒 # maxEvictableIdleTimeMillis: 900000 # # 配置检测连接是否有效 # validationQuery: SELECT 1 FROM DUAL # testWhileIdle: true # testOnBorrow: false # testOnReturn: false # webStatFilter: # enabled: true # statViewServlet: # enabled: true # # 设置白名单,不填则允许所有访问 # allow: # url-pattern: /druid/* # # 控制台管理用户名和密码 # login-username: ruoyi # login-password: 123456 # filter: # stat: # enabled: true # # 慢SQL记录 # log-slow-sql: true # slow-sql-millis: 1000 # merge-sql: true # wall: # config: # multi-statement-allow: true mqtt: #链接地址 broker: tcp://175.24.61.68:1883 #唯一标识 clientId: 70094a59d1d991d #公司id roleid: 2 mqtt_usernames: 12_ZNZY #订阅的topic topics: PUT/+,GET_REQ/+, READ/+,POST_REQ/+ username: 12_ZNZY password: Luhui586 client: #客户端操作时间 operationTime: 10
\ No newline at end of file
# 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8064 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* sys: staticPath: "file:/opt/lh-smart-feeder/lh-smart-feeder/html/" # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain,com.zhonglai.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # 数据源配置 spring: # autoconfigure: # exclude: org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: org.sqlite.JDBC druid: # 主库数据源 master: url: jdbc:sqlite:db/my.db username: password: # 从库数据源 slave: # 从数据源开关/默认关闭 enabled: false url: username: password: # 初始连接数 initialSize: 5 # 最小连接池数量 minIdle: 10 # 最大连接池数量 maxActive: 20 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最大生存的时间,单位是毫秒 maxEvictableIdleTimeMillis: 900000 # 配置检测连接是否有效 validationQuery: SELECT 1 testWhileIdle: true testOnBorrow: false testOnReturn: false webStatFilter: enabled: true statViewServlet: enabled: true # 设置白名单,不填则允许所有访问 allow: url-pattern: /druid/* # 控制台管理用户名和密码 login-username: ruoyi login-password: 123456 filter: stat: enabled: true # 慢SQL记录 log-slow-sql: true slow-sql-millis: 1000 merge-sql: true wall: config: multi-statement-allow: true ## 数据源配置 #spring: # datasource: # type: com.alibaba.druid.pool.DruidDataSource # driverClassName: com.mysql.cj.jdbc.Driver # druid: # # 主库数据源 # master: # url: jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/mqtt_broker?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # username: luhui # password: Luhui586 # # 从库数据源 # slave: # # 从数据源开关/默认关闭 # enabled: true # url: jdbc:mysql://119.23.218.181:3306/lh-server-ops?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # username: luhui # password: Luhui586 # # 初始连接数 # initialSize: 5 # # 最小连接池数量 # minIdle: 10 # # 最大连接池数量 # maxActive: 20 # # 配置获取连接等待超时的时间 # maxWait: 60000 # # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 # timeBetweenEvictionRunsMillis: 60000 # # 配置一个连接在池中最小生存的时间,单位是毫秒 # minEvictableIdleTimeMillis: 300000 # # 配置一个连接在池中最大生存的时间,单位是毫秒 # maxEvictableIdleTimeMillis: 900000 # # 配置检测连接是否有效 # validationQuery: SELECT 1 FROM DUAL # testWhileIdle: true # testOnBorrow: false # testOnReturn: false # webStatFilter: # enabled: true # statViewServlet: # enabled: true # # 设置白名单,不填则允许所有访问 # allow: # url-pattern: /druid/* # # 控制台管理用户名和密码 # login-username: ruoyi # login-password: 123456 # filter: # stat: # enabled: true # # 慢SQL记录 # log-slow-sql: true # slow-sql-millis: 1000 # merge-sql: true # wall: # config: # multi-statement-allow: true mqtt: #链接地址 broker: tcp://175.24.61.68:1883 #唯一标识 clientId: 70094a59d1d991d #公司id roleid: 2 mqtt_usernames: 12_ZNZY #订阅的topic topics: PUT/+,GET_REQ/+, READ/+,POST_REQ/+ username: 12_ZNZY password: Luhui586 client: #客户端操作时间 operationTime: 10
\ No newline at end of file
... ...
... ... @@ -493,6 +493,12 @@
<artifactId>chatgpt-java</artifactId>
<version>1.0.12</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
</dependencies>
... ...