数采业务代码开发v1

master
ccongli 1 year ago
parent 0d46b18c5c
commit 5d6dd5dbef

@ -38,13 +38,20 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- COM串口通讯 --> <!-- 232 485 COM串口通讯 -->
<dependency> <dependency>
<groupId>com.fazecast</groupId> <groupId>com.fazecast</groupId>
<artifactId>jSerialComm</artifactId> <artifactId>jSerialComm</artifactId>
<version>[2.0.0,3.0.0)</version> <version>[2.0.0,3.0.0)</version>
</dependency> </dependency>
<!-- Modbus TCP 以太网通讯 -->
<dependency>
<groupId>com.infiniteautomation</groupId>
<artifactId>modbus4j</artifactId>
<version>3.1.0</version>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
@ -62,8 +69,14 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<!-- redis缓存 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
@ -108,4 +121,31 @@
</plugins> </plugins>
</build> </build>
<!-- 若想引用modbus4j需要引入下列repository id:ias-snapshots id:ias-releases 两个,使用默认仓库下载,不要使用阿里云仓库-->
<repositories>
<repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>ias-snapshots</id>
<name>Infinite Automation Snapshot Repository</name>
<url>https://maven.mangoautomation.net/repository/ias-snapshot/</url>
</repository>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>ias-releases</id>
<name>Infinite Automation Release Repository</name>
<url>https://maven.mangoautomation.net/repository/ias-release/</url>
</repository>
</repositories>
</project> </project>

@ -2,14 +2,19 @@ package org.cjyx.chankosc.common;
import com.fazecast.jSerialComm.SerialPort; import com.fazecast.jSerialComm.SerialPort;
import com.fazecast.jSerialComm.SerialPortDataListener; import com.fazecast.jSerialComm.SerialPortDataListener;
import org.cjyx.chankosc.entity.ChConfig;
import org.cjyx.chankosc.utils.Rs485DataListener; import org.cjyx.chankosc.utils.Rs485DataListener;
import org.cjyx.chankosc.utils.Rs485Handler; import org.cjyx.chankosc.utils.Rs485Handler;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import java.util.Map;
@Component @Component
public class ComRunner implements ApplicationRunner { public class ComRunner implements ApplicationRunner {
@ -24,7 +29,17 @@ public class ComRunner implements ApplicationRunner {
// private Rs485Handler handler2; // private Rs485Handler handler2;
@Autowired @Autowired
SerialPortDataListener dataListener; private SerialPortDataListener dataListener;
@Autowired
private Map<String, ChConfig> deviceConfigs;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private HashOperations<String, String, Object> hashOperations;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
@ -35,8 +50,25 @@ public class ComRunner implements ApplicationRunner {
handler.openPort(); handler.openPort();
// handler.listen(new Rs485DataListener(handler)); // handler.listen(new Rs485DataListener(handler));
handler.listen(dataListener); handler.listen(dataListener);
this.loadConfigs();
} }
private void loadConfigs() {
redisTemplate.delete("sc0");
redisTemplate.delete("sc1");
redisTemplate.delete("sc2");
redisTemplate.delete("sc3");
for(Map.Entry<String, ChConfig> entry : deviceConfigs.entrySet()) {
ChConfig config = entry.getValue();
String key = "sc" + config.getAddrNo();
hashOperations.put(key, config.getChannel(), config.getDefData());
}
System.out.println("Redis配置初始化完成。。。");
}
@PreDestroy @PreDestroy
public void stop() { public void stop() {
System.out.println("服务关闭,执行清理操作..."); System.out.println("服务关闭,执行清理操作...");

@ -1,6 +1,7 @@
package org.cjyx.chankosc.common; package org.cjyx.chankosc.common;
import com.fazecast.jSerialComm.SerialPort; import com.fazecast.jSerialComm.SerialPort;
import com.sun.istack.internal.NotNull;
import org.cjyx.chankosc.utils.Rs485DataListener; import org.cjyx.chankosc.utils.Rs485DataListener;
import org.cjyx.chankosc.utils.Rs485Handler; import org.cjyx.chankosc.utils.Rs485Handler;
@ -10,15 +11,48 @@ import java.util.List;
public class ComTest { public class ComTest {
public static void main(String[] args) { public static void main(String[] args) {
SerialPort com3 = SerialPort.getCommPort("COM3"); // SerialPort com3 = SerialPort.getCommPort("COM3");
Rs485Handler handler = new Rs485Handler(); // Rs485Handler handler = new Rs485Handler();
handler.setSerialPort(com3); // handler.setSerialPort(com3);
handler.openPort(); // handler.openPort();
handler.listen(new Rs485DataListener(handler)); // handler.listen(new Rs485DataListener(handler));
// handler.closePort(); // handler.closePort();
// byte[] bytes = new byte[]{126, 0, 5, 0, 0, 5, 0, 126, 126, 1, 0, 1, 0, 2, 0, 126, 126, 0, 5, 0, 0, 5, 0, 126, 126, 1, 0, 1, 0, 2, 0, 126, 126, 0, 5, 0, 0, 5, 2, 0, 126, 126, 1, 0, 1, 0, 2, 0, 126, 126, 0, 5, 0, 0, 5, 0, 1,126}; byte[] bytes = new byte[]{
// DataParser parser = new DataParser(); 126, 0, 96, 98, 8, -54, 0, 126,
// parser.parseData(bytes); 126, 1, -125, 47, 0, -77, 0, 126,
126, 2, 23, 124, 88, -19, 0, 126,
126, 3, 0, -112, 0, -109, 0, 126
};
DataParser parser = new DataParser();
parser.parseData(bytes);
}
/*
* bytebit
* @description:
* 1Byte=8bits
* @date: 2022/4/1 10:43
* @param: b
* @return: java.lang.String 801
*/
public static String fromByte(byte b) {
return "" + (byte) ((b >> 7) & 0x1) +
(byte) ((b >> 6) & 0x1) +
(byte) ((b >> 5) & 0x1) +
(byte) ((b >> 4) & 0x1) +
(byte) ((b >> 3) & 0x1) +
(byte) ((b >> 2) & 0x1) +
(byte) ((b >> 1) & 0x1) +
(byte) ((b) & 0x1);
}
public static String formatBinary(byte b) {
StringBuilder sb = new StringBuilder();
for(int i = 7; i >=0; i--) {
sb.append((byte) ((b >> i) & 0x1));
}
return sb.toString();
} }
} }

@ -91,13 +91,18 @@ public class DataParser {
return address + ch1_8 + ch9_16 + ch17_24; return address + ch1_8 + ch9_16 + ch17_24;
} }
/** /*
* * bytebit
* @description:
* 1Byte=8bits
*/ */
private static String formatBinary(int number) { public static String formatBinary(byte b) {
String binary = String.format("%8s", Integer.toBinaryString(number)).replace(' ','0'); StringBuilder sb = new StringBuilder();
for(int i = 7; i >=0; i--) {
sb.append((byte) ((b >> i) & 0x1));
}
// 小端模式(低字节在前、高字节在后) // 小端模式(低字节在前、高字节在后)
return new StringBuilder(binary).reverse().toString(); return sb.reverse().toString();
} }

@ -0,0 +1,68 @@
package org.cjyx.chankosc.config;
import org.cjyx.chankosc.entity.ChConfig;
import org.cjyx.chankosc.service.chconfig.IChConfigService;
import org.springframework.beans.factory.annotation.Autowired;
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.*;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Configuration
public class BeanConfiguration {
/**
*
*/
@Bean
public Map<String, ChConfig> deviceConfigs(IChConfigService chConfigService) {
List<ChConfig> configs = chConfigService.list();
Map<String, ChConfig> configMap = configs.stream().collect(
Collectors.toMap(c -> (c.getAddrNo() + "-" + c.getChannel()), v -> v, (k1, k2) -> k1));
return configMap;
}
/**
* Redis
*/
@Autowired
private RedisConnectionFactory factory;
@Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setConnectionFactory(factory);
return redisTemplate;
}
@Bean
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForHash();
}
@Bean
public ValueOperations<String, String> valueOperations(RedisTemplate<String, String> redisTemplate) {
return redisTemplate.opsForValue();
}
@Bean
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForList();
}
@Bean
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForZSet();
}
}

@ -1,16 +0,0 @@
package org.cjyx.chankosc.config;
import org.cjyx.chankosc.utils.Rs485DataListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class createBeanConfiguration {
// @Bean
// public Rs485DataListener dataListener() {
// return new Rs485DataListener();
// }
}

@ -0,0 +1,30 @@
package org.cjyx.chankosc.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("config")
public class ChConfig {
@TableId(type = IdType.AUTO)
private Integer id;
@TableField("addrno")
private String addrNo; // 地址编号
private String channel; // 通道编号
@TableField("defdata")
private String defData; // 初始默认值
private int status; // 状态
@TableField("pointno")
private int pointNo; // 展台点位编号
private String comment;
}

@ -0,0 +1,9 @@
package org.cjyx.chankosc.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.cjyx.chankosc.entity.ChConfig;
@Mapper
public interface ChConfigMapper extends BaseMapper<ChConfig> {
}

@ -0,0 +1,10 @@
package org.cjyx.chankosc.service.chconfig;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.cjyx.chankosc.entity.ChConfig;
import org.cjyx.chankosc.mapper.ChConfigMapper;
import org.springframework.stereotype.Service;
@Service
public class ChConfigServiceImpl extends ServiceImpl<ChConfigMapper, ChConfig> implements IChConfigService {
}

@ -0,0 +1,7 @@
package org.cjyx.chankosc.service.chconfig;
import com.baomidou.mybatisplus.extension.service.IService;
import org.cjyx.chankosc.entity.ChConfig;
public interface IChConfigService extends IService<ChConfig> {
}

@ -1,4 +1,4 @@
package org.cjyx.chankosc.service; package org.cjyx.chankosc.service.chdevice;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.cjyx.chankosc.entity.ChDevice; import org.cjyx.chankosc.entity.ChDevice;

@ -1,4 +1,4 @@
package org.cjyx.chankosc.service; package org.cjyx.chankosc.service.chdevice;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.cjyx.chankosc.entity.ChDevice; import org.cjyx.chankosc.entity.ChDevice;

@ -0,0 +1,217 @@
package org.cjyx.chankosc.utils;
import com.serotonin.modbus4j.BatchRead;
import com.serotonin.modbus4j.BatchResults;
import com.serotonin.modbus4j.ModbusFactory;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.code.DataType;
import com.serotonin.modbus4j.exception.ErrorResponseException;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.serotonin.modbus4j.ip.IpParameters;
import com.serotonin.modbus4j.locator.BaseLocator;
/**
* modbus,modbus4j
*
* @author lxq
* @dependencies modbus4j-3.0.3.jar
* @website https://github.com/infiniteautomation/modbus4j
*/
public class Modbus4jUtils {
/**
*
*/
static ModbusFactory modbusFactory;
static {
if (modbusFactory == null) {
modbusFactory = new ModbusFactory();
}
}
/**
* master
*
* @return
* @throws ModbusInitException
*/
public static ModbusMaster getMaster() throws ModbusInitException {
IpParameters params = new IpParameters();
params.setHost("localhost");
params.setPort(502);
// modbusFactory.createRtuMaster(wapper); //RTU 协议
// modbusFactory.createUdpMaster(params);//UDP 协议
// modbusFactory.createAsciiMaster(wrapper);//ASCII 协议
ModbusMaster master = modbusFactory.createTcpMaster(params, false);// TCP 协议
master.init();
return master;
}
/**
* [01 Coil Status 0x]
*
* @param slaveId
* slaveId
* @param offset
*
* @return
* @throws ModbusTransportException
*
* @throws ErrorResponseException
*
* @throws ModbusInitException
*
*/
public static Boolean readCoilStatus(int slaveId, int offset)
throws ModbusTransportException, ErrorResponseException, ModbusInitException {
// 01 Coil Status
BaseLocator<Boolean> loc = BaseLocator.coilStatus(slaveId, offset);
Boolean value = getMaster().getValue(loc);
return value;
}
/**
* [02 Input Status 1x]
*
* @param slaveId
* @param offset
* @return
* @throws ModbusTransportException
* @throws ErrorResponseException
* @throws ModbusInitException
*/
public static Boolean readInputStatus(int slaveId, int offset)
throws ModbusTransportException, ErrorResponseException, ModbusInitException {
// 02 Input Status
BaseLocator<Boolean> loc = BaseLocator.inputStatus(slaveId, offset);
Boolean value = getMaster().getValue(loc);
return value;
}
/**
* [03 Holding Register 2x]
*
* @param slaveId
* slave Id
* @param offset
*
* @param dataType
* ,com.serotonin.modbus4j.code.DataType
* @return
* @throws ModbusTransportException
*
* @throws ErrorResponseException
*
* @throws ModbusInitException
*
*/
public static Number readHoldingRegister(int slaveId, int offset, int dataType)
throws ModbusTransportException, ErrorResponseException, ModbusInitException {
// 03 Holding Register类型数据读取
BaseLocator<Number> loc = BaseLocator.holdingRegister(slaveId, offset, dataType);
Number value = getMaster().getValue(loc);
return value;
}
/**
* [04 Input Registers 3x]
*
* @param slaveId
* slaveId
* @param offset
*
* @param dataType
* ,com.serotonin.modbus4j.code.DataType
* @return
* @throws ModbusTransportException
*
* @throws ErrorResponseException
*
* @throws ModbusInitException
*
*/
public static Number readInputRegisters(int slaveId, int offset, int dataType)
throws ModbusTransportException, ErrorResponseException, ModbusInitException {
// 04 Input Registers类型数据读取
BaseLocator<Number> loc = BaseLocator.inputRegister(slaveId, offset, dataType);
Number value = getMaster().getValue(loc);
return value;
}
/**
* 使
*
* @throws ModbusTransportException
* @throws ErrorResponseException
* @throws ModbusInitException
*/
public static void batchRead() throws ModbusTransportException, ErrorResponseException, ModbusInitException {
BatchRead<Integer> batch = new BatchRead<Integer>();
batch.addLocator(0, BaseLocator.holdingRegister(1, 1, DataType.FOUR_BYTE_FLOAT));
batch.addLocator(1, BaseLocator.inputStatus(1, 0));
ModbusMaster master = getMaster();
batch.setContiguousRequests(false);
BatchResults<Integer> results = master.send(batch);
System.out.println(results.getValue(0));
System.out.println(results.getValue(1));
}
/**
*
*
* @param args
*/
public static void main(String[] args) {
try {
// 01 读输出线圈
// Boolean x00001 = readCoilStatus(1, 0);
// Boolean x00003 = readCoilStatus(1, 2);
// Boolean x00007 = readCoilStatus(1, 6);
// System.out.println("0x0001:" + x00001);
// System.out.println("0x0003:" + x00003);
// System.out.println("0x0007:" + x00007);
//
// // 02 读输入线圈
// Boolean x10001 = readInputStatus(1, 0);
// Boolean x10003 = readInputStatus(1, 2);
// Boolean x10007 = readInputStatus(1, 6);
// System.out.println("1x0001:" + x10001);
// System.out.println("1x0003:" + x10003);
// System.out.println("1x0007:" + x10007);
//
// // 03 读保持寄存器
// Number x40002 = readHoldingRegister(1, 1, DataType.FOUR_BYTE_INT_SIGNED);
// Number x40005 = readHoldingRegister(1, 4, DataType.EIGHT_BYTE_INT_SIGNED);
// Number x40010 = readHoldingRegister(1, 9, DataType.TWO_BYTE_INT_SIGNED);
// System.out.println("4x0002:" + x40002);
// System.out.println("4x0005:" + x40005);
// System.out.println("4x0010:" + x40010);
//
// // 04 读输入寄存器
// Number x30001 = readInputRegisters(1, 0, DataType.EIGHT_BYTE_FLOAT);
// Number x30005 = readInputRegisters(1, 4, DataType.TWO_BYTE_INT_UNSIGNED);
// Number x30006 = readInputRegisters(1, 5, DataType.TWO_BYTE_INT_SIGNED);
// Number x30008 = readInputRegisters(1, 7, DataType.FOUR_BYTE_FLOAT);
// System.out.println("x30001:" + x30001);
// System.out.println("x30005:" + x30005);
// System.out.println("x30006:" + x30006);
// System.out.println("x30008:" + x30008);
// 读二进制位
Number xl30001 = readInputRegisters(1, 0, DataType.EIGHT_BYTE_FLOAT);
System.out.println("xl30001: " + xl30001);
// // 批量读取
// batchRead();
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -5,8 +5,9 @@ import com.fazecast.jSerialComm.SerialPortDataListener;
import com.fazecast.jSerialComm.SerialPortEvent; import com.fazecast.jSerialComm.SerialPortEvent;
import org.cjyx.chankosc.common.DataParser; import org.cjyx.chankosc.common.DataParser;
import org.cjyx.chankosc.entity.ChDevice; import org.cjyx.chankosc.entity.ChDevice;
import org.cjyx.chankosc.service.IChDeviceService; import org.cjyx.chankosc.service.chdevice.IChDeviceService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Collections; import java.util.Collections;
@ -27,6 +28,9 @@ public class Rs485DataListener implements SerialPortDataListener {
@Autowired @Autowired
private IChDeviceService chDeviceService; private IChDeviceService chDeviceService;
@Autowired
private HashOperations<String,String,Object> hashOperations;
// 注册要监听的事件类型 // 注册要监听的事件类型
@Override @Override
public int getListeningEvents() { public int getListeningEvents() {
@ -52,7 +56,15 @@ public class Rs485DataListener implements SerialPortDataListener {
byte[] AllBytes = handler.readData(); byte[] AllBytes = handler.readData();
List<ChDevice> chDevices = DataParser.parseData(AllBytes); List<ChDevice> chDevices = DataParser.parseData(AllBytes);
Collections.reverse(chDevices); Collections.reverse(chDevices);
// mysql
chDeviceService.saveBatch(chDevices); chDeviceService.saveBatch(chDevices);
// redis
for(ChDevice chdevice : chDevices) {
String addrNo = "sc" + chdevice.getAddress();
String channel = chdevice.getChannel();
String data = chdevice.getData();
hashOperations.put(addrNo, channel, data);
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -9,6 +9,16 @@ spring:
password: 123456 password: 123456
url: jdbc:mysql://localhost:3306/chankosc?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/chankosc?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
redis:
host: localhost
port: 6379
client-type: lettuce
timeout: 20000
lettuce:
max-idle: 6 #最大空闲数
max-active: 10 #最大连接数
min-idle: 2 #最小空闲数
# mybatis-plus配置 # mybatis-plus配置
mybatis-plus: mybatis-plus:

@ -1,10 +1,20 @@
package org.cjyx.chankosc; package org.cjyx.chankosc;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.cjyx.chankosc.entity.ChConfig;
import org.cjyx.chankosc.entity.ChDevice; import org.cjyx.chankosc.entity.ChDevice;
import org.cjyx.chankosc.service.IChDeviceService; import org.cjyx.chankosc.service.chconfig.IChConfigService;
import org.cjyx.chankosc.service.chdevice.IChDeviceService;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import java.sql.Wrapper;
import java.util.List;
import java.util.Map;
@SpringBootTest @SpringBootTest
class ChankoScApplicationTests { class ChankoScApplicationTests {
@ -12,6 +22,12 @@ class ChankoScApplicationTests {
@Autowired @Autowired
private IChDeviceService chDeviceService; private IChDeviceService chDeviceService;
@Autowired
private IChConfigService chConfigService;
@Autowired
RedisTemplate redisTemplate;
@Test @Test
void contextLoads() { void contextLoads() {
ChDevice chDevice = new ChDevice(); ChDevice chDevice = new ChDevice();
@ -22,4 +38,40 @@ class ChankoScApplicationTests {
chDeviceService.save(chDevice); chDeviceService.save(chDevice);
} }
@Autowired
private ValueOperations<String, String> valueOperations;
@Test
void test01() {
// ValueOperations vps = redisTemplate.opsForValue();
// vps.set("testKey", "testValue");
// String str = (String) vps.get("testKey");
valueOperations.set("sss","123456");
String str = valueOperations.get("sss");
System.out.println(str);
}
@Test
void test02 () {
HashOperations hps = redisTemplate.opsForHash();
hps.put("testKeyH", "testField", "testValue");
String str = (String) hps.get("testKeyH", "testField");
System.out.println(str);
}
@Autowired
private Map<String, ChConfig> deviceConfigs;
@Test
void test03() {
// List<ChConfig> configs = chConfigService.list();
// QueryWrapper<ChConfig> wrapper = new QueryWrapper<>();
// wrapper.eq("status",3);
// List<ChConfig> configs = chConfigService.list(wrapper);
// System.out.println(configs);
System.out.println(deviceConfigs);
}
} }

Loading…
Cancel
Save