package com.jiayue.biz.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.jiayue.biz.domain.WindTowerInfo; import com.jiayue.biz.service.WindTowerInfoService; import com.jiayue.biz.util.DateTimeUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jiayue.biz.mapper.AnalysisLogMapper; import com.jiayue.biz.domain.AnalysisLog; import com.jiayue.biz.service.IAnalysisLogService; import java.util.*; /** * 【请填写功能名称】Service业务层处理 * * @author L.ym * @date 2022-05-23 */ @Service public class AnalysisLogServiceImpl extends ServiceImpl implements IAnalysisLogService { @Autowired private WindTowerInfoService windTowerInfoService; /** * 根据时间范围和设备id查询数据 * * @param startTime 开始时间 * @param endTime 结束时间 * @param equipmentId 设备id * @return */ public List getByBetweenTimeAndEquipmentId(Date startTime, Date endTime, String equipmentId) { QueryWrapper wrapper = new QueryWrapper(); if (startTime != null && endTime != null) { wrapper.between("time", startTime, endTime); } if (equipmentId != null && !equipmentId.equals("")) { wrapper.eq("equipment_id", equipmentId); } return baseMapper.selectList(wrapper); } //获取时间是昨天的所有设备的解析记录 @Override public List getAllList() { List list = new ArrayList(); List windTowerInfoList = windTowerInfoService.list(); if (windTowerInfoList.size() > 0) { for (WindTowerInfo windTowerInfo : windTowerInfoList) { Date startTime = DateTimeUtil.getDayStartTime(new Date().getTime() - 1000 * 60 * 60 * 24); Date endTime = DateTimeUtil.getDayLastTime(new Date().getTime() - 1000 * 60 * 60 * 24); Map map = new HashMap(); List analysisLogList = getByBetweenTimeAndEquipmentId(startTime, endTime, windTowerInfo.getEquipmentNo()); if (analysisLogList.size() > 0) { //排序要降序 analysisLogList.sort(Comparator.comparing(AnalysisLog::getTime)); map.put("equipmentId", windTowerInfo.getEquipmentNo()); map.put("status", analysisLogList.get(0).getStatus()); map.put("time", analysisLogList.get(0).getTime()); list.add(map); } else { map.put("equipmentId", windTowerInfo.getEquipmentNo()); map.put("status", "0"); map.put("time", ""); list.add(map); } } } return list; } //根据解析的文件时间查看 @Override public Page findByTime(Integer current, Integer size, Long startTime, Long endTime, String equipmentId) { QueryWrapper wrapper = new QueryWrapper(); if (startTime != null && endTime != null) { wrapper.between("time", new Date(startTime), new Date(endTime)); } if (equipmentId != null && !equipmentId.equals("")) { wrapper.eq("equipment_id", equipmentId); } /*根据时间排序*/ wrapper.orderByAsc("time").orderByAsc("equipment_id"); /*分页*/ Page page = new Page(current, size); Page analysisLogPage = page(page, wrapper); return analysisLogPage; } //当天开始时间 public static Date getTodayStartTime() { Calendar todayStart = Calendar.getInstance(); todayStart.set(Calendar.HOUR_OF_DAY, 0); todayStart.set(Calendar.MINUTE, 0); todayStart.set(Calendar.SECOND, 0); return todayStart.getTime(); } //当天结束时间 public static Date getTodayEndTime() { Calendar todayEnd = Calendar.getInstance(); todayEnd.set(Calendar.HOUR_OF_DAY, 23); todayEnd.set(Calendar.MINUTE, 59); todayEnd.set(Calendar.SECOND, 59); return todayEnd.getTime(); } /** * 根据条件删除 * * @param startTime 开始时间 * @param endTime 结束时间 * @param equipmentId 设备编号 * @return */ public boolean removeByDate(Date startTime, Date endTime, String equipmentId) { QueryWrapper wrapper = new QueryWrapper(); if (startTime != null && endTime != null) { wrapper.between("time", startTime, endTime); } if (equipmentId != null) { wrapper.eq("equipment_id", equipmentId); } return super.remove(wrapper); } }