feat:探测器check
This commit is contained in:
parent
d02bd8127d
commit
1bea5eb58b
|
@ -2,7 +2,6 @@ package org.jeecg.common.properties;
|
||||||
|
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jeecg.common.constant.StringConstant;
|
import org.jeecg.common.constant.StringConstant;
|
||||||
|
@ -50,7 +49,10 @@ public class DetectorIdFormat {
|
||||||
return detectorId;
|
return detectorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer detectorCodeToId(String detectorCode){
|
/**
|
||||||
|
* 探测器Code解析出探测器Id
|
||||||
|
*/
|
||||||
|
public Integer codeToId(String detectorCode){
|
||||||
if (!StrUtil.contains(detectorCode, StrUtil.UNDERLINE))
|
if (!StrUtil.contains(detectorCode, StrUtil.UNDERLINE))
|
||||||
return null;
|
return null;
|
||||||
String[] split = StrUtil.split(detectorCode, StrUtil.UNDERLINE);
|
String[] split = StrUtil.split(detectorCode, StrUtil.UNDERLINE);
|
||||||
|
@ -100,4 +102,25 @@ public class DetectorIdFormat {
|
||||||
|
|
||||||
return stationId;
|
return stationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 探测器Id解析出台站Id
|
||||||
|
*/
|
||||||
|
public Integer codeToStationId(String detectorCode){
|
||||||
|
if (!StrUtil.contains(detectorCode, StrUtil.UNDERLINE))
|
||||||
|
return null;
|
||||||
|
String[] split = StrUtil.split(detectorCode, StrUtil.UNDERLINE);
|
||||||
|
String stationCode = split[0];
|
||||||
|
stationCode = StrUtil.sub(stationCode, 2, stationCode.length());
|
||||||
|
for (Map.Entry<String, String> entry : suffixMap.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
String value = entry.getValue();
|
||||||
|
if (!StrUtil.contains(stationCode, key))
|
||||||
|
continue;
|
||||||
|
stationCode = StrUtil.replace(stationCode, key, value);
|
||||||
|
}
|
||||||
|
if (!NumberUtil.isNumber(stationCode))
|
||||||
|
return null;
|
||||||
|
return Integer.valueOf(stationCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
package org.jeecg.modules.base.enums;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 探测器运行状态
|
|
||||||
*/
|
|
||||||
public enum DetectorsStatus {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 未运行
|
|
||||||
*/
|
|
||||||
UNOPERATING("Unoperating"),
|
|
||||||
/**
|
|
||||||
* 在运行
|
|
||||||
*/
|
|
||||||
OPERATING("Operating");
|
|
||||||
|
|
||||||
private String status;
|
|
||||||
|
|
||||||
DetectorsStatus(String type) {
|
|
||||||
this.status = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatus(){
|
|
||||||
return this.status;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +1,74 @@
|
||||||
package org.jeecg.modules.service.impl;
|
package org.jeecg.modules.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.collection.ListUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.jeecg.common.constant.Prompt;
|
||||||
import org.jeecg.common.properties.DetectorIdFormat;
|
import org.jeecg.common.properties.DetectorIdFormat;
|
||||||
import org.jeecg.modules.base.entity.configuration.GardsDetectors;
|
import org.jeecg.modules.base.entity.configuration.GardsDetectors;
|
||||||
import org.jeecg.modules.base.enums.DetectorsStatus;
|
import org.jeecg.modules.base.enums.DetectorStatus;
|
||||||
import org.jeecg.modules.mapper.GardsDetectorsMapper;
|
import org.jeecg.modules.mapper.GardsDetectorsMapper;
|
||||||
import org.jeecg.modules.service.GardsDetectorsService;
|
import org.jeecg.modules.service.GardsDetectorsService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Objects;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@DS("ora")
|
@DS("ora")
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper, GardsDetectors> implements GardsDetectorsService {
|
public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper, GardsDetectors> implements GardsDetectorsService {
|
||||||
|
|
||||||
private final DetectorIdFormat format;
|
private final DetectorIdFormat idFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验探测器是否存在,不存在则创建
|
* 校验探测器是否存在,不存在则创建
|
||||||
* @param detectorCode
|
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
|
public GardsDetectors check(String detectorCode) {
|
||||||
|
LambdaQueryWrapper<GardsDetectors> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(GardsDetectors::getDetectorCode, detectorCode);
|
||||||
|
Optional<GardsDetectors> optional = this.list(wrapper).stream().findFirst();
|
||||||
|
if (optional.isPresent())
|
||||||
|
return optional.get();
|
||||||
|
Integer detectorId = idFormat.codeToId(detectorCode);
|
||||||
|
Integer stationId = idFormat.codeToStationId(detectorCode);
|
||||||
|
if (ObjectUtil.isNull(detectorId) || ObjectUtil.isNull(stationId))
|
||||||
|
throw new RuntimeException("Invalid Detector Code: " + detectorCode);
|
||||||
|
GardsDetectors detector = new GardsDetectors();
|
||||||
|
detector.setDetectorId(detectorId);
|
||||||
|
detector.setStationId(stationId);
|
||||||
|
detector.setDetectorCode(detectorCode);
|
||||||
|
detector.setStatus(DetectorStatus.ON.getValue());
|
||||||
|
|
||||||
|
// 查询相同台站下所有工作的探测器 按照探测器Id升序排序
|
||||||
|
wrapper.clear();
|
||||||
|
wrapper.eq(GardsDetectors::getStationId, stationId);
|
||||||
|
List<GardsDetectors> detectors = this.list(wrapper);
|
||||||
|
detectors = detectors.stream()
|
||||||
|
.filter(item -> StrUtil.equals(StrUtil.trim(item.getStatus()), DetectorStatus.ON.getValue()))
|
||||||
|
.sorted(Comparator.comparingInt(GardsDetectors::getDetectorId))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
// 如果相同台站下没有工作探测器
|
||||||
|
if (CollUtil.isEmpty(detectors))
|
||||||
|
return this.save(detector) ? detector : null;
|
||||||
|
// 如果相同台站下有工作探测器 将Id最小的探测器状态置为 Unoperating
|
||||||
|
GardsDetectors detectorMin = detectors.get(0);
|
||||||
|
detectorMin.setStatus(DetectorStatus.OFF.getValue());
|
||||||
|
detectors = ListUtil.toList(detectorMin, detector);
|
||||||
|
return this.saveOrUpdateBatch(detectors) ? detector : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@Transactional
|
||||||
|
@Override
|
||||||
public GardsDetectors check(String detectorCode) {
|
public GardsDetectors check(String detectorCode) {
|
||||||
LambdaQueryWrapper<GardsDetectors> detectorsQuery = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<GardsDetectors> detectorsQuery = new LambdaQueryWrapper<>();
|
||||||
detectorsQuery.select(GardsDetectors::getDetectorId);
|
detectorsQuery.select(GardsDetectors::getDetectorId);
|
||||||
|
@ -42,5 +84,5 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
|
||||||
return detector;
|
return detector;
|
||||||
}
|
}
|
||||||
return query;
|
return query;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import org.jeecg.common.api.QueryRequest;
|
import org.jeecg.common.api.QueryRequest;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.constant.Prompt;
|
import org.jeecg.common.constant.Prompt;
|
||||||
|
@ -89,7 +88,7 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
|
||||||
@Transactional
|
@Transactional
|
||||||
public Result<?> create(GardsDetectorsSystem detector) {
|
public Result<?> create(GardsDetectorsSystem detector) {
|
||||||
String detectorCode = detector.getDetectorCode();
|
String detectorCode = detector.getDetectorCode();
|
||||||
Integer detectorId = idFormat.detectorCodeToId(detectorCode);
|
Integer detectorId = idFormat.codeToId(detectorCode);
|
||||||
if (ObjectUtil.isNull(detectorId))
|
if (ObjectUtil.isNull(detectorId))
|
||||||
return Result.error("Detector Code Is Invalid");
|
return Result.error("Detector Code Is Invalid");
|
||||||
if (ObjectUtil.isNotNull(getById(detectorId)))
|
if (ObjectUtil.isNotNull(getById(detectorId)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user