package com.bonus.sgzb.material.controller;

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

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

/**
* @description 新购配件任务
* @author hay
* @date   2024/1/16 11:28
*/
@RestController
@Api(value = "新购配件任务")
@RequestMapping("/purchaseAccessory")
public class PurchaseAccessoryController extends BaseController
{
    @Autowired
    private IPurchaseAccessoryService purchaseAccessoryService;

    /**
     * 查询新购配件任务验收列表
     */
    @ApiOperation("查询新购配件任务验收列表")
    @GetMapping("/list")
    public TableDataInfo list(PurchasePartInfo purchasePartInfo)
    {
        startPage();
        List<PurchasePartInfo> list = purchaseAccessoryService.selectPurchasePartInfoList(purchasePartInfo);
        return getDataTable(list);
    }

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

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

    /**
     * 新增新购配件任务
     */
    @ApiOperation("新增新购配件任务")
    @Log(title = "新购配件任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchasePartInfo purchasePartInfo)
    {
        return toAjax(purchaseAccessoryService.insertPurchaseAccessory(purchasePartInfo));
    }

    /**
     * 修改新购配件任务
     */
    @ApiOperation("修改新购配件任务")
    @Log(title = "修改新购配件任务", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResult edit(@RequestBody PurchasePartInfo purchasePartInfo){
        return toAjax(purchaseAccessoryService.updatePurchaseCheckInfo(purchasePartInfo));
    }

    /**
     * 删除新购配件任务
     */
    @ApiOperation("删除新购配件任务")
    @Log(title = "删除新购配件任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return purchaseAccessoryService.deletePurchasePartInfoByTaskIds(taskIds);
    }

    /**
     * 新购配件验收
     */
    @ApiOperation(value = "新购配件验收")
    @Log(title = "新购配件验收", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/check")
    public AjaxResult check(@RequestBody List<PurchasePartDetails> purchasePartDetailsList)
    {
        return toAjax(purchaseAccessoryService.updatePurchaseCheckDetails(purchasePartDetailsList));
    }

    /**
     * 新购配件验收导出
     */
    @ApiOperation("新购配件验收导出")
    @Log(title = "新购配件验收导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchasePartInfo bean)
    {
        List<PurchasePartInfo> list = purchaseAccessoryService.exportList(bean);
        ExcelUtil<PurchasePartInfo> util = new ExcelUtil<PurchasePartInfo>(PurchasePartInfo.class);
        util.exportExcel(response, list, "新购配件验收数据");
    }



    /**
     * 查询新购配件入库任务列表
     */
    @ApiOperation("查询新购配件入库任务列表")
    @GetMapping("/putInList")
    public TableDataInfo putInList(PurchasePartInfo purchasePartInfo)
    {
        startPage();
        List<PurchasePartInfo> list = purchaseAccessoryService.selectPutInListList(purchasePartInfo);
        return getDataTable(list);
    }

    /**
     * 获取配件信息
     */
    @ApiOperation(value = "获取配件信息")
    @GetMapping("/getPartList")
    public AjaxResult getPartList(String level){
        List<PurchasePartInfo> list = purchaseAccessoryService.getPartList(level);
        return AjaxResult.success(list);
    }

    /**
     * 获取新购配件入库详细信息
     */
    @ApiOperation(value = "获取新购配件入库详细信息")
    @GetMapping(value = "/putinDetails")
    public TableDataInfo putinDetails(PurchasePartDetails purchasePartDetails)
    {
        startPage();
        return getDataTable(purchaseAccessoryService.selectPutinDetails(purchasePartDetails));
    }

    /**
     * 获取新购配件入库单
     */
    @ApiOperation(value = "获取新购配件入库单")
    @GetMapping(value = "/warehousingEntry")
    public AjaxResult warehousingEntry(PurchasePartDetails purchasePartDetails)
    {
        return success(purchaseAccessoryService.warehousingEntry(purchasePartDetails));
    }

    /**
     * 新购配件入库审核
     */
    @ApiOperation(value = "新购配件入库审核")
    @PostMapping("/checkInput")
    public AjaxResult checkInput(@RequestBody List<PurchasePartDetails> purchasePartDetails){
        return toAjax(purchaseAccessoryService.checkInput(purchasePartDetails));
    }

    /**
     * 新购配件入库导出
     */
    @ApiOperation("新购配件入库导出")
    @Log(title = "新购配件入库导出", businessType = BusinessType.EXPORT)
    @PostMapping("/inputExport")
    public void inputExport(HttpServletResponse response, PurchasePartDetails bean)
    {
        List<PurchasePartDetails> list = purchaseAccessoryService.inputExport(bean);
        ExcelUtil<PurchasePartDetails> util = new ExcelUtil<PurchasePartDetails>(PurchasePartDetails.class);
        util.exportExcel(response, list, "新购配件入库数据");
    }
}
