package com.hzu.labbooking.controller;

import java.util.List;

import com.hzu.labbooking.domain.vo.MyCourseVO;
import com.ruoyi.common.core.domain.R;
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.hzu.labbooking.domain.Course;
import com.hzu.labbooking.service.ICourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程信息Controller
 *
 * @author yezihao
 * @date 2021-04-29
 */
@RestController
@RequestMapping("/labbooking/course")
public class CourseController extends BaseController {

    @Autowired
    private ICourseService courseService;

    /**
     * 查询个人课程信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Course course) {
        startPage();
        List<MyCourseVO> list = courseService.selectCourseList(course);
        return getDataTable(list);
    }

    /**
     * 查询个人所有课程（预约实验室模块）
     */
    @GetMapping("/getCourse")
    public R<List<Course>> getCourse() {
        List<Course> list = courseService.selectCourse();
        return R.ok(list);
    }

    /**
     * 获取课程信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(courseService.selectCourseById(id));
    }

    /**
     * 新增个人课程信息
     */
    @Log(title = "课程信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Course course) {
        return toAjax(courseService.insertCourse(course));
    }

    /**
     * 修改课程信息
     */
    @Log(title = "课程信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Course course) {
        return toAjax(courseService.updateCourse(course));
    }

    /**
     * 删除课程信息
     */
    @Log(title = "课程信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(courseService.deleteCourseByIds(ids));
    }

    /**
     * 导出个人课程信息列表
     */
    @Log(title = "课程信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Course course) {
        List<MyCourseVO> list = courseService.selectCourseList(course);
        ExcelUtil<MyCourseVO> util = new ExcelUtil<>(MyCourseVO.class);
        return util.exportExcel(list, "课程信息数据");
    }

}
