package com.cirs.biz.controller;

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.cirs.common.annotation.Log;
import com.cirs.common.core.controller.BaseController;
import com.cirs.common.core.domain.AjaxResult;
import com.cirs.common.enums.BusinessType;
import com.cirs.biz.domain.TPageViewTime;
import com.cirs.biz.service.ITPageViewTimeService;
import com.cirs.common.utils.poi.ExcelUtil;
import com.cirs.common.core.page.TableDataInfo;

/**
 * 页面浏览时长Controller
 * 
 * @author allen
 * @date 2023-11-03
 */
@RestController
@RequestMapping("/biz/time")
public class TPageViewTimeController extends BaseController
{
    @Autowired
    private ITPageViewTimeService tPageViewTimeService;

    /**
     * 查询页面浏览时长列表
     */
    @PreAuthorize("@ss.hasPermi('biz:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPageViewTime tPageViewTime)
    {
        startPage();
        List<TPageViewTime> list = tPageViewTimeService.selectTPageViewTimeList(tPageViewTime);
        return getDataTable(list);
    }

    /**
     * 导出页面浏览时长列表
     */
    @PreAuthorize("@ss.hasPermi('biz:time:export')")
    @Log(title = "页面浏览时长", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPageViewTime tPageViewTime)
    {
        List<TPageViewTime> list = tPageViewTimeService.selectTPageViewTimeList(tPageViewTime);
        ExcelUtil<TPageViewTime> util = new ExcelUtil<TPageViewTime>(TPageViewTime.class);
        util.exportExcel(response, list, "页面浏览时长数据");
    }

    /**
     * 获取页面浏览时长详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:time:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPageViewTimeService.selectTPageViewTimeById(id));
    }

    /**
     * 新增元器件详情浏览时长 wangruilin
     */
    @PreAuthorize("@ss.hasPermi('biz:time:add')")
    @Log(title = "页面浏览时长", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPageViewTime tPageViewTime)
    {
        return toAjax(tPageViewTimeService.insertTPageViewTime(tPageViewTime));
    }

    /**
     * 修改页面浏览时长
     */
    @PreAuthorize("@ss.hasPermi('biz:time:edit')")
    @Log(title = "页面浏览时长", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPageViewTime tPageViewTime)
    {
        return toAjax(tPageViewTimeService.updateTPageViewTime(tPageViewTime));
    }

    /**
     * 删除页面浏览时长
     */
    @PreAuthorize("@ss.hasPermi('biz:time:remove')")
    @Log(title = "页面浏览时长", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPageViewTimeService.deleteTPageViewTimeByIds(ids));
    }
}
