diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/Repository.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/Repository.kt index c559052c76..2cbd61ad87 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/Repository.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/Repository.kt @@ -30,6 +30,7 @@ internal class Repository { net.get(if (isDriven) "被动" else "主动", itx, 1) itx .takeIf { it.isNotEmpty() } + ?.sortedBy { it.sort } ?.also { store.updateRecords(it, isDriven) } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/net/BadCaseNetModel.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/net/BadCaseNetModel.kt index 4065bfabb5..e643ed63ef 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/net/BadCaseNetModel.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/net/BadCaseNetModel.kt @@ -25,7 +25,7 @@ internal class BadCaseNetModel { } ?.body()?.also { val data = it.data - if (data == null || it.total <= result.size) { + if (data == null || data.isEmpty() || it.total <= result.size) { return@also } result += data diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/net/api/entity/BadCaseResponse.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/net/api/entity/BadCaseResponse.kt index 7829a4d9a9..064130114a 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/net/api/entity/BadCaseResponse.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/badcase/repository/net/api/entity/BadCaseResponse.kt @@ -15,6 +15,7 @@ internal class BadCaseResponse { var id: String? = null var reason: String? = null var channel: String? = null + var sort: String? = null /** * 业务字段,不参与序列化和反序列化 @@ -23,7 +24,7 @@ internal class BadCaseResponse { var isChecked: Boolean = false override fun toString(): String { - return "Reason(id=$id, reason=$reason, channel=$channel, isChecked=$isChecked)" + return "Reason(id=$id, reason=$reason, channel=$channel, sort=$sort, isChecked=$isChecked)" } } } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/feedback/FeedbackManager.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/feedback/FeedbackManager.kt index 93b17a5d3b..fc34ea8fce 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/feedback/FeedbackManager.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/feedback/FeedbackManager.kt @@ -24,7 +24,6 @@ import com.zhjt.mogo_core_function_devatools.feedback.biz.bean.Feedback.BadCase import com.zhjt.mogo_core_function_devatools.feedback.biz.impl.FeedbackPresenter import com.zhjt.mogo_core_function_devatools.feedback.callback.IFeedbackCallback import kotlinx.coroutines.* -import kotlinx.coroutines.channels.Channel import record_cache.RecordPanelOuterClass import java.lang.IllegalStateException import kotlin.Result.Companion @@ -35,15 +34,6 @@ internal object FeedbackManager { private var hideFloat: (() -> Unit)? = null private val presenter by lazy { FeedbackPresenter() } - @OptIn(ExperimentalCoroutinesApi::class) - private var autoPilotCallback = Channel(Channel.RENDEZVOUS) - @Synchronized - get() = if (field.isClosedForReceive || field.isClosedForSend) { - field = Channel(Channel.RENDEZVOUS) - field - } else field - - fun showFeedbackWindow(ctx: Context) { CallerHmiManager.showFloatWindow("Feedback", FeedBackView(ctx).also { itx -> itx.registerCallback(object : IFeedbackCallback { @@ -79,20 +69,32 @@ internal object FeedbackManager { val listener = object : IMoGoAutopilotIdentifyListener { override fun onAutopilotRecordResult(recordPanel: RecordPanelOuterClass.RecordPanel) { super.onAutopilotRecordResult(recordPanel) - val newRecord = recordPanel.toRecord() - Log.d(TAG, "-- 收到工控机录制任务回调 -- $recordPanel") - if (newRecord.type == 1 && newRecord.id == taskId) { - if (newRecord.stat == 100 || newRecord.stat == 101) { - Log.d(TAG, "录制Bag完成, 触发结束录制全量日志 ...") - stopRecordLog(newRecord) - launch { - send(newRecord) + launch { + val newRecord = recordPanel.toRecord() + Log.d(TAG, "-- 收到工控机录制任务回调 -- $recordPanel") + if (newRecord.type == 1 && newRecord.id == taskId) { + when(newRecord.stat) { + 100, 101 -> { + //成功结束录制 + stopRecordLog(newRecord) + launch { + val ret = upload(record.context, badCase, checked, newRecord) + if (!ret) { + record.text = "开始录制" + record.setTag(R.id.feed_back_badcase_tag, 0) + } + } + } + 300 -> { + //开始录制 + startRecordLog(newRecord) + } + 200 -> { + TipToast.shortTip("录制失败") + hideFloat?.invoke() + } } } - if (newRecord.stat == 300) { - Log.d(TAG, "录制Bag开始, 触发录制全量日志 ...") - startRecordLog(newRecord) - } } } } @@ -104,27 +106,36 @@ internal object FeedbackManager { record.text = "结束录制" record.setTag(R.id.feed_back_badcase_tag, 1) record.setTag(R.id.feed_back_badcase_taskid_tag, taskId) - recordBag(1, taskId, 20) - Log.d(TAG, "延时20秒开始....") - delay(20000) //延时20秒 - Log.d(TAG, "延时20秒结束....") - stopRecordBag(1, taskId) - upload(record.context, badCase, checked) - }.also { - record.setTag(R.id.feed_back_badcase_job, it) + recordBag(1, taskId) + launch { + Log.d(TAG, "延时20秒开始....") + delay(20000) //延时20秒 + Log.d(TAG, "延时20秒结束....") + stopRecordBag(1, taskId) + }.also { itx -> + itx.invokeOnCompletion { + if (it is CancellationException) { + Log.d(TAG, "延时任务取消") + } + } + record.setTag(R.id.feed_back_badcase_job, itx) + } } } override fun onStopBadCaseRecord(record: TextView) { - val data = itx.adapter.data ?: return - val badCase = data.firstOrNull() as? BadCase ?: return - val checked = badCase.reasons.find { it.isChecked } ?: throw IllegalStateException("这种状态不存在") + val tag = (record.getTag(R.id.feed_back_badcase_tag) as? Int) ?: throw IllegalStateException("这个状态不存在") + if (tag == 2) { + TipToast.shortTip("正在结束录制,请稍候...") + return + } val taskId = (record.getTag(R.id.feed_back_badcase_taskid_tag) as? Int) ?: throw IllegalStateException("TaskId 不存在") val oldJob = record.getTag(R.id.feed_back_badcase_job) as? Job + record.text = "正在结束录制" + record.setTag(R.id.feed_back_badcase_tag, 2) + oldJob?.safeCancel() record.scope.launch { stopRecordBag(1, taskId) - oldJob?.safeCancel() - upload(record.context, badCase, checked) } } }) @@ -135,50 +146,49 @@ internal object FeedbackManager { } private fun startRecordLog(record: AutoPilotRecord) { - //val fileName = record.fileName - //添加全量日志开始录制 + Log.d(TAG, "录制Bag开始, 触发录制全量日志 ...") CallerDevaToolsManager.startCatchLog(1,record.fileName) } private fun stopRecordLog(newRecord: AutoPilotRecord) { - //val fileName = record.fileName - //添加全量日志结束录制 + Log.d(TAG, "录制Bag完成, 触发结束录制全量日志 ...") CallerDevaToolsManager.startCatchLog() } - private suspend fun upload(ctx: Context, badCase: BadCase, checked: Reason) { - val result = receive() - val remark = badCase.remark.text - presenter.upload(mutableMapOf().also { itx -> - itx["carLicense"] = MoGoAiCloudClientConfig.getInstance().sn - itx["filename"] = result.fileName ?: "" - itx["filesize"] = result.total.toString() - itx["key"] = result.key ?: "" - itx["reason"] = checked.reason ?: "" - itx["duration"] = result.duration.toInt().toString() - itx["timestamp"] = result.timestamp - itx["channel"] = "1" - if (!TextUtils.isEmpty(remark)) { - itx["remark"] = remark.toString() - } - }).also { - if (it == null || it.code != 200) { - ctx.toast("上报失败") - } else { - ctx.toast("上报成功") - hideFloat?.invoke() + private suspend fun upload(ctx: Context, badCase: BadCase, checked: Reason, record: AutoPilotRecord): Boolean { + try { + val remark = badCase.remark.text + return presenter.upload(mutableMapOf().also { itx -> + itx["carLicense"] = MoGoAiCloudClientConfig.getInstance().sn + itx["filename"] = record.fileName ?: "" + itx["filesize"] = record.total.toString() + itx["key"] = record.key ?: "" + itx["reason"] = checked.reason ?: "" + itx["duration"] = record.duration.toInt().toString() + itx["timestamp"] = record.timestamp + itx["channel"] = "1" + if (!TextUtils.isEmpty(remark)) { + itx["remark"] = remark.toString() + } + }).let { + if (it == null || it.code != 200) { + ctx.toast("上报失败") + false + } else { + ctx.toast("上报成功") + hideFloat?.invoke() + true + } } + } catch (t: Throwable) { + return false } } - private suspend fun send(record: AutoPilotRecord) = autoPilotCallback.send(record) - - private suspend fun receive(): AutoPilotRecord = autoPilotCallback.receive() - - private suspend fun recordBag(type: Int, id: Int, duration: Int) = suspendCancellableCoroutine { + private suspend fun recordBag(type: Int, id: Int) = suspendCancellableCoroutine { val future = ThreadUtils.getIoPool().submit { try { - CallerAutoPilotManager.recordPackage(type, id, duration) + CallerAutoPilotManager.recordPackage(type, id) it.resumeWith(Result.success(Unit)) } catch (t: Throwable) { it.resumeWith(Companion.failure(t))