package com.ruoyi.manage.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.RecordStoreCheck;
import com.ruoyi.manage.service.IRecordStoreCheckService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 盘点记录Controller
 * 
 * @author wangh
 * @date 2024-01-19
 */
@Controller
@RequestMapping("/manage/record_store_check")
public class RecordStoreCheckController extends BaseController
{
    private String prefix = "manage/record_store_check";

    @Autowired
    private IRecordStoreCheckService recordStoreCheckService;

    @RequiresPermissions("manage:record_store_check:view")
    @GetMapping()
    public String record_store_check()
    {
        return prefix + "/record_store_check";
    }

    /**
     * 查询盘点记录列表
     */
    @RequiresPermissions("manage:record_store_check:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordStoreCheck recordStoreCheck)
    {
        startPage();
        List<RecordStoreCheck> list = recordStoreCheckService.selectRecordStoreCheckList(recordStoreCheck);
        return getDataTable(list);
    }

    /**
     * 导出盘点记录列表
     */
    @RequiresPermissions("manage:record_store_check:export")
    @Log(title = "盘点记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecordStoreCheck recordStoreCheck)
    {
        List<RecordStoreCheck> list = recordStoreCheckService.selectRecordStoreCheckList(recordStoreCheck);
        ExcelUtil<RecordStoreCheck> util = new ExcelUtil<RecordStoreCheck>(RecordStoreCheck.class);
        return util.exportExcel(list, "盘点记录数据");
    }

    /**
     * 新增盘点记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存盘点记录
     */
    @RequiresPermissions("manage:record_store_check:add")
    @Log(title = "盘点记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordStoreCheck recordStoreCheck)
    {
        return toAjax(recordStoreCheckService.insertRecordStoreCheck(recordStoreCheck));
    }

    /**
     * 修改盘点记录
     */
    @RequiresPermissions("manage:record_store_check:edit")
    @GetMapping("/edit/{checkId}")
    public String edit(@PathVariable("checkId") Long checkId, ModelMap mmap)
    {
        RecordStoreCheck recordStoreCheck = recordStoreCheckService.selectRecordStoreCheckByCheckId(checkId);
        mmap.put("recordStoreCheck", recordStoreCheck);
        return prefix + "/edit";
    }

    /**
     * 修改保存盘点记录
     */
    @RequiresPermissions("manage:record_store_check:edit")
    @Log(title = "盘点记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordStoreCheck recordStoreCheck)
    {
        return toAjax(recordStoreCheckService.updateRecordStoreCheck(recordStoreCheck));
    }

    /**
     * 删除盘点记录
     */
    @RequiresPermissions("manage:record_store_check:remove")
    @Log(title = "盘点记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recordStoreCheckService.deleteRecordStoreCheckByCheckIds(ids));
    }
}
