package com.mvc.controller.copy;


import com.mvc.model.*;
import com.mvc.service.copy.TCheckDetailService;
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("/TCheckDetailAction")
@Controller
public class TCheckDetailAction {

    @Autowired
    private TCheckDetailService tCheckDetailService;

    @ApiOperation("根据设备sn查询拷机数据")
    @RequestMapping(value = "/finddata/{deviceSn}/{startTime}/{endTime}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findCopyDatasBySn(@PathVariable("deviceSn") String deviceSn,@PathVariable("startTime") String startTime,@PathVariable("endTime") String endTime){
        try {
            List<TAireadModel> resListt=tCheckDetailService.findCopyDatasBySn(deviceSn,startTime,endTime);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resListt);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("根据ID删除明细")
    @RequestMapping(value = "/deleteTCheckDetail/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object>  deleteTCheckDetail(@PathVariable("id") Integer id) {
        try {
            int res = tCheckDetailService.deleteTCheckDetail(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;
        }
    }

    @ApiOperation("更新拷机明细调用接口")
    @RequestMapping(value = "/updateTCheckDetail",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateTCheckDetail(@RequestBody TCheckDetailModel model){
        try {
            TCheckDetailModel res = tCheckDetailService.updateTCheckDetail(model);
            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 = "/addTCheckDetail",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> addTCheckDetail(@RequestBody TCheckDetailModel model){
        try {
            TCheckDetailModel res = tCheckDetailService.addTCheckDetail(model);
            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;
        }
    }

}
