package com.cyl.manager.ums.controller;

import java.io.IOException;
import java.util.List;

import com.cyl.manager.ums.domain.Pet;
import com.cyl.manager.ums.pojo.query.PetQuery;
import com.cyl.manager.ums.pojo.vo.PetVO;
import com.cyl.manager.ums.service.PetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
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.common.utils.poi.ExcelUtil;

import javax.servlet.http.HttpServletResponse;

/**
 * 宠物档案Controller
 *
 * @author daixiande
 * @date 2024-05-05
 */
//@Api("宠物档案")
@RestController
@RequestMapping("/ums/pet")
public class PetController extends BaseController {
    @Autowired
    private PetService petService;

    /**
     * 查询宠物档案列表
     */
//    @ApiOperation("查询宠物档案列表")
    @PreAuthorize("@ss.hasPermi('ums:pet:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<Pet>> list(@RequestBody PetQuery  pet, Pageable page) {
        List<Pet> list = petService.selectList(pet, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }


    /**
     * 导出宠物档案列表
     */
//    @ApiOperation("导出宠物档案列表")
    @PreAuthorize("@ss.hasPermi('ums:pet:export')")
    @Log(title = "宠物档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Pet pet) throws IOException {
        List<Pet> list = petService.selectPetList(pet);
        ExcelUtil<Pet> util = new ExcelUtil<Pet>(Pet.class);
        util.exportExcel(response, list, "宠物档案数据");
    }

    /**
     * 获取宠物档案详细信息
     */
//    @ApiOperation("获取宠物档案详细信息")
    @PreAuthorize("@ss.hasPermi('ums:pet:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<PetVO> getInfo(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(petService.selectPetById(id));
    }
    /**
     * 新增宠物档案
     */
//    @ApiOperation("新增宠物档案")
    @PreAuthorize("@ss.hasPermi('ums:pet:add')")
    @Log(title = "宠物档案", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody PetVO petVO) {
        return ResponseEntity.ok(petService.insertPet(petVO));
    }



    /**
     * 修改宠物档案
     */
//    @ApiOperation("修改宠物档案")
    @PreAuthorize("@ss.hasPermi('ums:pet:edit')")
    @Log(title = "宠物档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetVO petVO) {
        return toAjax(petService.updatePet(petVO));
    }

    /**
     * 删除宠物档案
     */
//    @ApiOperation("删除宠物档案")
    @PreAuthorize("@ss.hasPermi('ums:pet:remove')")
    @Log(title = "宠物档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public  ResponseEntity<Integer> remove(@PathVariable Integer[] ids) {
        return ResponseEntity.ok(petService.deletePetByIds(ids));
    }
}
