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.TbCaseType;
import com.ruoyi.hezhi.service.ITbCaseTypeService;
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/caseType")
public class TbCaseTypeController extends BaseController
{
    @Autowired
    private ITbCaseTypeService tbCaseTypeService;

    /**
     * 查询案例类型列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:caseType:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCaseType tbCaseType)
    {
        startPage();
        List<TbCaseType> list = tbCaseTypeService.selectTbCaseTypeList(tbCaseType);
        return getDataTable(list);
    }

    /**
     * 导出案例类型列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:caseType:export')")
    @Log(title = "案例类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCaseType tbCaseType)
    {
        List<TbCaseType> list = tbCaseTypeService.selectTbCaseTypeList(tbCaseType);
        ExcelUtil<TbCaseType> util = new ExcelUtil<TbCaseType>(TbCaseType.class);
        util.exportExcel(response, list, "案例类型数据");
    }

    /**
     * 获取案例类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:caseType:query')")
    @GetMapping(value = "/{caseTypeId}")
    public AjaxResult getInfo(@PathVariable("caseTypeId") Long caseTypeId)
    {
        return success(tbCaseTypeService.selectTbCaseTypeByCaseTypeId(caseTypeId));
    }

    /**
     * 新增案例类型
     */
    @PreAuthorize("@ss.hasPermi('hezhi:caseType:add')")
    @Log(title = "案例类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCaseType tbCaseType)
    {
        return toAjax(tbCaseTypeService.insertTbCaseType(tbCaseType));
    }

    /**
     * 修改案例类型
     */
    @PreAuthorize("@ss.hasPermi('hezhi:caseType:edit')")
    @Log(title = "案例类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCaseType tbCaseType)
    {
        return toAjax(tbCaseTypeService.updateTbCaseType(tbCaseType));
    }

    /**
     * 删除案例类型
     */
    @PreAuthorize("@ss.hasPermi('hezhi:caseType:remove')")
    @Log(title = "案例类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseTypeIds}")
    public AjaxResult remove(@PathVariable Long[] caseTypeIds)
    {
        return toAjax(tbCaseTypeService.deleteTbCaseTypeByCaseTypeIds(caseTypeIds));
    }
}
