package com.tofly.xrtygis.custom.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.xrtygis.custom.entity.dto.CostbgIndexDto;
import com.tofly.xrtygis.custom.service.CustomIndexPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**制水成本
 * @author 陈浩
 * @date 2021/3/18
 */
@RestController
@RequestMapping("/indexPlan")
@Api(tags = "计划管理-制水指标")
@AllArgsConstructor
public class CustomIndexPlanController {

    private final CustomIndexPlanService customIndexPlanService;

    /**
     * 添加计划
     *
     * @param year 年份
     * @return return
     */
    @PostMapping("/insertPlan")
    @ApiOperation("添加计划")
    public ResultRespone indexPlan(String year) {
        return ResultRespone.success(customIndexPlanService.insertPlan(year));
    }

    @PostMapping("/insertPlanInfo")
    @ApiOperation("添加计划详情")
    public ResultRespone insertPlanInfo(@RequestBody CostbgIndexDto costbgIndexDto) {
        return ResultRespone.success(customIndexPlanService.insertPlanInfo(costbgIndexDto));
    }

    @GetMapping("/selectPlan")
    @ApiOperation("查看计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year", value = "年份", dataType = "string"),
            @ApiImplicitParam(name = "state", value = "状态", dataType = "string")
    })
    public ResultRespone selectPlan(Page page, String year, String state) {
        return ResultRespone.success(customIndexPlanService.selectPlan(page, year, state));
    }

    @GetMapping("/selectPlanInfo")
    @ApiOperation("查看计划详情")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "计划id", required = true, dataType = "long")
    )
    public ResultRespone selectPlanInfo( Long id) {
        return ResultRespone.success(customIndexPlanService.selectPlanInfo(id));
    }

    @DeleteMapping("/deletePlan")
    @ApiOperation("删除计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "计划id", required = true, dataType = "string")
    )
    public ResultRespone deletePlan(String id) {
        return ResultRespone.success(customIndexPlanService.deletePlan(id));
    }

    @PutMapping("/updatePlanInfo")
    @ApiOperation("修改计划详情")
    public ResultRespone updatePlanInfo(@RequestBody CostbgIndexDto costbgIndexDto) {
        return ResultRespone.success(customIndexPlanService.updatePlanInfo(costbgIndexDto));
    }


}
