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.InventoryCheck;
import com.zbf.system.service.IInventoryCheckService;
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/check")
public class InventoryCheckController extends BaseController
{
    @Autowired
    private IInventoryCheckService inventoryCheckService;

    /**
     * 查询盘点主列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(InventoryCheck inventoryCheck)
    {
        startPage();
        List<InventoryCheck> list = inventoryCheckService.selectInventoryCheckList(inventoryCheck);
        return getDataTable(list);
    }

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

    /**
     * 获取盘点主详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inventoryCheckService.selectInventoryCheckById(id));
    }

    /**
     * 新增盘点主
     */
    @PreAuthorize("@ss.hasPermi('system:check:add')")
    @Log(title = "盘点主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InventoryCheck inventoryCheck)
    {
        return toAjax(inventoryCheckService.insertInventoryCheck(inventoryCheck));
    }

    /**
     * 修改盘点主
     */
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "盘点主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InventoryCheck inventoryCheck)
    {
        return toAjax(inventoryCheckService.updateInventoryCheck(inventoryCheck));
    }

    /**
     * 删除盘点主
     */
    @PreAuthorize("@ss.hasPermi('system:check:remove')")
    @Log(title = "盘点主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inventoryCheckService.deleteInventoryCheckByIds(ids));
    }

    /**
     * 启用
     */
    @PreAuthorize("@ss.hasPermi('system:check:remove')")
    @Log(title = "盘点主", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable Long[] ids)
    {
        return toAjax(inventoryCheckService.disabledInventoryCheckByIds(ids));
    }

    /**
     * 禁用
     */
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "盘点主", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable Long[] ids)
    {
        return toAjax(inventoryCheckService.enableInventoryCheckByIds(ids));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "盘点主", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody InventoryCheck inventoryCheck) {
        return toAjax(inventoryCheckService.updateStatus(inventoryCheck));
    }

}

