Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
|
d822014e60 | |
|
2e0eea6f40 |
|
@ -0,0 +1,26 @@
|
|||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.integrated_yjb_dataDocking</groupId>
|
||||
<artifactId>integrated_yjb_dataDocking</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>integrated_yjb_dataDocking</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.12.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<jdk.version>1.8</jdk.version>
|
||||
<knife4j.version>2.0.4</knife4j.version>
|
||||
<hutool.version>5.8.25</hutool.version>
|
||||
<lombok.version>1.16.18</lombok.version>
|
||||
<jna.version>5.4.0</jna.version>
|
||||
<spring-boot.version>2.3.12.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ghgande</groupId>
|
||||
<artifactId>j2mod</artifactId>
|
||||
<version>3.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.44</version>
|
||||
</dependency>
|
||||
<!-- Spring Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!-- spring aop -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.1.13</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>jconsole</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.baomidou</groupId>-->
|
||||
<!-- <artifactId>mybatis-plus-boot-starter</artifactId>-->
|
||||
<!-- <version>3.5.12</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!--knife4j-->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<version>${knife4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--Hutool工具包-->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--lombok-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!--jna-->
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>${jna.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>${jdk.version}</source>
|
||||
<target>${jdk.version}</target>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<!-- 读取resource文件夹下的所有文件-->
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.*</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>res</directory>
|
||||
<filtering>false</filtering>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>libs</directory>
|
||||
<filtering>false</filtering>
|
||||
<includes>
|
||||
<include>**/*.dll</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,23 @@
|
|||
package com.netsdk;
|
||||
|
||||
import com.ghgande.j2mod.modbus.slave.ModbusSlave;
|
||||
import com.ghgande.j2mod.modbus.slave.ModbusSlaveFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 主启动
|
||||
*
|
||||
* @author Yan Xu
|
||||
* @version 1.0
|
||||
* @date 2021/8/6
|
||||
* Copyright © goodits
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class DahuaApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DahuaApplication.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.netsdk;
|
||||
|
||||
import com.ghgande.j2mod.modbus.slave.ModbusSlave;
|
||||
import com.ghgande.j2mod.modbus.slave.ModbusSlaveFactory;
|
||||
import com.netsdk.service.DeviceService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* spring boot 启动后启动 modbusTcp服务
|
||||
*
|
||||
* @author lin
|
||||
*/
|
||||
@Component
|
||||
@Order(value = 1)
|
||||
public class StartModBusTcpServer implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private DeviceService deviceService;
|
||||
|
||||
|
||||
// 线圈(Coils) 01,05,15 00000-09999 读写 开关量输出new SimpleDigitalOut(true);
|
||||
// 离散输入(DI) 02 10000-19999 只读 开关量输入new SimpleDigitalIn(false);
|
||||
// 保持寄存器 读写 new SimpleRegister(251);
|
||||
// 输入寄存器 只读 new SimpleInputRegister(45);
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
deviceService.initMqOrderList();
|
||||
// 离散输入(DI) 02 10000-1FFFF 10001-19999 只读位
|
||||
// 输入寄存器(IR) 04 30000-3FFFF 30001-39999 只读16位值
|
||||
ModbusSlave slave = ModbusSlaveFactory.createTCPSlave(1888, 5);
|
||||
// 高炉
|
||||
slave.addProcessImage(1, deviceService.getGlProcessImage());
|
||||
// 转炉
|
||||
slave.addProcessImage(2, deviceService.getZlProcessImage());
|
||||
// 精炼炉
|
||||
slave.addProcessImage(3, deviceService.getLfProcessImage());
|
||||
// 煤气报警器
|
||||
slave.addProcessImage(4, deviceService.getMqProcessImage());
|
||||
slave.open();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.netsdk.config;
|
||||
|
||||
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||
import com.google.common.base.Predicates;
|
||||
import springfox.documentation.service.Contact;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 接口文档配置
|
||||
* @author Yan Xu
|
||||
* @version 1.0
|
||||
* @date 2021/8/7
|
||||
* Copyright © goodits
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@EnableKnife4j
|
||||
public class Knife4jConfiguration {
|
||||
|
||||
|
||||
private final ServerProperties serverProperties;
|
||||
private final SysInfoProperties sysInfoProperties;
|
||||
|
||||
public Knife4jConfiguration(ServerProperties serverProperties, SysInfoProperties sysInfoProperties) {
|
||||
this.serverProperties = serverProperties;
|
||||
this.sysInfoProperties = sysInfoProperties;
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
String serviceUrl = "http://localhost:" + serverProperties.getPort();
|
||||
return new ApiInfoBuilder()
|
||||
.title(sysInfoProperties.getChineseName()+"后台接口文档")
|
||||
.description(sysInfoProperties.getDescription())
|
||||
.termsOfServiceUrl(serviceUrl)
|
||||
.version(sysInfoProperties.getVersion())
|
||||
.contact(new Contact(sysInfoProperties.getPic(), null, "2366528143@qq.com"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean(value = "defaultApi2")
|
||||
public Docket defaultApi2() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
//分组名称
|
||||
.groupName("defaultApi2")
|
||||
.select()
|
||||
//这里指定Controller扫描包路径
|
||||
//.apis(RequestHandlerSelectors.basePackage("com.goodits.controller"))
|
||||
// 对所有api进行监控
|
||||
.apis(RequestHandlerSelectors.any())
|
||||
//错误路径不监控
|
||||
.paths(Predicates.not(PathSelectors.regex("/error.*")))
|
||||
//服务质量检测路径不监控
|
||||
.paths(Predicates.not(PathSelectors.regex("/actuator.*")))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.netsdk.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* 说明:第一数据源配置
|
||||
* 作者:luoxiaobao
|
||||
* 官网:www.qdkjchina.com
|
||||
*/
|
||||
@Configuration
|
||||
@MapperScan(basePackages = MasterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory") //扫描 Mapper 接口并容器管理
|
||||
public class MasterDataSourceConfig {
|
||||
|
||||
static final String PACKAGE = "com.netsdk.mapper.datasource"; //master 目录
|
||||
static final String MAPPER_LOCATION = "classpath:mybatis/datasource/*/*.xml"; //扫描的 xml 目录
|
||||
static final String CONFIG_LOCATION = "classpath:mybatis/datasource/mybatis-config.xml"; //自定义的mybatis config 文件位置
|
||||
static final String TYPE_ALIASES_PACKAGE = "com.netsdk.entity"; //扫描的 实体类 目录
|
||||
|
||||
@Value("${spring.datasource.url}")
|
||||
private String url;
|
||||
|
||||
@Value("${spring.datasource.username}")
|
||||
private String user;
|
||||
|
||||
@Value("${spring.datasource.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${spring.datasource.driver-class-name}")
|
||||
private String driverClass;
|
||||
|
||||
@Bean(name = "masterDataSource")
|
||||
@Primary
|
||||
public DataSource masterDataSource() {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Bean(name = "masterTransactionManager")
|
||||
@Primary
|
||||
public DataSourceTransactionManager masterTransactionManager() {
|
||||
return new DataSourceTransactionManager(masterDataSource());
|
||||
}
|
||||
|
||||
@Bean(name = "masterSqlSessionFactory")
|
||||
@Primary
|
||||
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource)throws Exception {
|
||||
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
||||
sessionFactory.setDataSource(masterDataSource);
|
||||
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MasterDataSourceConfig.MAPPER_LOCATION));
|
||||
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(MasterDataSourceConfig.CONFIG_LOCATION));
|
||||
sessionFactory.setTypeAliasesPackage(MasterDataSourceConfig.TYPE_ALIASES_PACKAGE);
|
||||
return sessionFactory.getObject();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.netsdk.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* 说明:Redis
|
||||
|
||||
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("all")
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
|
||||
template.setConnectionFactory(factory);
|
||||
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
// key采用String的序列化方式
|
||||
template.setKeySerializer(stringRedisSerializer);
|
||||
// hash的key也采用String的序列化方式
|
||||
template.setHashKeySerializer(stringRedisSerializer);
|
||||
// value序列化方式采用jackson
|
||||
template.setValueSerializer(jackson2JsonRedisSerializer);
|
||||
// hash的value序列化方式采用jackson
|
||||
template.setHashValueSerializer(jackson2JsonRedisSerializer);
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.netsdk.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* 静态文件访问映射
|
||||
*
|
||||
* @author Yan Xu
|
||||
* @version 1.0
|
||||
* @date 2021/8/7
|
||||
* Copyright © goodits
|
||||
*/
|
||||
@Configuration
|
||||
public class StaticFileConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
//访问 /img/**会被解析为/static/img/**
|
||||
registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/img/");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.netsdk.config;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
// 注册为组件
|
||||
@EnableConfigurationProperties
|
||||
// 启用配置自动注入功能
|
||||
@ConfigurationProperties(prefix = "project")
|
||||
//指定类对应的配置项前缀
|
||||
@ApiModel(description = "系统描述")
|
||||
public class SysInfoProperties {
|
||||
@ApiModelProperty(value = "应用中文名")
|
||||
private String chineseName;
|
||||
@ApiModelProperty(value = "应用描述")
|
||||
private String description;
|
||||
@ApiModelProperty(value = "版本")
|
||||
private String version;
|
||||
@ApiModelProperty(value = "开发")
|
||||
private String pic;
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package com.netsdk.entity;
|
||||
|
||||
import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Reader;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 说明:参数封装Map
|
||||
|
||||
|
||||
*/
|
||||
public class PageData extends HashMap<Object, Object> implements Map<Object, Object> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
Map<Object, Object> map = null;
|
||||
HttpServletRequest request;
|
||||
|
||||
public PageData(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
Map properties = request.getParameterMap();
|
||||
Map<Object, Object> returnMap = new HashMap<Object, Object>();
|
||||
Iterator<Object> entries = properties.entrySet().iterator();
|
||||
Entry<Object, Object> entry;
|
||||
String name = "";
|
||||
String value = "";
|
||||
while (entries.hasNext()) {
|
||||
entry = (Entry<Object, Object>) entries.next();
|
||||
name = (String) entry.getKey();
|
||||
Object valueObj = entry.getValue();
|
||||
if (null == valueObj) {
|
||||
value = "";
|
||||
} else if (valueObj instanceof String[]) {
|
||||
String[] values = (String[]) valueObj;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
value = values[i] + ",";
|
||||
}
|
||||
value = value.substring(0, value.length() - 1);
|
||||
} else {
|
||||
value = valueObj.toString();
|
||||
}
|
||||
returnMap.put(name, value);
|
||||
}
|
||||
map = returnMap;
|
||||
}
|
||||
|
||||
public PageData() {
|
||||
map = new HashMap<Object, Object>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object get(Object key) {
|
||||
Object obj = null;
|
||||
if (map.get(key) instanceof Object[]) {
|
||||
Object[] arr = (Object[]) map.get(key);
|
||||
obj = request == null ? arr : (request.getParameter((String) key) == null ? arr : arr[0]);
|
||||
} else {
|
||||
obj = map.get(key);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public String getString(Object key) {
|
||||
return get(key) == null ? null : get(key).toString().trim();
|
||||
}
|
||||
public String getStringOrDefault(Object key,String defaultValue) {
|
||||
return get(key) == null ? defaultValue : get(key).toString().trim();
|
||||
}
|
||||
@Override
|
||||
public Object getOrDefault(Object key,Object defaultValue) {
|
||||
return map.getOrDefault(key,defaultValue);
|
||||
}
|
||||
@Override
|
||||
public Object put(Object key, Object value) {
|
||||
if (value instanceof ClobProxyImpl) { // 读取oracle Clob类型数据
|
||||
try {
|
||||
ClobProxyImpl cpi = (ClobProxyImpl) value;
|
||||
Reader is = cpi.getCharacterStream(); // 获取流
|
||||
BufferedReader br = new BufferedReader(is);
|
||||
String str = br.readLine();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (str != null) { // 循环读取数据拼接到字符串
|
||||
sb.append(str);
|
||||
sb.append("\n");
|
||||
str = br.readLine();
|
||||
}
|
||||
value = sb.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return map.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object remove(Object key) {
|
||||
return map.remove(key);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
// TODO Auto-generated method stub
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
// TODO Auto-generated method stub
|
||||
return map.containsValue(value);
|
||||
}
|
||||
|
||||
public Set entrySet() {
|
||||
// TODO Auto-generated method stub
|
||||
return map.entrySet();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
// TODO Auto-generated method stub
|
||||
return map.isEmpty();
|
||||
}
|
||||
|
||||
public Set keySet() {
|
||||
// TODO Auto-generated method stub
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void putAll(Map t) {
|
||||
// TODO Auto-generated method stub
|
||||
map.putAll(t);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
// TODO Auto-generated method stub
|
||||
return map.size();
|
||||
}
|
||||
|
||||
public Collection values() {
|
||||
// TODO Auto-generated method stub
|
||||
return map.values();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.netsdk.exception;
|
||||
|
||||
/**
|
||||
* 自定义服务异常
|
||||
* @author Yan Xu
|
||||
* @version 1.0
|
||||
* @date 2023/4/19
|
||||
*/
|
||||
public class ServiceException extends RuntimeException{
|
||||
|
||||
public ServiceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ServiceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ServiceException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.netsdk.mapper.datasource.other;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
@Mapper
|
||||
public interface OtherMapper {
|
||||
ArrayList<HashMap<String, String>> getAllMqOrderList();
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.netsdk.service;
|
||||
|
||||
import com.ghgande.j2mod.modbus.procimg.ProcessImage;
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
public interface DeviceService {
|
||||
ProcessImage getGlProcessImage();
|
||||
|
||||
ProcessImage getZlProcessImage();
|
||||
|
||||
ProcessImage getLfProcessImage();
|
||||
|
||||
ProcessImage getMqProcessImage();
|
||||
void initMqOrderList();
|
||||
}
|
|
@ -0,0 +1,332 @@
|
|||
package com.netsdk.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.JSONPObject;
|
||||
import com.ghgande.j2mod.modbus.procimg.ProcessImage;
|
||||
import com.ghgande.j2mod.modbus.procimg.SimpleDigitalIn;
|
||||
import com.ghgande.j2mod.modbus.procimg.SimpleInputRegister;
|
||||
import com.ghgande.j2mod.modbus.procimg.SimpleProcessImage;
|
||||
import com.netsdk.mapper.datasource.other.OtherMapper;
|
||||
import com.netsdk.service.DeviceService;
|
||||
import com.netsdk.utils.OtherInputRegister;
|
||||
import com.netsdk.utils.RedisUtil;
|
||||
import com.netsdk.utils.SyncGlScheduledTasks;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
@Service
|
||||
public class DeviceServiceImpl implements DeviceService {
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private OtherMapper otherMapper;
|
||||
|
||||
@Override
|
||||
public ProcessImage getGlProcessImage() {
|
||||
// 高炉设备初始话获取数据
|
||||
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("GL_LIST"));
|
||||
// SBXH-GL-1 高炉#炉顶工作压力
|
||||
// 高炉#炉顶放散阀联锁投入状态#东大放散阀状态-关到位 SBXH-GL-2-2
|
||||
// 高炉#炉顶放散阀联锁投入状态#东大放散阀状态-开到位 SBXH-GL-2-1
|
||||
// 高炉#炉顶放散阀联锁投入状态#西大放散阀状态-开到位 SBXH-GL-2-3
|
||||
// 高炉#炉顶放散阀联锁投入状态#西大放散阀状态-关到位 SBXH-GL-2-4
|
||||
SimpleProcessImage spi = new SimpleProcessImage();
|
||||
// 离散输入(DI) 02 10000-1FFFF 10001-19999 只读位
|
||||
SimpleInputRegister SBXH_GL_2_5 = new SimpleInputRegister();
|
||||
SimpleInputRegister dynamicRegHig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister dynamicReglow = new SimpleInputRegister(0);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-GL-1" + "hig", dynamicRegHig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-GL-1" + "low", dynamicReglow);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-GL-2-5", SBXH_GL_2_5);
|
||||
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
JSONObject jsonObject = objects.getJSONObject(i);
|
||||
if ("SBXH-GL-1".equals(jsonObject.getString("IPCDEVICE_ID"))) {
|
||||
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
|
||||
int bits = Float.floatToIntBits(intValue);
|
||||
dynamicRegHig.setValue((bits >> 16) & 0xFFFF);
|
||||
dynamicReglow.setValue(bits & 0xFFFF);
|
||||
}
|
||||
if ("SBXH-GL-2-5".equals(jsonObject.getString("IPCDEVICE_ID"))) {
|
||||
double intValue = jsonObject.getDouble("CURRENT_VALUE");
|
||||
SBXH_GL_2_5.setValue((int) intValue);
|
||||
}
|
||||
|
||||
}
|
||||
// SBXH-GL-1 高炉#炉顶工作压力
|
||||
// 输入寄存器(IR) 04 30000-3FFFF 30001-39999 只读16位值
|
||||
spi.addInputRegister(dynamicRegHig);
|
||||
spi.addInputRegister(dynamicReglow);
|
||||
spi.addInputRegister(SBXH_GL_2_5);
|
||||
int inputRegisterCount = spi.getInputRegisterCount();
|
||||
for (int i = inputRegisterCount; i < 1000; i++) {
|
||||
spi.addInputRegister(new SimpleInputRegister(0));
|
||||
}
|
||||
return spi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessImage getZlProcessImage() {
|
||||
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("ZL_LIST"));
|
||||
SimpleProcessImage spi = new SimpleProcessImage();
|
||||
initZlSimpleInputRegister(spi);
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
JSONObject jsonObject = objects.getJSONObject(i);
|
||||
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
|
||||
if ("1".equals(jsonObject.getString("SIGNAL_TYPE"))) {
|
||||
// 模拟量
|
||||
SimpleInputRegister simpleInputRegister_hig = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "hig");
|
||||
SimpleInputRegister simpleInputRegister_low = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "low");
|
||||
if (simpleInputRegister_hig != null) {
|
||||
int bits = Float.floatToIntBits(intValue);
|
||||
simpleInputRegister_hig.setValue((bits >> 16) & 0xFFFF);
|
||||
simpleInputRegister_low.setValue(bits & 0xFFFF);
|
||||
}
|
||||
} else {
|
||||
SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
|
||||
if (simpleInputRegister == null) continue;
|
||||
// 开关量
|
||||
simpleInputRegister.setValue((int) intValue);
|
||||
}
|
||||
}
|
||||
// 这个别删除、省局要求 寄存器数量不能少于1000个哪怕没数据
|
||||
int inputRegisterCount = spi.getInputRegisterCount();
|
||||
for (int i = inputRegisterCount; i < 1000; i++) {
|
||||
spi.addInputRegister(new SimpleInputRegister(0));
|
||||
}
|
||||
return spi;
|
||||
}
|
||||
|
||||
private void initZlSimpleInputRegister(SimpleProcessImage spi) {
|
||||
SimpleInputRegister SBXH_ZL_1_1_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_1_1_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_1_2_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_1_2_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_2_1_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_2_1_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_2_2_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_2_2_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_4_1_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_4_1_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_4_2_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_4_2_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_5_1_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_5_1_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_5_2_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_ZL_5_2_low = new SimpleInputRegister(0);
|
||||
|
||||
|
||||
// 水冷氧枪-氧气压力1#枪氧气压力
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-1" + "hig", SBXH_ZL_1_1_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-1" + "low", SBXH_ZL_1_1_low);
|
||||
// 水冷氧枪-氧气压力2#枪氧气压力
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-2" + "hig", SBXH_ZL_1_2_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-2" + "low", SBXH_ZL_1_2_low);
|
||||
// 水冷氧枪-冷却水进水流量 1#枪冷却水进水流量
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-1" + "hig", SBXH_ZL_2_1_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-1" + "low", SBXH_ZL_2_1_low);
|
||||
// 水冷氧枪-冷却水进水流量 2#枪冷却水进水流量
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-2" + "hig", SBXH_ZL_2_2_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-2" + "low", SBXH_ZL_2_2_low);
|
||||
// 水冷氧枪-冷却水出水温度1#枪冷却水出水温度
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-1" + "hig", SBXH_ZL_4_1_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-1" + "low", SBXH_ZL_4_1_low);
|
||||
// 水冷氧枪-冷却水出水温度2#枪冷却水出水温度
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-2" + "hig", SBXH_ZL_4_2_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-2" + "low", SBXH_ZL_4_2_low);
|
||||
// 水冷氧枪-冷却水进出水流量差 SBXH-ZL_5-1 1#枪冷却水进出水流量差
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-1" + "hig", SBXH_ZL_5_1_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-1" + "low", SBXH_ZL_5_1_low);
|
||||
// 水冷氧枪-冷却水进出水流量差 SBXH-ZL_5-2 2#枪冷却水进出水流量差
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-2" + "hig", SBXH_ZL_5_2_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-2" + "low", SBXH_ZL_5_2_low);
|
||||
|
||||
|
||||
// 氧气压力与氧枪自动升起联锁投入状态
|
||||
SimpleInputRegister SBXH_ZL_5 = new SimpleInputRegister();
|
||||
// 冷却水进水流量与氧枪自动升起联锁投入状态
|
||||
SimpleInputRegister SBXH_ZL_6 = new SimpleInputRegister();
|
||||
// 冷却水出水温度与氧枪自动升起联锁投入状态
|
||||
SimpleInputRegister SBXH_ZL_7 = new SimpleInputRegister();
|
||||
// 进出水流量差与氧枪自动升起联锁投入状态
|
||||
SimpleInputRegister SBXH_ZL_8 = new SimpleInputRegister();
|
||||
// 冷却水进出水流量差与炉体倾动联锁投入状态
|
||||
SimpleInputRegister SBXH_ZL_9 = new SimpleInputRegister();
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-5", SBXH_ZL_5);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-6", SBXH_ZL_6);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-7", SBXH_ZL_7);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-8", SBXH_ZL_8);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-9", SBXH_ZL_9);
|
||||
spi.addInputRegister(SBXH_ZL_1_1_hig);
|
||||
spi.addInputRegister(SBXH_ZL_1_1_low);
|
||||
spi.addInputRegister(SBXH_ZL_1_2_hig);
|
||||
spi.addInputRegister(SBXH_ZL_1_2_low);
|
||||
spi.addInputRegister(SBXH_ZL_2_1_hig);
|
||||
spi.addInputRegister(SBXH_ZL_2_1_low);
|
||||
spi.addInputRegister(SBXH_ZL_2_2_hig);
|
||||
spi.addInputRegister(SBXH_ZL_2_2_low);
|
||||
spi.addInputRegister(SBXH_ZL_5_1_hig);
|
||||
spi.addInputRegister(SBXH_ZL_5_1_low);
|
||||
spi.addInputRegister(SBXH_ZL_5_2_hig);
|
||||
spi.addInputRegister(SBXH_ZL_5_2_low);
|
||||
spi.addInputRegister(SBXH_ZL_4_1_hig);
|
||||
spi.addInputRegister(SBXH_ZL_4_1_low);
|
||||
spi.addInputRegister(SBXH_ZL_4_2_hig);
|
||||
spi.addInputRegister(SBXH_ZL_4_2_low);
|
||||
|
||||
spi.addInputRegister(SBXH_ZL_5);
|
||||
spi.addInputRegister(SBXH_ZL_6);
|
||||
spi.addInputRegister(SBXH_ZL_7);
|
||||
spi.addInputRegister(SBXH_ZL_8);
|
||||
spi.addInputRegister(SBXH_ZL_9);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessImage getLfProcessImage() {
|
||||
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("JL_LIST"));
|
||||
SimpleProcessImage spi = new SimpleProcessImage();
|
||||
initLfSimpleInputRegister(spi);
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
JSONObject jsonObject = objects.getJSONObject(i);
|
||||
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
|
||||
if ("1".equals(jsonObject.getString("SIGNAL_TYPE"))) {
|
||||
// 模拟量
|
||||
SimpleInputRegister simpleInputRegister_hig = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "hig");
|
||||
SimpleInputRegister simpleInputRegister_low = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "low");
|
||||
if (simpleInputRegister_hig != null) {
|
||||
int bits = Float.floatToIntBits(intValue);
|
||||
simpleInputRegister_hig.setValue((bits >> 16) & 0xFFFF);
|
||||
simpleInputRegister_low.setValue(bits & 0xFFFF);
|
||||
}
|
||||
} else {
|
||||
SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
|
||||
// SBXH-JL-3
|
||||
SimpleInputRegister simpleInputRegister1 = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "_1");
|
||||
if (simpleInputRegister1 != null) {
|
||||
simpleInputRegister1.setValue((int) intValue);
|
||||
}
|
||||
if (simpleInputRegister == null) continue;
|
||||
// 开关量
|
||||
simpleInputRegister.setValue((int) intValue);
|
||||
}
|
||||
}
|
||||
int inputRegisterCount = spi.getInputRegisterCount();
|
||||
for (int i = inputRegisterCount; i < 1000; i++) {
|
||||
spi.addInputRegister(new SimpleInputRegister(0));
|
||||
}
|
||||
// 冷却水出水温度与电极自动断 电联锁投入状态
|
||||
// 冷却水出水温度与电极升起联锁投入状态
|
||||
// 进出水流量差与电极自动断电联锁投入状态
|
||||
// 进出水流量差与电极升起联锁投入状态
|
||||
return spi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessImage getMqProcessImage() {
|
||||
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("MQ_LIST"));
|
||||
SimpleProcessImage spi = new SimpleProcessImage();
|
||||
initMqSimpleInputRegister(spi);
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
JSONObject jsonObject = objects.getJSONObject(i);
|
||||
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
|
||||
SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
|
||||
if (simpleInputRegister == null) continue;
|
||||
// 开关量
|
||||
simpleInputRegister.setValue((int) intValue);
|
||||
}
|
||||
int inputRegisterCount = spi.getInputRegisterCount();
|
||||
for (int i = inputRegisterCount; i < 1000; i++) {
|
||||
spi.addInputRegister(new SimpleInputRegister(0));
|
||||
}
|
||||
return spi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initMqOrderList() {
|
||||
ArrayList<HashMap<String, String>> allMqOrderList = otherMapper.getAllMqOrderList();
|
||||
for (HashMap<String, String> hashMap : allMqOrderList) {
|
||||
SyncGlScheduledTasks.MQ_ORDER_MAP.put(Integer.parseInt(String.valueOf(hashMap.get("ID"))), hashMap.get("IPCDEVICE_ID"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initMqSimpleInputRegister(SimpleProcessImage spi) {
|
||||
int size = SyncGlScheduledTasks.MQ_ORDER_MAP.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
SimpleInputRegister simpleInputRegister = new SimpleInputRegister();
|
||||
spi.addInputRegister(simpleInputRegister);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put(SyncGlScheduledTasks.MQ_ORDER_MAP.get(i), simpleInputRegister);
|
||||
}
|
||||
}
|
||||
|
||||
private void initLfSimpleInputRegister(SimpleProcessImage spi) {
|
||||
// 冷却水出水温度
|
||||
// SBXH-JL-1-1 1#冷却水出水温度
|
||||
// SBXH-JL-1-2 2#冷却水出水温度
|
||||
//冷却水进出水流量差
|
||||
// SBXH-JL-3-1 1#冷却水进出水流量差
|
||||
// SBXH-JL-3-2 2#冷却水进出水流量差
|
||||
SimpleInputRegister SBXH_JL_1_1_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_JL_1_1_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_JL_1_2_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_JL_1_2_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_JL_3_1_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_JL_3_1_low = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_JL_3_2_hig = new SimpleInputRegister(0);
|
||||
SimpleInputRegister SBXH_JL_3_2_low = new SimpleInputRegister(0);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-1" + "hig", SBXH_JL_1_1_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-1" + "low", SBXH_JL_1_1_low);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-2" + "hig", SBXH_JL_1_2_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-2" + "low", SBXH_JL_1_2_low);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-1" + "hig", SBXH_JL_3_1_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-1" + "low", SBXH_JL_3_1_low);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-2" + "hig", SBXH_JL_3_2_hig);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-2" + "low", SBXH_JL_3_2_low);
|
||||
// 冷却水出水温度与电极自动断电联锁投入状态 冷却水出水温度与电极升起联锁投入状态 1#炉盖回水温度联锁
|
||||
SimpleInputRegister SBXH_JL_3 = new SimpleInputRegister();
|
||||
SimpleInputRegister SBXH_JL_3_1 = new SimpleInputRegister();
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3", SBXH_JL_3);
|
||||
// 冷却水出水温度与电极升起联锁投入状态 1#炉盖回水温度联锁
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3_1", SBXH_JL_3);
|
||||
// 冷却水出水温度与电极自动断电联锁投入状态 冷却水出水温度与电极升起联锁投入状态 2#炉盖回水温度联锁
|
||||
SimpleInputRegister SBXH_JL_4 = new SimpleInputRegister();
|
||||
SimpleInputRegister SBXH_JL_4_1 = new SimpleInputRegister();
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-4", SBXH_JL_4);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-4_1", SBXH_JL_4);
|
||||
// 进出水流量差与电极自动断电联锁投入状态 进出水流量差与电极升起联锁投入状态 1#炉盖回水流量差联锁
|
||||
SimpleInputRegister SBXH_JL_5 = new SimpleInputRegister();
|
||||
SimpleInputRegister SBXH_JL_5_1 = new SimpleInputRegister();
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-5", SBXH_JL_5);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-5_1", SBXH_JL_5);
|
||||
// 进出水流量差与电极自动断电联锁投入状态 进出水流量差与电极升起联锁投入状态 2#炉盖回水流量差联锁
|
||||
SimpleInputRegister SBXH_JL_6 = new SimpleInputRegister();
|
||||
SimpleInputRegister SBXH_JL_6_1 = new SimpleInputRegister();
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-6", SBXH_JL_6);
|
||||
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-6_1", SBXH_JL_6);
|
||||
spi.addInputRegister(SBXH_JL_1_1_hig);
|
||||
spi.addInputRegister(SBXH_JL_1_2_low);
|
||||
spi.addInputRegister(SBXH_JL_1_2_hig);
|
||||
spi.addInputRegister(SBXH_JL_1_2_low);
|
||||
spi.addInputRegister(SBXH_JL_3_1_hig);
|
||||
spi.addInputRegister(SBXH_JL_3_1_low);
|
||||
spi.addInputRegister(SBXH_JL_3_2_hig);
|
||||
spi.addInputRegister(SBXH_JL_3_2_low);
|
||||
spi.addInputRegister(SBXH_JL_3);
|
||||
spi.addInputRegister(SBXH_JL_4);
|
||||
spi.addInputRegister(SBXH_JL_5);
|
||||
spi.addInputRegister(SBXH_JL_6);
|
||||
spi.addInputRegister(SBXH_JL_3_1);
|
||||
spi.addInputRegister(SBXH_JL_4_1);
|
||||
spi.addInputRegister(SBXH_JL_5_1);
|
||||
spi.addInputRegister(SBXH_JL_6_1);
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,42 @@
|
|||
package com.netsdk.utils;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 文件工具类
|
||||
*
|
||||
* @author Yan Xu
|
||||
* @version 1.0
|
||||
* @date 2021/8/7
|
||||
* Copyright © goodits
|
||||
*/
|
||||
@Slf4j
|
||||
public class FilePathUtils {
|
||||
|
||||
//路径前加.号代表项目根目录
|
||||
private static final String DIR_PATH = "./static/img";
|
||||
|
||||
@SneakyThrows
|
||||
public static String getUploadDir() {
|
||||
//如果目录不存在,自动创建文件夹
|
||||
File dir = new File(DIR_PATH);
|
||||
if (!dir.exists()) {
|
||||
//文件
|
||||
boolean mkdir = dir.mkdirs();
|
||||
if (Boolean.FALSE.equals(mkdir)) {
|
||||
log.warn("创建目录{}失败", DIR_PATH);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return dir.getAbsolutePath();
|
||||
}
|
||||
|
||||
public static String getUrlPathByFileName(HttpServletRequest request, String fileName) {
|
||||
return request.getScheme() + "://" + request.getServerName() + ":" +
|
||||
request.getServerPort() + "/img/" + fileName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.netsdk.utils;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ModBusUtils {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.netsdk.utils;
|
||||
|
||||
import com.ghgande.j2mod.modbus.procimg.IllegalAddressException;
|
||||
import com.ghgande.j2mod.modbus.procimg.SimpleInputRegister;
|
||||
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
public class OtherInputRegister extends SimpleInputRegister {
|
||||
public OtherInputRegister() {
|
||||
}
|
||||
|
||||
public synchronized void setFloatValue(float f) {
|
||||
if (this.register == null) {
|
||||
throw new IllegalAddressException();
|
||||
}
|
||||
// 将浮点数转换为32位整数
|
||||
int intBits = Float.floatToIntBits(f);
|
||||
|
||||
// 拆分成两个16位寄存器
|
||||
this.register[0] = (byte) ((intBits >> 16) & 0xFF);
|
||||
// 高16位
|
||||
this.register[1] = (byte) (intBits & 0xFF);
|
||||
// 低16位
|
||||
}
|
||||
}
|
|
@ -0,0 +1,720 @@
|
|||
package com.netsdk.utils;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public final class RedisUtil {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
// =============================common============================
|
||||
|
||||
/**
|
||||
* 指定缓存失效时间
|
||||
*
|
||||
* @param key 键
|
||||
* @param time 时间(秒)
|
||||
* @return
|
||||
*/
|
||||
public boolean expire(String key, long time) {
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.expire(key, time, TimeUnit.SECONDS);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean expire(String key, long time, TimeUnit timeUnit) {
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.expire(key, time, timeUnit);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据key 获取过期时间
|
||||
*
|
||||
* @param key 键 不能为null
|
||||
* @return 时间(秒) 返回0代表为永久有效
|
||||
*/
|
||||
public long getExpire(String key) {
|
||||
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断key是否存在
|
||||
*
|
||||
* @param key 键
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public boolean hasKey(String key) {
|
||||
try {
|
||||
return redisTemplate.hasKey(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
*
|
||||
* @param key 可以传一个值 或多个
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void del(String... key) {
|
||||
if (key != null && key.length > 0) {
|
||||
if (key.length == 1) {
|
||||
redisTemplate.delete(key[0]);
|
||||
} else {
|
||||
redisTemplate.delete(CollectionUtils.arrayToList(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================String=============================
|
||||
|
||||
/**
|
||||
* 普通缓存获取
|
||||
*
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public Object get(String key) {
|
||||
return key == null ? null : redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通缓存放入
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return true成功 false失败
|
||||
*/
|
||||
public boolean set(String key, Object value) {
|
||||
try {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通缓存放入并设置时间
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
|
||||
* @return true成功 false 失败
|
||||
*/
|
||||
|
||||
public boolean set(String key, Object value, long time) {
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
|
||||
} else {
|
||||
set(key, value);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public boolean set(String key, Object value, long time, TimeUnit timeUnit) {
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.opsForValue().set(key, value, time, timeUnit);
|
||||
} else {
|
||||
set(key, value);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递增
|
||||
*
|
||||
* @param key 键
|
||||
* @param delta 要增加几(大于0)
|
||||
* @return
|
||||
*/
|
||||
|
||||
public long incr(String key, long delta) {
|
||||
if (delta < 0) {
|
||||
throw new RuntimeException("递增因子必须大于0");
|
||||
}
|
||||
return redisTemplate.opsForValue().increment(key, delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递减
|
||||
*
|
||||
* @param key 键
|
||||
* @param delta 要减少几(小于0)
|
||||
* @return
|
||||
*/
|
||||
public long decr(String key, long delta) {
|
||||
if (delta < 0) {
|
||||
throw new RuntimeException("递减因子必须大于0");
|
||||
}
|
||||
return redisTemplate.opsForValue().increment(key, -delta);
|
||||
}
|
||||
|
||||
// ================================Map=================================
|
||||
|
||||
/**
|
||||
* HashGet
|
||||
*
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 不能为null
|
||||
* @return 值
|
||||
*/
|
||||
public Object hget(String key, String item) {
|
||||
return redisTemplate.opsForHash().get(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 只有当给定的键不存在时,才设置键值对
|
||||
* @param hashKey 是哈希表的键,用于定位到Redis中的特定哈希表。
|
||||
* @param key 键 不能为null
|
||||
* @param value 项 不能为null
|
||||
* @return 值
|
||||
*/
|
||||
public Object hPutIfAbsent(String hashKey, String key, Object value) {
|
||||
return redisTemplate.opsForHash().putIfAbsent(hashKey, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取hashKey对应的所有键值
|
||||
*
|
||||
* @param key 键
|
||||
* @return 对应的多个键值
|
||||
*/
|
||||
public Map<Object, Object> hmget(String key) {
|
||||
return redisTemplate.opsForHash().entries(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* HashSet
|
||||
*
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
* @return true 成功 false 失败
|
||||
*/
|
||||
public boolean hmset(String key, Map<String, Object> map) {
|
||||
try {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HashSet 并设置时间
|
||||
*
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
* @param time 时间(秒)
|
||||
* @return true成功 false失败
|
||||
*/
|
||||
public boolean hmset(String key, Map<String, Object> map, long time) {
|
||||
try {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @return true 成功 false失败
|
||||
*/
|
||||
public boolean hset(String key, String item, Object value) {
|
||||
try {
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
|
||||
* @return true 成功 false失败
|
||||
*/
|
||||
public boolean hset(String key, String item, Object value, long time) {
|
||||
try {
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除hash表中的值
|
||||
*
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 可以使多个 不能为null
|
||||
*/
|
||||
public void hdel(String key, Object... item) {
|
||||
redisTemplate.opsForHash().delete(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断hash表中是否有该项的值
|
||||
*
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 不能为null
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public boolean hHasKey(String key, String item) {
|
||||
return redisTemplate.opsForHash().hasKey(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要增加几(大于0)
|
||||
* @return
|
||||
*/
|
||||
public double hincr(String key, String item, double by) {
|
||||
return redisTemplate.opsForHash().increment(key, item, by);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash递减
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要减少记(小于0)
|
||||
* @return
|
||||
*/
|
||||
public double hdecr(String key, String item, double by) {
|
||||
return redisTemplate.opsForHash().increment(key, item, -by);
|
||||
}
|
||||
|
||||
// ============================set=============================
|
||||
|
||||
/**
|
||||
* 根据key获取Set中的所有值
|
||||
*
|
||||
* @param key 键
|
||||
* @return
|
||||
*/
|
||||
public Set<Object> sGet(String key) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().members(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据value从一个set中查询,是否存在
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public boolean sHasKey(String key, Object value) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().isMember(key, value);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据放入set缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param values 值 可以是多个
|
||||
* @return 成功个数
|
||||
*/
|
||||
public long sSet(String key, Object... values) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().add(key, values);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将set数据放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param time 时间(秒)
|
||||
* @param values 值 可以是多个
|
||||
* @return 成功个数
|
||||
*/
|
||||
public long sSetAndTime(String key, long time, Object... values) {
|
||||
try {
|
||||
Long count = redisTemplate.opsForSet().add(key, values);
|
||||
if (time > 0) expire(key, time);
|
||||
return count;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取set缓存的长度
|
||||
*
|
||||
* @param key 键
|
||||
* @return
|
||||
*/
|
||||
public long sGetSetSize(String key) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().size(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除值为value的
|
||||
*
|
||||
* @param key 键
|
||||
* @param values 值 可以是多个
|
||||
* @return 移除的个数
|
||||
*/
|
||||
public long setRemove(String key, Object... values) {
|
||||
try {
|
||||
Long count = redisTemplate.opsForSet().remove(key, values);
|
||||
return count;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ===============================list=================================
|
||||
|
||||
/** ------------------------list相关操作---------------------------- */
|
||||
|
||||
/**
|
||||
* 通过索引获取列表中的元素
|
||||
*
|
||||
* @param key
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public Object lIndex(String key, long index) {
|
||||
return redisTemplate.opsForList().index(key, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表指定范围内的元素
|
||||
*
|
||||
* @param key
|
||||
* @param start 开始位置, 0是开始位置
|
||||
* @param end 结束位置, -1返回所有
|
||||
* @return
|
||||
*/
|
||||
public List<Object> lRange(String key, long start, long end) {
|
||||
return redisTemplate.opsForList().range(key, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储在list头部
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lLeftPush(String key, String value) {
|
||||
return redisTemplate.opsForList().leftPush(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lLeftPushAll(String key, String... value) {
|
||||
return redisTemplate.opsForList().leftPushAll(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lLeftPushAll(String key, Collection<String> value) {
|
||||
return redisTemplate.opsForList().leftPushAll(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当list存在的时候才加入
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lLeftPushIfPresent(String key, String value) {
|
||||
return redisTemplate.opsForList().leftPushIfPresent(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果pivot存在,再pivot前面添加
|
||||
*
|
||||
* @param key
|
||||
* @param pivot
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lLeftPush(String key, String pivot, String value) {
|
||||
return redisTemplate.opsForList().leftPush(key, pivot, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lRightPush(String key, String value) {
|
||||
return redisTemplate.opsForList().rightPush(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lRightPushAll(String key, String... value) {
|
||||
return redisTemplate.opsForList().rightPushAll(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lRightPushAll(String key, Collection<String> value) {
|
||||
return redisTemplate.opsForList().rightPushAll(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为已存在的列表添加值
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lRightPushIfPresent(String key, String value) {
|
||||
return redisTemplate.opsForList().rightPushIfPresent(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在pivot元素的右边添加值
|
||||
*
|
||||
* @param key
|
||||
* @param pivot
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lRightPush(String key, String pivot, String value) {
|
||||
return redisTemplate.opsForList().rightPush(key, pivot, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过索引设置列表元素的值
|
||||
*
|
||||
* @param key
|
||||
* @param index 位置
|
||||
* @param value
|
||||
*/
|
||||
public void lSet(String key, long index, String value) {
|
||||
redisTemplate.opsForList().set(key, index, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出并获取列表的第一个元素
|
||||
*
|
||||
* @param key
|
||||
* @return 删除的元素
|
||||
*/
|
||||
public Object lLeftPop(String key) {
|
||||
return redisTemplate.opsForList().leftPop(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出并获取列表的第一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
|
||||
*
|
||||
* @param key
|
||||
* @param timeout 等待时间
|
||||
* @param unit 时间单位
|
||||
* @return
|
||||
*/
|
||||
public Object lBLeftPop(String key, long timeout, TimeUnit unit) {
|
||||
return redisTemplate.opsForList().leftPop(key, timeout, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除并获取列表最后一个元素
|
||||
*
|
||||
* @param key
|
||||
* @return 删除的元素
|
||||
*/
|
||||
public Object lRightPop(String key) {
|
||||
return redisTemplate.opsForList().rightPop(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出并获取列表的最后一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
|
||||
*
|
||||
* @param key
|
||||
* @param timeout 等待时间
|
||||
* @param unit 时间单位
|
||||
* @return
|
||||
*/
|
||||
public Object lBRightPop(String key, long timeout, TimeUnit unit) {
|
||||
return redisTemplate.opsForList().rightPop(key, timeout, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除列表的最后一个元素,并将该元素添加到另一个列表并返回
|
||||
*
|
||||
* @param sourceKey
|
||||
* @param destinationKey
|
||||
* @return
|
||||
*/
|
||||
public Object lRightPopAndLeftPush(String sourceKey, String destinationKey) {
|
||||
return redisTemplate.opsForList().rightPopAndLeftPush(sourceKey, destinationKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从列表中弹出一个值,将弹出的元素插入到另外一个列表中并返回它; 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
|
||||
*
|
||||
* @param sourceKey
|
||||
* @param destinationKey
|
||||
* @param timeout
|
||||
* @param unit
|
||||
* @return
|
||||
*/
|
||||
public Object lBRightPopAndLeftPush(String sourceKey, String destinationKey, long timeout, TimeUnit unit) {
|
||||
return redisTemplate.opsForList().rightPopAndLeftPush(sourceKey, destinationKey, timeout, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除集合中值等于value得元素
|
||||
*
|
||||
* @param key
|
||||
* @param index index=0, 删除所有值等于value的元素; index>0, 从头部开始删除第一个值等于value的元素;
|
||||
* index<0, 从尾部开始删除第一个值等于value的元素;
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Long lRemove(String key, long index, String value) {
|
||||
return redisTemplate.opsForList().remove(key, index, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 裁剪list
|
||||
*
|
||||
* @param key
|
||||
* @param start
|
||||
* @param end
|
||||
*/
|
||||
public void lTrim(String key, long start, long end) {
|
||||
redisTemplate.opsForList().trim(key, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表长度
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public Long lLen(String key) {
|
||||
return redisTemplate.opsForList().size(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加锁方法
|
||||
*
|
||||
* @param lockKey 锁的键
|
||||
* @param value 锁的值(通常为唯一标识,如时间戳或UUID)
|
||||
* @param expireMs 锁的过期时间(毫秒)
|
||||
* @return true 加锁成功 false 加锁失败
|
||||
*/
|
||||
public boolean lock(String lockKey, String value, long expireMs) {
|
||||
try {
|
||||
Boolean result = redisTemplate.opsForValue().setIfAbsent(lockKey, value, expireMs, TimeUnit.MILLISECONDS);
|
||||
return Boolean.TRUE.equals(result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁方法
|
||||
*
|
||||
* @param lockKey 锁的键
|
||||
* @param value 锁的值(用于校验是否为当前持有锁的客户端)
|
||||
* @return true 解锁成功 false 解锁失败
|
||||
*/
|
||||
public boolean unlock(String lockKey, String value) {
|
||||
try {
|
||||
String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
|
||||
Object result = redisTemplate.execute(new DefaultRedisScript<>(script, Long.class), Collections.singletonList(lockKey), value);
|
||||
return result != null && (Long) result == 1L;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package com.netsdk.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ghgande.j2mod.modbus.procimg.SimpleDigitalIn;
|
||||
import com.ghgande.j2mod.modbus.procimg.SimpleInputRegister;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
@Component
|
||||
public class SyncGlScheduledTasks {
|
||||
// 开关量
|
||||
// public static final Map<String, SimpleDigitalIn> SIMPLE_DIGITAL_INMAP = new LinkedHashMap<>(16);
|
||||
public static final Map<String, SimpleInputRegister> SIMPLE_DIGITAL_INMAP_2 = new LinkedHashMap<>(16);
|
||||
public static final Map<Integer, String> MQ_ORDER_MAP = new LinkedHashMap<>(16);
|
||||
// 模拟量
|
||||
// public static final Map<String, SimpleInputRegister> SIMPLE_INPUT_REGISTER_MAP = new LinkedHashMap<>(16);
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
// 每五秒执行一次
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
@Async
|
||||
public void taskWithFixedDelay() {
|
||||
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("GL_LIST"));
|
||||
JSONArray zLobjects = JSONObject.parseArray((String) redisUtil.get("ZL_LIST"));
|
||||
JSONArray lFobjects = JSONObject.parseArray((String) redisUtil.get("JL_LIST"));
|
||||
JSONArray mQobjects = JSONObject.parseArray((String) redisUtil.get("MQ_LIST"));
|
||||
objects.addAll(zLobjects);
|
||||
objects.addAll(lFobjects);
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
JSONObject jsonObject = objects.getJSONObject(i);
|
||||
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
|
||||
|
||||
if ("1".equals(jsonObject.getString("SIGNAL_TYPE"))) {
|
||||
// 模拟量
|
||||
SimpleInputRegister simpleInputRegister_hig = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "hig");
|
||||
SimpleInputRegister simpleInputRegister_low = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "low");
|
||||
if (simpleInputRegister_hig != null) {
|
||||
int bits = Float.floatToIntBits(intValue);
|
||||
simpleInputRegister_hig.setValue((bits >> 16) & 0xFFFF);
|
||||
simpleInputRegister_low.setValue(bits & 0xFFFF);
|
||||
}
|
||||
} else {
|
||||
SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
|
||||
SimpleInputRegister simpleInputRegister1 = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID")+"_1");
|
||||
if (simpleInputRegister1 != null) {
|
||||
simpleInputRegister1.setValue((int) intValue);
|
||||
}
|
||||
if (simpleInputRegister == null) continue;
|
||||
// 开关量
|
||||
simpleInputRegister.setValue((int) intValue);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mQobjects.size(); i++) {
|
||||
JSONObject jsonObject = mQobjects.getJSONObject(i);
|
||||
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
|
||||
SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
|
||||
if (simpleInputRegister == null) continue;
|
||||
// 开关量
|
||||
simpleInputRegister.setValue((int) intValue);
|
||||
}
|
||||
|
||||
}
|
||||
// @Scheduled(fixedDelay = 5000)
|
||||
// @Async
|
||||
// public void taskWithZlFixedDelay() {
|
||||
// JSONArray objects = JSONObject.parseArray((String) redisUtil.get("ZL_LIST"));
|
||||
// System.out.println("更新转炉炉数据:"+DateUtil.date2Str(new Date()));
|
||||
// for (int i = 0; i < objects.size(); i++) {
|
||||
// JSONObject jsonObject = objects.getJSONObject(i);
|
||||
// double intValue = jsonObject.getDouble("CURRENT_VALUE");
|
||||
// if ("2".equals(jsonObject.getString("SIGNAL_TYPE"))) {
|
||||
// // 开关量
|
||||
// SimpleDigitalIn simpleDigitalIn = SIMPLE_DIGITAL_INMAP.get(jsonObject.getString("IPCDEVICE_ID"));
|
||||
// if (simpleDigitalIn != null) {
|
||||
// SIMPLE_DIGITAL_INMAP.get(jsonObject.getString("IPCDEVICE_ID")).set((int) intValue == 1);
|
||||
// }
|
||||
// } else {
|
||||
// SimpleInputRegister simpleInputRegister = SIMPLE_INPUT_REGISTER_MAP.get(jsonObject.getString("IPCDEVICE_ID"));
|
||||
// if (simpleInputRegister != null) {
|
||||
// SIMPLE_INPUT_REGISTER_MAP.get(jsonObject.getString("IPCDEVICE_ID")).setValue((int) intValue);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
server:
|
||||
port: 19393
|
||||
spring:
|
||||
application:
|
||||
name: integrated_yjb_dataDocking
|
||||
datasource:
|
||||
driver-class-name: org.postgresql.Driver
|
||||
url: jdbc:postgresql://10.199.64.30:15431/postgres?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=UTC
|
||||
password: rT)?DjIGYM8k0h!
|
||||
username: postgres
|
||||
redis:
|
||||
host: 10.199.64.30
|
||||
password: 5.5pYdZqHxpR#9%W.
|
||||
database: 1
|
||||
port: 16379
|
||||
modbus:
|
||||
port: 18888
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD SQL Map Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
|
||||
<typeAliases>
|
||||
<typeAlias type="com.netsdk.entity.PageData" alias="pd"/>
|
||||
|
||||
<!-- 这里添加实体类 -->
|
||||
|
||||
</typeAliases>
|
||||
</configuration>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.netsdk.mapper.datasource.other.OtherMapper">
|
||||
|
||||
<select id="getAllMqOrderList" resultType="java.util.HashMap">
|
||||
select *
|
||||
from mq_docking
|
||||
where ISDELETE = 0
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue