package com.ruoyi.web.controller.warehouse.basicData;

import com.ruoyi.basicData.domain.TWarehouseLocation;
import com.ruoyi.basicData.service.ITWarehouseLocationService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库位Controller
 *
 * @author ruoyi
 * @date 2020-12-11
 */
@RestController
@RequestMapping("/basicdata/location")
public class TWarehouseLocationController extends BaseController {
    @Autowired
    private ITWarehouseLocationService tWarehouseLocationService;

    /**
     * 查询库位列表
     */
    @PreAuthorize("@ss.hasPermi('basicdata:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(TWarehouseLocation tWarehouseLocation) {
        startPage();
        List<TWarehouseLocation> list = tWarehouseLocationService.selectTWarehouseLocationList(tWarehouseLocation);
        return getDataTable(list);
    }

    /**
     * 导出库位列表
     */
    @PreAuthorize("@ss.hasPermi('basicdata:location:export')")
    @Log(title = "库位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TWarehouseLocation tWarehouseLocation) {
        List<TWarehouseLocation> list = tWarehouseLocationService.selectTWarehouseLocationList(tWarehouseLocation);
        ExcelUtil<TWarehouseLocation> util = new ExcelUtil<TWarehouseLocation>(TWarehouseLocation.class);
        return util.exportExcel(list, "location");
    }

    /**
     * 获取库位详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicdata:location:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tWarehouseLocationService.selectTWarehouseLocationById(fId));
    }

    /**
     * 新增库位
     */
    @PreAuthorize("@ss.hasPermi('basicdata:location:add')")
    @Log(title = "库位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TWarehouseLocation tWarehouseLocation) {
        return toAjax(tWarehouseLocationService.insertTWarehouseLocation(tWarehouseLocation));
    }

    /**
     * 修改库位
     */
    @PreAuthorize("@ss.hasPermi('basicdata:location:edit')")
    @Log(title = "库位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TWarehouseLocation tWarehouseLocation) {
        return toAjax(tWarehouseLocationService.updateTWarehouseLocation(tWarehouseLocation));
    }

    /**
     * 删除库位
     */
    @PreAuthorize("@ss.hasPermi('basicdata:location:remove')")
    @Log(title = "库位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        return toAjax(tWarehouseLocationService.deleteTWarehouseLocationByIds(fIds));
    }
}
