package com.tofly.watermeter.custom.controller.meterRead;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.watermeter.custom.entity.meterRead.ReadSearch;
import com.tofly.watermeter.entity.Qfcbplan;
import com.tofly.watermeter.entity.Qfcbplandetails;
import com.tofly.watermeter.service.QfcbplanService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author FlashWJL
 * @date 2021/11/8 15:51
 */
@RestController
@RequestMapping("/readPlan")
@Api(tags = "抄表--抄表计划管理")
public class ReadPlanController {
    @Autowired
    private QfcbplanService qfcbplanService;

    @GetMapping("/getYearPlan")
    @ApiOperation(value = "年计划--查看")
    public ResultRespone getYearPlan(Page<Qfcbplan> page, Qfcbplan qfcbplan) {
        return ResultRespone.success(qfcbplanService.getYearPlan(page, qfcbplan));
    }

    @PostMapping("/makeYearPlan")
    @ApiOperation(value = "年计划--制定")
    public ResultRespone makeYearPlan(@RequestBody Qfcbplan qfcbplan) {
        return ResultRespone.success(qfcbplanService.makeYearPlan(qfcbplan));
    }

    @PostMapping("/updateYearPlan")
    @ApiOperation(value = "年计划--启用、禁用")
    @ApiImplicitParam(name = "isState", value = "0：禁用；1：启用", required = true, dataType = "String")
    public ResultRespone updateYearPlan(@RequestBody ReadSearch readSearch) {
        String ids = readSearch.getIds();
        String isState = readSearch.getIsState();
        String isGeneral = readSearch.getIsGeneral();
        return ResultRespone.success(qfcbplanService.updateYearPlan(ids, isState, isGeneral));
    }

    @DeleteMapping("/delYearPlan")
    @ApiOperation(value = "年计划--删除")
    public ResultRespone delYearPlan(String ids) {
        return ResultRespone.success(qfcbplanService.delYearPlan(ids));
    }

    /**
     * @param planId 被复制的年计划ID
     * @param year   复制后的年计划年份
     * @return 结果
     */
    @PostMapping("/copeYearPlan")
    @ApiOperation(value = "计划--一键复制")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "planId", value = "被复制的目标计划ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "year", value = "复制目标年份；格式：2022", required = true, dataType = "String"),
            @ApiImplicitParam(name = "descript", value = "复制备注", required = true, dataType = "String")
    })
    public ResultRespone copeYearPlan(Long planId, String year , String descript) {
        return qfcbplanService.copyYearPlan(planId, year , descript);
    }


    @GetMapping("/getDeatilByPlan")
    @ApiOperation(value = "计划详情--查看")
    public ResultRespone getDeatilByPlan(ReadSearch search) {
        return ResultRespone.success(qfcbplanService.getDeatilByPlan(search));
    }

    @PostMapping("/addDeatilPlan")
    @ApiOperation(value = "计划详情--添加")
    public ResultRespone addDeatilPlan(@RequestBody Qfcbplandetails qfcbplandetails) {
        return ResultRespone.success(qfcbplanService.addDeatilPlan(qfcbplandetails));
    }

    @GetMapping("/getQyInfoByPlan")
    @ApiOperation(value = "计划详情--查看已经制定计划的区域和区域段")
    public ResultRespone getQyInfoByPlan(Page<Qfcbplandetails> page, Long planId, String cbqyBm, String isGeneral) {
        return ResultRespone.success(qfcbplanService.getQyInfoByPlan(page, planId, cbqyBm, isGeneral));
    }

    @PutMapping("/updateDeatilPlan")
    @ApiOperation(value = "计划详情--修改")
    @ApiImplicitParam(name = "isUpdateType", value = "修改类型；0：抄表人员设置；1：抄表时间设置；2：计划启用停用", required = true, dataType = "String")
    public ResultRespone updateDeatilPlan(@RequestBody Qfcbplandetails qfcbplandetails) {
        return ResultRespone.success(qfcbplanService.updateDeatilPlan(qfcbplandetails));
    }

    @DeleteMapping("/deleteDeatilsPlan")
    @ApiOperation(value = "计划详情--计划移除")
    public ResultRespone deleteDeatilsPlan(String ids) {
        return ResultRespone.success(qfcbplanService.deleteDeatilsPlan(ids));
    }


    @GetMapping("/getCbry")
    @ApiOperation(value = "获取抄表人员")
    public ResultRespone getCbry(Long departId) {
        return ResultRespone.success(qfcbplanService.getCbry(departId));
    }

}
