设备数据配置

This commit is contained in:
tiger_zhou 2023-08-21 15:35:54 +08:00
parent 72bd54c723
commit 21623b8976
14 changed files with 488 additions and 8 deletions

View File

@ -0,0 +1,71 @@
package club.joylink.xiannccda.controller;
import club.joylink.xiannccda.dto.AlertRecordQueryDTO;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigQueryDto;
import club.joylink.xiannccda.entity.AlertRecord;
import club.joylink.xiannccda.entity.DeviceGuardConfig;
import club.joylink.xiannccda.repository.IDeviceGuardConfigRepository;
import club.joylink.xiannccda.service.DeviceGuardConfigService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "设备保护配置接口")
@RestController
@RequestMapping("/api/config/device")
public class DeviceGuardConfigController {
@Autowired
private IDeviceGuardConfigRepository iDeviceGuardConfigRepository;
@Autowired
private DeviceGuardConfigService configService;
@SecurityRequirement(name = "jwt")
@Operation(summary = "initData")
@GetMapping("/initData/{lineId}")
public List<DeviceGuardConfig> initData(@PathVariable("lineId") Integer lineId) {
LambdaQueryWrapper<DeviceGuardConfig> qw = Wrappers.lambdaQuery(DeviceGuardConfig.class).eq(DeviceGuardConfig::getConfigType, DeviceGuardConfig.CONFIG_TYPE_INIT);
qw.eq(DeviceGuardConfig::getLineId, lineId);
return this.iDeviceGuardConfigRepository.list(qw);
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "initData")
@GetMapping("/initData/{lineId}/{dt}")
public List<DeviceGuardConfig> initDataDeviceType(@PathVariable("lineId") Integer lineId, @PathVariable("dt") String dt) {
LambdaQueryWrapper<DeviceGuardConfig> qw = Wrappers.lambdaQuery(DeviceGuardConfig.class).eq(DeviceGuardConfig::getConfigType, DeviceGuardConfig.CONFIG_TYPE_INIT);
qw.eq(DeviceGuardConfig::getLineId, lineId).eq(DeviceGuardConfig::getDeviceType, dt);
return this.iDeviceGuardConfigRepository.list(qw);
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "保存修改")
@PostMapping("/save")
public String saveOrUpdate(@RequestBody DeviceGuardConfigDto dto) {
this.configService.saveOrUpdate(dto);
return "ok";
}
@GetMapping("/page")
@SecurityRequirement(name = "jwt")
@Operation(summary = "分页查询报警记录")
@ApiResponse(description = "报警记录")
public Page<DeviceGuardConfig> pageQuery(DeviceGuardConfigQueryDto queryDTO) {
return configService.page(queryDTO);
}
}

View File

@ -0,0 +1,37 @@
package club.joylink.xiannccda.dto.config;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.service.config.Operator;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(name = "设备保护参数配置")
public class DeviceGuardConfigDto {
private Long id;
@Schema(description = "线路id")
private Integer lineId;
@Schema(description = "名称")
private String name;
@Schema(description = "设备类型")
private DeviceType deviceType;
@Schema(description = "设备保护类型")
private GuardUnit guardUnit;
@Schema(description = "操作方式")
private Operator operator;
@Schema(description = "设备配置类型")
private ConfigDeviceType configDeviceType;
@Schema(description = "")
private Integer val;
public enum GuardUnit {
NUMS, TIMES
}
public enum ConfigDeviceType {
SWITCH_LOST, SWITCH_LOST_MOST, AXLE_LED_RED_MOST
}
}

View File

@ -0,0 +1,17 @@
package club.joylink.xiannccda.dto.config;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.entity.DeviceGuardConfig;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class DeviceGuardConfigQueryDto extends PageDTO<DeviceGuardConfig> {
@Schema(description = "线路id")
private Integer lineId;
@Schema(description = "设备类型")
private DeviceType deviceType;
}

View File

@ -0,0 +1,69 @@
package club.joylink.xiannccda.entity;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.ConfigDeviceType;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.GuardUnit;
import club.joylink.xiannccda.service.config.Operator;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author walker-sheng
* @since 2023-08-21
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("device_guard_config")
@Schema(name = "DeviceGuardConfig", description = "$!{table.comment}")
public class DeviceGuardConfig {
public static final Integer CONFIG_TYPE_INIT = 0;
public static final Integer CONFIG_TYPE_USER = 1;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private Integer lineId;
private String configName;
@Schema(description = "0=初始化1=用户自定义")
private Integer configType;
private DeviceType deviceType;
private Operator deviceOperator;
private GuardUnit deviceUnit;
private ConfigDeviceType deviceConfigType;
private Integer val;
public static final String ID = "id";
public static final String LINE_ID = "line_id";
public static final String CONFIG_NAME = "config_name";
public static final String CONFIG_TYPE = "config_type";
public static final String DEVICE_TYPE = "device_type";
public static final String DEVICE_OPERATOR = "device_operator";
public static final String DEVICE_UNIT = "device_unit";
public static final String DEVICE_CONFIG_TYPE = "device_config_type";
public static final String VAL = "val";
}

View File

@ -0,0 +1,18 @@
package club.joylink.xiannccda.mapper;
import club.joylink.xiannccda.entity.DeviceGuardConfig;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author walker-sheng
* @since 2023-08-21
*/
@Mapper
public interface DeviceGuardConfigMapper extends BaseMapper<DeviceGuardConfig> {
}

View File

@ -0,0 +1,23 @@
<?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="club.joylink.xiannccda.mapper.DeviceGuardConfigMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="club.joylink.xiannccda.entity.DeviceGuardConfig">
<id column="id" property="id" />
<result column="line_id" property="lineId" />
<result column="config_name" property="configName" />
<result column="config_type" property="configType" />
<result column="device_type" property="deviceType" />
<result column="device_operator" property="deviceOperator" />
<result column="device_unit" property="deviceUnit" />
<result column="device_config_type" property="deviceConfigType" />
<result column="val" property="val" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, line_id, config_name, config_type, device_type, device_operator, device_unit, device_config_type, val
</sql>
</mapper>

View File

@ -57,15 +57,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/mock")
//@RestController
//@RequestMapping("/mock")
@Tag(name = "mock")
public class MockDeviceController {
@Autowired
// @Autowired
private NccMockDataService mockDataService;
@Autowired
// @Autowired
private OccMessageManage occMessageManage;
@Operation(summary = "train阻塞状态设置变更")

View File

@ -28,7 +28,7 @@ public class MockLoadData implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
this.nccMockDataService.reset(10);
this.nccMockDataService.reset(3);
CIRCLE_QUERY_THREAD.scheduleAtFixedRate(() -> {
// this.nccMockDataService.skip(170L, 1100L, 1180L);
loadData();
@ -39,9 +39,10 @@ public class MockLoadData implements ApplicationRunner {
try {
Wrapper<NccMockData> wrapper = Wrappers.<NccMockData>lambdaQuery()
// .in(NccMockData::getMsgId, List.of("DEVICE_STATUS_BITMAP", "TRAIN_INDICATION_INIT", "TRAIN_INDICATION_UPDATE", "TRAIN_INDICATION_REMOVE"))
.eq(NccMockData::getMsgId, "DEVICE_STATUS_BITMAP")
// .gt(NccMockData::getMockReceiveTime, "2023-08-06 07:00:20")
// .eq(NccMockData::getMsgId, "DEVICE_STATUS_BITMAP")
.gt(NccMockData::getMockReceiveTime, "2023-08-06 12:20:20")
// .gt(NccMockData::getId, 2598023)
.gt(NccMockData::getId, 2933958)
// .ne(NccMockData::getIsDelete, 1)
.orderBy(true, true, NccMockData::getId);
List<MessageResponse> dataList = this.nccMockDataService.loadALLData(wrapper);

View File

@ -0,0 +1,16 @@
package club.joylink.xiannccda.repository;
import club.joylink.xiannccda.entity.DeviceGuardConfig;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 服务类
* </p>
*
* @author walker-sheng
* @since 2023-08-21
*/
public interface IDeviceGuardConfigRepository extends IService<DeviceGuardConfig> {
}

View File

@ -0,0 +1,20 @@
package club.joylink.xiannccda.repository.impl;
import club.joylink.xiannccda.entity.DeviceGuardConfig;
import club.joylink.xiannccda.mapper.DeviceGuardConfigMapper;
import club.joylink.xiannccda.repository.IDeviceGuardConfigRepository;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author walker-sheng
* @since 2023-08-21
*/
@Service
public class DeviceGuardConfigRepository extends ServiceImpl<DeviceGuardConfigMapper, DeviceGuardConfig> implements IDeviceGuardConfigRepository {
}

View File

@ -0,0 +1,69 @@
package club.joylink.xiannccda.service;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigQueryDto;
import club.joylink.xiannccda.entity.DeviceGuardConfig;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import club.joylink.xiannccda.repository.IDeviceGuardConfigRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DeviceGuardConfigService {
@Autowired
private IDeviceGuardConfigRepository configRepository;
// private final static Cache<String, String> cache = CacheBuilder.newBuilder().expireAfterWrite(0, TimeUnit.SECONDS).build();
public void saveOrUpdate(DeviceGuardConfigDto dto) {
LambdaQueryWrapper<DeviceGuardConfig> qw = Wrappers.lambdaQuery(DeviceGuardConfig.class);
qw.eq(DeviceGuardConfig::getLineId, dto.getLineId())
.eq(DeviceGuardConfig::getDeviceType, dto.getDeviceType().name())
.eq(DeviceGuardConfig::getDeviceConfigType, dto.getConfigDeviceType());
DeviceGuardConfig dataConfig = this.convertDB(dto);
if (Objects.nonNull(dto.getId())) {
DeviceGuardConfig guardConfig = this.configRepository.getById(dto.getId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(guardConfig), "未找到对应的数据");
qw.ne(DeviceGuardConfig::getId, dto.getId());
dataConfig.setId(guardConfig.getId());
}
Long typeCounter = this.configRepository.count(qw);
BusinessExceptionAssertEnum.UNIQUE_FIELD_REPEAT.assertTrue(typeCounter <= 0L, "重复的数据类型");
this.configRepository.saveOrUpdate(dataConfig);
}
public Page<DeviceGuardConfig> page(DeviceGuardConfigQueryDto queryDTO) {
LambdaQueryWrapper<DeviceGuardConfig> queryWrapper = Wrappers.lambdaQuery(DeviceGuardConfig.class);
if (Objects.nonNull(queryDTO.getLineId())) {
queryWrapper.eq(DeviceGuardConfig::getLineId, queryDTO.getLineId());
}
if (Objects.nonNull(queryDTO.getDeviceType())) {
queryWrapper.eq(DeviceGuardConfig::getConfigType, queryDTO.getDeviceType().name());
}
return configRepository.page(queryDTO, queryWrapper);
}
private DeviceGuardConfig convertDB(DeviceGuardConfigDto dto) {
DeviceGuardConfig guardConfig = new DeviceGuardConfig();
guardConfig.setLineId(dto.getLineId());
guardConfig.setConfigName(dto.getName());
guardConfig.setConfigType(DeviceGuardConfig.CONFIG_TYPE_USER);
guardConfig.setDeviceType(dto.getDeviceType());
guardConfig.setDeviceOperator(dto.getOperator());
guardConfig.setDeviceUnit(dto.getGuardUnit());
guardConfig.setDeviceConfigType(dto.getConfigDeviceType());
guardConfig.setVal(dto.getVal());
return guardConfig;
}
}

View File

@ -0,0 +1,44 @@
package club.joylink.xiannccda.service.config;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.GuardUnit;
public enum Operator {
GT {
@Override
public boolean contrastTimes(GuardUnit unit, int source, int val) {
if (unit == GuardUnit.NUMS) {
return source > val;
} else if (unit == GuardUnit.TIMES) {
return (source + (val * 1000L)) > System.currentTimeMillis();
}
return false;
}
},
GE {
@Override
public boolean contrastTimes(GuardUnit unit, int source, int val) {
if (unit == GuardUnit.NUMS) {
return source >= val;
} else if (unit == GuardUnit.TIMES) {
return (source + (val * 1000L)) >= System.currentTimeMillis();
}
return false;
}
},
LT {
@Override
public boolean contrastTimes(GuardUnit unit, int source, int val) {
if (unit == GuardUnit.NUMS) {
return source < val;
} else if (unit == GuardUnit.TIMES) {
return (source + (val * 1000L)) < System.currentTimeMillis();
}
return false;
}
},
;
public abstract boolean contrastTimes(GuardUnit unit, int source, int val);
}

View File

@ -2,7 +2,7 @@ server:
port: 9081
spring:
profiles:
active: dev
active: local
banner:
location: classpath:banner.txt
datasource:

View File

@ -0,0 +1,95 @@
package club.joylink.xiannccda.config;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.ConfigDeviceType;
import club.joylink.xiannccda.dto.config.DeviceGuardConfigDto.GuardUnit;
import club.joylink.xiannccda.entity.DeviceGuardConfig;
import club.joylink.xiannccda.repository.IDeviceGuardConfigRepository;
import club.joylink.xiannccda.service.config.Operator;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter.Feature;
import com.google.common.collect.Lists;
import java.util.List;
import lombok.Data;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class DataConfigTest {
@Autowired
private IDeviceGuardConfigRepository iDeviceGuardConfigRepository;
@Test
public void test() {
InitData initData = new InitData();
initData.setDeviceType(DeviceType.DEVICE_TYPE_TRACK);
List<DeviceRef> refs = Lists.newArrayList();
refs.add(new DeviceRef(ConfigDeviceType.SWITCH_LOST, new Oper(Operator.LT, GuardUnit.TIMES)));
refs.add(new DeviceRef(ConfigDeviceType.SWITCH_LOST_MOST, new Oper(Operator.GE, GuardUnit.NUMS)));
initData.setRefs(refs);
System.out.println(JSON.toJSONString(initData, Feature.WriteEnumsUsingName));
DeviceGuardConfig guardConfig = new DeviceGuardConfig();
guardConfig.setLineId(3);
guardConfig.setDeviceType(DeviceType.DEVICE_TYPE_SWITCH);
guardConfig.setDeviceOperator(Operator.LT);
guardConfig.setDeviceUnit(GuardUnit.TIMES);
guardConfig.setDeviceConfigType(ConfigDeviceType.SWITCH_LOST);
guardConfig.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT);
DeviceGuardConfig guardConfig2 = new DeviceGuardConfig();
guardConfig2.setLineId(3);
guardConfig2.setDeviceType(DeviceType.DEVICE_TYPE_SWITCH);
guardConfig2.setDeviceOperator(Operator.GE);
guardConfig2.setDeviceUnit(GuardUnit.NUMS);
guardConfig2.setDeviceConfigType(ConfigDeviceType.SWITCH_LOST_MOST);
guardConfig2.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT);
DeviceGuardConfig guardConfig3 = new DeviceGuardConfig();
guardConfig3.setLineId(3);
guardConfig3.setDeviceType(DeviceType.DEVICE_TYPE_TRACK);
guardConfig3.setDeviceOperator(Operator.GE);
guardConfig3.setDeviceUnit(GuardUnit.NUMS);
guardConfig3.setDeviceConfigType(ConfigDeviceType.AXLE_LED_RED_MOST);
guardConfig3.setConfigType(DeviceGuardConfig.CONFIG_TYPE_INIT);
this.iDeviceGuardConfigRepository.save(guardConfig);
this.iDeviceGuardConfigRepository.save(guardConfig2);
this.iDeviceGuardConfigRepository.save(guardConfig3);
}
@Data
public static class InitData {
private DeviceType deviceType;
private List<DeviceRef> refs;
}
@Data
private static class DeviceRef {
public DeviceRef(ConfigDeviceType deviceConfig, Oper opers) {
this.deviceConfig = deviceConfig;
this.opers = opers;
}
private ConfigDeviceType deviceConfig;
private Oper opers;
}
@Data
private static class Oper {
public Oper(Operator operator, GuardUnit unit) {
this.operator = operator;
this.unit = unit;
}
private Operator operator;
private GuardUnit unit;
}
}