Merge branch 'master' of https://github.com/gallonyin/worktool
This commit is contained in:
@@ -36,6 +36,7 @@ public class WeworkMessageBean {
|
||||
* 从外部群添加好友 ADD_FRIEND_BY_GROUP
|
||||
* 添加待办 ADD_NEED_DEAL
|
||||
* 打卡 CLOCK_IN
|
||||
* 切换企业 SWITCH_CORP
|
||||
* <p>
|
||||
* 非操作类型 300
|
||||
* 机器人普通日志记录 ROBOT_LOG
|
||||
@@ -47,6 +48,7 @@ public class WeworkMessageBean {
|
||||
* 获取好友信息 GET_FRIEND_INFO
|
||||
* 获取我的信息 GET_MY_INFO
|
||||
* 获取最近聊天列表 GET_RECENT_LIST
|
||||
* 获取企业列表 GET_CORP_LIST
|
||||
*/
|
||||
public static final int HEART_BEAT = 11;
|
||||
public static final int TYPE_RECEIVE_MESSAGE_LIST = 101;
|
||||
@@ -74,6 +76,7 @@ public class WeworkMessageBean {
|
||||
public static final int ADD_FRIEND_BY_GROUP = 220;
|
||||
public static final int ADD_NEED_DEAL = 221;
|
||||
public static final int CLOCK_IN = 222;
|
||||
public static final int SWITCH_CORP = 223;
|
||||
|
||||
public static final int ROBOT_LOG = 301;
|
||||
public static final int ROBOT_ERROR_LOG = 302;
|
||||
@@ -84,6 +87,7 @@ public class WeworkMessageBean {
|
||||
public static final int GET_MY_INFO = 503;
|
||||
public static final int GET_GROUP_QRCODE = 504;
|
||||
public static final int GET_RECENT_LIST = 505;
|
||||
public static final int GET_CORP_LIST = 506;
|
||||
|
||||
/**
|
||||
* roomType
|
||||
|
||||
@@ -169,6 +169,9 @@ object MyLooper {
|
||||
WeworkMessageBean.CLOCK_IN -> {
|
||||
WeworkController.clockIn(message)
|
||||
}
|
||||
WeworkMessageBean.SWITCH_CORP -> {
|
||||
WeworkController.switchCorp(message)
|
||||
}
|
||||
WeworkMessageBean.SHOW_GROUP_INFO -> {
|
||||
WeworkController.showGroupInfo(message)
|
||||
}
|
||||
@@ -184,6 +187,9 @@ object MyLooper {
|
||||
WeworkMessageBean.GET_RECENT_LIST -> {
|
||||
WeworkController.getRecentList(message)
|
||||
}
|
||||
WeworkMessageBean.GET_CORP_LIST -> {
|
||||
WeworkController.getCorpList(message)
|
||||
}
|
||||
WeworkMessageBean.ROBOT_CONTROLLER_TEST -> {
|
||||
WeworkController.test(message)
|
||||
}
|
||||
|
||||
@@ -230,6 +230,17 @@ object WeworkController {
|
||||
return WeworkOperationImpl.clockIn(message)
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换企业
|
||||
* @see WeworkMessageBean.SWITCH_CORP
|
||||
* @param message#objectName 企业名称
|
||||
*/
|
||||
@RequestMapping
|
||||
fun switchCorp(message: WeworkMessageBean): Boolean {
|
||||
LogUtils.d("switchCorp(): ${message.objectName}")
|
||||
return WeworkOperationImpl.switchCorp(message, message.objectName)
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送微盘图片
|
||||
* @see WeworkMessageBean.PUSH_MICRO_DISK_IMAGE
|
||||
@@ -401,4 +412,14 @@ object WeworkController {
|
||||
return WeworkGetImpl.getRecentList(message)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业列表
|
||||
* @see WeworkMessageBean.GET_CORP_LIST
|
||||
*/
|
||||
@RequestMapping
|
||||
fun getCorpList(message: WeworkMessageBean): Boolean {
|
||||
LogUtils.d("getCorpList():")
|
||||
return WeworkGetImpl.getCorpList(message)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -87,7 +87,7 @@ object WeworkGetImpl {
|
||||
sumInfo = info.toString()
|
||||
}
|
||||
WeworkController.weworkService.webSocketManager.send(weworkMessageBean)
|
||||
return true
|
||||
return getCorpList(message)
|
||||
} else {
|
||||
LogUtils.d("未找到我的昵称")
|
||||
log("未找到我的昵称")
|
||||
@@ -135,7 +135,7 @@ object WeworkGetImpl {
|
||||
weworkMessageBean.type = WeworkMessageBean.GET_MY_INFO
|
||||
weworkMessageBean.myInfo = myInfo
|
||||
WeworkController.weworkService.webSocketManager.send(weworkMessageBean)
|
||||
return true
|
||||
return getCorpList(message)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,4 +238,39 @@ object WeworkGetImpl {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业列表
|
||||
*/
|
||||
fun getCorpList(message: WeworkMessageBean): Boolean {
|
||||
goHomeTab("消息")
|
||||
val firstTv = AccessibilityUtil.findAllByClazz(getRoot(), Views.TextView)
|
||||
.firstOrNull { it.text == null }
|
||||
AccessibilityUtil.performClick(firstTv, retry = false)
|
||||
sleep(Constant.CHANGE_PAGE_INTERVAL)
|
||||
val listviewList = AccessibilityUtil.findAllOnceByClazz(getRoot(), Views.RecyclerView, Views.ListView, Views.ViewGroup)
|
||||
.filter { it.childCount >= 2 }
|
||||
val list = listviewList.firstOrNull()
|
||||
if (list != null) {
|
||||
val corpList = arrayListOf<String>()
|
||||
for (i in 0 until list.childCount) {
|
||||
val item = list.getChild(i)
|
||||
val tvList = AccessibilityUtil.findAllOnceByClazz(item, Views.TextView)
|
||||
val textList = tvList.filter { it.text != null }.map { it.text.toString() }
|
||||
if (textList.isNotEmpty()) {
|
||||
corpList.add(textList[0])
|
||||
}
|
||||
}
|
||||
LogUtils.d("我的企业", GsonUtils.toJson(corpList))
|
||||
val weworkMessageBean = WeworkMessageBean()
|
||||
weworkMessageBean.type = WeworkMessageBean.GET_CORP_LIST
|
||||
weworkMessageBean.titleList = corpList
|
||||
WeworkController.weworkService.webSocketManager.send(weworkMessageBean)
|
||||
goHome()
|
||||
return true
|
||||
} else {
|
||||
LogUtils.e("未找到企业列表")
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,10 +57,10 @@ object WeworkLoopImpl {
|
||||
if (item.parent != null && item.parent.childCount > 1) {
|
||||
LogUtils.d("通讯录有红点")
|
||||
AccessibilityUtil.performClick(item)
|
||||
val hasRecommendFriend = AccessibilityUtil.findOneByText(getRoot(), "可能的", timeout = Constant.POP_WINDOW_INTERVAL)
|
||||
val hasRecommendFriend = AccessibilityUtil.findOneByText(getRoot(), "可能的同事", exact = true, timeout = Constant.POP_WINDOW_INTERVAL)
|
||||
if (hasRecommendFriend != null) {
|
||||
LogUtils.d("有可能认识的人")
|
||||
AccessibilityUtil.performClick(hasRecommendFriend)
|
||||
AccessibilityUtil.performClick(AccessibilityUtil.findBackNode(hasRecommendFriend))
|
||||
goHome()
|
||||
return false
|
||||
}
|
||||
@@ -116,17 +116,39 @@ object WeworkLoopImpl {
|
||||
val title = titleList.joinToString()
|
||||
LogUtils.v("聊天: $title")
|
||||
log("聊天: $title")
|
||||
val messageList = arrayListOf<WeworkMessageBean.SubMessageBean>()
|
||||
val messageList2 = arrayListOf<WeworkMessageBean.SubMessageBean>()
|
||||
do {
|
||||
messageList.clear()
|
||||
messageList2.clear()
|
||||
//聊天消息列表 1ListView 0RecycleView xViewGroup
|
||||
val list = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView)
|
||||
if (list != null) {
|
||||
LogUtils.v("消息条数: " + list.childCount)
|
||||
val messageList = arrayListOf<WeworkMessageBean.SubMessageBean>()
|
||||
for (i in 0 until list.childCount) {
|
||||
val item = list.getChild(i)
|
||||
if (item != null && item.childCount > 0) {
|
||||
messageList.add(parseChatMessageItem(item, roomType))
|
||||
}
|
||||
}
|
||||
}
|
||||
sleep(Constant.POP_WINDOW_INTERVAL / 5)
|
||||
LogUtils.v("双重校验聊天列表")
|
||||
val list2 = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView)
|
||||
if (list2 != null) {
|
||||
LogUtils.v("list2消息条数: " + list2.childCount)
|
||||
for (i in 0 until list2.childCount) {
|
||||
val item = list2.getChild(i)
|
||||
if (item != null && item.childCount > 0) {
|
||||
messageList2.add(parseChatMessageItem(item, roomType))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (messageList != messageList2) {
|
||||
LogUtils.e("双重校验聊天列表失败")
|
||||
}
|
||||
} while (messageList != messageList2)
|
||||
if (messageList.isNotEmpty()) {
|
||||
WeworkController.weworkService.webSocketManager.send(
|
||||
WeworkMessageBean(
|
||||
null, null,
|
||||
@@ -446,8 +468,11 @@ object WeworkLoopImpl {
|
||||
message = WeworkMessageBean.SubMessageBean(0, textType, itemMessageList, nameList)
|
||||
} else if (Views.ImageView.equals(relativeLayoutItem.getChild(1).className)) {
|
||||
LogUtils.v("头像在右边 本条消息发送者为自己")
|
||||
var textType = WeworkMessageBean.TEXT_TYPE_UNKNOWN
|
||||
val subLayout = relativeLayoutItem.getChild(0)
|
||||
if (subLayout.childCount > 0) {
|
||||
textType = WeworkTextUtil.getTextType(subLayout)
|
||||
LogUtils.v("textType: $textType")
|
||||
val tvList = AccessibilityUtil.findAllOnceByClazz(
|
||||
subLayout.getChild(subLayout.childCount - 1),
|
||||
Views.TextView
|
||||
@@ -461,7 +486,13 @@ object WeworkLoopImpl {
|
||||
}
|
||||
}
|
||||
}
|
||||
message = WeworkMessageBean.SubMessageBean(1, 0, itemMessageList, nameList)
|
||||
//todo 发视频和文件也可能存在上传中状态
|
||||
if (textType == WeworkMessageBean.TEXT_TYPE_LINK && itemMessageList.size == 1
|
||||
&& itemMessageList[0].text.matches("[0-9]+%".toRegex())) {
|
||||
textType = WeworkMessageBean.TEXT_TYPE_IMAGE
|
||||
itemMessageList.clear()
|
||||
}
|
||||
message = WeworkMessageBean.SubMessageBean(1, textType, itemMessageList, nameList)
|
||||
} else {
|
||||
// 没有头像的消息(撤销消息、其他可能的系统消息)
|
||||
val tvList = AccessibilityUtil.findAllOnceByClazz(node, Views.TextView)
|
||||
|
||||
@@ -1039,6 +1039,41 @@ object WeworkOperationImpl {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换企业
|
||||
* @see WeworkMessageBean.SWITCH_CORP
|
||||
* @param objectName 企业名称
|
||||
*/
|
||||
fun switchCorp(message: WeworkMessageBean, objectName: String): Boolean {
|
||||
val startTime = System.currentTimeMillis()
|
||||
goHomeTab("消息")
|
||||
val firstTv = AccessibilityUtil.findAllByClazz(getRoot(), Views.TextView)
|
||||
.firstOrNull { it.text == null }
|
||||
AccessibilityUtil.performClick(firstTv, retry = false)
|
||||
sleep(Constant.CHANGE_PAGE_INTERVAL)
|
||||
val listviewList = AccessibilityUtil.findAllOnceByClazz(getRoot(), Views.RecyclerView, Views.ListView, Views.ViewGroup)
|
||||
.filter { it.childCount >= 2 }
|
||||
val listview = listviewList.firstOrNull()
|
||||
if (listview != null) {
|
||||
val tvCorp = AccessibilityUtil.findOnceByText(listview, objectName, exact = true)
|
||||
if (tvCorp != null) {
|
||||
LogUtils.d("找到目标企业: $objectName")
|
||||
AccessibilityUtil.performClick(tvCorp)
|
||||
goHome()
|
||||
return true
|
||||
} else {
|
||||
LogUtils.e("未找到目标企业: $objectName")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_TARGET, "未找到目标企业: $objectName", startTime)
|
||||
goHome()
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
LogUtils.e("未找到企业列表: $objectName")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_BUTTON, "未找到企业列表: $objectName", startTime)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示群信息
|
||||
* @see WeworkMessageBean.SHOW_GROUP_INFO
|
||||
@@ -1646,6 +1681,7 @@ object WeworkOperationImpl {
|
||||
LogUtils.d("发送消息: \n$content")
|
||||
log("发送消息: \n$content")
|
||||
AccessibilityUtil.performClick(sendButton)
|
||||
sleep(Constant.POP_WINDOW_INTERVAL)
|
||||
WeworkLoopImpl.getChatMessageList()
|
||||
return true
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user