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.TablelinkUserDto;
import com.tofly.xrtygis.custom.entity.dto.TablelinkpipeDto;
import com.tofly.xrtygis.custom.service.TheOnlineCheckService;
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 泡泡
 */
@RestController
@RequestMapping("/onlineCheck")
@AllArgsConstructor
@Api(tags = "综合展示-线上核对")
public class TheOnlineCheckController {

    private final TheOnlineCheckService theOnlineCheckService;

    @PostMapping("/bindLine")
    @ApiOperation("总表绑定管线")
    public ResultRespone bindLine(@RequestBody TablelinkpipeDto dto) {
        return ResultRespone.success(theOnlineCheckService.bindLine(dto));
    }

    @GetMapping("/tableInfo")
    @ApiOperation("查询总表信息")
    public ResultRespone selectSunTable() {
        return ResultRespone.success(theOnlineCheckService.selectSunTable());
    }

    @GetMapping("/viewTablePipe")
    @ApiOperation("显示管线、关联客户数、总表信息")
    @ApiImplicitParam(name = "type", value = "确认状态：0未确认、1已确认、2自动匹配 、3查询全部", dataType = "string")
    public ResultRespone viewTablePipe(Page page, String type) {
        return ResultRespone.success(theOnlineCheckService.viewTablePipe(page, type));
    }

    @PutMapping("/confirmTablePipe")
    @ApiOperation("确认管线与总表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "0：选中确认 1:全部确认",required = true, dataType = "string"),
            @ApiImplicitParam(name = "tableId", value = "总表id",  dataType = "string")
    })

    public ResultRespone confirmTablePipe(String tableId,String type) {
        return ResultRespone.success(theOnlineCheckService.confirmTablePipe(tableId,type));
    }

    @GetMapping("/customerInfo")
    @ApiOperation("未关联客户信息查询")
    @ApiImplicitParam(name = "str", value = "条件：客户姓名/客户编号/客户地址", dataType = "string")
    public ResultRespone unaffiliatedCustomer(Page page, String str) {
        return ResultRespone.success(theOnlineCheckService.unaffiliatedCustomer(page, str));
    }

    @PostMapping("/userToTable")
    @ApiOperation("用户关联总表")
    public ResultRespone userToTable(@RequestBody TablelinkUserDto dto) {
        return ResultRespone.success(theOnlineCheckService.userToTable(dto));
    }

    @PutMapping("/confirmTableUser")
    @ApiOperation("确认客户-总表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "codes", value = "客户编号，多个‘,’分割",  dataType = "string"),
            @ApiImplicitParam(name = "tableId", value = "总表id，多个‘,’分割",  dataType = "string"),
            @ApiImplicitParam(name = "type", value = "0：选中确认 1:全部确认",required = true, dataType = "string")
    })

    public ResultRespone confirmTableUser(String tableId,String codes,String type) {
        return ResultRespone.success(theOnlineCheckService.confirmTableUser(tableId,codes,type));
    }

    @GetMapping("/associatedCustomer")
    @ApiOperation("查询关联客户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code",value = "0:分页查询 1:全部查询",required = true,dataType = "string"),
            @ApiImplicitParam(name = "tableId", value = "总表id", required = true, dataType = "integer")
    })
    public ResultRespone associatedCustomer(Page page, Integer tableId,String code) {
        if ("0".equals(code)){
            return ResultRespone.success(theOnlineCheckService.associatedCustomer(page, tableId));
        }else {
            return ResultRespone.success(theOnlineCheckService.associatedCustomer(tableId));
        }
    }

    @DeleteMapping("/removeUser")
    @ApiOperation("移除用户表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "id,多个‘,’分割",dataType = "string"),
            @ApiImplicitParam(name = "tableId",value = "总表id",dataType = "string")
    })

    public ResultRespone removeUser(String tableId, String ids) {
        return ResultRespone.success(theOnlineCheckService.removeUser(tableId, ids));
    }

    @PutMapping("/moveUserTable")
    @ApiOperation("用户表更换总表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableId", value = "总表id", required = true, dataType = "string"),
            @ApiImplicitParam(name = "codes", value = "客户编号", required = true, dataType = "string")
    })
    public ResultRespone moveUserTable(String tableId, String codes) {
        return ResultRespone.success(theOnlineCheckService.moveUserTable(tableId, codes));
    }

    @PutMapping("/inTheTable")
    @ApiOperation("总表换表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "oldId", value = "旧表总表id", required = true, dataType = "string"),
            @ApiImplicitParam(name = "newId", value = "表总表id", required = true, dataType = "string")
    })
    public ResultRespone inTheTable(String oldId, String newId) {
        return ResultRespone.success(theOnlineCheckService.inTheTable(oldId, newId));
    }

    @PutMapping("/setPlotName")
    @ApiOperation("设置小区名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "小区名称", required = true, dataType = "string"),
            @ApiImplicitParam(name = "tableCode", value = "水表编号", required = true, dataType = "string")
    })
    public ResultRespone setPlotName(String name, String tableCode) {
        return ResultRespone.success(theOnlineCheckService.setPlotName(name, tableCode));
    }

    @PostMapping("/autoMatch")
    @ApiOperation("自动匹配关联客户表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current",value = "页数",required = true,dataType = "long"),
            @ApiImplicitParam(name = "size",value = "条数",required = true,dataType = "long")
    })
    @ApiImplicitParam(name = "current",value = "页数",required = true,dataType = "long")
    public ResultRespone autoMatch(Long current,Long size){
        return ResultRespone.success(theOnlineCheckService.autoMatch(current,size));
    }

    @GetMapping("/getSchedule")
    @ApiOperation("获取自动匹配进度进度")
    public ResultRespone getInsertSchedule(){
        return ResultRespone.success(theOnlineCheckService.getInsertSchedule());
    }

    @GetMapping("/queryCustomerByPipe")
    @ApiOperation("通过管线编号获取客户信息")
    @ApiImplicitParam(name = "pipe",value = "管线编号，多个‘,’分隔",required = true,dataType = "string")
    public ResultRespone queryCustomerByPipe(String pipe){
        return ResultRespone.success(theOnlineCheckService.queryCustomerByPipe(pipe));
    }
}
