package com.ruoyi.web.bst;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.snapshot.domain.Snapshot;
import com.ruoyi.bst.snapshot.domain.SnapshotQuery;
import com.ruoyi.bst.snapshot.domain.SnapshotVO;
import com.ruoyi.bst.snapshot.service.SnapshotService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 快照Controller
 *
 * @author ruoyi
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/bst/snapshot")
public class SnapshotController extends BaseController
{
    @Autowired
    private SnapshotService snapshotService;

    /**
     * 查询快照列表
     */
    @PreAuthorize("@ss.hasPermi('bst:snapshot:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnapshotQuery query)
    {
        startPage();
        startOrderBy();
        List<SnapshotVO> list = snapshotService.selectSnapshotList(query);
        return getDataTable(list);
    }

    /**
     * 导出快照列表
     */
    @PreAuthorize("@ss.hasPermi('bst:snapshot:export')")
    @Log(title = "快照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnapshotQuery query)
    {
        List<SnapshotVO> list = snapshotService.selectSnapshotList(query);
        ExcelUtil<SnapshotVO> util = new ExcelUtil<SnapshotVO>(SnapshotVO.class);
        util.exportExcel(response, list, "快照数据");
    }

    /**
     * 获取快照详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:snapshot:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(snapshotService.selectSnapshotById(id));
    }

    /**
     * 新增快照
     */
    @PreAuthorize("@ss.hasPermi('bst:snapshot:add')")
    @Log(title = "快照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Snapshot snapshot)
    {
        return toAjax(snapshotService.insertSnapshot(snapshot));
    }

    /**
     * 修改快照
     */
    @PreAuthorize("@ss.hasPermi('bst:snapshot:edit')")
    @Log(title = "快照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Snapshot snapshot)
    {
        return toAjax(snapshotService.updateSnapshot(snapshot));
    }

    /** 
     * 删除快照
     */
    @PreAuthorize("@ss.hasPermi('bst:snapshot:remove')")
    @Log(title = "快照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(snapshotService.deleteSnapshotByIds(ids));
    }
}
