package org.dromara.payment.taxRecords.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
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.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.payment.taxRecords.domain.vo.MerTaxRecordsDetailVo;
import org.dromara.payment.taxRecords.domain.bo.MerTaxRecordsDetailBo;
import org.dromara.payment.taxRecords.service.IMerTaxRecordsDetailService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 完税证明
 * 前端访问路由地址为:/taxRecords/taxRecordsDetail
 *
 * @author LionLi
 * @date 2024-05-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/taxRecordsDetail")
public class MerTaxRecordsDetailController extends BaseController {

    private final IMerTaxRecordsDetailService merTaxRecordsDetailService;

    /**
     * 查询完税证明列表
     */
//    @SaCheckPermission("taxRecords:taxRecordsDetail:list")
    @GetMapping("/list")
    public TableDataInfo<MerTaxRecordsDetailVo> list(MerTaxRecordsDetailBo bo, PageQuery pageQuery) {
        return merTaxRecordsDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出完税证明列表
     */
//    @SaCheckPermission("taxRecords:taxRecordsDetail:export")
    @Log(title = "完税证明", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MerTaxRecordsDetailBo bo, HttpServletResponse response) {
        List<MerTaxRecordsDetailVo> list = merTaxRecordsDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "报税汇总金额", MerTaxRecordsDetailVo.class, response);
    }

    /**
     * 获取完税证明详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("taxRecords:taxRecordsDetail:query")
    @GetMapping("/{id}")
    public R<MerTaxRecordsDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(merTaxRecordsDetailService.queryById(id));
    }

    /**
     * 新增完税证明
     */
    @SaCheckPermission("taxRecords:taxRecordsDetail:add")
    @Log(title = "完税证明", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MerTaxRecordsDetailBo bo) {
        return toAjax(merTaxRecordsDetailService.insertByBo(bo));
    }

    /**
     * 修改完税证明
     */
    @SaCheckPermission("taxRecords:taxRecordsDetail:edit")
    @Log(title = "完税证明", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MerTaxRecordsDetailBo bo) {
        return toAjax(merTaxRecordsDetailService.updateByBo(bo));
    }

    /**
     * 删除完税证明
     *
     * @param ids 主键串
     */
    @SaCheckPermission("taxRecords:taxRecordsDetail:remove")
    @Log(title = "完税证明", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(merTaxRecordsDetailService.deleteWithValidByIds(List.of(ids), true));
    }
}
