package com.ruoyi.web.controller.post;

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.post.domain.PostCollection;
import com.ruoyi.post.service.IPostCollectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 邮贝藏品信息; Controller
 * 
 * @author ruoyi
 * @date 2023-02-11
 */
@RestController
@RequestMapping("/post/collection")
public class PostCollectionController extends BaseController
{
    @Autowired
    private IPostCollectionService postCollectionService;

    /**
     * 查询邮贝藏品信息; 列表
     */
    @PreAuthorize("@ss.hasPermi('system:collection:list')")
    @GetMapping("/list")
    public TableDataInfo list(PostCollection postCollection)
    {
        startPage();
        List<PostCollection> list = postCollectionService.selectPostCollectionList(postCollection);
        return getDataTable(list);
    }

    /**
     * 导出邮贝藏品信息; 列表
     */
    @PreAuthorize("@ss.hasPermi('system:collection:export')")
    @Log(title = "邮贝藏品信息; ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PostCollection postCollection)
    {
        List<PostCollection> list = postCollectionService.selectPostCollectionList(postCollection);
        ExcelUtil<PostCollection> util = new ExcelUtil<PostCollection>(PostCollection.class);
        util.exportExcel(response, list, "邮贝藏品信息; ");
    }

    /**
     * 获取邮贝藏品信息; 详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:collection:query')")
    @GetMapping(value = "/{collectionId}")
    public AjaxResult getInfo(@PathVariable("collectionId") Long collectionId)
    {
        return success(postCollectionService.selectPostCollectionByCollectionId(collectionId));
    }

    /**
     * 新增邮贝藏品信息; 
     */
    @PreAuthorize("@ss.hasPermi('system:collection:add')")
    @Log(title = "邮贝藏品信息; ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostCollection postCollection)
    {
        return toAjax(postCollectionService.insertPostCollection(postCollection));
    }

    /**
     * 修改邮贝藏品信息; 
     */
    @PreAuthorize("@ss.hasPermi('system:collection:edit')")
    @Log(title = "邮贝藏品信息; ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostCollection postCollection)
    {
        return toAjax(postCollectionService.updatePostCollection(postCollection));
    }

    /**
     * 删除邮贝藏品信息; 
     */
    @PreAuthorize("@ss.hasPermi('system:collection:remove')")
    @Log(title = "邮贝藏品信息; ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectionIds}")
    public AjaxResult remove(@PathVariable Long[] collectionIds)
    {
        return toAjax(postCollectionService.deletePostCollectionByCollectionIds(collectionIds));
    }
}
