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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.BatchInstallTableDto;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.InstallConditionDto;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.InstallTableDto;
import com.tofly.watermeter.custom.service.meterBusiness.TableInstallService;
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.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@AllArgsConstructor
@RequestMapping("/tableInstall")
@Api(tags = "表务管理-水表安装改动")
public class TableInstallController {

    private final TableInstallService tableInstallService;

    @GetMapping("/getCustomerInfo")
    @ApiOperation("获取未安装水表客户信息")
    @ApiImplicitParam(name = "dto", value = "客户姓名、地址、电话、编号模糊查询", dataType = "string")
    public ResultRespone getCustomerInfo(Page page, String dto) {
        return ResultRespone.success(tableInstallService.getCustomerInfo(page, dto));
    }

    @GetMapping("/getTableInfo")
    @ApiOperation("获取水表信息")
    @ApiImplicitParam(name = "dto", value = "水表编号模糊查询", dataType = "string")
    public ResultRespone getTableInfo(Page page, String dto, Long sbcj, Long sblx, Long sbkj) {
        return ResultRespone.success(tableInstallService.getTableInfo(page, dto, sbcj, sblx, sbkj));
    }

    //    @PostMapping("/tableInstall")
//    @ApiOperation("水表安装")
//    public ResultRespone tableInstall(@RequestBody InstallTableDto dto) throws Exception{
//        return ResultRespone.success(tableInstallService.tableInstall(dto));
//    }

    @PostMapping("/tableInstall")
    @ApiOperation("水表安装")
    @ApiImplicitParam(name = "ids",value = "暂存id",required = true,dataType = "string")
    public ResultRespone tableInstall(String ids){
        return ResultRespone.success(tableInstallService.tableInstall(ids));
    }

    @GetMapping("/installCount")
    @ApiOperation("水表新装统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "export", value = "0 不导出 1 导出", required = true, dataType = "string"),
            @ApiImplicitParam(name = "start", value = "开始时间yyyy-MM-dd", required = true, dataType = "string"),
            @ApiImplicitParam(name = "end", value = "结束时间yyyy-MM-dd", required = true, dataType = "string"),
            @ApiImplicitParam(name = "dept", value = "部门", dataType = "list")

    })
    public ResultRespone installCount(HttpServletResponse response, InstallConditionDto dto) {
        return ResultRespone.success(tableInstallService.installCount(response, dto));
    }

    @GetMapping("/countByTyep")
    @ApiOperation("水表新装详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "export", value = "0 不导出 1 导出", required = true, dataType = "string"),
            @ApiImplicitParam(name = "start", value = "开始时间yyyy-MM-dd", required = true, dataType = "string"),
            @ApiImplicitParam(name = "end", value = "结束时间yyyy-MM-dd", required = true, dataType = "string"),
            @ApiImplicitParam(name = "state", value = "0 全部 1 同步 2 未同步", required = true, dataType = "long"),
            @ApiImplicitParam(name = "dept", value = "部门", dataType = "list")

    })
    public ResultRespone countByType(HttpServletResponse response, Page page, InstallConditionDto dto) {
        return ResultRespone.success(tableInstallService.countByType(response, page, dto));
    }

    @PostMapping("/theStagingAbout")
    @ApiOperation("水表暂存相关操作")
    public ResultRespone theStagingAbout(HttpServletResponse response,Page page,@RequestBody InstallTableDto dto) {
        return ResultRespone.success(tableInstallService.theStagingAbout(response,page,dto));
    }

    @GetMapping("/getStation")
    @ApiOperation("获取加压站名称")
    public ResultRespone getStation() throws Exception{
        return ResultRespone.success(tableInstallService.getStation());
    }

    @PostMapping("/batchTableInstall")
    @ApiOperation("批量添加暂存信息")
    public ResultRespone batchTableInstall(@RequestBody BatchInstallTableDto dto) throws Exception {
        return ResultRespone.success(tableInstallService.batchTableInstall(dto));
    }

    @GetMapping("/getQualityOrUse")
    @ApiOperation("获取水表性质、用途")
    public ResultRespone getQualityOrUse() throws Exception {
        return ResultRespone.success(tableInstallService.getQualityOrUse());
    }

}
