package com.ruoyi.adapter.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.json.JSONObject;
import com.ruoyi.predict.domain.PvPowerStation;
import com.ruoyi.predict.domain.WfProjectCwWtg;
import com.ruoyi.predict.domain.Windplant;
import com.ruoyi.predict.domain.Windplantproject;
import com.ruoyi.predict.service.IPvPowerStationService;
import com.ruoyi.predict.service.IWfProjectCwWtgService;
import com.ruoyi.predict.service.IWindplantService;
import com.ruoyi.predict.service.IWindplantprojectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hlf
 * @date 2022/11/18 10:58
 * 文件说明：图迹基础信息数据
 */
@Api(value = "图迹基础信息数据Controller", tags = {"图迹基础信息数据操作接口"})
@Controller
@RequestMapping("/adapter/api/tjbidc")
public class TuJiBasicInformationDataController extends BaseController {

    @Autowired
    private IWindplantService windplantService;

    @Autowired
    private IPvPowerStationService pvPowerStationService;

    @Autowired
    private IWindplantprojectService windplantprojectService;

    @Autowired
    private IWfProjectCwWtgService wfProjectCwWtgService;

    @ApiOperation("获取所有场站")
    @GetMapping("/getTerminalAllInfo")
    @ResponseBody
    public AjaxResult getTerminalAllInfo() {
        JSONObject json = new JSONObject();
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        List<Windplant> windplantList = windplantService.selectWindplantListByXhjyFlag();
        for (Windplant windplant : windplantList){
            List<Windplantproject> windplantprojectList = windplantprojectService.selectWindplantprojectByWindplantNo(windplant.getWindplantNo());
            List<Wp> wpList = new ArrayList<>();
            for (Windplantproject windplantproject : windplantprojectList){
                List<WfProjectCwWtg> wfProjectCwWtgList = wfProjectCwWtgService.selectWfProjectCwWtgByPojectNo(windplant.getWindplantNo(), windplantproject.getProjectNo());
                List<Unit> unitList = new ArrayList<>();
                for (WfProjectCwWtg wfProjectCwWtg : wfProjectCwWtgList){
                    Unit unit = new Unit();
                    unit.setUnitNo(wfProjectCwWtg.getWtgNo());
                    unit.setUnitName(wfProjectCwWtg.getWtgName());
                    unit.setUnitType(wfProjectCwWtg.getWtgType());
                    unitList.add(unit);
                }
                Wp wp = new Wp();
                wp.setProjectNo(windplantproject.getProjectNo());
                wp.setProjectName(windplantproject.getProjectName());
                wp.setUnitList(unitList);
                wpList.add(wp);
            }
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setSerialNumber(windplant.getWindplantNo());
            tjDataFormat.setName(windplant.getName());
            tjDataFormat.setType("风电");
            tjDataFormat.setWpList(wpList);
            tjDataFormatList.add(tjDataFormat);
        }
        List<PvPowerStation> pvPowerStationList = pvPowerStationService.selectPvPowerStationList(new PvPowerStation());
        for (PvPowerStation pvPowerStation : pvPowerStationList){
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setSerialNumber(pvPowerStation.getPvStationNo());
            tjDataFormat.setName(pvPowerStation.getName());
            tjDataFormat.setType("光伏");
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    public static class TjDataFormat {

        //编号
        private Long serialNumber;

        //场站名称
        private String name;

        //类型（风电 光伏）
        private String type;

        //期次list
        private List<Wp> wpList;

        public Long getSerialNumber() {
            return serialNumber;
        }

        public void setSerialNumber(Long serialNumber) {
            this.serialNumber = serialNumber;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public List<Wp> getWpList() {
            return wpList;
        }

        public void setWpList(List<Wp> wpList) {
            this.wpList = wpList;
        }
    }

    public static class Wp {

        //期次编号
        private Long projectNo;

        //期次名称
        private String projectName;

        //机组list
        private List<Unit> unitList;

        public Long getProjectNo() {
            return projectNo;
        }

        public void setProjectNo(Long projectNo) {
            this.projectNo = projectNo;
        }

        public String getProjectName() {
            return projectName;
        }

        public void setProjectName(String projectName) {
            this.projectName = projectName;
        }

        public List<Unit> getUnitList() {
            return unitList;
        }

        public void setUnitList(List<Unit> unitList) {
            this.unitList = unitList;
        }
    }

    public static class Unit {

        //机组编号
        private Long unitNo;

        //机组名称
        private String unitName;

        //机组类型
        private Long unitType;

        public Long getUnitNo() {
            return unitNo;
        }

        public void setUnitNo(Long unitNo) {
            this.unitNo = unitNo;
        }

        public String getUnitName() {
            return unitName;
        }

        public void setUnitName(String unitName) {
            this.unitName = unitName;
        }

        public Long getUnitType() {
            return unitType;
        }

        public void setUnitType(Long unitType) {
            this.unitType = unitType;
        }
    }
}
