package com.ruoyi.web.controller.system;

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 com.ruoyi.system.domain.TFacility;
import com.ruoyi.system.service.ITFacilityService;
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 zhengjie
 * @date 2023-08-12
 */
@RestController
@RequestMapping("/system/facility")
public class TFacilityController extends BaseController
{
    @Autowired
    private ITFacilityService tFacilityService;

    /**
     * 查询手环设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:facility:list')")
    @GetMapping("/list")
    public TableDataInfo list(TFacility tFacility)
    {
        startPage();
        List<TFacility> list = tFacilityService.selectTFacilityList(tFacility);
        return getDataTable(list);
    }

    /**
     * 导出手环设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:facility:export')")
    @Log(title = "手环设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TFacility tFacility)
    {
        List<TFacility> list = tFacilityService.selectTFacilityList(tFacility);
        ExcelUtil<TFacility> util = new ExcelUtil<TFacility>(TFacility.class);
        util.exportExcel(response, list, "手环设备数据");
    }

    /**
     * 获取手环设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:facility:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tFacilityService.selectTFacilityById(id));
    }

    /**
     * 新增手环设备
     */
    @PreAuthorize("@ss.hasPermi('system:facility:add')")
    @Log(title = "手环设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TFacility tFacility)
    {
        return toAjax(tFacilityService.insertTFacility(tFacility));
    }

    /**
     * 修改手环设备
     */
    @PreAuthorize("@ss.hasPermi('system:facility:edit')")
    @Log(title = "手环设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TFacility tFacility)
    {
        return toAjax(tFacilityService.updateTFacility(tFacility));
    }

    /**
     * 删除手环设备
     */
    @PreAuthorize("@ss.hasPermi('system:facility:remove')")
    @Log(title = "手环设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tFacilityService.deleteTFacilityByIds(ids));
    }
}
