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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.manage.system.api.param.CommonListIdParam;
import com.yuchen.saas.park.api.dto.property.*;
import com.yuchen.saas.park.api.vo.property.PropertyBillListVo;
import com.yuchen.saas.park.api.vo.property.PropertyBillReductionListVo;
import com.yuchen.saas.park.api.vo.property.PropertyFeeReductionListVo;
import com.yuchen.saas.park.service.service.property.bill.PropertyBillSearchService;
import com.yuchen.saas.park.service.service.property.bill.PropertyBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "账单管理")
@RestController
@RequestMapping("/propertyBill")
public class PropertyBillController {
    @Resource
    private PropertyBillSearchService propertyBillSearchService;
    @Resource
    private PropertyBillService propertyBillService;

    /**
     * 账单列表
     * @param propertyBillPageQryDto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "账单列表")
    public R<Page<PropertyBillListVo>> list(@RequestBody PropertyBillPageQryDto propertyBillPageQryDto) {
        return R.data(propertyBillSearchService.selectBillFullInfoPage(propertyBillPageQryDto));
    }

    /**
     * 未出账单导出
     */
    @PostMapping("/export")
    @ApiOperation(value = "未出账单导出")
    public void exportEnterprise(@RequestBody PropertyBillPageQryDto qryDto, HttpServletResponse response) {
        propertyBillSearchService.export(qryDto, response);
    }


    /**
     * 更改费用承租人
     * @param changeFeesLesseeDto
     * @return
     */
    @PostMapping("/changeFeesLessee")
    @ApiOperation(value = "更改费用承租人")
    public R changeFeesLessee(@Valid @RequestBody PropertyChangeFeesLesseeDto changeFeesLesseeDto) {
        propertyBillService.updateBillCustomer(changeFeesLesseeDto.getId(),changeFeesLesseeDto.getCustomerId());
        return R.success();
    }


    /**
     * 未出账单出账
     * @param commonListIdParam
     * @return
     */
    @PostMapping("/outBill")
    @ApiOperation(value = "未出账单出账")
    public R outBill(@Valid @RequestBody CommonListIdParam commonListIdParam) {
        propertyBillService.outBill(commonListIdParam.getIds());
        return R.success();
    }


    /**
     * 设置欠费原因
     * @param arrearsReasonDto
     * @return
     */
    @PostMapping("/setArrearsReason")
    @ApiOperation(value = "设置欠费原因")
    public R setArrearsReason(@Valid @RequestBody PropertyArrearsReasonDto arrearsReasonDto) {
        propertyBillService.setArrearsReason(arrearsReasonDto);
        return R.success();
    }


    /**
     * 冻结账单
     * @param commonIdParam
     * @return
     */
    @PostMapping("/freezeBill")
    @ApiOperation(value = "冻结账单")
    public R freezeBill(@Valid @RequestBody CommonIdParam commonIdParam) {
        propertyBillService.freezeBill(commonIdParam.getId());
        return R.success();
    }

    /**
     * 解冻账单
     * @param commonIdParam
     * @return
     */
    @PostMapping("/unfreezeBill")
    @ApiOperation(value = "解冻账单")
    public R unfreezeBill(@Valid @RequestBody CommonIdParam commonIdParam) {
        propertyBillService.unfreezeBill(commonIdParam.getId());
        return R.success();
    }

    /**
     * 账单管理-删除（实际是将已出账单状态更变为未出账单）
     * @param commonIdParam
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation(value = "账单状态变更为未出账单")
    public R delete(@Valid @RequestBody CommonIdParam commonIdParam) {
        propertyBillService.changeNoOUt(commonIdParam.getId());
        return R.success();
    }


    /**
     * 欠费催缴
     * @param commonListIdParam
     * @return
     */
    @PostMapping("/arrearsCall")
    @ApiOperation(value = "欠费催缴")
    public R arrearsCall(@Valid @RequestBody CommonListIdParam commonListIdParam) {
        return R.status(propertyBillService.reminder(commonListIdParam.getIds()));
    }

    /**
     * 收银台-费用减免列表
     * @param queryDto
     * @return
     */
    @PostMapping("/getFeeReductionList")
    @ApiOperation(value = "收银台-费用减免列表")
    public R<NestPage<PropertyFeeReductionListVo>> getFeeReductionList(@RequestBody PropertyFeeReductionListQueryDto queryDto) {
        return R.data(propertyBillService.getFeeReductionList(queryDto));
    }


    /**
     * 收银台-费用减免列表导出
     * @param queryDto
     * @return
     */
    @PostMapping("/feeReductionListExport")
    @ApiOperation(value = "收银台-费用减免列表导出")
    public void feeReductionListExport(@RequestBody PropertyFeeReductionListQueryDto queryDto, HttpServletResponse response) {
         propertyBillService.feeReductionListExport(queryDto, response);
    }

    @PostMapping("/billReductionPage")
    @ApiOperation(value = "减免指定金额统计")
    public R<Page<PropertyBillReductionListVo>> billReductionPage(@RequestBody PropertyBillReductionPageQryDto param) {
        return R.data(propertyBillService.billReductionPage(param));
    }

    @GetMapping("/exportBillReduction")
    @ApiOperation(value = "导出减免指定金额统计", notes = "导出减免指定金额统计")
    public void exportBillReduction(PropertyBillReductionPageQryDto param, HttpServletResponse response){
        propertyBillService.exportBillReduction(param, response);
    }
}
