package com.yiqi.admin.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.yiqi.common.constant.UrlConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.app.domain.AppVersion;
import com.yiqi.app.service.IAppVersionService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * APP版本管理Controller
 *
 * @author xiaohei
 * @date 2023-09-01
 */
@Api(tags = "管理后台 - APP版本管理")
@RestController
@RequestMapping(UrlConstants.managerApi + "/app/version")
public class AppVersionController extends BaseController {
    @Autowired
    private IAppVersionService appVersionService;

    /**
     * 查询APP版本管理列表
     */
    @PreAuthorize("@ss.hasPermi('app:version:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询APP版本管理列表")
    public TableDataInfo list(AppVersion appVersion) {
        startPage();
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        return getDataTable(list);
    }

    /**
     * 导出APP版本管理列表
     */
    @PreAuthorize("@ss.hasPermi('app:version:export')")
    @Log(title = "APP版本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出APP版本管理列表")
    public void export(HttpServletResponse response, AppVersion appVersion) {
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        ExcelUtil<AppVersion> util = new ExcelUtil<AppVersion>(AppVersion. class);
        util.exportExcel(response, list, "APP版本管理数据");
    }

    /**
     * 获取APP版本管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:version:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取APP版本管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appVersionService.selectAppVersionById(id));
    }

    /**
     * 新增APP版本管理
     */
    @PreAuthorize("@ss.hasPermi('app:version:add')")
    @Log(title = "APP版本管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增APP版本管理")
    public AjaxResult add(@RequestBody AppVersion appVersion) {
        appVersion.setCreateById(getUserId());
        appVersion.setCreateBy(getUsername());
        return toAjax(appVersionService.insertAppVersion(appVersion));
    }

    /**
     * 修改APP版本管理
     */
    @PreAuthorize("@ss.hasPermi('app:version:edit')")
    @Log(title = "APP版本管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改APP版本管理")
    public AjaxResult edit(@RequestBody AppVersion appVersion) {
        appVersion.setUpdateById(getUserId());
        appVersion.setUpdateBy(getUsername());
        return toAjax(appVersionService.updateAppVersion(appVersion));
    }

    /**
     * 删除APP版本管理
     */
    @PreAuthorize("@ss.hasPermi('app:version:remove')")
    @Log(title = "APP版本管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除APP版本管理")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appVersionService.deleteAppVersionByIds(ids));
    }

}
