package com.ruoyi.project.check.controller;

import java.util.Date;
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.project.check.domain.TCheckInstrument;
import com.ruoyi.project.check.service.ITCheckInstrumentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仪器Controller
 *
 * @author ruoyi
 * @date 2022-11-22
 */
@RestController
@RequestMapping("/check/instrument")
public class TCheckInstrumentController extends BaseController
{
    @Autowired
    private ITCheckInstrumentService tCheckInstrumentService;

    /**
     * 查询仪器列表
     */
    @PreAuthorize("@ss.hasPermi('check:instrument:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCheckInstrument tCheckInstrument)
    {
        startPage();
        List<TCheckInstrument> list = tCheckInstrumentService.selectTCheckInstrumentList(tCheckInstrument);
        return getDataTable(list);
    }

    @GetMapping("/allInstrument")
    public AjaxResult allInstrument()
    {
        return AjaxResult.success(tCheckInstrumentService.selectAllInstrument());
    }

    /**
     * 导出仪器列表
     */
    @PreAuthorize("@ss.hasPermi('check:instrument:export')")
    @Log(title = "仪器导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCheckInstrument tCheckInstrument)
    {
        List<TCheckInstrument> list = tCheckInstrumentService.selectTCheckInstrumentList(tCheckInstrument);
        ExcelUtil<TCheckInstrument> util = new ExcelUtil<TCheckInstrument>(TCheckInstrument.class);
        util.exportExcel(response, list, "仪器数据");
    }

    /**
     * 获取仪器详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:instrument:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tCheckInstrumentService.selectTCheckInstrumentById(id));
    }

    /**
     * 新增仪器
     */
    @PreAuthorize("@ss.hasPermi('check:instrument:add')")
    @Log(title = "仪器新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCheckInstrument tCheckInstrument)
    {
        tCheckInstrument.setUpdatedate(new Date());
        tCheckInstrument.setUpdaterCode(getUserId());
        tCheckInstrument.setCreaterCode(getUserId());
        return toAjax(tCheckInstrumentService.insertTCheckInstrument(tCheckInstrument));
    }

    /**
     * 修改仪器
     */
    @PreAuthorize("@ss.hasPermi('check:instrument:edit')")
    @Log(title = "仪器修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCheckInstrument tCheckInstrument)
    {
        tCheckInstrument.setUpdatedate(new Date());
        tCheckInstrument.setUpdaterCode(getUserId());
        return toAjax(tCheckInstrumentService.updateTCheckInstrument(tCheckInstrument));
    }

    /**
     * 删除仪器
     */
    @PreAuthorize("@ss.hasPermi('check:instrument:remove')")
    @Log(title = "仪器删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCheckInstrumentService.deleteTCheckInstrumentByIds(ids));
    }
}
