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.TbPlace;
import com.ruoyi.asset.service.ITbPlaceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地点Controller
 * 
 * @author 原动力
 * @date 2023-03-27
 */
@RestController
@RequestMapping("/asset/place")
public class TbPlaceController extends BaseController
{
    @Autowired
    private ITbPlaceService tbPlaceService;

    /**
     * 查询地点列表
     */
    @PreAuthorize("@ss.hasPermi('asset:place:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbPlace tbPlace)
    {
        startPage();
        List<TbPlace> list = tbPlaceService.selectTbPlaceList(tbPlace);
        return getDataTable(list);
    }

    /**
     * 导出地点列表
     */
    @PreAuthorize("@ss.hasPermi('asset:place:export')")
    @Log(title = "地点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPlace tbPlace)
    {
        List<TbPlace> list = tbPlaceService.selectTbPlaceList(tbPlace);
        ExcelUtil<TbPlace> util = new ExcelUtil<TbPlace>(TbPlace.class);
        util.exportExcel(response, list, "地点数据");
    }

    /**
     * 获取地点详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:place:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbPlaceService.selectTbPlaceById(id));
    }

    /**
     * 新增地点
     */
    @PreAuthorize("@ss.hasPermi('asset:place:add')")
    @Log(title = "地点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbPlace tbPlace)
    {
        return toAjax(tbPlaceService.insertTbPlace(tbPlace));
    }

    /**
     * 修改地点
     */
    @PreAuthorize("@ss.hasPermi('asset:place:edit')")
    @Log(title = "地点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbPlace tbPlace)
    {
        return toAjax(tbPlaceService.updateTbPlace(tbPlace));
    }

    /**
     * 删除地点
     */
    @PreAuthorize("@ss.hasPermi('asset:place:remove')")
    @Log(title = "地点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbPlaceService.deleteTbPlaceByIds(ids));
    }

    /**
     * 查询全部地点列表
     */
    @PreAuthorize("@ss.hasPermi('asset:place:list')")
    @GetMapping("/all")
    public AjaxResult all()
    {
        return AjaxResult.success(tbPlaceService.selectTbPlaceAll());
    }
}
