update 支持fileBase64;执行回调成功失败名单

This commit is contained in:
gallonyin
2022-11-07 14:31:26 +08:00
parent 298eeb7a51
commit bd79538a9a
6 changed files with 121 additions and 35 deletions

View File

@@ -8,16 +8,22 @@ data class ExecCallbackBean(
var rawMsg: String? = null, var rawMsg: String? = null,
//0成功 其他是失败错误码 //0成功 其他是失败错误码
var errorCode: Int = 0, var errorCode: Int? = null,
//失败原因 //失败原因
var errorReason: String = "", var errorReason: String? = null,
//执行时间 //执行时间
var runTime: Long = 0, var runTime: Long? = null,
//执行耗时 //执行耗时
var timeCost: Double = 0.0 var timeCost: Double? = null,
//成功名单
var successList: List<String>? = null,
//失败名单
var failList: List<String>? = null
) : WeworkMessageBean() { ) : WeworkMessageBean() {
companion object { companion object {
@@ -49,6 +55,8 @@ data class ExecCallbackBean(
const val ERROR_GROUP_CHANGE_REMARK = 201016 const val ERROR_GROUP_CHANGE_REMARK = 201016
//改群模板失败 //改群模板失败
const val ERROR_GROUP_TEMPLATE = 201017 const val ERROR_GROUP_TEMPLATE = 201017
//创建群达到上限
const val ERROR_CREATE_GROUP_LIMIT = 201018
//查找聊天窗失败 //查找聊天窗失败
const val ERROR_INTO_ROOM = 201101 const val ERROR_INTO_ROOM = 201101
//发送消息失败 //发送消息失败
@@ -89,6 +97,8 @@ data class ExecCallbackBean(
if (errorReason != other.errorReason) return false if (errorReason != other.errorReason) return false
if (runTime != other.runTime) return false if (runTime != other.runTime) return false
if (timeCost != other.timeCost) return false if (timeCost != other.timeCost) return false
if (successList != other.successList) return false
if (failList != other.failList) return false
return true return true
} }
@@ -96,12 +106,13 @@ data class ExecCallbackBean(
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + (rawMsg?.hashCode() ?: 0) result = 31 * result + (rawMsg?.hashCode() ?: 0)
result = 31 * result + errorCode result = 31 * result + (errorCode ?: 0)
result = 31 * result + errorReason.hashCode() result = 31 * result + (errorReason?.hashCode() ?: 0)
result = 31 * result + runTime.hashCode() result = 31 * result + (runTime?.hashCode() ?: 0)
result = 31 * result + timeCost.hashCode() result = 31 * result + (timeCost?.hashCode() ?: 0)
result = 31 * result + (successList?.hashCode() ?: 0)
result = 31 * result + (failList?.hashCode() ?: 0)
return result return result
} }
} }

View File

@@ -181,7 +181,7 @@ public class WeworkMessageBean {
//踢人列表 //踢人列表
public List<String> removeList; public List<String> removeList;
//拉人是否附带历史记录 //拉人是否附带历史记录
public boolean showMessageHistory = false; public Boolean showMessageHistory;
//我的信息 //我的信息
public MyInfo myInfo; public MyInfo myInfo;
//对象名称(图片、文件、小程序等) //对象名称(图片、文件、小程序等)
@@ -193,6 +193,7 @@ public class WeworkMessageBean {
public Friend friend; public Friend friend;
//网络文件 //网络文件
public String fileBase64;
public String fileUrl; public String fileUrl;
public String fileType; public String fileType;
@@ -293,18 +294,19 @@ public class WeworkMessageBean {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
WeworkMessageBean that = (WeworkMessageBean) o; WeworkMessageBean that = (WeworkMessageBean) o;
return textType == that.textType && showMessageHistory == that.showMessageHistory && type == that.type && Objects.equals(titleList, that.titleList) && Objects.equals(messageList, that.messageList) && Objects.equals(log, that.log) && Objects.equals(roomType, that.roomType) && Objects.equals(receivedName, that.receivedName) && Objects.equals(receivedContent, that.receivedContent) && Objects.equals(at, that.at) && Objects.equals(atList, that.atList) && Objects.equals(originalContent, that.originalContent) && Objects.equals(nameList, that.nameList) && Objects.equals(extraText, that.extraText) && Objects.equals(groupName, that.groupName) && Objects.equals(groupOwner, that.groupOwner) && Objects.equals(selectList, that.selectList) && Objects.equals(groupNumber, that.groupNumber) && Objects.equals(groupAnnouncement, that.groupAnnouncement) && Objects.equals(groupRemark, that.groupRemark) && Objects.equals(groupTemplate, that.groupTemplate) && Objects.equals(newGroupName, that.newGroupName) && Objects.equals(newGroupAnnouncement, that.newGroupAnnouncement) && Objects.equals(removeList, that.removeList) && Objects.equals(myInfo, that.myInfo) && Objects.equals(objectName, that.objectName) && Objects.equals(qrcode, that.qrcode) && Objects.equals(friend, that.friend) && Objects.equals(fileUrl, that.fileUrl) && Objects.equals(fileType, that.fileType); return textType == that.textType && showMessageHistory == that.showMessageHistory && type == that.type && Objects.equals(messageId, that.messageId) && Objects.equals(titleList, that.titleList) && Objects.equals(messageList, that.messageList) && Objects.equals(log, that.log) && Objects.equals(roomType, that.roomType) && Objects.equals(receivedName, that.receivedName) && Objects.equals(receivedContent, that.receivedContent) && Objects.equals(at, that.at) && Objects.equals(atList, that.atList) && Objects.equals(originalContent, that.originalContent) && Objects.equals(nameList, that.nameList) && Objects.equals(extraText, that.extraText) && Objects.equals(groupName, that.groupName) && Objects.equals(groupOwner, that.groupOwner) && Objects.equals(selectList, that.selectList) && Objects.equals(groupNumber, that.groupNumber) && Objects.equals(groupAnnouncement, that.groupAnnouncement) && Objects.equals(groupRemark, that.groupRemark) && Objects.equals(groupTemplate, that.groupTemplate) && Objects.equals(newGroupName, that.newGroupName) && Objects.equals(newGroupAnnouncement, that.newGroupAnnouncement) && Objects.equals(removeList, that.removeList) && Objects.equals(myInfo, that.myInfo) && Objects.equals(objectName, that.objectName) && Objects.equals(qrcode, that.qrcode) && Objects.equals(friend, that.friend) && Objects.equals(fileBase64, that.fileBase64) && Objects.equals(fileUrl, that.fileUrl) && Objects.equals(fileType, that.fileType);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(titleList, messageList, log, roomType, receivedName, receivedContent, at, atList, originalContent, nameList, extraText, textType, groupName, groupOwner, selectList, groupNumber, groupAnnouncement, groupRemark, groupTemplate, newGroupName, newGroupAnnouncement, removeList, showMessageHistory, myInfo, objectName, qrcode, friend, fileUrl, fileType, type); return Objects.hash(messageId, titleList, messageList, log, roomType, receivedName, receivedContent, at, atList, originalContent, nameList, extraText, textType, groupName, groupOwner, selectList, groupNumber, groupAnnouncement, groupRemark, groupTemplate, newGroupName, newGroupAnnouncement, removeList, showMessageHistory, myInfo, objectName, qrcode, friend, fileBase64, fileUrl, fileType, type);
} }
@Override @Override
public String toString() { public String toString() {
return "WeworkMessageBean{" + return "WeworkMessageBean{" +
"titleList=" + titleList + "messageId='" + messageId + '\'' +
", titleList=" + titleList +
", messageList=" + messageList + ", messageList=" + messageList +
", log='" + log + '\'' + ", log='" + log + '\'' +
", roomType=" + roomType + ", roomType=" + roomType +
@@ -331,6 +333,7 @@ public class WeworkMessageBean {
", objectName='" + objectName + '\'' + ", objectName='" + objectName + '\'' +
", qrcode='" + qrcode + '\'' + ", qrcode='" + qrcode + '\'' +
", friend=" + friend + ", friend=" + friend +
", fileBase64='" + fileBase64 + '\'' +
", fileUrl='" + fileUrl + '\'' + ", fileUrl='" + fileUrl + '\'' +
", fileType='" + fileType + '\'' + ", fileType='" + fileType + '\'' +
", type=" + type + ", type=" + type +

View File

@@ -156,14 +156,17 @@ fun backPress() {
/** /**
* 上传执行指令结果 * 上传执行指令结果
*/ */
fun uploadCommandResult(message: WeworkMessageBean, errorCode: Int, errorReason: String, startTime: Long) { fun uploadCommandResult(message: WeworkMessageBean, errorCode: Int, errorReason: String, startTime: Long, successList: List<String> = listOf(), failList: List<String> = listOf()) {
WeworkController.weworkService.webSocketManager.send( WeworkController.weworkService.webSocketManager.send(
WeworkMessageListBean( WeworkMessageListBean(
ExecCallbackBean(GsonUtils.toJson(message), errorCode, errorReason, startTime, (System.currentTimeMillis() - startTime) / 1000.0), ExecCallbackBean(GsonUtils.toJson(message), errorCode, errorReason, startTime, (System.currentTimeMillis() - startTime) / 1000.0, successList, failList),
WeworkMessageListBean.SOCKET_TYPE_RAW_CONFIRM, WeworkMessageListBean.SOCKET_TYPE_RAW_CONFIRM,
messageId = message.messageId messageId = message.messageId
), true ), true
) )
if (errorCode != 0) {
ToastUtils.show("错误提示 错误码: $errorCode 错误信息: $errorReason")
}
} }
/** /**

View File

@@ -266,17 +266,19 @@ object WeworkController {
* @param message#titleList 待发送姓名列表 * @param message#titleList 待发送姓名列表
* @param message#objectName 文件名称 * @param message#objectName 文件名称
* @param message#fileUrl 文件网络地址 * @param message#fileUrl 文件网络地址
* @param message#fileBase64 文件Base64
* @param message#fileType 文件类型 * @param message#fileType 文件类型
* @param message#extraText 附加留言 可选 * @param message#extraText 附加留言 可选
*/ */
@RequestMapping @RequestMapping
fun pushFile(message: WeworkMessageBean): Boolean { fun pushFile(message: WeworkMessageBean): Boolean {
LogUtils.d("pushFile(): ${message.titleList} ${message.objectName} ${message.fileUrl} ${message.fileType} ${message.extraText}") LogUtils.d("pushFile(): ${message.titleList} ${message.objectName} ${message.fileUrl} ${message.fileBase64} ${message.fileType} ${message.extraText}")
return WeworkOperationImpl.pushFile( return WeworkOperationImpl.pushFile(
message, message,
message.titleList, message.titleList,
message.objectName, message.objectName,
message.fileUrl, message.fileUrl,
message.fileBase64,
message.fileType, message.fileType,
message.extraText message.extraText
) )

View File

@@ -17,8 +17,8 @@ object WeworkInteractionImpl {
*/ */
fun consoleToast( fun consoleToast(
message: ExecCallbackBean, message: ExecCallbackBean,
errorCode: Int, errorCode: Int?,
errorReason: String errorReason: String?
): Boolean { ): Boolean {
LogUtils.e("错误提示 错误码: $errorCode 错误信息: $errorReason") LogUtils.e("错误提示 错误码: $errorCode 错误信息: $errorReason")
ToastUtils.show("错误提示 错误码: $errorCode 错误信息: $errorReason") ToastUtils.show("错误提示 错误码: $errorCode 错误信息: $errorReason")

View File

@@ -36,7 +36,7 @@ object WeworkOperationImpl {
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
if (receivedContent.isNullOrEmpty()) { if (receivedContent.isNullOrEmpty()) {
LogUtils.d("未发现发送内容") LogUtils.d("未发现发送内容")
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "发送内容为空", startTime) uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "发送内容为空", startTime, listOf(), titleList)
return false return false
} }
val successList = arrayListOf<String>() val successList = arrayListOf<String>()
@@ -58,10 +58,10 @@ object WeworkOperationImpl {
} }
} }
if (failList.isNotEmpty()) { if (failList.isNotEmpty()) {
uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "发送成功: ${successList.joinToString()} 发送失败: ${failList.joinToString()}", startTime) uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "发送成功: ${successList.joinToString()} 发送失败: ${failList.joinToString()}", startTime, successList, failList)
return false return false
} }
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime) uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime, successList, failList)
return true return true
} }
@@ -265,7 +265,7 @@ object WeworkOperationImpl {
groupRemark: String?, groupRemark: String?,
groupTemplate: String?, groupTemplate: String?,
selectList: List<String>?, selectList: List<String>?,
showMessageHistory: Boolean = false, showMessageHistory: Boolean?,
removeList: List<String>? removeList: List<String>?
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
@@ -277,7 +277,7 @@ object WeworkOperationImpl {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_RENAME, "进入房间成功 群改名失败", startTime) uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_RENAME, "进入房间成功 群改名失败", startTime)
return false return false
} }
if (!groupAddMember(selectList, showMessageHistory)) { if (!groupAddMember(selectList, showMessageHistory == true)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_ADD_MEMBER, "进入房间成功 群改名成功 群拉人失败 ${selectList?.joinToString()}", startTime) uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_ADD_MEMBER, "进入房间成功 群改名成功 群拉人失败 ${selectList?.joinToString()}", startTime)
return false return false
} }
@@ -535,6 +535,7 @@ object WeworkOperationImpl {
* @param titleList 待发送姓名列表 * @param titleList 待发送姓名列表
* @param objectName 文件名称 * @param objectName 文件名称
* @param fileUrl 文件网络地址 * @param fileUrl 文件网络地址
* @param fileBase64 文件Base64
* @param fileType 文件类型 * @param fileType 文件类型
* @param extraText 附加留言 可选 * @param extraText 附加留言 可选
*/ */
@@ -542,7 +543,8 @@ object WeworkOperationImpl {
message: WeworkMessageBean, message: WeworkMessageBean,
titleList: List<String>, titleList: List<String>,
objectName: String, objectName: String,
fileUrl: String, fileUrl: String?,
fileBase64: String?,
fileType: String, fileType: String,
extraText: String? = null extraText: String? = null
): Boolean { ): Boolean {
@@ -552,13 +554,16 @@ object WeworkOperationImpl {
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_PERMISSION, "未打开悬浮窗权限", startTime) uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_PERMISSION, "未打开悬浮窗权限", startTime)
return false return false
} }
if (fileUrl != null) {
LogUtils.i("下载开始 $fileUrl") LogUtils.i("下载开始 $fileUrl")
val execute = OkGo.get<File>(fileUrl).execute() val execute = OkGo.get<File>(fileUrl).execute()
LogUtils.i("下载完成 $fileUrl") LogUtils.i("下载完成 $fileUrl")
val body = execute.body() val body = execute.body()
if (body != null) { if (body != null) {
val df = SimpleDateFormat("yyyy-MM-dd") val df = SimpleDateFormat("yyyy-MM-dd")
val filePath = "${Utils.getApp().getExternalFilesDir("share")}/${df.format(Date())}/$objectName" val filePath = "${
Utils.getApp().getExternalFilesDir("share")
}/${df.format(Date())}/$objectName"
val newFile = File(filePath) val newFile = File(filePath)
val create = FileUtils.createFileByDeleteOldFile(newFile) val create = FileUtils.createFileByDeleteOldFile(newFile)
if (create && newFile.canWrite()) { if (create && newFile.canWrite()) {
@@ -574,17 +579,79 @@ object WeworkOperationImpl {
return true return true
} else { } else {
LogUtils.e("文件转发失败: $objectName") LogUtils.e("文件转发失败: $objectName")
uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "文件转发失败: $objectName", startTime) uploadCommandResult(
message,
ExecCallbackBean.ERROR_RELAY,
"文件转发失败: $objectName",
startTime
)
return false return false
} }
} else { } else {
LogUtils.e("文件存储本地失败 $filePath") LogUtils.e("文件存储本地失败 $filePath")
uploadCommandResult(message, ExecCallbackBean.ERROR_FILE_STORAGE, "文件存储本地失败 $filePath", startTime) uploadCommandResult(
message,
ExecCallbackBean.ERROR_FILE_STORAGE,
"文件存储本地失败 $filePath",
startTime
)
return false return false
} }
} else { } else {
LogUtils.e("文件下载失败") LogUtils.e("文件下载失败")
uploadCommandResult(message, ExecCallbackBean.ERROR_FILE_DOWNLOAD, "文件下载失败 $fileUrl", startTime) uploadCommandResult(
message,
ExecCallbackBean.ERROR_FILE_DOWNLOAD,
"文件下载失败 $fileUrl",
startTime
)
return false
}
} else if (fileBase64 != null) {
val df = SimpleDateFormat("yyyy-MM-dd")
val filePath = "${
Utils.getApp().getExternalFilesDir("share")
}/${df.format(Date())}/$objectName"
val newFile = File(filePath)
val create = FileUtils.createFileByDeleteOldFile(newFile)
if (create && newFile.canWrite()) {
newFile.writeBytes(EncodeUtils.base64Decode(fileBase64))
LogUtils.i("文件存储本地成功 $filePath")
ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile)
val shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true), "发送给同事")
AccessibilityUtil.performClick(shareToWorkButton)
if (relaySelectTarget(titleList, extraText)) {
val stayButton = AccessibilityUtil.findOneByText(getRoot(), "留在企业微信")
AccessibilityUtil.performClick(stayButton)
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
return true
} else {
LogUtils.e("文件转发失败: $objectName")
uploadCommandResult(
message,
ExecCallbackBean.ERROR_RELAY,
"文件转发失败: $objectName",
startTime
)
return false
}
} else {
LogUtils.e("文件存储本地失败 $filePath")
uploadCommandResult(
message,
ExecCallbackBean.ERROR_FILE_STORAGE,
"文件存储本地失败 $filePath",
startTime
)
return false
}
} else {
uploadCommandResult(
message,
ExecCallbackBean.ERROR_ILLEGAL_DATA,
"未找到文件资源参数",
startTime
)
return false return false
} }
} }