package com.mvc.controller.dic;

import com.mvc.model.*;
import com.mvc.service.dic.DicMarkTypeService;
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;

@Api(tags = "标记类型字典控制类")
@RequestMapping("/DicMarkTypeAction")
@Controller
public class DicMarkTypeAction {

    @Autowired
    private DicMarkTypeService dicMarkTypeService;

    @ApiOperation("查询所有标记类型字典表")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public ResultModel findAllDicMarkType(){
        ResultModel resultModel;
        try {
            List<DicMarkTypeModel> resList = dicMarkTypeService.findAllDicMarkType();
            resultModel=new ResultModel(resList);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("新增标记类型字典记录")
    @RequestMapping(value = "/saveDicMarkType",method = RequestMethod.POST)
    @ResponseBody
    public ResultModel saveDicMarkType(@RequestBody DicMarkTypeModel model){
        ResultModel resultModel;
        try {
            DicMarkTypeModel resModel= dicMarkTypeService.saveDicMarkType(model);
            resultModel=new ResultModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("更新标记类型字典记录")
    @RequestMapping(value = "/updateDicMarkType",method = RequestMethod.POST)
    @ResponseBody
    public ResultModel updateDeviceAcc(@RequestBody DicMarkTypeModel model){
        ResultModel resultModel;
        try {
            DicMarkTypeModel resModel= dicMarkTypeService.updateDicMarkType(model);
            resultModel=new ResultModel(resModel);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
        }
        return resultModel;
    }

    @ApiOperation("删除标记类型字典记录")
    @RequestMapping(value = "/deleteDicMarkType/{id}",method = RequestMethod.GET)
    @ResponseBody
    public ResultModel deleteDicMarkType(@PathVariable("id") int id){
        ResultModel resultModel;
        try {
            int  res= dicMarkTypeService.deleteDicMarkType(id);
            resultModel=new ResultModel(res);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel=new ResultModel(e.getMessage());
        }
        return resultModel;
    }
}
