|
|
|
@ -41,163 +41,163 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
@Service
|
|
|
|
|
public class DeviceAreaConfigService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DeviceAreaConfigRepository deviceAreaConfigRepository;
|
|
|
|
|
@Autowired
|
|
|
|
|
private DeviceAreaConfigRepository deviceAreaConfigRepository;
|
|
|
|
|
|
|
|
|
|
private final static Cache<Integer, Map<AlertDeviceType, List<AreaConfigVO>>> AREA_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(2 * 60, TimeUnit.MINUTES).build();
|
|
|
|
|
private final static Cache<Integer, Map<AlertDeviceType, List<AreaConfigVO>>> AREA_CONFIG_CACHE = CacheBuilder.newBuilder().expireAfterWrite(5 * 60, TimeUnit.MINUTES).build();
|
|
|
|
|
|
|
|
|
|
public List<AreaConfigVO> getCache(int lineId, AlertDeviceType dt) {
|
|
|
|
|
try {
|
|
|
|
|
Map<AlertDeviceType, List<AreaConfigVO>> configList = AREA_CONFIG_CACHE.get(lineId, () -> {
|
|
|
|
|
List<DeviceAreaConfig> configs = deviceAreaConfigRepository.list(Wrappers.lambdaQuery(DeviceAreaConfig.class).eq(DeviceAreaConfig::getLineId, lineId));
|
|
|
|
|
List<AreaConfigVO> listVO = configs.stream().map(AreaConfigVO::new).toList();
|
|
|
|
|
return listVO.stream().collect(Collectors.groupingBy(AreaConfigVO::getDeviceType));
|
|
|
|
|
});
|
|
|
|
|
return configList.get(dt);
|
|
|
|
|
} catch (ExecutionException e) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
public List<AreaConfigVO> getCache(int lineId, AlertDeviceType dt) {
|
|
|
|
|
try {
|
|
|
|
|
Map<AlertDeviceType, List<AreaConfigVO>> configList = AREA_CONFIG_CACHE.get(lineId, () -> {
|
|
|
|
|
List<DeviceAreaConfig> configs = deviceAreaConfigRepository.list(Wrappers.lambdaQuery(DeviceAreaConfig.class).eq(DeviceAreaConfig::getLineId, lineId));
|
|
|
|
|
List<AreaConfigVO> listVO = configs.stream().map(AreaConfigVO::new).toList();
|
|
|
|
|
return listVO.stream().collect(Collectors.groupingBy(AreaConfigVO::getDeviceType));
|
|
|
|
|
});
|
|
|
|
|
return configList.get(dt);
|
|
|
|
|
} catch (ExecutionException e) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String findDevice(Integer lineId, List<String> deviceIds) {
|
|
|
|
|
List<String> errorDevices = Lists.newArrayList();
|
|
|
|
|
|
|
|
|
|
for (String deviceId : deviceIds) {
|
|
|
|
|
MessageOrBuilder msgBuild = LineGraphicDataRepository.getDeviceByCodeNotException(lineId, deviceId);
|
|
|
|
|
if (Objects.nonNull(msgBuild)) {
|
|
|
|
|
String deviceCode = DeviceStatusDataOperate.findFieldVal(msgBuild, "code", String.class);
|
|
|
|
|
errorDevices.add(deviceCode);
|
|
|
|
|
} else {
|
|
|
|
|
errorDevices.add(String.format("id[%s]未找到设备", deviceId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Joiner.on(StringPool.COMMA).join(errorDevices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkDataForSql(DeviceAreaConfigDto dto, boolean isUpdate) {
|
|
|
|
|
LambdaQueryWrapper<DeviceAreaConfig> queryWrapper = Wrappers.lambdaQuery(DeviceAreaConfig.class);
|
|
|
|
|
queryWrapper.eq(DeviceAreaConfig::getDeviceType, dto.getDeviceType());
|
|
|
|
|
queryWrapper.ne(isUpdate, DeviceAreaConfig::getId, dto.getId());
|
|
|
|
|
List<String> lastSqlList = Lists.newArrayList();
|
|
|
|
|
for (String alertType : dto.getAlertTypes()) {
|
|
|
|
|
lastSqlList.add(String.format(" find_in_set('%s',%s) > 0 ", alertType, DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(lastSqlList)) {
|
|
|
|
|
StringBuilder queryTypes = new StringBuilder(" and ( ");
|
|
|
|
|
queryTypes.append(Joiner.on(" or ").join(lastSqlList)).append(") ");
|
|
|
|
|
queryWrapper.last(queryTypes.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String findDevice(Integer lineId, List<String> deviceIds) {
|
|
|
|
|
List<String> errorDevices = Lists.newArrayList();
|
|
|
|
|
List<DeviceAreaConfig> areaConfigList = this.deviceAreaConfigRepository.list(queryWrapper);
|
|
|
|
|
|
|
|
|
|
for (String deviceId : deviceIds) {
|
|
|
|
|
MessageOrBuilder msgBuild = LineGraphicDataRepository.getDeviceByCodeNotException(lineId, deviceId);
|
|
|
|
|
if (Objects.nonNull(msgBuild)) {
|
|
|
|
|
String deviceCode = DeviceStatusDataOperate.findFieldVal(msgBuild, "code", String.class);
|
|
|
|
|
errorDevices.add(deviceCode);
|
|
|
|
|
} else {
|
|
|
|
|
errorDevices.add(String.format("id[%s]未找到设备", deviceId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Joiner.on(StringPool.COMMA).join(errorDevices);
|
|
|
|
|
for (DeviceAreaConfig areaConfig : areaConfigList) {
|
|
|
|
|
List<String> dbDatas = Splitter.on(StringPool.COMMA).splitToList(areaConfig.getData());
|
|
|
|
|
List<String> saveDatas = Lists.newArrayList(dto.getData());
|
|
|
|
|
saveDatas.retainAll(dbDatas);
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isEmpty(saveDatas),
|
|
|
|
|
String.format("添加重复的设备区域[%s] 设备:%s", areaConfig.getAreaName(), this.findDevice(areaConfig.getLineId(), saveDatas)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void saveOrUpdate(DeviceAreaConfigDto dto) {
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(dto.getAlertTypes()), "绑定数据类型不能为空");
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(dto.getAlertTypes().contains(AlertType.INTERLOCK_LEVEL_ONE.name()) && dto.getAlertTypes().size() != 1, "联锁区只能选择一个类型");
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(dto.getAlertTypes().contains(AlertType.INTERLOCK_LEVEL_ONE.name()) && dto.getData().size() > 1, "联锁区只能添加一个设备");
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(dto.getData()), "绑定数据不能为空");
|
|
|
|
|
|
|
|
|
|
boolean isUpdate = false;
|
|
|
|
|
DeviceAreaConfig areaConfig = this.convertDB(dto);
|
|
|
|
|
if (Objects.nonNull(dto.getId()) && dto.getId() != 0L) {
|
|
|
|
|
LambdaQueryWrapper<DeviceAreaConfig> qw = Wrappers.lambdaQuery(DeviceAreaConfig.class);
|
|
|
|
|
qw.eq(DeviceAreaConfig::getId, dto.getId());
|
|
|
|
|
Long counter = this.deviceAreaConfigRepository.count(qw);
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(counter > 0L, "未找到对应的数据");
|
|
|
|
|
areaConfig.setId(dto.getId());
|
|
|
|
|
isUpdate = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
this.checkDataForSql(dto, isUpdate);
|
|
|
|
|
this.deviceAreaConfigRepository.saveOrUpdate(areaConfig);
|
|
|
|
|
AREA_CONFIG_CACHE.invalidate(dto.getLineId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DeviceAreaConfig convertDB(DeviceAreaConfigDto dto) {
|
|
|
|
|
DeviceAreaConfig deviceAreaConfig = new DeviceAreaConfig();
|
|
|
|
|
deviceAreaConfig.setLineId(dto.getLineId());
|
|
|
|
|
deviceAreaConfig.setAreaName(dto.getAreaName());
|
|
|
|
|
deviceAreaConfig.setData(dto.getData().stream().distinct().collect(Collectors.joining(StringPool.COMMA)));
|
|
|
|
|
deviceAreaConfig.setDeviceType(dto.getDeviceType());
|
|
|
|
|
deviceAreaConfig.setAlertTypes(dto.getAlertTypes().stream().distinct().collect(Collectors.joining(StringPool.COMMA)));
|
|
|
|
|
return deviceAreaConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private DeviceAreaConfigDto convertDto(DeviceAreaConfig dto) {
|
|
|
|
|
DeviceAreaConfigDto deviceAreaConfig = new DeviceAreaConfigDto();
|
|
|
|
|
deviceAreaConfig.setLineId(dto.getLineId());
|
|
|
|
|
deviceAreaConfig.setAreaName(dto.getAreaName());
|
|
|
|
|
List<String> datas = Splitter.on(StringPool.COMMA).splitToList(dto.getData());
|
|
|
|
|
|
|
|
|
|
deviceAreaConfig.setData(datas);
|
|
|
|
|
deviceAreaConfig.setDeviceType(dto.getDeviceType());
|
|
|
|
|
if (StringUtils.isNotEmpty(dto.getAlertTypes())) {
|
|
|
|
|
List<String> ll = Splitter.on(StringPool.COMMA).splitToList(dto.getAlertTypes());
|
|
|
|
|
deviceAreaConfig.setAlertTypes(ll);
|
|
|
|
|
}
|
|
|
|
|
return deviceAreaConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void bindAlertType(Long id, List<String> alertTypes) {
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(alertTypes), "绑定数据类型不能为空");
|
|
|
|
|
DeviceAreaConfig areaConfig = this.deviceAreaConfigRepository.getById(id);
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(areaConfig), "未找到对应的数据");
|
|
|
|
|
LambdaUpdateWrapper<DeviceAreaConfig> qw = Wrappers.lambdaUpdate(DeviceAreaConfig.class);
|
|
|
|
|
qw.set(DeviceAreaConfig::getAlertTypes, alertTypes.stream().distinct().collect(Collectors.joining())).eq(DeviceAreaConfig::getId, id);
|
|
|
|
|
this.deviceAreaConfigRepository.update(qw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DeviceAreaConfigDto findInfo(Long id) {
|
|
|
|
|
DeviceAreaConfig areaConfig = this.deviceAreaConfigRepository.getById(id);
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(areaConfig), "未找到对应的数据");
|
|
|
|
|
return this.convertDto(areaConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<DeviceAreaConfigPageDto> page(DeviceAreaConfigQueryDto queryDTO, Integer lineId) {
|
|
|
|
|
LambdaQueryWrapper<DeviceAreaConfig> queryWrapper = Wrappers.lambdaQuery(DeviceAreaConfig.class);
|
|
|
|
|
queryWrapper.select(List.of(DeviceAreaConfig::getId, DeviceAreaConfig::getAreaName, DeviceAreaConfig::getLineId, DeviceAreaConfig::getDeviceType));
|
|
|
|
|
queryWrapper.eq(DeviceAreaConfig::getLineId, lineId);
|
|
|
|
|
queryWrapper.like(StringUtils.isNotEmpty(queryDTO.getAreaName()), DeviceAreaConfig::getAreaName, queryDTO.getAreaName());
|
|
|
|
|
if (Objects.nonNull(queryDTO.getDeviceType())) {
|
|
|
|
|
queryWrapper.eq(DeviceAreaConfig::getDeviceType, queryDTO.getDeviceType().name());
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(queryDTO.getAlertType())) {
|
|
|
|
|
queryWrapper.last(String.format(" and find_in_set('%s',%s) > 0", queryDTO.getAlertType().name(), DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Page<DeviceAreaConfig> pageConfig = deviceAreaConfigRepository.page(queryDTO, queryWrapper);
|
|
|
|
|
return this.convertPage(pageConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkDataForSql(DeviceAreaConfigDto dto, boolean isUpdate) {
|
|
|
|
|
LambdaQueryWrapper<DeviceAreaConfig> queryWrapper = Wrappers.lambdaQuery(DeviceAreaConfig.class);
|
|
|
|
|
queryWrapper.eq(DeviceAreaConfig::getDeviceType, dto.getDeviceType());
|
|
|
|
|
queryWrapper.ne(isUpdate, DeviceAreaConfig::getId, dto.getId());
|
|
|
|
|
List<String> lastSqlList = Lists.newArrayList();
|
|
|
|
|
for (String alertType : dto.getAlertTypes()) {
|
|
|
|
|
lastSqlList.add(String.format(" find_in_set('%s',%s) > 0 ", alertType, DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(lastSqlList)) {
|
|
|
|
|
StringBuilder queryTypes = new StringBuilder(" and ( ");
|
|
|
|
|
queryTypes.append(Joiner.on(" or ").join(lastSqlList)).append(") ");
|
|
|
|
|
queryWrapper.last(queryTypes.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DeviceAreaConfig> areaConfigList = this.deviceAreaConfigRepository.list(queryWrapper);
|
|
|
|
|
|
|
|
|
|
for (DeviceAreaConfig areaConfig : areaConfigList) {
|
|
|
|
|
List<String> dbDatas = Splitter.on(StringPool.COMMA).splitToList(areaConfig.getData());
|
|
|
|
|
List<String> saveDatas = Lists.newArrayList(dto.getData());
|
|
|
|
|
saveDatas.retainAll(dbDatas);
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isEmpty(saveDatas),
|
|
|
|
|
String.format("添加重复的设备区域[%s] 设备:%s", areaConfig.getAreaName(), this.findDevice(areaConfig.getLineId(), saveDatas)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void saveOrUpdate(DeviceAreaConfigDto dto) {
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(dto.getAlertTypes()), "绑定数据类型不能为空");
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(dto.getAlertTypes().contains(AlertType.INTERLOCK_LEVEL_ONE.name()) && dto.getAlertTypes().size() != 1, "联锁区只能选择一个类型");
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotTrue(dto.getAlertTypes().contains(AlertType.INTERLOCK_LEVEL_ONE.name()) && dto.getData().size() > 1, "联锁区只能添加一个设备");
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(dto.getData()), "绑定数据不能为空");
|
|
|
|
|
|
|
|
|
|
boolean isUpdate = false;
|
|
|
|
|
DeviceAreaConfig areaConfig = this.convertDB(dto);
|
|
|
|
|
if (Objects.nonNull(dto.getId()) && dto.getId() != 0L) {
|
|
|
|
|
LambdaQueryWrapper<DeviceAreaConfig> qw = Wrappers.lambdaQuery(DeviceAreaConfig.class);
|
|
|
|
|
qw.eq(DeviceAreaConfig::getId, dto.getId());
|
|
|
|
|
Long counter = this.deviceAreaConfigRepository.count(qw);
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(counter > 0L, "未找到对应的数据");
|
|
|
|
|
areaConfig.setId(dto.getId());
|
|
|
|
|
isUpdate = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
this.checkDataForSql(dto, isUpdate);
|
|
|
|
|
this.deviceAreaConfigRepository.saveOrUpdate(areaConfig);
|
|
|
|
|
AREA_CONFIG_CACHE.invalidate(dto.getLineId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DeviceAreaConfig convertDB(DeviceAreaConfigDto dto) {
|
|
|
|
|
DeviceAreaConfig deviceAreaConfig = new DeviceAreaConfig();
|
|
|
|
|
deviceAreaConfig.setLineId(dto.getLineId());
|
|
|
|
|
deviceAreaConfig.setAreaName(dto.getAreaName());
|
|
|
|
|
deviceAreaConfig.setData(dto.getData().stream().distinct().collect(Collectors.joining(StringPool.COMMA)));
|
|
|
|
|
deviceAreaConfig.setDeviceType(dto.getDeviceType());
|
|
|
|
|
deviceAreaConfig.setAlertTypes(dto.getAlertTypes().stream().distinct().collect(Collectors.joining(StringPool.COMMA)));
|
|
|
|
|
return deviceAreaConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private DeviceAreaConfigDto convertDto(DeviceAreaConfig dto) {
|
|
|
|
|
DeviceAreaConfigDto deviceAreaConfig = new DeviceAreaConfigDto();
|
|
|
|
|
deviceAreaConfig.setLineId(dto.getLineId());
|
|
|
|
|
deviceAreaConfig.setAreaName(dto.getAreaName());
|
|
|
|
|
List<String> datas = Splitter.on(StringPool.COMMA).splitToList(dto.getData());
|
|
|
|
|
|
|
|
|
|
deviceAreaConfig.setData(datas);
|
|
|
|
|
deviceAreaConfig.setDeviceType(dto.getDeviceType());
|
|
|
|
|
if (StringUtils.isNotEmpty(dto.getAlertTypes())) {
|
|
|
|
|
List<String> ll = Splitter.on(StringPool.COMMA).splitToList(dto.getAlertTypes());
|
|
|
|
|
deviceAreaConfig.setAlertTypes(ll);
|
|
|
|
|
}
|
|
|
|
|
return deviceAreaConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void bindAlertType(Long id, List<String> alertTypes) {
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(alertTypes), "绑定数据类型不能为空");
|
|
|
|
|
DeviceAreaConfig areaConfig = this.deviceAreaConfigRepository.getById(id);
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(areaConfig), "未找到对应的数据");
|
|
|
|
|
LambdaUpdateWrapper<DeviceAreaConfig> qw = Wrappers.lambdaUpdate(DeviceAreaConfig.class);
|
|
|
|
|
qw.set(DeviceAreaConfig::getAlertTypes, alertTypes.stream().distinct().collect(Collectors.joining())).eq(DeviceAreaConfig::getId, id);
|
|
|
|
|
this.deviceAreaConfigRepository.update(qw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DeviceAreaConfigDto findInfo(Long id) {
|
|
|
|
|
DeviceAreaConfig areaConfig = this.deviceAreaConfigRepository.getById(id);
|
|
|
|
|
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(areaConfig), "未找到对应的数据");
|
|
|
|
|
return this.convertDto(areaConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<DeviceAreaConfigPageDto> page(DeviceAreaConfigQueryDto queryDTO, Integer lineId) {
|
|
|
|
|
LambdaQueryWrapper<DeviceAreaConfig> queryWrapper = Wrappers.lambdaQuery(DeviceAreaConfig.class);
|
|
|
|
|
queryWrapper.select(List.of(DeviceAreaConfig::getId, DeviceAreaConfig::getAreaName, DeviceAreaConfig::getLineId, DeviceAreaConfig::getDeviceType));
|
|
|
|
|
queryWrapper.eq(DeviceAreaConfig::getLineId, lineId);
|
|
|
|
|
queryWrapper.like(StringUtils.isNotEmpty(queryDTO.getAreaName()), DeviceAreaConfig::getAreaName, queryDTO.getAreaName());
|
|
|
|
|
if (Objects.nonNull(queryDTO.getDeviceType())) {
|
|
|
|
|
queryWrapper.eq(DeviceAreaConfig::getDeviceType, queryDTO.getDeviceType().name());
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(queryDTO.getAlertType())) {
|
|
|
|
|
queryWrapper.last(String.format(" and find_in_set('%s',%s) > 0", queryDTO.getAlertType().name(), DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Page<DeviceAreaConfig> pageConfig = deviceAreaConfigRepository.page(queryDTO, queryWrapper);
|
|
|
|
|
return this.convertPage(pageConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Page<DeviceAreaConfigPageDto> convertPage(Page<DeviceAreaConfig> pageConfig) {
|
|
|
|
|
private Page<DeviceAreaConfigPageDto> convertPage(Page<DeviceAreaConfig> pageConfig) {
|
|
|
|
|
// List<Long> areaConfigIds = pageConfig.getRecords().stream().map(DeviceAreaConfig::getId).toList();
|
|
|
|
|
List<DeviceAreaConfigPageDto> pageList = Lists.newArrayListWithCapacity(pageConfig.getRecords().size());
|
|
|
|
|
List<DeviceAreaConfigPageDto> pageList = Lists.newArrayListWithCapacity(pageConfig.getRecords().size());
|
|
|
|
|
// Map<Long, String> areaIdMapTipIds = iAlertTipRepository.findBindAreaConfigId(areaConfigIds);
|
|
|
|
|
for (DeviceAreaConfig ac : pageConfig.getRecords()) {
|
|
|
|
|
pageList.add(new DeviceAreaConfigPageDto(ac));
|
|
|
|
|
}
|
|
|
|
|
Page<DeviceAreaConfigPageDto> dtoPage = Page.of(pageConfig.getCurrent(), pageConfig.getSize(), pageConfig.getTotal());
|
|
|
|
|
dtoPage.setRecords(pageList);
|
|
|
|
|
return dtoPage;
|
|
|
|
|
for (DeviceAreaConfig ac : pageConfig.getRecords()) {
|
|
|
|
|
pageList.add(new DeviceAreaConfigPageDto(ac));
|
|
|
|
|
}
|
|
|
|
|
Page<DeviceAreaConfigPageDto> dtoPage = Page.of(pageConfig.getCurrent(), pageConfig.getSize(), pageConfig.getTotal());
|
|
|
|
|
dtoPage.setRecords(pageList);
|
|
|
|
|
return dtoPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<AreaFinder> findAlertType(Integer lineId, String alertType) {
|
|
|
|
|
LambdaQueryWrapper<DeviceAreaConfig> query = Wrappers.lambdaQuery(DeviceAreaConfig.class);
|
|
|
|
|
query.select(DeviceAreaConfig::getId, DeviceAreaConfig::getAreaName);
|
|
|
|
|
query.eq(DeviceAreaConfig::getLineId, lineId);
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.append(String.format(" and find_in_set('%s',%s) > 0", alertType, DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
public List<AreaFinder> findAlertType(Integer lineId, String alertType) {
|
|
|
|
|
LambdaQueryWrapper<DeviceAreaConfig> query = Wrappers.lambdaQuery(DeviceAreaConfig.class);
|
|
|
|
|
query.select(DeviceAreaConfig::getId, DeviceAreaConfig::getAreaName);
|
|
|
|
|
query.eq(DeviceAreaConfig::getLineId, lineId);
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.append(String.format(" and find_in_set('%s',%s) > 0", alertType, DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
/*if (StringUtils.equals(alertType, AlertType.AXLE_LED_RED_MOST.name()) || StringUtils.equals(alertType, AlertType.AXLE_LED_ORANGE_MOST.name())) {
|
|
|
|
|
sb.append(String.format(" or find_in_set('%s',%s) > 0", AlertType.INTERLOCK_LEVEL_TWO.name(), DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
} else if (StringUtils.equals(alertType, AlertType.AXLE_LED_RED_INTERLOCK_AREA.name()) || StringUtils.equals(alertType, AlertType.AXLE_LED_ORANGE_INTERLOCK_AREA.name())) {
|
|
|
|
@ -205,29 +205,29 @@ public class DeviceAreaConfigService {
|
|
|
|
|
} else if (StringUtils.equals(alertType, AlertType.SWITCH_LOST_MOST.name())) {
|
|
|
|
|
sb.append(String.format(" or find_in_set('%s',%s) > 0", AlertType.INTERLOCK_LEVEL_TWO.name(), DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
}*/
|
|
|
|
|
if (StringUtils.equals(alertType, AlertType.AXLE_LED_RED_INTERLOCK_AREA.name())
|
|
|
|
|
|| StringUtils.equals(alertType, AlertType.AXLE_LED_ORANGE_INTERLOCK_AREA.name())
|
|
|
|
|
|| StringUtils.equals(alertType, AlertType.SWITCH_LOST_INTERLOCK_AREA.name())) {
|
|
|
|
|
sb.append(String.format(" or find_in_set('%s',%s) > 0", AlertType.INTERLOCK_LEVEL_ONE.name(), DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
}
|
|
|
|
|
query.last(sb.toString());
|
|
|
|
|
return this.deviceAreaConfigRepository.list(query).stream().map(AreaFinder::new).toList();
|
|
|
|
|
if (StringUtils.equals(alertType, AlertType.AXLE_LED_RED_INTERLOCK_AREA.name())
|
|
|
|
|
|| StringUtils.equals(alertType, AlertType.AXLE_LED_ORANGE_INTERLOCK_AREA.name())
|
|
|
|
|
|| StringUtils.equals(alertType, AlertType.SWITCH_LOST_INTERLOCK_AREA.name())) {
|
|
|
|
|
sb.append(String.format(" or find_in_set('%s',%s) > 0", AlertType.INTERLOCK_LEVEL_ONE.name(), DeviceAreaConfig.ALERT_TYPES));
|
|
|
|
|
}
|
|
|
|
|
query.last(sb.toString());
|
|
|
|
|
return this.deviceAreaConfigRepository.list(query).stream().map(AreaFinder::new).toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void delete(Long id) {
|
|
|
|
|
deviceAreaConfigRepository.removeById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
|
public static class AreaFinder {
|
|
|
|
|
|
|
|
|
|
private Long id;
|
|
|
|
|
private String areaName;
|
|
|
|
|
|
|
|
|
|
public AreaFinder(DeviceAreaConfig areaConfig) {
|
|
|
|
|
this.id = areaConfig.getId();
|
|
|
|
|
this.areaName = areaConfig.getAreaName();
|
|
|
|
|
}
|
|
|
|
|
public void delete(Long id) {
|
|
|
|
|
deviceAreaConfigRepository.removeById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
|
public static class AreaFinder {
|
|
|
|
|
|
|
|
|
|
private Long id;
|
|
|
|
|
private String areaName;
|
|
|
|
|
|
|
|
|
|
public AreaFinder(DeviceAreaConfig areaConfig) {
|
|
|
|
|
this.id = areaConfig.getId();
|
|
|
|
|
this.areaName = areaConfig.getAreaName();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|