package com.tofly.xrtygis.custom.controller.dma;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.xrtygis.custom.service.dma.CustomDmaTableService;
import com.tofly.xrtygis.entity.Dmatable;
import com.tofly.xrtygis.entity.Dmatablechange;
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;

/**
 * @author 20126
 */
@RestController
@AllArgsConstructor
@Api(tags = "分区计量--区域表管理")
@RequestMapping("/dmaTable")
public class CustomDmatableController {

    private final CustomDmaTableService customDmaTableService;

    @PostMapping("/insertTableInfo")
    @ApiOperation(value = "添加表信息")
    public ResultRespone insertTableInfo(@RequestBody Dmatable dmatable) {
        return ResultRespone.success(customDmaTableService.insertTableInfo(dmatable));
    }


    @DeleteMapping("/deleteTableInfo")
    @ApiOperation(value = "删除表信息")
    public ResultRespone deleteTableInfo(String ids) {
        return ResultRespone.success(customDmaTableService.deleteTableInfo(ids));
    }

    @PutMapping("/updateTableInfo")
    @ApiOperation(value = "修改表信息")
    public ResultRespone updateTableInfo(@RequestBody Dmatable dmatable) {
        return ResultRespone.success(customDmaTableService.updateTableInfo(dmatable));
    }

    @GetMapping("/selectTableInfo")
    @ApiOperation(value = "查看表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "code", required = false, defaultValue = "0L", dataType = "string"),
            @ApiImplicitParam(name = "name", value = "name", required = false, defaultValue = "", dataType = "string"),
    })
    public ResultRespone selectTableInfo(Page page, String code, String name) {
        return ResultRespone.success(customDmaTableService.selectTableInfo(page, code, name));
    }

    @GetMapping("/viewIndex")
    @ApiOperation(value = "查询符合条件指标编号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationId", value = "站点id", readOnly = true, dataType = "long"),
    })
    public ResultRespone viewIndex(Long stationId) {
        return ResultRespone.success(customDmaTableService.viewIndex(stationId));
    }

    @PostMapping("/bindIndex")
    @ApiOperation("区域表绑定指标")
    public ResultRespone bindIndex(Long tableId, Long stationId, String itype) {
        return ResultRespone.success(customDmaTableService.bindIndex(tableId, stationId, itype));
    }

    @DeleteMapping("/untieIndex")
    @ApiOperation("区域表解绑指标")
    public ResultRespone untieIndex(String id) {
        return ResultRespone.success(customDmaTableService.untieIndex(id));
    }


    @GetMapping("/bindTableInfo")
    @ApiOperation("查看绑定表信息")
    @ApiImplicitParam(name = "id", value = "配置表id", required = true, dataType = "long")
    public ResultRespone getBindTableInfo(Page page, Long id) {
        return ResultRespone.success(customDmaTableService.getBindTableInfo(page, id));
    }

    @ApiOperation(value = "区域表导出")
    @GetMapping("/exportTableInfo")
    public void exportTableInfo(HttpServletResponse response, String dto) {
        customDmaTableService.exportTableInfo(response, dto);
    }

    @GetMapping("/oldTableData")
    @ApiOperation("换表-旧表数据")
    @ApiImplicitParam(name = "id", value = "配置表id", required = true, dataType = "long")
    public ResultRespone oldTableData(Long id) {
        return ResultRespone.success(customDmaTableService.oldTableData(id));
    }

    @GetMapping("/historicalTraffic")
    @ApiOperation("换表-历史流量")
    @ApiImplicitParam(name = "id", value = "配置表id", required = true, dataType = "long")
    public ResultRespone historicalTraffic(Long id, String start, String end) {
        return ResultRespone.success(customDmaTableService.historicalTraffic(id, start, end));
    }

    @GetMapping("/avgFlow")
    @ApiOperation("换表-平均流量")
    @ApiImplicitParam(name = "id", value = "配置表id", required = true, dataType = "long")
    public ResultRespone avgFlow(Long id, String start, String end) {
        return ResultRespone.success(customDmaTableService.avgFlow(id, start, end));
    }

    @PostMapping("/changeTable")
    @ApiOperation("换表")
    public ResultRespone changeTable(@RequestBody Dmatablechange dmatablechange) {
        return ResultRespone.success(customDmaTableService.changeTable(dmatablechange));
    }

}
