Newer
Older
huludao / src / main / java / com / newfiber / api / pc / service / impl / TempDataServiceImpl.java
package com.newfiber.api.pc.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.newfiber.api.pc.dao.TempDataMapper;
import com.newfiber.api.pc.model.entity.ProSiteWarnEntity;
import com.newfiber.api.pc.model.vo.TempDataVo;
import com.newfiber.api.pc.model.vo.WaterLevelMonitorVo;
import com.newfiber.api.pc.service.TempDataService;
import com.newfiber.api.pc.service.impl.monitoring.ProSiteWarnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description: TODO
 * @author: 张鸿志
 * @date: 2021/1/7 17:20
 * @version: v1.0
 */
@Service
public class TempDataServiceImpl implements TempDataService {

    @Autowired
    private TempDataMapper tempDataMapper;

    @Autowired
    private ProSiteWarnService proSiteWarnService;

    @Override
    public WaterLevelMonitorVo selectData() {
        WaterLevelMonitorVo waterLevelMonitorVo = new WaterLevelMonitorVo();
        List<TempDataVo> vos = tempDataMapper.selectSiteNameAndZData();
        EntityWrapper<ProSiteWarnEntity> wrapper = new EntityWrapper<>();
        wrapper.in("site_no",vos.stream().map(TempDataVo::getSiteNo).collect(Collectors.toList()));
        List<ProSiteWarnEntity> proSiteWarnEntities = proSiteWarnService.selectList(wrapper);
        List<String> siteNames = vos.stream().map(TempDataVo::getSiteName).collect(Collectors.toList());
        waterLevelMonitorVo.setSiteNames(siteNames);
        List<BigDecimal> zzs = vos.stream().map(TempDataVo::getZ).collect(Collectors.toList());
        waterLevelMonitorVo.setZzs(zzs);
        List<BigDecimal> yj = new ArrayList<>();
        List<BigDecimal> bj = new ArrayList<>();
        List<ProSiteWarnEntity> yjs = proSiteWarnEntities.stream().filter(s -> s.getWarnType().equals(0)).collect(Collectors.toList());
        List<ProSiteWarnEntity> bjs = proSiteWarnEntities.stream().filter(s -> s.getWarnType().equals(1)).collect(Collectors.toList());
        for(TempDataVo vo : vos){
            if(yjs.size() != 0){
                int count = 0;
                for(ProSiteWarnEntity yjPro : yjs){
                    if(yjPro.getSiteNo().equalsIgnoreCase(vo.getSiteNo())){
                        count = 1;
                        yj.add(yjPro.getWarnValue());
                        break;
                    }
                }
                if(count == 0){
                    yj.add(null);
                }
            }else {
                yj.add(null);
            }


            if(bjs.size() != 0){
                int count = 0;
                for(ProSiteWarnEntity bjPro : bjs){
                    if(bjPro.getSiteNo().equalsIgnoreCase(vo.getSiteNo())){
                        count = 1;
                        bj.add(bjPro.getWarnValue());
                        break;
                    }
                }
                if(count == 0){
                    bj.add(null);
                }
            }else{
                bj.add(null);
            }

        }

        waterLevelMonitorVo.setAlarmValues(yj);
        waterLevelMonitorVo.setAldoys(bj);
        return waterLevelMonitorVo;
    }
}