package com.ruoyi.web.controller.appVersion;

import java.util.List;

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.appVersion.domain.TAppVersion;
import com.ruoyi.appVersion.service.ITAppVersionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * APP版本信息Controller
 *
 * @author ruoyi
 * @date 2021-06-16
 */
@RestController
@RequestMapping("/appVersion/version")
public class TAppVersionController extends BaseController {
    @Autowired
    private ITAppVersionService tAppVersionService;

    /**
     * 查询APP版本信息列表
     */
    @PreAuthorize("@ss.hasPermi('appVersion:version:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAppVersion tAppVersion) {
        startPage();
        List<TAppVersion> list = tAppVersionService.selectTAppVersionList(tAppVersion);
        return getDataTable(list);
    }

    /**
     * 导出APP版本信息列表
     */
    @PreAuthorize("@ss.hasPermi('appVersion:version:export')")
    @Log(title = "APP版本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TAppVersion tAppVersion) {
        List<TAppVersion> list = tAppVersionService.selectTAppVersionList(tAppVersion);
        ExcelUtil<TAppVersion> util = new ExcelUtil<TAppVersion>(TAppVersion.class);
        return util.exportExcel(list, "version");
    }

    /**
     * 获取APP版本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('appVersion:version:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tAppVersionService.selectTAppVersionById(fId));
    }

    /**
     * 新增APP版本信息
     */
    @PreAuthorize("@ss.hasPermi('appVersion:version:add')")
    @Log(title = "APP版本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAppVersion tAppVersion) {
        return toAjax(tAppVersionService.insertTAppVersion(tAppVersion));
    }

    /**
     * 修改APP版本信息
     */
    @PreAuthorize("@ss.hasPermi('appVersion:version:edit')")
    @Log(title = "APP版本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAppVersion tAppVersion) {
        return toAjax(tAppVersionService.updateTAppVersion(tAppVersion));
    }

    /**
     * 删除APP版本信息
     */
    @PreAuthorize("@ss.hasPermi('appVersion:version:remove')")
    @Log(title = "APP版本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        return toAjax(tAppVersionService.deleteTAppVersionByIds(fIds));
    }

    /**
     * 获取app版本信息
     * @return
     */
    @Log(title = "获取APP版本信息", businessType = BusinessType.DELETE)
    @GetMapping("getAppVersion")
    public AjaxResult getAppVersion(Integer integer){
        if (integer == null){
            return AjaxResult.error("参数不能为空");
        }
        return tAppVersionService.getAppVersion(integer);
    }
}
