Commit 25817e40 by Wyh

Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	component-print/src/main/res/layout/print_dialog_loading.xml
parents da8dbb14 7376ca17
......@@ -38,7 +38,7 @@ import com.gingersoft.gsa.cloud.common.function.FunctionManager;
import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpBean;
import com.gingersoft.gsa.cloud.common.function.jump.ActivityJumpStrategy;
import com.gingersoft.gsa.cloud.common.logan.LoganManager;
import com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService;
import com.gingersoft.gsa.cloud.common.service.DataNotificationService;
import com.gingersoft.gsa.cloud.common.utils.AppDevices;
import com.gingersoft.gsa.cloud.common.utils.JsonUtils;
import com.gingersoft.gsa.cloud.common.utils.StytemUtils;
......@@ -218,24 +218,24 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
}
private void initService() {
// boolean deliveryOrderServiceRunning = StytemUtils.isServiceRunning("com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService", this);
// if (!deliveryOrderServiceRunning) {
// Intent service = new Intent(GsaCloudApplication.getAppContext(), GetInfoUpdateService.class);
// service.putExtra(GetInfoUpdateService.CONNECTION_TYPE, GetInfoUpdateService.mCurrConnectionType);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// startForegroundService(service);
// } else {
// startService(service);
// }
// }
boolean prjServiceRunning = StytemUtils.isServiceRunning("com.joe.print.mvp.print.service.PrjService", this);
if (!prjServiceRunning) {
//開啟Prj打印服務
CC.obtainBuilder(ComponentName.COMPONENT_PRINT)
.setActionName("openPrintService")
.build()
.call();
boolean deliveryOrderServiceRunning = StytemUtils.isServiceRunning("com.gingersoft.gsa.cloud.common.service.DataNotificationService", this);
if (!deliveryOrderServiceRunning) {
Intent service = new Intent(GsaCloudApplication.getAppContext(), DataNotificationService.class);
service.putExtra(DataNotificationService.CONNECTION_TYPE, DataNotificationService.mCurrConnectionType);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(service);
} else {
startService(service);
}
}
// boolean prjServiceRunning = StytemUtils.isServiceRunning("com.joe.print.mvp.print.service.PrjService", this);
// if (!prjServiceRunning) {
// //開啟Prj打印服務
// CC.obtainBuilder(ComponentName.COMPONENT_PRINT)
// .setActionName("openPrintService")
// .build()
// .call();
// }
}
......
......@@ -266,6 +266,7 @@ public abstract class PrinterRoot<T extends PrintContent> implements PrintSocket
*/
private void sunmiPrint(List<Bitmap> bitmaps, PrintListener listener) {
//商米打印
PrinterPlugins.getOnPrinterFlowHandler().connectionSuccess();
AidlUtil.getInstance().printBitmaps(bitmaps, SUNMI_PAPER_WIDTH, new InnerResultCallbcak() {
@Override
public void onRunResult(boolean isSuccess) {
......
......@@ -133,6 +133,7 @@ public class PrjPtinterManager implements ReceiveListener {
* 請求prj數據
*/
public void getPrjInfo() {
LoganManager.w_printer(TAG, "heart ThreadName:"+Thread.currentThread().getName());
OkHttp3Utils.get(HttpsConstans.ROOT_SERVER_ADDRESS_FORMAL + "printerRecording/get?restaurantId=" + RestaurantInfoManager.newInstance().getRestaurantId())
.subscribeOn(Schedulers.io())//切换到io线程進行網絡請求
.observeOn(Schedulers.io())//切換到io线程處理請求結果
......@@ -140,24 +141,24 @@ public class PrjPtinterManager implements ReceiveListener {
@Override
public void onSubscribe(Disposable d) {
LoganManager.w_printer(TAG, "獲取Prj數據 Disposable");
LoganManager.w_printer(TAG, "heart 獲取Prj數據 Disposable");
}
@Override
public void onNext(String prjInfo) {
LoganManager.w_printer(TAG, "獲取Prj數據 onNext: " + prjInfo);
LoganManager.w_printer(TAG, "heart 獲取Prj數據 onNext: " + prjInfo);
//請求到數據,停止輪詢,開始打印,在打印完之後再重新開始輪詢
actionPrint(prjInfo);
}
@Override
public void onError(Throwable e) {
LoganManager.w_printer(TAG, "獲取Prj數據 onError:" + e.getMessage());
LoganManager.w_printer(TAG, "heart 獲取Prj數據 onError:" + e.getMessage());
}
@Override
public void onComplete() {
LoganManager.w_printer(TAG, "獲取Prj數據 onComplete");
LoganManager.w_printer(TAG, "heart 獲取Prj數據 onComplete");
}
});
}
......
......@@ -5,6 +5,7 @@ import android.graphics.Bitmap;
import java.util.Hashtable;
public class BytesUtil {
//字节流转16进制字符串
public static String getHexStringFromBytes(byte[] data) {
if (data == null || data.length <= 0) {
......
<?xml version="1.0" encoding="utf-8"?>
<com.qmuiteam.qmui.layout.QMUILinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/theme_white_color"
android:gravity="center"
android:background="@color/theme_white_color"
android:orientation="vertical">
<com.airbnb.lottie.LottieAnimationView
......@@ -70,7 +69,8 @@
android:layout_marginTop="@dimen/dp_10"
android:textColor="@color/red"
android:textSize="@dimen/font_small"
tools:text="連接打印機超時" />
android:text="連接打印機超時"
android:visibility="invisible"/>
</com.qmuiteam.qmui.layout.QMUILinearLayout>
\ No newline at end of file
......@@ -33,7 +33,7 @@
android:name="design_height_in_dp"
android:value="640"/>
<service
android:name="com.gingersoft.gsa.cloud.common.service.GetInfoUpdateService"
android:name="com.gingersoft.gsa.cloud.common.service.DataNotificationService"
android:enabled="true" />
</application>
</manifest>
......@@ -15,18 +15,23 @@ import android.os.Build
import android.os.IBinder
import android.os.PowerManager
import android.util.Log
import android.view.View
import android.widget.RemoteViews
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import com.billy.cc.core.component.CC
import com.billy.cc.core.component.CCResult
import com.gingersoft.gsa.cloud.common.R
import com.gingersoft.gsa.cloud.common.constans.AppConstans
import com.gingersoft.gsa.cloud.common.constans.HttpsConstans
import com.gingersoft.gsa.cloud.common.constans.PrintConstans
import com.gingersoft.gsa.cloud.common.core.restaurant.RestaurantInfoManager
import com.gingersoft.gsa.cloud.common.core.user.UserContext
import com.gingersoft.gsa.cloud.common.logan.LoganManager
import com.gingersoft.gsa.cloud.common.utils.SoundPoolUtils
import com.gingersoft.gsa.cloud.common.utils.okhttpUtils.OkHttp3Utils
import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils
import com.gingersoft.gsa.cloud.component.ComponentName
import com.google.gson.Gson
import io.reactivex.Observable
import io.reactivex.Observer
......@@ -39,7 +44,7 @@ import org.json.JSONObject
import java.util.*
import java.util.concurrent.TimeUnit
class GetInfoUpdateService : Service() {
class DataNotificationService : Service() {
private val TAG = "heart"
......@@ -61,13 +66,49 @@ class GetInfoUpdateService : Service() {
private val CHANNEL_ID = "cloud_gsa"
private var isCreate = false
/**
* prj數據
*/
private var PRJ_DATA = 10
/**
* prj數據
*/
private var TABLE_DATA = 11
private var NOMAL_NOTIFITY_ID = 456
private var DELIVETY_NOTIFITY_ID = 123
companion object {
@kotlin.jvm.JvmField
var loginfo = StringBuffer()
}
val restaurantId by lazy {
RestaurantInfoManager.newInstance().getRestaurantId()
@kotlin.jvm.JvmField
var CONNECTION_TYPE = "connection_type"
/**
* 开启外送接单长连
*/
@kotlin.jvm.JvmField
var OPEN_DELIVET_ORDER_CONNECTION = 2
/**
* 开启数据接收长连(prj,餐台数据)
*/
@kotlin.jvm.JvmField
var OPEN_OTHER_CONNECTION = 1
/**
* 当前连接类型
*/
@kotlin.jvm.JvmField
var mCurrConnectionType = OPEN_OTHER_CONNECTION
}
override fun onBind(intent: Intent?): IBinder? {
......@@ -88,66 +129,107 @@ class GetInfoUpdateService : Service() {
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
} else {
startNotification()
//获取当前长连类型
mCurrConnectionType = intent!!.getIntExtra(CONNECTION_TYPE, OPEN_DELIVET_ORDER_CONNECTION)
initNotification()
if (isCreate) {
send(mCurrConnectionType)
}
isCreate = true
putTimeLog("啟動服務onStartCommand")
return super.onStartCommand(intent, flags, startId)
}
private fun initNotification() {
if (mCurrConnectionType == OPEN_DELIVET_ORDER_CONNECTION) {
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(DELIVETY_NOTIFITY_ID)
} else {
startNotification(DELIVETY_NOTIFITY_ID)
}
} else {
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(NOMAL_NOTIFITY_ID)
} else {
startNotification(NOMAL_NOTIFITY_ID)
}
}
}
/**
* 创建通知渠道
*/
@RequiresApi(Build.VERSION_CODES.O)
fun createNotificationChannel() {
fun createNotificationChannel(notifiyId: Int) {
if (!UserContext.newInstance().isLogin) {
stopSelf()
return
}
//设定的通知渠道名称
val channelName = "New Order Notification"
var channelName = "Data Notification"
//设置通知的重要程度
val importance = NotificationManager.IMPORTANCE_LOW
//构建通知渠道
val channel = NotificationChannel(CHANNEL_ID, channelName, importance)
channel.description = "New Order Notification"
channel.description = "Data Notification"
//向系统注册通知渠道,注册后不能改变重要性以及其他通知行为
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
notificationManager.cancelAll()
startNotification()
startNotification(notifiyId)
}
@SuppressLint("InflateParams")
private fun startNotification() {
private fun startNotification(notifiyId: Int) {
val broadcastReceiver = Intent(AppConstans.CLEAR_ORDER_RECEIVING_HEART)
val broadcastIntent = PendingIntent.getBroadcast(this, 10, broadcastReceiver, 0)
val remoteViews = RemoteViews(packageName, R.layout.layout_order_receiving)
remoteViews.setOnClickPendingIntent(R.id.btn_stop_service, broadcastIntent)
var intent: Intent? = null
myBind?.jumpActivity?.let {
intent = Intent(this, it)
}
if (intent == null) {
intent = Intent("action.gingersoft.DELIVERY_ORDER")
var remoteViews: RemoteViews
if (notifiyId == DELIVETY_NOTIFITY_ID) {
remoteViews = RemoteViews(packageName, R.layout.notifity_remote_order_receiving)
remoteViews.setOnClickPendingIntent(R.id.btn_stop_service, broadcastIntent)
} else {
remoteViews = RemoteViews(packageName, R.layout.notifity_remote_receive_command)
}
val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
//在创建的通知渠道上发送通知
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
builder.setSmallIcon(R.mipmap.ic_launcher) //设置通知图标
.setContentTitle("Ricepon Pos")//设置通知标题
.setContentText("外賣接單服務")//设置通知内容Takeaway order service
.setContent(remoteViews)
.setContentIntent(pendingIntent)
.setAutoCancel(false) //用户触摸时,自动关闭
.setOngoing(true)//设置处于运行状态
.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
builder.setContentTitle("Ricepon POS")//设置通知标题
builder.setContentText("connection service")//设置通知内容
var pendingIntent: PendingIntent
if (notifiyId == DELIVETY_NOTIFITY_ID) {
var intent: Intent? = null
myBind?.jumpActivity?.let {
intent = Intent(this, it)
}
if (intent == null) {
intent = Intent("action.gingersoft.DELIVERY_ORDER")
}
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
builder.setContentIntent(pendingIntent)
}
builder.setContent(remoteViews)
builder.setAutoCancel(false) //用户触摸时,自动关闭
builder.setOngoing(true)//设置处于运行状态
builder.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
//将服务置于启动状态 NOTIFICATION_ID指的是创建的通知的ID
startForeground(123, builder.build())
startForeground(notifiyId, builder.build())
}
fun restartNotification() {
mCurrConnectionType = OPEN_OTHER_CONNECTION;
//先停止前台服務
stopForeground(true)
// 在API11之后构建Notification的方式
initNotification()
}
inner class MyBind : Binder() {
......@@ -156,14 +238,14 @@ class GetInfoUpdateService : Service() {
set(value) {
field = value
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
createNotificationChannel(DELIVETY_NOTIFITY_ID)
} else {
startNotification()
startNotification(DELIVETY_NOTIFITY_ID)
}
}
fun setOnPostCallBack(postCallBack: PostCallBack?) {
this@GetInfoUpdateService.postCallBack = postCallBack
this@DataNotificationService.postCallBack = postCallBack
}
fun execute(block: (isShow: Boolean) -> Unit) {
......@@ -202,10 +284,9 @@ class GetInfoUpdateService : Service() {
it.newWebSocket(request, object : WebSocketListener() {
override fun onOpen(webSocket: WebSocket, response: Response) {//开启长连接成功的回调
super.onOpen(webSocket, response)
if (!this@GetInfoUpdateService.isDestroy) {
if (!this@DataNotificationService.isDestroy) {
mWebSocket = webSocket
val token = "weixin_" + restaurantId + "_" + getRandomString(24)
webSocket.send(Gson().toJson(MsgBean(1, token)))
send(mCurrConnectionType)
putTimeLog("連接成功")
cancelTimerDisposable()
myBind?.block?.invoke(false)
......@@ -222,6 +303,8 @@ class GetInfoUpdateService : Service() {
if (postCallBack != null) {
postCallBack!!.callBack(type)
}
//收到服务器端传过来的消息text
putTimeLog("收到回調:$text")
//-1斷開連接,
// \n-2:消息傳輸錯誤,
// \n0:連接消息,
......@@ -232,37 +315,40 @@ class GetInfoUpdateService : Service() {
// \n5:歷史訂單通知,
// \n6:修改訂單狀態通知,
// \n7:支付成功通知"
// 10:prj数据
// 11:餐台数据
if (type == 3 || type == 4 || type == 5 || type == 7) {
//播放提示音
initSoundPool(R.raw.newordervocal)
} else if (type == 8) {
initSoundPool(R.raw.raw_logistics_cancel)
} else if (type == PRJ_DATA) {
CC.obtainBuilder(ComponentName.COMPONENT_PRINT)
.setActionName("getPrjData")
.build()
.call()
} else if (type == TABLE_DATA) {
}
//收到服务器端传过来的消息text
Log.e(TAG, "onMessage:$text")
putTimeLog("收到回調:$text")
}
override fun onMessage(webSocket: WebSocket, bytes: ByteString) {
super.onMessage(webSocket, bytes)
val json = JSONObject(bytes.toString())
putTimeLog("onMessage222:$bytes")
if (postCallBack != null) {
postCallBack!!.callBack(json.optInt("type"))
}
Log.e(TAG, "onMessage222:$bytes")
putTimeLog("onMessage222:$bytes")
}
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
super.onClosing(webSocket, code, reason)
//連接斷開,
Log.e(TAG, "onClosing$reason")
putTimeLog("onClosing關閉連接")
}
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
super.onClosed(webSocket, code, reason)
Log.e(TAG, "onClosed")
putTimeLog("onClosed斷開連接")
webSocket.cancel()
}
......@@ -270,7 +356,8 @@ class GetInfoUpdateService : Service() {
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {//长连接连接失败的回调
super.onFailure(webSocket, t, response)
Log.e(TAG, "onFailure " + t.message)
if (!this@GetInfoUpdateService.isDestroy) {
if (!this@DataNotificationService.isDestroy) {
//連接斷開,定時五秒,如果未重連,播放提示音
delayFun({
initSoundPool(R.raw.raw_disconnect)
......@@ -283,6 +370,7 @@ class GetInfoUpdateService : Service() {
webSocket.cancel()
it.dispatcher().cancelAll()
}
}
})
it.dispatcher().executorService().shutdown()
......@@ -290,6 +378,22 @@ class GetInfoUpdateService : Service() {
}, HEART_BEAT_RATE)
}
fun send(currConnectionType: Int) {
val token = "weixin_" + RestaurantInfoManager.newInstance().restaurantId + "_" + UserContext.newInstance().memberId + "_" + getRandomString(24)
LoganManager.w_code(TAG, "token=" + token);
if (mWebSocket != null) {
mWebSocket?.send(Gson().toJson(MsgBean(1, getConnectiontype(), token)))
}
}
private fun getConnectiontype(): String {
var connectiontype = "$OPEN_OTHER_CONNECTION"
if (mCurrConnectionType == OPEN_DELIVET_ORDER_CONNECTION) {
connectiontype = "$OPEN_OTHER_CONNECTION , $OPEN_DELIVET_ORDER_CONNECTION"
}
return connectiontype
}
private var lastSoundTime: Long = 0L
fun initSoundPool(resId: Int) {
val nowTime = System.currentTimeMillis()//當前時間減去上次播放的時間,如果超過五秒,那麼才會再次播放提示聲
......@@ -346,7 +450,7 @@ class GetInfoUpdateService : Service() {
private fun clearHeart() {
val requestBody = FormBody.Builder()
.add("restaurantId", restaurantId.toString())
.add("restaurantId", RestaurantInfoManager.newInstance().restaurantId.toString())
.build()
OkHttp3Utils.post(HttpsConstans.ROOT_URL + "/member-web/api/restaurant/clearHeartbeat", requestBody)
.subscribeOn(Schedulers.io()).subscribe()
......@@ -355,7 +459,9 @@ class GetInfoUpdateService : Service() {
inner class ClearHeartBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
//關閉service,會調用service的onDestroy
stopSelf()
// stopSelf()
restartNotification()
send(mCurrConnectionType)
}
}
......@@ -373,6 +479,7 @@ class GetInfoUpdateService : Service() {
var mIntervalDisposable: Disposable? = null
var timerDisposable: Disposable? = null
/**
* 执行定时任务
*/
......@@ -428,6 +535,6 @@ class GetInfoUpdateService : Service() {
})
}
class MsgBean(var type: Int, var token: String)
class MsgBean(var type: Int, var data: String, var token: String)
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@
android:orientation="vertical">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ricepon pos"
......@@ -29,6 +30,7 @@
android:textSize="@dimen/dp_14" />
<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="@dimen/dp_10">
<ImageView
android:id="@+id/iv_launch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:layout_toEndOf="@id/iv_launch"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ricepon pos"
android:textColor="@color/color_3c"
android:textSize="@dimen/dp_14" />
<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text="connection service"
android:textColor="@color/color_3c"
android:textSize="@dimen/dp_14" />
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
package com.gingersoft.gsa.cloud.pay.pos.hywebpos.bean.request.pos;
import lombok.Data;
/**
* 作者:ELEGANT_BIN
* 版本:1.6.0
* 创建日期:2019-11-15
* 修订历史:2019-11-15
* 描述:
*/
@Data
public class WaitRequest {
private long id;
private String type;
private String orderId;
private String payId;
//支付所需
private String orderXml;
//調整貼士所需
private String TXN_ID = "";
private double tipAmount = 0.0;
//清机所需
private String settlementTime;
//公共字段
private String MachineCode;
private String LoginID;
private String LoginName;
private String SessionID;
private String Station_id;
private String ShopID;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment