package com.zbf.web.controller.system;

import com.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.common.core.page.TableDataInfo;
import com.zbf.common.enums.BusinessType;
import com.zbf.common.utils.poi.ExcelUtil;
import com.zbf.system.domain.TStockCheck;
import com.zbf.system.service.ITStockCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 盘点库存数据Controller
 *
 * @author tony
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/system/checkStock")
public class TStockCheckController extends BaseController
{
    @Autowired
    private ITStockCheckService tStockCheckService;

    /**
     * 查询盘点库存数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(TStockCheck tStockCheck)
    {
        startPage();
        List<TStockCheck> list = tStockCheckService.selectTStockCheckList(tStockCheck);
        return getDataTable(list);
    }

    /**
     * 导出盘点库存数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:export')")
    @Log(title = "盘点库存数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TStockCheck tStockCheck)
    {
        List<TStockCheck> list = tStockCheckService.selectTStockCheckList(tStockCheck);
        ExcelUtil<TStockCheck> util = new ExcelUtil<TStockCheck>(TStockCheck.class);
        util.exportExcel(response, list, "盘点库存数据数据");
    }

    /**
     * 获取盘点库存数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("checkId") String checkId)

    {
        startPage();
        return success(tStockCheckService.selectTStockCheckById(checkId));
    }

    /**
     * 新增盘点库存数据
     */
    @PreAuthorize("@ss.hasPermi('system:check:add')")
    @Log(title = "盘点库存数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TStockCheck tStockCheck)
    {
        return toAjax(tStockCheckService.insertTStockCheck(tStockCheck));
    }

    /**
     * 修改盘点库存数据
     */
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "盘点库存数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TStockCheck tStockCheck)
    {
        return toAjax(tStockCheckService.updateTStockCheck(tStockCheck));
    }





    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "盘点库存数据", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TStockCheck tStockCheck) {
        return toAjax(tStockCheckService.updateStatus(tStockCheck));
    }

}

