package com.srs.web.controller.comprehensive;

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

import com.srs.common.utils.DateUtils;
import com.srs.comprehensive.domain.Vo.CphClassGoodStuYear;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.comprehensive.domain.CphClassGood;
import com.srs.comprehensive.service.ICphClassGoodService;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 优秀班级Controller
 *
 * @author srs
 * @date 2023-07-04
 */
@RestController
@RequestMapping("/system/class/good")
@Api(tags = "优秀班级")
public class CphClassGoodController extends BaseController
{
    @Autowired
    private ICphClassGoodService cphClassGoodService;

    /**
     * 查询优秀班级列表
     */
    @ApiOperation(value = "查询优秀班级列表")
//    @PreAuthorize("@ss.hasPermi('system:good:list')")
    @GetMapping("/list")
    public TableDataInfo list(CphClassGood cphClassGood)
    {
        startPage();
        List<CphClassGoodStuYear> list = cphClassGoodService.selectCphClassGoodList(cphClassGood);
        return getDataTable(list);
    }

    /**
     * 导出优秀班级列表
     */
    @ApiOperation(value = "导出优秀班级列表")
//    @PreAuthorize("@ss.hasPermi('system:good:export')")
    @Log(title = "优秀班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CphClassGood cphClassGood)
    {
        List<CphClassGoodStuYear> list = cphClassGoodService.selectCphClassGoodList(cphClassGood);
        ExcelUtil<CphClassGoodStuYear> util = new ExcelUtil<CphClassGoodStuYear>(CphClassGoodStuYear.class);
        util.exportExcel(response, list, "优秀班级数据");
    }

    /**
     * 获取优秀班级详细信息
     */
    //    @PreAuthorize("@ss.hasPermi('system:good:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cphClassGoodService.selectCphClassGoodById(id));
    }

    /**
     * 新增优秀班级
     */
    @ApiOperation(value = "新增优秀班级")
//    @PreAuthorize("@ss.hasPermi('system:good:add')")
    @Log(title = "优秀班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CphClassGood cphClassGood)
    {
        cphClassGood.setCreateBy(getUsername());
        cphClassGood.setCreateTime(DateUtils.getNowDate());
        return toAjax(cphClassGoodService.insertCphClassGood(cphClassGood));
    }

    /**
     * 修改优秀班级
     */
    @ApiOperation(value = "修改优秀班级")
//    @PreAuthorize("@ss.hasPermi('system:good:edit')")
    @Log(title = "优秀班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CphClassGood cphClassGood)
    {
        return toAjax(cphClassGoodService.updateCphClassGood(cphClassGood));
    }

    /**
     * 删除优秀班级
     */
    @ApiOperation(value = "删除优秀班级")
//    @PreAuthorize("@ss.hasPermi('system:good:remove')")
    @Log(title = "优秀班级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cphClassGoodService.deleteCphClassGoodByIds(ids));
    }
}
