package com.gyee.frame.controller.projectplan;

import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.custom.ProjectPlanVo;
import com.gyee.frame.service.ProjectPlanService;
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("/projectplan")
@Api(value = "计划发电量",tags =  "计划发电量")
public class ProjectPlanController {

    @Resource
    private ProjectPlanService projectPlanService;

    /**计划发电量列表**/
    @PostMapping("/getProjectPlanVo")
    @ResponseBody
    @ApiOperation(value = "计划发电量列表", notes = "计划发电量列表")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "wpId", value = "风场编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pjId", value = "项目编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, dataType = "string", paramType = "query")})

    public AjaxResult getProjectPlanVo(String wpId, String pjId, String year)  {

        List<ProjectPlanVo> vos=new ArrayList<>();
        if (StringUtils.notEmp(year))
        {
            vos=projectPlanService.getProjectPlanVo(wpId, pjId, year);
        }

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

    }

    /**返回计划发电量修改对象**/
    @PostMapping("/getSingleProjectPlan")
    @ResponseBody
    @ApiOperation(value = "查询计划发电量修改对象", notes = "查询计划发电量修改对象")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pjId", value = "项目编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, dataType = "string", paramType = "query")})

    public AjaxResult getSingleProjectPlan(String pjId, String year) {

        if (StringUtils.notEmp(pjId) && StringUtils.notEmp(year))
        {
            ProjectPlanVo  vo=projectPlanService.getSingleProjectPlan(pjId,year);

            return AjaxResult.successData(AjaxStatus.success.code, vo);
        }


        return AjaxResult.successData(AjaxStatus.success.code, new ProjectPlanVo());
    }

    /**计划发电量添加和修改**/
    @PostMapping("/saveData")
    @ResponseBody
    @ApiOperation(value = "查询计划发电量修改对象", notes = "查询计划发电量修改对象")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vo", value = "项目VO对象", required = true, dataType = "ProjectPlanVo", paramType = "query")})

    public AjaxResult saveData(ProjectPlanVo vo) {

        int value=0;
        if (StringUtils.notEmp(vo))
        {

            value=projectPlanService.saveData(vo);
            return AjaxResult.successData(AjaxStatus.success.code, value);
        }

        return AjaxResult.successData(AjaxStatus.success.code, value);

    }



}
