package com.mvc.controller.copy;


import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.CertifAccModel;
import com.mvc.service.copy.CertifAccService;
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 = "合格证数据表")
@RequestMapping("/CertifAccAction")
@Controller
public class CertifAccAction {

    @Autowired
    private CertifAccService certifAccService;


    @ApiOperation("新增合格证数据表")
    @RequestMapping(value = "/saveCertifAcc",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveCertifAcc(@RequestBody CertifAccModel model){
        try {
            CertifAccModel resModel= certifAccService.saveCertifAcc(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 = "/updateCertifAcc",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody CertifAccModel model){
        try {
            CertifAccModel resModel= certifAccService.updateCertifAcc(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 = "/deleteCertifAcc/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteCertifAcc(@PathVariable("id") int id){
        try {
            int  res= certifAccService.deleteCertifAcc(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;
        }
    }
}
