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.auto.Inputoroutputspeedtotal;
import com.gyee.frame.model.custom.ProjectPlanVo;
import com.gyee.frame.service.ProjectPlanService;
import com.gyee.frame.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/projectplan")
public class ProjectPlanController {

    @Autowired
    private ProjectPlanService projectPlanService;

    /**计划发电量列表**/
    @PostMapping("/getProjectPlanVo")
    @ResponseBody
    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.emptyresultset.code, vos);
        }

    }

    /**返回计划发电量修改对象**/
    @PostMapping("/getSingleProjectPlan")
    @ResponseBody
    public AjaxResult getSingleProjectPlan(String projectid, String year) {

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

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


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

    /**计划发电量添加和修改**/
    @PostMapping("/saveData")
    @ResponseBody
    public AjaxResult saveData(ProjectPlanVo vo) {

        List<Inputoroutputspeedtotal> vos=new ArrayList<>();
        if (StringUtils.notEmp(vo))
        {

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

        return AjaxResult.successData(AjaxStatus.emptyresultset.code, vos);

    }



}
