package com.zd.laboratory.controller;

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

import com.zd.common.core.domain.R;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.web.domain.ResultData;
import com.zd.laboratory.service.ILabSemesterService;
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.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.laboratory.domain.LabSemester;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.zd.common.core.web.page.TableDataInfo;

/**
 * 学期设置Controller
 *
 * @author zd
 * @date 2021-12-13
 */
@RestController
@Api(tags = "【学期设置】")

@RequestMapping("/semester")
public class LabSemesterController extends BaseController
{
    @Autowired
    private ILabSemesterService labSemesterService;

    /**
     * 查询学期设置列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SEMESTER + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询学期设置列表")
    public TableDataInfo<LabSemester> list(LabSemester labSemester)
    {
        startPage();
        List<LabSemester> list = labSemesterService.selectLabSemesterList(labSemester);
        return getDataTable(list);
    }

    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SEMESTER + PerFun.LIST)
    @GetMapping("/getlist")
    @ApiOperation(value = "查询学期设置列表")
    public R getlist()
    {
        List<LabSemester> list = labSemesterService.selectLabSemesterList(null);
        return R.ok(list);
    }

    /**
     * 导出学期设置列表
     */
    @ApiOperation(value = "导出学期设置列表")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SEMESTER + PerFun.EXPORT)
    @Log(title = "学期设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabSemester labSemester) throws IOException
    {
        List<LabSemester> list = labSemesterService.selectLabSemesterList(labSemester);
        ExcelUtil<LabSemester> util = new ExcelUtil<LabSemester>(LabSemester.class);
        util.exportExcel(response, list, "学期设置数据");
    }

    /**
     * 获取学期设置详细信息
     */
    @ApiOperation(value = "获取学期设置详细信息")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SEMESTER + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabSemester> getInfo(@PathVariable("id") Long id)
    {
        return ResultData.success(labSemesterService.selectLabSemesterById(id));
    }

    /**
     * 新增学期设置
     */
    @ApiOperation(value = "新增学期设置")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SEMESTER + PerFun.ADD)
    @Log(title = "学期设置", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabSemester labSemester)
    {
        return ResultData.result(labSemesterService.insertLabSemester(labSemester));
    }

    /**
     * 修改学期设置
     */
    @ApiOperation(value = "修改学期设置")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SEMESTER + PerFun.EDIT)
    @Log(title = "学期设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabSemester labSemester)
    {
        return  ResultData.result(labSemesterService.updateLabSemester(labSemester));
    }

    /**
     * 删除学期设置
     */
    @ApiOperation(value = "删除学期设置")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SEMESTER + PerFun.REMOVE)
    @Log(title = "学期设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids)
    {
        return ResultData.result(labSemesterService.deleteLabSemesterByIds(ids));
    }


    /**
     * 查询学期设置列表
     */
    @GetMapping("/getSemesterList")
    @ApiOperation(value = "查询学期列表")
    public ResultData getSemesterList(LabSemester labSemester)
    {
        List<LabSemester> list = labSemesterService.selectLabSemesterList(labSemester);
        return ResultData.success(list);
    }
}
