Browse Source

fix 2 add api for order result

dev
赵明涛 5 days ago
parent
commit
49d016f425
  1. 209
      app/src/main/java/com/ouxuan/oxface/orderOX/OrderSelectionActivity.java
  2. 101
      app/src/main/java/com/ouxuan/oxface/orderOX/OrderVerificationResultActivity.java
  3. 43
      app/src/main/res/layout/activity_order_verification_result.xml

209
app/src/main/java/com/ouxuan/oxface/orderOX/OrderSelectionActivity.java

@ -250,37 +250,192 @@ public class OrderSelectionActivity extends AppCompatActivity {
* 执行订单核销
*/
private void performOrderVerification(OrderVerificationData.OrderItem order) {
LogManager.logInfo(TAG, "执行订单核销: " + order.getOrder_no());
LogManager.logInfo(TAG, "开始执行订单核销: " + order.getOrder_no());
// 停止倒计时
stopCountdown();
// 准备结果数据
Intent resultIntent = new Intent();
resultIntent.putExtra("selected_order", new Gson().toJson(order));
resultIntent.putExtra("order_no", order.getOrder_no());
resultIntent.putExtra("verification_code", order.getVerificationCode());
resultIntent.putExtra("order_type", order.getOrder_type());
resultIntent.putExtra("card_no", order.getInfo() != null ? order.getInfo().getCard_no() : "");
resultIntent.putExtra("project", order.getProject());
resultIntent.putExtra("verification_type", verificationType);
setResult(RESULT_OK, resultIntent);
// 显示成功提示并跳转到结果页面
showToast("订单核销成功");
// 跳转到核销结果页面
Intent intent = new Intent(this, OrderVerificationResultActivity.class);
intent.putExtra("verification_type", verificationType);
intent.putExtra("order_no", order.getOrder_no());
intent.putExtra("verification_code", order.getVerificationCode());
intent.putExtra("order_type", order.getOrder_type());
intent.putExtra("card_no", order.getInfo() != null ? order.getInfo().getCard_no() : "");
intent.putExtra("status", "核销成功");
startActivity(intent);
finish();
// 获取认证token
String token = loginDataManager.getAuthToken();
if (token == null || token.isEmpty()) {
LogManager.logError(TAG, "获取认证token失败");
showToast("获取认证token失败,无法核销订单");
return;
}
// 获取订单ID和核销码
String orderId = order.getOrder_no();
String verifyCode = order.getVerificationCode();
if (verifyCode == null || verifyCode.isEmpty()) {
// 如果没有直接的验证码尝试从v_code字段获取
if (order.getV_code() != null && !order.getV_code().isEmpty()) {
verifyCode = order.getV_code().get(0);
}
}
if (verifyCode == null || verifyCode.isEmpty()) {
LogManager.logError(TAG, "未找到有效的核销码");
showToast("未找到有效的核销码,无法核销订单");
return;
}
LogManager.logInfo(TAG, "调用核销接口: orderId=" + orderId + ", verifyCode=" + verifyCode);
// 显示加载状态
showToast("正在核销订单,请稍候...");
// 调用NetworkUtils.verifyOrder接口进行实际核销
com.ouxuan.oxface.network.utils.NetworkUtils.verifyOrder(
token,
orderId,
verifyCode,
new com.ouxuan.oxface.network.callback.NetworkCallback<com.ouxuan.oxface.network.api.PadApiService.VerifyOrderResponse>() {
@Override
public void onStart() {
LogManager.logInfo(TAG, "核销请求开始");
}
@Override
public void onSuccess(com.ouxuan.oxface.network.api.PadApiService.VerifyOrderResponse data) {
LogManager.logInfo(TAG, "核销请求成功: " + (data != null ? data.toString() : "null"));
runOnUiThread(() -> {
// 核销成功跳转到结果页面并传递完整的核销结果数据
String status = "核销成功";
String message = "订单核销成功";
if (data != null) {
if (data.isResult()) {
status = "核销成功";
message = data.getMessage() != null && !data.getMessage().isEmpty()
? data.getMessage() : "订单核销成功";
} else {
status = "核销失败";
message = data.getMessage() != null && !data.getMessage().isEmpty()
? data.getMessage() : "订单核销失败";
}
}
showToast(message);
// 跳转到核销结果页面传递完整的订单和核销结果数据
Intent intent = new Intent(OrderSelectionActivity.this, OrderVerificationResultActivity.class);
intent.putExtra("verification_type", verificationType);
intent.putExtra("order_no", order.getOrder_no());
intent.putExtra("verification_code", verifyCode);
intent.putExtra("order_type", order.getOrder_type());
intent.putExtra("card_no", order.getInfo() != null ? order.getInfo().getCard_no() : "");
intent.putExtra("project", order.getProject());
intent.putExtra("status", status);
intent.putExtra("message", message);
// 传递完整的订单数据和核销结果数据
intent.putExtra("order_data", new Gson().toJson(order));
if (data != null) {
intent.putExtra("verify_result", new Gson().toJson(data));
}
startActivity(intent);
// 准备返回结果给调用Activity
Intent resultIntent = new Intent();
resultIntent.putExtra("selected_order", new Gson().toJson(order));
resultIntent.putExtra("order_no", order.getOrder_no());
resultIntent.putExtra("verification_code", verifyCode);
resultIntent.putExtra("order_type", order.getOrder_type());
resultIntent.putExtra("card_no", order.getInfo() != null ? order.getInfo().getCard_no() : "");
resultIntent.putExtra("project", order.getProject());
resultIntent.putExtra("verification_type", verificationType);
resultIntent.putExtra("verify_status", status);
resultIntent.putExtra("verify_message", message);
setResult(RESULT_OK, resultIntent);
finish();
});
}
@Override
public void onError(int errorCode, String errorMessage) {
LogManager.logError(TAG, "核销请求失败: errorCode=" + errorCode + ", errorMessage=" + errorMessage);
runOnUiThread(() -> {
String displayMessage = errorMessage != null && !errorMessage.isEmpty()
? errorMessage : "订单核销失败,错误码: " + errorCode;
showToast(displayMessage);
// 核销失败也跳转到结果页面显示失败信息
Intent intent = new Intent(OrderSelectionActivity.this, OrderVerificationResultActivity.class);
intent.putExtra("verification_type", verificationType);
intent.putExtra("order_no", order.getOrder_no());
intent.putExtra("verification_code", verifyCode);
intent.putExtra("order_type", order.getOrder_type());
intent.putExtra("card_no", order.getInfo() != null ? order.getInfo().getCard_no() : "");
intent.putExtra("project", order.getProject());
intent.putExtra("status", "核销失败");
intent.putExtra("message", displayMessage);
intent.putExtra("order_data", new Gson().toJson(order));
startActivity(intent);
// 设置失败结果
Intent resultIntent = new Intent();
resultIntent.putExtra("selected_order", new Gson().toJson(order));
resultIntent.putExtra("order_no", order.getOrder_no());
resultIntent.putExtra("verification_code", verifyCode);
resultIntent.putExtra("verification_type", verificationType);
resultIntent.putExtra("verify_status", "核销失败");
resultIntent.putExtra("verify_message", displayMessage);
setResult(RESULT_OK, resultIntent);
finish();
});
}
@Override
public void onException(Throwable throwable) {
LogManager.logError(TAG, "核销请求异常", throwable);
runOnUiThread(() -> {
String displayMessage = "网络请求异常: " + throwable.getMessage();
showToast(displayMessage);
// 异常情况也跳转到结果页面显示异常信息
Intent intent = new Intent(OrderSelectionActivity.this, OrderVerificationResultActivity.class);
intent.putExtra("verification_type", verificationType);
intent.putExtra("order_no", order.getOrder_no());
intent.putExtra("verification_code", verifyCode);
intent.putExtra("order_type", order.getOrder_type());
intent.putExtra("card_no", order.getInfo() != null ? order.getInfo().getCard_no() : "");
intent.putExtra("project", order.getProject());
intent.putExtra("status", "核销异常");
intent.putExtra("message", displayMessage);
intent.putExtra("order_data", new Gson().toJson(order));
startActivity(intent);
// 设置异常结果
Intent resultIntent = new Intent();
resultIntent.putExtra("selected_order", new Gson().toJson(order));
resultIntent.putExtra("order_no", order.getOrder_no());
resultIntent.putExtra("verification_code", verifyCode);
resultIntent.putExtra("verification_type", verificationType);
resultIntent.putExtra("verify_status", "核销异常");
resultIntent.putExtra("verify_message", displayMessage);
setResult(RESULT_OK, resultIntent);
finish();
});
}
@Override
public void onComplete() {
LogManager.logInfo(TAG, "核销请求完成");
}
}
);
}
/**

101
app/src/main/java/com/ouxuan/oxface/orderOX/OrderVerificationResultActivity.java

@ -28,9 +28,9 @@ public class OrderVerificationResultActivity extends AppCompatActivity {
private ImageButton btnClose;
private Button btnConfirm;
private TextView tvTitle, tvOrderNo, tvVerificationCode, tvOrderType, tvCardNo, tvStatus;
private String orderNo, verificationCode, orderType, cardNo, status;
private int verificationType; // 1-验证码验证, 4-扫码器验证
private TextView tvTitle, tvOrderNo, tvVerificationCode, tvOrderType, tvCardNo, tvStatus, tvMessage, tvProject;
private String orderNo, verificationCode, orderType, cardNo, status, message, project;
private int verificationType; // 1-验证码验证, 2-人脸验证, 3-扫码验证, 4-扫码器验证
// 强制关闭广播接收器
private BroadcastReceiver forceCloseReceiver;
@ -78,6 +78,8 @@ public class OrderVerificationResultActivity extends AppCompatActivity {
tvOrderType = findViewById(R.id.tv_order_type);
tvCardNo = findViewById(R.id.tv_card_no);
tvStatus = findViewById(R.id.tv_status);
tvMessage = findViewById(R.id.tv_message); // 新增消息显示
tvProject = findViewById(R.id.tv_project); // 新增项目显示
}
private void getIntentData() {
@ -90,6 +92,19 @@ public class OrderVerificationResultActivity extends AppCompatActivity {
orderType = String.valueOf(orderTypeInt);
cardNo = intent.getStringExtra("card_no");
status = intent.getStringExtra("status");
message = intent.getStringExtra("message"); // 获取核销结果消息
project = intent.getStringExtra("project"); // 获取项目名称
// 输出调试日志
LogManager.logInfo(TAG, "收到核销结果数据: ");
LogManager.logInfo(TAG, "verificationType: " + verificationType);
LogManager.logInfo(TAG, "orderNo: " + orderNo);
LogManager.logInfo(TAG, "verificationCode: " + verificationCode);
LogManager.logInfo(TAG, "orderType: " + orderType);
LogManager.logInfo(TAG, "cardNo: " + cardNo);
LogManager.logInfo(TAG, "status: " + status);
LogManager.logInfo(TAG, "message: " + message);
LogManager.logInfo(TAG, "project: " + project);
}
// 设置默认值
@ -98,16 +113,28 @@ public class OrderVerificationResultActivity extends AppCompatActivity {
if (orderType == null) orderType = "";
if (cardNo == null) cardNo = "";
if (status == null) status = "核销成功";
if (message == null) message = "订单核销成功";
if (project == null) project = "";
}
private void updateUI() {
// 根据验证类型设置标题
if (verificationType == 1) {
tvTitle.setText("验证码核销结果");
} else if (verificationType == 4) {
tvTitle.setText("扫码器核销结果");
} else {
tvTitle.setText("订单核销结果");
switch (verificationType) {
case 1:
tvTitle.setText("验证码核销结果");
break;
case 2:
tvTitle.setText("人脸核销结果");
break;
case 3:
tvTitle.setText("扫码核销结果");
break;
case 4:
tvTitle.setText("扫码器核销结果");
break;
default:
tvTitle.setText("订单核销结果");
break;
}
// 更新UI内容
@ -116,6 +143,39 @@ public class OrderVerificationResultActivity extends AppCompatActivity {
tvOrderType.setText(orderType);
tvCardNo.setText(cardNo);
tvStatus.setText(status);
// 更新新增的字段
if (tvMessage != null) {
tvMessage.setText(message);
}
if (tvProject != null && project != null && !project.isEmpty()) {
tvProject.setText(project);
// 显示项目布局
View projectLayout = findViewById(R.id.ll_project);
if (projectLayout != null) {
projectLayout.setVisibility(View.VISIBLE);
}
} else {
// 隐藏项目布局
View projectLayout = findViewById(R.id.ll_project);
if (projectLayout != null) {
projectLayout.setVisibility(View.GONE);
}
}
// 根据核销状态设置不同的UI样式
if (status != null) {
if (status.contains("成功")) {
// 成功状态 - 绿色
tvStatus.setTextColor(getResources().getColor(android.R.color.holo_green_dark));
} else if (status.contains("失败") || status.contains("异常")) {
// 失败或异常状态 - 红色
tvStatus.setTextColor(getResources().getColor(android.R.color.holo_red_dark));
} else {
// 默认状态 - 黑色
tvStatus.setTextColor(getResources().getColor(android.R.color.black));
}
}
}
private void setupListeners() {
@ -138,7 +198,28 @@ public class OrderVerificationResultActivity extends AppCompatActivity {
private void handleConfirm() {
LogManager.logInfo(TAG, "用户确认订单核销结果");
Toast.makeText(this, "订单核销完成", Toast.LENGTH_SHORT).show();
// 根据核销状态显示不同的确认消息
String confirmMessage = "订单核销完成";
if (status != null) {
if (status.contains("成功")) {
confirmMessage = "订单核销成功完成";
} else if (status.contains("失败")) {
confirmMessage = "订单核销失败,已确认";
} else if (status.contains("异常")) {
confirmMessage = "订单核销异常,已确认";
}
}
Toast.makeText(this, confirmMessage, Toast.LENGTH_SHORT).show();
// 保留语音播放和继电器开门功能的注释但暂时不实现
// TODO: 根据需要实现语音播放功能
// if (status != null && status.contains("成功")) {
// playSuccessVoice(); // 播放成功语音
// triggerRelayDoor(); // 触发继电器开门
// }
finish();
}

43
app/src/main/res/layout/activity_order_verification_result.xml

@ -154,6 +154,33 @@
</LinearLayout>
<!-- 项目名称 -->
<LinearLayout
android:id="@+id/ll_project"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="项目:"
android:textColor="#666666"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_project"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textColor="#333333"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<!-- 状态信息 -->
@ -163,18 +190,30 @@
android:layout_height="wrap_content"
android:layout_below="@id/ll_order_info"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginBottom="10dp"
android:text="核销成功"
android:textColor="#009874"
android:textSize="16sp"
android:textStyle="bold" />
<!-- 消息信息 -->
<TextView
android:id="@+id/tv_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_status"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:text="订单核销成功"
android:textColor="#666666"
android:textSize="14sp" />
<!-- 确认按钮 -->
<Button
android:id="@+id/btn_confirm_result"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@id/tv_status"
android:layout_below="@id/tv_message"
android:background="@drawable/gradient_button_selector"
android:text="确认"
android:textColor="@android:color/white"

Loading…
Cancel
Save