package com.bonus.material.purchase.controller;

import com.bonus.common.biz.annotation.StoreLog;
import com.bonus.common.biz.enums.HttpCodeEnum;
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.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.common.biz.domain.purchase.PurchaseDto;
import com.bonus.material.purchase.service.IPurchaseStorageService;
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 13:51
 */
@Api(tags = "新购验收入库接口")
@RestController
@RequestMapping("/purchase/storage")
public class PurchaseStorageController extends BaseController {

    @Resource
    private IPurchaseStorageService purchaseStorageService;

    /**
     * 入库或批量入库
     * @param dto
     * @return
     */
    @ApiOperation(value = "入库或批量入库操作")
    @PreventRepeatSubmit
//    @RequiresPermissions("purchase:storage:add")
    @StoreLog(title = "新购验收入库任务", module = "物资新购->入库或批量入库操作")
    @PostMapping("/warehouse")
    public AjaxResult warehouse(@RequestBody PurchaseDto dto) {
        return purchaseStorageService.warehouse(dto);
    }


    @ApiOperation(value = "查询待绑定编号机具详情")
//    @RequiresPermissions("purchase:storage:query")
    @PostMapping("/getMachineById")
    public AjaxResult getMachineById(@RequestBody PurchaseDto dto) {
        return purchaseStorageService.getMachineById(dto);
    }

    /**
     * 查询待入库编号机具详情
     * @param dto
     * @return
     */
    @ApiOperation(value = "查询待入库编号机具详情")
//    @RequiresPermissions("purchase:storage:query")
    @GetMapping("/getMachineByCode")
    public AjaxResult getMachineByCode(PurchaseDto dto) {
        try {
            return purchaseStorageService.getMachineByCode(dto);
        } catch (Exception e) {
            return AjaxResult.error("查询待入库设备编码查询失败");
        }
    }

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

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