refactor(intent): 移除意图识别帮助类的内置问题轮换功能
- 移除 IntentRecognizeHelper 中的内置问题列表和轮换逻辑 - 修改 recognize 方法参数 text 从可选改为必填字符串类型 - 更新 TaskListData 数据类字段为可空或必需类型 - 修复 HeaderInterceptor 中的 currentUserId 头部值 - 移除 TaskListActivity 中的语音命令解析相关代码和常量 - 优化分页滚动逻辑并移除任务索引打开功能 - 调整 MyApplication 中的 baseurl 配置回退到域名地址 - 移除未使用的导入和扩展函数调用
这个提交包含在:
父节点
3f6eec3e34
当前提交
3a59d11795
@ -15,8 +15,8 @@ import com.xuqm.base.di.manager.HttpManager;
|
||||
*/
|
||||
public class MyApplication extends App {
|
||||
|
||||
// public static String baseUrl = "http://22fs132201.imwork.net";
|
||||
public static String baseUrl = "http://192.168.6.20";
|
||||
public static String baseUrl = "http://22fs132201.imwork.net";
|
||||
// public static String baseUrl = "http://192.168.6.20";
|
||||
|
||||
public static AppComponent appComponent1;
|
||||
|
||||
@ -24,8 +24,8 @@ public class MyApplication extends App {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
appComponent = HttpManager.getAppComponent(baseUrl, new HeaderInterceptor(getApplicationContext()));
|
||||
// appComponent1 = HttpManager.getAppComponent("https://22v1322u01.vicp.fun", new HeaderInterceptor(getApplicationContext()));
|
||||
appComponent1 = HttpManager.getAppComponent("http://192.168.6.20:12119", new HeaderInterceptor(getApplicationContext()));
|
||||
appComponent1 = HttpManager.getAppComponent("https://22v1322u01.vicp.fun", new HeaderInterceptor(getApplicationContext()));
|
||||
// appComponent1 = HttpManager.getAppComponent("http://192.168.6.20:12119", new HeaderInterceptor(getApplicationContext()));
|
||||
|
||||
initSdk();
|
||||
|
||||
|
||||
@ -11,34 +11,28 @@ import com.xuqm.base.extensions.showMessage
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlin.jvm.java
|
||||
|
||||
/**
|
||||
* 意图识别全局工具。
|
||||
*
|
||||
* - [recognize] 发起识别请求;自动轮换内置问题作为 text(非 Welcome 页调用)。
|
||||
* - [recognize] 发起识别请求。
|
||||
* - [dispose] 在页面销毁时调用,取消进行中的请求。
|
||||
*/
|
||||
object IntentRecognizeHelper {
|
||||
|
||||
private val builtInQuestions = listOf(
|
||||
"C大脑V2.24版本进行到什么阶段了",
|
||||
"我的任务有哪些",
|
||||
"个人任务系统功能的需求来自哪个项目",
|
||||
"浙江华瑞项目有哪些进行中的采购流程"
|
||||
)
|
||||
private var questionIndex = 0
|
||||
private var disposable: Disposable? = null
|
||||
|
||||
/**
|
||||
* @param text 指定问题文本;为 null 时自动轮换内置问题
|
||||
* @param scence 场景标识,默认 "home"
|
||||
* @param extra 额外上下文数据(如 list 场景下的任务列表),原样传给服务端
|
||||
* @param actions 允许的 action 列表,默认全部
|
||||
* @param text 识别文本(必填)
|
||||
* @param scence 场景标识,默认 "home"
|
||||
* @param extra 额外上下文数据(如 list 场景下的任务列表),原样传给服务端
|
||||
* @param actions 允许的 action 列表,默认全部
|
||||
* @param onSuccess 识别成功且 code=="0" 时回调,参数为 [RecognizeAction]
|
||||
* @param onComplete 无论成功失败都会回调,用于调用方重置 loading 状态
|
||||
*/
|
||||
fun recognize(
|
||||
text: String? = null,
|
||||
text: String,
|
||||
scence: String = "home",
|
||||
extra: List<Any> = emptyList(),
|
||||
actions: List<String> = listOf("goToTaskCenter", "goToDecisionCenter"),
|
||||
@ -46,11 +40,8 @@ object IntentRecognizeHelper {
|
||||
onComplete: () -> Unit = {}
|
||||
) {
|
||||
disposable?.dispose()
|
||||
val question = text ?: nextQuestion()
|
||||
disposable = HttpManager.getApi(
|
||||
MyApplication.appComponent1, Service::class.java
|
||||
)
|
||||
.recognize(RecognizeData(text = question, scence = scence, extra = extra, actions = actions))
|
||||
disposable = HttpManager.getApi(MyApplication.appComponent1, Service::class.java)
|
||||
.recognize(RecognizeData(text = text, scence = scence, extra = extra, actions = actions))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ model ->
|
||||
@ -70,10 +61,4 @@ object IntentRecognizeHelper {
|
||||
disposable?.dispose()
|
||||
disposable = null
|
||||
}
|
||||
|
||||
private fun nextQuestion(): String {
|
||||
val q = builtInQuestions[questionIndex % builtInQuestions.size]
|
||||
questionIndex++
|
||||
return q
|
||||
}
|
||||
}
|
||||
@ -12,9 +12,9 @@ package com.nova.brain.glass.model.data
|
||||
data class TaskListData(
|
||||
val taskType: String,
|
||||
val keyword: String,
|
||||
val dateRange: Int,
|
||||
val dateRange: Int?,
|
||||
val dateType: Int,
|
||||
val isOverdue: Int=2,
|
||||
val userId: String = "AI0022",
|
||||
val tenantId: Int = 1,
|
||||
val isOverdue: Int,
|
||||
val userId: String,
|
||||
val tenantId: Int,
|
||||
)
|
||||
|
||||
@ -27,7 +27,7 @@ class HeaderInterceptor(val context: Context) : Interceptor {
|
||||
.addHeader("Content-Type", "application/json;charset=UTF-8")
|
||||
.addHeader("Cookie", "__itrace_wid=87125211-8742-4f12-b5ca-32b9b6c860e4; locale=zh-Hans; _webtracing_device_id=t_13501877-b9b303fc-d3f52eb530e026b0")
|
||||
.addHeader("Environment", "1")
|
||||
.addHeader("currentUserId", "rokid1")
|
||||
.addHeader("currentUserId", "rokid")
|
||||
.addHeader("terminal", "1")
|
||||
.addHeader("modulename", "web")
|
||||
.addHeader("currentUserName", "")
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package com.nova.brain.glass.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.nova.brain.glass.R
|
||||
@ -18,7 +18,6 @@ import com.xuqm.base.adapter.CommonPagedAdapter
|
||||
import com.xuqm.base.adapter.ViewHolder
|
||||
import com.xuqm.base.common.LogHelper
|
||||
import com.xuqm.base.common.ToolsHelper
|
||||
import com.xuqm.base.extensions.log
|
||||
import com.xuqm.base.ui.BaseListFormLayoutActivity
|
||||
|
||||
class TaskListActivity :
|
||||
@ -28,30 +27,7 @@ class TaskListActivity :
|
||||
private var pageStartPosition = 0
|
||||
|
||||
companion object {
|
||||
// 序数词到索引的映射
|
||||
private val ORDINAL_INDEX = mapOf(
|
||||
"第一" to 0, "第二" to 1, "第三" to 2, "第四" to 3,
|
||||
"第五" to 4, "第六" to 5, "第七" to 6, "第八" to 7,
|
||||
"第九" to 8, "第十" to 9
|
||||
)
|
||||
// 单字序数词(口语化)到索引的映射
|
||||
private val SHORT_ORDINAL_INDEX = mapOf(
|
||||
"第一个" to 0, "第一条" to 0, "第一项" to 0,
|
||||
"第二个" to 1, "第二条" to 1, "第二项" to 1,
|
||||
"第三个" to 2, "第三条" to 2, "第三项" to 2,
|
||||
"第四个" to 3, "第四条" to 3, "第四项" to 3,
|
||||
"第五个" to 4, "第五条" to 4, "第五项" to 4,
|
||||
"第六个" to 5, "第六条" to 5, "第六项" to 5,
|
||||
"第七个" to 6, "第七条" to 6, "第七项" to 6,
|
||||
"第八个" to 7, "第八条" to 7, "第八项" to 7,
|
||||
"第九个" to 8, "第九条" to 8, "第九项" to 8,
|
||||
"第十个" to 9, "第十条" to 9, "第十项" to 9
|
||||
)
|
||||
private val TASK_PREFIXES = listOf("查看", "打开", "处理")
|
||||
private val TASK_SUFFIXES = listOf("任务", "条任务", "项任务", "个任务")
|
||||
private val NEXT_PAGE_CMDS = setOf("下一页", "翻页", "查看下一页", "继续翻页", "继续下一页")
|
||||
private val PREV_PAGE_CMDS = setOf("上一页", "查看上一页", "继续上一页")
|
||||
private val EXIT_CMDS = setOf("退出", "返回", "退回")
|
||||
private val EXIT_CMDS = setOf("退出", "返回", "退回", "关闭")
|
||||
}
|
||||
|
||||
override fun initView(savedInstanceState: Bundle?) {
|
||||
@ -68,12 +44,8 @@ class TaskListActivity :
|
||||
refreshVisibleOrder()
|
||||
}
|
||||
|
||||
binding.xia.setOnClickListener {
|
||||
toNext()
|
||||
}
|
||||
binding.shang.setOnClickListener {
|
||||
toPre()
|
||||
}
|
||||
binding.xia.setOnClickListener { toNext() }
|
||||
binding.shang.setOnClickListener { toPre() }
|
||||
|
||||
viewModel.taskCount.observe(this) { count ->
|
||||
binding.tvTaskHeader.text = "查询到您当前有${count}条任务,信息如下:"
|
||||
@ -81,11 +53,10 @@ class TaskListActivity :
|
||||
}
|
||||
|
||||
override fun initData() {
|
||||
|
||||
viewModel.searchParams = TaskListData(
|
||||
taskType = intent.getStringExtra("taskType") ?: "",
|
||||
keyword = intent.getStringExtra("keyword") ?: "",
|
||||
dateRange = intent.getIntExtra("dateRange", 0),
|
||||
dateRange = intent.getIntExtra("dateRange", -1).takeIf { it >= 0 },
|
||||
dateType = intent.getIntExtra("dateType", 0),
|
||||
isOverdue = intent.getIntExtra("isOverdue", 2),
|
||||
tenantId = intent.getIntExtra("tenantId", 1),
|
||||
@ -96,101 +67,52 @@ class TaskListActivity :
|
||||
|
||||
private val offlineCmdListener = object : OfflineCmdListener {
|
||||
override fun onOfflineCmd(cmd: String) {
|
||||
runOnUiThread { dispatchVoiceCmd(cmd) }
|
||||
if (cmd in EXIT_CMDS) runOnUiThread { finish() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun dispatchVoiceCmd(cmd: String) {
|
||||
when {
|
||||
cmd in EXIT_CMDS -> finish()
|
||||
cmd in NEXT_PAGE_CMDS -> {
|
||||
"--------------->".log()
|
||||
toNext()
|
||||
}
|
||||
cmd in PREV_PAGE_CMDS -> toPre()
|
||||
else -> resolveTaskIndex(cmd)?.let { openVisibleTask(it) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将语音命令解析为任务序号(0-based),无法识别则返回 null。
|
||||
* 支持格式:「第N个/条/项」、「查看/打开/处理 + 第N条/项/个 + 任务(可省)」
|
||||
*/
|
||||
private fun resolveTaskIndex(cmd: String): Int? {
|
||||
SHORT_ORDINAL_INDEX[cmd]?.let { return it }
|
||||
val prefix = TASK_PREFIXES.firstOrNull { cmd.startsWith(it) } ?: return null
|
||||
val body = cmd.removePrefix(prefix)
|
||||
val ordinalEntry = ORDINAL_INDEX.entries.firstOrNull { body.startsWith(it.key) } ?: return null
|
||||
return ordinalEntry.value
|
||||
}
|
||||
|
||||
private fun toPre() {
|
||||
val layoutManager = binding.baseRecyclerView.layoutManager as? LinearLayoutManager
|
||||
if (layoutManager != null) {
|
||||
val firstVisible = layoutManager.findFirstVisibleItemPosition()
|
||||
if (firstVisible > 0) {
|
||||
val lastVisible = layoutManager.findLastVisibleItemPosition()
|
||||
val pageSize = (lastVisible - firstVisible).coerceAtLeast(1)
|
||||
val previousPosition = (firstVisible - pageSize).coerceAtLeast(0)
|
||||
layoutManager.scrollToPositionWithOffset(previousPosition, 0)
|
||||
binding.baseRecyclerView.post { refreshVisibleOrder() }
|
||||
} else {
|
||||
ToolsHelper.showMessage("没有上一页了")
|
||||
}
|
||||
val lm = binding.baseRecyclerView.layoutManager as? LinearLayoutManager ?: return
|
||||
val firstVisible = lm.findFirstVisibleItemPosition()
|
||||
if (firstVisible > 0) {
|
||||
val pageSize = (lm.findLastVisibleItemPosition() - firstVisible).coerceAtLeast(1)
|
||||
lm.scrollToPositionWithOffset((firstVisible - pageSize).coerceAtLeast(0), 0)
|
||||
binding.baseRecyclerView.post { refreshVisibleOrder() }
|
||||
} else {
|
||||
ToolsHelper.showMessage("没有上一页了")
|
||||
}
|
||||
}
|
||||
|
||||
private fun toNext() {
|
||||
val layoutManager = binding.baseRecyclerView.layoutManager as? LinearLayoutManager
|
||||
if (layoutManager != null) {
|
||||
val lastVisible = layoutManager.findLastVisibleItemPosition()
|
||||
LogHelper.d("lastVisible:$lastVisible")
|
||||
val nextPosition = lastVisible + 1
|
||||
if (nextPosition < adapter.itemCount) {
|
||||
layoutManager.scrollToPositionWithOffset(nextPosition, 0)
|
||||
binding.baseRecyclerView.post { refreshVisibleOrder() }
|
||||
} else {
|
||||
ToolsHelper.showMessage("没有下一页了")
|
||||
}
|
||||
val lm = binding.baseRecyclerView.layoutManager as? LinearLayoutManager ?: return
|
||||
val lastVisible = lm.findLastVisibleItemPosition()
|
||||
LogHelper.d("lastVisible:$lastVisible")
|
||||
val nextPosition = lastVisible + 1
|
||||
if (nextPosition < adapter.itemCount) {
|
||||
lm.scrollToPositionWithOffset(nextPosition, 0)
|
||||
binding.baseRecyclerView.post { refreshVisibleOrder() }
|
||||
} else {
|
||||
ToolsHelper.showMessage("没有下一页了")
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshVisibleOrder() {
|
||||
val layoutManager = binding.baseRecyclerView.layoutManager as? LinearLayoutManager ?: return
|
||||
val firstVisible = layoutManager.findFirstVisibleItemPosition()
|
||||
if (firstVisible == RecyclerView.NO_POSITION || firstVisible == pageStartPosition) {
|
||||
return
|
||||
}
|
||||
val lm = binding.baseRecyclerView.layoutManager as? LinearLayoutManager ?: return
|
||||
val firstVisible = lm.findFirstVisibleItemPosition()
|
||||
if (firstVisible == RecyclerView.NO_POSITION || firstVisible == pageStartPosition) return
|
||||
pageStartPosition = firstVisible
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun openVisibleTask(offset: Int) {
|
||||
val layoutManager = binding.baseRecyclerView.layoutManager as? LinearLayoutManager ?: return
|
||||
val firstVisible = layoutManager.findFirstVisibleItemPosition()
|
||||
if (firstVisible == RecyclerView.NO_POSITION) {
|
||||
return
|
||||
}
|
||||
val targetPosition = firstVisible + offset
|
||||
val lastVisible = layoutManager.findLastVisibleItemPosition()
|
||||
if (targetPosition > lastVisible || targetPosition >= adapter.itemCount) {
|
||||
return
|
||||
}
|
||||
openTask(targetPosition)
|
||||
}
|
||||
|
||||
private fun openTask(position: Int) {
|
||||
when (position % 4) {
|
||||
0 -> startActivity(Intent(this@TaskListActivity, FoActivity::class.java))
|
||||
1 -> startActivity(Intent(this@TaskListActivity, ReviewActivity::class.java))
|
||||
2 -> startActivity(Intent(this@TaskListActivity, InspectionActivity::class.java))
|
||||
3 -> startActivity(Intent(this@TaskListActivity, SprayingActivity::class.java))
|
||||
}
|
||||
val item = viewModel.currentItems.getOrNull(position) ?: return
|
||||
Log.d("TaskListActivity", "openTask position=$position item=$item")
|
||||
// TODO: 根据 item.taskType / item.params 路由到对应 Activity
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
OfflineCmdServiceHelper.addListenerList()
|
||||
LogHelper.d(">>>>>>>>>>>>--------------------")
|
||||
OfflineCmdServiceHelper.addOnLineListener(offlineCmdListener)
|
||||
AsrHelper.scene = "list"
|
||||
AsrHelper.extraProvider = {
|
||||
@ -205,15 +127,8 @@ class TaskListActivity :
|
||||
}
|
||||
}
|
||||
AsrHelper.onGoToDecisionCenter = { action ->
|
||||
val taskId = action.params.taskId
|
||||
val taskIndex = action.params.taskIndex
|
||||
when {
|
||||
taskId != null -> {
|
||||
val position = viewModel.currentItems.indexOfFirst { it.id == taskId }
|
||||
if (position >= 0) openTask(position)
|
||||
}
|
||||
taskIndex != null -> openVisibleTask(taskIndex - 1)
|
||||
}
|
||||
// 暂只打日志,等确认返回结构后处理
|
||||
Log.d("TaskListActivity", "recognize result: $action")
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,12 +144,9 @@ class TaskListActivity :
|
||||
private val adapter = object : CommonPagedAdapter<TaskItem>(R.layout.item_task_list) {
|
||||
override fun convert(holder: ViewHolder, item: TaskItem, position: Int) {
|
||||
val displayPosition = (position - pageStartPosition + 1).coerceAtLeast(1)
|
||||
val title = "${displayPosition}. ${item.aiDescription}【${item.processStatus}】"
|
||||
holder
|
||||
.setText(R.id.tv_title, title)
|
||||
.setClickListener(R.id.tv_title) {
|
||||
openTask(position)
|
||||
}
|
||||
.setText(R.id.tv_title, "${displayPosition}. ${item.aiDescription}【${item.processStatus}】")
|
||||
.setClickListener(R.id.tv_title) { openTask(position) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,4 +156,4 @@ class TaskListActivity :
|
||||
super.onDestroy()
|
||||
window.clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -113,7 +113,7 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
||||
Intent(this, TaskListActivity::class.java).apply {
|
||||
putExtra("taskType", params.taskType ?: "")
|
||||
putExtra("keyword", params.keyword ?: "")
|
||||
putExtra("dateRange", params.dateRange ?: 0)
|
||||
params.dateRange?.let { putExtra("dateRange", it) }
|
||||
putExtra("dateType", params.dateTpye ?: 0)
|
||||
putExtra("isOverdue", params.isOverdue ?: 2)
|
||||
putExtra("tenantId", params.tenantId ?: 1)
|
||||
|
||||
@ -14,7 +14,7 @@ import io.reactivex.schedulers.Schedulers
|
||||
class TaskListVM : BaseListViewModel<TaskItem>() {
|
||||
|
||||
var searchParams: TaskListData =
|
||||
TaskListData(taskType = "", keyword = "", dateRange = 0, dateType = 0)
|
||||
TaskListData(taskType = "", keyword = "", dateRange = null, dateType = 0, isOverdue = 2, userId = "", tenantId = 1)
|
||||
|
||||
val taskCount = MutableLiveData<Int>()
|
||||
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户