package org.cs.ws.user.ctl;

import java.util.Map;

import org.cs.constants.Constants;
import org.cs.core.ctl.BaseCtl;
import org.cs.mgr.product.model.MgmIntentOrder;
import org.cs.mgr.product.service.IMgmIntentOrderService;
import org.cs.mgr.user.service.IMgmUserService;
import org.cs.ws.inteceptor.Valid;
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.ResponseBody;

import com.alibaba.fastjson.JSONObject;
@Controller
@RequestMapping("/rest/order")
public class OrderApi extends BaseCtl{
	@Autowired
	private IMgmIntentOrderService mgmIntentOrderService;
	@Autowired
	private IMgmUserService mgmUserService;
	/**
	 * 
	 * <p>buyNow</p>
	 * @return
	 * @throws Exception 
	 */
	@Valid(tk=false)
	@RequestMapping("remoteadd")
	@ResponseBody
	public String remoteAdd(String data, ModelMap mm){
		try{
			Map<String, String> map = getMapFromJson(data);
			System.out.println(map);
			Map<String,Object> user = mgmUserService.getUserByCode(map.get("jobNumber"));
			
			if(user == null){
				return JSONObject.toJSONString(getJson(0, "", "用戶不存在"), features);
			}
			System.out.println(user.get("jobNumber"));
			JSONObject object = this.mgmIntentOrderService.addMgmIntentOrderFromApp(map, user);
			Integer data1 = Integer.parseInt(object.get("data").toString());

			return JSONObject.toJSONString(getJson(1, data1, "意向购买提交成功"), features);
		}catch(Exception e){
			e.printStackTrace();
			return JSONObject.toJSONString(getJson(0, "", "意向购买提交失败"), features);
		}
	}
}
