package com.gyee.frame.controller.health;

import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.auto.StopAnalysismainVo;
import com.gyee.frame.model.custom.StopAnalysisNodeVo;
import com.gyee.frame.service.stopanalysis.StopAnalysisStaticService;
import com.gyee.frame.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/stopanalysis")
@Api(value = "故障诊断" ,tags =  "故障诊断")
public class StopAnalysisController {

    @Resource
    private StopAnalysisStaticService stopAnalysisStaticService;


    @PostMapping("/stopAnalysisList")
    @ResponseBody
    @ApiOperation(value = "故障诊断列表", notes = "故障诊断列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "modelId", value = "模型编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "typeId", value = "时间类型", required = true, dataType = "string", paramType = "query")})

    public AjaxResult stopAnalysisList( String wpId, String modelId, String typeId) throws Exception {

        List<StopAnalysismainVo> vos = new ArrayList<StopAnalysismainVo>();
        if (StringUtils.notEmp(wpId) && StringUtils.notEmp(modelId)&& StringUtils.notEmp(typeId))
        {

            vos=stopAnalysisStaticService.stopAnalysisList(wpId, modelId, typeId);
        }

        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }

    @PostMapping("/stopAnalysisTree")
    @ResponseBody
    @ApiOperation(value = "故障诊断部件树", notes = "故障诊断部件树")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风场编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult stopAnalysisTree( String mainId,String wtId, String values) throws Exception {

        List<StopAnalysisNodeVo> vos = new ArrayList<StopAnalysisNodeVo>();
        if (StringUtils.notEmp(mainId) && StringUtils.notEmp(wtId) && StringUtils.notEmp(values))
        {

            vos=stopAnalysisStaticService.findLocationTreeByWtId(mainId,wtId,values);
        }

        if (null!=vos) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }

    @PostMapping("/saveStopAnalysis")
    @ResponseBody
    @ApiOperation(value = "保存故障诊断结果", notes = "保存故障诊断结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "modelId", value = "模型编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "typeId", value = "时间类型", required = true, dataType = "string", paramType = "query")})

        public AjaxResult saveStopAnalysis( String wpId, String modelId, String typeId) throws Exception {


        stopAnalysisStaticService.saveStopAnalysis(wpId, modelId, typeId);

        return AjaxResult.successData(AjaxStatus.success.code, "保存成功！");

    }

}
