Commit 2da52ed5 by Wyh

4.25 接單已完成

parent c9784e1c
......@@ -8,9 +8,9 @@ import okhttp3.FormBody
class WeatherRepository private constructor(private val network: CoolWeatherNetwork) {
suspend fun requestOrderList(status: String, type: String, page: String, orderNo: String, phone: String) = withContext(Dispatchers.IO) {
suspend fun requestOrderList(restaurantId: String, status: String, type: String, page: String, orderNo: String, phone: String) = withContext(Dispatchers.IO) {
val requestBody = FormBody.Builder()
.add("restaurantId", "26")
.add("restaurantId", restaurantId)
.add("page", page)
.add("status", status)
.add("orderNo", orderNo)
......@@ -21,9 +21,9 @@ class WeatherRepository private constructor(private val network: CoolWeatherNetw
heWeather
}
suspend fun updateRestOpenStatus(state: Boolean) = withContext(Dispatchers.IO) {
suspend fun updateRestOpenStatus(state: Boolean,restaurantId: String) = withContext(Dispatchers.IO) {
val requestBody = FormBody.Builder()
.add("restId", "26")
.add("restId", restaurantId)
.add("openStatus", if (state) "1" else "2")
.build()
val data = network.updateRestOpenStatus(requestBody)
......
package com.gingersoft.gsa.other_order_mode.model.viewModel
import android.content.Context
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
import com.gingersoft.gsa.cloud.print.bean.OrderDetails
import com.gingersoft.gsa.other_order_mode.data.HistoryOrderRepository
import com.gingersoft.gsa.other_order_mode.data.model.bean.HistoryOrderBean
......@@ -14,7 +16,7 @@ class HistoryOrderViewModel(private val historyOrderRepository: HistoryOrderRepo
/**
* 根據訂單id獲取訂單詳細信息
*/
fun getHistoryOrderList(pageIndex: String, orderNum: String = "", listener: (HistoryOrderBean) -> Unit) {
fun getHistoryOrderList(context: Context, pageIndex: String, orderNum: String = "", listener: (HistoryOrderBean) -> Unit) {
launch({
var phone = ""
var orderNumber = ""
......@@ -24,7 +26,7 @@ class HistoryOrderViewModel(private val historyOrderRepository: HistoryOrderRepo
orderNumber = orderNum
}
historyOrderRepository.getHistoryOrderList("26", "4", pageIndex, "10", orderNumber, phone).apply {
historyOrderRepository.getHistoryOrderList(GsaCloudApplication.getRestaurantId(context).toString(), "4", pageIndex, "10", orderNumber, phone).apply {
this.getData()?.let {
if (it.size > 0) {
it.removeAt(it.size - 1)
......
......@@ -12,6 +12,7 @@ import androidx.lifecycle.viewModelScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.billy.cc.core.component.CC
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils
import com.gingersoft.gsa.cloud.base.widget.DialogUtils
......@@ -50,9 +51,9 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
/**
* 獲取訂單信息
*/
fun getOrderList(position: Int, page: String, isLoadMore: Boolean, listener: (String) -> Unit) {
fun getOrderList(context: Context, position: Int, page: String, isLoadMore: Boolean, listener: (String) -> Unit) {
launch({
repository.requestOrderList(fragmentStatus[position], fragmentType[position], page, orderNo, phone).apply {
repository.requestOrderList(GsaCloudApplication.getRestaurantId(context).toString(), fragmentStatus[position], fragmentType[position], page, orderNo, phone).apply {
loadInfo(listener, isLoadMore, position)
}
}, {
......@@ -76,12 +77,14 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
} else {
otherInfo.value = myData[myData.size - 1]
}
//移除掉最後一個對象
myData.removeAt(myData.size - 1)
//如果是加載更多
Log.e("eee", "加載更多$isLoadMore")
if (isLoadMore) {
if (mOrderList[position].value != null) {
mOrderList[position].value!!.addAll(myData)
} else {
mOrderList[position].value = myData
mOrderList[position].postValue(mOrderList[position].value)
}
} else {
mOrderList[position].value = myData
......@@ -103,7 +106,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
launch({
Log.e("eee", "點擊狀態$state")
if (state) {
updateRestOpenStatus(state)
updateRestOpenStatus(state, context)
} else {
//暫停接單,彈窗向用戶確認是否關閉
object : DialogUtils(context, R.layout.other_order_pause_orders) {
......@@ -111,7 +114,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
hepler.getView<TextView>(R.id.tv_dialog_confirm).setOnClickListener {
it.isClickable = false
launch({
updateRestOpenStatus(state).let {
updateRestOpenStatus(state, context).let {
dialog.dismiss()
}
}, {
......@@ -132,8 +135,8 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
/**
* 修改餐廳營業狀態
*/
suspend fun updateRestOpenStatus(state: Boolean) {
repository.updateRestOpenStatus(state).apply {
suspend fun updateRestOpenStatus(state: Boolean, context: Context) {
repository.updateRestOpenStatus(state, GsaCloudApplication.getRestaurantId(context).toString()).apply {
if (isSuccess()) {
restaurantState.value = state
}
......@@ -190,6 +193,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
override fun initLayout(hepler: ViewHepler, dialog: Dialog) {
hepler.setText(R.id.tv_warning_title, "是否確認結賬?")
hepler.getView<TextView>(R.id.tv_dialog_confirm).setOnClickListener {
dialog.dismiss()
launch({
updateOrderStatus(data.Id.toString(), "", status, "", "", isPush, data.order_type).apply {
listener.invoke(success)
......@@ -237,7 +241,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}
} else {
// 自取的確認訂單
repository.updateSelfOrderStatus(data.Id.toString(), status.toString(), "26").apply {
repository.updateSelfOrderStatus(data.Id.toString(), status.toString(), GsaCloudApplication.getRestaurantId(context).toString()).apply {
listener.invoke(success)
}
}
......@@ -310,9 +314,9 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
/**
* 獲取配送員信息
*/
fun getDeliveryInfo() {
fun getDeliveryInfo(context: Context) {
launch({
repository.getDeliveryInfo("26", "329").apply {
repository.getDeliveryInfo(GsaCloudApplication.getRestaurantId(context).toString(), GsaCloudApplication.getMemberId(context).toString()).apply {
deliveryBean = this
}
}, {
......
......@@ -17,14 +17,13 @@ import java.util.concurrent.TimeUnit
class GetInfoUpdateService : Service() {
private val TAG = "eee"
/**
* 心跳检测时间
*/
private val HEART_BEAT_RATE = (15 * 1000).toLong()//每隔15秒进行一次对长连接的心跳检测
private val WEBSOCKET_HOST_AND_PORT = "https://hktest.ricepon.com:64377/ricepon-websocket/js/webSocketServer"//可替换为自己的主机名和端口号
private var mWebSocket: WebSocket? = null
private val sendMsg = "{\"type\":1,\"token\":\"weixin_26_7xjmv0geea1111111111\"}"
var postCallBack: PostCallBack? = null
override fun onBind(intent: Intent?): IBinder? {
......@@ -32,12 +31,10 @@ class GetInfoUpdateService : Service() {
return MyBind()
}
interface PostCallBack {
fun callBack(type: Int)
}
inner class MyBind : Binder() {
fun getService(): GetInfoUpdateService {
return this@GetInfoUpdateService
......@@ -72,11 +69,13 @@ class GetInfoUpdateService : Service() {
client.newWebSocket(request, object : WebSocketListener() {
override fun onOpen(webSocket: WebSocket?, response: Response?) {//开启长连接成功的回调
super.onOpen(webSocket, response)
if (!this@GetInfoUpdateService.isDestroy) {
mWebSocket = webSocket
val token = "weixin_" + GsaCloudApplication.getRestaurantId(this@GetInfoUpdateService) + "_" + getRandomString(24)
Log.e("eee", "token:$token")
Log.e(TAG, "token:$token")
webSocket!!.send(Gson().toJson(MsgBean(1, token)))
}
}
override fun onMessage(webSocket: WebSocket?, text: String?) {//接收消息的回调
super.onMessage(webSocket, text)
......@@ -85,7 +84,7 @@ class GetInfoUpdateService : Service() {
postCallBack!!.callBack(json.optInt("type"))
}
//收到服务器端传过来的消息text
Log.e("aaa", "onMessage:" + text!!)
Log.e(TAG, "onMessage:" + text!!)
}
override fun onMessage(webSocket: WebSocket?, bytes: ByteString?) {
......@@ -94,25 +93,32 @@ class GetInfoUpdateService : Service() {
if (postCallBack != null) {
postCallBack!!.callBack(json.optInt("type"))
}
Log.e("aaa", "onMessage222:" + bytes!!)
Log.e(TAG, "onMessage222:" + bytes!!)
}
override fun onClosing(webSocket: WebSocket?, code: Int, reason: String?) {
super.onClosing(webSocket, code, reason)
//連接斷開,
Log.e("aaa", "onClosing")
InitSocketThread().start()//创建一个新的连接
Log.e(TAG, "onClosing")
// InitSocketThread().start()//创建一个新的连接
}
override fun onClosed(webSocket: WebSocket?, code: Int, reason: String?) {
super.onClosed(webSocket, code, reason)
Log.e("aaa", "onClosed")
Log.e(TAG, "onClosed")
webSocket?.cancel()
}
override fun onFailure(webSocket: WebSocket?, t: Throwable?, response: Response?) {//长连接连接失败的回调
super.onFailure(webSocket, t, response)
Log.e("aaa", "onFailure" + t!!.message)
InitSocketThread().start()//创建一个新的连接
Log.e(TAG, "onFailure" + t!!.message)
if (!this@GetInfoUpdateService.isDestroy) {
Log.e(TAG, "沒銷毀")
initSocket()//创建一个新的连接
} else {
webSocket?.cancel()
client.dispatcher().cancelAll()
}
}
})
client.dispatcher().executorService().shutdown()
......@@ -140,7 +146,7 @@ class GetInfoUpdateService : Service() {
if (!isDestroy) {
if (System.currentTimeMillis() - sendTime >= HEART_BEAT_RATE) {
val isSuccess = mWebSocket?.send("0")//发送一个空消息给服务器,通过发送消息的成功失败来判断长连接的连接状态
Log.e("aaa", "連接狀態:$isSuccess")
Log.e(TAG, "連接狀態:$isSuccess")
if (isSuccess != null && !isSuccess) {//长连接已断开
mHandler.removeCallbacks(this)
mWebSocket?.cancel()//取消掉以前的长连接
......@@ -159,7 +165,7 @@ class GetInfoUpdateService : Service() {
override fun onDestroy() {
super.onDestroy()
Log.e("aaa", "onDestroy")
Log.e(TAG, "onDestroy")
isDestroy = true
if (mWebSocket != null) {
mWebSocket!!.send("-1")
......
......@@ -31,7 +31,7 @@ class HistoryOrderActivity : BaseActivity() {
private fun getHistoryInfo(page: Int = pageIndex, orderNum: String = "") {
showLoading()
mViewModel.getHistoryOrderList(page.toString(), orderNum) {
mViewModel.getHistoryOrderList(this, page.toString(), orderNum) {
cancelDialogForLoading()
refresh_layout.setEnableLoadMore(it.getData() != null)
refresh_layout.finishRefresh()
......
......@@ -19,6 +19,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.viewpager.widget.ViewPager
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils
import com.gingersoft.gsa.cloud.ui.view.SwitchButton
import com.gingersoft.gsa.other_order_mode.R
......@@ -76,7 +77,7 @@ class OtherOrderActivity : BaseActivity() {
layout_today_order_info.post {
layoutHeight = layout_today_order_info.height.toFloat()
}
pageViewModel.getDeliveryInfo()
pageViewModel.getDeliveryInfo(this)
}
......@@ -141,7 +142,7 @@ class OtherOrderActivity : BaseActivity() {
//搜索
if (ed_order_num_search.text != null && ed_order_num_search.text.isNotEmpty()) {
pageViewModel.phone = ed_order_num_search.text.toString()
pageViewModel.getOrderList(viewPager.currentItem, "0", false) {}
pageViewModel.getOrderList(this, viewPager.currentItem, "0", false) {}
} else {
ToastUtils.show(this@OtherOrderActivity, "請輸入手機號或訂單號")
}
......@@ -169,6 +170,12 @@ class OtherOrderActivity : BaseActivity() {
//開啟websocket
val intent = Intent(this, GetInfoUpdateService::class.java)
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)
}
override fun onDestroy() {
super.onDestroy()
unbindService(serviceConnection)
}
private var serviceConnection = object : ServiceConnection {
......
......@@ -40,9 +40,11 @@ class PlaceholderFragment : BaseFragment() {
//如果當前fragment的狀態中包含需要刷新的狀態,獲取數據
Log.e("eee", "$it,當前fragment的" + PageViewModel.fragmentStatus[arguments?.getInt(INDEX)!!])
// if (PageViewModel.fragmentStatus[arguments?.getInt(INDEX)!!].contains(it.toString())) {
page = 1
getOrderList(this, false)
// }
})
}
// 初始化recyclerview
......@@ -74,6 +76,7 @@ class PlaceholderFragment : BaseFragment() {
}
// 綁定當前fragment的數據項
pageViewModel.mOrderList[arguments?.getInt(INDEX)!!].observe(viewLifecycleOwner, Observer {
Log.e("eee", "刷新數據")
it.let { adapter.setData(it) }
})
......@@ -91,7 +94,7 @@ class PlaceholderFragment : BaseFragment() {
}
private fun refresh() {
page = 0
page = 1
pageViewModel.orderNo = ""
pageViewModel.phone = ""
getOrderList(pageViewModel, false)
......@@ -102,7 +105,8 @@ class PlaceholderFragment : BaseFragment() {
}
private fun getOrderList(pageViewModel: PageViewModel, isLoadMore: Boolean) {
pageViewModel.getOrderList(arguments?.getInt(INDEX) ?: 0, page.toString(), isLoadMore) {
pageViewModel.getOrderList(activity!!, arguments?.getInt(INDEX)
?: 0, page.toString(), isLoadMore) {
refresh_layout.finishRefresh()
refresh_layout.finishLoadMore()
}
......
......@@ -168,7 +168,7 @@ public class PrintOtherOrder extends PrinterRoot {
tvOrderNum.setText("訂單號:" + dataBean.getORDER_NO());
rvFood.setLayoutManager(new LinearLayoutManager(context));
rvFood.setAdapter(new OtherOrderAdapter(context, orderDetail));
rvFood.setAdapter(new OtherOrderAdapter(context, orderDetail, false));
return viewToBitmap(context, view);
}
......@@ -209,7 +209,7 @@ public class PrintOtherOrder extends PrinterRoot {
if (data.getPRODUCT_NAME() != null) {
RecyclerView rvFoodList = view.findViewById(R.id.rv_order_print_food);
rvFoodList.setLayoutManager(new LinearLayoutManager(context));
rvFoodList.setAdapter(new OtherOrderAdapter(context, data.getPRODUCT_NAME()));
rvFoodList.setAdapter(new OtherOrderAdapter(context, data.getPRODUCT_NAME(), true));
}
return viewToBitmap(context, view);
}
......
......@@ -22,11 +22,12 @@ import static com.qmuiteam.qmui.util.QMUIDisplayHelper.dp2px;
public class OtherOrderAdapter extends BaseQuickAdapter<OrderDetails.DataBean.PRODUCTNAMEBean, BaseViewHolder> {
private Context context;
private int indentation;
private boolean isShowPrice;
public OtherOrderAdapter(Context context, @Nullable List<OrderDetails.DataBean.PRODUCTNAMEBean> data) {
public OtherOrderAdapter(Context context, @Nullable List<OrderDetails.DataBean.PRODUCTNAMEBean> data, boolean isShowPrice) {
super(R.layout.print_other_order_food_item, data);
this.context = context;
this.isShowPrice = isShowPrice;
}
@Override
......@@ -34,6 +35,7 @@ public class OtherOrderAdapter extends BaseQuickAdapter<OrderDetails.DataBean.PR
helper.setText(R.id.tv_food_name, item.getPRODUCT_NAME());
helper.setText(R.id.tv_food_number, item.getNum());
helper.setText(R.id.tv_food_price, item.getPRICE());
helper.getView(R.id.tv_food_price).setVisibility(isShowPrice ? View.VISIBLE : View.GONE);
if (helper.getAdapterPosition() == 0) {
indentation = new BigDecimal(((TextView) helper.getView(R.id.tv_food_name)).getPaint().measureText("哈")).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}
......
package com.gingersoft.gsa.cloud.base.utils;
import android.text.TextUtils;
import android.util.SparseArray;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.database.bean.FoodCombo;
import com.gingersoft.gsa.cloud.database.bean.Modifier;
import com.gingersoft.gsa.cloud.database.utils.FoodComboDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 作者:ELEGANT_BIN
......
......@@ -303,7 +303,6 @@ public class SwitchButton extends CompoundButton {
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Log.e("eee", "onSizeChanged");
if (w != oldw || h != oldh) {
setup();
}
......@@ -447,8 +446,6 @@ public class SwitchButton extends CompoundButton {
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
Log.e("eee", "drawableStateChanged");
if (!mIsThumbUseDrawable && mThumbColor != null) {
mCurrThumbColor = mThumbColor.getColorForState(getDrawableState(), mCurrThumbColor);
} else {
......@@ -482,8 +479,6 @@ public class SwitchButton extends CompoundButton {
//
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.e("eee", "onTouchEvent");
if (!isEnabled() || !isClickable()) {
return false;
}
......@@ -561,7 +556,6 @@ public class SwitchButton extends CompoundButton {
@Override
public boolean performClick() {
Log.e("eee", "performClick" + !getStatusBasedOnPos());
// return super.performClick();
// animateToState(!getStatusBasedOnPos());
if (onClickListener != null) {
......@@ -608,7 +602,6 @@ public class SwitchButton extends CompoundButton {
@Override
public void setChecked(final boolean checked) {
Log.e("eee", "setChecked");
// animate before super.setChecked() become user may call setChecked again in OnCheckedChangedListener
if (isChecked() != checked) {
animateToState(checked);
......@@ -659,7 +652,6 @@ public class SwitchButton extends CompoundButton {
@Override
public void setOnCheckedChangeListener(OnCheckedChangeListener onCheckedChangeListener) {
super.setOnCheckedChangeListener(onCheckedChangeListener);
Log.e("eee", "setOnCheckedChangeListener");
mChildOnCheckedChangeListener = onCheckedChangeListener;
}
......
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