diff --git a/sec-api/src/main/java/com/imdroid/secapi/dto/WarningCfg.java b/sec-api/src/main/java/com/imdroid/secapi/dto/WarningCfg.java index 2b4970fb..b4d67056 100644 --- a/sec-api/src/main/java/com/imdroid/secapi/dto/WarningCfg.java +++ b/sec-api/src/main/java/com/imdroid/secapi/dto/WarningCfg.java @@ -42,6 +42,10 @@ public class WarningCfg { public static final String TYPE_NAME_CONT_INVALID_RESULT = "长时间无有效解"; public static final int TYPE_INCLINE = 0x400; public static final String TYPE_NAME_INCLINE = "异常倾斜"; + public static final int TYPE_SIM_STATUS_ABNORMAL = 0x800; + public static final String TYPE_NAME_SIM_STATUS_ABNORMAL = "流量卡状态异常"; + public static final int TYPE_SIM_LOW_TRAFFIC = 0x900; + public static final String TYPE_NAME_SIM_LOW_TRAFFIC = "流量卡流量不足"; // warning level definition public static final short LEVEL_0 = 0; //正常 @@ -68,6 +72,8 @@ public class WarningCfg { if((code & TYPE_NO_FIXED_RESULT) !=0) warningInfo.add(TYPE_NAME_NO_FIXED_RESULT); if((code & TYPE_CONT_INVALID_RESULT) !=0) warningInfo.add(TYPE_NAME_CONT_INVALID_RESULT); if((code & TYPE_INCLINE) !=0) warningInfo.add(TYPE_NAME_INCLINE); + if((code & TYPE_SIM_STATUS_ABNORMAL) !=0) warningInfo.add(TYPE_NAME_SIM_STATUS_ABNORMAL); + if((code & TYPE_SIM_LOW_TRAFFIC) !=0) warningInfo.add(TYPE_NAME_SIM_LOW_TRAFFIC); return warningInfo; } } diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/service/WarningServiceImpl.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/service/WarningServiceImpl.java index 5b8c71e1..469daeb3 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/service/WarningServiceImpl.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/service/WarningServiceImpl.java @@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.Duration; import java.time.LocalDateTime; import java.util.List; @@ -267,6 +269,79 @@ public class WarningServiceImpl implements WarningService { } } + // 检查SIM卡状态 + public void checkSimCardStatus(Device device, SimCard simCard) { + GnssStatus status = gnssStatusMapper.getByDeviceId(device.getDeviceId()); + if (status == null) return; + + boolean isUpdated = false; + + // 检查SIM卡状态是否异常(停机、注销、失效) + if (simCard.getStatus() == SimCard.STATUS_SUSPENDED || + simCard.getStatus() == SimCard.STATUS_CANCELLED || + simCard.getStatus() == SimCard.STATUS_INVALID) { + + String statusDesc; + switch(simCard.getStatus()) { + case SimCard.STATUS_SUSPENDED: + statusDesc = "停机"; + break; + case SimCard.STATUS_CANCELLED: + statusDesc = "注销"; + break; + case SimCard.STATUS_INVALID: + statusDesc = "失效"; + break; + default: + statusDesc = "未知状态"; + } + + if (check(status, WarningCfg.TYPE_SIM_STATUS_ABNORMAL, + WarningCfg.TYPE_NAME_SIM_STATUS_ABNORMAL, false, + simCard.getStatus(), null, + "SIM卡状态: " + statusDesc)) { + isUpdated = true; + } + } else if (simCard.getStatus() == SimCard.STATUS_ACTIVATED) { + // 状态正常(已激活),清除告警 + if ((status.getWarningcode() & WarningCfg.TYPE_SIM_STATUS_ABNORMAL) != 0) { + clearWarning(status, WarningCfg.TYPE_SIM_STATUS_ABNORMAL); + isUpdated = true; + } + } + + if (isUpdated) { + status.setWarning(getWarningLevel(status.getWarningcode())); + gnssStatusMapper.updateById(status); + } + } + + public void checkSimCardTraffic(Device device, SimCard simCard) { + GnssStatus status = gnssStatusMapper.getByDeviceId(device.getDeviceId()); + if (status == null) return; + + boolean isUpdated = false; + + BigDecimal usedPercentage = simCard.getUsed() + .divide(simCard.getTotal(), 4, RoundingMode.HALF_UP) + .multiply(BigDecimal.valueOf(100)); + + // 检查流量使用情况 + if (check(status, WarningCfg.TYPE_SIM_LOW_TRAFFIC, + WarningCfg.TYPE_NAME_SIM_LOW_TRAFFIC, + false, // 大于等于流量门限值,那么就报警 + usedPercentage.intValue(), + null, + String.format("流量已使用 %.2f%%", usedPercentage.doubleValue()))) { + isUpdated = true; + } + + if (isUpdated) { + status.setWarning(getWarningLevel(status.getWarningcode())); + gnssStatusMapper.updateById(status); + } + } + public void generate_warning_logs(String device_id,int warning_type,String warning_type_name){ // 连续无固定解 和 掉电 警告 if (warning_type == WarningCfg.TYPE_NO_FIXED_RESULT || warning_type == WarningCfg.TYPE_LOW_VOLTAGE) { diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/controller/WarningController.java b/sec-beidou/src/main/java/com/imdroid/beidou/controller/WarningController.java index bc9a36b8..9284ace3 100644 --- a/sec-beidou/src/main/java/com/imdroid/beidou/controller/WarningController.java +++ b/sec-beidou/src/main/java/com/imdroid/beidou/controller/WarningController.java @@ -47,6 +47,10 @@ public class WarningController extends BasicController implements CommonExcelSer warningMap.put(WarningCfg.TYPE_LOW_RSSI, WarningCfg.TYPE_NAME_LOW_RSSI); warningMap.put(WarningCfg.TYPE_RX_MUCH_UNKNOWN, WarningCfg.TYPE_NAME_RX_MUCH_UNKNOWN); warningMap.put(WarningCfg.TYPE_INCLINE, WarningCfg.TYPE_NAME_INCLINE); + warningMap.put(WarningCfg.TYPE_SIM_LOW_TRAFFIC, WarningCfg.TYPE_NAME_SIM_LOW_TRAFFIC); + warningMap.put(WarningCfg.TYPE_SIM_STATUS_ABNORMAL, WarningCfg.TYPE_NAME_SIM_STATUS_ABNORMAL); + + } /**** 推送页面 *****/