package com.bonus.sgzb.material.controller;

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

import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
import com.bonus.sgzb.material.domain.PurchaseInput;
import com.bonus.sgzb.material.service.IPurchaseCheckInfoService;
import com.bonus.sgzb.material.domain.PurchaseCheckInfo;
import com.bonus.sgzb.material.service.PurchaseCheckServiceCenterService;
import com.bonus.sgzb.material.vo.NoticeInfoVO;
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.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
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("/purchaseCheckInfo")
public class PurchaseCheckInfoController extends BaseController {
    @Autowired
    private IPurchaseCheckInfoService purchaseCheckInfoService;

    @Autowired
    private PurchaseCheckServiceCenterService purchaseCheckServiceCenterService;

    /**
     * 查询新购入库任务列表
     */
    @ApiOperation("查询新购入库任务列表")
    @GetMapping("/putInList")
    @RequiresPermissions("warehousing:newTools:list")
    public TableDataInfo putInList(PurchaseCheckInfo purchaseCheckInfo) {
        startPage();
        return getDataTable(purchaseCheckInfoService.selectPutInListList(purchaseCheckInfo));
    }

    /**
     * 成套机具明细查看
     */
    @ApiOperation("成套机具明细查看")
    @GetMapping("/wholeSetDetails")
    public TableDataInfo wholeSetDetails(PurchaseCheckInfo purchaseCheckInfo) {
        startPage();
        return getDataTable(purchaseCheckInfoService.getWholeSetDetails(purchaseCheckInfo));
    }

    /**
     * 查询新购验收任务列表
     */
    @ApiOperation("查询新购验收任务列表")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseCheckInfo purchaseCheckInfo) {
        startPage();
        return getDataTable(purchaseCheckInfoService.selectPurchaseCheckInfoList(purchaseCheckInfo));
    }

    /**
     * 导出新购验收任务列表
     */
    @ApiOperation("导出新购验收任务列表")
    @Log(title = "新购验收任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseCheckInfo purchaseCheckInfo) {
        List<PurchaseCheckInfo> list = purchaseCheckInfoService.exportList(purchaseCheckInfo);
        ExcelUtil<PurchaseCheckInfo> util = new ExcelUtil<>(PurchaseCheckInfo.class);
        util.exportExcel(response, list, "新购验收任务数据");
    }

    /**
     * 导出新购工机具入库
     */
    @ApiOperation("导出新购工机具入库")
    @Log(title = "导出新购工机具入库", businessType = BusinessType.EXPORT)
    @PostMapping("/putInExport")
    public void putInExport(HttpServletResponse response, PurchaseCheckInfo purchaseCheckInfo) {
        List<PurchaseInput> list = purchaseCheckInfoService.putInExportList(purchaseCheckInfo);
        ExcelUtil<PurchaseInput> util = new ExcelUtil<>(PurchaseInput.class);
        util.exportExcel(response, list, "新购工机具入库");
    }

    /**
     * 获取新购验收任务详细信息
     */
    @ApiOperation("获取新购验收任务详细信息")
    @GetMapping(value = "/getDetails")
    public AjaxResult getInfo(@RequestParam(required = false) Long taskId,
                              @RequestParam(required = false) String keyWord) {
        return success(purchaseCheckInfoService.selectPurchaseCheckInfoByTaskId(taskId, keyWord));
    }

    /**
     * 获取新购验收任务--验收单
     */
    @ApiOperation("获取新购验收任务验收单")
    @GetMapping(value = "/getAcceptanceForm")
    public AjaxResult getAcceptanceForm(@RequestParam(required = false) Long taskId,
                                        @RequestParam(required = false) String keyWord) {
        return success(purchaseCheckInfoService.getAcceptanceForm(taskId, keyWord));
    }

    /**
     * 新增新购验收任务
     */
    @ApiOperation("新增新购验收任务")
    @Log(title = "新购验收任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseCheckInfo purchaseCheckInfo) {
        return toAjax(purchaseCheckInfoService.insertPurchaseCheckInfo(purchaseCheckInfo));
    }

    /**
     * 验收通知
     */
    @ApiOperation("验收通知")
    @PostMapping("/bmNoticeInfo")
    public AjaxResult bmNoticeInfo(@RequestBody NoticeInfoVO noticeInfoVO) throws Exception {
        return toAjax(purchaseCheckInfoService.insertBmNoticeInfo(noticeInfoVO));
    }

    /**
     * 修改新购验收任务
     */
    @ApiOperation("修改新购验收任务")
    @Log(title = "新购验收任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseCheckInfo purchaseCheckInfo) throws Exception {
        return toAjax(purchaseCheckInfoService.updatePurchaseCheckInfo(purchaseCheckInfo));
    }

    /**
     * 删除新购验收任务
     */
    @ApiOperation("删除新购验收任务")
    @Log(title = "新购验收任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskId}")
    public AjaxResult remove(@PathVariable Long taskId) {
        return toAjax(purchaseCheckInfoService.deletePurchaseCheckInfoByTaskId(taskId));
    }
}
