package com.yunfeiyun.agmp.fms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yunfeiyun.agmp.fms.domain.TmnBase;
import com.yunfeiyun.agmp.fms.domain.resvo.TmnBaseTypeResVo;
import com.yunfeiyun.agmp.fms.service.ITmnBaseService;
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.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.enums.BusinessType;

import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;

/**
 * 设备Controller
 * 
 * @author 杨晓辉
 * @date 2023-07-06
 */
@RestController
@RequestMapping("/tmn/device")
public class TmnBaseController extends BaseController
{
    @Autowired
    private ITmnBaseService tmnBaseService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('tmn:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(TmnBase tmnBase)
    {
        startPage();
        List<TmnBase> list = tmnBaseService.selectTmnBaseList(tmnBase);
        return getDataTable(list);
    }

    /**
     * 查询设备类型列表
     */
    @PreAuthorize("@ss.hasPermi('tmn:device:type:info')")
    @GetMapping("/type/info")
    public TableDataInfo typeList()
    {
        List<TmnBaseTypeResVo> list = tmnBaseService.selectTmnBaseTypeList();
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @PreAuthorize("@ss.hasPermi('tmn:device:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TmnBase tmnBase)
    {
        List<TmnBase> list = tmnBaseService.selectTmnBaseList(tmnBase);
        ExcelUtil<TmnBase> util = new ExcelUtil<TmnBase>(TmnBase.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('tmn:device:info')")
    @GetMapping(value = "/info/{tmnId}")
    public AjaxResult getInfo(@PathVariable("tmnId") String tmnId)
    {
        return success(tmnBaseService.selectTmnBaseByTmnId(tmnId));
    }

    /**
     * 新增设备
     */
    @PreAuthorize("@ss.hasPermi('tmn:device:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TmnBase tmnBase)
    {
        return toAjax(tmnBaseService.insertTmnBase(tmnBase));
    }

    /**
     * 修改设备
     */
    @PreAuthorize("@ss.hasPermi('tmn:device:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody TmnBase tmnBase)
    {
        return toAjax(tmnBaseService.updateTmnBase(tmnBase));
    }

    /**
     * 删除设备
     */
    @PreAuthorize("@ss.hasPermi('tmn:device:delete')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete/{tmnIds}")
    public AjaxResult remove(@PathVariable String[] tmnIds)
    {
        return toAjax(tmnBaseService.deleteTmnBaseByTmnIds(tmnIds));
    }

    /**
     * 同步设备
     */
    @PreAuthorize("@ss.hasPermi('tmn:device:sync')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @GetMapping("/sync")
    public AjaxResult sync()
    {
        return toAjax(tmnBaseService.syncTmnBase());
    }
}
