update 支持fileBase64;执行回调成功失败名单
This commit is contained in:
@@ -8,16 +8,22 @@ data class ExecCallbackBean(
|
||||
var rawMsg: String? = null,
|
||||
|
||||
//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() {
|
||||
companion object {
|
||||
@@ -49,6 +55,8 @@ data class ExecCallbackBean(
|
||||
const val ERROR_GROUP_CHANGE_REMARK = 201016
|
||||
//改群模板失败
|
||||
const val ERROR_GROUP_TEMPLATE = 201017
|
||||
//创建群达到上限
|
||||
const val ERROR_CREATE_GROUP_LIMIT = 201018
|
||||
//查找聊天窗失败
|
||||
const val ERROR_INTO_ROOM = 201101
|
||||
//发送消息失败
|
||||
@@ -89,6 +97,8 @@ data class ExecCallbackBean(
|
||||
if (errorReason != other.errorReason) return false
|
||||
if (runTime != other.runTime) return false
|
||||
if (timeCost != other.timeCost) return false
|
||||
if (successList != other.successList) return false
|
||||
if (failList != other.failList) return false
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -96,12 +106,13 @@ data class ExecCallbackBean(
|
||||
override fun hashCode(): Int {
|
||||
var result = super.hashCode()
|
||||
result = 31 * result + (rawMsg?.hashCode() ?: 0)
|
||||
result = 31 * result + errorCode
|
||||
result = 31 * result + errorReason.hashCode()
|
||||
result = 31 * result + runTime.hashCode()
|
||||
result = 31 * result + timeCost.hashCode()
|
||||
result = 31 * result + (errorCode ?: 0)
|
||||
result = 31 * result + (errorReason?.hashCode() ?: 0)
|
||||
result = 31 * result + (runTime?.hashCode() ?: 0)
|
||||
result = 31 * result + (timeCost?.hashCode() ?: 0)
|
||||
result = 31 * result + (successList?.hashCode() ?: 0)
|
||||
result = 31 * result + (failList?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -181,7 +181,7 @@ public class WeworkMessageBean {
|
||||
//踢人列表
|
||||
public List<String> removeList;
|
||||
//拉人是否附带历史记录
|
||||
public boolean showMessageHistory = false;
|
||||
public Boolean showMessageHistory;
|
||||
//我的信息
|
||||
public MyInfo myInfo;
|
||||
//对象名称(图片、文件、小程序等)
|
||||
@@ -193,6 +193,7 @@ public class WeworkMessageBean {
|
||||
public Friend friend;
|
||||
|
||||
//网络文件
|
||||
public String fileBase64;
|
||||
public String fileUrl;
|
||||
public String fileType;
|
||||
|
||||
@@ -293,18 +294,19 @@ public class WeworkMessageBean {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
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
|
||||
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
|
||||
public String toString() {
|
||||
return "WeworkMessageBean{" +
|
||||
"titleList=" + titleList +
|
||||
"messageId='" + messageId + '\'' +
|
||||
", titleList=" + titleList +
|
||||
", messageList=" + messageList +
|
||||
", log='" + log + '\'' +
|
||||
", roomType=" + roomType +
|
||||
@@ -331,6 +333,7 @@ public class WeworkMessageBean {
|
||||
", objectName='" + objectName + '\'' +
|
||||
", qrcode='" + qrcode + '\'' +
|
||||
", friend=" + friend +
|
||||
", fileBase64='" + fileBase64 + '\'' +
|
||||
", fileUrl='" + fileUrl + '\'' +
|
||||
", fileType='" + fileType + '\'' +
|
||||
", type=" + type +
|
||||
|
||||
@@ -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(
|
||||
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,
|
||||
messageId = message.messageId
|
||||
), true
|
||||
)
|
||||
if (errorCode != 0) {
|
||||
ToastUtils.show("错误提示 错误码: $errorCode 错误信息: $errorReason")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -266,17 +266,19 @@ object WeworkController {
|
||||
* @param message#titleList 待发送姓名列表
|
||||
* @param message#objectName 文件名称
|
||||
* @param message#fileUrl 文件网络地址
|
||||
* @param message#fileBase64 文件Base64
|
||||
* @param message#fileType 文件类型
|
||||
* @param message#extraText 附加留言 可选
|
||||
*/
|
||||
@RequestMapping
|
||||
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(
|
||||
message,
|
||||
message.titleList,
|
||||
message.objectName,
|
||||
message.fileUrl,
|
||||
message.fileBase64,
|
||||
message.fileType,
|
||||
message.extraText
|
||||
)
|
||||
|
||||
@@ -17,8 +17,8 @@ object WeworkInteractionImpl {
|
||||
*/
|
||||
fun consoleToast(
|
||||
message: ExecCallbackBean,
|
||||
errorCode: Int,
|
||||
errorReason: String
|
||||
errorCode: Int?,
|
||||
errorReason: String?
|
||||
): Boolean {
|
||||
LogUtils.e("错误提示 错误码: $errorCode 错误信息: $errorReason")
|
||||
ToastUtils.show("错误提示 错误码: $errorCode 错误信息: $errorReason")
|
||||
|
||||
@@ -36,7 +36,7 @@ object WeworkOperationImpl {
|
||||
val startTime = System.currentTimeMillis()
|
||||
if (receivedContent.isNullOrEmpty()) {
|
||||
LogUtils.d("未发现发送内容")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "发送内容为空", startTime)
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "发送内容为空", startTime, listOf(), titleList)
|
||||
return false
|
||||
}
|
||||
val successList = arrayListOf<String>()
|
||||
@@ -58,10 +58,10 @@ object WeworkOperationImpl {
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime)
|
||||
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime, successList, failList)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ object WeworkOperationImpl {
|
||||
groupRemark: String?,
|
||||
groupTemplate: String?,
|
||||
selectList: List<String>?,
|
||||
showMessageHistory: Boolean = false,
|
||||
showMessageHistory: Boolean?,
|
||||
removeList: List<String>?
|
||||
): Boolean {
|
||||
val startTime = System.currentTimeMillis()
|
||||
@@ -277,7 +277,7 @@ object WeworkOperationImpl {
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_RENAME, "进入房间成功 群改名失败", startTime)
|
||||
return false
|
||||
}
|
||||
if (!groupAddMember(selectList, showMessageHistory)) {
|
||||
if (!groupAddMember(selectList, showMessageHistory == true)) {
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_GROUP_ADD_MEMBER, "进入房间成功 群改名成功 群拉人失败 ${selectList?.joinToString()}", startTime)
|
||||
return false
|
||||
}
|
||||
@@ -535,6 +535,7 @@ object WeworkOperationImpl {
|
||||
* @param titleList 待发送姓名列表
|
||||
* @param objectName 文件名称
|
||||
* @param fileUrl 文件网络地址
|
||||
* @param fileBase64 文件Base64
|
||||
* @param fileType 文件类型
|
||||
* @param extraText 附加留言 可选
|
||||
*/
|
||||
@@ -542,7 +543,8 @@ object WeworkOperationImpl {
|
||||
message: WeworkMessageBean,
|
||||
titleList: List<String>,
|
||||
objectName: String,
|
||||
fileUrl: String,
|
||||
fileUrl: String?,
|
||||
fileBase64: String?,
|
||||
fileType: String,
|
||||
extraText: String? = null
|
||||
): Boolean {
|
||||
@@ -552,17 +554,68 @@ object WeworkOperationImpl {
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_PERMISSION, "未打开悬浮窗权限", startTime)
|
||||
return false
|
||||
}
|
||||
LogUtils.i("下载开始 $fileUrl")
|
||||
val execute = OkGo.get<File>(fileUrl).execute()
|
||||
LogUtils.i("下载完成 $fileUrl")
|
||||
val body = execute.body()
|
||||
if (body != null) {
|
||||
if (fileUrl != null) {
|
||||
LogUtils.i("下载开始 $fileUrl")
|
||||
val execute = OkGo.get<File>(fileUrl).execute()
|
||||
LogUtils.i("下载完成 $fileUrl")
|
||||
val body = execute.body()
|
||||
if (body != 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(body.bytes())
|
||||
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 {
|
||||
LogUtils.e("文件下载失败")
|
||||
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 filePath = "${
|
||||
Utils.getApp().getExternalFilesDir("share")
|
||||
}/${df.format(Date())}/$objectName"
|
||||
val newFile = File(filePath)
|
||||
val create = FileUtils.createFileByDeleteOldFile(newFile)
|
||||
if (create && newFile.canWrite()) {
|
||||
newFile.writeBytes(body.bytes())
|
||||
newFile.writeBytes(EncodeUtils.base64Decode(fileBase64))
|
||||
LogUtils.i("文件存储本地成功 $filePath")
|
||||
ShareUtil.share("${if (fileType.isBlank()) "*" else fileType}/*", newFile)
|
||||
val shareToWorkButton = AccessibilityUtil.findOneByText(getRoot(true), "发送给同事")
|
||||
@@ -574,17 +627,31 @@ object WeworkOperationImpl {
|
||||
return true
|
||||
} else {
|
||||
LogUtils.e("文件转发失败: $objectName")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_RELAY, "文件转发失败: $objectName", startTime)
|
||||
uploadCommandResult(
|
||||
message,
|
||||
ExecCallbackBean.ERROR_RELAY,
|
||||
"文件转发失败: $objectName",
|
||||
startTime
|
||||
)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
LogUtils.e("文件存储本地失败 $filePath")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_FILE_STORAGE, "文件存储本地失败 $filePath", startTime)
|
||||
uploadCommandResult(
|
||||
message,
|
||||
ExecCallbackBean.ERROR_FILE_STORAGE,
|
||||
"文件存储本地失败 $filePath",
|
||||
startTime
|
||||
)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
LogUtils.e("文件下载失败")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_FILE_DOWNLOAD, "文件下载失败 $fileUrl", startTime)
|
||||
uploadCommandResult(
|
||||
message,
|
||||
ExecCallbackBean.ERROR_ILLEGAL_DATA,
|
||||
"未找到文件资源参数",
|
||||
startTime
|
||||
)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user