package com.mvc.controller.app;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.AppAuthModel;
import com.mvc.service.app.AppAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "APP安装认证控制类")
@RequestMapping("/AppAuthAction")
@Controller
public class AppAuthAction {

    @Autowired
    private AppAuthService appAuthService;


    @ApiOperation("分页查询APP认证表")
    @RequestMapping(value = "/list/{page}/{rows}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findAllAppAuth(@PathVariable("page") Integer page, @PathVariable("rows") Integer rows){
        try {
            Map<String,Object> res= appAuthService.findAllAppAuth(page,rows);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }



    @ApiOperation("新增查询APP认证表")
    @RequestMapping(value = "/saveAppAuth",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveAppAuth(@RequestBody AppAuthModel model){
        try {
            AppAuthModel resModel= appAuthService.saveAppAuth(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("更新查询APP认证表")
    @RequestMapping(value = "/updateAppAuth",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody AppAuthModel model){
        try {
            AppAuthModel resModel= appAuthService.updateAppAuth(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("删除查询APP认证表")
    @RequestMapping(value = "/deleteAppAuth/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteAppAuth(@PathVariable("id") int id){
        try {
            int  res= appAuthService.deleteAppAuth(id);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }


}
