123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- package com.jiayue.biz.service.impl;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.jiayue.biz.domain.StatisticsSituation;
- import com.jiayue.common.core.redis.RedisCache;
- 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.WindTowerInfoMapper;
- import com.jiayue.biz.domain.WindTowerInfo;
- import com.jiayue.biz.service.WindTowerInfoService;
- import java.sql.Struct;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.concurrent.TimeUnit;
- import java.util.stream.Collectors;
- /**
- * 测风塔信息Service业务层处理
- *
- * @author L.ym
- * @date 2022-05-11
- */
- @Service
- public class WindTowerInfoServiceImpl extends ServiceImpl<WindTowerInfoMapper, WindTowerInfo> implements WindTowerInfoService {
- @Autowired
- StatisticsSituationServiceImpl statisticsSituationService;
- @Autowired
- RedisCache redisCache;
- @Override
- public List<WindTowerInfo> getDashAllWindInfo() {
- List list = new ArrayList();
- List<WindTowerInfo> windTowerInfos = this.list();
- if (windTowerInfos.size() > 0) {
- for (WindTowerInfo windTowerInfo : windTowerInfos) {
- Map map = new HashMap();
- map.put("name", windTowerInfo.getName());
- map.put("lon", windTowerInfo.getLongitude());
- map.put("lat", windTowerInfo.getLatitude());
- list.add(map);
- }
- }
- return list;
- }
- //获取所有测风塔信息
- public List<WindTowerInfo> getAllWindTower(){
- return this.lambdaQuery().list();
- }
- /**
- * 新建测风塔时生成对应的测风塔表
- *
- * @param windTowerInfo
- * @return
- */
- public boolean saveWindTowerInfo(WindTowerInfo windTowerInfo) {
- baseMapper.createCalculationTable("wind_tower_calculation_data_" + windTowerInfo.getEquipmentNo());
- boolean save = this.save(windTowerInfo);
- return save;
- }
- public boolean update(WindTowerInfo windTowerInfo){
- boolean b = this.updateById(windTowerInfo);
- return b;
- }
- /**
- * 删除塔时删除表
- *
- * @param ids
- * @return
- */
- public boolean deleteWindTowerInfo(List<String> ids) {
- for (String id : ids) {
- WindTowerInfo w = this.getById(id);
- baseMapper.deleteCalculationTable("wind_tower_calculation_data_" + w.getEquipmentNo());
- }
- boolean b = this.removeByIds(ids);
- return b;
- }
- /*
- * 根据设备编号查询测风塔信息
- */
- public List<WindTowerInfo> getByEquipmentNo(String equipmentNo) {
- List<WindTowerInfo> allWindTower = getAllWindTower();
- return allWindTower.stream().filter(w -> w.getEquipmentNo().equals(equipmentNo)).collect(Collectors.toList());
- }
- /*
- * 根据设备编号查询测风塔信息
- */
- public List<WindTowerInfo> getByProjectId(String projectId) {
- QueryWrapper<WindTowerInfo> wrapper = new QueryWrapper();
- if (projectId != null && !projectId.equals("")) {
- wrapper.eq("project_id", projectId);
- }
- return baseMapper.selectList(wrapper);
- }
- /*
- * 分页查询设备编号查询测风塔信息
- */
- @Override
- public Page pageByEquipmentNo(Integer current, Integer size, String equipmentNo) {
- QueryWrapper<WindTowerInfo> wrapper = new QueryWrapper();
- if (equipmentNo != null && !equipmentNo.equals("")) {
- wrapper.eq("equipment_no", equipmentNo);
- }
- wrapper.orderByAsc("equipment_no");
- Page page = new Page(current, size);
- return page(page, wrapper);
- }
- public List<Map<String, String>> listEquipmentIdAndDataTime() {
- //TODO韩雪峰 新建的塔没有统计概述的时候无法显示 需要考虑到这种情况
- List<WindTowerInfo> windTowerInfoList = this.list();
- List<StatisticsSituation> statisticsSituationList = statisticsSituationService.list();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- List<Map<String, String>> mapList = new ArrayList<>();
- List<Map<String, String>> statusMapList = new ArrayList<>();
- //List<WindTowerInfo> windTowerInfoListCollect = windTowerInfoList.stream().sorted(Comparator.comparing(WindTowerInfo::getEquipmentNo)).collect(Collectors.toList());
- Map<String, Long> maps = new HashMap<>();
- for (StatisticsSituation s : statisticsSituationList) {
- maps.put(s.getEquipmentId(), Long.parseLong(s.getStartTimeAndEndTime().split(",")[1]));
- }
- List<Map.Entry<String, Long>> lstEntry = new ArrayList<>(maps.entrySet());
- //根据value 排序 降序
- lstEntry.sort(((o1, o2) -> o2.getValue().compareTo(o1.getValue())));
- List<WindTowerInfo> windTowerInfos = new ArrayList<>();
- lstEntry.forEach(o -> {
- //lstEntry 已经是排完序的了 for循环对比设备编号 添加到windTowerInfoList里 结果就是根据统计概述的数据截止时间从大到小的结果
- for (WindTowerInfo w : windTowerInfoList) {
- if (w.getEquipmentNo().equals(o.getKey())) {
- windTowerInfos.add(w);
- }
- }
- });
- if (windTowerInfoList.size() != windTowerInfos.size()) {
- for (WindTowerInfo w : windTowerInfoList) {
- if (windTowerInfos.stream().filter(wt -> wt.getId().equals(w.getId())).collect(Collectors.toList()).isEmpty()) {
- windTowerInfos.add(w);
- }
- }
- }
- Map<String, String> map;
- for (WindTowerInfo w : windTowerInfos) {
- map = new HashMap<>();
- map.put("value", w.getEquipmentNo());
- map.put("label", w.getName());
- map.put("wdHeights", w.getWdHeights());
- map.put("heights", w.getHeights());
- map.put("status", w.getStatus());
- List<StatisticsSituation> collect = statisticsSituationList.stream().filter(s -> s.getEquipmentId().equals(w.getEquipmentNo())).collect(Collectors.toList());
- if (!collect.isEmpty()) {
- //collect.get(0).getStartTimeAndEndTime().split(",") = "1638288000000,1638373800000"
- String[] strings = collect.get(0).getStartTimeAndEndTime().split(",");
- String str = sdf.format(new Date(Long.parseLong(strings[0]))) + "-" + sdf.format(new Date(Long.parseLong(strings[1])));
- map.put("date", str);
- }
- if (w.getStatus() == null || w.getStatus().equals("")) {
- statusMapList.add(map);
- } else {
- mapList.add(map);
- }
- }
- mapList.addAll(statusMapList);
- //redisCache.setCacheObject("listEquipmentIdAndDataTime", mapList, 1, TimeUnit.HOURS);
- return mapList;
- }
- /**
- * TODO 需要改的地方过多 重写list
- *
- * @return List<WindTowerInfo>
- */
- // public List<WindTowerInfo> list() {
- // return this.lambdaQuery().eq(WindTowerInfo::getType, "1").list();
- // }
- //获取测风塔层高
- public String getWsHeights(String equipmentId) {
- String wsHeights = "";
- try {
- if (StrUtil.isNotBlank(equipmentId)) {
- List<WindTowerInfo> equipmentNo = this.getByEquipmentNo(equipmentId);
- if (!equipmentNo.isEmpty()) {
- wsHeights = equipmentNo.get(0).getHeights();
- }
- }
- } catch (Exception e) {
- log.error("测风塔编号错误");
- throw new RuntimeException(e);
- }
- return wsHeights;
- }
- }
|