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.TPanDetail;
import com.zbf.system.service.ITPanDetailService;
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 wgs
 * @date 2024-11-01
 */
@RestController
@RequestMapping("/system/pan")
public class TPanDetailController extends BaseController
{
    @Autowired
    private ITPanDetailService tPanDetailService;

    /**
     * 查询盘点明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:pan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPanDetail tPanDetail)
    {
        startPage();
        List<TPanDetail> list = tPanDetailService.selectTPanDetailList(tPanDetail);
        return getDataTable(list);
    }

    /**
     * 导出盘点明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:pan:export')")
    @Log(title = "盘点明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPanDetail tPanDetail)
    {
        List<TPanDetail> list = tPanDetailService.selectTPanDetailList(tPanDetail);
        ExcelUtil<TPanDetail> util = new ExcelUtil<TPanDetail>(TPanDetail.class);
        util.exportExcel(response, list, "盘点明细数据");
    }

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

    /**
     * 新增盘点明细
     */
    @PreAuthorize("@ss.hasPermi('system:pan:add')")
    @Log(title = "盘点明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPanDetail tPanDetail)
    {
        return toAjax(tPanDetailService.insertTPanDetail(tPanDetail));
    }

    /**
     * 修改盘点明细
     */
    @PreAuthorize("@ss.hasPermi('system:pan:edit')")
    @Log(title = "盘点修改库存数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPanDetail tPanDetail)
    {
        return toAjax(tPanDetailService.updateTPanDetail(tPanDetail));
    }

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

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

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

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:pan:edit')")
    @Log(title = "盘点明细", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TPanDetail tPanDetail) {
        return toAjax(tPanDetailService.updateStatus(tPanDetail));
    }

}

