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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.watermeter.custom.entity.meterRead.Allocation;
import com.tofly.watermeter.custom.entity.meterRead.AppRead;
import com.tofly.watermeter.custom.entity.meterRead.ReadSearch;
import com.tofly.watermeter.custom.entity.meterRead.YhbhAndCbxhList;
import com.tofly.watermeter.entity.Cbqydbm;
import com.tofly.watermeter.entity.Yhbingqy;
import com.tofly.watermeter.service.CbqydbmService;
import com.tofly.watermeter.service.YhbingqyService;
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;
import java.util.List;
import java.util.Map;

/**
 * @author FlashWJL
 * @date 2021/6/2 10:54
 */
@RestController
@AllArgsConstructor
@RequestMapping("/readData")
@Api(tags = "抄表--抄表数据")
public class ReadDataController {

    private final YhbingqyService yhbingqyService;
    private final CbqydbmService cbqydbmService;


    @GetMapping("/getQyCllect")
    @ApiOperation(value = "分配页面首页--区域分配汇总数据")
    public List<Map> getQyCllect(String inputcontent) {
        return yhbingqyService.getQyCllect(inputcontent);
    }

    @GetMapping("/allocationParagraph")
    @ApiOperation(value = "分配页面--区域段分配汇总数据")
    public ResultRespone allocationParagraph(Page page, @ModelAttribute Cbqydbm cbqydbm) {

        String qydbm = cbqydbm.getQydbm();
        String qybm = cbqydbm.getQybm();
        IPage<Map> mapIPage = cbqydbmService.allocationParagraph(page, qybm, qydbm);
        return ResultRespone.success(mapIPage);
    }

    @GetMapping("/getNoAllocationTwo")
    @ApiOperation(value = "分配--未分配的用户")
    public ResultRespone getNoAllocationTwo(Page page, Allocation allocation) {
        return ResultRespone.success(yhbingqyService.getNoAllocationTwo(page, allocation));
    }

    @GetMapping("/getCbbOrCbpq")
    @ApiOperation(value = "抄表本或抄表片区")
    public ResultRespone getCbbOrCbpq(String cbpq, String isPqOrCbb) {
        return ResultRespone.success(yhbingqyService.getCbbOrCbpq(cbpq, isPqOrCbb));
    }

    @PostMapping("/allocation")
    @ApiOperation(value = "分配--用户分配")
    public ResultRespone allocation(@RequestBody Allocation allocation) {
        return ResultRespone.success(yhbingqyService.allocation(allocation));
    }

    @PostMapping("/allocationManager")
    @ApiOperation(value = "分配管理--WEB端用户分配/移除")
    public ResultRespone allocationManager(@RequestBody Allocation allocation) {
        return ResultRespone.success(yhbingqyService.allocationManager(allocation));
    }

    @PostMapping("/orderManager")
    @ApiOperation(value = "排序管理")
    public ResultRespone orderManager(@RequestBody YhbhAndCbxhList yhbhAndCbxhList) {
        return ResultRespone.success(yhbingqyService.orderManager(yhbhAndCbxhList));
    }

    @PostMapping("/orderManagerTask")
    @ApiOperation(value = "排序管理-任务;APP以后也改成调用这个接口，不再使用之前那个了，之前使用代码处理太占内存，而且效率低")
    public ResultRespone orderManagerTask(@RequestBody YhbhAndCbxhList yhbhAndCbxhList) {
        return yhbingqyService.orderManagerTask(yhbhAndCbxhList);
    }


    @PostMapping("/undock")
    @ApiOperation(value = "分配--用户移除")
    public ResultRespone undock(@RequestBody Allocation allocation) {
        return ResultRespone.success(yhbingqyService.undock(allocation));
    }


    @GetMapping("/watchAllocation")
    @ApiOperation(value = "分配--已分配用户")
    public ResultRespone watchAllocation(Page<Map> page, Yhbingqy yhbingqy, String yhxm,
                                         String pqbm, String cbb, String yhdz, String inputcontent, HttpServletResponse response, String export) {
        String yhbh = yhbingqy.getYhbh();
        String qybm = yhbingqy.getQybm();
        String qydbm = yhbingqy.getQydbm();
        IPage<Map> mapList = yhbingqyService.allocationPage(page, yhbh, qybm, qydbm, yhxm, pqbm, cbb, yhdz, inputcontent, response, export);
        return ResultRespone.success(mapList);
    }

//    @PostMapping("/importFileAllcation")
//    @ApiOperation(value = "分配--根据文件导入绑定用户")
//    public ResultRespone importFileAllcation(@RequestParam("file") MultipartFile file, String qydbm, String qybm) {
//        return ResultRespone.success(yhbingqyService.importFileAllcation(file, qydbm, qybm));
//    }


    @GetMapping("/getNoOrderYh")
    @ApiOperation(value = "抄表顺序--查询不排序的目标(排除掉已选用户)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "exclude", value = "已勾选的用户，用逗号隔开", required = true, type = "String"),
            @ApiImplicitParam(name = "qydbm", value = "区域段编码", required = true, type = "String"),
            @ApiImplicitParam(name = "inputcontent", value = "搜索内容", type = "String"),
            @ApiImplicitParam(name = "isPlan", value = "是否计划的；1：是", type = "String")
    })
    public ResultRespone getNoOrderYh(Page<Map> page, String exclude, String qydbm, String inputcontent, String isPlan,String qybm) {
        return ResultRespone.success(yhbingqyService.getNoOrderYh(page, exclude, qydbm, inputcontent, isPlan,qybm));
    }

    @PostMapping("/cbOrder")
    @ApiOperation(value = "抄表顺序--修改，现在不建议使用该接口进行排序")
    public ResultRespone cbOrder(@RequestBody YhbhAndCbxhList yhbhAndCbxhList) {
        return ResultRespone.success(yhbingqyService.cbOrder(yhbhAndCbxhList));
    }

    @GetMapping("/getCbryXY")
    @ApiOperation(value = "获取抄表人员抄表水表轨迹及信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "isGeneral", value = "是否普查表；0：人工抄表；1：普查表", required = true, type = "String"),
            @ApiImplicitParam(name = "cbry", value = "抄表人员", required = true, type = "Long"),
            @ApiImplicitParam(name = "endDate", value = "开始时间", required = true, type = "Date"),
            @ApiImplicitParam(name = "startDate", value = "结束时间", required = true, type = "Date"),
    })
    public ResultRespone<List<AppRead>> getCbryXY(ReadSearch search) {
        return ResultRespone.success(yhbingqyService.getCbryXY(search));
    }

    @GetMapping("/clientDistribution")
    @ApiOperation("一键分配未分配用户")
    public ResultRespone clientDistribution(){
        return ResultRespone.success(yhbingqyService.clientDistribution());
    }


}
