feat:探测器Id生成

This commit is contained in:
nieziyan 2024-01-11 16:37:56 +08:00
parent 4e2313945a
commit f67db42995
4 changed files with 39 additions and 23 deletions

View File

@ -1,11 +1,15 @@
package org.jeecg.common.properties;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.models.auth.In;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Data
@ -46,6 +50,30 @@ public class DetectorIdFormat {
return detectorId;
}
public Integer detectorCodeToId(String detectorCode){
if (!StrUtil.contains(detectorCode, StrUtil.UNDERLINE))
return null;
String[] split = StrUtil.split(detectorCode, StrUtil.UNDERLINE);
String prefix = split[0];
String suffix = split[1];
// 根据台站code即prefix解析出Id的前半部分
prefix = StrUtil.sub(prefix, 2, prefix.length());
for (Map.Entry<String, String> entry : suffixMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (!StrUtil.contains(prefix, key))
continue;
prefix = StrUtil.replace(prefix, key, value);
}
if (!NumberUtil.isNumber(prefix))
return null;
// 根据探测器序号即suffix解析出Id的后半部分
if (!NumberUtil.isNumber(suffix))
return null;
suffix = String.format("%02d", Integer.valueOf(suffix));
return Integer.valueOf(prefix + suffix);
}
/**
* 格式化探测器id解析出台站id
* @param detectorCode

View File

@ -70,9 +70,4 @@ public class GardsDetectorsController {
public Map<String, List<GardsDetectorsSystem>> findStationDetectors(@RequestBody List<String> stationIds){
return gardsDetectorsService.findStationDetectors(stationIds);
}
@GetMapping("duplicateCheck")
public Result<?> duplicateCheck(String field, String value){
return gardsDetectorsService.duplicateCheck(field, value);
}
}

View File

@ -64,6 +64,4 @@ public interface IGardsDetectorsService extends IService<GardsDetectorsSystem> {
* @return
*/
Map<String, List<GardsDetectorsSystem>> findStationDetectors(List<String> stationIds);
Result<?> duplicateCheck(String field, String value);
}

View File

@ -15,6 +15,7 @@ import com.google.common.collect.Lists;
import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.properties.DetectorIdFormat;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.base.entity.configuration.GardsDetectors;
import org.jeecg.modules.base.enums.DetectorStatus;
@ -36,6 +37,9 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
@Autowired
private RedisUtil redisUtil;
@Autowired
private DetectorIdFormat idFormat;
@Override
public Result<IPage<GardsDetectorsSystem>> findPage(QueryRequest queryRequest, GardsDetectorsSystem gardsDetectors) {
Result<IPage<GardsDetectorsSystem>> result = new Result<>();
@ -84,9 +88,14 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
@Override
@Transactional
public Result<?> create(GardsDetectorsSystem detector) {
String detectorCode = detector.getDetectorCode();
Integer detectorId = idFormat.detectorCodeToId(detectorCode);
if (ObjectUtil.isNull(detectorId))
return Result.error("Detector Code Is Invalid");
if (ObjectUtil.isNotNull(getById(detectorId)))
return Result.error("Detector Code Cannot Repeated");
detector.setDetectorId(detectorId);
Integer stationId = detector.getStationId();
if (ObjectUtil.isNull(stationId))
return Result.error("Station Id Of The Detector Cannot Be Empty");
// 查询相同台站下所有工作的探测器 按照探测器Id升序排序
LambdaQueryWrapper<GardsDetectorsSystem> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsDetectors::getStationId, stationId);
@ -161,18 +170,4 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
}
return map;
}
@Override
public Result<?> duplicateCheck(String field, String value) {
LambdaQueryWrapper<GardsDetectorsSystem> wrapper = new LambdaQueryWrapper<>();
if (StrUtil.equals(field, "DETECTOR_ID")){
wrapper.eq(GardsDetectors::getDetectorId, value);
return this.list(wrapper).isEmpty() ? Result.OK() : Result.error("Id Cannot Be Repeated");
}else if (StrUtil.equals(field, "DETECTOR_CODE")){
wrapper.eq(GardsDetectors::getDetectorCode, value);
return this.list(wrapper).isEmpty() ? Result.OK() : Result.error("Code Cannot Be Repeated");
}else {
return Result.OK();
}
}
}