Commit 247d0772 by pye52

恢复到原来发送订单的方案(让后台去处理异常订单)

parent 633e3868
......@@ -22,8 +22,6 @@ import com.google.gson.JsonObject;
import org.java_websocket.handshake.ServerHandshake;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
......@@ -205,58 +203,13 @@ public class PayOfflineViewModel extends ViewModel {
LogUtils.d(TAG, "所有离线订单处理完毕");
return;
}
// 由于离线支付订单有可能和设备码不一致,需要兼容该情况
// 保证离线订单的equipmentId与equipmentNo一致
// 去除不一致的订单(留待下次上传)
String mainEquipmentNo = acquireMaxEquipmentNo(payOfflineData);
if (TextUtils.isEmpty(mainEquipmentNo)) {
mainEquipmentNo = deviceSN;
}
ArrayList<PayData> theSameEquipmentNoData = new ArrayList<>();
for (PayData t : payOfflineData) {
if (t.getEquipmentNo().equals(mainEquipmentNo)) {
theSameEquipmentNoData.add(t);
}
}
payRequest = new PayRequest(mainEquipmentNo, theSameEquipmentNoData);
payRequest = new PayRequest(deviceSN, payOfflineData);
String requestStr = gson.toJson(payRequest);
payOfflineState.postValue(new PayOfflineState(PayOfflineState.SEND, requestStr));
SCWebSocketClient.getInstance().send(requestStr);
LogUtils.d(TAG, "离线支付: " + payRequest.toString());
}
private String acquireMaxEquipmentNo(List<PayData> list) {
HashMap<String, Integer> tMap = new HashMap<>();
String mainEquipmentNo = "";
int size = list.size();
int max = 0;
for (PayData t : list) {
String key = t.getEquipmentNo();
int value;
if (tMap.containsKey(key)) {
Integer vWrapper = tMap.get(key);
if (vWrapper == null) {
value = 1;
} else {
value = vWrapper + 1;
}
if (value > (size / 2)) {
return key;
}
} else {
value = 1;
}
if (value >= max) {
max = value;
mainEquipmentNo = key;
}
tMap.put(key, value);
}
tMap.clear();
return mainEquipmentNo;
}
}
private class UpdateUploadTimeRunnable implements Runnable {
......
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 sign in to comment