1633 lines
76 KiB
Java
1633 lines
76 KiB
Java
package com.bonus.canteen.activity;
|
||
|
||
import android.annotation.SuppressLint;
|
||
import android.app.AlertDialog;
|
||
import android.content.BroadcastReceiver;
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.content.IntentFilter;
|
||
import android.graphics.Paint;
|
||
import android.graphics.RectF;
|
||
import android.media.MediaRouter;
|
||
import android.os.Build;
|
||
import android.os.Bundle;
|
||
import android.os.Handler;
|
||
import android.provider.Settings;
|
||
import android.util.DisplayMetrics;
|
||
import android.util.Log;
|
||
import android.view.Display;
|
||
import android.view.LayoutInflater;
|
||
import android.view.MenuItem;
|
||
import android.view.MotionEvent;
|
||
import android.view.View;
|
||
import android.view.WindowManager;
|
||
import android.view.inputmethod.InputMethodManager;
|
||
import android.widget.Button;
|
||
import android.widget.EditText;
|
||
import android.widget.GridView;
|
||
import android.widget.ImageView;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.ListView;
|
||
import android.widget.PopupWindow;
|
||
import android.widget.ProgressBar;
|
||
import android.widget.TextView;
|
||
|
||
import androidx.annotation.NonNull;
|
||
import androidx.appcompat.widget.Toolbar;
|
||
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.alibaba.fastjson2.JSON;
|
||
import com.bonus.canteen.activity.order.MachineSaleActivity;
|
||
import com.bonus.canteen.activity.setting.SettingsActivity;
|
||
import com.bonus.canteen.adapter.menu.DishListAdapter;
|
||
import com.bonus.canteen.adapter.menu.SalesMenuAdapter;
|
||
import com.bonus.canteen.adapter.menu.entity.DishEntity;
|
||
import com.bonus.canteen.adapter.menu.entity.IssueRecipeCompressVO;
|
||
import com.bonus.canteen.adapter.menu.entity.IssueRecipeDetailCompressVO;
|
||
import com.bonus.canteen.adapter.menu.entity.IssueRecipeIntervalCompressVO;
|
||
import com.bonus.canteen.adapter.menu.entity.IssueRecipeMealCompressVO;
|
||
import com.bonus.canteen.adapter.menu.entity.MenuDishesTypeAllVO;
|
||
import com.bonus.canteen.adapter.menu.entity.SalesMenuEntity;
|
||
import com.bonus.canteen.core.BaseActivity;
|
||
import com.bonus.canteen.db.AppDatabase;
|
||
import com.bonus.canteen.db.entity.base.BusinessDataInfo;
|
||
import com.bonus.canteen.db.entity.base.CookBookInfo;
|
||
import com.bonus.canteen.db.entity.base.CookMeetDetailInfo;
|
||
import com.bonus.canteen.db.entity.base.CookMeetMealInfo;
|
||
import com.bonus.canteen.db.entity.base.CookMeetTimesInfo;
|
||
import com.bonus.canteen.db.entity.base.CustPhotoFulInfo;
|
||
import com.bonus.canteen.db.entity.base.DeviceInfo;
|
||
import com.bonus.canteen.db.entity.base.LoginInfo;
|
||
import com.bonus.canteen.db.entity.base.OfflineOrderInfo;
|
||
import com.bonus.canteen.db.entity.base.OrderDetailsInfo;
|
||
import com.bonus.canteen.db.entity.base.UserInfo;
|
||
import com.bonus.canteen.entity.OrderDetailPayDTO;
|
||
import com.bonus.canteen.entity.OrderPayAndroidDTO;
|
||
import com.bonus.canteen.presentation.SecondPresentation;
|
||
import com.bonus.canteen.service.data.HeartbeatService;
|
||
import com.bonus.canteen.service.upload.UpLoadDataService;
|
||
import com.bonus.canteen.utils.DateTimeHelper;
|
||
import com.bonus.canteen.utils.GlideUtil;
|
||
import com.bonus.canteen.utils.MyLog;
|
||
import com.bonus.canteen.utils.OkHttpService;
|
||
import com.bonus.canteen.utils.SimplePopupWindow;
|
||
import com.bonus.canteen.utils.StringHelper;
|
||
import com.bonus.canteen.utils.ThreadPoolManager;
|
||
import com.bonus.canteen.utils.UrlConfig;
|
||
import com.bonus.canteen.utils.WorkConfig;
|
||
import com.bonus.canteen.utils.sound.Sound;
|
||
import com.bonus.canteen.utils.sound.SoundManager;
|
||
import com.ccb.facedevice.sdk.RecognizeCallback;
|
||
import com.ccb.facedevice.sdk.data.ScanResult;
|
||
import com.ccb.facedevice.sdk.utils.AppUtil;
|
||
import com.ccb.facedevice.sdk.utils.FaceScanUtil;
|
||
import com.ccb.facedevice.sdk.utils.NetworkUtils;
|
||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||
import com.google.gson.Gson;
|
||
import com.xuexiang.xui.XUI;
|
||
import com.xuexiang.xui.utils.WidgetUtils;
|
||
import com.xuexiang.xui.utils.XToastUtils;
|
||
import com.xuexiang.xui.widget.dialog.DialogLoader;
|
||
import com.xuexiang.xutil.XUtil;
|
||
import com.xuexiang.xutil.common.ClickUtils;
|
||
|
||
import org.easydarwin.easypusher.R;
|
||
import org.easydarwin.easypusher.databinding.ActivityCanteenOperationBinding;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.math.RoundingMode;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.ArrayList;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.HashSet;
|
||
import java.util.LinkedHashSet;
|
||
import java.util.List;
|
||
import java.util.Locale;
|
||
import java.util.Map;
|
||
import java.util.Objects;
|
||
import java.util.Set;
|
||
|
||
import cn.hutool.core.util.ObjectUtil;
|
||
import okhttp3.MediaType;
|
||
import okhttp3.Request;
|
||
import okhttp3.RequestBody;
|
||
|
||
public class OperationActivity extends BaseActivity<ActivityCanteenOperationBinding> implements BottomNavigationView.OnNavigationItemSelectedListener,
|
||
ClickUtils.OnClick2ExitListener, Toolbar.OnMenuItemClickListener {
|
||
|
||
private static final String TAG = "OperationActivity";
|
||
|
||
private SecondPresentation myPresentation;
|
||
|
||
public OkHttpService service = new OkHttpService();
|
||
//补价金额
|
||
private StringBuilder premiumAmount = new StringBuilder();
|
||
|
||
private SalesMenuAdapter mSalesMenuAdapter;
|
||
|
||
private DishListAdapter mDishListAdapter;
|
||
|
||
private List<SalesMenuEntity> salesMenuEntityList = new ArrayList<>();
|
||
private List<DishEntity> dishEntityList = new ArrayList<>();
|
||
|
||
private ListView salesListView;
|
||
private GridView dishListView;
|
||
AlertDialog alertDialog, pickUpYourMealDialog, loginDialog, balanceDialog, balanceResultDialog;
|
||
|
||
private Handler mHandler;
|
||
private TextView timeShow;
|
||
private View decorView = null;
|
||
private PopupWindow mPopupWindow = null;
|
||
|
||
@Override
|
||
protected ActivityCanteenOperationBinding viewBindingInflate(LayoutInflater inflater) {
|
||
return ActivityCanteenOperationBinding.inflate(inflater);
|
||
}
|
||
|
||
@Override
|
||
protected void onCreate(Bundle savedInstanceState) {
|
||
super.onCreate(savedInstanceState);
|
||
XUI.initTheme(this);
|
||
setupImmersiveMode();
|
||
initViews();
|
||
initData();
|
||
initListeners();
|
||
showPresentation();
|
||
// 启动服务
|
||
startService(new Intent(this, HeartbeatService.class));
|
||
//判断是否存在当天订单
|
||
ThreadPoolManager.getExecutor().execute(() -> {
|
||
BusinessDataInfo businessDataInfo = AppDatabase.getDatabase(this).businessDataDao().getBusinessDataInfoByDate(DateTimeHelper.getNowDate());
|
||
if (businessDataInfo == null) {
|
||
//获取当前餐次
|
||
CookMeetTimesInfo cookMeetTimesInfo = AppDatabase.getDatabase(this).cookMeetTimesDao().getDefaultCookMeetTime();
|
||
if (cookMeetTimesInfo != null) {
|
||
AppDatabase.getDatabase(this).businessDataDao().insert(new BusinessDataInfo(DateTimeHelper.getNowDate(), "0", "0", "0", "0", "0", "0", cookMeetTimesInfo.getIntervalId()));
|
||
}
|
||
}
|
||
LoginInfo loginInfo = AppDatabase.getDatabase(this).loginInfoDao().getLoginInfoOne();
|
||
if (loginInfo != null) {
|
||
binding.loginName.setText(loginInfo.getUserName());
|
||
}
|
||
});
|
||
// 调用自定义方法获取屏幕分辨率
|
||
int[] resolution = getScreenResolution();
|
||
int widthPixels = resolution[0];
|
||
int heightPixels = resolution[1];
|
||
|
||
// 将获取到的屏幕分辨率数据输出到Logcat中,便于调试
|
||
Log.d(TAG, "resolutionText 屏幕宽度:" + widthPixels + " 像素");
|
||
Log.d(TAG, "resolutionText 屏幕高度:" + heightPixels + " 像素");
|
||
|
||
// 显示屏幕分辨率在TextView上
|
||
String resolutionText = "屏幕分辨率:\n宽度:" + widthPixels + " 像素\n高度:" + heightPixels + " 像素";
|
||
Log.d(TAG, "resolutionText: " + resolutionText);
|
||
|
||
|
||
startService(new Intent(this, UpLoadDataService.class));
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取当前设备的屏幕分辨率
|
||
*
|
||
* @return 返回一个包含宽度与高度的整型数组,[0]为宽度,[1]为高度(单位:像素)
|
||
*/
|
||
private int[] getScreenResolution() {
|
||
// 定义DisplayMetrics对象,用于接收屏幕尺寸及密度信息
|
||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||
|
||
// 通过系统服务获取WindowManager对象
|
||
// getSystemService()方法返回一个Object,需要进行类型转换为WindowManager
|
||
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
||
|
||
if (windowManager != null) {
|
||
// 通过getDefaultDisplay()获取当前屏幕的Display对象
|
||
// 再调用getMetrics()方法将当前屏幕参数写入displayMetrics对象中
|
||
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
|
||
} else {
|
||
// 若WindowManager为空,则打印日志并返回默认值
|
||
Log.e(TAG, "无法获取WindowManager服务,返回默认分辨率 0x0");
|
||
return new int[]{0, 0};
|
||
}
|
||
|
||
// 从DisplayMetrics对象中提取屏幕宽度与高度(单位:像素)
|
||
int widthPixels = displayMetrics.widthPixels;
|
||
int heightPixels = displayMetrics.heightPixels;
|
||
|
||
// 返回屏幕分辨率数据
|
||
return new int[]{widthPixels, heightPixels};
|
||
}
|
||
|
||
private void setupImmersiveMode() {
|
||
decorView = getWindow().getDecorView();
|
||
int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
|
||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||
}
|
||
decorView.setSystemUiVisibility(flags);
|
||
}
|
||
|
||
/**
|
||
* 组合支付数据
|
||
*
|
||
* @param nuClearMode 0:记账 1:刷卡 2:刷脸 3:扫码 4:补扣
|
||
* orderType 订单类型 1 当餐 2 预订餐 3 报餐 4 商城 11 设备 12 自助餐 21 补扣 22 外部订单
|
||
* consumMode 消费模式 1:手动 2:定额 3:类别 4:当面付
|
||
* ifOnline 在线状态 1:在线 2:离线
|
||
* payType 支付方式 1:账户支付 2:现金支付 10:支付宝扫码 20:微信扫码
|
||
*/
|
||
public void combineData(int nuClearMode, String carryGinseng, Long userId) {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.paying));
|
||
UserInfo userInfo = AppDatabase.getDatabase(this).userDao().getUserInfoById(userId + "");
|
||
// 判断账户信息
|
||
if (judgeAccInfo(userInfo)) return;
|
||
BigDecimal balance = userInfo.getPersonalWalletBalance() != null && userInfo.getSubsidiesBalance() != null
|
||
? new BigDecimal(userInfo.getPersonalWalletBalance()).add(new BigDecimal(userInfo.getSubsidiesBalance()))
|
||
: BigDecimal.ZERO;
|
||
BigDecimal payAmount = binding.salesAmountDue.getText() != null && !binding.salesAmountDue.getText().toString().isEmpty()
|
||
? new BigDecimal(binding.salesAmountDue.getText().toString())
|
||
: BigDecimal.ZERO;
|
||
CookMeetTimesInfo cookMeetTimesInfo = AppDatabase.getDatabase(this).cookMeetTimesDao().getDefaultCookMeetTime();
|
||
if (cookMeetTimesInfo == null) {
|
||
runOnUiThread(() -> {
|
||
XToastUtils.error("请在餐次内进行支付");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.not_time));
|
||
});
|
||
return;
|
||
}
|
||
if (balance.compareTo(payAmount) < 0) {
|
||
closePayWay();
|
||
runOnUiThread(() -> {
|
||
XToastUtils.warning("账户余额不足,请充值");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.please_recharge));
|
||
});
|
||
} else {
|
||
List<OrderPayAndroidDTO> orderList = new ArrayList<>();
|
||
List<OrderDetailsInfo> orderDetailsInfoList = new ArrayList<>();
|
||
//获取所有餐单数据
|
||
String orderId = System.currentTimeMillis() + AppUtil.getSn(this);
|
||
BigDecimal num = getOrderData(nuClearMode, orderList, orderId, orderDetailsInfoList);
|
||
//调用后台支付接口
|
||
try {
|
||
JSONObject json = new JSONObject();
|
||
json.put("payableAmount", new BigDecimal(binding.salesDiscountAmount.getText().toString()).multiply(new BigDecimal(100)).setScale(0, RoundingMode.DOWN));
|
||
json.put("realAmount", new BigDecimal(binding.salesAmountDue.getText().toString()).multiply(new BigDecimal(100)).setScale(0, RoundingMode.DOWN));
|
||
json.put("userId", userId);
|
||
json.put("placeDate", DateTimeHelper.getNowDate());
|
||
json.put("sourceType", 20);
|
||
json.put("payType", 1);
|
||
json.put("orderList", orderList);
|
||
String jsonString = json.toString();
|
||
// 定义 JSON 的 MediaType
|
||
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||
DeviceInfo deviceInfo = AppDatabase.getDatabase(this).deviceInfoDao().getDeviceInfoOne();
|
||
String deviceNum = "";
|
||
String tenantId = "";
|
||
if (deviceInfo == null) {
|
||
runOnUiThread(() -> XToastUtils.error("设备信息异常!"));
|
||
} else {
|
||
deviceNum = StringHelper.isEmptyAndNull(deviceInfo.getDeviceNum()) ? "" : deviceInfo.getDeviceNum();
|
||
tenantId = StringHelper.isEmptyAndNull(deviceInfo.getTenantId()) ? "" : deviceInfo.getTenantId();
|
||
}
|
||
// 创建 RequestBody
|
||
RequestBody body = RequestBody.create(JSON, jsonString);
|
||
String url = WorkConfig.getBaseUrl() + UrlConfig.PLACE_AND_PAY;
|
||
Request request = new Request.Builder().url(url)
|
||
.addHeader("machine-sn", Objects.requireNonNull(AppUtil.getSn(this)))
|
||
.addHeader("machine-num", deviceNum)
|
||
.addHeader("MERCHANT-ID", tenantId)
|
||
.addHeader("source-type", "20")
|
||
.post(body).build();
|
||
|
||
//存储本地
|
||
OfflineOrderInfo offlineOrderInfo = new OfflineOrderInfo();
|
||
offlineOrderInfo.setOrderId(orderId);
|
||
offlineOrderInfo.setOrderTime(DateTimeHelper.getTime());
|
||
offlineOrderInfo.setSource("消费机");
|
||
offlineOrderInfo.setUserId(String.valueOf(userId));
|
||
offlineOrderInfo.setUserName(AppDatabase.getDatabase(this).userDao().getUserInfoById(String.valueOf(userId)).getUserName());
|
||
offlineOrderInfo.setAmountDue(new BigDecimal(binding.salesAmountDue.getText().toString()).multiply(new BigDecimal(100)) + "");
|
||
offlineOrderInfo.setDiscountAmount(new BigDecimal(binding.salesDiscountAmount.getText().toString()).multiply(new BigDecimal(100)) + "");
|
||
offlineOrderInfo.setNum(num + "");
|
||
offlineOrderInfo.setIsOnline("0");
|
||
offlineOrderInfo.setPayStatus("1");
|
||
offlineOrderInfo.setIntervalId(cookMeetTimesInfo.getIntervalId());
|
||
offlineOrderInfo.setJsonStr(jsonString);
|
||
BusinessDataInfo businessDataInfo = AppDatabase.getDatabase(this).businessDataDao().getBusinessDataInfoByDate(DateTimeHelper.getNowDate());
|
||
|
||
if (!String.valueOf(businessDataInfo.getIsClear()).equals(cookMeetTimesInfo.getIntervalId())) {
|
||
ThreadPoolManager.getExecutor().execute(() -> {
|
||
businessDataInfo.setCurrentOrderNum(1);
|
||
businessDataInfo.setCurrentMoney(binding.salesAmountDue.getText().toString());
|
||
businessDataInfo.setIsClear(Integer.parseInt(cookMeetTimesInfo.getIntervalId()));
|
||
});
|
||
} else {
|
||
businessDataInfo.setCurrentMoney(new BigDecimal(binding.salesAmountDue.getText().toString()).add(new BigDecimal(businessDataInfo.getCurrentMoney())) + "");
|
||
businessDataInfo.setCurrentOrderNum(businessDataInfo.getCurrentOrderNum() + 1);
|
||
}
|
||
try {
|
||
AppDatabase.getDatabase(this).offlineOrderDao().insert(offlineOrderInfo);
|
||
for (OrderDetailsInfo orderDetailsInfo : orderDetailsInfoList) {
|
||
AppDatabase.getDatabase(this).orderDetailsDao().insert(orderDetailsInfo);
|
||
}
|
||
} catch (Exception e) {
|
||
Log.d(TAG, "combineData: " + e.getMessage());
|
||
XToastUtils.error("存储本地订单失败!");
|
||
return;
|
||
}
|
||
|
||
boolean isConnected = NetworkUtils.isNetworkConnected(this);
|
||
|
||
businessDataInfo.setTodayMoney(new BigDecimal(binding.salesAmountDue.getText().toString()).add(new BigDecimal(businessDataInfo.getTodayMoney())) + "");
|
||
businessDataInfo.setTodayOrderNum(businessDataInfo.getTodayOrderNum() + 1);
|
||
|
||
if (isConnected) {
|
||
//请求后台
|
||
String result = service.httpPost(url, body, OperationActivity.this, request);
|
||
if (!StringHelper.isEmptyAndNull(result)) {
|
||
JSONObject firstJson = JSONObject.parseObject(result);
|
||
String code = firstJson.getString("code");
|
||
//添加当天金额和当餐金额
|
||
if (code.equals("200")) {
|
||
ThreadPoolManager.getExecutor().execute(() -> {
|
||
AppDatabase.getDatabase(this).businessDataDao().update(businessDataInfo);
|
||
AppDatabase.getDatabase(this).offlineOrderDao().updateIsOnline("1", orderId);
|
||
});
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.pay_success_new));
|
||
runOnUiThread(() -> XToastUtils.success("支付成功"));
|
||
closePayWay();
|
||
runOnUiThread(() -> {
|
||
salesMenuEntityList.clear();
|
||
setViewData(salesMenuEntityList, false);
|
||
mSalesMenuAdapter.notifyDataSetChanged();
|
||
});
|
||
} else {
|
||
runOnUiThread(() -> {
|
||
XToastUtils.error(firstJson.getString("msg"));
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.pay_fail));
|
||
closePayWay();
|
||
});
|
||
}
|
||
} else {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.pay_fail));
|
||
runOnUiThread(() -> XToastUtils.error("支付出错"));
|
||
closePayWay();
|
||
}
|
||
} else {
|
||
businessDataInfo.setOfflineMoney(new BigDecimal(binding.salesAmountDue.getText().toString()).add(new BigDecimal(businessDataInfo.getOfflineMoney())) + "");
|
||
businessDataInfo.setOfflineOrderNum(businessDataInfo.getOfflineOrderNum() + 1);
|
||
ThreadPoolManager.getExecutor().execute(() -> {
|
||
closePayWay();
|
||
AppDatabase.getDatabase(this).businessDataDao().update(businessDataInfo);
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.pay_success_new));
|
||
runOnUiThread(() -> {
|
||
salesMenuEntityList.clear();
|
||
setViewData(salesMenuEntityList, false);
|
||
mSalesMenuAdapter.notifyDataSetChanged();
|
||
XToastUtils.success("支付成功");
|
||
});
|
||
});
|
||
}
|
||
} catch (Exception e) {
|
||
Log.e(TAG, "支付出错:" + e.getMessage());
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.pay_fail));
|
||
closePayWay();
|
||
runOnUiThread(() -> XToastUtils.error("支付出错"));
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/**
|
||
* 判断账户信息
|
||
*
|
||
* @param userInfo
|
||
* @return
|
||
*/
|
||
private boolean judgeAccInfo(UserInfo userInfo) {
|
||
if (StringHelper.isEmptyAndNull(userInfo.getAccStatus())) {
|
||
runOnUiThread(() -> {
|
||
XToastUtils.warning("账户状态异常!!!");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.account_abnormality));
|
||
});
|
||
closePayWay();
|
||
return true;
|
||
} else if (!userInfo.getAccStatus().equals("0")) {
|
||
if ("2".equals(userInfo.getAccStatus())) {
|
||
runOnUiThread(() -> {
|
||
XToastUtils.warning("此账户已被冻结!!!");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.account_freeze));
|
||
});
|
||
} else {
|
||
runOnUiThread(() -> {
|
||
XToastUtils.warning("账户状态异常!!!");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.account_abnormality));
|
||
});
|
||
}
|
||
closePayWay();
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
private BigDecimal getOrderData(int identityVerification, List<
|
||
OrderPayAndroidDTO> orderList, String
|
||
orderId, List<OrderDetailsInfo> orderDetailsInfoList) {
|
||
int num = 0;
|
||
DeviceInfo deviceInfo = AppDatabase.getDatabase(this).deviceInfoDao().getDeviceInfoOne();
|
||
//获取当前餐次
|
||
CookMeetTimesInfo cookMeetTimesInfo = AppDatabase.getDatabase(this).cookMeetTimesDao().getDefaultCookMeetTime();
|
||
OrderPayAndroidDTO orderPayAndroidDTO = new OrderPayAndroidDTO();
|
||
orderPayAndroidDTO.setCanteenId(deviceInfo.getCanteenId());
|
||
orderPayAndroidDTO.setCanteenName(deviceInfo.getCanteenName());
|
||
orderPayAndroidDTO.setStallId(deviceInfo.getStallId());
|
||
orderPayAndroidDTO.setStallName(deviceInfo.getStallName());
|
||
orderPayAndroidDTO.setDeviceSn(AppUtil.getSn(this));
|
||
orderPayAndroidDTO.setDeviceNum(deviceInfo.getDeviceNum());
|
||
orderPayAndroidDTO.setDeviceOrderId(orderId);
|
||
orderPayAndroidDTO.setOrderType("11"); //双屏机11 超市4
|
||
orderPayAndroidDTO.setIdentityVerification(identityVerification + "");
|
||
orderPayAndroidDTO.setMealtimeName(cookMeetTimesInfo.getIntervalName());
|
||
orderPayAndroidDTO.setMealtimeType(Integer.valueOf(cookMeetTimesInfo.getIntervalId()));
|
||
orderPayAndroidDTO.setOrderDate(DateTimeHelper.getNowDate());
|
||
|
||
List<OrderDetailPayDTO> orderDetailList = new ArrayList<>();
|
||
for (SalesMenuEntity bean : salesMenuEntityList) {
|
||
boolean isKeyBoard = "-1".equals(bean.getId());
|
||
num = num + bean.getNum().intValue();
|
||
CookMeetMealInfo cookMeetMealInfo = AppDatabase.getDatabase(this).cookMeetMealDao().getCookMeetMealById(bean.getId());
|
||
CookMeetDetailInfo cookMeetDetailInfo = AppDatabase.getDatabase(this).cookMeetDetailDao().getCookMeetDetailByDishIdAndMealTypeId(bean.getId(), cookMeetTimesInfo.getIntervalId());
|
||
OrderDetailPayDTO orderDetailPayDTO = new OrderDetailPayDTO();
|
||
orderDetailPayDTO.setDetailType(isKeyBoard ? 4 : 1);
|
||
orderDetailPayDTO.setGoodsId(isKeyBoard ? "-1" : cookMeetMealInfo.getDishesId());
|
||
orderDetailPayDTO.setGoodsName(isKeyBoard ? "按键金额" : cookMeetMealInfo.getProductName());
|
||
orderDetailPayDTO.setGoodsImgUrl("");
|
||
orderDetailPayDTO.setMealtimeName(cookMeetTimesInfo.getIntervalName());
|
||
orderDetailPayDTO.setMealtimeType(Integer.valueOf(cookMeetTimesInfo.getIntervalId()));
|
||
orderDetailPayDTO.setMenuDetailId(isKeyBoard ? -1 : Long.parseLong(cookMeetDetailInfo.getDetailId()));
|
||
orderDetailPayDTO.setMenuId(Long.valueOf(deviceInfo.getRecipeId()));
|
||
orderDetailPayDTO.setOrderDate(DateTimeHelper.getNowDate());
|
||
orderDetailPayDTO.setOrderType(1);
|
||
orderDetailPayDTO.setFinalPrice(isKeyBoard ? bean.getPrice().multiply(new BigDecimal(100)) : new BigDecimal(cookMeetDetailInfo.getPrefPrice()));
|
||
orderDetailPayDTO.setDiscountPrice(isKeyBoard ? BigDecimal.ZERO : new BigDecimal(cookMeetDetailInfo.getSalePrice()).subtract(new BigDecimal(cookMeetDetailInfo.getPrefPrice())));
|
||
orderDetailPayDTO.setQuantity(bean.getNum().intValue());
|
||
orderDetailPayDTO.setSalePrice(isKeyBoard ? bean.getPrice().multiply(new BigDecimal(100)) : new BigDecimal(cookMeetDetailInfo.getSalePrice()));
|
||
orderDetailPayDTO.setSalesMode(1);
|
||
orderDetailList.add(orderDetailPayDTO);
|
||
OrderDetailsInfo orderDetailsInfo = new OrderDetailsInfo();
|
||
orderDetailsInfo.setOrderId(orderId);
|
||
orderDetailsInfo.setGoodsDishesName(isKeyBoard ? "按键金额" : cookMeetMealInfo.getProductName());
|
||
orderDetailsInfo.setNum(String.valueOf(bean.getNum()));
|
||
orderDetailsInfo.setPrice(String.valueOf(bean.getPrice()));
|
||
orderDetailsInfo.setSubTotal(String.valueOf(bean.getSubtotal()));
|
||
orderDetailsInfoList.add(orderDetailsInfo);
|
||
}
|
||
orderPayAndroidDTO.setOrderDetailList(orderDetailList);
|
||
orderList.add(orderPayAndroidDTO);
|
||
return new BigDecimal(num);
|
||
}
|
||
|
||
public void openScan(String type) {
|
||
//开启扫码
|
||
FaceScanUtil.startQrcodeScan(OperationActivity.this, new RecognizeCallback() {
|
||
@Override
|
||
public void onPreView(byte[] data, int width, int height, RectF rect) {
|
||
}
|
||
|
||
@Override
|
||
public void onRecognized(ScanResult scanResult) {
|
||
// xnzn{"s":1,"y":3,"p":"380247805614100480","t":"1743065252277"} --- 小牛扫码信息
|
||
//组合数据
|
||
com.alibaba.fastjson2.JSONObject jsonObject = null;
|
||
try {
|
||
jsonObject = JSON.parseObject(scanResult.getQRCodeString().replaceAll("xnzn", ""));
|
||
} catch (Exception e) {
|
||
Log.e(TAG, "onRecognized: 扫码 onRecognized--jsonObject: 不是一个json");
|
||
return;
|
||
}
|
||
Long custId = 0L;
|
||
try {
|
||
String p = (String) jsonObject.get("p");
|
||
custId = Long.parseLong(p);
|
||
} catch (Exception e) {
|
||
XToastUtils.warning("请使用正确的二维码");
|
||
return;
|
||
}
|
||
if ("pick".equals(type)) {
|
||
//TODO 调用取餐接口
|
||
return;
|
||
}
|
||
Long finalCustId = custId;
|
||
ThreadPoolManager.getExecutor().execute(() -> combineData(3, scanResult.getQRCodeString(), finalCustId));
|
||
}
|
||
|
||
@Override
|
||
public void onError(String errCode, String errMsg) {
|
||
//关闭扫码
|
||
Log.e(TAG, "onRecognized: 扫码 onError:" + errMsg);
|
||
}
|
||
|
||
@Override
|
||
public void onTips(String msg) {
|
||
}
|
||
|
||
@Override
|
||
public void onCancel() {
|
||
//关闭扫码
|
||
closePayWay();
|
||
}
|
||
});
|
||
}
|
||
|
||
public void openReadMealCard(String type) {
|
||
FaceScanUtil.startReadMealCard(this, new RecognizeCallback() {
|
||
|
||
@Override
|
||
public void onPreView(byte[] data, int width, int height, RectF rect) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onRecognized(ScanResult scanResult) {
|
||
ThreadPoolManager.getExecutor().execute(() -> {
|
||
UserInfo userInfo = AppDatabase.getDatabase(OperationActivity.this).userDao().getUserInfoByCard(scanResult.getCardString());
|
||
if (userInfo == null) {
|
||
runOnUiThread(() -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.card_invalid));
|
||
XToastUtils.error("无效卡!");
|
||
});
|
||
return;
|
||
}
|
||
CustPhotoFulInfo custPhotoFulInfo = AppDatabase.getDatabase(OperationActivity.this).custPhotoFulDao().getCustPhotoById(Integer.parseInt(userInfo.getUserId() + ""));
|
||
if ("pick".equals(type)) {
|
||
//调用取餐接口
|
||
runOnUiThread(() -> XToastUtils.error("调用取餐接口"));
|
||
}
|
||
if ("balance".equals(type)) {
|
||
runOnUiThread(() -> {
|
||
Log.e("Dialog", "balanceDialog: ");
|
||
balanceDialog.dismiss();
|
||
balanceDialog = null;
|
||
mPopupWindow.dismiss();
|
||
mPopupWindow = null;
|
||
FaceScanUtil.stopReadMealCard(OperationActivity.this);
|
||
myPresentation.closeScan();
|
||
new Handler().postDelayed(() -> openBalanceResultDialog(userInfo, custPhotoFulInfo), 500);
|
||
|
||
});
|
||
}
|
||
if ("pay".equals(type)) {
|
||
combineData(1, scanResult.getCardString(), userInfo.getUserId());
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
public void onError(String errCode, String errMsg) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onTips(String msg) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onCancel() {
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override
|
||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||
super.onActivityResult(requestCode, resultCode, data);
|
||
if (requestCode == 100) {
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||
if (Settings.canDrawOverlays(this)) {
|
||
XToastUtils.success("权限获取成功");
|
||
//已获得权限
|
||
} else {
|
||
XToastUtils.error("权限获取失败");
|
||
//未获取到权限
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void showPresentation() {
|
||
if (myPresentation != null) {
|
||
myPresentation.dismiss();
|
||
myPresentation = null;
|
||
}
|
||
//方式1
|
||
MediaRouter mediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
|
||
MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_AUDIO);
|
||
if (route != null) {
|
||
Display presentationDisplay = route.getPresentationDisplay();
|
||
if (presentationDisplay != null) {
|
||
myPresentation = new SecondPresentation(OperationActivity.this, presentationDisplay);
|
||
myPresentation.show();
|
||
}
|
||
} else {
|
||
XToastUtils.warning("不支持分屏");
|
||
}
|
||
}
|
||
|
||
private void initViews() {
|
||
WidgetUtils.clearActivityBackground(this);
|
||
mHandler = new Handler();
|
||
//开启时间显示
|
||
timeShow = findViewById(R.id.time_show);
|
||
startUpdateTime();
|
||
}
|
||
|
||
private void startUpdateTime() {
|
||
Runnable runnable = new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
updateTextView();
|
||
mHandler.postDelayed(this, 1000);
|
||
}
|
||
};
|
||
mHandler.post(runnable);
|
||
}
|
||
|
||
private void updateTextView() {
|
||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||
String currentTime = df.format(new Date());
|
||
timeShow.setText(currentTime);
|
||
}
|
||
|
||
private void initData() {
|
||
initMenuData(-1L);
|
||
}
|
||
|
||
Set<MenuDishesTypeAllVO>[] typeSet = new Set[]{new LinkedHashSet<>()};
|
||
|
||
public void initMenuData(Long originalTypeId) {
|
||
ThreadPoolManager.getExecutor().execute(() -> {
|
||
List<CookMeetTimesInfo> cookMeetTimeList = AppDatabase.getDatabase(OperationActivity.this).cookMeetTimesDao().getCookMeetTime();
|
||
String nowDate = DateTimeHelper.getNowDate();
|
||
for (CookMeetTimesInfo cookMeetTimesInfo : cookMeetTimeList) {
|
||
if (cookMeetTimesInfo.getApplyDate().equals(nowDate)) {
|
||
//根据当前时间判断是否在时间内
|
||
if (DateTimeHelper.getDifferTime(DateTimeHelper.getNowTime(), cookMeetTimesInfo.getStartTime()) > 0 &&
|
||
DateTimeHelper.getDifferTime(DateTimeHelper.getNowTime(), cookMeetTimesInfo.getEndTime()) < 0) {
|
||
//在时间范围内
|
||
cookMeetTimesInfo.setIsDefault("1");
|
||
AppDatabase.getDatabase(OperationActivity.this).cookMeetTimesDao().update(cookMeetTimesInfo);
|
||
} else {
|
||
cookMeetTimesInfo.setIsDefault("0");
|
||
AppDatabase.getDatabase(OperationActivity.this).cookMeetTimesDao().update(cookMeetTimesInfo);
|
||
}
|
||
}
|
||
}
|
||
List<CookBookInfo> cookBookInfoList = AppDatabase.getDatabase(OperationActivity.this).cookBookDao().getCookBook();
|
||
String result = "";
|
||
String recipeId = "";
|
||
String recipeType = "";
|
||
String uptime = "";
|
||
String intervalId = "";
|
||
String intervalName = "";
|
||
String startTime = "";
|
||
String endTime = "";
|
||
List<String> mealList = new ArrayList<>();
|
||
|
||
Map<String, Object> allMap = new HashMap<>();
|
||
if (cookBookInfoList != null && cookBookInfoList.size() > 0) {
|
||
recipeId = cookBookInfoList.get(0).getRecipeId();
|
||
recipeType = cookBookInfoList.get(0).getRecipeType();
|
||
uptime = cookBookInfoList.get(0).getUptime();
|
||
allMap.put("recipeId", recipeId);
|
||
allMap.put("recipeType", recipeType);
|
||
allMap.put("uptime", uptime);
|
||
|
||
Map<String, Object> dateListMap = new HashMap<>();
|
||
List<Map<String, Object>> dateList = new ArrayList<>();
|
||
CookMeetTimesInfo cookMeetTimesInfo = AppDatabase.getDatabase(OperationActivity.this).cookMeetTimesDao().getDefaultCookMeetTime();
|
||
if (cookMeetTimesInfo != null) {
|
||
dateListMap.put("applyDate", nowDate);
|
||
intervalId = cookMeetTimesInfo.getIntervalId();
|
||
intervalName = cookMeetTimesInfo.getIntervalName();
|
||
startTime = cookMeetTimesInfo.getStartTime();
|
||
endTime = cookMeetTimesInfo.getEndTime();
|
||
Map<String, Object> intervalListMap = new HashMap<>();
|
||
List<Map<String, String>> iproductList = new ArrayList<>();
|
||
List<CookMeetDetailInfo> cookMeetDetailInfoList = AppDatabase.getDatabase(OperationActivity.this).cookMeetDetailDao().getCookMeetDetailByIntervalId(intervalId, nowDate);
|
||
for (CookMeetDetailInfo b : cookMeetDetailInfoList) {
|
||
String detailId = b.getDetailId();
|
||
String dishesId = b.getDishesId();
|
||
String prefPrice = b.getPrefPrice();
|
||
String salePrice = b.getSalePrice();
|
||
Map<String, String> productListMap = new HashMap<>();
|
||
productListMap.put("detailId", detailId);
|
||
productListMap.put("dishesId", dishesId);
|
||
productListMap.put("prefPrice", prefPrice);
|
||
productListMap.put("salePrice", salePrice);
|
||
mealList.add(dishesId);
|
||
iproductList.add(productListMap);
|
||
}
|
||
intervalListMap.put("intervalId", intervalId);
|
||
intervalListMap.put("intervalName", intervalName);
|
||
intervalListMap.put("startTime", startTime);
|
||
intervalListMap.put("endTime", endTime);
|
||
intervalListMap.put("productList", iproductList);
|
||
dateListMap.put("intervalList", intervalListMap);
|
||
dateList.add(dateListMap);
|
||
allMap.put("dateList", dateList);
|
||
List<CookMeetMealInfo> cookMeetMealInfoList = new ArrayList<>();
|
||
for (String str : mealList) {
|
||
CookMeetMealInfo cookMeetMealInfo = AppDatabase.getDatabase(OperationActivity.this).cookMeetMealDao().getCookMeetMealById(str);
|
||
cookMeetMealInfoList.add(cookMeetMealInfo);
|
||
}
|
||
allMap.put("mealList", cookMeetMealInfoList);
|
||
Gson gson = new Gson();
|
||
result = gson.toJson(allMap);
|
||
} else {
|
||
return;
|
||
}
|
||
} else {
|
||
return;
|
||
}
|
||
if (!StringHelper.isEmptyAndNull(result)) {
|
||
if (result.contains("登录状态已过期")) {
|
||
ThreadPoolManager.executeInUIThread(() -> XToastUtils.warning("登录状态已过期,请重新登录"));
|
||
} else {
|
||
IssueRecipeCompressVO jsonObject = JSONObject.parseObject(result, IssueRecipeCompressVO.class);
|
||
ThreadPoolManager.executeInUIThread(() -> {
|
||
typeSet[0].add(new MenuDishesTypeAllVO(0L, "全部"));
|
||
dishEntityList = new ArrayList<>();
|
||
List<IssueRecipeDetailCompressVO> currentDishList = new ArrayList<>();
|
||
String currentTime = DateTimeHelper.getNowTime();
|
||
List<IssueRecipeMealCompressVO> menuList = jsonObject.getMealList();
|
||
if (jsonObject.getDateList() != null && jsonObject.getDateList().size() > 0) {
|
||
Log.d(TAG, "initMenuData getDateList:" + jsonObject.getDateList().toString());
|
||
} else {
|
||
return;
|
||
}
|
||
if (jsonObject.getDateList().get(0).getIntervalList() != null && jsonObject.getDateList().get(0).getIntervalList().size() > 0) {
|
||
Log.d(TAG, "initMenuData getIntervalList:" + jsonObject.getDateList().get(0).getIntervalList().toString());
|
||
} else {
|
||
return;
|
||
}
|
||
//根据当前时间的餐品
|
||
for (IssueRecipeIntervalCompressVO vo : jsonObject.getDateList().get(0).getIntervalList()) {
|
||
if (DateTimeHelper.getDifferTime(currentTime, String.valueOf(vo.getStartTime())) > 0
|
||
&& DateTimeHelper.getDifferTime(currentTime, String.valueOf(vo.getEndTime())) < 0) {
|
||
if (vo.getProductList() != null && vo.getProductList().size() > 0) {
|
||
currentDishList = vo.getProductList();
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
//取出当前餐品的所有类别及餐品数据
|
||
for (IssueRecipeDetailCompressVO dishItem : currentDishList) {
|
||
//从menuList 中获取当前的餐品
|
||
for (IssueRecipeMealCompressVO mealItem : menuList) {
|
||
if (mealItem.getDishesId().equals(dishItem.getDishesId())) {
|
||
typeSet[0].add(new MenuDishesTypeAllVO(mealItem.getTypeId(), mealItem.getTypeName()));
|
||
if (originalTypeId != -1 && Objects.equals(mealItem.getTypeId(), originalTypeId)) {
|
||
dishEntityList.add(new DishEntity(dishItem.getDishesId(), mealItem.getProductName(), dishItem.getPrefPrice(), dishItem.getSalePrice()
|
||
, jsonObject.getRecipeType(), jsonObject.getRecipeId(), mealItem.getCustomId(), mealItem.getTypeId(), mealItem.getTypeName(),
|
||
mealItem.getCalories(), mealItem.getProtein(), mealItem.getFat(), mealItem.getSodium(), mealItem.getCarbohydrate()));
|
||
}
|
||
if (originalTypeId == -1) {
|
||
dishEntityList.add(new DishEntity(dishItem.getDishesId(), mealItem.getProductName(), dishItem.getPrefPrice(), dishItem.getSalePrice()
|
||
, jsonObject.getRecipeType(), jsonObject.getRecipeId(), mealItem.getCustomId(), mealItem.getTypeId(), mealItem.getTypeName(),
|
||
mealItem.getCalories(), mealItem.getProtein(), mealItem.getFat(), mealItem.getSodium(), mealItem.getCarbohydrate()));
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
mDishListAdapter = new DishListAdapter(OperationActivity.this, dishEntityList, salesMenuEntityList, mSalesMenuAdapter);
|
||
dishListView.setAdapter(mDishListAdapter);
|
||
mDishListAdapter.notifyDataSetChanged();
|
||
//typeSet去重
|
||
Set<String> uniqueKeys = new HashSet<>();
|
||
List<MenuDishesTypeAllVO> filteredList = new ArrayList<>();
|
||
for (MenuDishesTypeAllVO vo : typeSet[0]) {
|
||
String key = vo.getTypeId() + "_" + vo.getTypeName();
|
||
if (uniqueKeys.add(key)) { // 通过 Key 去重
|
||
filteredList.add(vo);
|
||
}
|
||
}
|
||
typeSet[0] = new LinkedHashSet<>(filteredList);
|
||
binding.menuCategory.removeAllViews();
|
||
for (MenuDishesTypeAllVO item : typeSet[0]) {
|
||
TextView textView = new TextView(OperationActivity.this);
|
||
textView.setText(item.getTypeName());
|
||
textView.setTextSize(23);
|
||
textView.setPadding(10, 10, 10, 10);
|
||
textView.setTextColor(getResources().getColor(R.color.app_color_grey));
|
||
if (originalTypeId == -1 && item.getTypeId() == 0) {
|
||
textView.setTextColor(getResources().getColor(R.color.app_color_theme_2));
|
||
} else {
|
||
if (item.getTypeId().equals(originalTypeId)) {
|
||
textView.setTextColor(getResources().getColor(R.color.app_color_theme_2));
|
||
}
|
||
}
|
||
textView.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
|
||
textView.setOnClickListener(v -> {
|
||
//设置颜色
|
||
((TextView) v).setTextColor(getResources().getColor(R.color.app_color_theme_2));
|
||
//重置其他文本颜色
|
||
for (int i = 0; i < binding.menuCategory.getChildCount(); i++) {
|
||
TextView textView1 = (TextView) binding.menuCategory.getChildAt(i);
|
||
if (textView1 != v) {
|
||
textView1.setTextColor(getResources().getColor(R.color.app_color_grey));
|
||
}
|
||
}
|
||
initMenuData(item.getTypeName().equals("全部") ? -1L : item.getTypeId());
|
||
mDishListAdapter = new DishListAdapter(OperationActivity.this, dishEntityList, salesMenuEntityList, mSalesMenuAdapter);
|
||
dishListView.setAdapter(mDishListAdapter);
|
||
});
|
||
binding.menuCategory.addView(textView);
|
||
}
|
||
});
|
||
}
|
||
} else {
|
||
MyLog.e("OperationActivity_log", "数据获取出错,请联系管理员!");
|
||
ThreadPoolManager.executeInUIThread(() -> XToastUtils.error("数据获取出错,请联系管理员!"));
|
||
}
|
||
});
|
||
// 关闭线程池
|
||
ThreadPoolManager.shutdown();
|
||
}
|
||
|
||
@SuppressLint({"ClickableViewAccessibility", "NonConstantResourceId"})
|
||
private void initListeners() {
|
||
SoundManager.initialize(this);
|
||
//悬浮键盘事件
|
||
binding.keybroadSuspension.setOnTouchListener((view, event) -> {
|
||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||
dishListView.setNumColumns(3);
|
||
// 如果没有拖动,则触发点击事件
|
||
binding.keyboardMain.setVisibility(View.VISIBLE);
|
||
binding.keybroadSuspension.setVisibility(View.GONE);
|
||
binding.btnOkOut.setVisibility(View.GONE);
|
||
// 刷新数据
|
||
mDishListAdapter.notifyDataSetChanged();
|
||
mSalesMenuAdapter.notifyDataSetChanged();
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
});
|
||
|
||
binding.keybroadSuspension.setVisibility(View.GONE);
|
||
binding.btnOkOut.setVisibility(View.GONE);
|
||
salesListView = findViewById(R.id.sales_list_view);
|
||
dishListView = findViewById(R.id.dish_list_view);
|
||
|
||
//初始化键盘监听器
|
||
initKeyboardListener();
|
||
|
||
//打开营业数据页面
|
||
binding.businessData.setOnClickListener(v -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.business_data));
|
||
Intent intent = new Intent(OperationActivity.this, BusinessDataActivity.class);
|
||
startActivity(intent);
|
||
finish();
|
||
});
|
||
|
||
//取餐
|
||
binding.pickUpYourMeal.setOnClickListener(vi -> {
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(OperationActivity.this);
|
||
View view = LayoutInflater.from(OperationActivity.this).inflate(R.layout.dialog_pick_up_meals, null);
|
||
TextView tipTitle = view.findViewById(R.id.tip_title);
|
||
TextView pickUpMealsContentTip = view.findViewById(R.id.pick_up_meals_content_tip);
|
||
TextView close = view.findViewById(R.id.btn_close);
|
||
builder.setView(view);
|
||
pickUpYourMealDialog = builder.create();
|
||
//取消支付
|
||
close.setOnClickListener(v -> {
|
||
pickUpYourMealDialog.dismiss();
|
||
closePayWay();
|
||
});
|
||
pickUpYourMealDialog.setCancelable(false);
|
||
pickUpYourMealDialog.show();
|
||
|
||
//TODO 如何确认哪一个是菜单支付 哪一个是取餐 ?
|
||
openPayWay("pick");
|
||
|
||
});
|
||
|
||
//刷新
|
||
binding.salesRefresh.setOnClickListener(v -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.refresh));
|
||
salesMenuEntityList.clear();
|
||
dishEntityList.clear();
|
||
typeSet = new Set[]{new LinkedHashSet<>()};
|
||
binding.menuCategory.removeAllViews();
|
||
setViewData(salesMenuEntityList, true);
|
||
mDishListAdapter.notifyDataSetChanged();
|
||
mSalesMenuAdapter.notifyDataSetChanged();
|
||
initMenuData(-1L);
|
||
});
|
||
|
||
//加载选菜适配器
|
||
mSalesMenuAdapter = new SalesMenuAdapter(this, salesMenuEntityList);
|
||
salesListView.setAdapter(mSalesMenuAdapter);
|
||
|
||
mDishListAdapter = new DishListAdapter(this, dishEntityList, salesMenuEntityList, mSalesMenuAdapter);
|
||
dishListView.setAdapter(mDishListAdapter);
|
||
|
||
binding.orderManagement.setOnClickListener(v -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.order_management));
|
||
Intent intent = new Intent(OperationActivity.this, MachineSaleActivity.class);
|
||
startActivity(intent);
|
||
finish();
|
||
});
|
||
|
||
binding.loginLayout.setOnClickListener(v -> {
|
||
if (!binding.loginName.getText().toString().equals("未登录")) {
|
||
DialogLoader.getInstance().showConfirmDialog(
|
||
this,
|
||
"是否退出登录",
|
||
getString(R.string.lab_yes),
|
||
(dialog, which) -> {
|
||
ThreadPoolManager.getExecutor().execute(() -> {
|
||
AppDatabase.getDatabase(this).loginInfoDao().deleteAll();
|
||
runOnUiThread(() -> {
|
||
binding.loginName.setText("未登录");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.login_out_success));
|
||
});
|
||
});
|
||
dialog.dismiss();
|
||
},
|
||
getString(R.string.lab_no),
|
||
(dialog, which) -> {
|
||
dialog.dismiss();
|
||
}
|
||
);
|
||
} else {
|
||
openLoginDialog();
|
||
}
|
||
});
|
||
|
||
binding.operationMore.setOnClickListener(v -> {
|
||
SimplePopupWindow.with(OperationActivity.this)
|
||
.setView(R.layout.popup_window_more)
|
||
.setBackgroundAlpha(0.6f) //设置你的背景透明度
|
||
.show(v, 200, (view, popupWindow) -> {
|
||
mPopupWindow = popupWindow;
|
||
TextView setting = view.findViewById(R.id.setting);
|
||
setting.setOnClickListener(v1 -> {
|
||
if (binding.loginName.getText().toString().equals("未登录")) {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.please_login));
|
||
XToastUtils.warning("请先登录!");
|
||
mPopupWindow.dismiss();
|
||
mPopupWindow = null;
|
||
} else {
|
||
Intent intent = new Intent(OperationActivity.this, SettingsActivity.class);
|
||
startActivity(intent);
|
||
finish();
|
||
}
|
||
});
|
||
TextView checkBalance = view.findViewById(R.id.check_balance);
|
||
checkBalance.setOnClickListener(v2 -> {
|
||
openBalanceDialog();
|
||
openPayWay("balance");
|
||
});
|
||
TextView reboot = view.findViewById(R.id.reboot);
|
||
reboot.setOnClickListener(v3 -> DialogLoader.getInstance().showConfirmDialog(
|
||
this,
|
||
"是否确认重启APP?",
|
||
getString(R.string.lab_yes),
|
||
(dialog, which) -> {
|
||
// 重启应用程序
|
||
Intent intent = getBaseContext().getPackageManager()
|
||
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||
startActivity(intent);
|
||
System.exit(0);
|
||
dialog.dismiss();
|
||
},
|
||
getString(R.string.lab_no),
|
||
(dialog, which) -> dialog.dismiss()
|
||
));
|
||
});
|
||
});
|
||
}
|
||
|
||
public void openBalanceDialog() {
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(OperationActivity.this);
|
||
View view = LayoutInflater.from(OperationActivity.this).inflate(R.layout.dialog_wait_for_payment, null);
|
||
TextView tipTitle = view.findViewById(R.id.tip_title);
|
||
TextView payCancel = view.findViewById(R.id.btn_pay_cancel);
|
||
tipTitle.setText("查询余额");
|
||
payCancel.setText("取消");
|
||
builder.setView(view);
|
||
balanceDialog = builder.create();
|
||
//取消支付
|
||
payCancel.setOnClickListener(v -> {
|
||
FaceScanUtil.stopReadMealCard(OperationActivity.this);
|
||
myPresentation.closeScan();
|
||
balanceDialog.dismiss();
|
||
balanceDialog = null;
|
||
mPopupWindow.dismiss();
|
||
mPopupWindow = null;
|
||
});
|
||
balanceDialog.setCancelable(false);
|
||
balanceDialog.show();
|
||
}
|
||
|
||
@SuppressLint("SetTextI18n")
|
||
public void openBalanceResultDialog(UserInfo userInfo, CustPhotoFulInfo custPhotoFulInfo) {
|
||
Log.d("Dialog", "openBalanceResultDialog: 进入:" + userInfo);
|
||
runOnUiThread(() -> {
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(OperationActivity.this);
|
||
View view = LayoutInflater.from(OperationActivity.this).inflate(R.layout.dialog_person_balance, null);
|
||
ImageView personPhoto = view.findViewById(R.id.person_photo);
|
||
TextView userName = view.findViewById(R.id.userName);
|
||
TextView phone = view.findViewById(R.id.phone);
|
||
TextView balanceWallet = view.findViewById(R.id.balance_wallet);
|
||
TextView personalWallet = view.findViewById(R.id.personal_wallet);
|
||
TextView subsidyBalance = view.findViewById(R.id.subsidy_balance);
|
||
@SuppressLint({"MissingInflatedId", "LocalSuppress"}) Button cancel = view.findViewById(R.id.cancel_balance);
|
||
if (custPhotoFulInfo != null) {
|
||
GlideUtil.GlideWithPlaceHolder(this, WorkConfig.getFileUrl() + custPhotoFulInfo.getPhotoUrl()).into(personPhoto);
|
||
} else {
|
||
GlideUtil.GlideWithPlaceHolder(this, R.drawable.my_photo).into(personPhoto);
|
||
}
|
||
userName.setText(userInfo.getUserName());
|
||
phone.setText(userInfo.getPhone());
|
||
balanceWallet.setText((new BigDecimal(userInfo.getPersonalWalletBalance()).add(new BigDecimal(userInfo.getSubsidiesBalance()))).divide(new BigDecimal(100)).toString());
|
||
personalWallet.setText(new BigDecimal(userInfo.getPersonalWalletBalance()).divide(new BigDecimal(100)).toString());
|
||
subsidyBalance.setText(new BigDecimal(userInfo.getSubsidiesBalance()).divide(new BigDecimal(100)).toString());
|
||
ThreadPoolManager.getExecutor().execute(() -> myPresentation.setBalanceInfo(userInfo, custPhotoFulInfo, 1));
|
||
builder.setView(view);
|
||
balanceResultDialog = builder.create();
|
||
cancel.setOnClickListener(view1 -> {
|
||
myPresentation.setBalanceInfo(userInfo, null, 2);
|
||
balanceResultDialog.dismiss();
|
||
balanceResultDialog = null;
|
||
});
|
||
balanceResultDialog.setCancelable(false);
|
||
balanceResultDialog.show();
|
||
|
||
// 五秒后自动关闭对话框
|
||
new Handler().postDelayed(() -> {
|
||
if (balanceResultDialog != null && balanceResultDialog.isShowing()) {
|
||
myPresentation.setBalanceInfo(userInfo, null, 2);
|
||
balanceResultDialog.dismiss();
|
||
balanceResultDialog = null;
|
||
}
|
||
}, 5000);
|
||
});
|
||
}
|
||
|
||
public void openLoginDialog() {
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(OperationActivity.this);
|
||
View view = LayoutInflater.from(OperationActivity.this).inflate(R.layout.dialog_login, null);
|
||
EditText etNameInput = view.findViewById(R.id.et_name_input);
|
||
EditText etPasswordInput = view.findViewById(R.id.et_password_input);
|
||
TextView btnCancel = view.findViewById(R.id.btn_close);
|
||
TextView btnOk = view.findViewById(R.id.btn_ok);
|
||
builder.setView(view);
|
||
loginDialog = builder.create();
|
||
//登录
|
||
btnOk.setOnClickListener(v -> {
|
||
if (etNameInput.getText().toString().isEmpty()) {
|
||
XToastUtils.warning("请先输入账号!");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.please_input_account));
|
||
return;
|
||
}
|
||
// if (etPasswordInput.getText().toString().isEmpty()) {
|
||
// XToastUtils.error("请输入密码!");
|
||
// return;
|
||
// }
|
||
login(etNameInput.getText().toString(), "", etNameInput);
|
||
});
|
||
//取消
|
||
btnCancel.setOnClickListener(v -> {
|
||
//隐藏键盘
|
||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||
if (imm != null && imm.isActive()) {
|
||
imm.hideSoftInputFromWindow(etNameInput.getWindowToken(), 0);
|
||
}
|
||
loginDialog.dismiss();
|
||
loginDialog = null;
|
||
});
|
||
loginDialog.setCancelable(false);
|
||
loginDialog.show();
|
||
}
|
||
|
||
public void login(String name, String password, EditText etNameInput) {
|
||
ThreadPoolManager.getExecutor().execute(() -> {
|
||
UserInfo userInfo = AppDatabase.getDatabase(this).userDao().getUserInfoByPhone(name);
|
||
if (userInfo == null || !userInfo.getLoginType().contains("0")) {
|
||
runOnUiThread(() -> {
|
||
XToastUtils.warning("该账号不支持登录!");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.accont_not_to_login));
|
||
});
|
||
return;
|
||
}
|
||
LoginInfo loginInfo = new LoginInfo();
|
||
loginInfo.setUserId(String.valueOf(userInfo.getUserId()));
|
||
loginInfo.setUserName(userInfo.getUserName());
|
||
loginInfo.setPhone(name);
|
||
loginInfo.setUserPwd(password);
|
||
AppDatabase.getDatabase(this).loginInfoDao().insert(loginInfo);
|
||
runOnUiThread(() -> {
|
||
XToastUtils.success("登录成功!");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.login_success));
|
||
//隐藏键盘
|
||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||
if (imm != null && imm.isActive()) {
|
||
imm.hideSoftInputFromWindow(etNameInput.getWindowToken(), 0);
|
||
}
|
||
loginDialog.dismiss();
|
||
loginDialog = null;
|
||
binding.loginName.setText(userInfo.getUserName());
|
||
});
|
||
});
|
||
}
|
||
|
||
/**
|
||
* *************************************以下键盘点击事件********************************************
|
||
*/
|
||
@SuppressLint("DefaultLocale")
|
||
private void initKeyboardListener() {
|
||
//阻止EditText点击出现键盘
|
||
// 隐藏键盘
|
||
TextView premiumAmountEdit = findViewById(R.id.premium_amount);
|
||
binding.keyboardMain.findViewById(R.id.tv_0).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_0));
|
||
addKeyboardNum("0", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_1).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_1));
|
||
addKeyboardNum("1", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_2).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_2));
|
||
addKeyboardNum("2", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_3).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_3));
|
||
addKeyboardNum("3", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_4).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_4));
|
||
addKeyboardNum("4", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_5).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_5));
|
||
addKeyboardNum("5", false);
|
||
});
|
||
binding.keyboardMain.findViewById(R.id.tv_6).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_6));
|
||
addKeyboardNum("6", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_7).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_7));
|
||
addKeyboardNum("7", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_8).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_8));
|
||
addKeyboardNum("8", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_9).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_9));
|
||
addKeyboardNum("9", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_x).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_clear));
|
||
addKeyboardNum("x", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_add).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_add));
|
||
addKeyboardNum("0", true);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_point).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_dot));
|
||
addKeyboardNum(".", false);
|
||
});
|
||
|
||
binding.keyboardMain.findViewById(R.id.tv_clear).setOnClickListener(view -> {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_clear));
|
||
premiumAmount = new StringBuilder();
|
||
premiumAmountEdit.setText("");
|
||
});
|
||
binding.keyboardMain.findViewById(R.id.tv_ok).setOnClickListener(view -> {
|
||
if (premiumAmount.toString().isEmpty() && !salesMenuEntityList.isEmpty()) {
|
||
//弹出支付弹窗 可取消支付 或 记账
|
||
openDialog();
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.please_pay));
|
||
openPayWay("pay");
|
||
return;
|
||
} else if (premiumAmount.toString().isEmpty() && salesMenuEntityList.isEmpty()) {
|
||
XToastUtils.warning("请先点餐!");
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.please_choose_food));
|
||
return;
|
||
}
|
||
double sum = 0.0;
|
||
String[] numArr = premiumAmount.toString().split("\\+");
|
||
|
||
for (String money : numArr) {
|
||
sum += Double.parseDouble(money);
|
||
}
|
||
sum = Double.parseDouble(String.format("%.2f", sum));
|
||
SalesMenuEntity salesMenuEntity = new SalesMenuEntity();
|
||
salesMenuEntity.setId("-1");
|
||
salesMenuEntity.setName("按键金额");
|
||
salesMenuEntity.setNum(BigDecimal.valueOf(1));
|
||
salesMenuEntity.setPrice(BigDecimal.valueOf(sum));
|
||
salesMenuEntity.setOldPrice(BigDecimal.valueOf(sum));
|
||
salesMenuEntity.setSubtotal(BigDecimal.valueOf(sum));
|
||
salesMenuEntityList.add(salesMenuEntity);
|
||
mSalesMenuAdapter.notifyDataSetChanged();
|
||
setViewData(salesMenuEntityList, false);
|
||
premiumAmount = new StringBuilder();
|
||
premiumAmountEdit.setText("");
|
||
});
|
||
//键盘隐藏事件 展示悬浮按钮
|
||
binding.keyboardMain.findViewById(R.id.hide_keyboard).setOnClickListener(view -> {
|
||
binding.keybroadSuspension.setVisibility(View.VISIBLE);
|
||
binding.btnOkOut.setVisibility(View.VISIBLE);
|
||
|
||
dishListView.setNumColumns(5);
|
||
// 刷新数据
|
||
mDishListAdapter.notifyDataSetChanged();
|
||
binding.keyboardMain.setVisibility(View.GONE);
|
||
});
|
||
binding.btnOkPay.setOnClickListener(view -> {
|
||
if (premiumAmount.toString().isEmpty() && salesMenuEntityList.isEmpty()) {
|
||
SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.please_choose_food));
|
||
XToastUtils.warning("请先点餐!");
|
||
return;
|
||
}
|
||
openDialog();
|
||
openPayWay("scan");
|
||
});
|
||
}
|
||
|
||
private void openPayWay(String type) {
|
||
// openScan(type);
|
||
openReadMealCard(type);
|
||
myPresentation.openScan(type);
|
||
}
|
||
|
||
@SuppressLint({"SetTextI18n", "DefaultLocale"})
|
||
private void addKeyboardNum(String currentNum, boolean isAdd) {
|
||
// 处理退格逻辑
|
||
if ("x".equals(currentNum)) {
|
||
if (premiumAmount.length() > 0) {
|
||
premiumAmount.deleteCharAt(premiumAmount.length() - 1);
|
||
}
|
||
} else if (isAdd) {
|
||
// 处理加号逻辑
|
||
handlePlusOperator();
|
||
} else {
|
||
// 处理数字或小数点
|
||
if (".".equals(currentNum)) {
|
||
handleDecimalPoint();
|
||
} else {
|
||
if (premiumAmount.length() > 5) {
|
||
return;
|
||
}
|
||
// 直接添加数字
|
||
premiumAmount.append(currentNum);
|
||
}
|
||
}
|
||
// 计算并更新显示
|
||
updateDisplay();
|
||
}
|
||
|
||
private void handlePlusOperator() {
|
||
if (premiumAmount.length() == 0) return;
|
||
|
||
char lastChar = premiumAmount.charAt(premiumAmount.length() - 1);
|
||
if (lastChar == '+' || lastChar == '.') return;
|
||
|
||
premiumAmount.append("+");
|
||
}
|
||
|
||
private void handleDecimalPoint() {
|
||
if (premiumAmount.length() > 5) {
|
||
return;
|
||
}
|
||
int lastPlusIndex = premiumAmount.lastIndexOf("+");
|
||
String currentNumber = lastPlusIndex == -1
|
||
? premiumAmount.toString()
|
||
: premiumAmount.substring(lastPlusIndex + 1);
|
||
|
||
if (currentNumber.contains(".")) return;
|
||
|
||
if (currentNumber.isEmpty()) {
|
||
premiumAmount.append("0");
|
||
}
|
||
premiumAmount.append(".");
|
||
}
|
||
|
||
@SuppressLint("SetTextI18n")
|
||
private void updateDisplay() {
|
||
String expression = premiumAmount.toString();
|
||
double sum = calculateSum(expression);
|
||
// @SuppressLint("DefaultLocale") String formattedSum = String.format("%.2f", sum);
|
||
|
||
TextView premiumAmountEdit = findViewById(R.id.premium_amount);
|
||
// premiumAmountEdit.setText(expression + (expression.isEmpty() ? "" : " = ") + formattedSum);
|
||
premiumAmountEdit.setText(expression);
|
||
}
|
||
|
||
private double calculateSum(String expression) {
|
||
if (expression.isEmpty()) return 0.0;
|
||
|
||
String[] parts = expression.split("\\+");
|
||
double sum = 0.0;
|
||
|
||
for (String part : parts) {
|
||
if (part.isEmpty()) continue;
|
||
|
||
try {
|
||
sum += parseNumber(part);
|
||
} catch (NumberFormatException e) {
|
||
// 处理无效格式
|
||
}
|
||
}
|
||
|
||
return Math.round(sum * 100.0) / 100.0; // 保留两位小数
|
||
}
|
||
|
||
private double parseNumber(String number) {
|
||
if (number.endsWith(".")) {
|
||
return Double.parseDouble(number + "0");
|
||
}
|
||
return Double.parseDouble(number);
|
||
}
|
||
|
||
|
||
@SuppressLint("SetTextI18n")
|
||
public void setViewData(List<SalesMenuEntity> salesMenuEntityList, boolean isSales) {
|
||
//获取总金额salesMenuEntityList
|
||
BigDecimal salesAmountDueMoney = BigDecimal.ZERO;
|
||
//优惠金额
|
||
BigDecimal salesDiscountAmountMoney = BigDecimal.ZERO;
|
||
//份数
|
||
BigDecimal salesNumber = BigDecimal.ZERO;
|
||
for (SalesMenuEntity salesMenuEntity : salesMenuEntityList) {
|
||
salesAmountDueMoney = salesAmountDueMoney.add(salesMenuEntity.getSubtotal());
|
||
salesNumber = salesNumber.add(salesMenuEntity.getNum());
|
||
if (isSales) {
|
||
salesDiscountAmountMoney = salesDiscountAmountMoney.add(salesMenuEntity.getOldPrice().subtract(salesMenuEntity.getPrice())).multiply(salesMenuEntity.getNum());
|
||
} else {
|
||
salesDiscountAmountMoney = salesDiscountAmountMoney.add(salesMenuEntity.getOldPrice().subtract(salesMenuEntity.getPrice()));
|
||
}
|
||
}
|
||
if (salesAmountDueMoney.compareTo(BigDecimal.ZERO) < 0) {
|
||
salesAmountDueMoney = BigDecimal.ZERO;
|
||
}
|
||
BigDecimal dueMoney = salesAmountDueMoney;
|
||
if (dueMoney.compareTo(BigDecimal.ZERO) < 0) {
|
||
dueMoney = BigDecimal.ZERO;
|
||
}
|
||
binding.salesNumber.setText("总数量:" + salesNumber + "份");
|
||
binding.salesTotalMoney.setText("总金额:" + salesAmountDueMoney + "元");
|
||
binding.salesDiscountAmount.setText(String.valueOf(salesDiscountAmountMoney));
|
||
binding.salesAmountDue.setText(String.valueOf(dueMoney));
|
||
mSalesMenuAdapter.notifyDataSetChanged();
|
||
if (myPresentation != null) {
|
||
myPresentation.setSalesData(salesMenuEntityList);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public boolean onMenuItemClick(MenuItem item) {
|
||
return false;
|
||
}
|
||
|
||
@Override
|
||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||
return false;
|
||
}
|
||
|
||
@Override
|
||
public void onRetry() {
|
||
XToastUtils.toast("再按一次退出程序");
|
||
}
|
||
|
||
@Override
|
||
public void onExit() {
|
||
XUtil.exitApp();
|
||
}
|
||
|
||
public void openDialog() {
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(OperationActivity.this);
|
||
View view = LayoutInflater.from(OperationActivity.this).inflate(R.layout.dialog_wait_for_payment, null);
|
||
TextView tipTitle = view.findViewById(R.id.tip_title);
|
||
TextView bookKeeping = view.findViewById(R.id.btn_book_keeping);
|
||
TextView payCancel = view.findViewById(R.id.btn_pay_cancel);
|
||
TextView payContentTip = view.findViewById(R.id.payment_content_tip);
|
||
ProgressBar progress = view.findViewById(R.id.progress);
|
||
LinearLayout layoutBookKeeping = view.findViewById(R.id.layout_book_keeping);
|
||
builder.setView(view);
|
||
alertDialog = builder.create();
|
||
//记账
|
||
bookKeeping.setOnClickListener(v -> {
|
||
//成功内容 在餐次内的操作
|
||
|
||
//失败内容 不在餐次内
|
||
payContentTip.setVisibility(View.VISIBLE);
|
||
progress.setVisibility(View.GONE);
|
||
tipTitle.setText("支付失败");
|
||
});
|
||
//取消支付
|
||
payCancel.setOnClickListener(v -> {
|
||
closePayWay();
|
||
|
||
});
|
||
alertDialog.setCancelable(false);
|
||
alertDialog.show();
|
||
|
||
}
|
||
|
||
private void closePayWay() {
|
||
// FaceScanUtil.stopQrcodeScan(OperationActivity.this);
|
||
FaceScanUtil.stopReadMealCard(OperationActivity.this);
|
||
myPresentation.closeScan();
|
||
alertDialog.dismiss();
|
||
alertDialog = null;
|
||
}
|
||
|
||
int code = 0;
|
||
private BroadcastReceiver networkReceiver = new BroadcastReceiver() {
|
||
@Override
|
||
public void onReceive(Context context, Intent intent) {
|
||
boolean isConnected = intent.getBooleanExtra("isConnected", false);
|
||
if (isConnected) {
|
||
// 更新UI:网络正常
|
||
Log.d(TAG, "onReceive: 网络正常");
|
||
} else {
|
||
// 更新UI:网络异常
|
||
Log.d(TAG, "onReceive: 网络异常");
|
||
if (code < 3) {
|
||
XToastUtils.toast("网络异常,请检查网络连接");
|
||
}
|
||
code++;
|
||
}
|
||
}
|
||
};
|
||
|
||
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||
@Override
|
||
protected void onResume() {
|
||
super.onResume();
|
||
registerReceiver(networkReceiver, new IntentFilter("NETWORK_STATUS_ACTION"));
|
||
IntentFilter filter = new IntentFilter("ACTION_UPDATE_MENU");
|
||
registerReceiver(updateReceiver, filter);
|
||
IntentFilter faceFilter = new IntentFilter("FACE_SCAN_SUCCESS");
|
||
registerReceiver(faceReceiver, faceFilter);
|
||
}
|
||
|
||
private final BroadcastReceiver updateReceiver = new BroadcastReceiver() {
|
||
@Override
|
||
public void onReceive(Context context, Intent intent) {
|
||
if ("ACTION_UPDATE_MENU".equals(intent.getAction())) {
|
||
// 执行更新逻辑
|
||
dishEntityList = new ArrayList<>();
|
||
salesMenuEntityList = new ArrayList<>();
|
||
mSalesMenuAdapter = new SalesMenuAdapter(OperationActivity.this, salesMenuEntityList);
|
||
salesListView.setAdapter(mSalesMenuAdapter);
|
||
|
||
mDishListAdapter = new DishListAdapter(OperationActivity.this, dishEntityList, salesMenuEntityList, mSalesMenuAdapter);
|
||
dishListView.setAdapter(mDishListAdapter);
|
||
|
||
typeSet[0] = new LinkedHashSet<>();
|
||
binding.menuCategory.removeAllViews();
|
||
initMenuData(-1L); // 示例方法
|
||
}
|
||
}
|
||
};
|
||
private final BroadcastReceiver faceReceiver = new BroadcastReceiver() {
|
||
@Override
|
||
public void onReceive(Context context, Intent intent) {
|
||
if ("FACE_SCAN_SUCCESS".equals(intent.getAction())) {
|
||
// 执行更新逻辑
|
||
String userId = intent.getStringExtra("userId");
|
||
if (ObjectUtil.isEmpty(userId) || "null".equals(userId) || "".equals(userId)) {
|
||
userId = "0";
|
||
}
|
||
String type = intent.getStringExtra("type");
|
||
Log.d(TAG, "onReceive type: " + type);
|
||
if (ObjectUtil.isEmpty(type) || "null".equals(type) || "".equals(type)) {
|
||
String finalUserId = userId;
|
||
ThreadPoolManager.getExecutor().execute(() -> combineData(2, finalUserId, Long.valueOf(finalUserId)));
|
||
} else if ("balance".equals(type)) {
|
||
String finalUserId1 = userId;
|
||
Log.e("Dialog", "balanceDialog: ");
|
||
balanceDialog.dismiss();
|
||
balanceDialog = null;
|
||
mPopupWindow.dismiss();
|
||
mPopupWindow = null;
|
||
FaceScanUtil.stopReadMealCard(OperationActivity.this);
|
||
myPresentation.closeScan();
|
||
ThreadPoolManager.getExecutor().execute(() -> {
|
||
UserInfo userInfo = AppDatabase.getDatabase(context).userDao().getUserInfoById(finalUserId1);
|
||
CustPhotoFulInfo custPhotoFulInfo = AppDatabase.getDatabase(context).custPhotoFulDao().getCustPhotoById(Integer.parseInt(finalUserId1));
|
||
runOnUiThread(() -> new Handler().postDelayed(() -> openBalanceResultDialog(userInfo, custPhotoFulInfo), 500));
|
||
});
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|
||
@Override
|
||
protected void onPause() {
|
||
super.onPause();
|
||
code = 0;
|
||
unregisterReceiver(networkReceiver);
|
||
unregisterReceiver(updateReceiver);
|
||
unregisterReceiver(faceReceiver);
|
||
}
|
||
|
||
@Override
|
||
public void onDestroy() {
|
||
ThreadPoolManager.shutdown();
|
||
decorView = null;
|
||
FaceScanUtil.releaseResources();
|
||
// 注销广播接收器
|
||
try {
|
||
unregisterReceiver(networkReceiver);
|
||
unregisterReceiver(updateReceiver);
|
||
unregisterReceiver(faceReceiver);
|
||
} catch (IllegalArgumentException e) {
|
||
Log.w(TAG, "Receiver not registered: " + e.getMessage());
|
||
}
|
||
|
||
|
||
if (myPresentation != null) {
|
||
myPresentation.unInitEngine();
|
||
myPresentation.dismiss();
|
||
myPresentation = null;
|
||
}
|
||
if (alertDialog != null) {
|
||
alertDialog.dismiss();
|
||
alertDialog = null;
|
||
}
|
||
if (balanceResultDialog != null) {
|
||
balanceResultDialog.dismiss();
|
||
balanceResultDialog = null;
|
||
}
|
||
if (balanceDialog != null) {
|
||
balanceDialog.dismiss();
|
||
balanceDialog = null;
|
||
}
|
||
if (loginDialog != null) {
|
||
loginDialog.dismiss();
|
||
loginDialog = null;
|
||
}
|
||
if (pickUpYourMealDialog != null) {
|
||
pickUpYourMealDialog.dismiss();
|
||
pickUpYourMealDialog = null;
|
||
}
|
||
if (mHandler != null) {
|
||
mHandler.removeCallbacksAndMessages(null);
|
||
mHandler = null;
|
||
}
|
||
if (mSalesMenuAdapter != null) {
|
||
mSalesMenuAdapter = null;
|
||
}
|
||
if (mDishListAdapter != null) {
|
||
mDishListAdapter = null;
|
||
}
|
||
|
||
if (dishEntityList != null) {
|
||
dishEntityList.clear();
|
||
dishEntityList = null;
|
||
}
|
||
if (salesMenuEntityList != null) {
|
||
salesMenuEntityList.clear();
|
||
salesMenuEntityList = null;
|
||
}
|
||
if (typeSet != null) {
|
||
typeSet = null;
|
||
}
|
||
super.onDestroy();
|
||
}
|
||
}
|
||
|
||
|
||
|