浏览代码

新增主号批量删除

yangyang 3 月之前
父节点
当前提交
e19f0919ff

+ 2 - 2
app/build.gradle

@@ -9,8 +9,8 @@ android {
         applicationId "com.rk.worktool"
         minSdkVersion 24
         targetSdkVersion 30
-        versionCode 20250730
-        versionName "2.9.9"
+        versionCode 20250822
+        versionName "3.0.1"
     }
 
     buildTypes {

+ 1 - 0
app/src/main/java/org/yameida/worktool/model/WeworkMessageBean.java

@@ -110,6 +110,7 @@ public class WeworkMessageBean {
 
     public static final int PUBLISH_MOMENTS = 236;
 
+    public static final int DELETE_FRIEND = 237;
     public static final int ROBOT_LOG = 301;
     public static final int ROBOT_ERROR_LOG = 302;
     public static final int ROBOT_CONTROLLER_TEST = 303;

+ 3 - 0
app/src/main/java/org/yameida/worktool/service/MyLooper.kt

@@ -400,6 +400,9 @@ object MyLooper {
             WeworkMessageBean.PUBLISH_MOMENTS -> {
                 WeworkController.publishMoments(message)
             }
+            WeworkMessageBean.DELETE_FRIEND -> {
+                WeworkController.deleteFriends(message)
+            }
         }
     }
 }

+ 9 - 0
app/src/main/java/org/yameida/worktool/service/WeworkController.kt

@@ -780,4 +780,13 @@ object WeworkController {
     fun publishMoments(message: WeworkMessageBean):Boolean{
         return WeworkOperationImpl.publishMoments(message)
     }
+
+    /**
+     * 删除单向好友
+     * @see WeworkMessageBean.GET_CORP_LIST
+     */
+    @RequestMapping
+    fun deleteFriends(message: WeworkMessageBean):Boolean{
+        return WeworkOperationImpl.deleteFriends(message)
+    }
 }

+ 180 - 2
app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt

@@ -244,12 +244,21 @@ object WeworkOperationImpl {
         originalContent: String,
         textType: Int,
         nameList: List<String>,
-        extraText: String? = null
+        extraText: String? = null,
+        maxRetryCount: Int? = null
     ): Boolean {
         val startTime = System.currentTimeMillis()
+        val retryCount = maxRetryCount ?: 2
         for (title in LinkedHashSet(titleList)) {
             if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) {
                 if (!receivedName.isNullOrEmpty()) {
+                    AccessibilityUtil.scrollAndFindByText(
+                        WeworkController.weworkService,
+                        getRoot(),
+                        originalContent,
+                        exact = true
+                    )
+                    sleep(Constant.LONG_INTERVAL)
                     if (WeworkTextUtil.longClickMessageItem(
                             //聊天消息列表 1ListView 0RecycleView xViewGroup
                             AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView),
@@ -297,6 +306,19 @@ object WeworkOperationImpl {
                             return false
                         }
                     } else {
+                        if (retryCount > 0) {
+                            goHome()
+                            return relayMessage(
+                                message,
+                                titleList,
+                                receivedName,
+                                originalContent,
+                                textType,
+                                nameList,
+                                extraText,
+                                retryCount - 1
+                            )
+                        }
                         LogUtils.e("$title: 长按条目失败 $originalContent")
                         uploadCommandResult(
                             message,
@@ -309,6 +331,13 @@ object WeworkOperationImpl {
                         return false
                     }
                 } else {
+                    AccessibilityUtil.scrollAndFindByText(
+                        WeworkController.weworkService,
+                        getRoot(),
+                        originalContent,
+                        exact = true
+                    )
+                    sleep(Constant.LONG_INTERVAL)
                     if (WeworkTextUtil.longClickMyMessageItem(
                             //聊天消息列表 1ListView 0RecycleView xViewGroup
                             AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView),
@@ -353,6 +382,19 @@ object WeworkOperationImpl {
                             return false
                         }
                     } else {
+                        if (retryCount > 0) {
+                            goHome()
+                            return relayMessage(
+                                message,
+                                titleList,
+                                receivedName,
+                                originalContent,
+                                textType,
+                                nameList,
+                                extraText,
+                                retryCount - 1
+                            )
+                        }
                         LogUtils.e("$title: 长按条目失败 $originalContent")
                         uploadCommandResult(
                             message,
@@ -2541,7 +2583,8 @@ object WeworkOperationImpl {
                 originalContent,
                 textType,
                 nameList,
-                extraText
+                extraText,
+                retryCount
             )
         }
         for (title in LinkedHashSet(titleList)) {
@@ -7060,4 +7103,139 @@ object WeworkOperationImpl {
         return false
     }
 
+    fun deleteFriends(message: WeworkMessageBean): Boolean {
+        val startTime = System.currentTimeMillis()
+        goHomeTab("通讯录")
+        sleep(Constant.CHANGE_PAGE_INTERVAL)
+        AccessibilityUtil.scrollToTop(WeworkController.weworkService, getRoot())
+        val customerFlag =
+            AccessibilityUtil.findAllByText(getRoot(), "我的客户","我的学员", exact = true).lastOrNull()
+        if (customerFlag != null) {
+            AccessibilityUtil.performClick(customerFlag)
+            AccessibilityExtraUtil.loadingPage("BaseContentActivity")
+            val list =
+                AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView, Views.RecyclerView)
+            if (list == null) {
+                LogUtils.e("未找到我的客户列表")
+                uploadCommandResult(
+                    message,
+                    ExecCallbackBean.ERROR_BUTTON,
+                    "未找到我的客户列表",
+                    startTime
+                )
+                return false
+            }
+            val allCustomer =
+                AccessibilityUtil.findOneByText(getRoot(), "全部微信客户","全部微信学员")
+            if (allCustomer != null) {
+                AccessibilityUtil.performClick(allCustomer)
+                AccessibilityExtraUtil.loadingPage("BaseContentActivity")
+                val oneCustomer =
+                    AccessibilityUtil.findOneByText(getRoot(), "单向微信客户","单向微信学员", exact = true)
+                if (oneCustomer != null) {
+                    AccessibilityUtil.performClick(oneCustomer)
+                    sleep(500)
+                    val editCustomer =
+                        AccessibilityUtil.findOneByText(getRoot(), "编辑", exact = true)
+                    AccessibilityUtil.performClick(editCustomer)
+                    val list = AccessibilityUtil.findOneByClazz(
+                        getRoot(),
+                        Views.ListView,
+                        Views.RecyclerView
+                    )
+                    if (list == null) {
+                        LogUtils.e("未找到我的客户列表")
+                        uploadCommandResult(
+                            message,
+                            ExecCallbackBean.ERROR_BUTTON,
+                            "未找到我的客户列表",
+                            startTime
+                        )
+                        return false
+                    }
+                    val set = linkedSetOf<String>()
+                    val onScrollListener = object : AccessibilityUtil.OnScrollListener() {
+                        override fun onScroll(): Boolean {
+                            if (!AccessibilityExtraUtil.loadingPage("BaseContentActivity")) {
+                                return true
+                            }
+                            list.refresh()
+                            for (i in 0 until list.childCount) {
+                                val item = list.getChild(i)
+                                if (item.className != Views.RelativeLayout) {
+                                    continue
+                                }
+                                val name = AccessibilityUtil.findOneByClazz(
+                                    item,
+                                    Views.TextView
+                                )?.text?.toString()
+                                    ?: continue
+                                if (!name.matches("(标签)|(其他外部联系人)|((共?.*个)?客户)".toRegex())) {
+                                    if (set.size == message.num) {
+                                        return true
+                                    }
+                                    if (!set.contains(name)) {
+                                        AccessibilityUtil.performClick(item)
+                                        set.add(name)
+                                    }
+                                }
+
+                            }
+                            return false
+                        }
+                    }
+                    //滚动前先获取一次
+                    onScrollListener.onScroll()
+                    AccessibilityUtil.scrollToBottom(
+                        WeworkController.weworkService,
+                        list,
+                        listener = onScrollListener,
+                        maxRetry = 100
+                    )
+                    LogUtils.d("客户数量: ${set.size} 客户列表: ${set.joinToString()}")
+                    message.nameList = set.toList()
+                    val delete =
+                        AccessibilityUtil.findOneByText(getRoot(), "删除")
+                    if (delete != null) {
+                        AccessibilityUtil.performClick(delete)
+                        val deleteConfirm =
+                            AccessibilityUtil.findOneByText(getRoot(), "删除联系人")
+                        if (deleteConfirm != null) {
+                            AccessibilityUtil.performClick(deleteConfirm)
+                            uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
+                        } else {
+                            uploadCommandResult(
+                                message,
+                                ExecCallbackBean.ERROR_TARGET,
+                                "找不到确认删除按钮",
+                                startTime
+                            )
+                        }
+                    } else {
+                        uploadCommandResult(
+                            message,
+                            ExecCallbackBean.ERROR_TARGET,
+                            "找不到删除按钮",
+                            startTime
+                        )
+                    }
+                } else {
+                    uploadCommandResult(
+                        message,
+                        ExecCallbackBean.ERROR_TARGET,
+                        "找不到全部单项客户按钮",
+                        startTime
+                    )
+                }
+            }
+        }else{
+            uploadCommandResult(
+                message,
+                ExecCallbackBean.ERROR_TARGET,
+                "找不到我的客户和我的学员按钮",
+                startTime
+            )
+        }
+        return true
+    }
 }