package com.tofly.qualitycontrol.controller;

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.qualitycontrol.dto.CollectionNumberSummaryClientDTO;
import com.tofly.qualitycontrol.dto.CollectionNumberSummaryDTO;
import com.tofly.qualitycontrol.entity.CollectionNumberDetail;
import com.tofly.qualitycontrol.entity.CollectionNumberSummary;
import com.tofly.qualitycontrol.service.ICollectionNumberSummaryService;
import com.tofly.qualitycontrol.vo.CollectionNumberClientVO;
import com.tofly.qualitycontrol.vo.CollectionNumberSummaryGraphVO;
import com.tofly.qualitycontrol.vo.CollectionNumberSummaryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

import static com.tofly.qualitycontrol.common.QualityControlConstant.SUCCESS;

/**
 * 归集管理控制器
 *
 * @author B
 */
@RestController
@RequestMapping("/collectionNumberSummary")
@Api(value = "归集汇总分析接口", tags = "归集汇总分析接口")
@RequiredArgsConstructor
public class CollectionNumberSummaryController {

	private final ICollectionNumberSummaryService collectionNumberSummaryService;

	@ApiImplicitParams({
							   @ApiImplicitParam(value = "开始日期,如202101", name = "startDate", required = false, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "结束日期,如202102", name = "endDate", required = false, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "归集编号或名称", name = "collectionInfo", required = false, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "客户编号", name = "clientNumber", required = false, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "客户姓名", name = "clientName", required = false, paramType = "query", dataType = "string", dataTypeClass = String.class),
					   })
	@ApiOperation(value = "归集汇总分析分页,查询", notes = "", httpMethod = "POST")
	@PostMapping("/list")
	public ResultRespone<IPage<CollectionNumberSummaryVO>> list(@RequestParam(required = false) String startDate,@RequestParam(required = false) String endDate,@RequestParam(required = false) String collectionInfo,@RequestParam(required = false) String clientNumber,@RequestParam(required = false) String clientName,@RequestBody Page<CollectionNumberSummary> page) {
		return ResultRespone.success(collectionNumberSummaryService.getList(startDate,endDate,collectionInfo,clientNumber,clientName,page),SUCCESS);
	}

	@ApiOperation(value = "导出当前归集汇总分析列表excel", notes = "传入当前list,用collectionNumberSummaryDTO包装", httpMethod = "POST")
	@PostMapping("/export")
	public void export(HttpServletResponse response,@RequestBody CollectionNumberSummaryDTO collectionNumberSummaryDTO) {
		collectionNumberSummaryService.export(response,collectionNumberSummaryDTO);
	}

	@ApiOperation(value = "导出当前归集中客户统计信息列表excel", notes = "传入当前list,用collectionNumberSummaryClientDTO包装", httpMethod = "POST")
	@PostMapping("/exportClientDetail")
	public void exportClientDetail(HttpServletResponse response,@RequestBody CollectionNumberSummaryClientDTO collectionNumberSummaryClientDTO) {
		collectionNumberSummaryService.exportClientDetail(response,collectionNumberSummaryClientDTO);
	}

	@ApiImplicitParams({
							   @ApiImplicitParam(value = "归集编号", name = "collectionNumber", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "开始日期,如202101", name = "startDate", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "结束日期,如202102", name = "endDate", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
					   })
	@ApiOperation(value = "汇总分析里的详情分页,查询", notes = "点击归集汇总分析,弹出的页面,每个客户的费用合计信息", httpMethod = "POST")
	@PostMapping("/getDetailList")
	public ResultRespone<IPage<CollectionNumberClientVO>> getDetailList(@RequestParam String collectionNumber,@RequestParam String startDate,@RequestParam String endDate,@RequestBody Page<CollectionNumberDetail> page) {
		return ResultRespone.success(collectionNumberSummaryService.getDetailList(collectionNumber,startDate,endDate,page),SUCCESS);
	}

	@ApiImplicitParams({
							   @ApiImplicitParam(value = "归集号", name = "collectionNumber", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "开始日期,如202101", name = "startDate", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "结束日期,如202102", name = "endDate", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class)
					   })
	@ApiOperation(value = "归集月份水量波动图", notes = "", httpMethod = "GET")
	@GetMapping("/getCollectionMonthGraph")
	public ResultRespone<List<CollectionNumberSummaryGraphVO>> getCollectionMonthGraph(@RequestParam String collectionNumber,@RequestParam String startDate,@RequestParam String endDate) {
		return ResultRespone.success(collectionNumberSummaryService.getCollectionMonthGraph(collectionNumber,startDate,endDate),SUCCESS);
	}

	@ApiImplicitParams({
							   @ApiImplicitParam(value = "客户编号", name = "clientNumber", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "开始日期,如202101", name = "startDate", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
							   @ApiImplicitParam(value = "结束日期,如202102", name = "endDate", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class)
					   })
	@ApiOperation(value = "客户月份水量波动图", notes = "", httpMethod = "GET")
	@GetMapping("/getClientMonthGraph")
	public ResultRespone<List<CollectionNumberSummaryGraphVO>> getClientMonthGraph(@RequestParam String clientNumber,@RequestParam String startDate,@RequestParam String endDate) {
		return ResultRespone.success(collectionNumberSummaryService.getClientMonthGraph(clientNumber,startDate,endDate),SUCCESS);
	}

	@ApiImplicitParams({
							   @ApiImplicitParam(value = "客户编号", name = "clientNumber", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
					   })
	@ApiOperation(value = "客户历史三月水量波动图", notes = "", httpMethod = "GET")
	@GetMapping("/getClientHistoryGraph")
	public ResultRespone<List<CollectionNumberSummaryGraphVO>> getClientHistoryGraph(@RequestParam String clientNumber) {
		return ResultRespone.success(collectionNumberSummaryService.getClientHistoryGraph(clientNumber),SUCCESS);
	}

}
