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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.ChangeTableCondition;
import com.tofly.watermeter.custom.entity.meterBusiness.dto.ChangeTableDto;
import com.tofly.watermeter.custom.service.meterBusiness.ChangeTableService;
import com.tofly.watermeter.entity.Bwhbdatail;
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.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/changeTable")
@Api(tags = "表务管理-水表换表改动接口")
public class ChangeTableController {

    private final ChangeTableService changeTableService;

    @PostMapping("/changeTable")
    @ApiOperation("水表换表")
    public ResultRespone changeTable(ChangeTableDto dto, @RequestParam(value = "signature", required = false) List<MultipartFile> signature, @RequestParam(value = "images", required = false) List<MultipartFile> images) {
        return ResultRespone.success(changeTableService.changeTableStaging(dto, signature, images));
    }

    @PostMapping("/changeTableBatch")
    @ApiOperation("批量换表")
    public ResultRespone changeTableBatch(String dto, @RequestParam(value = "signature", required = false) List<MultipartFile> signature, @RequestParam(value = "images", required = false) List<MultipartFile> images) {
        return ResultRespone.success(changeTableService.batchInsertStaging(dto, signature, images));
    }

    @GetMapping("/queryInfo")
    @ApiOperation("查询换表客户信息")
    @ApiImplicitParam(name = "dto", value = "模糊查询用户地址、姓名、电话、编号，水表编号")
    public ResultRespone queryInfo(Page page, String dto, String sbkj, String sblx, String sbcj) {
        return ResultRespone.success(changeTableService.queryInfo(page, dto, sbkj, sblx, sbcj));
    }

    @GetMapping("/countChangeTable")
    @ApiOperation("换表统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "export", value = "0 不导出 1 导出", required = true, dataType = "long"),
            @ApiImplicitParam(name = "dept", value = "部门", dataType = "List<Long>"),
            @ApiImplicitParam(name = "vendor", value = "厂家", dataType = "List<Long>"),
            @ApiImplicitParam(name = "start", value = "开始月份 yyyy-MM-dd", required = true, dataType = "string"),
            @ApiImplicitParam(name = "end", value = "结束月份 yyyy-MM-dd", required = true, dataType = "string")
    })
    public ResultRespone countChangeTable(HttpServletResponse response, ChangeTableCondition dto) {
        return ResultRespone.success(changeTableService.countChangeTable(response, dto));
    }

    @GetMapping("/queryChangeTable")
    @ApiOperation("换表详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "export", value = "0 不导出 1 导出", required = true, dataType = "long"),
            @ApiImplicitParam(name = "dept", value = "部门", dataType = "List<Long>"),
            @ApiImplicitParam(name = "vendor", value = "厂家", dataType = "List<Long>"),
            @ApiImplicitParam(name = "cal", value = "口径", dataType = "List<Long>"),
            @ApiImplicitParam(name = "type", value = "类型", dataType = "List<Long>"),
            @ApiImplicitParam(name = "start", value = "开始月份 yyyy-MM-dd", required = true, dataType = "string"),
            @ApiImplicitParam(name = "end", value = "结束月份 yyyy-MM-dd", required = true, dataType = "string"),
            @ApiImplicitParam(name = "isSyn", value = "0 暂存 1 已同步 2 未同步", dataType = "long")
    })
    public ResultRespone queryChangeTable(Page page, HttpServletResponse response, ChangeTableCondition dto) {
        return ResultRespone.success(changeTableService.queryChangeTable(page, response, dto));
    }

    @GetMapping("/newChangeTable")
    @ApiOperation("水表换表同步")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "列表id",required = true,dataType = "string"),
            @ApiImplicitParam(name = "state",value = "是否同步 0 暂存 1 同步 2 未同步 3 无需同步",dataType = "long"),
            @ApiImplicitParam(name = "auditOpinion",value = "审核意见",dataType = "string")
    })
    public ResultRespone newChangeTable(String ids,Long state,String auditOpinion) {
        return ResultRespone.success(changeTableService.newChangeTable(ids,state,auditOpinion));
    }

    @PutMapping("/updateChangeTable")
    @ApiOperation("水表换表信息修改")
    public ResultRespone updateChangeTable(@RequestParam(value = "signatures", required = false) List<MultipartFile> signatures, @RequestParam(value = "images", required = false) List<MultipartFile> images, Bwhbdatail datail) {
        return ResultRespone.success(changeTableService.updateChangeTable(signatures, images, datail));
    }

    @GetMapping("/changeTableCause")
    @ApiOperation("换表原因")
    public ResultRespone changeTableCause() throws Exception {
        return ResultRespone.success(changeTableService.changeTableCause());
    }

    @GetMapping("/changeTableCountByType")
    @ApiOperation("根据水表类型统计")
    public ResultRespone changeTableCountByType(ChangeTableCondition dto){
        return ResultRespone.success(changeTableService.changeTableCountByType(dto));
    }

    @GetMapping("/getModelInfo")
    @ApiOperation("获取换表森鑫炬水表型号")
    public ResultRespone getModelInfo(String factory){
        return ResultRespone.success(changeTableService.getModelInfo(factory));
    }

}
