package com.mvc.controller.taizhang;

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

        @Autowired
        private TCustomrService tCustomrService;

        @ApiOperation("客户管理表分页查询")
        @RequestMapping(value = "/list/{page}/{rows}",method = RequestMethod.GET)
        @ResponseBody
        public Map<String,Object> findAllTCustomr(@PathVariable("page") Integer page, @PathVariable("rows") Integer rows){

        try {
            Map<String,Object> res= tCustomrService.findAllTCustomr(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 = "/saveTCustomr",method = RequestMethod.POST)
        @ResponseBody
        public Map<String,Object> saveTCustomr(@RequestBody TCustomrModel model){

        try {
            TCustomrModel resModel= tCustomrService.saveTCustomr(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 = "/updateTCustomr",method = RequestMethod.POST)
        @ResponseBody
        public Map<String,Object> updateTCustomr(@RequestBody TCustomrModel model){
        try {
            TCustomrModel resModel= tCustomrService.updateTCustomr(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 = "/deleteTCustomr/{id}",method = RequestMethod.GET)
        @ResponseBody
        public Map<String,Object> deleteTCustomr(@PathVariable("id") int id){
        try {
            int  res= tCustomrService.deleteTCustomr(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;
        }
    }

}
