Merge remote-tracking branch 'origin/mdc' into mdc

This commit is contained in:
nieziyan 2024-01-05 11:15:29 +08:00
commit e5fbffe637
2 changed files with 28 additions and 0 deletions

View File

@ -45,4 +45,31 @@ public class DetectorIdFormat {
Integer detectorId = Integer.valueOf(prefixFormatResult + suffixFormatResult);
return detectorId;
}
/**
* 格式化探测器id解析出台站id
* @param detectorCode
* @return
*/
public Integer formatDetectorCodeToStationId(String detectorCode){
if(!detectorCode.contains(StringConstant.UNDER_LINE)){
throw new RuntimeException("The "+detectorCode+" detector code is illegal");
}
//举例FRP28_007
final String[] arr = detectorCode.split(StringConstant.UNDER_LINE);
final String prefix = arr[0];
Integer stationId = null;
//格式化前缀
for(int i=prefix.length()-1;i>=0;i--){
final String letter = String.valueOf(prefix.charAt(i));
if(StringUtils.isAlpha(letter)){
final String mapVal = suffixMap.getOrDefault(letter, "-1");
stationId = Integer.valueOf(mapVal + prefix.substring(i + 1));
break;
}
}
return stationId;
}
}

View File

@ -37,6 +37,7 @@ public class GardsDetectorsServiceImpl extends ServiceImpl<GardsDetectorsMapper,
detector.setDetectorId(format.formatDetectorCodeToId(detectorCode));
detector.setDetectorCode(detectorCode);
detector.setStatus(DetectorsStatus.OPERATING.getStatus());
detector.setStationId(format.formatDetectorCodeToStationId(detectorCode));
this.baseMapper.insert(detector);
return detector;
}