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.RecordStoreCheckInfo;
import com.ruoyi.manage.service.IRecordStoreCheckInfoService;
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-22
 */
@Controller
@RequestMapping("/manage/check_info")
public class RecordStoreCheckInfoController extends BaseController
{
    private String prefix = "manage/check_info";

    @Autowired
    private IRecordStoreCheckInfoService recordStoreCheckInfoService;

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

    /**
     * 查询盘点数据记录列表
     */
    @RequiresPermissions("manage:check_info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordStoreCheckInfo recordStoreCheckInfo)
    {
        // startPage();
        List<RecordStoreCheckInfo> list = recordStoreCheckInfoService.selectRecordStoreCheckInfoList(recordStoreCheckInfo);
        return getDataTable(list);
    }

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

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

    /**
     * 新增保存盘点数据记录
     */
    @RequiresPermissions("manage:check_info:add")
    @Log(title = "盘点数据记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordStoreCheckInfo recordStoreCheckInfo)
    {
        return toAjax(recordStoreCheckInfoService.insertRecordStoreCheckInfo(recordStoreCheckInfo));
    }

    /**
     * 修改盘点数据记录
     */
    @RequiresPermissions("manage:check_info:edit")
    @GetMapping("/edit/{checkId}")
    public String edit(@PathVariable("checkId") Long checkId, ModelMap mmap)
    {
        RecordStoreCheckInfo recordStoreCheckInfo = recordStoreCheckInfoService.selectRecordStoreCheckInfoByCheckId(checkId);
        mmap.put("recordStoreCheckInfo", recordStoreCheckInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存盘点数据记录
     */
    @RequiresPermissions("manage:check_info:edit")
    @Log(title = "盘点数据记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordStoreCheckInfo recordStoreCheckInfo)
    {
        return toAjax(recordStoreCheckInfoService.updateRecordStoreCheckInfo(recordStoreCheckInfo));
    }

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