package com.ruoyi.cgb.controller;

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

import org.springframework.security.access.prepost.PreAuthorize;
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 java.util.Arrays;

import com.ruoyi.common.core.controller.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cgb.domain.CgbScoreItem;
import com.ruoyi.cgb.service.ICgbScoreItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作品评分Controller
 *
 * @author ruoyi
 * @date 2023-08-16
 */
@RestController
@RequestMapping("/cgb/cgbScoreItem")
public class CgbScoreItemController extends BaseController {
    private final ICgbScoreItemService cgbScoreItemService;

    public CgbScoreItemController(ICgbScoreItemService cgbScoreItemService) {
        this.cgbScoreItemService = cgbScoreItemService;
    }


    /**
     * 查询作品评分列表
     *
     * @param cgbScoreItem 作品评分
     * @return 作品评分集合
     * @date 2023-08-16
     */
    @PreAuthorize("@ss.hasPermi('cgb:cgbScoreItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(CgbScoreItem cgbScoreItem) {
        startPage();
        List<CgbScoreItem> list = cgbScoreItemService.queryList(cgbScoreItem);
        return getDataTable(list);
    }


    /**
     * 导出作品评分列表
     *
     * @param cgbScoreItem 作品评分
     * @date 2023-08-16
     */
    @PreAuthorize("@ss.hasPermi('cgb:cgbScoreItem:export')")
    @Log(title = "作品评分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CgbScoreItem cgbScoreItem) {
        List<CgbScoreItem> list = cgbScoreItemService.list(new QueryWrapper<>());
        ExcelUtil<CgbScoreItem> util = new ExcelUtil<>(CgbScoreItem. class);
        util.exportExcel(response, list, "作品评分数据");
    }

    /**
     * 获取作品评分详细信息
     *
     * @param id 主键id
     * @return 结果
     * @date 2023-08-16
     */
    @PreAuthorize("@ss.hasPermi('cgb:cgbScoreItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cgbScoreItemService.getById(id));
    }


    /**
     * 新增作品评分信息
     *
     * @param cgbScoreItem 作品评分
     * @return 结果
     * @date 2023-08-16
     */
    @PreAuthorize("@ss.hasPermi('cgb:cgbScoreItem:add')")
    @Log(title = "作品评分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CgbScoreItem cgbScoreItem) {
        return toAjax(cgbScoreItemService.save(cgbScoreItem));
    }


    /**
     * 修改作品评分信息
     *
     * @param cgbScoreItem 作品评分
     * @return 结果
     * @date 2023-08-16
     */
    @PreAuthorize("@ss.hasPermi('cgb:cgbScoreItem:edit')")
    @Log(title = "作品评分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CgbScoreItem cgbScoreItem) {
        return toAjax(cgbScoreItemService.updateById(cgbScoreItem));
    }


    /**
     * 删除作品评分信息
     *
     * @param ids 主键ids
     * @return 结果
     * @date 2023-08-16
     */
    @PreAuthorize("@ss.hasPermi('cgb:cgbScoreItem:remove')")
    @Log(title = "作品评分", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cgbScoreItemService.removeByIds(Arrays.asList(ids)));
    }


}
