package com.bonus.sgzb.material.controller;

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

import cn.hutool.core.bean.BeanUtil;
import com.bonus.sgzb.material.service.IPurchaseCheckDetailsService;
import com.bonus.sgzb.material.domain.PurchaseCheckDetails;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
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("/purchaseCheckDetails")
public class PurchaseCheckDetailsController extends BaseController
{
    @Autowired
    private IPurchaseCheckDetailsService purchaseCheckDetailsService;

    /**
     * 查询新购验收任务详细列表
     */
    @ApiOperation(value = "查询新购验收任务详细列表")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseCheckDetails purchaseCheckDetails)
    {
        List<PurchaseCheckDetails> list = purchaseCheckDetailsService.selectPurchaseCheckDetailsList(purchaseCheckDetails);
        return getDataTable(list);
    }

    /**
     * 导出新购验收任务详细列表
     */
    @RequiresPermissions("domain:details:export")
    @Log(title = "新购验收任务详细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseCheckDetails purchaseCheckDetails)
    {
        List<PurchaseCheckDetails> list = purchaseCheckDetailsService.selectPurchaseCheckDetailsList(purchaseCheckDetails);
        ExcelUtil<PurchaseCheckDetails> util = new ExcelUtil<PurchaseCheckDetails>(PurchaseCheckDetails.class);
        util.exportExcel(response, list, "新购验收任务详细数据");
    }

    /**
     * 获取新购验收任务详细详细信息
     */
    @ApiOperation(value = "获取新购验收任务详细详细信息")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(purchaseCheckDetailsService.selectPurchaseCheckDetailsByTaskId(taskId));
    }

    /**
     * 新增新购验收任务详细
     */
    @ApiOperation(value = "新增新购验收任务详细")
    @Log(title = "新购验收任务详细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<PurchaseCheckDetails> purchaseCheckDetailsList)
    {
        return toAjax(purchaseCheckDetailsService.insertPurchaseCheckDetails(purchaseCheckDetailsList));
    }

    /**
     * 验收审核
     * 通过/不通过
     */
    @ApiOperation(value = "验收审核")
    @Log(title = "验收审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody List<PurchaseCheckDetails> purchaseCheckDetailsList)
    {
        return toAjax(purchaseCheckDetailsService.updatePurchaseCheckDetails(purchaseCheckDetailsList));
    }

    /**
     * 删除新购验收任务详细
     */
    @ApiOperation(value = "删除新购验收任务详细")
    @Log(title = "删除新购验收任务详细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(purchaseCheckDetailsService.deletePurchaseCheckDetailsByTaskId(id));
    }
}
