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.CostbgFixedDto;
import com.tofly.xrtygis.custom.service.CustomFixedPlanService;
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/22
 */
@RestController
@RequestMapping("/fixedPlan")
@AllArgsConstructor
@Api(tags = "计划管理-制水单变")
public class CustomFixedPlanController {

    private final CustomFixedPlanService customFixedPlanService;

    /**
     * 新增计划
     *
     * @param year 年
     * @return true
     */
    @PostMapping("/insertPlan")
    @ApiOperation("添加计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "year", value = "年份", required = true, dataType = "string")
    )
    public ResultRespone insertPlan(String year) {
        return ResultRespone.success(customFixedPlanService.insertPlan(year));
    }

    /**
     * 添加计划详情
     *
     * @param costbgFixedDto vo
     * @return true
     */
    @PostMapping("/insertPlanInfo")
    @ApiOperation("添加计划详情")
    public ResultRespone insertPlanInfo(@RequestBody CostbgFixedDto costbgFixedDto) {
        return ResultRespone.success(customFixedPlanService.insertPlanInfo(costbgFixedDto));
    }

    /**
     * 删除计划
     *
     * @param id 计划id
     * @return true
     */
    @DeleteMapping("/deletePlan")
    @ApiOperation("删除计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "计划id,多个，分隔", required = true, dataType = "string")
    )
    public ResultRespone deletePlan(String id) {
        return ResultRespone.success(customFixedPlanService.deletePlan(id));
    }

    /**
     * 查询计划
     *
     * @param page  page
     * @param year  年份
     * @param state 状态
     * @return page
     */
    @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(customFixedPlanService.selectPlan(page, year, state));
    }

    @PutMapping("/updatePlanInfo")
    @ApiOperation("修改计划详情")
    public ResultRespone updatePlanInfo(@RequestBody CostbgFixedDto costbgFixedDto) {
        return ResultRespone.success(customFixedPlanService.updatePlanInfo(costbgFixedDto));
    }

}
