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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.StringUtil;
import com.tofly.common.core.util.io.ExcelUtil;
import com.tofly.common.oauth.exception.ToflyDeniedException;
import com.tofly.xrtygis.custom.entity.dma.ConstomAddPipe;
import com.tofly.xrtygis.custom.service.dma.YhBingAreaService;
import com.tofly.xrtygis.custom.service.export.ClientBingAreaService;
import com.tofly.xrtygis.entity.Dmausercbb;
import com.tofly.xrtygis.entity.Dmausertable;
import com.tofly.xrtygis.service.DmausercbbService;
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 org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;

/**
 * 用户绑定分区
 *
 * @author FlashWJL
 * @date 2021/7/20 10:04
 */
@RestController
@AllArgsConstructor
@RequestMapping("/AreaBingYh")
@Api(tags = "分区计量--用户绑定分区")
public class AreaBingYhController {

    private final YhBingAreaService yhBingAreaService;
    private final DmausercbbService dmausercbbService;

    //    @GetMapping("/getBingExcel")
//    @ApiOperation(value = "获取Excel绑定表")
//    public void getClientBingExcel(Long id , String areaName , HttpServletResponse response) {
//        yhBingAreaService.getClientBingExcel(id , areaName , response);
//    }

    @GetMapping("/cbb")
    @ApiOperation(value = "获取抄表本")
    public ResultRespone getDmausercbb( ) {
        return ResultRespone.success(dmausercbbService.list(Wrappers.<Dmausercbb>lambdaQuery().eq(Dmausercbb::getYxbz , "1")));
    }

    @GetMapping("/getBing")
    @ApiOperation(value = "根据分区ID，获取该分区下的用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "分区ID", dataType = "Long"),
            @ApiImplicitParam(name = "cbbName", value = "抄表本名称", dataType = "String"),
            @ApiImplicitParam(name = "inputcontent", value = "输入框内容", dataType = "String")
    })
    public ResultRespone getClientByArea(Long id,String cbbName, String inputcontent , Page<Dmausertable> page) {
        return ResultRespone.success(yhBingAreaService.getClientByArea(id,cbbName ,inputcontent , page));
    }

    @PostMapping("/bing")
    @ApiOperation(value = "绑定")
    @ApiImplicitParam(name = "id", value = "分区ID", dataType = "Long")
    public ResultRespone clientBingArea(Long id, MultipartFile file) {
        return ResultRespone.success(yhBingAreaService.clientBingArea(id, file));
    }

    @PostMapping("/unbing")
    @ApiOperation(value = "用户分区解绑")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "分区ID", dataType = "Long"),
            @ApiImplicitParam(name = "yhbhList", value = "用户编号；逗号隔开", dataType = "String")
    })
    public ResultRespone cientUnbingArea(@RequestBody ConstomAddPipe constomAddPipe) {
        Long id = constomAddPipe.getId();
        String yhbhList = constomAddPipe.getYhbhList();
        return ResultRespone.success(yhBingAreaService.cientUnbingArea(id, yhbhList));
    }

    @PostMapping("/unbingAreaId")
    @ApiOperation(value = "根据分区ID；解绑所有")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "分区ID", dataType = "Long")
    })
    public ResultRespone unbingAreaId(@RequestBody ConstomAddPipe constomAddPipe) {
        Long id = constomAddPipe.getId();
        return ResultRespone.success(yhBingAreaService.unbingAreaId(id));
    }


}
