package com.zehong.web.controller.track;

import java.util.List;

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.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.enums.BusinessType;
import com.zehong.system.domain.track.TProductDevice;
import com.zehong.system.service.track.ITProductDeviceService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;

/**
 * 设备Controller
 * 
 * @author zehong
 * @date 2024-08-28
 */
@RestController
@RequestMapping("/track/device")
public class TProductDeviceController extends BaseController
{
    @Autowired
    private ITProductDeviceService tProductDeviceService;

    /**
     * 查询设备列表
     */
   // @PreAuthorize("@ss.hasPermi('system:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(TProductDevice tProductDevice)
    {
        startPage();
        List<TProductDevice> list = tProductDeviceService.selectTProductDeviceList(tProductDevice);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    //@PreAuthorize("@ss.hasPermi('system:device:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TProductDevice tProductDevice)
    {
        List<TProductDevice> list = tProductDeviceService.selectTProductDeviceList(tProductDevice);
        ExcelUtil<TProductDevice> util = new ExcelUtil<TProductDevice>(TProductDevice.class);
        return util.exportExcel(list, "设备数据");
    }

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

    /**
     * 新增设备
     */
    //@PreAuthorize("@ss.hasPermi('system:device:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProductDevice tProductDevice)
    {
        return toAjax(tProductDeviceService.insertTProductDevice(tProductDevice));
    }

    /**
     * 修改设备
     */
    //@PreAuthorize("@ss.hasPermi('system:device:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProductDevice tProductDevice)
    {
        return toAjax(tProductDeviceService.updateTProductDevice(tProductDevice));
    }

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