package com.ruoyi.hezhi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hezhi.domain.TbAuthorizeHonor;
import com.ruoyi.hezhi.service.ITbAuthorizeHonorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 授权荣誉Controller
 *
 * @author ruoyi
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/hezhi/authorizeHonor")
public class TbAuthorizeHonorController extends BaseController
{
    @Autowired
    private ITbAuthorizeHonorService tbAuthorizeHonorService;

    /**
     * 查询授权荣誉列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:authorizeHonor:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbAuthorizeHonor tbAuthorizeHonor)
    {
        startPage();
        List<TbAuthorizeHonor> list = tbAuthorizeHonorService.selectTbAuthorizeHonorList(tbAuthorizeHonor);
        return getDataTable(list);
    }

    /**
     * 导出授权荣誉列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:authorizeHonor:export')")
    @Log(title = "授权荣誉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbAuthorizeHonor tbAuthorizeHonor)
    {
        List<TbAuthorizeHonor> list = tbAuthorizeHonorService.selectTbAuthorizeHonorList(tbAuthorizeHonor);
        ExcelUtil<TbAuthorizeHonor> util = new ExcelUtil<TbAuthorizeHonor>(TbAuthorizeHonor.class);
        util.exportExcel(response, list, "授权荣誉数据");
    }

    /**
     * 获取授权荣誉详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:authorizeHonor:query')")
    @GetMapping(value = "/{authorizeHonorId}")
    public AjaxResult getInfo(@PathVariable("authorizeHonorId") Long authorizeHonorId)
    {
        return success(tbAuthorizeHonorService.selectTbAuthorizeHonorByAuthorizeHonorId(authorizeHonorId));
    }

    /**
     * 新增授权荣誉
     */
    @PreAuthorize("@ss.hasPermi('hezhi:authorizeHonor:add')")
    @Log(title = "授权荣誉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbAuthorizeHonor tbAuthorizeHonor)
    {
        return toAjax(tbAuthorizeHonorService.insertTbAuthorizeHonor(tbAuthorizeHonor));
    }

    /**
     * 修改授权荣誉
     */
    @PreAuthorize("@ss.hasPermi('hezhi:authorizeHonor:edit')")
    @Log(title = "授权荣誉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbAuthorizeHonor tbAuthorizeHonor)
    {
        return toAjax(tbAuthorizeHonorService.updateTbAuthorizeHonor(tbAuthorizeHonor));
    }

    /**
     * 删除授权荣誉
     */
    @PreAuthorize("@ss.hasPermi('hezhi:authorizeHonor:remove')")
    @Log(title = "授权荣誉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{authorizeHonorIds}")
    public AjaxResult remove(@PathVariable Long[] authorizeHonorIds)
    {
        return toAjax(tbAuthorizeHonorService.deleteTbAuthorizeHonorByAuthorizeHonorIds(authorizeHonorIds));
    }
}
