package com.mvc.controller.copy;

import com.mvc.model.CorrectMap;
import com.mvc.model.TServerReadModel;
import com.mvc.model.ErrorMap;
import com.mvc.service.copy.TServerReadService;
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.List;
import java.util.Map;

@Api(tags = "服务器侧识别读数表")
@RequestMapping("/TServerReadAction")
@Controller
public class TServerReadAction {

    @Autowired
    private TServerReadService tServerReadService;


    @ApiOperation("查询服务器侧识别读数表")
    @RequestMapping(value = "/list/{aiReadid}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findAllTServerRead(String aiReadid){
        try {
            List<TServerReadModel> res= tServerReadService.findTServerReadByAiReadid(aiReadid);
            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("新增服务器侧识别读数记录")
    @RequestMapping(value = "/saveTServerRead",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveTServerRead(@RequestBody TServerReadModel model){
        try {
            TServerReadModel resModel= tServerReadService.saveTServerRead(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("更新服务器侧识别读数")
    @RequestMapping(value = "/updateTServerRead",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody TServerReadModel model){
        try {
            TServerReadModel resModel= tServerReadService.updateTServerRead(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("删除服务器侧识别读数记录")
    @RequestMapping(value = "/deleteTServerRead/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteTServerRead(@PathVariable("id") int id){
        try {
            int  res= tServerReadService.deleteTServerRead(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;
        }
    }
}
