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.AuditQuality;
import com.tofly.watermeter.custom.entity.meterRead.ReadSearch;
import com.tofly.watermeter.custom.entity.meterRead.readstatic.AuditMap;
import com.tofly.watermeter.custom.service.ReadDataCheckService;
import com.tofly.watermeter.custom.service.ReadMeterService;
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 java.util.List;
import java.util.Map;

/**
 * 抄表管理
 *
 * @author FlashWJL
 * @date 2021/4/15 11:54
 */
@RestController
@AllArgsConstructor
@RequestMapping("/read")
@Api(tags = "抄表--抄表管理")
public class ReadController {

    private final ReadMeterService meterService;
    private final ReadDataCheckService checkService;

    @GetMapping("/getSlInfoByYh")
    @ApiOperation(value = "根据用户查看同比、环比、区域、区域段、上月水量、当月水量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yhbh", value = "用户编号", required = true, dataType = "string")
    })
    public ResultRespone getYhInfo(String yhbh) {
        return ResultRespone.success(checkService.getYhInfo(yhbh));

    }

    @GetMapping("/getRevenueStatistics")
    @ApiOperation(value = "获取营收统计信息")
    public ResultRespone<Map> getRevenueStatistics(String startMonth, String endMonth){
        return ResultRespone.success(meterService.getRevenueStatistics(startMonth, endMonth));
    }


    @GetMapping("/getReadHistory")
    @ApiOperation(value = "根据用户编号获取抄表历史数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "yhbh", value = "用户编号", required = true, dataType = "string")
    })
    public ResultRespone getReadHistory(Page page, ReadSearch search) {
        String yhbh = search.getYhbh();
        String startTime = search.getStartTime();
        String endTime = search.getEndTime();
        String isGeneral = search.getIsGeneral();
        String isCollect = search.getIsCollect();
        return ResultRespone.success(meterService.getReadHistory(page, yhbh, startTime, endTime, isGeneral, isCollect));
    }


    @GetMapping("/getStatisAudit")
    @ApiOperation(value = "抄表审核--异常汇总数据")
    public ResultRespone getStatisAudit(String yearMonth, String isGeneral) {
        return ResultRespone.success(meterService.getStatisAudit(yearMonth, isGeneral));
    }


    @GetMapping("/getAudit")
    @ApiOperation(value = "抄表审核数据查看")
    public ResultRespone<IPage<AuditMap>> getAuditCbData(Page page, ReadSearch search) {
        return ResultRespone.success(meterService.getAuditCbData(page, search));
    }

    //@RequestPart @Valid AuditQuality auditQuality , @RequestPart(value = "fileList", required = false) List<MultipartFile> fileList
    @PostMapping("/audit")
    @ApiOperation(value = "抄表数据审核(通过、不通过)")
    public ResultRespone auditCbData(@RequestBody AuditQuality auditQuality) {
        return meterService.auditCbData(auditQuality, null);
    }

    @PostMapping("/auditYc")
    @ApiOperation(value = "抄表数据审核(通过、不通过)")
    public ResultRespone auditYcbData(@RequestBody AuditQuality auditQuality) {
        return meterService.auditYcbData(auditQuality, null);
    }

    /**
     * 这个接口与上面的是一模一样的，只不过前端的传参修改很麻烦
     *
     * @param auditQuality
     * @return
     */
    @PostMapping("/auditRedDeploy")
    @ApiOperation(value = "抄表数据审核(转工单)")
    public ResultRespone auditCbDataRedDeploy(AuditQuality auditQuality, List<MultipartFile> fileList) {
        return meterService.auditCbData(auditQuality, fileList);
    }

    @PostMapping("/auditRedDeployYc")
    @ApiOperation(value = "抄表数据审核(转工单)")
    public ResultRespone auditYcbDataRedDeploy(AuditQuality auditQuality, List<MultipartFile> fileList) {
        return meterService.auditYcbData(auditQuality, fileList);
    }


    @GetMapping("/getSbByRFID")
    @ApiOperation(value = "APP根据RFID查询水表信息")
    public ResultRespone getSbByRFID(String rfid) {
        return ResultRespone.success(meterService.getSbByRFID(rfid));
    }


    /**
     * 生成抄表
     * 抄表数据；每月27号凌晨4点
     *
     * @return
     */
    @ApiOperation(value = "手动获取森鑫炬抄表数据，之后改在每月27日")
    @GetMapping("/generate")
    public ResultRespone generateReadPlan() {
        return ResultRespone.success(meterService.generateReadPlan());
    }

    /**
     * 生成抄表
     * 抄表数据；每月27号凌晨4点重写
     *
     * @return
     */
    @ApiOperation(value = "手动获取森鑫炬抄表数据，之后改在每月27日重写")
    @GetMapping("/generateReadPlanRewrite")
    public ResultRespone generateReadPlanRewrite() {
        return ResultRespone.success(meterService.generateReadPlanRewrite());
    }


    /**
     * 获取抄表历史数据
     *
     * @return
     */
    @ApiOperation(value = "手动获取森鑫炬抄表历史数据，之后改在每月27日")
    @GetMapping("/generateHistory")
    public ResultRespone generateRealHistory() {
        return ResultRespone.success(meterService.generateHistory());
    }

    /**
     * 获取用水性质
     * 用水性质；每月27号凌晨1点，与上面的时间隔开
     *
     * @return
     */
    @ApiOperation(value = "手动获取森鑫炬用水性质数据，之后改在每月27日")
    @GetMapping("/waterNature")
    public ResultRespone generateWaterNature() {
        return ResultRespone.success(meterService.generateWaterNature());
    }

    /**
     * 获取用水细分性质
     * 用水性质；每月27号凌晨2点，与上面的时间隔开
     *
     * @return
     */
    @ApiOperation(value = "手动获取森鑫炬用水细分性质数据，之后改在每月27日")
    @GetMapping("/waterXFNature")
    public ResultRespone generateWaterXFNature() {
        return ResultRespone.success(meterService.generateWaterXFNature());
    }

    @ApiOperation(value = "手动获取森鑫炬客户信息，之后改在每月27日")
    @GetMapping("/genClientInfo")
    public ResultRespone genClientInfo() {
        return ResultRespone.success(meterService.genClientInfo());
    }

    @ApiOperation(value = "手动获取森鑫炬客户用水量")
    @GetMapping("/historyWaterData")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "again", value = "是否清空数据库", required = true, dataType = "Boolean")
    })
    public ResultRespone genHistoryWaterData(Boolean again) {
        return ResultRespone.success(meterService.getHistoryWaterData(again));
    }

    @ApiOperation(value = "获取用户最新抄表用水量")
    @GetMapping("/getNewCbsl")
    public String getNewCbsl(String yhbh) {
        return meterService.getNewCbsl(yhbh);
    }


}
