package com.propertyManagement.web.controller.business;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.propertyManagement.business.domain.bo.WxPayRecordBo;
import com.propertyManagement.business.domain.vo.WxPayRecordVo;
import com.propertyManagement.business.service.IWxPayRecordService;
import com.propertyManagement.common.annotation.Log;
import com.propertyManagement.common.annotation.RepeatSubmit;
import com.propertyManagement.common.core.controller.BaseController;
import com.propertyManagement.common.core.domain.PageQuery;
import com.propertyManagement.common.core.domain.R;
import com.propertyManagement.common.core.page.TableDataInfo;
import com.propertyManagement.common.core.validate.AddGroup;
import com.propertyManagement.common.core.validate.EditGroup;
import com.propertyManagement.common.enums.BusinessType;
import com.propertyManagement.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 缴费记录
 *
 * @author liushuai
 * @date 2025-05-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/payRecord")
public class WxPayRecordController extends BaseController {

    private final IWxPayRecordService iWxPayRecordService;

    /**
     * 查询缴费记录列表
     */
    @SaCheckPermission("business:payRecord:list")
    @GetMapping("/list")
    public TableDataInfo<WxPayRecordVo> list(WxPayRecordBo bo, PageQuery pageQuery) {
        return iWxPayRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出缴费记录列表
     */
    @SaCheckPermission("business:payRecord:export")
    @Log(title = "缴费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WxPayRecordBo bo, HttpServletResponse response) {
        List<WxPayRecordVo> list = iWxPayRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "缴费记录", WxPayRecordVo.class, response);
    }

    /**
     * 获取缴费记录详细信息
     *
     * @param recordId 主键
     */
    @SaCheckPermission("business:payRecord:query")
    @GetMapping("/{recordId}")
    public R<WxPayRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long recordId) {
        return R.ok(iWxPayRecordService.queryById(recordId));
    }

    /**
     * 新增缴费记录
     */
    @SaCheckPermission("business:payRecord:add")
    @Log(title = "缴费记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WxPayRecordBo bo) {
        return toAjax(iWxPayRecordService.insertByBo(bo));
    }

    /**
     * 修改缴费记录
     */
    @SaCheckPermission("business:payRecord:edit")
    @Log(title = "缴费记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WxPayRecordBo bo) {
        return toAjax(iWxPayRecordService.updateByBo(bo));
    }

    /**
     * 删除缴费记录
     *
     * @param recordIds 主键串
     */
    @SaCheckPermission("business:payRecord:remove")
    @Log(title = "缴费记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] recordIds) {
        return toAjax(iWxPayRecordService.deleteWithValidByIds(Arrays.asList(recordIds), true));
    }
}
