package com.sqx.modules.app.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.entity.App;
import com.sqx.modules.app.service.AppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * APP登录授权
 *
 */
@RestController
@RequestMapping("/appinfo")
@Api(value = "APP升级管理", tags = {"APP升级管理"})
public class AppUpgradeController {

    @Autowired
    private AppService iAppService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation("管理平台升级详情")
    @ResponseBody
    public Result list(Integer page,Integer limit) {
        PageHelper.startPage(page,limit);
        List<App> list = iAppService.list();
        PageInfo<App> pageInfo = new PageInfo<>(list);
        return Result.success().put("data", PageUtils.page(pageInfo, true));
    }


    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiOperation("管理平台升级详情")
    @ResponseBody
    public Result getBanner(@PathVariable Long id) {
        return Result.success().put("data",iAppService.selectAppById(id));
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation("管理平台添加升级信息")
    @ResponseBody
    public Result addBanner(@RequestBody App app) {
        if(app.getId()!=null){
            iAppService.updateAppById(app);
        }else{
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            app.setCreateAt(sdf.format(new Date()));
            iAppService.insertApp(app);
        }
        return Result.success();
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ApiOperation("管理平台删除升级信息")
    public Result deleteBanner(@PathVariable Long id) {
        iAppService.deleteAppById(id);
        return Result.success();
    }





}
