package com.djhk.uav.versioninfo.controller;


import com.djhk.common.annotation.Log;
import com.djhk.common.core.controller.BaseController;
import com.djhk.common.core.domain.AjaxResult;
import com.djhk.common.core.page.TableDataInfo;
import com.djhk.common.enums.BusinessType;
import com.djhk.common.utils.poi.ExcelUtil;
import com.djhk.uav.versioninfo.domain.VersionInfo;
import com.djhk.uav.versioninfo.service.IVersionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 版本公告Controller
 * 
 * @author qpc
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/version/info")
public class VersionInfoController extends BaseController
{
    @Autowired
    private IVersionInfoService versionInfoService;

    /**
     * 查询版本公告列表
     */
    @GetMapping("/list")
    public TableDataInfo list(VersionInfo versionInfo)
    {
        startPage();
        List<VersionInfo> list = versionInfoService.selectVersionInfoList(versionInfo);
        return getDataTable(list);
    }

    /**
     * 导出版本公告列表
     */
    @Log(title = "版本公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VersionInfo versionInfo)
    {
        List<VersionInfo> list = versionInfoService.selectVersionInfoList(versionInfo);
        ExcelUtil<VersionInfo> util = new ExcelUtil<VersionInfo>(VersionInfo.class);
        util.exportExcel(response, list, "版本公告数据");
    }

    /**
     * 获取版本公告详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(versionInfoService.selectVersionInfoById(id).toString());
    }

    /**
     * 新增版本公告
     */
//    @RequiresPermission("system:versioninfo:add")
    @Log(title = "版本公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VersionInfo versionInfo)
    {
        return toAjax(versionInfoService.insertVersionInfo(versionInfo));
    }

    /**
     * 修改版本公告
     */
    @Log(title = "版本公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VersionInfo versionInfo)
    {
        return toAjax(versionInfoService.updateVersionInfo(versionInfo));
    }

    /**
     * 删除版本公告
     */
    @Log(title = "版本公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(versionInfoService.deleteVersionInfoByIds(ids));
    }
}
