oto餐饮app实时推送订单给店家程序详细实现(二)

时间:2022-10-10 17:56:35

   文接"oto餐饮app实时订单追踪系统架构设计"一文。

    用户生成一个外卖订单后,可以以发短信的方式告知店家有一个订单,但是短信方式的缺点是非常明显的,如果想让用户和网站知道店家接受订单和其他的操作就需要网站人工干预,这在智能手机没有出来之前,那些外卖网站这样运营是可以理解的,但是智能手机都出来这么多年了,现在的有些外卖网站还是这么运营我是难以理解。上次我用“饿了么”下一个外卖订单,订单下了后,饿了么客服立马打电话过来确认订单,我不知道是否确认后他们客服再打电话给店家通知订单。我对这样的体验也是非常不满意的,不满意这样的流程而不是服务。

      有点扯远了。

     5.2.1 用户app提交订单业务逻辑层:

  oto餐饮app实时推送订单给店家程序详细实现(二)

				order.setHowmuch(total);
order.setMenu(menuList);
order.setOrderType(0x001); //代表的是外卖订单
order.setPayType(0x002); //支付宝网上支付
order.setUser_id(1/*Integer.parseInt(mApplication.getmUser().getId())*/);
//把订单发送出去
OrderServer orderServer = new OrderServer();
orderServer.dealOrder(order,new AsyncHttpResponseHandler(){
@Override
public void onSuccess(String response) {
if(!response.equals("0"))
{
Log.i("TakeawayCommitActivity","提交订单成功 " + response);
startActivity(new Intent(TakeawayCommitActivity.this,PaySuccessActivity.class));
finish();
}
}
@Override
public void onFailure(Throwable error, String content) {

}
});

网络通信层

package com.cmyy.httpServer;
import com.cmyy.model.Order;
import com.cmyy.util.HttpUtil;
import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;

//订单表操作
public class OrderServer {
//生成订单
public void dealOrder(Order order,AsyncHttpResponseHandler responseHandler)
{
Gson gSon = new Gson();
String json = gSon.toJson(order);
String postUrl=HttpUtil.ORDER_ACTION;
AsyncHttpClient orderRequest = new AsyncHttpClient();
//orderRequest.post(postUrl,responseHandler);
RequestParams prarms = new RequestParams();
prarms.put("req", json);
orderRequest.post(postUrl, prarms, responseHandler);
}
}

通信协议模型

订单

package com.cmyy.model;

import java.util.ArrayList;


//订单列表
public class Order {

private double howmuch; //消费金额
private ArrayList<CommitMenu> menu; //消费的菜品
private Bussiness bussiness;//商家
private String checkCode; //验证码
private int orderType; //订单类型 订单分为3中类型:1.外卖 2.预订 3.团定
private int payType; //付款类型 付款类型分为:1.支付宝 2.网银 3.饭到付款
private int user_id; //用户id

public int getUser_id() {
return user_id;
}
public void setUser_id(int user_id) {
this.user_id = user_id;
}
public int getOrderType() {
return orderType;
}
public void setOrderType(int orderType) {
this.orderType = orderType;
}
public int getPayType() {
return payType;
}
public void setPayType(int payType) {
this.payType = payType;
}
public Bussiness getBussiness() {
return bussiness;
}
public void setBussiness(Bussiness bussiness) {
this.bussiness = bussiness;
}
public String getCheckCode() {
return checkCode;
}
public void setCheckCode(String checkCode) {
this.checkCode = checkCode;
}
public double getHowmuch() {
return howmuch;
}
public void setHowmuch(double howmuch) {
this.howmuch = howmuch;
}
public ArrayList<CommitMenu> getMenu() {
return menu;
}
public void setMenu(ArrayList<CommitMenu> menu) {
this.menu = menu;
}

}
菜单
package com.cmyy.model;import java.io.Serializable;//餐单列表public class Menu implements Serializable{	     private static final long serialVersionUID = 1L;	     // Fields		private Integer id;		private String caiName;		private String decsrible;		private String imagesPath;		private Integer commentCount;		private Integer bussinessId;		private Integer count;		private Integer categorizeId;		private Integer price;		private String imagesPath3;		private String imagesPath5;		private String imagesPath4;		private String imagesPath2;		private String imagesPath1;		private String categorize;		// Constructors		public String getCategorize() {			return categorize;		}		public void setCategorize(String categorize) {			this.categorize = categorize;		}		/** default constructor */		public Menu() {		}		/** minimal constructor */		public Menu(Integer id) {			this.id = id;		}		/** full constructor */		public Menu(Integer id, String caiName, String decsrible,				String imagesPath, Integer commentCount, Integer bussinessId,				Integer count, Integer categorizeId, Integer price,				String imagesPath3, String imagesPath5, String imagesPath4,				String imagesPath2, String imagesPath1) {			this.id = id;			this.caiName = caiName;			this.decsrible = decsrible;			this.imagesPath = imagesPath;			this.commentCount = commentCount;			this.bussinessId = bussinessId;			this.count = count;			this.categorizeId = categorizeId;			this.price = price;			this.imagesPath3 = imagesPath3;			this.imagesPath5 = imagesPath5;			this.imagesPath4 = imagesPath4;			this.imagesPath2 = imagesPath2;			this.imagesPath1 = imagesPath1;		}		// Property accessors		public Integer getId() {			return this.id;		}		public void setId(Integer id) {			this.id = id;		}		public String getCaiName() {			return this.caiName;		}		public void setCaiName(String caiName) {			this.caiName = caiName;		}		public String getDecsrible() {			return this.decsrible;		}		public void setDecsrible(String decsrible) {			this.decsrible = decsrible;		}		public String getImagesPath() {			return this.imagesPath;		}		public void setImagesPath(String imagesPath) {			this.imagesPath = imagesPath;		}		public Integer getCommentCount() {			return this.commentCount;		}		public void setCommentCount(Integer commentCount) {			this.commentCount = commentCount;		}		public Integer getBussinessId() {			return this.bussinessId;		}		public void setBussinessId(Integer bussinessId) {			this.bussinessId = bussinessId;		}		public Integer getCount() {			return this.count;		}		public void setCount(Integer count) {			this.count = count;		}		public Integer getCategorizeId() {			return this.categorizeId;		}		public void setCategorizeId(Integer categorizeId) {			this.categorizeId = categorizeId;		}		public Integer getPrice() {			return this.price;		}		public void setPrice(Integer price) {			this.price = price;		}		public String getImagesPath3() {			return this.imagesPath3;		}		public void setImagesPath3(String imagesPath3) {			this.imagesPath3 = imagesPath3;		}		public String getImagesPath5() {			return this.imagesPath5;		}		public void setImagesPath5(String imagesPath5) {			this.imagesPath5 = imagesPath5;		}		public String getImagesPath4() {			return this.imagesPath4;		}		public void setImagesPath4(String imagesPath4) {			this.imagesPath4 = imagesPath4;		}		public String getImagesPath2() {			return this.imagesPath2;		}		public void setImagesPath2(String imagesPath2) {			this.imagesPath2 = imagesPath2;		}		public String getImagesPath1() {			return this.imagesPath1;		}		public void setImagesPath1(String imagesPath1) {			this.imagesPath1 = imagesPath1;		}}

  oto餐饮app实时推送订单给店家程序详细实现(二)

5.2.2 web服务端接收订单

       web服务端接收订单,生成订单序列号,写入数据库保存,并将该订单必要信息转发给店家app

       web 服务器采用j2ee ssh框架。本来电子商务类网站用php应该好一点吧。

      

package cmyy.web.action.user;

import java.io.IOException;

import org.apache.struts2.ServletActionContext;
import org.ddpush.im.util.StringUtil;
import org.ddpush.im.v1.client.appserver.Pusher;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import cmyy.domain.bussiness.BussinessOrder;
import cmyy.domain.bussiness.Order;
import cmyy.utils.MD5Utils;
import cmyy.web.action.base.BaseAction;
import javax.servlet.http.HttpServletRequest;
//订单提交
public class OrderAction extends BaseAction{
private HttpServletRequest req ;
public void orderSubmit()
{
req = ServletActionContext.getRequest();
Gson gSon = new Gson();
Order order = gSon.fromJson(req.getParameter("req"), new TypeToken<Order>(){}.getType());
//转发给追踪服务器去推送给相应的店家
byte[] bussinessId = null;
try {
bussinessId = StringUtil.md5Byte(String.valueOf(order.getBussiness().getId()));
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} //店家id
Pusher pusher = null;
BussinessOrder bussinessOrder = new BussinessOrder();
bussinessOrder.setOrder_uuid("dajldahgiahlajl");

try {
//推送服务器ip地址可以放到配置文件中,这里暂时写定值
pusher = new Pusher("127.0.0.1",9999, 1000*5);
boolean result = pusher.push0x20Message(bussinessId,gSon.toJson(bussinessOrder).getBytes());
if(result){
System.out.println("通用信息发送成功");
}else{
System.out.println("发送失败!格式有误");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

//生成订单号信息
try {
outPrint(req.getParameter("req"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}



   5.2.3 推送服务器接收订单并转发


  5.2.4 店家app接收订单

oto餐饮app实时推送订单给店家程序详细实现(二)