package com.zksy.controller.property;

import com.zksy.property.domain.ARefund;
import com.zksy.property.service.ARefundService;
import com.zksy.utils.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0
 * @project enterprise-assets-service
 * @description 退款控制层
 * @date 2025/6/24 14:33:13
 */
@RestController
@RequestMapping("/arefund")
@Api(tags = "退款信息",description = "退款信息desc")
public class ARefundController {
    @Autowired
    private ARefundService service;
    @GetMapping("/findByPage")
    @ApiOperation(value = "退款信息查询分页")
    public AjaxResult findByPage(long pageNum, long pageSize, String unit,String tenant,String generationDate){
        return AjaxResult.success(service.findByPage(pageNum, pageSize, unit,tenant,generationDate));
    }

    @GetMapping("/findByPageWithContract")
    @ApiOperation(value = "收据信息查询分页")
    public AjaxResult findByPageWithContract(long pageNum, long pageSize, String unit,String tenant,String contractNumber){
        return AjaxResult.success(service.findByPageWithContract(pageNum, pageSize, unit,tenant,contractNumber));
    }
    @GetMapping("/getARefundList")
    @ApiOperation(value = "退款信息查询")
    public AjaxResult getARefundList(String unit,String tenant,String generationDate){
        return AjaxResult.success(service.getARefundList(unit,tenant,generationDate));
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据Id查询退款信息")
    public AjaxResult getById(@PathVariable String id){
        return AjaxResult.success(service.getById(id));
    }
    @PostMapping("/save")
    @ApiOperation(value = "退款信息保存")
    public AjaxResult save(@RequestBody ARefund entity) {
        return service.save(entity) ? AjaxResult.success(entity) : AjaxResult.error("保存失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "退款信息修改")
    public AjaxResult update(@RequestBody ARefund entity) {
        entity.setUpdateTime(LocalDateTime.now());
        return service.updateById(entity) ? AjaxResult.success(entity) : AjaxResult.error("修改失败");
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "退款信息删除")
    public AjaxResult delete(@RequestBody String[] ids) {
        return service.removeBatchByIdsWithUrl(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
    @GetMapping("/calculateMonthlyRefundStatistics")
    @ApiOperation(value = "退款信息月度统计")
    public AjaxResult calculateMonthlyRefundStatistics(int year) {
        return AjaxResult.success(service.calculateMonthlyRefundStatistics(year));
    }
    @GetMapping("/calculateQuarterlyRefundStatistics")
    @ApiOperation(value = "退款信息季度统计")
    public AjaxResult calculateQuarterlyRefundStatistics(int year) {
        return AjaxResult.success(service.calculateQuarterlyRefundStatistics(year));
    }
    @GetMapping("/calculateYearlyRefundStatistics")
    @ApiOperation(value = "退款信息年度统计")
    public AjaxResult calculateYearlyRefundStatistics() {
        return AjaxResult.success(service.calculateYearlyRefundStatistics());
    }
    @GetMapping("/getExistingRefundYears")
    @ApiOperation(value = "退款信息查询所有年份")
    public AjaxResult getExistingRefundYears() {
        return AjaxResult.success(service.getExistingRefundYears());
    }

}
