package org.dromara.controller.houseInfo;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.domain.houseInfo.bo.PropertyFeeBo;
import org.dromara.domain.houseInfo.vo.PropertyFeeVo;
import org.dromara.service.IPropertyFeeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 物业费管理
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/fee")
public class PropertyFeeController extends BaseController {

    private final IPropertyFeeService propertyFeeService;

    /**
     * 查询物业费管理列表
     */
    @SaCheckPermission("wuYe:fee:list")
    @GetMapping("/list")
    public TableDataInfo<PropertyFeeVo> list(PropertyFeeBo bo, PageQuery pageQuery) {
        return propertyFeeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出物业费管理列表
     */
    @SaCheckPermission("wuYe:fee:export")
    @Log(title = "物业费管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PropertyFeeBo bo, HttpServletResponse response) {
        List<PropertyFeeVo> list = propertyFeeService.queryList(bo);
        ExcelUtil.exportExcel(list, "物业费管理", PropertyFeeVo.class, response);
    }

    /**
     * 获取物业费管理详细信息
     *
     * @param propertyId 主键
     */
    @SaCheckPermission("wuYe:fee:query")
    @GetMapping("/{propertyId}")
    public R<PropertyFeeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long propertyId) {
        return R.ok(propertyFeeService.queryById(propertyId));
    }

    /**
     * 新增物业费管理
     */
    @SaCheckPermission("wuYe:fee:add")
    @Log(title = "物业费管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PropertyFeeBo bo) {
        return toAjax(propertyFeeService.insertByBo(bo));
    }

    /**
     * 修改物业费管理
     */
    @SaCheckPermission("wuYe:fee:edit")
    @Log(title = "物业费管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PropertyFeeBo bo) {
        return toAjax(propertyFeeService.updateByBo(bo));
    }

    /**
     * 删除物业费管理
     *
     * @param propertyIds 主键串
     */
    @SaCheckPermission("wuYe:fee:remove")
    @Log(title = "物业费管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{propertyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] propertyIds) {
        return toAjax(propertyFeeService.deleteWithValidByIds(List.of(propertyIds), true));
    }

    /**
     * 物业费统计
     */
    @SaCheckPermission("wuYe:fee:statistics")
    @Log(title = "物业费管理", businessType = BusinessType.DELETE)
    @GetMapping("/statistics")
    public R<Map<String, BigDecimal>> statistics(@RequestBody PropertyFeeBo bo)
    {
        return propertyFeeService.statistics(bo);
    }

    /**
     * 物业费催缴
     */
    @SaCheckPermission("wuYe:fee:callPayment")
    @Log(title = "物业费管理", businessType = BusinessType.DELETE)
    @GetMapping("/callPayment/{houseId}")
    public R<Void> CallPayment(@PathVariable Long houseId)
    {
        return propertyFeeService.CallPayment(houseId);
    }

    /**
     * 物业费催缴（一键催缴）
     */
    @SaCheckPermission("wuYe:fee:callPaymentAll")
    @Log(title = "物业费管理", businessType = BusinessType.DELETE)
    @GetMapping("/callPaymentAll")
    public R<Void> CallPaymentAll(@RequestBody PropertyFeeBo bo)
    {
        return propertyFeeService.CallPaymentAll(bo);
    }
}
