123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package com.jiayue.biz.service.impl;
- import cn.hutool.db.Entity;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.jiayue.biz.domain.ProphaseWeatherData;
- import com.jiayue.biz.domain.StatisticsSituation;
- import com.jiayue.biz.mapper.ProphaseWeatherDataMapper;
- import com.jiayue.biz.service.ProphaseWeatherDataService;
- import com.jiayue.biz.service.StatisticsSituationService;
- import com.jiayue.common.core.text.Convert;
- import lombok.AllArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.ibatis.annotations.Param;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.sql.Timestamp;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- @Service
- @Slf4j
- public class ProphaseWeatherDataServiceImpl extends ServiceImpl<ProphaseWeatherDataMapper, ProphaseWeatherData> implements ProphaseWeatherDataService {
- @Lazy
- @Resource
- StatisticsSituationService statisticsSituationService;
- //获取测风塔起止时间
- public Map<String, Long> getDataTimeStartAndEnd(String equipmentNo) {
- HashMap<String, Long> hashMap = new HashMap<>();
- hashMap.put("startTime", 0l);
- hashMap.put("endTime", 0l);
- try {
- List<Entity> lastData = baseMapper.getLastData(equipmentNo);
- List<Entity> firstData = baseMapper.getFirstData(equipmentNo);
- if (!lastData.isEmpty() && !firstData.isEmpty()) {
- Timestamp timeEnd = (Timestamp) lastData.get(0).get("last (ts)");
- Timestamp timeStart = (Timestamp) firstData.get(0).get("first (ts)");
- hashMap.put("startTime", timeStart.getTime());
- hashMap.put("endTime", timeEnd.getTime());
- }
- } catch (Exception e) {
- List<StatisticsSituation> statisticsSituationList = statisticsSituationService.list();
- List<StatisticsSituation> collect = statisticsSituationList.stream().filter(s -> s.getEquipmentId().equals(equipmentNo)).collect(Collectors.toList());
- if(collect.size() != 0){
- String[] timeArr = collect.get(0).getStartTimeAndEndTime().split(",");
- hashMap.put("startTime", Long.parseLong(timeArr[0]));
- hashMap.put("endTime", Long.parseLong(timeArr[1]));
- }
- log.error("{} 此测风塔没有表,创建表",equipmentNo);
- try {
- createTable(equipmentNo);
- }catch (Exception e1){
- log.error("创建测风塔设备:{} 的环境表数据失败:{}",equipmentNo,e1);
- }
- }
- return hashMap;
- }
- //根据设备编号取出所有条数
- /*
- td engine 取出的时间需要截取字段
- String wstart = entity.get("_wstart").toString().substring(0, 10);
- formatMap.put(wstart, entity.get("count(*)"));
- */
- public List<Entity> selectCount(String equipmentNo) {
- return baseMapper.selectCount(equipmentNo);
- }
- //查询温度平均值、压强平均值、空气密度
- public List<ProphaseWeatherData> selectTAveAndPaAveAndAir(String equipmentId, Timestamp startTime, Timestamp endTime) {
- return baseMapper.selectTAveAndPaAveAndAir(equipmentId, startTime, endTime);
- }
- //查询空气密度
- public List<ProphaseWeatherData> selectAir(String equipmentId, Timestamp startTime, Timestamp endTime) {
- List<ProphaseWeatherData> weatherDataList = baseMapper.selectAir(equipmentId, startTime, endTime);
- return weatherDataList.stream().filter(w -> Convert.toFloat(w.getAirDensity(),0f) > 0).collect(Collectors.toList());
- }
- //查询最开始一条记录
- public List<Entity> getFirstData(String equipmentId) {
- return baseMapper.getFirstData(equipmentId);
- }
- //查询最后一条记录
- public List<Entity> getLastData(String equipmentId) {
- return baseMapper.getLastData(equipmentId);
- }
- //批量保存
- public int insertSplice(List<ProphaseWeatherData> prophaseWeatherDataList, String equipmentId) {
- return baseMapper.insertSplice(prophaseWeatherDataList, equipmentId);
- }
- //查询所有数据
- public List<ProphaseWeatherData> selectPublicData(String equipmentId, Timestamp startTime, Timestamp endTime) {
- return baseMapper.selectPublicData(equipmentId, startTime, endTime);
- }
- //删除时间段内数据
- public void deleteData(String equipmentId, Timestamp startTime, Timestamp endTime) {
- baseMapper.deleteData(equipmentId, startTime, endTime);
- }
- public void insertOne(ProphaseWeatherData prophaseWeatherData){
- baseMapper.insertOneWithNew(prophaseWeatherData);
- }
- /**
- * 创建不存在的环境数据表
- * @param equipmentId
- */
- public void createTable(String equipmentId){
- baseMapper.createTable(equipmentId);
- }
- /**
- * 待改造
- * @return
- */
- }
|