package com.whyc.service;
|
|
import com.whyc.constant.AlarmConstant;
|
import com.whyc.constant.BatteryConstant;
|
import com.whyc.constant.DeviceConstant;
|
import com.whyc.dto.BatteryAlarmDto;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.BatteryAlarmMapper;
|
import com.whyc.mapper.BatteryInfoMapper;
|
import com.whyc.mapper.Fbs9100StateMapper;
|
import com.whyc.pojo.FBS9100State;
|
import com.whyc.util.MathUtil;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.util.Arrays;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service
|
public class BatteryAlarmService {
|
|
@Resource
|
private BatteryAlarmMapper mapper;
|
|
@Resource
|
private Fbs9100StateMapper fbs9100StateMapper;
|
|
@Resource
|
private BatteryInfoMapper infoMapper;
|
|
/**
|
* 单体容量 monCapStd
|
* alm_id
|
* Alarm_CapAlarm =119010
|
* @param userId
|
* @return
|
*/
|
public Response<Map> getMonCapacityLowAnalysis(int userId) {
|
Response<Map> response = new Response();
|
Map<String, Object> resultMap = new HashMap<>();
|
|
try {
|
//单体容量低告警数和对应的告警机房数
|
BatteryAlarmDto batteryAlarmDto = mapper.getLowCapacityAlarms(userId,AlarmConstant.Alarm_IGNAL_ID_CapAlarmLow);
|
int alarmNum = batteryAlarmDto.getNum();
|
//int stationNum = batteryAlarmDto.getStationNum();
|
//总告警数
|
//Integer totalAlarmNum = mapper.getTotalAlarms(userId);
|
//总机房数
|
//int totalStationNum = infoMapper.getStationCount(userId);
|
|
//容量低告警占比
|
//String capLowRateStr = (String) MathUtil.divide(alarmNum,totalAlarmNum,3);
|
//容量低告警机房占比
|
//String capLowStationRateStr = (String) MathUtil.divide(stationNum,totalStationNum,3);
|
|
resultMap.put("告警数",alarmNum);
|
//resultMap.put("告警总数",totalAlarmNum);
|
//resultMap.put("告警占比",capLowRateStr);
|
|
//resultMap.put("告警机房数",alarmNum);
|
//resultMap.put("告警机房占比",capLowStationRateStr);
|
|
response.set(1, resultMap);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return response.set(0);
|
}
|
return response;
|
}
|
|
/**
|
* 在线电压和组端电压
|
* alm_id 电池告警参数
|
* Alarm_vol_Online =119001
|
* Alarm_vol_Group =119002
|
*
|
* @param userId
|
* @return
|
*/
|
public Response<Map> getOnlineAndGroupVolAnalysis(int userId) {
|
List<Integer> alarmIds = Arrays.asList(AlarmConstant.Alarm_vol_Online,AlarmConstant.Alarm_vol_Group);
|
List<String> alarmNames =Arrays.asList("在线电压","组端电压");
|
List<Integer> alarmSignalIds = Arrays.asList(
|
AlarmConstant.ALM_SIGNAL_ID_OnlineVolHigh,AlarmConstant.ALM_SIGNAL_ID_OnlineVolLow,
|
AlarmConstant.ALM_SIGNAL_ID_GroupVolHigh,AlarmConstant.ALM_SIGNAL_ID_GroupVolLow);
|
String mapName1 = "高告警数量";
|
String mapName2 = "低告警数量";
|
|
Map<String, Map> doubleAnalysis = getDoubleAnalysis(userId, alarmIds, alarmSignalIds, alarmNames, mapName1, mapName2);
|
|
return new Response<Map>().set(1,doubleAnalysis);
|
}
|
|
public Response<Map> getBTSEquipStatus(int userId) {
|
|
Response<Map> response = new Response();
|
Map<String, Object> resultMap = new HashMap<>();
|
try {
|
List<FBS9100State> statusList = fbs9100StateMapper.getStatus(userId);
|
for (int i = 0; i < statusList.size(); i++) {
|
switch (statusList.get(i).getWorkState()){
|
case DeviceConstant.DEV_ONLINE_CHARGE:
|
resultMap.put("在线浮充",statusList.get(i).getNum());
|
break;
|
case DeviceConstant.DEV_PRE_CHARGE:
|
resultMap.put("预充电",statusList.get(i).getNum());
|
break;
|
case DeviceConstant.DEV_NUCLEAR_CAP:
|
resultMap.put("核容测试",statusList.get(i).getNum());
|
break;
|
case DeviceConstant.DEV_RES_TEST:
|
resultMap.put("内阻测试",statusList.get(i).getNum());
|
break;
|
}
|
}
|
response.setCode(1);
|
response.setData(resultMap);
|
} catch (Exception e) {
|
e.printStackTrace();
|
response.setCode(0);
|
return response;
|
}
|
return response;
|
}
|
|
|
/**
|
* 放电电流 Alarm_curr_Discharge =119004
|
* alm_signal_id 查询条件 ALM_SIGNAL_ID_DisChargeCurrLow
|
* @param userId
|
* @return
|
*/
|
public Response<Map> getDischargeAnalysis(int userId) {
|
|
Response<Map> response = new Response();
|
Map<String, Object> resultMap = new HashMap<>();
|
|
try {
|
//放电电流低告警数和对应的告警机房数
|
BatteryAlarmDto batteryAlarmDto = mapper.getLowDischargeAlarms(userId,AlarmConstant.ALM_SIGNAL_ID_DisChargeCurrLow);
|
int disChargeAlarmNum = batteryAlarmDto.getNum();
|
//int disChargeStationNum = batteryAlarmDto.getStationNum();
|
|
//总告警数
|
//Integer totalAlarmNum = mapper.getTotalAlarms(userId);
|
//总机房数
|
//int totalStationNum = infoMapper.getStationCount(userId);
|
//放电电流低告警占比
|
//String disChargeLowRateStr = (String) MathUtil.divide(disChargeAlarmNum,totalAlarmNum,3);
|
//放电电流低告警机房占比
|
//String disChargeLowStationRateStr = (String) MathUtil.divide(disChargeStationNum,totalStationNum,3);
|
|
resultMap.put("低告警数量", disChargeAlarmNum); //低告警数量 alm_signal_id:DisChargeCurr 7 high; 8 low
|
//resultMap.put("告警机房总数", disChargeStationNum); //告警机房总数
|
//resultMap.put("告警机房数比例", disChargeLowRateStr); //告警机房数比例
|
//resultMap.put("告警总数", totalAlarmNum); //告警总数
|
//resultMap.put("告警总数比例", disChargeLowStationRateStr); //告警总数比例
|
response.setCode(1);
|
response.setData(resultMap);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return response.setCode(0);
|
}
|
return response;
|
}
|
|
/**
|
* 放电和充电电流 高
|
* alm_id 电池告警参数
|
* @param userId
|
* @return
|
*/
|
public Response<Map> getChargeAnalysis(int userId) {
|
HashMap<String, Object> resultMap = new HashMap<>();
|
Map<String, Object> disCharge = new HashMap<>();//放电电流 Alarm_curr_Discharge =119004
|
Map<String, Object> reCharge = new HashMap<>();//充电电流 Alarm_curr_Charge =119003
|
|
//放电电流高告警数量
|
Integer dischargeHighAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_DisChargeCurrHigh);
|
|
//告警总数
|
//Integer totalStationAlarmNum =mapper.getTotalAlarms(userId);
|
|
//放电电流高告警机房数
|
//int dischargeTotalAlarmStations = mapper.getTotalAlarmStations(userId,AlarmConstant.ALM_SIGNAL_ID_DisChargeCurrHigh);
|
|
//总机房数
|
//int totalStationNum = infoMapper.getStationCount(userId);
|
|
//放电电流高告警占比
|
//String dischargeRateStr = (String) MathUtil.divide(dischargeHighAlarmsNum,totalStationAlarmNum,3);
|
//放电电流高告警机房占比
|
//String dischargeStationRateStr = (String) MathUtil.divide(dischargeTotalAlarmStations,totalStationNum,3);
|
|
disCharge.put("高告警数量",dischargeHighAlarmsNum); //高告警数量 alm_signal_id:ChargeCurrHigh 5 high; 6 low
|
//disCharge.put("告警总数",totalStationAlarmNum); //告警总数
|
//disCharge.put("告警总数比例", dischargeRateStr); //告警总数比例
|
//disCharge.put("告警机房总数", dischargeTotalAlarmStations); //告警机房总数
|
//disCharge.put("告警机房数比例",dischargeStationRateStr); //告警机房数比例
|
resultMap.put("disCharge", disCharge);
|
|
/*=====充电电流高======*/
|
|
//放电电流高告警数量
|
Integer chargeHighAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_ChargeCurrHigh);
|
|
//放电电流高告警机房数
|
int chargeTotalAlarmStations = mapper.getTotalAlarmStations(userId,AlarmConstant.ALM_SIGNAL_ID_ChargeCurrHigh);
|
|
//放电电流高告警占比
|
//String chargeRateStr = (String) MathUtil.divide(chargeHighAlarmsNum,totalStationAlarmNum,3);
|
//放电电流高告警机房占比
|
//String chargeStationRateStr = (String) MathUtil.divide(chargeTotalAlarmStations,totalStationNum,3);
|
|
reCharge.put("高告警数量", chargeHighAlarmsNum); //高告警数量
|
//reCharge.put("告警总数", totalStationAlarmNum); //告警总数
|
//reCharge.put("告警总数比例", chargeRateStr); //告警总数比例
|
//reCharge.put("告警机房总数", chargeTotalAlarmStations); //告警机房总数
|
//reCharge.put("告警机房数比例", chargeStationRateStr); //告警机房数比例
|
resultMap.put("reCharge", reCharge);
|
|
return new Response<Map>().set(1,resultMap);
|
}
|
|
|
/**
|
* 单体电压、内阻和温度
|
* alm_id 电池告警参数
|
* 三个告警总数不同,带条件?电压、内阻、温度
|
* @param userId
|
* @return
|
*/
|
public Response<Map> getMonVRTAnalysis(int userId) {
|
|
Response<Map> response = new Response();
|
HashMap<String, Object> resultMap = new HashMap<>();
|
Map<String, Object> monVolMap = new HashMap<>();//单体电压 Alarm_vol_Monomer =119005;
|
Map<String, Object> monResMap = new HashMap<>();//单体内阻 Alarm_res_Monomer =119007
|
Map<String, Object> monTemMap = new HashMap<>();//单体温度 Alarm_tmp_Monomer =119006
|
|
/*======单体电压======*/
|
|
//高告警数量
|
Integer volHighAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonVolHigh);
|
//低告警数量
|
Integer volLowAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonVolLow);
|
|
//单体电压总告警数
|
//Integer volTotalAlarmNum = volHighAlarmsNum+volLowAlarmsNum;
|
|
//告警总数
|
//Integer totalStationAlarmNum =mapper.getTotalAlarms(userId);
|
|
//电压告警机房数
|
//int volTotalAlarmStations = mapper.getTotalAlarmStations(userId,AlarmConstant.Alarm_vol_Monomer);
|
|
//总机房数
|
//int totalStationNum = infoMapper.getStationCount(userId);
|
|
//电压告警占比
|
//String volRateStr = (String) MathUtil.divide(volTotalAlarmNum,totalStationAlarmNum,3);
|
//电压告警机房占比
|
//String volStationRateStr = (String) MathUtil.divide(volTotalAlarmStations,totalStationNum,3);
|
|
|
monVolMap.put("高告警数量", volHighAlarmsNum); //高告警数量 alm_signal_id 9
|
monVolMap.put("低告警数量", volLowAlarmsNum); //低告警数量 alm_signal_id 10
|
//monVolMap.put("告警总数", volTotalAlarmNum); //告警总数
|
//monVolMap.put("告警总数比例", volRateStr); //告警总数比例
|
//monVolMap.put("告警机房总数", volTotalAlarmStations); //告警机房总数
|
//monVolMap.put("告警机房数比例", volStationRateStr); //告警机房数比例
|
resultMap.put("单体电压", monVolMap);
|
|
|
|
/*======单体内阻======*/
|
|
//高告警数量
|
Integer resHighAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonResHigh);
|
//低告警数量
|
Integer resLowAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonResLow);
|
|
//单体内阻总告警数
|
//Integer resTotalAlarmNum = resHighAlarmsNum+resLowAlarmsNum;
|
|
//内阻告警机房数
|
//int resTotalAlarmStations = mapper.getTotalAlarmStations(userId,AlarmConstant.Alarm_res_Monomer);
|
|
//内阻告警占比
|
//String resRateStr = (String) MathUtil.divide(resTotalAlarmNum,totalStationAlarmNum,3);
|
//内阻告警机房占比
|
//String resStationRateStr = (String) MathUtil.divide(resTotalAlarmStations,totalStationNum,3);
|
|
monResMap.put("高告警数量", resHighAlarmsNum); //高告警数量 alm_signal_id 13
|
monResMap.put("低告警数量", resLowAlarmsNum); //低告警数量 alm_signal_id 14
|
//monResMap.put("告警总数", resTotalAlarmNum); //告警总数
|
//monResMap.put("告警总数比例", resRateStr); //告警总数比例
|
//monResMap.put("告警机房总数", resTotalAlarmStations); //告警机房总数
|
//monResMap.put("告警机房数比例", resStationRateStr); //告警机房数比例
|
resultMap.put("单体内阻", monResMap);
|
|
/*======单体温度======*/
|
|
//高告警数量
|
Integer tempHighAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonTmpHigh);
|
//低告警数量
|
Integer tempLowAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonTmpLow);
|
|
//单体温度总告警数
|
//Integer tempTotalAlarmNum = tempHighAlarmsNum+tempLowAlarmsNum;
|
|
//温度告警机房数
|
//int tempTotalAlarmStations = mapper.getTotalAlarmStations(userId,AlarmConstant.Alarm_tmp_Monomer);
|
|
//温度告警占比
|
//String tempRateStr = (String) MathUtil.divide(tempTotalAlarmNum,totalStationAlarmNum,3);
|
//温度告警机房占比
|
//String tempStationRateStr = (String) MathUtil.divide(tempTotalAlarmStations,totalStationNum,3);
|
|
monTemMap.put("高告警数量", tempHighAlarmsNum); //高告警数量 alm_signal_id 13
|
monTemMap.put("低告警数量", tempLowAlarmsNum); //低告警数量 alm_signal_id 14
|
//monTemMap.put("告警总数", tempTotalAlarmNum); //告警总数
|
//monTemMap.put("告警总数比例", tempRateStr); //告警总数比例
|
//monTemMap.put("告警机房总数", tempTotalAlarmStations); //告警机房总数
|
//monTemMap.put("告警机房数比例", tempStationRateStr); //告警机房数比例
|
resultMap.put("单体温度", monTemMap);
|
|
response.setCode(1);
|
response.setData(resultMap);
|
return response;
|
}
|
|
/**
|
* 单个告警-通过告警标识id
|
* @param userId
|
* @param alarmSignalId
|
* @param alarmName
|
* @return
|
*/
|
private Map<String,Object> getSingleAnalysisOfSignal(int userId,int alarmSignalId,String alarmName){
|
Map<String, Object> resMap = new HashMap<>();
|
|
//告警数量
|
Integer alarmNum = mapper.getAlarmHighLow(userId,alarmSignalId);
|
|
//告警总数
|
Integer totalAlarmNum =mapper.getTotalAlarms(userId);
|
|
//告警机房数
|
int alarmStationNum = mapper.getTotalAlarmStations(userId,alarmSignalId);
|
|
//总机房数
|
int totalStationNum = infoMapper.getStationCount(userId);
|
|
//告警占比
|
String rate = (String) MathUtil.divide(alarmNum,totalAlarmNum,3);
|
//告警机房占比
|
String stationRate = (String) MathUtil.divide(alarmStationNum,totalStationNum,3);
|
|
resMap.put(alarmName,alarmNum); //告警数量
|
resMap.put("告警总数", totalAlarmNum); //告警总数
|
resMap.put("告警总数比例", rate); //告警总数比例
|
resMap.put("告警机房总数", totalStationNum); //告警机房总数
|
resMap.put("告警机房数比例", stationRate); //告警机房数比例
|
return resMap;
|
}
|
|
/**
|
* 2个告警-通过告警id,告警标识id
|
* @param userId
|
* @param alarmIds 告警id列表
|
* @param alarmSignalIds 告警标识id列表,为@alarmIds的两倍
|
* @param alarmNames 告警名称,是单体电压/单体xxx
|
* @param mapName1 map的名1
|
* @param mapName2 map的名2
|
* @return
|
*/
|
private Map<String,Map> getDoubleAnalysis(int userId,List<Integer> alarmIds,List<Integer> alarmSignalIds,
|
List<String> alarmNames,String mapName1,String mapName2){
|
Map<String,Map> res = new HashMap<>();
|
for (int i = 0; i < alarmIds.size(); i++) {
|
Map<String, Object> resMap = new HashMap<>();
|
//告警1数量
|
Integer alarmNum = mapper.getAlarmHighLow(userId,alarmSignalIds.get(i));
|
//告警2数量
|
Integer alarmNum2 = mapper.getAlarmHighLow(userId,alarmSignalIds.get(i)+1);
|
|
//告警总数
|
//Integer totalAlarmNum =alarmNum+alarmNum2;
|
|
//总告警数
|
//Integer totalAlarms = mapper.getTotalAlarms(userId);
|
|
//告警机房数
|
//int alarmStationNum = mapper.getTotalAlarmStations(userId,alarmIds.get(i));
|
|
//总机房数
|
//int totalStationNum = infoMapper.getStationCount(userId);
|
|
//告警占比
|
//String rate = (String) MathUtil.divide(totalAlarmNum,totalAlarms,3);
|
//告警机房占比
|
//String stationRate = (String) MathUtil.divide(alarmStationNum,totalStationNum,3);
|
|
resMap.put(mapName1,alarmNum); //告警1数量
|
resMap.put(mapName2,alarmNum2); //告警2数量
|
//resMap.put("告警总数", totalAlarmNum); //告警总数
|
//resMap.put("告警总数比例", rate); //告警总数比例
|
//resMap.put("告警机房总数", alarmStationNum); //告警机房总数
|
//resMap.put("告警机房数比例", stationRate); //告警机房数比例
|
res.put(alarmNames.get(i),resMap);
|
}
|
return res;
|
}
|
|
}
|