package com.ruoyi.hywz.controller.stamp.tax;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.hywz.entity.AdsMatHyxtStampTaxZhptInvoiceD;
import com.ruoyi.hywz.entity.AdsMatHyxtStampTaxZhptInvoiceItemD;
import com.ruoyi.hywz.entity.po.IdsPO;
import com.ruoyi.hywz.service.IAdsMatHyxtStampTaxZhptInvoiceDService;
import com.ruoyi.hywz.service.IAdsMatHyxtStampTaxZhptInvoiceItemDService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 【印花税】【智慧平台】发票信息表 前端控制器
 * </p>
 *
 * @author mybatisplus-generator
 * @date 2024-08-23 11:15:50
 */
@RestController
@RequestMapping("adsMatHyxtStampTaxZhptInvoiceD")
@AllArgsConstructor
@Api(value = "adsMatHyxtStampTaxZhptInvoiceD", tags = "【印花税】【智慧平台】发票信息表")
public class AdsMatHyxtStampTaxZhptInvoiceDController {

    private final IAdsMatHyxtStampTaxZhptInvoiceDService adsMatHyxtStampTaxZhptInvoiceDService;
    private final IAdsMatHyxtStampTaxZhptInvoiceItemDService adsMatHyxtStampTaxZhptInvoiceItemDService;


    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/queryPage")
    public R queryPage(@RequestParam(defaultValue = "10") Long pageSize,
                       @RequestParam(defaultValue = "1") Long pageNo,
                       @RequestBody(required = false) AdsMatHyxtStampTaxZhptInvoiceD param) {
        return R.ok(adsMatHyxtStampTaxZhptInvoiceDService.queryPage(pageSize, pageNo, param));
    }

    @ApiOperation(value = "下载导入模板")
    @PostMapping("/downloadTemplate")
    public void downloadTemplate(HttpServletResponse response) {
        adsMatHyxtStampTaxZhptInvoiceDService.downloadTemplate(response);
    }

    @ApiOperation(value = "数据导入")
    @PostMapping("/importData")
    public R importData(@RequestParam("file") MultipartFile file) throws IOException {
        return adsMatHyxtStampTaxZhptInvoiceDService.importData(file);
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public R delete(@RequestBody IdsPO param) {
        adsMatHyxtStampTaxZhptInvoiceDService.deleteOne(param);
        return R.ok();
    }

    @ApiOperation(value = "批量删除")
    @PostMapping("/batchDelete")
    public R batchDelete(@RequestBody IdsPO param) {
        List<String> ids = param.getIds();
        if (ObjectUtils.isEmpty(ids) || ids.isEmpty()) {
            return R.fail("请选择要删除的数据！");
        }
        adsMatHyxtStampTaxZhptInvoiceDService.batchDelete(param);
        return R.ok();
    }

    @ApiOperation(value = "明细查询", notes = "明细查询")
    @PostMapping("/item/list")
    public R itemList(@RequestBody(required = false) AdsMatHyxtStampTaxZhptInvoiceItemD param) {
        return R.ok(adsMatHyxtStampTaxZhptInvoiceItemDService.queryList(param));
    }

    @ApiOperation(value = "下载导入模板")
    @PostMapping("/item/downloadTemplate")
    public void itemDownloadTemplate(HttpServletResponse response) {
        adsMatHyxtStampTaxZhptInvoiceItemDService.downloadTemplate(response);
    }

    @ApiOperation(value = "数据导入")
    @PostMapping("/item/importData")
    public R itemImportData(@RequestParam("file") MultipartFile file, @RequestParam("invoiceId") String invoiceId) throws IOException {
        return adsMatHyxtStampTaxZhptInvoiceItemDService.importData(file, invoiceId);
    }

    @ApiOperation(value = "批量删除")
    @PostMapping("/item/batchDelete")
    public R itemBatchDelete(@RequestBody IdsPO param) {
        List<String> ids = param.getIds();
        if (ObjectUtils.isEmpty(ids) || ids.isEmpty()) {
            return R.fail("请选择要删除的数据！");
        }
        adsMatHyxtStampTaxZhptInvoiceItemDService.batchDelete(param);
        return R.ok();
    }
}
