package com.ruoyi.web.controller.ss;

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

import com.ruoyi.ss.record.time.domain.RecordTimeQuery;
import com.ruoyi.ss.record.time.domain.RecordTimeVO;
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.ss.record.time.domain.RecordTime;
import com.ruoyi.ss.record.time.service.IRecordTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备时长变化记录Controller
 *
 * @author ruoyi
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/ss/time")
public class RecordTimeController extends BaseController
{
    @Autowired
    private IRecordTimeService recordTimeService;

    /**
     * 查询设备时长变化记录列表
     */
    @PreAuthorize("@ss.hasPermi('ss:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordTimeQuery recordTime)
    {
        startPage();
        List<RecordTimeVO> list = recordTimeService.selectRecordTimeList(recordTime);
        return getDataTable(list);
    }

    /**
     * 导出设备时长变化记录列表
     */
    @PreAuthorize("@ss.hasPermi('ss:time:export')")
    @Log(title = "设备时长变化记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordTimeQuery recordTime)
    {
        List<RecordTimeVO> list = recordTimeService.selectRecordTimeList(recordTime);
        ExcelUtil<RecordTimeVO> util = new ExcelUtil<RecordTimeVO>(RecordTimeVO.class);
        util.exportExcel(response, list, "设备时长变化记录数据");
    }

    /**
     * 获取设备时长变化记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:time:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(recordTimeService.selectRecordTimeById(id));
    }

    /**
     * 新增设备时长变化记录
     */
    @PreAuthorize("@ss.hasPermi('ss:time:add')")
    @Log(title = "设备时长变化记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordTime recordTime)
    {
        return toAjax(recordTimeService.insertRecordTime(recordTime));
    }

    /**
     * 修改设备时长变化记录
     */
    @PreAuthorize("@ss.hasPermi('ss:time:edit')")
    @Log(title = "设备时长变化记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordTime recordTime)
    {
        return toAjax(recordTimeService.updateRecordTime(recordTime));
    }

    /**
     * 删除设备时长变化记录
     */
    @PreAuthorize("@ss.hasPermi('ss:time:remove')")
    @Log(title = "设备时长变化记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recordTimeService.deleteRecordTimeByIds(ids));
    }
}
