package com.zehong.web.controller.supervise;
import com.zehong.system.domain.*;
import com.zehong.system.service.IPipeInterfaceService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 管道信息接口控制层
 */
@Controller
@RestController
@RequestMapping("/pipe/pipe")
public class PipeInterfaceController {

    @Autowired
    IPipeInterfaceService iPipeInterfaceService;


    /**
     * 查询管道数据列表
     */
    @RequestBody
    @RequestMapping("/selectPipeData")
    public PipeList selectPipeData() {
        //获取分组数据
        List<PipeDate> pipeDatesGroup = iPipeInterfaceService.selectGroupPipeData();
        //查询管道数据列表
        List<PipeDate> pipeDates = iPipeInterfaceService.selectPipeData();
        int k=1;
        //循环根据权属单位名称分组的数据
        for (int i=0;i<pipeDatesGroup.size();i++){
             //循环全部数据
            for (int n=0;n<pipeDates.size();n++){
                //判断如果名称一样就一组
                if (pipeDatesGroup.get(i).getPowerCompany().equals(pipeDates.get(n).getPowerCompany())){
//                    //设置分组类型
//                    pipeDates.get(n).setCompanyType(Integer.parseInt(pipeDates.get(n).getPipeId()));
                    pipeDates.get(n).setIconType(1);
                }
            }
            k++;
        }
        PipeList pipeList=new PipeList();
        pipeList.setData(pipeDates);
        return pipeList;
    }


    /**
     * 调压箱数据查询接口
     */
    @RequestBody
    @RequestMapping("/selectDeviceData")
    public DeviceList  selectDeviceData(){
        //调压箱数据查询方法
        List<DeviceData> deviceData = iPipeInterfaceService.selectDeviceData();
        DeviceList deviceList=new DeviceList();
        for (int i=0;i<deviceData.size();i++){
            //查询下级设备数据
            List<PressureFlow> pressureFlows = iPipeInterfaceService.selectPressureFlow(deviceData.get(i).getDeviceId());
            deviceData.get(i).setPressureFlows(pressureFlows);
            deviceData.get(i).setIconType(2);
        }
        deviceList.setData(deviceData);
        return deviceList;
    }


    /**
     * 场站信息查询接口
     */
    @RequestBody
    @RequestMapping("/selectTSiteStationInfoData")
    public TSiteStationInfoDataList selectTSiteStationInfoData(){
        //场站信息查询方法
        List<TSiteStationInfoData> tSiteStationInfoData = iPipeInterfaceService.selectTSiteStationInfoData();
        TSiteStationInfoDataList tSiteStationInfoDataList=new TSiteStationInfoDataList();
        for (int i=0;i<tSiteStationInfoData.size();i++){
            //查询场站下级设备数据
            List<PressureFlow> pressureFlows = iPipeInterfaceService.selecttSiteStationInfoDataList(tSiteStationInfoData.get(i).getSiteStationId());
            tSiteStationInfoData.get(i).setPressureFlows(pressureFlows);
            tSiteStationInfoData.get(i).setIconType(4);
        }
        tSiteStationInfoDataList.setData(tSiteStationInfoData);
        return tSiteStationInfoDataList;
    }

    /**
     * 监控信息查询
     */
    @RequestBody
    @RequestMapping("/selectTvideoManagerData")
    public List<TvideoManagerData> selectTvideoManagerData(){
        //查询监控信息
        List<TvideoManagerData> tvideoManagerData = iPipeInterfaceService.selectTvideoManagerData();
        for (int i=0;i<tvideoManagerData.size();i++){
            tvideoManagerData.get(i).setIconType(5);
        }
        return tvideoManagerData;
    }

    /**
     * 燃气用户信息查询接口
     */
    @RequestBody
    @RequestMapping("/selectTdetectorUser")
    public TenterpriseInfoDataList selectTdetectorUser(){
        TenterpriseInfoDataList tenterpriseInfoDataList=new TenterpriseInfoDataList();
       //燃气用户信息查询方法
        List<TdetectorUserData> tdetectorUserData = iPipeInterfaceService.selectTdetectorUser();
        for (int i=0;i<tdetectorUserData.size();i++){
            tdetectorUserData.get(i).setIconType(6);
        }
        tenterpriseInfoDataList.setData(tdetectorUserData);
        return tenterpriseInfoDataList;
    }

    /**
     * 企业名称id查询接口
     */
    @RequestBody
    @RequestMapping("/selectTenterpriseInfoData")
    public List<TenterpriseInfoData> selectTenterpriseInfoData(){
        //查询企业名称id方法
        List<TenterpriseInfoData> tenterpriseInfoData = iPipeInterfaceService.selectTenterpriseInfoData();
        return tenterpriseInfoData;
    }

    /**
     * 阀门数据查询接口
     */
    @RequestBody
    @RequestMapping("/selectvalveData")
    public DeviceDataList selectvalveData(){
        DeviceDataList deviceDataList=new DeviceDataList();
        //查询阀门井数据
        List<DeviceData> pipeDates = iPipeInterfaceService.selectvalveData();
        for (int i=0;i<pipeDates.size();i++){
            pipeDates.get(i).setIconType(3);
        }
        deviceDataList.setData(pipeDates);
        return deviceDataList;
    }

}
