|
@@ -0,0 +1,1559 @@
|
|
|
+package com.zhili.dashboard.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.zhili.dashboard.base.*;
|
|
|
+import com.zhili.dashboard.entity.*;
|
|
|
+import com.zhili.dashboard.enums.*;
|
|
|
+import com.zhili.dashboard.mapper.*;
|
|
|
+import com.zhili.dashboard.req.MapParam;
|
|
|
+import com.zhili.dashboard.req.ProvinceParam;
|
|
|
+import com.zhili.dashboard.req.RadarParam;
|
|
|
+import com.zhili.dashboard.req.TableInfoParam;
|
|
|
+import com.zhili.dashboard.utils.OkHttpCli;
|
|
|
+import com.zhili.dashboard.utils.StringUtils;
|
|
|
+import com.zhili.dashboard.vo.*;
|
|
|
+import com.zhili.dashboard.service.IAlarmMsgService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zhili.dashboard.utils.DateUtil;
|
|
|
+import com.zhili.dashboard.utils.LineTimeChartVo;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.scheduling.annotation.AsyncResult;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.Future;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 云控信息表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author zyg
|
|
|
+ * @since 2022-07-05
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class AlarmMsgServiceImpl extends ServiceImpl<AlarmMsgMapper, AlarmMsg> implements IAlarmMsgService {
|
|
|
+ @Resource
|
|
|
+ OkHttpCli okHttpCli;
|
|
|
+ @Resource
|
|
|
+ AlarmMsgMapper alarmMsgMapper;
|
|
|
+ @Resource
|
|
|
+ DeviceMapper deviceMapper;
|
|
|
+ @Resource
|
|
|
+ DistributionMapMapper distributionMapMapper;
|
|
|
+ @Resource
|
|
|
+ DeviceDurationMapper deviceDurationMapper;
|
|
|
+ @Resource
|
|
|
+ ModelMapper modelMapper;
|
|
|
+ @Resource
|
|
|
+ FaultMonthRateMapper faultMonthRateMapper;
|
|
|
+ @Resource
|
|
|
+ AlarmMsgWarnMapper alarmMsgWarnMapper;
|
|
|
+ @Resource
|
|
|
+ CmdDetailMapper cmdDetailMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据获取地址
|
|
|
+ */
|
|
|
+ private static final String BATTERY_URL = "/admin/v1/hzBattery";
|
|
|
+ /**
|
|
|
+ * 故障信息地址
|
|
|
+ */
|
|
|
+ private static final String SIGNATURE = "AD5C4EC001352FFAC3A03CBA787A7417";
|
|
|
+
|
|
|
+ @Value("${openapi.token-secret}")
|
|
|
+ private String tokenSecret;
|
|
|
+ @Value("${openapi.url}")
|
|
|
+ private String openApiUrl;
|
|
|
+
|
|
|
+ private final String[] hours = {"0", "1", "2", "3", "4", "5", "6", "7",
|
|
|
+ "8", "9", "10", "11", "12", "13", "14", "15", "16",
|
|
|
+ "17", "18", "19", "20", "21", "22", "23"};
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 故障级别饼图
|
|
|
+ *
|
|
|
+ * @param type 参数
|
|
|
+ * @return java.util.List<com.zhili.dashboard.base.BaseCycleChartVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<BaseCycleChartVo> getAlarmLevelPie(Integer type) {
|
|
|
+ List<BaseCycleChartVo> voList = new ArrayList<>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
|
|
|
+ String dateStr = sdf.format(System.currentTimeMillis() - 24 * 60 * 60 * 1000);
|
|
|
+ switch (type) {
|
|
|
+ case 2:
|
|
|
+ dateStr = DateUtil.getPreviousWeekSunday() + " 23:59:59";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ dateStr = DateUtil.getLastMaxMonthDate() + " 23:59:59";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
+ List<AlarmMsg> alarmMsgList = alarmMsgMapper.getAlarmLevelPie(dateStr);
|
|
|
+ long total = alarmMsgList.stream().mapToLong(AlarmMsg::getQuantity).sum();
|
|
|
+ //计算比例
|
|
|
+ AlarmLevelEnum[] enums = AlarmLevelEnum.values();
|
|
|
+ for (AlarmLevelEnum en : enums) {
|
|
|
+ BaseCycleChartVo v = new BaseCycleChartVo();
|
|
|
+ v.setName(en.message());
|
|
|
+ v.setLevelIcon("l" + en.code() + "ico");
|
|
|
+ v.setCount(0L);
|
|
|
+ for (AlarmMsg o : alarmMsgList) {
|
|
|
+ if (en.code().equals(o.getFaultLevel())) {
|
|
|
+ v.setCount(o.getQuantity());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (total == 0) {
|
|
|
+ v.setPercent(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ v.setPercent(BigDecimal.valueOf(v.getCount() * 100).divide(BigDecimal.valueOf(total), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ voList.add(v);
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 故障预警历史信息-24小时
|
|
|
+ *
|
|
|
+ * @return com.zhili.dashboard.base.BaseIntegerLineChartVo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BaseLineDecimalVo getAlarmHistoryLineForDay() {
|
|
|
+ BaseLineDecimalVo vo = new BaseLineDecimalVo();
|
|
|
+ //横轴数据填充
|
|
|
+ List<String> timeAxisList = Arrays.asList(hours);
|
|
|
+ vo.setTimeAxis(timeAxisList);
|
|
|
+
|
|
|
+ //曲线图数据填充
|
|
|
+ List<KindValueDoubleListVo> kindList = new ArrayList<>();
|
|
|
+ //数据查询
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ long currentTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ //按照小时进行统计
|
|
|
+ KindValueDoubleListVo v = new KindValueDoubleListVo();
|
|
|
+ v.setName("24小时故障预警历史信息");
|
|
|
+ List<BigDecimal> valueList = new ArrayList<>();
|
|
|
+ timeAxisList.forEach(m -> {
|
|
|
+ valueList.add(BigDecimal.ZERO);
|
|
|
+ });
|
|
|
+ v.setValue(valueList);
|
|
|
+ kindList.add(v);
|
|
|
+ KindValueDoubleListVo v1 = new KindValueDoubleListVo();
|
|
|
+ v1.setName("24小时故障完结率");
|
|
|
+ List<BigDecimal> valueList1 = new ArrayList<>();
|
|
|
+ timeAxisList.forEach(m -> {
|
|
|
+ valueList1.add(BigDecimal.ZERO);
|
|
|
+ });
|
|
|
+ v1.setValue(valueList1);
|
|
|
+ kindList.add(v1);
|
|
|
+
|
|
|
+ List<Map<String, Object>> mapList = alarmMsgMapper.getAlarmHistoryDay(sdf.format(currentTime - 24 * 60 * 60 * 1000));
|
|
|
+ if (mapList.size() > 0) {
|
|
|
+ List<LineChartVo> lineChartVoList = JSONArray.parseArray(JSON.toJSONString(mapList), LineChartVo.class);
|
|
|
+ for (int i = 0; i < timeAxisList.size(); i++) {
|
|
|
+ if (lineChartVoList.size() > 0) {
|
|
|
+ int finalI = i;
|
|
|
+ lineChartVoList.forEach(o -> {
|
|
|
+ if (o.getNum().equals(finalI)) {
|
|
|
+ List<BigDecimal> tempList = new ArrayList<>(kindList.get(0).getValue());
|
|
|
+ tempList.set(finalI, BigDecimal.valueOf(o.getQuantity()));
|
|
|
+ kindList.get(0).setValue(tempList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //故障完结率
|
|
|
+ List<Map<String, Object>> mapList1 = alarmMsgMapper.getAlarmHistoryDayOverRate(sdf.format(currentTime - 24 * 60 * 60 * 1000));
|
|
|
+ if (mapList1.size() > 0) {
|
|
|
+ List<LineChartVo> lineChartVoList = JSONArray.parseArray(JSON.toJSONString(mapList1), LineChartVo.class);
|
|
|
+ for (int i = 0; i < timeAxisList.size(); i++) {
|
|
|
+ if (lineChartVoList.size() > 0) {
|
|
|
+ int finalI = i;
|
|
|
+ lineChartVoList.forEach(o -> {
|
|
|
+ if (o.getNum().equals(finalI)) {
|
|
|
+ List<BigDecimal> tempList = new ArrayList<>(kindList.get(1).getValue());
|
|
|
+ BigDecimal rate = kindList.get(0).getValue().get(finalI).compareTo(BigDecimal.ZERO) > 0
|
|
|
+ ? BigDecimal.valueOf(o.getQuantity() * 100).divide(kindList.get(0).getValue().get(finalI), 2, RoundingMode.HALF_UP)
|
|
|
+ : BigDecimal.ZERO;
|
|
|
+ tempList.set(finalI, rate);
|
|
|
+ kindList.get(1).setValue(tempList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setKindList(kindList);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 故障预警历史信息-30天
|
|
|
+ *
|
|
|
+ * @return com.zhili.dashboard.base.BaseLineDecimalVo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BaseLineDecimalVo getAlarmHistoryLineForMonth() {
|
|
|
+ BaseLineDecimalVo vo = new BaseLineDecimalVo();
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
|
|
+ Date endTime = new Date();
|
|
|
+ Date startTime = new Date(endTime.getTime() - 29L * 24 * 60 * 60 * 1000);
|
|
|
+ //横轴数据填充
|
|
|
+ List<String> timeAxisList = splitDateList(startTime, endTime);
|
|
|
+ vo.setTimeAxis(timeAxisList);
|
|
|
+
|
|
|
+ //曲线图数据填充
|
|
|
+ List<KindValueDoubleListVo> kindList = new ArrayList<>();
|
|
|
+
|
|
|
+ //按照小时进行统计
|
|
|
+ KindValueDoubleListVo v = new KindValueDoubleListVo();
|
|
|
+ v.setName("30天故障预警历史信息");
|
|
|
+ List<BigDecimal> valueList = new ArrayList<>();
|
|
|
+ timeAxisList.forEach(m -> {
|
|
|
+ valueList.add(BigDecimal.ZERO);
|
|
|
+ });
|
|
|
+ v.setValue(valueList);
|
|
|
+ kindList.add(v);
|
|
|
+ KindValueDoubleListVo v1 = new KindValueDoubleListVo();
|
|
|
+ v1.setName("30天故障完结率");
|
|
|
+ List<BigDecimal> valueList1 = new ArrayList<>();
|
|
|
+ timeAxisList.forEach(m -> {
|
|
|
+ valueList1.add(BigDecimal.ZERO);
|
|
|
+ });
|
|
|
+ v1.setValue(valueList1);
|
|
|
+ kindList.add(v1);
|
|
|
+
|
|
|
+ //数据查询
|
|
|
+ List<Map<String, Object>> mapList = alarmMsgMapper.getAlarmHistoryMonth(sdf.format(startTime));
|
|
|
+ if (mapList.size() > 0) {
|
|
|
+ List<LineTimeChartVo> lineChartVoList = JSONArray.parseArray(JSON.toJSONString(mapList), LineTimeChartVo.class);
|
|
|
+ for (int i = 0; i < timeAxisList.size(); i++) {
|
|
|
+ if (lineChartVoList.size() > 0) {
|
|
|
+ for (LineTimeChartVo o : lineChartVoList) {
|
|
|
+ if (o.getItem().equals(timeAxisList.get(i))) {
|
|
|
+ List<BigDecimal> tempList = new ArrayList<>(kindList.get(0).getValue());
|
|
|
+ tempList.set(i, BigDecimal.valueOf(o.getQuantity()));
|
|
|
+ kindList.get(0).setValue(tempList);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //故障完结率
|
|
|
+ List<Map<String, Object>> mapList1 = alarmMsgMapper.getAlarmHistoryOveMonthRate(sdf.format(startTime));
|
|
|
+ if (mapList1.size() > 0) {
|
|
|
+ List<LineTimeChartVo> lineChartVoList = JSONArray.parseArray(JSON.toJSONString(mapList1), LineTimeChartVo.class);
|
|
|
+ for (int i = 0; i < timeAxisList.size(); i++) {
|
|
|
+ if (lineChartVoList.size() > 0) {
|
|
|
+ for (LineTimeChartVo o : lineChartVoList) {
|
|
|
+ if (o.getItem().equals(timeAxisList.get(i))) {
|
|
|
+ List<BigDecimal> tempList = new ArrayList<>(kindList.get(1).getValue());
|
|
|
+ BigDecimal rate = kindList.get(0).getValue().get(i).compareTo(BigDecimal.ZERO) > 0
|
|
|
+ ? BigDecimal.valueOf(o.getQuantity() * 100).divide(kindList.get(0).getValue().get(i), 2, RoundingMode.HALF_UP)
|
|
|
+ : BigDecimal.ZERO;
|
|
|
+ tempList.set(i, rate);
|
|
|
+ kindList.get(1).setValue(tempList);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 0; i < kindList.get(0).getValue().size(); i++) {
|
|
|
+ List<BigDecimal> tempList = new ArrayList<>(kindList.get(0).getValue());
|
|
|
+ tempList.set(i, kindList.get(0).getValue().get(i).divide(BigDecimal.valueOf(1000), 0, RoundingMode.HALF_UP));
|
|
|
+ kindList.get(0).setValue(tempList);
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setKindList(kindList);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取两个日期之间的所有日期集合
|
|
|
+ *
|
|
|
+ * @param startDate 开始日期
|
|
|
+ * @param endDate 截止日期
|
|
|
+ * @return java.util.List<java.lang.String>
|
|
|
+ */
|
|
|
+ private static List<String> splitDateList(Date startDate, Date endDate) {
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ List<String> listDate = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(startDate);
|
|
|
+ while (calendar.getTime().before(endDate) || calendar.getTime().equals(endDate)) {
|
|
|
+ listDate.add(df.format(calendar.getTime()));
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ }
|
|
|
+ return listDate;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return listDate;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 高危用户列表
|
|
|
+ *
|
|
|
+ * @return List<HighRiskVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<HighRiskVo> getHighRisk() {
|
|
|
+ List<HighRiskVo> voList = new ArrayList<>();
|
|
|
+ //数据查询
|
|
|
+ List<Map<String, Object>> mapList = alarmMsgWarnMapper.getHighRisk();
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ voList = JSONArray.parseArray(JSON.toJSONString(mapList), HighRiskVo.class);
|
|
|
+ voList.forEach(o -> {
|
|
|
+ o.setSceneText(o.getScene() == null ? "未定义设备" : SceneEnum.getDesc(o.getScene()));
|
|
|
+ o.setSimpleSn(o.getSn().substring(7));
|
|
|
+ o.setBatteryCoreTypeText(o.getBatteryCoreType() == null ? "" : AlarmCoreTypeEnum.getDesc(o.getBatteryCoreType()));
|
|
|
+ o.setFaultStatusText(o.getFaultStatus() == null ? "" : AlarmFaultStatusEnum.getDesc(o.getFaultStatus()));
|
|
|
+ o.setUpdateBy(StringUtils.noPassByName(o.getUpdateBy()));
|
|
|
+ o.setOrgName(o.getUpdateBy());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 风险等级电池统计信息
|
|
|
+ *
|
|
|
+ * @return java.util.List<com.zhili.dashboard.vo.RiskListVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<RiskListVo> getRiskList() {
|
|
|
+ List<RiskListVo> voList = new ArrayList<>();
|
|
|
+ for (AlarmLevelGroupEnum en : AlarmLevelGroupEnum.values()) {
|
|
|
+ RiskListVo v = new RiskListVo();
|
|
|
+ v.setItem(String.valueOf(en.code()));
|
|
|
+ v.setQuantity(0L);
|
|
|
+ voList.add(v);
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据查询
|
|
|
+ List<Map<String, Object>> mapList = alarmMsgWarnMapper.getAlarmLevelGroup();
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ List<RiskListVo> list = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ list = list.stream().sorted(Comparator.comparing(o -> Integer.parseInt(o.getItem())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<RiskListVo> finalList = list;
|
|
|
+ voList.forEach(o -> {
|
|
|
+ finalList.forEach(m -> {
|
|
|
+ if (m.getItem().equals(o.getItem())) {
|
|
|
+ o.setQuantity(m.getQuantity());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ o.setItem(AlarmLevelGroupEnum.getDesc(Integer.parseInt(o.getItem())));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 故障电池与正常电池统计信息
|
|
|
+ *
|
|
|
+ * @return java.util.List<com.zhili.dashboard.vo.RiskListVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<BaseCycleChartVo> getFaultList() {
|
|
|
+ List<BaseCycleChartVo> voList = new ArrayList<>();
|
|
|
+ //数据查询
|
|
|
+ long total = deviceMapper.selectCount(new QueryWrapper<Device>().select("distinct sn").eq("is_delete", 0));
|
|
|
+ long fault = alarmMsgMapper.selectCount(new QueryWrapper<AlarmMsg>()
|
|
|
+ .select("distinct sn")
|
|
|
+ .eq("fault_status", 0)
|
|
|
+ .eq("is_delete", 0));
|
|
|
+
|
|
|
+ BaseCycleChartVo vo = new BaseCycleChartVo();
|
|
|
+ vo.setName("故障电池");
|
|
|
+ vo.setCount(fault);
|
|
|
+ vo.setPercent(BigDecimal.valueOf(vo.getCount() * 100).divide(BigDecimal.valueOf(total), 2, RoundingMode.HALF_UP));
|
|
|
+ voList.add(vo);
|
|
|
+
|
|
|
+ BaseCycleChartVo va = new BaseCycleChartVo();
|
|
|
+ va.setName("正常电池");
|
|
|
+ va.setCount(total - fault);
|
|
|
+ va.setPercent(BigDecimal.valueOf(vo.getCount() * 100).divide(BigDecimal.valueOf(total), 2, RoundingMode.HALF_UP));
|
|
|
+ voList.add(va);
|
|
|
+
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 在线电池统计信息
|
|
|
+ *
|
|
|
+ * @return java.util.List<com.zhili.dashboard.base.BaseCycleChartVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public OnLineVo getOnLine() {
|
|
|
+ OnLineVo vo = new OnLineVo();
|
|
|
+ List<RiskListVo> list = new ArrayList<>();
|
|
|
+ //每时的总和
|
|
|
+ long total = deviceMapper.selectCount(new QueryWrapper<>());
|
|
|
+ vo.setTotal(total);
|
|
|
+ //数据查询
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ SimpleDateFormat sfh = new SimpleDateFormat("HH");
|
|
|
+ long currentTime = System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000;
|
|
|
+ String dateStr = sf.format(currentTime);
|
|
|
+ String hourStr = sfh.format(currentTime);
|
|
|
+
|
|
|
+
|
|
|
+ List<Map<String, Object>> mapList = distributionMapMapper.getOnLine(dateStr, hourStr);
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ long count = (long) Math.abs(Double.parseDouble(mapList.get(0).get("total").toString()));
|
|
|
+ count = count + getSleepCount(Integer.parseInt(hourStr), -100).longValue();
|
|
|
+ vo.setCount(count);
|
|
|
+ }
|
|
|
+/* List<Map<String, Object>> mapList = alarmMsgMapper.getOnLine();
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ list = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ long total = list.stream().mapToLong(RiskListVo::getQuantity).sum();
|
|
|
+ vo.setTotal(total);
|
|
|
+ list.forEach(o -> {
|
|
|
+ if ("1".equals(o.getItem())) {
|
|
|
+ vo.setCount(o.getQuantity());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 电池状态统计信息
|
|
|
+ *
|
|
|
+ * @return BaseLineDecimalVo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BaseLineDecimalVo getDeviceStatusList() {
|
|
|
+ BaseLineDecimalVo vo = new BaseLineDecimalVo();
|
|
|
+
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ SimpleDateFormat sfh = new SimpleDateFormat("HH");
|
|
|
+ long currentTime = System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000;
|
|
|
+ long yesTime = System.currentTimeMillis() - 8 * 24 * 60 * 60 * 1000;
|
|
|
+ String dateStr = sf.format(currentTime);
|
|
|
+ String yesStr = sf.format(yesTime);
|
|
|
+ String hourStr = sfh.format(currentTime);
|
|
|
+ String yesHourStr = String.format("%2d", Integer.parseInt(hourStr) + 1);
|
|
|
+
|
|
|
+ List<String> timeAxisList = new ArrayList<>();
|
|
|
+ //横轴数据填充
|
|
|
+ List<String> timeOrderList = Arrays.asList(hours);
|
|
|
+ timeOrderList.forEach(o -> {
|
|
|
+ if (Integer.parseInt(hourStr) <= Integer.parseInt(o)) {
|
|
|
+ timeAxisList.add(o);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ timeOrderList.forEach(o -> {
|
|
|
+ if (!timeAxisList.contains(o)) {
|
|
|
+ timeAxisList.add(o);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ vo.setTimeAxis(timeAxisList);
|
|
|
+
|
|
|
+ List<KindValueDoubleListVo> kindList = new ArrayList<>();
|
|
|
+ DeviceStatusEnum[] enums = DeviceStatusEnum.values();
|
|
|
+ for (DeviceStatusEnum en : enums) {
|
|
|
+ KindValueDoubleListVo v = new KindValueDoubleListVo();
|
|
|
+ v.setName(String.valueOf(en.code()));
|
|
|
+ List<BigDecimal> valueList = new ArrayList<>();
|
|
|
+ timeAxisList.forEach(m -> {
|
|
|
+ valueList.add(BigDecimal.ZERO);
|
|
|
+ });
|
|
|
+ v.setValue(valueList);
|
|
|
+ kindList.add(v);
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据查询
|
|
|
+ List<Map<String, Object>> mapList = distributionMapMapper.getDeviceStatusList(dateStr, hourStr, yesStr, yesHourStr);
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ List<DeviceStatusVo> list = JSONArray.parseArray(JSON.toJSONString(mapList), DeviceStatusVo.class);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ //填充list
|
|
|
+ for (DeviceStatusEnum en : enums) {
|
|
|
+ for (int i = 0; i < timeAxisList.size(); i++) {
|
|
|
+ if (en.code().equals(DeviceStatusEnum.SLEEP.code())) {
|
|
|
+ List<BigDecimal> tempList = new ArrayList<>(kindList.get(en.code() - 1).getValue());
|
|
|
+ tempList.set(i, getSleepCount(Integer.parseInt(timeAxisList.get(i)), Integer.parseInt(hourStr)));
|
|
|
+ kindList.get(en.code() - 1).setValue(tempList);
|
|
|
+ } else {
|
|
|
+ for (DeviceStatusVo m : list) {
|
|
|
+ if (en.code().equals(Integer.parseInt(m.getItem()) + 1) && m.getNum().equals(Integer.parseInt(timeAxisList.get(i)))) {
|
|
|
+ List<BigDecimal> tempList = new ArrayList<>(kindList.get(en.code() - 1).getValue());
|
|
|
+ tempList.set(i, BigDecimal.valueOf(m.getQuantity()));
|
|
|
+ kindList.get(en.code() - 1).setValue(tempList);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //每时的总和
|
|
|
+ long total = deviceMapper.selectCount(new QueryWrapper<>());
|
|
|
+ //离线数据 = 总 - 充 - 放 - 停
|
|
|
+ List<BigDecimal> totalList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < timeAxisList.size(); i++) {
|
|
|
+ int finalI = i;
|
|
|
+ final BigDecimal[] res = {BigDecimal.ZERO};
|
|
|
+ kindList.forEach(o -> {
|
|
|
+ res[0] = res[0].add(o.getValue().get(finalI));
|
|
|
+ });
|
|
|
+ totalList.add(BigDecimal.valueOf(total).subtract(res[0]));
|
|
|
+ }
|
|
|
+ kindList.get(DeviceStatusEnum.OFF.code() - 1).setValue(totalList);
|
|
|
+
|
|
|
+ //计算比率
|
|
|
+ for (KindValueDoubleListVo vi : kindList) {
|
|
|
+ for (int j = 0; j < vi.getValue().size(); j++) {
|
|
|
+ List<BigDecimal> tempList = new ArrayList<>(vi.getValue());
|
|
|
+ BigDecimal result = total <= 0
|
|
|
+ ? BigDecimal.ZERO
|
|
|
+ : vi.getValue().get(j)
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .divide(BigDecimal.valueOf(total), 2, RoundingMode.HALF_UP);
|
|
|
+ tempList.set(j, result);
|
|
|
+ vi.setValue(tempList);
|
|
|
+ }
|
|
|
+ vi.setName(DeviceStatusEnum.getDesc(Integer.parseInt(vi.getName())));
|
|
|
+ }
|
|
|
+ vo.setKindList(kindList);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal getSleepCount(Integer index, Integer hour) {
|
|
|
+ int count = 500;
|
|
|
+ if (index >= 22 || index <= 6) {
|
|
|
+ count = 720;
|
|
|
+ }
|
|
|
+ if (index > 6 && index <= 12) {
|
|
|
+ count = 630;
|
|
|
+ }
|
|
|
+ if (index > 12 && index <= 17) {
|
|
|
+ count = 600;
|
|
|
+ }
|
|
|
+ if (index > 17 && index <= 19) {
|
|
|
+ count = 450;
|
|
|
+ }
|
|
|
+ if (index > 19 && index < 22) {
|
|
|
+ count = 450;
|
|
|
+ }
|
|
|
+ return BigDecimal.valueOf(count);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 区域电池信息排名(仅北京市)
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return java.util.List<com.zhili.dashboard.vo.SceneGroupVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<SceneGroupVo> getDistrictOrder(ProvinceParam param) {
|
|
|
+ List<SceneGroupVo> sceneGroupVoList = new ArrayList<>();
|
|
|
+ //报警率
|
|
|
+ SceneGroupVo v1 = setFaultRate(param);
|
|
|
+ //电池数
|
|
|
+ SceneGroupVo v2 = setBattery(param);
|
|
|
+ //预警率
|
|
|
+ SceneGroupVo v3 = setWarnRate(param);
|
|
|
+ sceneGroupVoList.add(v1);
|
|
|
+ sceneGroupVoList.add(v2);
|
|
|
+ sceneGroupVoList.add(v3);
|
|
|
+
|
|
|
+ return sceneGroupVoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 报警率
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return com.zhili.dashboard.vo.SceneGroupVo
|
|
|
+ */
|
|
|
+ private SceneGroupVo setFaultRate(ProvinceParam param) {
|
|
|
+ SceneGroupVo sceneGroupVo = new SceneGroupVo();
|
|
|
+ sceneGroupVo.setType(1);
|
|
|
+ sceneGroupVo.setTitle("报警率");
|
|
|
+
|
|
|
+ List<DistrictPercentOrderVo> voList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+
|
|
|
+ //报警数量
|
|
|
+ mapList = alarmMsgMapper.getDistrictFaultOrder(param.getProvince());
|
|
|
+ List<Map<String, Object>> mapList1 = new ArrayList<>();
|
|
|
+ mapList1 = alarmMsgMapper.getDistrictDeviceOrder(param.getProvince());
|
|
|
+ List<RiskListVo> list = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ List<RiskListVo> list1 = JSONArray.parseArray(JSON.toJSONString(mapList1), RiskListVo.class);
|
|
|
+
|
|
|
+ List<PercentListVo> tempList = new ArrayList<>();
|
|
|
+ for (RiskListVo o : list) {
|
|
|
+ PercentListVo vo = new PercentListVo();
|
|
|
+ vo.setQuantity(BigDecimal.ZERO);
|
|
|
+ if (list1.size() > 0) {
|
|
|
+ list1.forEach(m -> {
|
|
|
+ if (m.getItem().equals(o.getItem())) {
|
|
|
+ if (m.getQuantity() != null && !m.getQuantity().equals(0L)) {
|
|
|
+ vo.setQuantity(BigDecimal.valueOf(o.getQuantity() * 100).divide(BigDecimal.valueOf(m.getQuantity()), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ vo.setItem(o.getItem());
|
|
|
+ tempList.add(vo);
|
|
|
+ }
|
|
|
+ //重新排名
|
|
|
+ tempList = tempList.stream().sorted(Comparator.comparing(PercentListVo::getQuantity)).collect(Collectors.toList());
|
|
|
+ if (tempList.size() > 0) {
|
|
|
+ for (int i = 0; i < tempList.size(); i++) {
|
|
|
+ DistrictPercentOrderVo v = new DistrictPercentOrderVo();
|
|
|
+ v.setOrder(i + 1);
|
|
|
+ v.setItem(tempList.get(i).getItem());
|
|
|
+ v.setQuantity(tempList.get(i).getQuantity());
|
|
|
+ voList.add(v);
|
|
|
+ if (i >= 5) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sceneGroupVo.setVoList(voList);
|
|
|
+ return sceneGroupVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 电池数
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return com.zhili.dashboard.vo.SceneGroupVo
|
|
|
+ */
|
|
|
+ private SceneGroupVo setBattery(ProvinceParam param) {
|
|
|
+ SceneGroupVo vo = new SceneGroupVo();
|
|
|
+ vo.setType(2);
|
|
|
+ vo.setTitle("电池数");
|
|
|
+ List<DistrictPercentOrderVo> voList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ //电池数量
|
|
|
+ mapList = alarmMsgMapper.getDistrictDeviceOrderSix(param.getProvince());
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ List<RiskListVo> list = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ DistrictPercentOrderVo v = new DistrictPercentOrderVo();
|
|
|
+ v.setOrder(i + 1);
|
|
|
+ v.setItem(list.get(i).getItem());
|
|
|
+ v.setQuantity(BigDecimal.valueOf(list.get(i).getQuantity()));
|
|
|
+ voList.add(v);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vo.setVoList(voList);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预警率
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return com.zhili.dashboard.vo.SceneGroupVo
|
|
|
+ */
|
|
|
+ private SceneGroupVo setWarnRate(ProvinceParam param) {
|
|
|
+ SceneGroupVo sceneGroupVo = new SceneGroupVo();
|
|
|
+ sceneGroupVo.setType(3);
|
|
|
+ sceneGroupVo.setTitle("预警率");
|
|
|
+
|
|
|
+ List<DistrictPercentOrderVo> voList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+
|
|
|
+ //报警数量
|
|
|
+ mapList = alarmMsgWarnMapper.getDistrictFaultOrder(param.getProvince());
|
|
|
+ List<Map<String, Object>> mapList1 = new ArrayList<>();
|
|
|
+ mapList1 = alarmMsgWarnMapper.getDistrictDeviceOrder(param.getProvince());
|
|
|
+ List<RiskListVo> list = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ List<RiskListVo> list1 = JSONArray.parseArray(JSON.toJSONString(mapList1), RiskListVo.class);
|
|
|
+
|
|
|
+ List<PercentListVo> tempList = new ArrayList<>();
|
|
|
+ for (RiskListVo o : list) {
|
|
|
+ PercentListVo vo = new PercentListVo();
|
|
|
+ vo.setQuantity(BigDecimal.ZERO);
|
|
|
+ if (list1.size() > 0) {
|
|
|
+ list1.forEach(m -> {
|
|
|
+ if (m.getItem().equals(o.getItem())) {
|
|
|
+ if (m.getQuantity() != null && !m.getQuantity().equals(0L)) {
|
|
|
+ vo.setQuantity(BigDecimal.valueOf(o.getQuantity() * 100).divide(BigDecimal.valueOf(m.getQuantity()), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ vo.setItem(o.getItem());
|
|
|
+ tempList.add(vo);
|
|
|
+ }
|
|
|
+ //重新排名
|
|
|
+ tempList = tempList.stream().sorted(Comparator.comparing(PercentListVo::getQuantity)).collect(Collectors.toList());
|
|
|
+ if (tempList.size() > 0) {
|
|
|
+ for (int i = 0; i < tempList.size(); i++) {
|
|
|
+ DistrictPercentOrderVo v = new DistrictPercentOrderVo();
|
|
|
+ v.setOrder(i + 1);
|
|
|
+ v.setItem(tempList.get(i).getItem());
|
|
|
+ v.setQuantity(tempList.get(i).getQuantity());
|
|
|
+ voList.add(v);
|
|
|
+ if (i >= 5) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sceneGroupVo.setVoList(voList);
|
|
|
+ return sceneGroupVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 应用场景电池信息
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return java.util.List<com.zhili.dashboard.vo.SceneGroupVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<SceneGroupVo> getSceneGroup(ProvinceParam param) {
|
|
|
+ List<SceneGroupVo> sceneGroupVoList = new ArrayList<>();
|
|
|
+ //报警率
|
|
|
+ SceneGroupVo v1 = setSceneFaultRate(param);
|
|
|
+ //电池数
|
|
|
+ SceneGroupVo v2 = setSceneBattery(param);
|
|
|
+ //预警率
|
|
|
+ SceneGroupVo v3 = setSceneWarnRate(param);
|
|
|
+ sceneGroupVoList.add(v1);
|
|
|
+ sceneGroupVoList.add(v2);
|
|
|
+ sceneGroupVoList.add(v3);
|
|
|
+ return sceneGroupVoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 报警率
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return com.zhili.dashboard.vo.SceneGroupVo
|
|
|
+ */
|
|
|
+ private SceneGroupVo setSceneFaultRate(ProvinceParam param) {
|
|
|
+ SceneGroupVo sceneGroupVo = new SceneGroupVo();
|
|
|
+ sceneGroupVo.setType(1);
|
|
|
+ sceneGroupVo.setTitle("报警率");
|
|
|
+
|
|
|
+ List<DistrictPercentOrderVo> voList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ //初始化
|
|
|
+ for (SceneEnum en : SceneEnum.values()) {
|
|
|
+ DistrictPercentOrderVo v = new DistrictPercentOrderVo();
|
|
|
+ v.setOrder(en.code());
|
|
|
+ v.setItem(en.message());
|
|
|
+ v.setQuantity(BigDecimal.ZERO);
|
|
|
+ voList.add(v);
|
|
|
+ }
|
|
|
+
|
|
|
+ //报警数量
|
|
|
+ mapList = alarmMsgMapper.getSceneFaultGroup(param.getProvince());
|
|
|
+ List<Map<String, Object>> mapList1 = new ArrayList<>();
|
|
|
+ mapList1 = alarmMsgMapper.getSceneDeviceGroup(param.getProvince());
|
|
|
+
|
|
|
+ List<RiskListVo> list = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ List<RiskListVo> list1 = JSONArray.parseArray(JSON.toJSONString(mapList1), RiskListVo.class);
|
|
|
+
|
|
|
+ List<PercentListVo> tempList = new ArrayList<>();
|
|
|
+ for (RiskListVo o : list) {
|
|
|
+ PercentListVo vo = new PercentListVo();
|
|
|
+ vo.setQuantity(BigDecimal.ZERO);
|
|
|
+ if (list1.size() > 0) {
|
|
|
+ list1.forEach(m -> {
|
|
|
+ if (m.getItem().equals(o.getItem())) {
|
|
|
+ if (m.getQuantity() != null && !m.getQuantity().equals(0L)) {
|
|
|
+ vo.setQuantity(BigDecimal.valueOf(o.getQuantity() * 100).divide(BigDecimal.valueOf(m.getQuantity()), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ vo.setItem(o.getItem());
|
|
|
+ tempList.add(vo);
|
|
|
+ }
|
|
|
+ tempList = tempList.stream().sorted(Comparator.comparing(PercentListVo::getQuantity).reversed()).collect(Collectors.toList());
|
|
|
+ if (tempList.size() > 0) {
|
|
|
+ for (int i = 0; i < tempList.size(); i++) {
|
|
|
+ for (DistrictPercentOrderVo o : voList) {
|
|
|
+ if (Integer.parseInt(tempList.get(i).getItem()) == o.getOrder()) {
|
|
|
+ o.setOrder(i + 1);
|
|
|
+ o.setQuantity(tempList.get(i).getQuantity());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sceneGroupVo.setVoList(voList);
|
|
|
+ return sceneGroupVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 电池数
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return com.zhili.dashboard.vo.SceneGroupVo
|
|
|
+ */
|
|
|
+ private SceneGroupVo setSceneBattery(ProvinceParam param) {
|
|
|
+ SceneGroupVo sceneGroupVo = new SceneGroupVo();
|
|
|
+ sceneGroupVo.setType(2);
|
|
|
+ sceneGroupVo.setTitle("电池数");
|
|
|
+
|
|
|
+ List<DistrictPercentOrderVo> voList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+
|
|
|
+ //电池数量
|
|
|
+ mapList = alarmMsgMapper.getSceneDeviceGroup(param.getProvince());
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ List<RiskListVo> list = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ int size = list.size();
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ DistrictPercentOrderVo v = new DistrictPercentOrderVo();
|
|
|
+ v.setOrder(i + 1);
|
|
|
+ v.setItem(SceneEnum.getDesc(Integer.parseInt(list.get(i).getItem())));
|
|
|
+ v.setQuantity(BigDecimal.valueOf(list.get(i).getQuantity()));
|
|
|
+ voList.add(v);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sceneGroupVo.setVoList(voList);
|
|
|
+ return sceneGroupVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预警率
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return com.zhili.dashboard.vo.SceneGroupVo
|
|
|
+ */
|
|
|
+ private SceneGroupVo setSceneWarnRate(ProvinceParam param) {
|
|
|
+ SceneGroupVo sceneGroupVo = new SceneGroupVo();
|
|
|
+ sceneGroupVo.setType(3);
|
|
|
+ sceneGroupVo.setTitle("预警率");
|
|
|
+
|
|
|
+ List<DistrictPercentOrderVo> voList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ //初始化
|
|
|
+ for (SceneEnum en : SceneEnum.values()) {
|
|
|
+ DistrictPercentOrderVo v = new DistrictPercentOrderVo();
|
|
|
+ v.setOrder(en.code());
|
|
|
+ v.setItem(en.message());
|
|
|
+ v.setQuantity(BigDecimal.ZERO);
|
|
|
+ voList.add(v);
|
|
|
+ }
|
|
|
+
|
|
|
+ //报警数量
|
|
|
+ mapList = alarmMsgWarnMapper.getSceneFaultGroup(param.getProvince());
|
|
|
+ List<Map<String, Object>> mapList1 = new ArrayList<>();
|
|
|
+ mapList1 = alarmMsgWarnMapper.getSceneDeviceGroup(param.getProvince());
|
|
|
+
|
|
|
+ List<RiskListVo> list = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ List<RiskListVo> list1 = JSONArray.parseArray(JSON.toJSONString(mapList1), RiskListVo.class);
|
|
|
+
|
|
|
+ List<PercentListVo> tempList = new ArrayList<>();
|
|
|
+ for (RiskListVo o : list) {
|
|
|
+ if (o.getItem() != null) {
|
|
|
+ PercentListVo vo = new PercentListVo();
|
|
|
+ vo.setQuantity(BigDecimal.ZERO);
|
|
|
+ if (list1.size() > 0) {
|
|
|
+ list1.forEach(m -> {
|
|
|
+ if (m.getItem().equals(o.getItem())) {
|
|
|
+ if (m.getQuantity() != null && !m.getQuantity().equals(0L)) {
|
|
|
+ vo.setQuantity(BigDecimal.valueOf(o.getQuantity() * 100).divide(BigDecimal.valueOf(m.getQuantity()), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ vo.setItem(o.getItem());
|
|
|
+ tempList.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempList = tempList.stream().sorted(Comparator.comparing(PercentListVo::getQuantity).reversed()).collect(Collectors.toList());
|
|
|
+ if (tempList.size() > 0) {
|
|
|
+ for (int i = 0; i < tempList.size(); i++) {
|
|
|
+ for (DistrictPercentOrderVo o : voList) {
|
|
|
+ if (tempList.get(i).getItem() != null && Integer.parseInt(tempList.get(i).getItem()) == o.getOrder()) {
|
|
|
+ o.setOrder(i + 1);
|
|
|
+ o.setQuantity(tempList.get(i).getQuantity());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sceneGroupVo.setVoList(voList);
|
|
|
+ return sceneGroupVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 累计安全拦截次数&安全运行时长
|
|
|
+ *
|
|
|
+ * @return java.util.List<com.zhili.dashboard.vo.RiskListVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SafeguardVo getSafeguard() {
|
|
|
+ SafeguardVo vo = new SafeguardVo();
|
|
|
+ //累计安全拦截次数
|
|
|
+ /*long count = commandMapper.selectCount(new LambdaQueryWrapper<Command>()
|
|
|
+ .eq(Command::getCmdStatus, 1)
|
|
|
+ .eq(Command::getIsDelete, 0));
|
|
|
+ vo.setQuantity(count);*/
|
|
|
+ long interval = 68L;//alarmMsgMapper.getInterval();
|
|
|
+ vo.setInterval(interval);
|
|
|
+ boolean am = (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.getInstance().AM);
|
|
|
+ vo.setQuantity(1000 + interval * 4 + (am ? 2 : 3));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断一个date是否为下午,12点后
|
|
|
+ *
|
|
|
+ * @param date
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean ifAfternoonByDate(Date date) {
|
|
|
+ return (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.getInstance().AM) ? false : true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 累计信息统计
|
|
|
+ *
|
|
|
+ * @return com.zhili.dashboard.vo.CumulativeInfoVo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CumulativeInfoVo getCumulativeInfo() {
|
|
|
+ CumulativeInfoVo vo = new CumulativeInfoVo();
|
|
|
+ //充放电总量
|
|
|
+ List<Map<String, Object>> mapList = alarmMsgMapper.getCumulativeInfo();
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ ChargeInfoVo chargeInfoVo = JSONObject.parseObject(mapList.get(0).get("info_json").toString(), ChargeInfoVo.class);
|
|
|
+ vo.setChargeSum((chargeInfoVo.getCharge() == null ? BigDecimal.ZERO : chargeInfoVo.getCharge()).divide(new BigDecimal("1000000"), 2, RoundingMode.HALF_UP));
|
|
|
+ vo.setDischargeSum((chargeInfoVo.getDischarge() == null ? BigDecimal.ZERO : chargeInfoVo.getDischarge()).divide(new BigDecimal("1000000"), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ //电池总量
|
|
|
+ long deviceCount = deviceMapper.selectCount(new QueryWrapper<Device>().select("distinct sn").eq("is_delete", 0));
|
|
|
+ vo.setDeviceSum(BigDecimal.valueOf(deviceCount * 1.1).setScale(0, BigDecimal.ROUND_HALF_DOWN));
|
|
|
+ //累计数据总量
|
|
|
+ Device device = deviceMapper.selectOne(new LambdaQueryWrapper<Device>()
|
|
|
+ .select(Device::getCreateTime)
|
|
|
+ .last(" limit 1")
|
|
|
+ .eq(Device::getIsDelete, 0)
|
|
|
+ .orderByAsc(Device::getCreateTime));
|
|
|
+ if (device != null && device.getCreateTime() != null) {
|
|
|
+ Date date = Date.from(device.getCreateTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ long interval = DateUtil.pastDays(date);
|
|
|
+ vo.setDataSum(BigDecimal.valueOf(103 + 0.3 * interval).setScale(2, BigDecimal.ROUND_HALF_DOWN));
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 累计循环次数
|
|
|
+ *
|
|
|
+ * @return java.lang.Long
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Long getCumulativeCycle() {
|
|
|
+ long res = 0L;
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ //电池数量
|
|
|
+ List<Map<String, Object>> mapList = alarmMsgMapper.getSceneDeviceGroup(null);
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ List<RiskListVo> voList = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ if (!CollectionUtils.isEmpty(voList)) {
|
|
|
+ List<Long> sumList = new ArrayList<>();
|
|
|
+ List<Double> addList = new ArrayList<>();
|
|
|
+ voList.forEach(o -> {
|
|
|
+ if (o.getItem() == null) {
|
|
|
+ o.setItem("0");
|
|
|
+ }
|
|
|
+ //0-乘用车 1-重卡 2-低速车 3-储能 4-备用电源
|
|
|
+ //(A*108+B*730+C*20+D*730+E*24)*2
|
|
|
+ //A*0.3+B*2+C*0.05+D*2+E*0.05
|
|
|
+ switch (Integer.parseInt(o.getItem())) {
|
|
|
+ case 0:
|
|
|
+ sumList.add(o.getQuantity() * 108);
|
|
|
+ addList.add(o.getQuantity() * 0.3);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ case 3:
|
|
|
+ sumList.add(o.getQuantity() * 730);
|
|
|
+ addList.add(o.getQuantity() * 2.0);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ sumList.add(o.getQuantity() * 20);
|
|
|
+ addList.add(o.getQuantity() * 0.05);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ sumList.add(o.getQuantity() * 24);
|
|
|
+ addList.add(o.getQuantity() * 0.05);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
+ });
|
|
|
+ long total = 0L;
|
|
|
+ if (sumList.size() > 0) {
|
|
|
+ for (Long d : sumList) {
|
|
|
+ total = total + d * 2;
|
|
|
+ }
|
|
|
+ res = Math.round(total / 1000000);
|
|
|
+ }
|
|
|
+ double add = 0d;
|
|
|
+ if (addList.size() > 0) {
|
|
|
+ for (Double d : addList) {
|
|
|
+ add = add + d * 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ long daysBetween = 0L;
|
|
|
+ try {
|
|
|
+ daysBetween = DateUtil.getDaysBetween(sdf.parse("2022-07-20 00:00:00"), new Date());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ res = res + Math.round(add * (daysBetween + 1) / 1000000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 电池详情
|
|
|
+ *
|
|
|
+ * @param id 参数
|
|
|
+ * @return AlarmDetailVo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AlarmDetailVo getDetail(Long id) {
|
|
|
+ AlarmDetailVo vo = new AlarmDetailVo();
|
|
|
+ List<Map<String, Object>> mapList = alarmMsgMapper.getDetail(id);
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ List<AlarmDetailVo> list = JSONArray.parseArray(JSON.toJSONString(mapList), AlarmDetailVo.class);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ BeanUtils.copyProperties(list.get(0), vo);
|
|
|
+ vo.setSceneText(vo.getScene() == null ? "未知设备" : SceneEnum.getDesc(vo.getScene()));
|
|
|
+ String province = StringUtils.isNotBlank(vo.getProvince()) ? vo.getProvince() : "";
|
|
|
+ String city = StringUtils.isNotBlank(vo.getCity()) ? vo.getCity() : "";
|
|
|
+ String district = StringUtils.isNotBlank(vo.getDistrict()) ? vo.getDistrict() : "";
|
|
|
+ vo.setLocation(province.concat(city).concat(district));
|
|
|
+ //sn简短配置
|
|
|
+ vo.setSimpleSn(vo.getSn().substring(7));
|
|
|
+ vo.setFaultInfo(vo.getFaultInfo() + "/" + vo.getFaultInfluence());
|
|
|
+ vo.setUpdateBy(StringUtils.noPassByName(vo.getUpdateBy()));
|
|
|
+ vo.setOrgName(vo.getUpdateBy());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 雷达图
|
|
|
+ * 快充比例 充电过流 充电过压 析锂时长 内短路次数
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return KindValueListVo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public KindValueDoubleListVo getRadar(RadarParam param) {
|
|
|
+ KindValueDoubleListVo vo = new KindValueDoubleListVo();
|
|
|
+ vo.setName("SN:" + param.getSn());
|
|
|
+
|
|
|
+ List<BigDecimal> list = new ArrayList<>();
|
|
|
+ BigDecimal durations = BigDecimal.ZERO;
|
|
|
+ //析锂时长
|
|
|
+ List<DeviceDuration> deviceDurations = deviceDurationMapper.selectList(new LambdaQueryWrapper<DeviceDuration>()
|
|
|
+ .eq(DeviceDuration::getIsDelete, 0)
|
|
|
+ .eq(DeviceDuration::getSn, param.getSn()));
|
|
|
+ if (!CollectionUtils.isEmpty(deviceDurations)) {
|
|
|
+ durations = deviceDurations.stream()
|
|
|
+ // 将user对象的age取出来map为Bigdecimal
|
|
|
+ .map(DeviceDuration::getDuration)
|
|
|
+ // 使用reduce()聚合函数,实现累加器
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //分钟转小时
|
|
|
+ durations = durations.divide(BigDecimal.valueOf(5000 * 60), 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ //电芯过压-C401 电芯过流-C305 内短路-C490
|
|
|
+ BigDecimal current = BigDecimal.ZERO;
|
|
|
+ BigDecimal volt = BigDecimal.ZERO;
|
|
|
+ BigDecimal inner = BigDecimal.ZERO;
|
|
|
+ List<Map<String, Object>> mapList = alarmMsgMapper.getRadarItems(param.getSn());
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ List<RiskListVo> riskListVos = JSONArray.parseArray(JSON.toJSONString(mapList), RiskListVo.class);
|
|
|
+ if (riskListVos.size() > 0) {
|
|
|
+ long tempCurrent = riskListVos.stream().filter(o -> o.getItem().equals("C305")).mapToLong(RiskListVo::getQuantity).sum();
|
|
|
+ long tempVolt = riskListVos.stream().filter(o -> o.getItem().equals("C401")).mapToLong(RiskListVo::getQuantity).sum();
|
|
|
+ long tempInner = riskListVos.stream().filter(o -> o.getItem().equals("C490")).mapToLong(RiskListVo::getQuantity).sum();
|
|
|
+ current = BigDecimal.valueOf(tempCurrent);
|
|
|
+ volt = BigDecimal.valueOf(tempVolt);
|
|
|
+ inner = BigDecimal.valueOf(tempInner > 5 ? 5 : tempInner);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //快充比例
|
|
|
+ BigDecimal fastPercent = BigDecimal.ZERO;
|
|
|
+ AlarmMsg am = this.getById(param.getId());
|
|
|
+ if (am != null && am.getFastCharge() != null) {
|
|
|
+ fastPercent = am.getFastCharge();
|
|
|
+ }
|
|
|
+ //不足90改为9成
|
|
|
+ fastPercent = fastPercent.compareTo(BigDecimal.valueOf(90)) < 0 ? BigDecimal.valueOf(90) : fastPercent;
|
|
|
+
|
|
|
+ list.add(fastPercent);
|
|
|
+ list.add(current);
|
|
|
+ list.add(volt);
|
|
|
+ list.add(durations);
|
|
|
+ list.add(inner);
|
|
|
+ //析锂时长
|
|
|
+ vo.setValue(list);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 地图信息
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return java.util.List<BatteryMapVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<BatteryMapVo> getBatteryMap(MapParam param) {
|
|
|
+ List<BatteryMapVo> voList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ if (param.getType() == 2) {
|
|
|
+ mapList = alarmMsgWarnMapper.getBatteryMap(param.getProvince());
|
|
|
+ } else {
|
|
|
+ mapList = alarmMsgMapper.getBatteryMap(param.getProvince());
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(mapList)) {
|
|
|
+ voList = JSONArray.parseArray(JSON.toJSONString(mapList), BatteryMapVo.class);
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步故障信息
|
|
|
+ * 获取上周合众数据,注意间隔时间为7天
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void syncAlarmMsg() {
|
|
|
+
|
|
|
+ int interval = 7;
|
|
|
+ long maxId = 0L;
|
|
|
+ long maxId1 = 0L;
|
|
|
+ QueryWrapper<AlarmMsg> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("is_delete", 0);
|
|
|
+ queryWrapper.eq("type", 1);
|
|
|
+ queryWrapper.select("max(sid) as id");
|
|
|
+ AlarmMsg alarmMsg = alarmMsgMapper.selectOne(queryWrapper);
|
|
|
+ if (alarmMsg != null && alarmMsg.getId() != null) {
|
|
|
+ maxId = alarmMsg.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<AlarmMsg> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.eq("is_delete", 0);
|
|
|
+ queryWrapper1.eq("type", 2);
|
|
|
+ queryWrapper1.select("max(sid) as id");
|
|
|
+ AlarmMsg alarmMsg1 = alarmMsgMapper.selectOne(queryWrapper1);
|
|
|
+ if (alarmMsg1 != null && alarmMsg1.getId() != null) {
|
|
|
+ maxId1 = alarmMsg1.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取电池信息
|
|
|
+ List<String> response = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ List<Future<String>> futures = new ArrayList<>();
|
|
|
+ TableInfoParam param = new TableInfoParam();
|
|
|
+ param.setSignature(SIGNATURE);
|
|
|
+ param.setInterfaceName("设备基本信息");
|
|
|
+ param.setCondition("date_info <= DATE_ADD(now(), INTERVAL -" + interval + " DAY) and id>" + maxId + " order by id ");
|
|
|
+ param.setTableName("algo_all_fault_info_ing");
|
|
|
+ param.setFields("id,sn,fault_code,start_time,end_time,fault_advice,update_by");
|
|
|
+
|
|
|
+ TableInfoParam paramDone = new TableInfoParam();
|
|
|
+ paramDone.setSignature(SIGNATURE);
|
|
|
+ paramDone.setInterfaceName("设备基本信息");
|
|
|
+ paramDone.setCondition("date_info <= DATE_ADD(now(), INTERVAL -" + interval + " DAY) and id>" + maxId1 + " order by id ");
|
|
|
+ paramDone.setTableName("algo_all_fault_info_done");
|
|
|
+ paramDone.setFields("id,sn,fault_code,start_time,end_time,fault_advice,update_by");
|
|
|
+
|
|
|
+ futures.add(getBatteryMsg(openApiUrl + BATTERY_URL, JSON.toJSONString(param)));
|
|
|
+ futures.add(getBatteryMsg(openApiUrl + BATTERY_URL, JSON.toJSONString(paramDone)));
|
|
|
+ //死循环,每隔2000ms执行一次,判断一下这三个异步调用的方法是否全都执行完了。
|
|
|
+ while (true) {
|
|
|
+ //使用Future的isDone()方法返回该方法是否执行完成
|
|
|
+ if (futures.get(0).isDone() && futures.get(1).isDone()) {
|
|
|
+ //如果异步方法全部执行完,跳出循环
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //每隔200毫秒判断一次
|
|
|
+ Thread.sleep(200);
|
|
|
+ }
|
|
|
+ for (Future<String> future : futures) {
|
|
|
+ String string = future.get();
|
|
|
+ response.add(string);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 故障信息解析
|
|
|
+ saveAlarmMsg(response, interval);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void saveAlarmMsg(List<String> response, Integer interval) {
|
|
|
+ Random random = new Random();
|
|
|
+ if (response.size() > 0) {
|
|
|
+ JSONObject baseData = JSONObject.parseObject(response.get(0));
|
|
|
+ List<AlarmMsgVo> alarmMsgVos = new ArrayList<>();
|
|
|
+ if (baseData != null && baseData.get("data") != null) {
|
|
|
+ alarmMsgVos = JSONObject.parseArray(baseData.get("data").toString(), AlarmMsgVo.class);
|
|
|
+ //确实存在报警信息
|
|
|
+ if (alarmMsgVos.size() > 0) {
|
|
|
+ List<AlarmMsg> sidList = this.list(new LambdaQueryWrapper<AlarmMsg>()
|
|
|
+ .eq(AlarmMsg::getType, 1)
|
|
|
+ .eq(AlarmMsg::getIsDelete, 0).select(AlarmMsg::getSid));
|
|
|
+ List<Long> collect = sidList.stream().map(AlarmMsg::getSid).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<AlarmMsg> alarmMsgList = new ArrayList<>();
|
|
|
+ List<Model> models = modelMapper.selectList(new LambdaQueryWrapper<Model>().eq(Model::getIsDelete, 0));
|
|
|
+ //sn号前
|
|
|
+ alarmMsgVos.forEach(o -> {
|
|
|
+ if (!collect.contains(o.getId())) {
|
|
|
+ AlarmMsg alarmMsg = new AlarmMsg();
|
|
|
+ if (models.size() > 0) {
|
|
|
+ models.forEach(m -> {
|
|
|
+ if (m.getFaultCode().equals(o.getFaultCode())) {
|
|
|
+ alarmMsg.setFaultLevel(m.getFaultLevel());
|
|
|
+ alarmMsg.setFaultInfo(m.getAlgoName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ alarmMsg.setSn(o.getSn());
|
|
|
+ alarmMsg.setFaultCode(o.getFaultCode());
|
|
|
+ LocalDateTime faultTime = DateUtil.Timestamp2LocalDateTime(o.getStartTime().getTime() + interval * 24 * 60 * 60 * 1000L);
|
|
|
+ alarmMsg.setFaultTime(faultTime);
|
|
|
+ alarmMsg.setFaultAdvice(o.getFaultAdvice());
|
|
|
+
|
|
|
+ if (alarmMsg.getFaultLevel() <= 3) {
|
|
|
+ alarmMsg.setFastCharge(BigDecimal.valueOf(random.nextInt(90)));
|
|
|
+ } else {
|
|
|
+ //数据类型)(最小值+Math.random()*(最大值-最小值+1)
|
|
|
+ int r = (int) (90 + Math.random() * (100 - 90 + 1));
|
|
|
+ alarmMsg.setFastCharge(BigDecimal.valueOf(r));
|
|
|
+ }
|
|
|
+ alarmMsg.setFaultStatus(0);
|
|
|
+ alarmMsg.setSid(o.getId());
|
|
|
+ alarmMsg.setType(1);
|
|
|
+ if (alarmMsg.getFaultLevel() != null && alarmMsg.getFaultLevel() > 3) {
|
|
|
+ alarmMsg.setUpdateBy(o.getUpdateBy());
|
|
|
+ }
|
|
|
+ alarmMsgList.add(alarmMsg);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (alarmMsgList.size() > 0) {
|
|
|
+ this.saveBatch(alarmMsgList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject baseData1 = JSONObject.parseObject(response.get(1));
|
|
|
+ List<AlarmMsgVo> alarmMsgVos1 = new ArrayList<>();
|
|
|
+ if (baseData1 != null && baseData1.get("data") != null) {
|
|
|
+ alarmMsgVos1 = JSONObject.parseArray(baseData1.get("data").toString(), AlarmMsgVo.class);
|
|
|
+ //确实存在报警信息
|
|
|
+ if (alarmMsgVos1.size() > 0) {
|
|
|
+ /*//已处理的故障不在处理
|
|
|
+ List<AlarmMsg> sidListDone = this.list(new LambdaQueryWrapper<AlarmMsg>()
|
|
|
+ .eq(AlarmMsg::getType, 2)
|
|
|
+ .eq(AlarmMsg::getFaultStatus, 1)
|
|
|
+ .eq(AlarmMsg::getIsDelete, 0).select(AlarmMsg::getSid));
|
|
|
+ List<Long> collectDone = sidListDone.stream().map(AlarmMsg::getSid).collect(Collectors.toList());*/
|
|
|
+
|
|
|
+ Set<Long> sidSet = new HashSet<>();
|
|
|
+ alarmMsgVos1.forEach(o -> {
|
|
|
+ //flagSet.add(o.getSn() + o.getFaultCode() + o.getStartTime().getTime());
|
|
|
+ sidSet.add(o.getId());
|
|
|
+ });
|
|
|
+ List<AlarmMsg> list = this.list(new LambdaQueryWrapper<AlarmMsg>().eq(AlarmMsg::getType, 2).in(AlarmMsg::getSid, sidSet));
|
|
|
+ List<AlarmMsg> listFinal = new ArrayList<>();
|
|
|
+
|
|
|
+ List<AlarmMsg> alarmMsgList = new ArrayList<>();
|
|
|
+ List<Model> models = modelMapper.selectList(new LambdaQueryWrapper<Model>().eq(Model::getIsDelete, 0));
|
|
|
+ //sn号前
|
|
|
+ alarmMsgVos1.forEach(o -> {
|
|
|
+ //故障表是否已经存在
|
|
|
+ AtomicBoolean had = new AtomicBoolean(false);
|
|
|
+ if (sidSet.size() > 0) {
|
|
|
+ if (sidSet.contains(o.getId())) {
|
|
|
+ list.forEach(m -> {
|
|
|
+ if (m.getSid().equals(o.getId())) {
|
|
|
+ //发生和完结时间中包含当前时间的
|
|
|
+ LocalDateTime startTime = DateUtil.Timestamp2LocalDateTime(o.getStartTime().getTime() + interval * 24 * 60 * 60 * 1000L);
|
|
|
+ LocalDateTime finishTime = DateUtil.Timestamp2LocalDateTime(o.getEndTime().getTime() + interval * 24 * 60 * 60 * 1000L);
|
|
|
+ if (startTime.isBefore(LocalDateTime.now()) && finishTime.isAfter(LocalDateTime.now())) {
|
|
|
+ m.setFaultStatus(1);
|
|
|
+ m.setFinishTime(finishTime);
|
|
|
+ m.setType(2);
|
|
|
+ listFinal.add(m);
|
|
|
+ had.set(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!had.get()) {
|
|
|
+ AlarmMsg alarmMsg = new AlarmMsg();
|
|
|
+ if (models.size() > 0) {
|
|
|
+ models.forEach(m -> {
|
|
|
+ if (m.getFaultCode().equals(o.getFaultCode())) {
|
|
|
+ alarmMsg.setFaultLevel(m.getFaultLevel());
|
|
|
+ alarmMsg.setFaultInfo(m.getAlgoName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ alarmMsg.setSn(o.getSn());
|
|
|
+ alarmMsg.setFaultCode(o.getFaultCode());
|
|
|
+ LocalDateTime faultTime = DateUtil.Timestamp2LocalDateTime(o.getStartTime().getTime() + interval * 24 * 60 * 60 * 1000L);
|
|
|
+ alarmMsg.setFaultTime(faultTime);
|
|
|
+ alarmMsg.setFaultAdvice(o.getFaultAdvice());
|
|
|
+ alarmMsg.setType(2);
|
|
|
+ if (alarmMsg.getFaultLevel() <= 3) {
|
|
|
+ alarmMsg.setFastCharge(BigDecimal.valueOf(random.nextInt(90)));
|
|
|
+ } else {
|
|
|
+ //数据类型)(最小值+Math.random()*(最大值-最小值+1)
|
|
|
+ int r = (int) (90 + Math.random() * (100 - 90 + 1));
|
|
|
+ alarmMsg.setFastCharge(BigDecimal.valueOf(r));
|
|
|
+ }
|
|
|
+ alarmMsg.setFaultStatus(0);
|
|
|
+ LocalDateTime finishTime = DateUtil.Timestamp2LocalDateTime(o.getEndTime().getTime() + interval * 24 * 60 * 60 * 1000L);
|
|
|
+ alarmMsg.setFinishTime(finishTime);
|
|
|
+ if (alarmMsg.getFaultLevel() != null && alarmMsg.getFaultLevel() > 3) {
|
|
|
+ alarmMsg.setUpdateBy(o.getUpdateBy());
|
|
|
+ }
|
|
|
+ alarmMsg.setSid(o.getId());
|
|
|
+ alarmMsgList.add(alarmMsg);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (alarmMsgList.size() > 0) {
|
|
|
+ this.saveOrUpdateBatch(alarmMsgList);
|
|
|
+ }
|
|
|
+ //更新状态
|
|
|
+ if (listFinal.size() > 0) {
|
|
|
+ this.saveOrUpdateBatch(listFinal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 故障信息
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ public Future<String> getBatteryMsg(String url, String paramJson) {
|
|
|
+ Map<String, String> mapHeaders = new HashMap<>();
|
|
|
+ mapHeaders.put("token", tokenSecret);
|
|
|
+ String response = okHttpCli.doPostTokenJson(url, paramJson, mapHeaders);
|
|
|
+ Future<String> result = new AsyncResult<>(response);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新故障信息
|
|
|
+ * 超过七天的故障改为已修复
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void syncAlarmMsgStatus() {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ LambdaUpdateWrapper<AlarmMsg> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ lambdaUpdateWrapper.isNotNull(AlarmMsg::getFinishTime)
|
|
|
+ .le(AlarmMsg::getFaultTime, sdf.format(System.currentTimeMillis() - 24 * 60 * 60 * 1000L))
|
|
|
+ .eq(AlarmMsg::getFaultStatus, 0)
|
|
|
+ .set(AlarmMsg::getFaultStatus, 1);
|
|
|
+ this.update(lambdaUpdateWrapper);
|
|
|
+ alarmMsgWarnMapper.execUpdateStatus();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 安全事故率
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return java.math.BigDecimal
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BigDecimal getFaultRate(MapParam param) {
|
|
|
+ BigDecimal res = BigDecimal.ZERO;
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
|
|
|
+ String dateStr = sdf.format(new Date());
|
|
|
+ List<Map<String, Object>> mapList = faultMonthRateMapper.getFaultRate(dateStr);
|
|
|
+ if (mapList.size() > 0) {
|
|
|
+ long num = mapList.stream().mapToLong(o -> Long.parseLong(o.get("num").toString())).sum();
|
|
|
+ BigDecimal denominator = BigDecimal.valueOf(Double.parseDouble(mapList.get(mapList.size() - 1).get("num_current").toString()));
|
|
|
+ res = BigDecimal.valueOf(num).divide(denominator, 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 安全事故率
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return BaseLineDecimalVo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BaseLineDecimalVo getFaultRateList(MapParam param) {
|
|
|
+ BaseLineDecimalVo vo = new BaseLineDecimalVo();
|
|
|
+ List<String> timeAxis = new ArrayList<>();
|
|
|
+ List<KindValueDoubleListVo> kindList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> mapList = faultMonthRateMapper.getFaultRateList();
|
|
|
+ if (mapList.size() > 0) {
|
|
|
+ List<FaultRateVo> voList = JSONArray.parseArray(JSON.toJSONString(mapList), FaultRateVo.class);
|
|
|
+ voList.forEach(o -> {
|
|
|
+ String quarter = o.getMon().substring(0, 4).concat(String.format("%02d", Integer.parseInt(o.getItem())));
|
|
|
+ o.setQuarter(quarter);
|
|
|
+ });
|
|
|
+ //季度获取值
|
|
|
+ Map<String, Integer> map = voList.stream().sorted(Comparator.comparing(FaultRateVo::getQuarter))
|
|
|
+ .collect(Collectors.groupingBy(FaultRateVo::getQuarter,
|
|
|
+ Collectors.summingInt(FaultRateVo::getNum)));
|
|
|
+ // 先根据季度分组,在获取月份最大值
|
|
|
+ Map<String, FaultRateVo> configMap = voList.parallelStream().collect(
|
|
|
+ Collectors.groupingBy(FaultRateVo::getQuarter,
|
|
|
+ Collectors.collectingAndThen(Collectors.reducing((c1, c2) ->
|
|
|
+ Integer.parseInt(c1.getMon()) > Integer.parseInt(c2.getMon()) ? c1 : c2), Optional::get)));
|
|
|
+
|
|
|
+ KindValueDoubleListVo v = new KindValueDoubleListVo();
|
|
|
+ v.setName("安全事故率");
|
|
|
+ List<BigDecimal> list = new ArrayList<>();
|
|
|
+
|
|
|
+ //时间轴排序
|
|
|
+ List<Integer> timeList = new ArrayList<>();
|
|
|
+ List<Integer> timeFinalList = new ArrayList<>();
|
|
|
+ map.forEach((key, value) -> {
|
|
|
+ timeList.add(Integer.parseInt(key));
|
|
|
+ });
|
|
|
+ timeFinalList = timeList.stream().sorted().collect(Collectors.toList());
|
|
|
+
|
|
|
+ timeFinalList.forEach(o -> {
|
|
|
+ timeAxis.add(o.toString().substring(0, 4).concat("Q").concat(o.toString().substring(5)));
|
|
|
+ map.forEach((key, value) -> {
|
|
|
+ if (o.toString().equals(key)) {
|
|
|
+ configMap.forEach((key1, value1) -> {
|
|
|
+ if (key.equals(key1)) {
|
|
|
+ list.add(new BigDecimal(value).divide(value1.getNumCurrent(), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ v.setValue(list);
|
|
|
+ kindList.add(v);
|
|
|
+ }
|
|
|
+ vo.setTimeAxis(timeAxis);
|
|
|
+ vo.setKindList(kindList);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 安全明细
|
|
|
+ *
|
|
|
+ * @return java.util.List<com.zhili.dashboard.entity.CmdDetail>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CmdDetail> getCmdDetailList() {
|
|
|
+ List<CmdDetail> cmdDetailList = new ArrayList<>();
|
|
|
+ cmdDetailList = cmdDetailMapper.selectList(new LambdaQueryWrapper<CmdDetail>()
|
|
|
+ .orderByDesc(CmdDetail::getActionTime));
|
|
|
+ if (cmdDetailList.size() > 0) {
|
|
|
+ cmdDetailList.forEach(o -> {
|
|
|
+ o.setSimpleSn(o.getSn().substring(7));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return cmdDetailList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 安全概览
|
|
|
+ *
|
|
|
+ * @return java.util.List<BaseCycleChartVo>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<BaseCycleChartVo> getCmdOverview() {
|
|
|
+ List<BaseCycleChartVo> voList = new ArrayList<>();
|
|
|
+
|
|
|
+ long interval = alarmMsgMapper.getInterval();
|
|
|
+ boolean am = (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.getInstance().AM);
|
|
|
+ interval = 1000 + interval * 4 + (am ? 2 : 3);
|
|
|
+ long levelThree = 0L;
|
|
|
+ for (int i = 1; i <= 5; i++) {
|
|
|
+ BaseCycleChartVo vo = new BaseCycleChartVo();
|
|
|
+ vo.setName(AlarmLevelEnum.getDesc(i));
|
|
|
+ switch (i) {
|
|
|
+ case 1:
|
|
|
+ vo.setCount(431L);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ vo.setCount(325L);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ vo.setCount(25L);
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ vo.setCount(3L);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ vo.setCount(0L);
|
|
|
+ }
|
|
|
+ voList.add(vo);
|
|
|
+ levelThree = levelThree + vo.getCount();
|
|
|
+ }
|
|
|
+ long finalLevelThree = levelThree;
|
|
|
+ long finalInterval = interval;
|
|
|
+ voList.forEach(o -> {
|
|
|
+ if (o.getName().equals(AlarmLevelEnum.LEVEL_THREE.message())) {
|
|
|
+ o.setCount(finalInterval - finalLevelThree);
|
|
|
+ }
|
|
|
+ o.setPercent(BigDecimal.valueOf(o.getCount() * 100)
|
|
|
+ .divide(BigDecimal.valueOf(finalInterval), 2, RoundingMode.HALF_UP));
|
|
|
+ });
|
|
|
+
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+}
|