package com.gyee.frame.controller.warn;

import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.auto.Brownoutsevent2;
import com.gyee.frame.model.auto.MainBrownouts2;
import com.gyee.frame.model.custom.MainBrownoutsVo;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.service.Brownoutsevent2Service;
import com.gyee.frame.service.MainBrownouts2Service;
import com.gyee.frame.util.DateUtils;
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.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/brownouts")
@Api(value = "限电事件", tags = "限电事件")
public class MainBrownouts2Controller {

    @Resource
    private MainBrownouts2Service mhutdowneventService;
    @Resource
    private Brownoutsevent2Service brownoutsevent2Service;


    @PostMapping("/getBrownoutsList")
    @ResponseBody
    @ApiOperation(value = "限电事件查询", notes = "限电事件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页控件", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult getBrownoutsList(Tablepar tablepar, String wpId, String beginDate, String endDate) throws Exception {

        PageInfo<MainBrownoutsVo> result=new PageInfo<>() ;
        if (StringUtils.notEmp(tablepar) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            result=mhutdowneventService.getMainBrownouts2(tablepar, wpId, DateUtils.parseDate(beginDate), DateUtils.parseDate(endDate));

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

    }

    @PostMapping("/getBrownouts")
    @ResponseBody
    @ApiOperation(value = "限电详细事件查询", notes = "限电详细事件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mainId", value = "主表编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult getBrownouts(String mainId) throws Exception {

        Map<String,Object> map= new HashMap<>();
        if (StringUtils.notEmp(mainId) ) {

            MainBrownouts2 main=mhutdowneventService.selectByPrimaryKey(mainId);
            List<Brownoutsevent2> list=brownoutsevent2Service.getBrownoutsevent2List(mainId);
            map.put("main",main);
            map.put("list",list);

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

    }

}
