package com.gyee.alarm.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.alarm.init.CacheContext;
import com.gyee.alarm.model.auto.ProBasicEquipment;
import com.gyee.alarm.model.auto.ProBasicEquipmentPoint;
import com.gyee.alarm.model.auto.ProEconShutdownEvent2;
import com.gyee.alarm.model.vo.AjaxResult;
import com.gyee.alarm.model.vo.AjaxStatus;
import com.gyee.alarm.service.auto.IProEconShutdownEvent2Service;
import com.gyee.alarm.util.StringUtils;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * <p>
 * 停机事件2 前端控制器
 * </p>
 *
 * @author shilin
 * @since 2022-10-21
 */
@RestController
@RequestMapping("//shutdownevent2")
public class ProEconShutdownEvent2Controller {
    @Resource
    private IProEconShutdownEvent2Service proEconShutdownEvent2Service;

    @GetMapping(value = "/queryshutdowneventlist")
    @ApiOperation(value = "查询停机事件记录", notes = "查询停机事件记录")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wtId", value = "设备编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "description", value = "故障描述 模糊查询", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "begin", value = "开始时间", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "end", value = "结束时间", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "当前页号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型（gz 故障、wh 维护）", required = true, dataType = "string", paramType = "query")

    })
    public AjaxResult queryshutdowneventlist(String wpId, String wtId,String description,String begin,String end,Integer pageNum, Integer pageSize,String type) {

        IPage<ProEconShutdownEvent2> vos=new Page<>();


        if (StringUtils.notEmp(begin) && StringUtils.notEmp(end) && StringUtils.notEmp(pageNum) && StringUtils.notEmp(pageSize) && StringUtils.notEmp(type)) {

            vos=proEconShutdownEvent2Service.queryShutdownEvent2(wpId, wtId, description, begin, end, pageNum, pageSize,type);
        }

        for(ProEconShutdownEvent2 vo:vos.getRecords())
        {
            if(StringUtils.notEmp(vo.getWindturbineId()) && CacheContext.wtmap.containsKey(vo.getWindturbineId()))
            {
                vo.setCode(CacheContext.wtmap.get(vo.getWindturbineId()).getNemCode());
            }
            if(StringUtils.notEmp(vo.getWindturbineId()) && CacheContext.wtmap.containsKey(vo.getWindturbineId()))
            {
                vo.setWindturbineName(CacheContext.wtmap.get(vo.getWindturbineId()).getName());
            }
        }
        if (StringUtils.notEmp(vos)) {

            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
        }
    }

}
