package com.bonus.sgzb.material.controller;

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

import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import com.bonus.sgzb.material.service.IPurchaseMacodeInfoService;
import com.bonus.sgzb.material.domain.PurchaseMacodeInfo;
import com.bonus.sgzb.base.api.domain.MaInputVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;

/**
 * 新购验收编号管理
 *
 * @author bonus
 * @date 2023-12-10
 */
@RestController
@Api(value = "新购验收编号管理")
@RequestMapping("/purchaseMacode")
public class PurchaseMacodeInfoController extends BaseController {
    @Autowired
    private IPurchaseMacodeInfoService purchaseMacodeInfoService;

    /**
     * 查询新购验收编号管理列表
     */
    @ApiOperation(value = "查询新购验收编号管理列表")
    @GetMapping("/list")
    public AjaxResult list(PurchaseMacodeInfo purchaseMacodeInfo) throws Exception {
        if (purchaseMacodeInfo.getTaskId() == null || purchaseMacodeInfo.getTaskId() == 0) {
            throw new Exception("任务taskId为空!!!");
        }
        List<PurchaseMacodeInfo> list = purchaseMacodeInfoService.selectPurchaseMacodeInfoList(purchaseMacodeInfo);
        return AjaxResult.success(list);
    }

    /**
     * 查询新购验收编号管理列表
     */
    @ApiOperation(value = "查询单个新购验收编号管理列表详情")
    @GetMapping("/details")
    public AjaxResult details(PurchaseMacodeInfo purchaseMacodeInfo) throws Exception {
        if (purchaseMacodeInfo.getTaskId() == null || purchaseMacodeInfo.getTaskId() == 0
        || purchaseMacodeInfo.getTypeId() == null || purchaseMacodeInfo.getTypeId() == 0) {
            throw new Exception("任务taskId或者类型typeId为空!!!");
        }
        List<PurchaseMacodeInfo> list = purchaseMacodeInfoService.selectPurchaseMacodeInfoListDetails(purchaseMacodeInfo);
        return AjaxResult.success(list);
    }
    /**
     * 导出新购验收编号管理列表
     */
    @ApiOperation(value = "导出新购验收编号管理列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseMacodeInfo purchaseMacodeInfo) {
        List<PurchaseMacodeInfo> list = purchaseMacodeInfoService.selectPurchaseMacodeInfoList(purchaseMacodeInfo);
        ExcelUtil<PurchaseMacodeInfo> util = new ExcelUtil<PurchaseMacodeInfo>(PurchaseMacodeInfo.class);
        util.exportExcel(response, list, "新购验收编号管理数据");
    }

    /**
     * 获取新购验收编号管理详细信息
     */
    @ApiOperation(value = "获取新购验收编号管理详细信息")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(PurchaseMacodeInfo purchaseMacodeInfo) {
        return success(purchaseMacodeInfoService.selectPurchaseMacodeInfo(purchaseMacodeInfo));
    }

    /**
     * 获取新购验收编号管理详细信息
     */
    @ApiOperation(value = "新购入库清单明细")
    @GetMapping(value = "/putinDetails")
    public TableDataInfo putinDetails(PurchaseMacodeInfo purchaseMacodeInfo) {
        startPage();

        return getDataTable(purchaseMacodeInfoService.selectPutinDetails(purchaseMacodeInfo));
    }

    /**
     * 获取新购入库单
     */
    @ApiOperation(value = "入库单")
    @GetMapping(value = "/warehousingEntry")
    public AjaxResult warehousingEntry(PurchaseMacodeInfo purchaseMacodeInfo) {
        return success(purchaseMacodeInfoService.warehousingEntry(purchaseMacodeInfo));
    }

    /**
     * 新增新购验收编号管理
     */
    @ApiOperation(value = "新增新购验收编号管理")
    @PostMapping
    public AjaxResult add(@RequestBody List<PurchaseMacodeInfo> purchaseMacodeInfoList) throws Exception {
        return purchaseMacodeInfoService.insertPurchaseMacodeInfo(purchaseMacodeInfoList);
    }

    /**
     * 修改新购验收编号管理
     */
    @ApiOperation(value = "修改新购验收编号管理")
    @PutMapping
    public AjaxResult edit(@RequestBody List<PurchaseMacodeInfo> purchaseMacodeInfoList) throws Exception {
        return toAjax(purchaseMacodeInfoService.updatePurchaseMacodeInfo(purchaseMacodeInfoList));
    }

    /**
     * 新购入库审核
     * 通过/不通过
     */
    @ApiOperation(value = "新购入库审核")
    @PreventRepeatSubmit
    @Log(title = "新购验收任务", businessType = BusinessType.MATERIAL)
    @PutMapping("/manageStatus")
    public AjaxResult modifyManageStatus(@RequestBody MaInputVO maInputVO) throws Exception {
        return toAjax(purchaseMacodeInfoService.modifyManageStatus(maInputVO));
    }

    /**
     * 删除新购验收编号管理
     */
    @ApiOperation(value = "删除新购验收编号管理")
    @DeleteMapping("/{maCode}")
    public AjaxResult remove(@PathVariable String maCode) {
        return toAjax(purchaseMacodeInfoService.deletePurchaseMacodeInfoByMaCode(maCode));
    }
}
