package com.pnkx.web.controller.system;

import com.pnkx.common.annotation.Log;
import com.pnkx.common.core.controller.BaseController;
import com.pnkx.common.core.domain.AjaxResult;
import com.pnkx.common.core.page.TableDataInfo;
import com.pnkx.common.enums.BusinessType;
import com.pnkx.common.utils.ExcelUtil;
import com.pnkx.system.domain.SysAppUpdateLog;
import com.pnkx.system.service.ISysAppService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * app版本管理
 *
 * @author phy
 */
@RestController
@RequestMapping("/app")
public class SysAppController extends BaseController {
    @Resource
    ISysAppService sysAppService;

    /**
     * 获取最新版app信息
     */
    @GetMapping("/getNewestAppInfo")
    public AjaxResult getNewestAppInfo() {
        return AjaxResult.success(sysAppService.getNewestAppInfo());
    }

    /**
     * 查询app更新日志列表
     */
    @GetMapping("/log/list")
    public TableDataInfo getUpdateLogList(SysAppUpdateLog appUpdateLog) {
        startPage();
        List<SysAppUpdateLog> list = sysAppService.selectAppUpdateLogList(appUpdateLog);
        return getDataTable(list);
    }

    /**
     * 导出app更新日志列表
     */
    @Log(title = "app更新日志", businessType = BusinessType.EXPORT)
    @GetMapping("/log/export")
    public AjaxResult export(SysAppUpdateLog appUpdateLog) {
        List<SysAppUpdateLog> list = sysAppService.selectAppUpdateLogList(appUpdateLog);
        ExcelUtil<SysAppUpdateLog> util = new ExcelUtil<>(SysAppUpdateLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 获取app更新日志详细信息
     */
    @GetMapping(value = "/log/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysAppService.selectAppUpdateLogById(id));
    }

    /**
     * 新增app更新日志
     */
    @Log(title = "app更新日志", businessType = BusinessType.INSERT)
    @PostMapping("/log")
    public AjaxResult add(@RequestBody SysAppUpdateLog appUpdateLog) {
        return toAjax(sysAppService.insertAppUpdateLog(appUpdateLog));
    }

    /**
     * 修改app更新日志
     */
    @Log(title = "app更新日志", businessType = BusinessType.UPDATE)
    @PutMapping("/log")
    public AjaxResult edit(@RequestBody SysAppUpdateLog appUpdateLog) {
        return toAjax(sysAppService.updateAppUpdateLog(appUpdateLog));
    }

    /**
     * 删除app更新日志
     */
    @Log(title = "app更新日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/log/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysAppService.deleteAppUpdateLogByIds(ids));
    }
}
