package com.yuchen.saas.park.service.controller.property;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.property.*;
import com.yuchen.saas.park.api.vo.property.*;
import com.yuchen.saas.park.service.service.property.IPropertyPublicMeterReadingService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 公摊仪表抄表 前端控制器
 * </p>
 *
 * @author cxj
 * @since 2023-12-04
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/propertyPublicMeterReading")
public class PropertyPublicMeterReadingController {

    private final IPropertyPublicMeterReadingService baseService;

    @GetMapping("listForMeter")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "公摊仪表抄表-概况(按仪表统计)", notes = "房源仪表抄表-概况(按仪表统计)")
    public R<PropertyPublicMeterReadingForMeterVo> listForMeter(@Valid PropertyPublicMeterReadingQueryDto dto) {
        PropertyPublicMeterReadingForMeterVo vo = baseService.listForMeter(dto);
        return R.data(vo);
    }

    @GetMapping("getPageByPark")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "公摊仪表抄表-概况分页查询(批量录入抄表数据)", notes = "公摊仪表抄表-概况分页查询(批量录入抄表数据)")
    public R<NestPage<PropertyPublicMeterReadingByParkPageVo>> getPageByPark(@Valid PropertyPublicMeterReadingQueryDto dto) {
        NestPage<PropertyPublicMeterReadingByParkPageVo> page = baseService.getPageByPark(dto);
        return R.data(page);
    }

    @PostMapping("/addList")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "批量新增", notes = "批量新增")
    public R addList(@Valid @RequestBody List<PropertyPublicMeterReadingAddDto> dto) {
        return R.status(baseService.addList(dto));
    }


    @GetMapping("getPageForDetail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "公摊仪表抄表-(/明细/历史)", notes = "房源仪表抄表-(/明细/历史)")
    public R<NestPage<PropertyPublicMeterReadingDetailPageVo>> getPageForDetail(@Valid PropertyPublicMeterReadingDetailQueryDto dto) {
        NestPage<PropertyPublicMeterReadingDetailPageVo> page = baseService.getPageForDetail(dto);
        return R.data(page);
    }

    @PostMapping("/deleteList")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "批量删除", notes = "删除")
    public R deleteList(@RequestBody List<Long> ids) {
        return R.status(baseService.deleteList(ids));
    }

    @GetMapping("getPageByReading")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "公摊仪表抄表-分摊明细-分页", notes = "公摊仪表抄表-分摊明细-分页")
    public R<NestPage<PropertyPublicMeterReadingPageVo>> getPageByReading(@Valid PropertyPublicMeterReadingQueryDto dto) {
        NestPage<PropertyPublicMeterReadingPageVo> page = baseService.getPageByReading(dto);
        return R.data(page);
    }

    @GetMapping("getShareCount")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "公摊仪表抄表-分摊进度", notes = "公摊仪表抄表-分摊进度")
    public R<PropertyPublicMeterReadingCountVo> getShareCount(@Valid PropertyPublicMeterReadingQueryDto dto) {
        PropertyPublicMeterReadingCountVo vo = baseService.getShareCount(dto);
        return R.data(vo);
    }

    @PostMapping("/shareList")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "批量分摊/单个分摊", notes = "批量分摊/单个分摊")
    public R<PropertyPublicMeterReadingShareResultVo> shareList(@RequestBody List<Long> ids) {
        return R.data(baseService.shareList(ids));
    }

    @GetMapping("getSharePage")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "公摊仪表抄表-分摊结果-分页", notes = "公摊仪表抄表-分摊结果-分页")
    public R<NestPage<PropertyPublicMeterReadingSharePageVo>> getSharePage(@Valid PropertyPublicMeterReadingShareQueryDto dto) {
        NestPage<PropertyPublicMeterReadingSharePageVo> page = baseService.getSharePage(dto);
        return R.data(page);
    }
}
