package com.newfiber.api.pc.service; import com.baomidou.mybatisplus.plugins.Page; import com.newfiber.api.core.utils.CommonUtils; import com.newfiber.api.pc.dao.WarnLogDao; import com.newfiber.api.pc.dao.newmonitoring.StationBaseDao; import com.newfiber.api.pc.model.zhz.WarnLog; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; import java.util.stream.Collectors; @Service public class WarnLogService { @Autowired private WarnLogDao warnLogDao; @Autowired private StationBaseDao stationBaseDao; public List<WarnLog> listWarnLog(Map<String,Object> map, Page<WarnLog> page){ return warnLogDao.listWarnLog(map,page); } public List<Map<String, Object>> getSiteWarnState(Map<String,Object> map){ List<Map<String, Object>> result = new ArrayList<>(); List<WarnLog> siteWarnState = warnLogDao.getSiteWarnState(map); if (siteWarnState != null && siteWarnState.size() > 0){ siteWarnState.stream().collect(Collectors.groupingBy(WarnLog::getSiteNo)).entrySet().forEach(e -> getResult(result,e)); } return result; } private void getResult(List<Map<String, Object>> result, Map.Entry<String, List<WarnLog>> entry) { Integer state = entry.getValue().stream().max(Comparator.comparing(WarnLog::getState)).get().getState(); Map<String,Object> data = new HashMap<>(); data.put("siteNo",entry.getValue().get(0).getSiteNo()); data.put("siteName",entry.getValue().get(0).getSiteName()); data.put("state",state); data.put("factorsAscii",entry.getValue()); result.add(data); } public Map<String,Object> getSiteStateStatistics(String platform){ Map<String,Object> result = new HashMap<>(); List<String> xdata = new ArrayList<>(); List<Integer> offline = new ArrayList<>(); List<Integer> alarm = new ArrayList<>(); List<Integer> warn = new ArrayList<>(); List<Integer> malfunction = new ArrayList<>(); Calendar calendar = Calendar.getInstance(); CommonUtils.setCalenderTime(calendar,null,null,null,null,0,0,0,0); calendar.add(Calendar.DAY_OF_MONTH,-6); for (int i = 0; i < 7; i++) { Date startTime = calendar.getTime(); xdata.add(calendar.get(Calendar.MONTH) + 1 + "/" + calendar.get(Calendar.DAY_OF_MONTH)); calendar.add(Calendar.DAY_OF_MONTH,1); Date endTime = calendar.getTime(); Map<String, Integer> siteStateStatistics = stationBaseDao.getSiteStateStatistics(platform,startTime,endTime); offline.add(siteStateStatistics.get("offline")); alarm.add(siteStateStatistics.get("alarm")); warn.add(siteStateStatistics.get("warn")); malfunction.add(siteStateStatistics.get("malfunction")); } result.put("xdata",xdata); result.put("offline",offline); result.put("alarm",alarm); result.put("warn",warn); result.put("malfunction",malfunction); return result; } public List<WarnLog> getWarnLogOfPlatform(Map<String, Object> map,Page<WarnLog> page){ return warnLogDao.getWarnLogOfPlatform(map,page); } }