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

/**
 * 宠物信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/model/AppletPet")
public class AppletPetController extends BaseController
{
    @Autowired
    private IAppletPetService appletPetService;

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

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

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

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

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

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