package com.zbf.web.controller.system;

import com.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.common.core.page.TableDataInfo;
import com.zbf.common.enums.BusinessType;
import com.zbf.common.utils.poi.ExcelUtil;
import com.zbf.system.domain.TBaseStorageArea;
import com.zbf.system.service.ITBaseStorageAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 仓库库区Controller
 *
 * @author tony
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/system/storageArea")
public class TBaseStorageAreaController extends BaseController {
    @Autowired
    private ITBaseStorageAreaService tBaseStorageAreaService;

    /**
     * 查询仓库库区列表
     */
    //@PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBaseStorageArea tBaseStorageArea) {
        startPage();
        List<TBaseStorageArea> list = tBaseStorageAreaService.selectTBaseStorageAreaList(tBaseStorageArea);
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setColumns(tBaseStorageArea.getColumnsJson());
        return dataTable;
    }

    /**
     * 导出仓库库区列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:export')")
    @Log(title = "仓库库区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBaseStorageArea tBaseStorageArea) {
        List<TBaseStorageArea> list = tBaseStorageAreaService.selectTBaseStorageAreaList(tBaseStorageArea);
        ExcelUtil<TBaseStorageArea> util = new ExcelUtil<TBaseStorageArea>(TBaseStorageArea.class);
        util.exportExcel(response, list, "仓库库区数据");
    }

    /**
     * 获取仓库库区详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tBaseStorageAreaService.selectTBaseStorageAreaById(id));
    }

    /**
     * 新增仓库库区
     */
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "仓库库区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBaseStorageArea tBaseStorageArea) {
        return toAjax(tBaseStorageAreaService.insertTBaseStorageArea(tBaseStorageArea));
    }

    /**
     * 修改仓库库区
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "仓库库区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBaseStorageArea tBaseStorageArea) {
        return toAjax(tBaseStorageAreaService.updateTBaseStorageArea(tBaseStorageArea));
    }

    /**
     * 删除仓库库区
     */
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "仓库库区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tBaseStorageAreaService.deleteTBaseStorageAreaByIds(ids));
    }

    /**
     * 启用
     */
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "仓库库区", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable Long[] ids) {
        return toAjax(tBaseStorageAreaService.disabledTBaseStorageAreaByIds(ids));
    }

    /**
     * 禁用
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "仓库库区", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable Long[] ids) {
        return toAjax(tBaseStorageAreaService.enableTBaseStorageAreaByIds(ids));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "仓库库区", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TBaseStorageArea tBaseStorageArea) {
        return toAjax(tBaseStorageAreaService.updateStatus(tBaseStorageArea));
    }

}

