package com.mvc.controller.copy;


import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.TChkrptDetailModel;
import com.mvc.model.TChkrptModel;
import com.mvc.service.copy.TChkrptService;
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("/TChkrptAction")
@Controller
public class TChkrptAction {
    @Autowired
    private TChkrptService tChkrptService;

    @ApiOperation("拷机报告分页查询")
    @RequestMapping(value = "/findAllTChkrpt",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findAllTChkrpt(@RequestBody TChkrptModel model){
        try {
            Map<String,Object> res= tChkrptService.findAllTChkrpt(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("根据chkrptId查报告明细")
    @RequestMapping(value = "/findByChkrptId/{chkrptId}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findByChkrptId(@PathVariable("chkrptId") String chkrptId){

        try {
            List<TChkrptDetailModel> res= tChkrptService.findByChkrptId(chkrptId);
            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 = "/saveTChkrpt",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveTChkrpt(@RequestBody TChkrptModel model){

        try {
            TChkrptModel resModel= tChkrptService.saveTChkrpt(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 = "/updateTChkrpt",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateTChkrpt(@RequestBody TChkrptModel model){
        try {
            TChkrptModel resModel= tChkrptService.updateTChkrpt(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 = "/deleteTChkrpt/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteTChkrpt(@PathVariable("id") int id){
        try {
            int  res= tChkrptService.deleteTChkrpt(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 = "/generateTChkrpt/{checkId}/{userName}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> generateTChkrpt(@PathVariable("checkId") String checkId,@PathVariable("userName") String userName){
        try {
            TChkrptModel res= tChkrptService.generateTChkrpt(checkId,userName,false);
            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;
        }
    }
}
