| | |
| | | |
| | | import com.yssh.dao.*; |
| | | import com.yssh.entity.*; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | @Service |
| | | public class WarningAnalyseServiceImpl implements IWarningAnalyseService { |
| | | |
| | | protected final Log logger = LogFactory.getLog(this.getClass()); |
| | | protected final Logger logger = LoggerFactory.getLogger(this.getClass()); |
| | | |
| | | @Resource |
| | | private WarningDetailMapper warningDetailMapper; |
| | | |
| | | @Resource |
| | | private AlertConfigMapper alertConfigMapper; |
| | | |
| | | @Resource |
| | | private ICommonService commonService; |
| | |
| | | |
| | | List<WarningDetail> list = new ArrayList<>(); |
| | | Calendar calendar = getCalendar(nowDate); |
| | | for (int i = 0; i < 3; i++) { |
| | | for (int i = 0; i < 6; i++) { |
| | | calendar.add(Calendar.HOUR, -1); |
| | | List<WarningDetail> rs = alarmAnalyseOperation(calendar.getTime()); |
| | | List<WarningDetail> rs = getAlarmWarnAnalyse(calendar.getTime(), false); |
| | | if (null != rs && rs.size() > 0) { |
| | | list.addAll(rs); |
| | | } |
| | | } |
| | | list.forEach(s -> { |
| | | result.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue())); |
| | | String time = ymdh.format(s.getCreateTime()); |
| | | result.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue(), time)); |
| | | }); |
| | | return result; |
| | | } |
| | |
| | | |
| | | List<WarningDetail> list = new ArrayList<>(); |
| | | Calendar calendar = getCalendar(nowDate); |
| | | for (int i = 0; i < 3; i++) { |
| | | for (int i = 0; i < 6; i++) { |
| | | calendar.add(Calendar.HOUR, -1); |
| | | List<WarningDetail> rs = warningAnalyseOperation(calendar.getTime()); |
| | | List<WarningDetail> rs = getAlarmWarnAnalyse(calendar.getTime(), true); |
| | | if (null != rs && rs.size() > 0) { |
| | | list.addAll(rs); |
| | | } |
| | | } |
| | | list.forEach(s -> { |
| | | result.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue())); |
| | | String time = ymdh.format(s.getCreateTime()); |
| | | result.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue(), time)); |
| | | }); |
| | | return result; |
| | | } |
| | | |
| | | public List<WarningDetail> alarmAnalyseOperation(Date date) { |
| | | List<WarningDetail> result = new ArrayList<>(); |
| | | String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date); |
| | | private List<WarningDetail> getAlarmWarnAnalyse(Date date, boolean isWarn) { |
| | | List<String> ids = CalculateUtils.assembleId(commonService.getCheckPoints3d()); |
| | | if (ids.size() == 0) { |
| | | return result; |
| | | } |
| | | DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time)); |
| | | if (null == dictRecord) { |
| | | return result; |
| | | } |
| | | String tableName = dictRecord.getTableName(); |
| | | if (suYuanMapper.isTableExists(tableName) == 0) { |
| | | return result; |
| | | } |
| | | |
| | | List<SuYuan2d> list = suYuanMapper.getAlarmsAnalyse(tableName, ids); |
| | | if (null != list && list.size() > 0) { |
| | | for (SuYuan2d s : list) { |
| | | String locationName = commonService.select3dCheckPointById(s.getId()).getName(); |
| | | result.add(new WarningDetail(0L, tableName, s.getId(), locationName, date, 0, s.getValue())); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public List<WarningDetail> warningAnalyseOperation(Date date) { |
| | | List<WarningDetail> result = new ArrayList<>(); |
| | | String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date); |
| | | List<String> ids = CalculateUtils.assembleId(commonService.getCheckPoints3d()); |
| | | if (ids.size() == 0) { |
| | | return result; |
| | | } |
| | | DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time)); |
| | | if (null == dictRecord) { |
| | | return result; |
| | | } |
| | | if (null == dictRecord) return null; |
| | | |
| | | String tableName = dictRecord.getTableName(); |
| | | if (suYuanMapper.isTableExists(tableName) == 0) { |
| | | return result; |
| | | if (suYuanMapper.isTableExists(tableName) == 0) return null; |
| | | |
| | | List<SuYuan2d> list = isWarn ? suYuanMapper.getWarningAnalyse(tableName, ids) : suYuanMapper.getAlarmsAnalyse(tableName, ids); |
| | | if (null == list || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | List<SuYuan2d> list = suYuanMapper.getWarningAnalyse(tableName, ids); |
| | | if (null != list && list.size() > 0) { |
| | | for (SuYuan2d s : list) { |
| | | String locationName = commonService.select3dCheckPointById(s.getId()).getName(); |
| | | result.add(new WarningDetail(0L, tableName, s.getId(), locationName, date, 1, s.getValue())); |
| | | } |
| | | int type = isWarn ? 1 : 0; |
| | | List<WarningDetail> result = new ArrayList<>(); |
| | | for (SuYuan2d s : list) { |
| | | String locationName = commonService.select3dCheckPointById(s.getId()).getName(); |
| | | result.add(new WarningDetail(0L, tableName, s.getId(), locationName, date, type, s.getValue())); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void warningOperationStorage(Date date) { |
| | | List<WarningDetail> allData = new ArrayList<>(); |
| | | List<WarningDetail> alarms = this.alarmAnalyseOperation(date); |
| | | List<WarningDetail> alarms = this.getAlarmWarnAnalyse(date, false); |
| | | if (StringUtils.isNotEmpty(alarms)) { |
| | | allData.addAll(alarms); |
| | | } |
| | | List<WarningDetail> warnings = this.warningAnalyseOperation(date); |
| | | |
| | | List<WarningDetail> warnings = this.getAlarmWarnAnalyse(date, true); |
| | | if (StringUtils.isNotEmpty(warnings)) { |
| | | allData.addAll(warnings); |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(allData)) { |
| | | try { |
| | | insertWarningDetails(allData); |
| | | } catch (Exception e) { |
| | | logger.error("批量插入告警数据出现异常!!!"); |
| | | logger.error("批量插入告警数据出现异常!!!", e); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | |
| | | public Map<String, Integer> countThisMonthAlarmAndWarning() { |
| | | Map<String, Integer> result = new HashMap<>(); |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("type", 0); |
| | | param.put("startTime", DateUtils.getMonthStart()); |
| | | param.put("endTime", DateUtils.getMonthEnd()); |
| | | param.put("startTime", ymdhms.format(DateUtils.getMonthStart())); |
| | | param.put("endTime", ymdhms.format(DateUtils.getMonthEnd())); |
| | | |
| | | /*param.put("type", 0); |
| | | List<WarningVo> alarms = warningDetailMapper.selectWarningDetailByMap(param); |
| | | if (StringUtils.isNull(alarms)) { |
| | | alarms = new ArrayList<>(); |
| | | } |
| | | result.put("alarmNumber", alarms.size()); |
| | | result.put("alarmNumber", alarms.size());*/ |
| | | Integer alarmNum = warningDetailMapper.countAlarmByMap(param); |
| | | result.put("alarmNumber", null == alarmNum ? 0 : alarmNum); |
| | | |
| | | param.put("type", 1); |
| | | List<WarningVo> warnings = warningDetailMapper.selectWarningDetailByMap(param); |
| | | /*List<WarningVo> warnings = warningDetailMapper.selectWarningDetailByMap(param); |
| | | if (StringUtils.isNull(warnings)) { |
| | | warnings = new ArrayList<>(); |
| | | } |
| | | result.put("warningNumber", warnings.size()); |
| | | result.put("warningNumber", warnings.size());*/ |
| | | Integer warnNum = warningDetailMapper.countWarnByMap(param); |
| | | result.put("warningNumber", null == warnNum ? 0 : warnNum); |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public Map<String, List<Double>> select3Hours() { |
| | | Map<String, List<Double>> map = new HashMap<>(); |
| | | Map<String, List<Double>> map = new LinkedHashMap<>(); |
| | | |
| | | List<String> times = DateUtils.get3Hours(); |
| | | List<Qxsh> list = qxshMapper.select3Hours(times); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<WarningVo> getAlarmAndWarnByTime(Date begin, Date end) { |
| | | public List<Report> getAlarmAndWarnByTime(Date begin, Date end) { |
| | | String startTime = ymdhms.format(begin); |
| | | String endTime = ymdhms.format(end); |
| | | |
| | | List<WarningDetail> rs = new ArrayList<>(); |
| | | List<WarningDetail> rsYj = warningDetailMapper.selectByTimeForYj(startTime, endTime); |
| | | if (null != rsYj && rsYj.size() > 0) rs.addAll(rsYj); |
| | | |
| | | List<WarningDetail> rsBj = warningDetailMapper.selectByTimeForBj(startTime, endTime); |
| | | if (null != rsBj && rsBj.size() > 0) rs.addAll(rsBj); |
| | | |
| | | List<Report> list = new ArrayList<>(); |
| | | for (WarningDetail wd : rs) { |
| | | //String time = ymdh.format(wd.getCreateTime()); |
| | | //list.add(new WarningVo(wd.getLocationName(), wd.getSuYuanId(), 0.0, 0.0, wd.getValue(), time)); |
| | | |
| | | DistanceSuYuan suYuan = suYuanMapper.getSuYuanById(wd.getTableName(), wd.getSuYuanId()); |
| | | Double lastVal = warningDetailMapper.getLastYearVal(wd.getId()); |
| | | |
| | | int rows = suYuanMapper.isTableExists(wd.getTableName()); |
| | | DistanceSuYuan suMax = null; |
| | | if (rows > 0) { |
| | | MonitorPointPosition point = commonService.select3dCheckPointByName(wd.getLocationName()); |
| | | List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(point, 50); |
| | | suMax = suYuanMapper.getSuYuan500Max(wd.getTableName(), ids3d); |
| | | } else { |
| | | suMax = suYuan; |
| | | } |
| | | |
| | | Report report = Report.calcReport(wd, suYuan, suMax); |
| | | report.setLastVal(lastVal); |
| | | |
| | | list.add(report); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | public List<WarningVo> getAlarmAndWarnByTime_old(Date begin, Date end) { |
| | | List<WarningVo> list = new ArrayList<>(); |
| | | List<String> ids = CalculateUtils.assembleId(commonService.getCheckPoints3d()); |
| | | if (ids.size() == 0) { |
| | |
| | | for (String tab : tables) { |
| | | List<WarningDetail> alarmList = getAlarmByTime(tab, ids); |
| | | for (WarningDetail s : alarmList) { |
| | | list.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue())); |
| | | String time = ymdh.format(s.getCreateTime()); |
| | | list.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue(), time)); |
| | | } |
| | | } |
| | | for (String tab : tables) { |
| | | List<WarningDetail> warnList = getWarnByTime(tab, ids); |
| | | for (WarningDetail s : warnList) { |
| | | list.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue())); |
| | | String time = ymdh.format(s.getCreateTime()); |
| | | list.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue(), time)); |
| | | } |
| | | } |
| | | |