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.AppPets;
import com.ruoyi.model.service.IAppPetsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宠物信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/model/AppPets")
public class AppPetsController extends BaseController
{
    @Autowired
    private IAppPetsService appPetsService;

    /**
     * 查询宠物信息列表
     */
    @PreAuthorize("@ss.hasPermi('model:AppPets:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppPets appPets)
    {
        startPage();
        List<AppPets> list = appPetsService.selectAppPetsList(appPets);
        return getDataTable(list);
    }

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

    /**
     * 获取宠物信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:AppPets:query')")
    @GetMapping(value = "/{petId}")
    public AjaxResult getInfo(@PathVariable("petId") Long petId)
    {
        return success(appPetsService.selectAppPetsByPetId(petId));
    }

    /**
     * 新增宠物信息
     */
    @PreAuthorize("@ss.hasPermi('model:AppPets:add')")
    @Log(title = "宠物信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppPets appPets)
    {
        return toAjax(appPetsService.insertAppPets(appPets));
    }

    /**
     * 修改宠物信息
     */
    @PreAuthorize("@ss.hasPermi('model:AppPets:edit')")
    @Log(title = "宠物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppPets appPets)
    {
        return toAjax(appPetsService.updateAppPets(appPets));
    }

    /**
     * 删除宠物信息
     */
    @PreAuthorize("@ss.hasPermi('model:AppPets:remove')")
    @Log(title = "宠物信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{petIds}")
    public AjaxResult remove(@PathVariable Long[] petIds)
    {
        return toAjax(appPetsService.deleteAppPetsByPetIds(petIds));
    }
}
