oto餐饮app实时订单物流追踪系统架构设计(一)

时间:2021-11-25 07:47:17

   

1.引言

.1     1.1目的

    不管是淘点点或者饿了么,只要是打算做外卖的app,我觉得没有实时地图展示外卖订单位置信息是说不过去的,因为我觉得外卖对于物流实时性是非常苛刻的。11:00定的外卖在12:00还没有送到用户手中,都是不可原谅的。

   基于此我想设计一个地图实时显示送货员位置信息的系统。

    2.1 功能需求

    该系统主要功能包括:

    1).配送员app登录上线后,接收订单后循环的把自己的位置信息发送给服务器管理

    2).用户客户端在订单经过店家转给配送员后,即可在地图上查看实时位置信息

    3)服务器收到配送员位置信息后根据配送订单信息转发给相应的用户客户端

    4)其他功能。用户app提交提单给web服务器后,web服务器把这条消息推送给订单追踪服务器

    3.1 业务流程设计

   oto餐饮app实时订单物流追踪系统架构设计(一)

  4.1界面设计

     1)店家版

     

oto餐饮app实时订单物流追踪系统架构设计(一)

  2)配送员

  oto餐饮app实时订单物流追踪系统架构设计(一)

oto餐饮app实时订单物流追踪系统架构设计(一)





5)各个模块详细设计和实现

   5.1 用户app请求地理位置

   

public class MyUdpClient extends UDPClientBase {

public MyUdpClient(byte[] uuid, int appid, String serverAddr, int serverPort)
throws Exception {
super(uuid, appid, serverAddr, serverPort);

}

@Override
public boolean hasNetworkConnection() {
return Util.hasNetwork(OnlineService.this);
}


@Override
public void trySystemSleep() {
tryReleaseWakeLock();
}

@Override
public void onPushMessage(Message message) {
if(message == null){
return;
}
else if(message.getData() == null || message.getData().length == 0){
return;
}
else if(message.getCmd() == 16){// 0x10 通用推送信息

}
else if(message.getCmd() == 17){// 0x11 分组推送信息

}
else if(message.getCmd() == 32){// 0x20 自定义推送信息
String str = null;
try{
str = new String(message.getData(),5,message.getContentLength(), "UTF-8");
}catch(Exception e){
str = Util.convert(message.getData(),5,message.getContentLength());
}

//转化成json串 lbs 实时物流追中,
Gson gson = new Gson();
MsgType msgType = gson.fromJson(str,new TypeToken<MsgType>(){}.getType());
if(msgType.equals("wuliu"))
{
//配送员地址位置

}
else if(msgType.equals("order"))
{
//订单确认
}
else
{
notifyUser(32,"自定义推送信息",""+str,"收到自定义推送信息");
}
}
setPkgsInfo();
}

}



百度地图api版本v_3_1,百度定位api版本v_4.2

 

package com.cmyy.ui;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.model.LatLng;
import com.cmyy.R;
import com.cmyy.push.OnlineService;
import com.cmyy.push.Params;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;


//实时物流页面
public class LogisticsTrackingActivity extends BaseActivity{
private static final String LTAG = LogisticsTrackingActivity.class.getSimpleName();
private MapView mMapView;
private BaiduMap mBaiduMap;
private SDKReceiver mReceiver;
// 定位相关
private LocationClient mLocClient;
public MyLocationListenner myListener = new MyLocationListenner(); //定位
boolean isFirstLoc = true;// 是否首次定位

private PushLocationReceiver mPushLocationReceice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 注册 SDK 广播监听者
IntentFilter iFilter = new IntentFilter();
iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
mReceiver = new SDKReceiver();
registerReceiver(mReceiver, iFilter);

setContentView(R.layout.activity_tracking);

//向服务器通知需要物流地理位置了

//注册接受位置信息广播
IntentFilter ipushFilter = new IntentFilter();
ipushFilter.addAction("com.cmyy.ui.LogisticsTrackingActivity.PushLocationReceiver");
mPushLocationReceice = new PushLocationReceiver();
registerReceiver(mPushLocationReceice, ipushFilter);

//启动服务去接收位置
saveAccountInfo();
Intent startSrv = new Intent(this, OnlineService.class);
startSrv.putExtra("CMD", "RESET");
startService(startSrv);
//展示地图
mMapView = (MapView) findViewById(R.id.bmapView);
mBaiduMap = mMapView.getMap();
// 开启定位图层
mBaiduMap.setMyLocationEnabled(true);
// 定位初始化
/*mLocClient = new LocationClient(this);
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);// 打开gps
option.setCoorType("bd09ll"); // 设置坐标类型
option.setScanSpan(1000);
mLocClient.setLocOption(option);
mLocClient.start();*/
}

public class PushLocationReceiver extends BroadcastReceiver {

public PushLocationReceiver() {

}

@Override
public void onReceive(Context context, Intent intent) {
//接收到配送员发送过来的位置信息
String message = intent.getStringExtra("data");
Log.i("receive",message);
Gson gson = new Gson();
MyLocationData locData = gson.fromJson(message,new TypeToken<MyLocationData>(){}.getType());
JSONObject jsonObj;
double latitude = 39.915;
double longitude = 116.404;
try {
jsonObj = new JSONObject(message);
latitude = jsonObj.getDouble("latitude");
longitude= jsonObj.getDouble("longitude");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i("receive",String.valueOf(latitude));
Log.i("receive",String.valueOf(longitude));
mBaiduMap.setMyLocationData(locData);
if (isFirstLoc) {
isFirstLoc = false;
LatLng ll = new LatLng(latitude,
longitude);
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
mBaiduMap.animateMapStatus(u);
}
}

}

/**
* 定位SDK监听函数
*/
public class MyLocationListenner implements BDLocationListener {

@Override
public void onReceiveLocation(BDLocation location) {
// map view 销毁后不在处理新接收的位置
if (location == null || mMapView == null)
return;
MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
// 此处设置开发者获取到的方向信息,顺时针0-360
.direction(100).latitude(location.getLatitude())
.longitude(location.getLongitude()).build();
mBaiduMap.setMyLocationData(locData);
if (isFirstLoc) {
isFirstLoc = false;
LatLng ll = new LatLng(location.getLatitude(),
location.getLongitude());
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
mBaiduMap.animateMapStatus(u);
}
}

public void onReceivePoi(BDLocation poiLocation) {
}
}

/**
* 构造广播监听类,监听 SDK key 验证以及网络异常广播
*/
public class SDKReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String s = intent.getAction();
Log.d(LTAG, "action: " + s);
if (s.equals(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR)) {
Log.e("LogisticsTrackingActivity","key 验证出错! 请在 AndroidManifest.xml 文件中检查 key 设置");
} else if (s.equals(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR)) {
Log.e("LogisticsTrackingActivity","网络出错");
}
}
}

protected void saveAccountInfo(){
SharedPreferences account = this.getSharedPreferences(Params.DEFAULT_PRE_NAME,Context.MODE_PRIVATE);
SharedPreferences.Editor editor = account.edit();
editor.putString(Params.SERVER_IP, "192.168.88.130");
editor.putString(Params.SERVER_PORT, "9966");
editor.putString(Params.PUSH_PORT, "9998");
editor.putString(Params.USER_NAME, "333");
editor.putString(Params.SENT_PKGS, "0");
editor.putString(Params.RECEIVE_PKGS, "0");
editor.commit();
}

@Override
protected void onPause() {
super.onPause();
// activity 暂停时同时暂停地图控件
mMapView.onPause();
}

@Override
protected void onResume() {
super.onResume();
// activity 恢复时同时恢复地图控件
mMapView.onResume();
}

@Override
protected void onDestroy() {
mLocClient.stop();
// 关闭定位图层
mBaiduMap.setMyLocationEnabled(false);
super.onDestroy();
// 取消监听 SDK 广播
unregisterReceiver(mReceiver);
// activity 销毁时同时销毁地图控件
mMapView.onDestroy();
}

}<strong>
</strong>

 


5.2 配送员app发送地理位置信息给追踪服务器

   

  //接受服务器推送信息
saveAccountInfo(); //设置服务器ip 端口
Intent startSrv = new Intent(this, OnlineService.class);
startService(startSrv);

push = new Push(this);
//启动地理位置监控
mBaiduMapControl = new BaiduMapControl();
mBaiduMapControl.Location(getApplicationContext(),new BDLocationListener()
{
@Override
public void onReceiveLocation(BDLocation location) {
MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
// 此处设置开发者获取到的方向信息,顺时针0-360
.direction(100).latitude(location.getLatitude())
.longitude(location.getLongitude()).build();
Gson gson = new Gson();
//地理位置信息
String strLocation = gson.toJson(locData).toString();
Log.i("BaiduLocationApiDem",strLocation);
//Receive Location
/*StringBuffer sb = new StringBuffer(256);
sb.append("time : ");
sb.append(location.getTime()); //定位时间
sb.append("\nerror code : ");
sb.append(location.getLocType());
sb.append("\nlatitude : ");
sb.append(location.getLatitude()); // 开发者获取到的方向信息,顺时针0-360
sb.append("\nlontitude : ");
sb.append(location.getLongitude());
sb.append("\nradius : ");
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation){
sb.append("\nspeed : ");
sb.append(location.getSpeed());
sb.append("\nsatellite : ");
sb.append(location.getSatelliteNumber());
sb.append("\ndirection : ");
sb.append("\naddr : ");
sb.append(location.getAddrStr());
sb.append(location.getDirection());
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
sb.append("\naddr : ");
sb.append(location.getAddrStr());
//运营商信息
sb.append("\noperationers : ");
sb.append(location.getOperators());
}

Log.i("BaiduLocationApiDem", sb.toString());*/
//定位成功发送给服务器
push.send0x20("333", strLocation);

}

});

未完....