package com.mvc.controller.ysfx;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.ysfx.DicWaterTypeModel;
import com.mvc.service.ysfx.DicWaterTypeService;
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("/DicWaterTypeAction")
@Controller
public class DicWaterTypeAction {

    @Autowired
    private DicWaterTypeService dicWaterTypeService;

    @ApiOperation("查询所有用水类型字典")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findAllDicWaterType(){

        try {
            List<DicWaterTypeModel> resList = dicWaterTypeService.findAllDicWaterType();
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resList);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("新增用水类型字典")
    @RequestMapping(value = "/saveDicWaterType",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveDicWaterType(@RequestBody DicWaterTypeModel model){
        try {
            DicWaterTypeModel resModel= dicWaterTypeService.saveDicWaterType(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 = "/updateDicWaterType",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody DicWaterTypeModel model){
        try {
            DicWaterTypeModel resModel= dicWaterTypeService.updateDicWaterType(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 = "/deleteDicWaterType/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteDicWaterType(@PathVariable("id") int id){
        try {
            int  res= dicWaterTypeService.deleteDicWaterType(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;
        }
    }
}
