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.custom.*;
import com.gyee.frame.service.health.HealthSubService;
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.*;

@Controller
@RequestMapping("/healthsub")
@Api(value = "健康管理风机页面" ,tags =  "健康管理风机页面")
public class HealthSubController {

    @Resource
    private HealthSubService healthSubService;


    @PostMapping("/findPartHealthInfo")
    @ResponseBody
    @ApiOperation(value = "获取健康管理风机部件基础信息", notes = "获取健康管理风机部件基础信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
            })
    public AjaxResult findPartHealthInfo(String wtId) throws Exception {


        Map<String, Map<String, Object>>  map = new HashMap<>();

        if(StringUtils.notEmp(wtId))
        {
            map = healthSubService.findPartHealthInfo(wtId);
        }

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

    }


    @PostMapping("/initalGzjfx")
    @ResponseBody
    @ApiOperation(value = "故障数据统计", notes = "故障数据统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult initalGzjfx(String wtId) throws Exception {


        List<GzfxVo> vos = new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {
            Calendar cal = Calendar.getInstance();
            Date recodedate = cal.getTime();
            vos = healthSubService.initalGzjfx(wtId,recodedate);
        }

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

    }

    @PostMapping("/initalYjfx")
    @ResponseBody
    @ApiOperation(value = "预警数据统计", notes = "预警数据统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult initalYjfx(String wtId) throws Exception {


        List<YjfxVo> vos = new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {
            Calendar cal = Calendar.getInstance();
            Date recodedate = cal.getTime();
            vos = healthSubService.initalYjfx(wtId,recodedate);
        }

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

    }

    @PostMapping("/initalYxfx")
    @ResponseBody
    @ApiOperation(value = "部件运行数据", notes = "部件运行数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult initalYxfx(String wtId) throws Exception {


        List<YxfxVo> vos = new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {
            Calendar cal = Calendar.getInstance();
            Date recodedate = cal.getTime();
            vos = healthSubService.initalYxfx(wtId,recodedate);
        }

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

    }

    @PostMapping("/initalXnfx")
    @ResponseBody
    @ApiOperation(value = "获得日、月等级评估", notes = "获得日、月等级评估")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult initalXnfx(String wtId) throws Exception {


        List<XnfxVo> vos = new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {
            Calendar cal = Calendar.getInstance();
            vos = healthSubService.initalXnfx(wtId,cal);
        }

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

    }

    @PostMapping("/initalShutdown")
    @ResponseBody
    @ApiOperation(value = "获得当日停机事件", notes = "获得当日停机事件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult initalShutdown(String wtId) throws Exception {


        List<ShutdowneventVo> vos = new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {
             vos = healthSubService.initalShutdown(wtId);
        }

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

    }

    @PostMapping("/findJudgmentList")
    @ResponseBody
    @ApiOperation(value = "获得健康评价列表", notes = "获得健康评价列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult findJudgmentList(String wtId) throws Exception {


        List<ValueVo> vos = new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {

            vos = healthSubService.findJudgmentList(wtId);
        }

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

    }

    @PostMapping("/findQxpcList")
    @ResponseBody
    @ApiOperation(value = "各个区间曲线偏差率", notes = "各个区间曲线偏差率")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult findQxpcList(String wtId) throws Exception {


        List<QxpcVo> vos = new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {

            vos = healthSubService.findQxpcList(wtId);
        }

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

    }

    @PostMapping("/findWdList")
    @ResponseBody
    @ApiOperation(value = "温度范围", notes = "温度范围")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult findWdList(String wtId) throws Exception {


        List<YxfxVo> vos = new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {

            vos = healthSubService.findWdList(wtId);
        }

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

    }


    @PostMapping("/gadaytop5")
    @ResponseBody
    @ApiOperation(value = "获得等级评估前5数据", notes = "获得等级评估前5数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult gadaytop5(String wtId) throws Exception {


        Map<String, Object> map = new HashMap<>();

        if(StringUtils.notEmp(wtId))
        {

            map = healthSubService.gadaytop5(wtId);
        }

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

    }


    @PostMapping("/queryStopTop10")
    @ResponseBody
    @ApiOperation(value = "获取最新的十次停机事件", notes = "获取最新的十次停机事件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult queryStopTop10(String wtId) throws Exception {


        List<ShutdowneventVo> vos = new ArrayList<>();

        if(StringUtils.notEmp(wtId))
        {

            vos = healthSubService.queryStopTop10(wtId);
        }

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

    }




    @PostMapping("/findPowerChar")
    @ResponseBody
    @ApiOperation(value = "获取最新的十次停机事件", notes = "获取最新的十次停机事件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult findPowerChar(String wtId) throws Exception {


        Map<String, Object[]> map = new HashMap<>();

        if(StringUtils.notEmp(wtId))
        {

            map = healthSubService.findPowerChar(wtId);
        }

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

    }

    @PostMapping("/hsFjValueIndex")
    @ResponseBody
    @ApiOperation(value = "获取最新的十次停机事件", notes = "获取最新的十次停机事件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult hsFjValueIndex(String wtId) throws Exception {


        ActivityVo vo = new ActivityVo();

        if(StringUtils.notEmp(wtId))
        {
            Calendar cal = Calendar.getInstance();

            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);


            Date endDate = cal.getTime();

            cal.add(Calendar.DAY_OF_MONTH, -1);
            Date beginDate = cal.getTime();
            vo = healthSubService.hsFjValueIndex(wtId,beginDate,endDate);
        }

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

    }
}
