package com.aucma.base.controller;

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

import com.aucma.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.base.domain.BaseStoreInfo;
import com.aucma.base.service.IBaseStoreInfoService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * 仓库信息Controller
 *
 * @author Yinq
 * @date 2023-09-20
 */
@RestController
@RequestMapping("/base/storeInfo")
public class BaseStoreInfoController extends BaseController {
    @Autowired
    private IBaseStoreInfoService baseStoreInfoService;

    /**
     * 查询仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:storeInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseStoreInfo baseStoreInfo) {
        startPage();
        List<BaseStoreInfo> list = baseStoreInfoService.selectBaseStoreInfoList(baseStoreInfo);
        return getDataTable(list);
    }

    /**
     * 查询仓库下拉框列表
     */
    @GetMapping("/findStoreList")
    public AjaxResult findStoreList(BaseStoreInfo baseStoreInfo) {
        List<BaseStoreInfo> list = baseStoreInfoService.selectBaseStoreInfoList(baseStoreInfo);
        return success(list);
    }

    /**
     * 导出仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:storeInfo:export')")
    @Log(title = "仓库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseStoreInfo baseStoreInfo) {
        List<BaseStoreInfo> list = baseStoreInfoService.selectBaseStoreInfoList(baseStoreInfo);
        ExcelUtil<BaseStoreInfo> util = new ExcelUtil<BaseStoreInfo>(BaseStoreInfo.class);
        util.exportExcel(response, list, "仓库信息数据");
    }

    /**
     * 获取仓库信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:storeInfo:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(baseStoreInfoService.selectBaseStoreInfoByObjId(objId));
    }

    /**
     * 新增仓库信息
     */
    @PreAuthorize("@ss.hasPermi('base:storeInfo:add')")
    @Log(title = "仓库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseStoreInfo baseStoreInfo) {
        baseStoreInfo.setCreatedBy(getUsername());
        baseStoreInfo.setCreatedTime(DateUtils.getNowDate());
        return toAjax(baseStoreInfoService.insertBaseStoreInfo(baseStoreInfo));
    }

    /**
     * 修改仓库信息
     */
    @PreAuthorize("@ss.hasPermi('base:storeInfo:edit')")
    @Log(title = "仓库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseStoreInfo baseStoreInfo) {
        baseStoreInfo.setUpdatedBy(getUsername());
        baseStoreInfo.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(baseStoreInfoService.updateBaseStoreInfo(baseStoreInfo));
    }

    /**
     * 删除仓库信息
     */
    @PreAuthorize("@ss.hasPermi('base:storeInfo:remove')")
    @Log(title = "仓库信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(baseStoreInfoService.deleteBaseStoreInfoByObjIds(objIds));
    }
}
