package com.ruoyi.adapter.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.predict.domain.*;
import com.ruoyi.predict.service.ICollectorwireprojectService;
import com.ruoyi.predict.service.IWfProjectCwWtgService;
import com.ruoyi.predict.service.IWindplantService;
import com.ruoyi.predict.service.IWindplantprojectService;
import io.swagger.annotations.Api;
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/9/9 10:16
 * 文件说明：组态设计
 */
@Api(value = "组态设计Controller", tags = {"组态设计操作接口"})
@Controller
@RequestMapping("/")
public class ConfigurationDesignController extends BaseController {

    @Autowired
    private IWindplantService windplantService;

    @Autowired
    private IWindplantprojectService windplantprojectService;

    @Autowired
    private ICollectorwireprojectService collectorwireprojectService;

    @Autowired
    private IWfProjectCwWtgService wfProjectCwWtgService;

    /**
     * 场站信息
     */
    @GetMapping("/thing/station")
    @ResponseBody
    public List<Windplant> station() {
        return windplantService.selectWindplantListByGlFlag();
    }

    /**
     * 场站下层信息
     */
    @GetMapping("/electrical/electricaltestingpoint")
    @ResponseBody
    public List<ConfigurationElement> electricaltestingpoint(String type, String windpowerstationid) {
        List<ConfigurationElement> list = new ArrayList<>();
        List<Windplantproject> windplantprojectList = windplantprojectService.selectWindplantprojectByWindplantNo(Convert.toLong(windpowerstationid));
        for (Windplantproject windplantproject : windplantprojectList) {
            ConfigurationElement c1 = new ConfigurationElement();
            c1.setId(windpowerstationid + "/" + windplantproject.getProjectNo());
            c1.setName(windplantproject.getProjectName());
            list.add(c1);
            List<Collectorwireproject> collectorwireprojectList = collectorwireprojectService.selectCollectorwireprojectByProjectNo(Convert.toLong(windpowerstationid), windplantproject.getProjectNo());
            for (Collectorwireproject collectorwireproject : collectorwireprojectList) {
                ConfigurationElement c2 = new ConfigurationElement();
                c2.setId(windpowerstationid + "/" + windplantproject.getProjectNo() + "/" + collectorwireproject.getCollectorwireNo());
                c2.setName(collectorwireproject.getWireName());
                list.add(c2);
                List<WfProjectCwWtg> wfProjectCwWtgList = wfProjectCwWtgService.selectWfProjectCwWtgByCollectorwireNo(collectorwireproject.getWpNo(), collectorwireproject.getProjectNo(), collectorwireproject.getCollectorwireNo());
                for (WfProjectCwWtg wfProjectCwWtg : wfProjectCwWtgList) {
                    ConfigurationElement c3 = new ConfigurationElement();
                    c3.setId(windpowerstationid + "/" + windplantproject.getProjectNo() + "/" + collectorwireproject.getCollectorwireNo() + "/" + wfProjectCwWtg.getWtgNo());
                    c3.setName(wfProjectCwWtg.getWtgName());
                    list.add(c3);
                }
            }
        }
        return list;
    }
}
