package com.ruoyi.asset.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.TbLocation;
import com.ruoyi.asset.service.ITbLocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 所属位置Controller
 * 
 * @author 原动力
 * @date 2023-05-15
 */
@RestController
@RequestMapping("/asset/location")
public class TbLocationController extends BaseController
{
    @Autowired
    private ITbLocationService tbLocationService;

    /**
     * 查询所属位置列表
     */
    @PreAuthorize("@ss.hasPermi('asset:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbLocation tbLocation)
    {
        startPage();
        List<TbLocation> list = tbLocationService.selectTbLocationList(tbLocation);
        return getDataTable(list);
    }

    /**
     * 导出所属位置列表
     */
    @PreAuthorize("@ss.hasPermi('asset:location:export')")
    @Log(title = "所属位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbLocation tbLocation)
    {
        List<TbLocation> list = tbLocationService.selectTbLocationList(tbLocation);
        ExcelUtil<TbLocation> util = new ExcelUtil<TbLocation>(TbLocation.class);
        util.exportExcel(response, list, "所属位置数据");
    }

    /**
     * 获取所属位置详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:location:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbLocationService.selectTbLocationById(id));
    }

    /**
     * 新增所属位置
     */
    @PreAuthorize("@ss.hasPermi('asset:location:add')")
    @Log(title = "所属位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbLocation tbLocation)
    {
        return toAjax(tbLocationService.insertTbLocation(tbLocation));
    }

    /**
     * 修改所属位置
     */
    @PreAuthorize("@ss.hasPermi('asset:location:edit')")
    @Log(title = "所属位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbLocation tbLocation)
    {
        return toAjax(tbLocationService.updateTbLocation(tbLocation));
    }

    /**
     * 删除所属位置
     */
    @PreAuthorize("@ss.hasPermi('asset:location:remove')")
    @Log(title = "所属位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbLocationService.deleteTbLocationByIds(ids));
    }
}
