package com.mvc.controller;

import com.mvc.model.TUsingunitGroupModel;
import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.service.TUsingunitGroupService;
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("/TUsingunitGroupAction")
@Controller
public class TUsingunitGroupAction {

    @Autowired
    private TUsingunitGroupService tUsingunitGroupService;

    @ApiOperation("分页查询使用单位分组表")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findAllTUsingunitGroup(@RequestBody TUsingunitGroupModel model){
        try {
            List<TUsingunitGroupModel> res= tUsingunitGroupService.findAllTUsingunitGroup(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 = "/saveTUsingunitGroup",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveTUsingunitGroup(@RequestBody TUsingunitGroupModel model){
        try {
            TUsingunitGroupModel resModel= tUsingunitGroupService.saveTUsingunitGroup(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 = "/updateTUsingunitGroup",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody TUsingunitGroupModel model){
        try {
            TUsingunitGroupModel resModel= tUsingunitGroupService.updateTUsingunitGroup(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 = "/deleteTUsingunitGroup/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteTUsingunitGroup(@PathVariable("id") int id){
        try {
            int  res= tUsingunitGroupService.deleteTUsingunitGroup(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;
        }
    }
}
