package com.zcxk.rmcp.web.controller;

import com.zcxk.core.common.pojo.AjaxMessage;
import com.zcxk.core.mysql.pageing.Pagination;
import com.zcxk.rmcp.api.dto.measurementsettlement.*;
import com.zcxk.rmcp.web.service.MeasurementSettlementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
/**
 *
 * @author heyumin
 * @date 2021-07-30 9:44
 */
@Controller
@ResponseBody
@RequestMapping("measurement/settlement")
@Api(tags = "计量结算")
public class MeasurementSettlementController {
    @Autowired
    private MeasurementSettlementService measurementSettlementService;

    @PostMapping(value = "/page")
    @ApiOperation(value = "分页查询结算计划")
    public AjaxMessage<Pagination<MeasurementSettlementDto>> pageMeasurementSettlement(@RequestBody @Valid MeasurementSettlementPageDto pageDto) {
        return AjaxMessage.success(measurementSettlementService.pageMeasurementSettlement(pageDto));
    }
    @PostMapping(value = "/page/record")
    @ApiOperation(value = "分页查询结算记录")
    public AjaxMessage<Pagination<MeasurementSettlementDto>> pageMeasurementSettlementRecord(@RequestBody @Valid MeasurementSettlementPageDto pageDto) {
        return AjaxMessage.success(measurementSettlementService.pageMeasurementSettlementRecord(pageDto));
    }
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增结算计划")
    public AjaxMessage<Void> addPlan(@RequestBody @Valid MeasurementSettlementDto measurementSettlementDto) {
        measurementSettlementService.addPlan(measurementSettlementDto);
        return AjaxMessage.success();
    }
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改结算计划")
    public AjaxMessage<Void> updatePlan(@RequestBody @Valid MeasurementSettlementDto measurementSettlementDto) {
        measurementSettlementService.updatePlan(measurementSettlementDto);
        return AjaxMessage.success();
    }
    @PostMapping(value = "/delete")
    @ApiOperation(value = "删除结算计划")
    public AjaxMessage<Void> deletePlan(@RequestBody List<MeasurementSettlementDto> ids) {
        measurementSettlementService.deletePlan(ids);
        return AjaxMessage.success();
    }
    @PostMapping(value = "/deleteAll")
    @ApiOperation(value = "删除所有结算计划")
    public AjaxMessage<Void> deleteAllPlan() {
        measurementSettlementService.deleteAll();
        return AjaxMessage.success();
    }
    @PostMapping(value = "/page/detail")
    @ApiOperation(value = "查询结算记录详细记录")
    public AjaxMessage<Pagination<MeasurementRecordDto>> pageMeasurementRecord(@RequestBody @Valid MeasurementRecordPageDto pageDto) {
        return AjaxMessage.success(measurementSettlementService.pageMeasurementRecord(pageDto));
    }

    @PostMapping(value = "/audit")
    @ApiOperation(value = "审核水量")
    public AjaxMessage<Void> auditWater(@RequestBody List<MeasurementRecordDto> ids) {
        measurementSettlementService.auditWater(ids);
        return AjaxMessage.success();
    }
    @PostMapping(value = "/auditAll")
    @ApiOperation(value = "审核所有水量")
    public AjaxMessage<Void> auditAllWater(@RequestParam Integer planId) {
        measurementSettlementService.auditAllWater(planId);
        return AjaxMessage.success();
    }
    @PostMapping(value = "/modifyTheAmountOfWater")
    @ApiOperation(value = "修改水量")
    public AjaxMessage<Void> modifyTheAmountOfWater(@RequestBody @Valid WaterConsumptionUpdateDto waterConsumptionUpdateDto) {
        measurementSettlementService.modifyTheAmountOfWater(waterConsumptionUpdateDto);
        return AjaxMessage.success();
    }
    @PostMapping(value = "/setBillingPeriod")
    @ApiOperation(value = "设置账期")
    public AjaxMessage<Void> setBillingPeriod(@RequestBody @Valid MeasurementSettlementDto measurementSettlementDto) {
        measurementSettlementService.setBillingPeriod(measurementSettlementDto);
        return AjaxMessage.success();
    }
}
