package com.ruoyi.frequency.appversion.controller;

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;
import com.ruoyi.frequency.appversion.entity.AppVersion;
import com.ruoyi.frequency.appversion.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 版本Controller
 * 
 * @author liwenlong
 * @date 2023-11-27
 */
@RestController
@RequestMapping("/frequency/appversion")
public class AppVersionController extends BaseController
{
    @Autowired
    private AppVersionService appVersionService;

    /**
     * 查询版本列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:appversion:list')")
    @PostMapping("/list")
    public TableDataInfo<AppVersion> list(@RequestBody AppVersion appVersion)
    {
        startPage();
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        return getDataTable(list);
    }

    /**
     * 导出版本列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:appversion:export')")
    @Log(title = "版本", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppVersion appVersion)
    {
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        ExcelUtil<AppVersion> util = new ExcelUtil<AppVersion>(AppVersion.class);
        return util.exportExcel(list, "版本数据");
    }

    /**
     * 获取版本详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:appversion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<AppVersion> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appVersionService.selectAppVersionById(id));
    }

    /**
     * 新增版本
     */
    @PreAuthorize("@ss.hasPermi('frequency:appversion:add')")
    @Log(title = "版本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppVersion appVersion)
    {
        return toAjax(appVersionService.insertAppVersion(appVersion));
    }

    /**
     * 修改版本
     */
    @PreAuthorize("@ss.hasPermi('frequency:appversion:edit')")
    @Log(title = "版本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppVersion appVersion)
    {
        return toAjax(appVersionService.updateAppVersion(appVersion));
    }

    /**
     * 删除版本
     */
    @PreAuthorize("@ss.hasPermi('frequency:appversion:remove')")
    @Log(title = "版本", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(appVersionService.deleteAppVersionByIds(ids,delFlag));
    }
}
