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.TbCase;
import com.ruoyi.hezhi.service.ITbCaseService;
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-09-14
 */
@RestController
@RequestMapping("/hezhi/case")
public class TbCaseController extends BaseController
{
    @Autowired
    private ITbCaseService tbCaseService;

    /**
     * 查询案例列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCase tbCase)
    {
        startPage();
        List<TbCase> list = tbCaseService.selectTbCaseList(tbCase);
        return getDataTable(list);
    }

    /**
     * 导出案例列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:case:export')")
    @Log(title = "案例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCase tbCase)
    {
        List<TbCase> list = tbCaseService.selectTbCaseList(tbCase);
        ExcelUtil<TbCase> util = new ExcelUtil<TbCase>(TbCase.class);
        util.exportExcel(response, list, "案例数据");
    }

    /**
     * 获取案例详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:case:query')")
    @GetMapping(value = "/{caseId}")
    public AjaxResult getInfo(@PathVariable("caseId") Long caseId)
    {
        return success(tbCaseService.selectTbCaseByCaseId(caseId));
    }

    /**
     * 新增案例
     */
    @PreAuthorize("@ss.hasPermi('hezhi:case:add')")
    @Log(title = "案例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCase tbCase)
    {
        return toAjax(tbCaseService.insertTbCase(tbCase));
    }

    /**
     * 修改案例
     */
    @PreAuthorize("@ss.hasPermi('hezhi:case:edit')")
    @Log(title = "案例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCase tbCase)
    {
        return toAjax(tbCaseService.updateTbCase(tbCase));
    }

    /**
     * 删除案例
     */
    @PreAuthorize("@ss.hasPermi('hezhi:case:remove')")
    @Log(title = "案例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseIds}")
    public AjaxResult remove(@PathVariable Long[] caseIds)
    {
        return toAjax(tbCaseService.deleteTbCaseByCaseIds(caseIds));
    }
}
