package com.mvc.controller.dic;

import com.mvc.model.CorrectMap;
import com.mvc.model.DicChkplatModel;
import com.mvc.model.ErrorMap;
import com.mvc.service.dic.DicChkplatService;
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("/DicChkplatAction")
@Controller
public class DicChkplatAction {

    @Autowired
    private DicChkplatService dicChkplatService;


    @ApiOperation("分页查询工装列表")
    @RequestMapping(value = "/list/{page}/{rows}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findAllDicChkplat(@PathVariable("page") Integer page, @PathVariable("rows") Integer rows){
        try {
            Map<String,Object> res= dicChkplatService.findAllDicChkplat(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("新增工装")
    @RequestMapping(value = "/saveDicChkplat",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveDicChkplat(@RequestBody DicChkplatModel model){
        try {
            DicChkplatModel resModel= dicChkplatService.saveDicChkplat(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 = "/updateDicChkplat",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody DicChkplatModel model){
        try {
            DicChkplatModel resModel= dicChkplatService.updateDicChkplat(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 = "/deleteDicChkplat/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteDicChkplat(@PathVariable("id") int id){
        try {
            int  res= dicChkplatService.deleteDicChkplat(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;
        }
    }
}
