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.CgbScoreDetail;
import com.ruoyi.cgb.service.ICgbScoreDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评分明细Controller
 *
 * @author ruoyi
 * @date 2023-08-16
 */
@RestController
@RequestMapping("/cgb/cgbScoreDetail")
public class CgbScoreDetailController extends BaseController {
    private final ICgbScoreDetailService cgbScoreDetailService;

    public CgbScoreDetailController(ICgbScoreDetailService cgbScoreDetailService) {
        this.cgbScoreDetailService = cgbScoreDetailService;
    }


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


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

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


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


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


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


}
