package com.ruoyi.web.controller.system;

import com.ruoyi.ruiYiController.annotation.Log;
import com.ruoyi.ruiYiController.core.controller.BaseController;
import com.ruoyi.ruiYiController.core.domain.AjaxResult;
import com.ruoyi.ruiYiController.core.page.TableDataInfo;
import com.ruoyi.ruiYiController.enums.BusinessType;
import com.ruoyi.ruiYiController.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.StoreInfo;
import com.ruoyi.system.service.IStoreInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库位信息，记录周装货架存放库位信息Controller
 * 
 * @author ruoyi
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/system/info")
public class StoreInfoController extends BaseController
{
    @Autowired
    private IStoreInfoService storeInfoService;

    /**
     * 查询库位信息，记录周装货架存放库位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreInfo storeInfo)
    {
        startPage();
        List<StoreInfo> list = storeInfoService.selectStoreInfoList(storeInfo);
        return getDataTable(list);
    }

    /**
     * 导出库位信息，记录周装货架存放库位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "库位信息，记录周装货架存放库位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreInfo storeInfo)
    {
        List<StoreInfo> list = storeInfoService.selectStoreInfoList(storeInfo);
        ExcelUtil<StoreInfo> util = new ExcelUtil<StoreInfo>(StoreInfo.class);
        util.exportExcel(response, list, "库位信息，记录周装货架存放库位信息数据");
    }

    /**
     * 获取库位信息，记录周装货架存放库位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storeInfoService.selectStoreInfoById(id));
    }

    /**
     * 新增库位信息，记录周装货架存放库位信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "库位信息，记录周装货架存放库位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreInfo storeInfo)
    {
        return toAjax(storeInfoService.insertStoreInfo(storeInfo));
    }

    /**
     * 修改库位信息，记录周装货架存放库位信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "库位信息，记录周装货架存放库位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreInfo storeInfo)
    {
        return toAjax(storeInfoService.updateStoreInfo(storeInfo));
    }

    /**
     * 删除库位信息，记录周装货架存放库位信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "库位信息，记录周装货架存放库位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeInfoService.deleteStoreInfoByIds(ids));
    }
}
