package com.zehong.web.controller.detector;

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.TDetectorInfo;
import com.zehong.system.service.ITDetectorInfoService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageInfo;
import com.zehong.common.core.page.TableDataInfo;

/**
 * 探测器Controller
 * 
 * @author zehong
 * @date 2021-11-02
 */
@RestController
@RequestMapping("/detector/detectorInfo")
public class TDetectorInfoController extends BaseController
{
    @Autowired
    private ITDetectorInfoService tDetectorInfoService;

     /**
     * 查询探测器列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TDetectorInfo tDetectorInfo)
    {
        startPage();
        PageInfo<TDetectorInfo> list = tDetectorInfoService.selectTDetectorInfoPage(tDetectorInfo);
        return getDataTable(list);
    }

    /**
     * 获取探测器列表
     * @param tDetectorInfo
     * @return
     */
    @GetMapping("/detectorInfoList")
    public AjaxResult detectorInfoList(TDetectorInfo tDetectorInfo){
        return AjaxResult.success(tDetectorInfoService.selectTDetectorInfoList(tDetectorInfo));
    }

    /**
     * 导出探测器列表
     */
    @Log(title = "探测器", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TDetectorInfo tDetectorInfo)
    {
        List<TDetectorInfo> list = tDetectorInfoService.selectTDetectorInfoList(tDetectorInfo);
        ExcelUtil<TDetectorInfo> util = new ExcelUtil<TDetectorInfo>(TDetectorInfo.class);
        return util.exportExcel(list, "探测器数据");
    }

    /**
     * 获取探测器详细信息
     */
    @GetMapping(value = "/{detectorId}")
    public AjaxResult getInfo(@PathVariable("detectorId") Long detectorId)
    {
        return AjaxResult.success(tDetectorInfoService.selectTDetectorInfoById(detectorId));
    }

    /**
     * 新增探测器
     */
    @Log(title = "探测器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDetectorInfo tDetectorInfo)
    {
        return toAjax(tDetectorInfoService.insertTDetectorInfo(tDetectorInfo));
    }

    /**
     * 修改探测器
     */
    @Log(title = "探测器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDetectorInfo tDetectorInfo)
    {
        return toAjax(tDetectorInfoService.updateTDetectorInfo(tDetectorInfo));
    }

    /**
     * 删除探测器
     */
    @Log(title = "探测器", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detectorIds}")
    public AjaxResult remove(@PathVariable Long[] detectorIds)
    {
        return toAjax(tDetectorInfoService.deleteTDetectorInfoByIds(detectorIds));
    }
}
