package com.ruoyi.model.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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 com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.model.domain.PetType;
import com.ruoyi.model.service.IPetTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宠物类型Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/model/petType")
public class PetTypeController extends BaseController
{
    @Autowired
    private IPetTypeService petTypeService;

    /**
     * 查询宠物类型列表
     */
    @PreAuthorize("@ss.hasPermi('model:petType:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetType petType)
    {
        startPage();
        List<PetType> list = petTypeService.selectPetTypeList(petType);
        return getDataTable(list);
    }

    /**
     * 导出宠物类型列表
     */
    @PreAuthorize("@ss.hasPermi('model:petType:export')")
    @Log(title = "宠物类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetType petType) throws IOException {
        List<PetType> list = petTypeService.selectPetTypeList(petType);
        ExcelUtil<PetType> util = new ExcelUtil<PetType>(PetType.class);
        util.exportExcel(response, list, "宠物类型数据");
    }

    /**
     * 获取宠物类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:petType:query')")
    @GetMapping(value = "/{petTypeId}")
    public AjaxResult getInfo(@PathVariable("petTypeId") Long petTypeId)
    {
        return success(petTypeService.selectPetTypeByPetTypeId(petTypeId));
    }

    /**
     * 新增宠物类型
     */
    @PreAuthorize("@ss.hasPermi('model:petType:add')")
    @Log(title = "宠物类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetType petType)
    {
        return toAjax(petTypeService.insertPetType(petType));
    }

    /**
     * 修改宠物类型
     */
    @PreAuthorize("@ss.hasPermi('model:petType:edit')")
    @Log(title = "宠物类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetType petType)
    {
        return toAjax(petTypeService.updatePetType(petType));
    }

    /**
     * 删除宠物类型
     */
    @PreAuthorize("@ss.hasPermi('model:petType:remove')")
    @Log(title = "宠物类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{petTypeIds}")
    public AjaxResult remove(@PathVariable Long[] petTypeIds)
    {
        return toAjax(petTypeService.deletePetTypeByPetTypeIds(petTypeIds));
    }
}
