package com.bonus.material.purchase.controller;

import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.material.purchase.domain.dto.PurchaseDto;
import com.bonus.material.purchase.service.IPurchaseBindService;
import com.bonus.material.purchase.domain.vo.PurchaseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 新购验收绑定接口
 * @Author ma_sh
 * @create 2024/10/21 18:41
 */
@Api(tags = "新购验收绑定接口")
@RestController
@RequestMapping("/purchase/bind")
public class PurchaseBindController extends BaseController {

    @Resource
    private IPurchaseBindService purchaseBindService;

    /**
     * 一级分页查询
     */
//    @ApiOperation(value = "查询新购验收绑定详细列表")
//    @RequiresPermissions("purchase:bind:list")
//    @GetMapping(value = "/list")
//    public TableDataInfo getList(PurchaseDto dto) {
//        startPage();
//        List<PurchaseVo> list = purchaseBindService.selectAll(dto);
//        return getDataTable(list);
//    }

    /**
     * 获取新购绑定二级明细列表
     * @param
     * @return
     */
//    @ApiOperation(value = "获取新购绑定二级明细列表")
//    @RequiresPermissions("purchase:bind:query")
//    @GetMapping("/details")
//    public TableDataInfo getDetails(PurchaseDto dto) {
//        startPage();
//        List<PurchaseVo> list = purchaseBindService.getDetails(dto);
//        return getDataTable(list);
//    }

    /**
     * 绑定
     * @param dto
     * @return
     */
    @ApiOperation(value = "编码绑定")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:bind:add")
    @PostMapping("/bind")
    public AjaxResult bind(@RequestBody PurchaseDto dto) {
        return purchaseBindService.bind(dto);
    }

    /**
     * 获取新购验收绑定详细信息
     */
    @ApiOperation(value = "获取新购验收绑定详细信息")
    @RequiresPermissions("purchase:bind:query")
    @GetMapping(value = "/getById")
    public AjaxResult getInfo(PurchaseDto dto) {
        return purchaseBindService.selectPurchaseCheckInfoById(dto);
    }

    /**
     * 二维码生成下载一体操作
     * @param response
     * @param purchaseDto
     */
    @ApiOperation(value = "二维码生成下载")
    @PostMapping(value = "/downloadQrCode")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:bind:download")
    public void downloadQrCode(HttpServletResponse response, PurchaseDto purchaseDto) {
        purchaseBindService.downloadQrCode(response, purchaseDto);
    }

    /**
     * 驳回或批量驳回
     * @param dto
     * @return
     */
    @ApiOperation(value = "驳回或批量驳回操作")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:bind:reject")
    @PostMapping("/reject")
    public AjaxResult reject(@RequestBody PurchaseDto dto) {
        return purchaseBindService.reject(dto);
    }

    /**
     * 导出新购验收绑定详细列表
     */
    @ApiOperation(value = "导出新购验收绑定详细列表")
    @PreventRepeatSubmit
    @RequiresPermissions("purchase:bind:export")
    @SysLog(title = "新购验收绑定任务", businessType = OperaType.EXPORT, module = "仓储管理->导出新购验收绑定任务")
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseDto dto) {
        List<PurchaseVo> list = purchaseBindService.selectAll(dto);
        ExcelUtil<PurchaseVo> util = new ExcelUtil<PurchaseVo>(PurchaseVo.class);
        util.exportExcel(response, list, "新购验收绑定任务数据");
    }
}
