package org.cs.mgr.user.ctl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

import org.cs.core.ctl.BaseCtl;
import org.cs.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.cs.mgr.user.service.IMgmCustomerService;
import org.cs.util.Pager;
import org.cs.mgr.user.model.MgmCustomer;
import org.cs.util.StringUtil;
import com.alibaba.fastjson.JSONObject;


/**
 * 
 * @ClassName: MgmCustomer 
 * @Description:  
 * @author: sunny_shi
 * @date: 2018-06-09 13:28:56
 */
@Controller
@RequestMapping("/rest/mgmCustomer")
public class MgmCustomerApi extends BaseCtl {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private IMgmCustomerService mgmCustomerService;
	
	
	@ResponseBody
	@RequestMapping(value="addCustomer", method = RequestMethod.POST)	
	public String addCustomer(String data,ModelMap mm){		
		Map<String, String> map = getMapFromJson(data);
		logger.info("map::" + map);
		JSONObject json = new JSONObject();		
		json=mgmCustomerService.addMgmCustomer(map);
		//mm.put("json", JSONObject.toJSONString(json, features));
		return JSONObject.toJSONString(json, features);
	}

	@ResponseBody
	@RequestMapping(value="updateCustomer", method = RequestMethod.POST)	
	public String updateCustomer(String data,ModelMap mm){		
		Map<String, String> map = getMapFromJson(data);
		System.out.println("map::" + map);
		JSONObject json = new JSONObject();		
		json=mgmCustomerService.updateMgmCustomer(map);
		//mm.put("json", JSONObject.toJSONString(json, features));
		return JSONObject.toJSONString(json, features);
	}
		
	@RequestMapping("del")
	public String del(Integer id){
		if(id != null){
			this.mgmCustomerService.delMgmCustomer(id);
		}
		return AJAX_SUCCESS;
	}
	
	@ResponseBody
	@RequestMapping(value="deleteCustomer", method = RequestMethod.POST)	
	public String deleteCustomer(String data,ModelMap mm){		
		Map<String, String> map = getMapFromJson(data);
		System.out.println("map::" + map);
		JSONObject json = new JSONObject();		
		json=mgmCustomerService.deleteMgmCustomer(map);
		//mm.put("json", JSONObject.toJSONString(json, features));
		return JSONObject.toJSONString(json, features);
	}
	
	
	
		
}

