package com.mvc.controller.taizhang;


import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.WmAccModel;
import com.mvc.service.taizhang.WmAccService;
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("/WmAccAction")
@Controller
public class WmAccAction {

    @Autowired
    private WmAccService WmAccService;

    @ApiOperation("水表台账表分页查询")
    @RequestMapping(value = "/list/{page}/{rows}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findAllWmAcc(@PathVariable("page") Integer page, @PathVariable("rows") Integer rows){

        try {
            Map<String,Object> res= WmAccService.findAllWmAcc(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 = "/saveWmAcc",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveWmAcc(@RequestBody WmAccModel model){

        try {
            WmAccModel resModel= WmAccService.saveWmAcc(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 = "/updateWmAcc",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateWmAcc(@RequestBody WmAccModel model){
        try {
            WmAccModel resModel= WmAccService.updateWmAcc(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 = "/deleteWmAcc/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteWmAcc(@PathVariable("id") int id){
        try {
            int  res= WmAccService.deleteWmAcc(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;
        }
    }
}
