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.RecordInspectionInfo;
import com.ruoyi.manage.service.IRecordInspectionInfoService;
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-02-18
 */
@Controller
@RequestMapping("/manage/record_inspection_info")
public class RecordInspectionInfoController extends BaseController
{
    private String prefix = "manage/record_inspection_info";

    @Autowired
    private IRecordInspectionInfoService recordInspectionInfoService;

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

    /**
     * 查询盘点数据记录列表
     */
    @RequiresPermissions("manage:record_inspection_info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordInspectionInfo recordInspectionInfo)
    {
        startPage();
        List<RecordInspectionInfo> list = recordInspectionInfoService.selectRecordInspectionInfoList(recordInspectionInfo);
        return getDataTable(list);
    }

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

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

    /**
     * 新增保存盘点数据记录
     */
    @RequiresPermissions("manage:record_inspection_info:add")
    @Log(title = "盘点数据记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordInspectionInfo recordInspectionInfo)
    {
        return toAjax(recordInspectionInfoService.insertRecordInspectionInfo(recordInspectionInfo));
    }

    /**
     * 修改盘点数据记录
     */
    @RequiresPermissions("manage:record_inspection_info:edit")
    @GetMapping("/edit/{inspectionId}")
    public String edit(@PathVariable("inspectionId") Long inspectionId, ModelMap mmap)
    {
        RecordInspectionInfo recordInspectionInfo = recordInspectionInfoService.selectRecordInspectionInfoByInspectionId(inspectionId);
        mmap.put("recordInspectionInfo", recordInspectionInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存盘点数据记录
     */
    @RequiresPermissions("manage:record_inspection_info:edit")
    @Log(title = "盘点数据记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordInspectionInfo recordInspectionInfo)
    {
        return toAjax(recordInspectionInfoService.updateRecordInspectionInfo(recordInspectionInfo));
    }

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