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.CostbgUnitDto;
import com.tofly.xrtygis.custom.service.CustomUnitPlanService;
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
 */
@Api(tags = "计划管理-单耗计划")
@RestController
@RequestMapping("/unitPlan")
@AllArgsConstructor
public class CustomUnitConPlanController {

    private final CustomUnitPlanService customUnitPlanService;

    /**
     * 添加单耗预算计划
     *
     * @param year 年份
     * @return true
     */
    @PostMapping("/insertPlan")
    @ApiOperation("添加单耗预算计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "year", value = "年份", required = true, dataType = "long")
    )
    public ResultRespone insetPlan(String year) {
        return ResultRespone.success(customUnitPlanService.insertPlan(year));
    }

    /**
     * 添加预算计划详情
     *
     * @param costbgUnitDto vo
     * @return true
     */
    @PostMapping("/insertPlanInfo")
    @ApiOperation("添加预算计划详情")
    public ResultRespone insertPlanInfo(@RequestBody CostbgUnitDto costbgUnitDto) {
        return ResultRespone.success(customUnitPlanService.insertPlanInfo(costbgUnitDto));
    }

    /**
     * 查看用户创建计划
     *
     * @param page  page
     * @param year  年份
     * @param state 状态
     * @return true
     */
    @GetMapping("/pagePlan")
    @ApiOperation("查看用户创建计划")
    public ResultRespone pagePlan(Page page, String year, String state) {
        return ResultRespone.success(customUnitPlanService.pagePlan(page, year, state));
    }

    /**
     * 查看预算计划详情
     *
     * @param id   id
     * @return page
     */
    @GetMapping("/pagePlanIngo")
    @ApiOperation("查看预算计划详情")
    public ResultRespone pagePlanInfo(Long id) {
        return ResultRespone.success(customUnitPlanService.pagePlanInfo(id));
    }

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

    @PutMapping("/updatePlan")
    @ApiOperation("修改计划详情")
    public ResultRespone updatePlan(@RequestBody CostbgUnitDto costbgUnitDto){
        return ResultRespone.success(customUnitPlanService.update(costbgUnitDto));
    }
}
