package org.dromara.payment.taxRecords.controller;

import java.util.List;
import java.util.Map;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.payment.bill.domain.vo.MerBillDetailVo;
import org.dromara.payment.bill.domain.vo.MerBillVo;
import org.dromara.payment.common.domain.CommonSelConditionEntity;
import org.dromara.payment.taxRecords.domain.vo.MerTaxRecordsDetailVo;
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.MerTaxRecordsVo;
import org.dromara.payment.taxRecords.domain.bo.MerTaxRecordsBo;
import org.dromara.payment.taxRecords.service.IMerTaxRecordsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

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

    private final IMerTaxRecordsService merTaxRecordsService;

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

    /**
     * 导出完税证明列表
     */
    @SaCheckPermission("taxRecords:taxRecords:export")
    @Log(title = "完税证明", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MerTaxRecordsBo bo, HttpServletResponse response) {
        List<MerTaxRecordsVo> list = merTaxRecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "完税证明", MerTaxRecordsVo.class, response);
    }

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

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

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

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


    /***
     * 下载身份证
     * @param trId
     * @return
     * @throws Exception
     */
//    @SaCheckPermission("taxRecords:taxRecords:downLoadSfz")
    @Log(title = "下载身份证", businessType = BusinessType.OTHER)
    @GetMapping("/downLoadSfz")
    public R<Map> downLoadSfz(Long trId)throws Exception{
        return R.ok(merTaxRecordsService.downLoadUserworkSfz(trId));
    }


    /***
     * 下载合同
     * @param trId
     * @return
     * @throws Exception
     */
//    @SaCheckPermission("taxRecords:taxRecords:downLoadHt")
    @Log(title = "下载合同", businessType = BusinessType.OTHER)
    @GetMapping("/downLoadHt")
    public R<Map> downLoadHt(Long trId)throws Exception{
        return R.ok(merTaxRecordsService.downLoadUserworkHt(trId));
    }


    /***
     * 下载支付凭证
     * @param trId
     * @return
     * @throws Exception
     */
//    @SaCheckPermission("taxRecords:taxRecords:downLoadPayCer")
    @Log(title = "下载支付凭证", businessType = BusinessType.OTHER)
    @GetMapping("/downLoadPayCer")
    public R<Map> downLoadPay(Long trId)throws Exception{
        return R.ok(merTaxRecordsService.downLoadUserworkPayCer(trId));
    }


    @Log(title = "根据账单编号获取账单详情", businessType = BusinessType.OTHER)
    @GetMapping("/getMerBillInfo")
    public R<MerBillVo> getMerBillInfo(String billNo){
        return R.ok(this.merTaxRecordsService.getMerBillInfo(billNo));
    }




//    @SaCheckPermission("taxRecords:taxRecords:list")
    @Log(title = "根据账单编号获取账单明细", businessType = BusinessType.OTHER)
//    @GetMapping("/getMbDetailList")
    public TableDataInfo<MerBillDetailVo> getMerBillDetailList(String billNo, PageQuery pageQuery) {
        return merTaxRecordsService.getMerBillDetailList(billNo, pageQuery);
    }




    @Log(title = "根据开票流水号获取开票详情", businessType = BusinessType.OTHER)
    @GetMapping("/getInvInfo")
    public R  getInvInfo(String invNo){
        return R.ok(this.merTaxRecordsService.getInvInfo(invNo));
    }



//    /    @SaCheckPermission("taxRecords:taxRecords:list")
    @Log(title = "根据开票流水号分页获取发票明细", businessType = BusinessType.OTHER)
    @GetMapping("/getMbDetailList")
    public TableDataInfo getInvDetailList(String invNo, PageQuery pageQuery) {
        return merTaxRecordsService.getInvDetailList(invNo, pageQuery);
    }







}
