123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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<AnalysisLogMapper, AnalysisLog> implements IAnalysisLogService {
- @Autowired
- private WindTowerInfoService windTowerInfoService;
- /**
- * 根据时间范围和设备id查询数据
- *
- * @param startTime 开始时间
- * @param endTime 结束时间
- * @param equipmentId 设备id
- * @return
- */
- public List<AnalysisLog> getByBetweenTimeAndEquipmentId(Date startTime, Date endTime, String equipmentId) {
- QueryWrapper<AnalysisLog> 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<AnalysisLog> getAllList() {
- List list = new ArrayList();
- List<WindTowerInfo> 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<AnalysisLog> 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<AnalysisLog> findByTime(Integer current, Integer size, Long startTime, Long endTime, String equipmentId) {
- QueryWrapper<AnalysisLog> 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<AnalysisLog> 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<AnalysisLog> 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);
- }
- }
|