package com.xinelu.manage.controller.trainingitemplayrecord;


import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.trainingitemplayrecord.TrainingItemPlayRecord;
import com.xinelu.manage.service.trainingitemplayrecord.ITrainingItemPlayRecordService;
import com.xinelu.manage.vo.trainingitemplayrecord.TrainingItemPlayRecordVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 学习培训项目播放日志记录Controller
 *
 * @author ljh
 * @date 2023-05-06
 */
@RestController
@RequestMapping("/system/playRecord")
public class TrainingItemPlayRecordController extends BaseController {
    @Resource
    private ITrainingItemPlayRecordService trainingItemPlayRecordService;

    /**
     * 查询学习培训项目播放日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:playRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingItemPlayRecord trainingItemPlayRecord) {
        startPage();
        List<TrainingItemPlayRecord> list = trainingItemPlayRecordService.selectTrainingItemPlayRecordList(trainingItemPlayRecord);
        return getDataTable(list);
    }

    /**
     * 导出学习培训项目播放日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:playRecord:export')")
    @Log(title = "学习培训项目播放日志记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingItemPlayRecord trainingItemPlayRecord) {
        List<TrainingItemPlayRecord> list = trainingItemPlayRecordService.selectTrainingItemPlayRecordList(trainingItemPlayRecord);
        ExcelUtil<TrainingItemPlayRecord> util = new ExcelUtil<>(TrainingItemPlayRecord.class);
        util.exportExcel(response, list, "学习培训项目播放日志记录数据");
    }

    /**
     * 获取学习培训项目播放日志记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:playRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(trainingItemPlayRecordService.selectTrainingItemPlayRecordById(id));
    }

    /**
     * 新增学习培训项目播放日志记录
     */
    @PreAuthorize("@ss.hasPermi('system:playRecord:add')")
    @Log(title = "学习培训项目播放日志记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingItemPlayRecord trainingItemPlayRecord) {
        return toAjax(trainingItemPlayRecordService.insertTrainingItemPlayRecord(trainingItemPlayRecord));
    }

    /**
     * 修改学习培训项目播放日志记录
     */
    @PreAuthorize("@ss.hasPermi('system:playRecord:edit')")
    @Log(title = "学习培训项目播放日志记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingItemPlayRecord trainingItemPlayRecord) {
        return toAjax(trainingItemPlayRecordService.updateTrainingItemPlayRecord(trainingItemPlayRecord));
    }

    /**
     * 删除学习培训项目播放日志记录
     */
    @PreAuthorize("@ss.hasPermi('system:playRecord:remove')")
    @Log(title = "学习培训项目播放日志记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trainingItemPlayRecordService.deleteTrainingItemPlayRecordByIds(ids));
    }

    /**
     * 查询学习培训项目播放日志记录列表数量
     */
    @GetMapping("/trainingItemPlayRecordList")
    public TableDataInfo trainingItemPlayRecordList(TrainingItemPlayRecord trainingItemPlayRecord) {
        startPage();
        List<TrainingItemPlayRecordVO> trainingItemPlayRecordList = trainingItemPlayRecordService.getTrainingItemPlayRecordList(trainingItemPlayRecord);
        return getDataTable(trainingItemPlayRecordList);
    }
}