package com.ruoyi.manage.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.manage.domain.BaseStore;
import com.ruoyi.manage.service.IBaseStoreService;
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.*;

import java.util.List;

/**
 * 仓库信息维护Controller
 * 
 * @author ruoyi
 * @date 2023-12-08
 */
@Controller
@RequestMapping("/manager/base_area")
public class BaseAreaController extends BaseController
{
    private String prefix = "manage/base_area";

    @Autowired
    private IBaseStoreService baseStoreService;

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

    /**
     * 查询仓库信息维护列表
     */
    @RequiresPermissions("manager:base_store:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseStore baseStore)
    {
        startPage();
        baseStore.setStoreTag(2L);
        List<BaseStore> list = baseStoreService.selectBaseStoreList(baseStore);
        return getDataTable(list);
    }

    /**
     * 导出仓库信息维护列表
     */
    @RequiresPermissions("manager:base_store:export")
    @Log(title = "仓库信息维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseStore baseStore)
    {
        List<BaseStore> list = baseStoreService.selectBaseStoreList(baseStore);
        ExcelUtil<BaseStore> util = new ExcelUtil<BaseStore>(BaseStore.class);
        return util.exportExcel(list, "仓库信息维护数据");
    }

    /**
     * 新增仓库信息维护
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存仓库信息维护
     */
    @RequiresPermissions("manager:base_store:add")
    @Log(title = "仓库信息维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseStore baseStore)
    {
        return toAjax(baseStoreService.insertBaseStore(baseStore));
    }

    /**
     * 修改仓库信息维护
     */
    @RequiresPermissions("manager:base_store:edit")
    @GetMapping("/edit/{storeId}")
    public String edit(@PathVariable("storeId") Long storeId, ModelMap mmap)
    {
        BaseStore baseStore = baseStoreService.selectBaseStoreByStoreId(storeId);
        mmap.put("baseStore", baseStore);
        return prefix + "/edit";
    }

    /**
     * 修改保存仓库信息维护
     */
    @RequiresPermissions("manager:base_store:edit")
    @Log(title = "仓库信息维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseStore baseStore)
    {
        return toAjax(baseStoreService.updateBaseStore(baseStore));
    }

    /**
     * 删除仓库信息维护
     */
    @RequiresPermissions("manager:base_store:remove")
    @Log(title = "仓库信息维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseStoreService.deleteBaseStoreByStoreIds(ids));
    }
}
