1、aop切面拦截异常信息并发送机器人消息
continuous-integration/drone/push Build is passing Details

2、根据飞书表格创建飞书任务
3、飞书任务回调(未完成)
于相涌/robot_optimize
YXY 1 year ago
parent ffe7e238f2
commit 40f1f3deef

@ -108,3 +108,6 @@ flowable:
async-executor-activate: false async-executor-activate: false
attachment: attachment:
path: /data/attachment path: /data/attachment
lark:
robot:
group: https://open.feishu.cn/open-apis/bot/v2/hook/cf432ef4-e526-4595-8330-2d2a361f7a29

@ -10,6 +10,7 @@ public enum CallBackTypeEnum {
* *
*/ */
TABLE_ROW_CHANGE("drive.file.bitable_record_changed_v1", "多维表格行记录变更"), TABLE_ROW_CHANGE("drive.file.bitable_record_changed_v1", "多维表格行记录变更"),
LARK_TASK("task.task.updated_v1", "飞书任务回调"),
APPROVAL_TASK("approval_task", "审批事件回调"); APPROVAL_TASK("approval_task", "审批事件回调");
private final String code; private final String code;

@ -10,13 +10,16 @@ public enum EventOperateType {
* *
*/ */
CALL_BACK("CALL_BACK", "反馈"), CALL_BACK("CALL_BACK", "反馈"),
LARK_TASK_CALL_BACK("LARK_TASK_CALL_BACK", "飞书任务回调"),
CREATE("CREATE", "创建"), CREATE("CREATE", "创建"),
UPDATE("UPDATE", "更新"), UPDATE("UPDATE", "更新"),
DELETE("DELETE", "删除"), DELETE("DELETE", "删除"),
STOP("STOP", "终止"), STOP("STOP", "终止"),
SYNC_MAIL("SYNC_MAIL", "同步邮件"), SYNC_MAIL("SYNC_MAIL", "同步邮件"),
SCHEDULE_REMINDER("SCHEDULE_REMINDER", "定时提醒"), SCHEDULE_REMINDER("SCHEDULE_REMINDER", "定时提醒"),
SYNC_DATA_TO_TABLE("SYNC_DATA_TO_TABLE", "同步数据到多维表格"); SYNC_DATA_TO_TABLE("SYNC_DATA_TO_TABLE", "同步数据到多维表格"),
CREATE_TASK("CREATE_TASK", "创建任务"),
SYNC_CANDLE("SYNC_CANDLE", "同步日历");
private final String code; private final String code;
private final String info; private final String info;

@ -10,7 +10,8 @@ public enum EventTypeEnum {
* *
*/ */
ROW_CHANGE("ROW_CHANGE", "多维表格行记录变更"), ROW_CHANGE("ROW_CHANGE", "多维表格行记录变更"),
APPROVAL_TASK("APPROVAL_TASK", "审批事件"); APPROVAL_TASK("APPROVAL_TASK", "审批事件"),
LARK_TASK("LARK_TASK", "飞书任务");
private final String code; private final String code;
private final String info; private final String info;

@ -15,7 +15,8 @@ public enum TableRelationTypeEnum {
DOUBLE_DIRECTION("DOUBLE_DIRECTION", "双向传递"), DOUBLE_DIRECTION("DOUBLE_DIRECTION", "双向传递"),
SYNC_EMAIL("SYNC_EMAIL", "同步邮箱"), SYNC_EMAIL("SYNC_EMAIL", "同步邮箱"),
SCHEDULED_REMINDERS("SCHEDULED_REMINDERS", "定时提醒"), SCHEDULED_REMINDERS("SCHEDULED_REMINDERS", "定时提醒"),
SYNC_EXTERNAL_DATA_TO_MULTI_TABLE("SYNC_EXTERNAL_DATA_TO_MULTI_TABLE", "同步外部数据到多维表格"); SYNC_EXTERNAL_DATA_TO_MULTI_TABLE("SYNC_EXTERNAL_DATA_TO_MULTI_TABLE", "同步外部数据到多维表格"),
CREATE_TASK_BY_TABLE("CREATE_TASK_BY_TABLE", "根据多维表格配置创建任务");
private String code; private String code;
private String info; private String info;

@ -62,6 +62,10 @@
<artifactId>javax.mail</artifactId> <artifactId>javax.mail</artifactId>
<version>1.6.2</version> <version>1.6.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
</dependencies> </dependencies>

@ -2,6 +2,7 @@ package com.ruoyi.flyingbook.LarkHelper;
import com.lark.oapi.service.approval.v4.model.*; import com.lark.oapi.service.approval.v4.model.*;
import com.ruoyi.flyingbook.domain.lark.LarkApprovalRequest; import com.ruoyi.flyingbook.domain.lark.LarkApprovalRequest;
import com.ruoyi.flyingbook.domain.lark.LarkException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -34,10 +35,10 @@ public class LarkApprovalHelper extends LarkHelper{
if (getInstanceResp.getCode() == 0){ if (getInstanceResp.getCode() == 0){
return getInstanceResp.getData(); return getInstanceResp.getData();
}else { }else {
throw new RuntimeException(getInstanceResp.getMsg()); throw new RuntimeException(new LarkException("LarkApprovalHelper.getApprovalInfoDetail",getInstanceResp.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkApprovalHelper.getApprovalInfoDetail",e.getMessage(),request).getErrorMessageBody());
} }
} }
} }

@ -5,6 +5,7 @@ import com.lark.oapi.service.drive.v1.model.UploadAllFileReq;
import com.lark.oapi.service.drive.v1.model.UploadAllFileReqBody; import com.lark.oapi.service.drive.v1.model.UploadAllFileReqBody;
import com.lark.oapi.service.drive.v1.model.UploadAllFileResp; import com.lark.oapi.service.drive.v1.model.UploadAllFileResp;
import com.lark.oapi.service.drive.v1.model.UploadAllFileRespBody; import com.lark.oapi.service.drive.v1.model.UploadAllFileRespBody;
import com.ruoyi.flyingbook.domain.lark.LarkException;
import com.ruoyi.flyingbook.domain.lark.LarkFileRequest; import com.ruoyi.flyingbook.domain.lark.LarkFileRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -52,10 +53,10 @@ public class LarkFileHelper extends LarkHelper {
if (uploadAllFileResp.getCode() == 0){ if (uploadAllFileResp.getCode() == 0){
return uploadAllFileResp.getData(); return uploadAllFileResp.getData();
}else { }else {
throw new RuntimeException(uploadAllFileResp.getMsg()); throw new RuntimeException(new LarkException("LarkFileHelper.uploadFile",uploadAllFileResp.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkFileHelper.uploadFile",e.getMessage(),request).getErrorMessageBody());
} }
} }
} }

@ -1,5 +1,8 @@
package com.ruoyi.flyingbook.LarkHelper; package com.ruoyi.flyingbook.LarkHelper;
import com.alibaba.fastjson.JSONObject;
import com.lark.oapi.core.response.RawResponse;
import com.lark.oapi.core.token.AccessTokenType;
import com.lark.oapi.service.im.v1.enums.CreateMessageReceiveIdTypeEnum; import com.lark.oapi.service.im.v1.enums.CreateMessageReceiveIdTypeEnum;
import com.lark.oapi.service.im.v1.model.CreateMessageReq; import com.lark.oapi.service.im.v1.model.CreateMessageReq;
import com.lark.oapi.service.im.v1.model.CreateMessageReqBody; import com.lark.oapi.service.im.v1.model.CreateMessageReqBody;
@ -9,6 +12,9 @@ import com.ruoyi.flyingbook.domain.lark.LarkRobotRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author yuxiangyong * @author yuxiangyong
@ -26,6 +32,20 @@ public class LarkRobotHelper extends LarkHelper{
int i = 0; int i = 0;
} }
public void sendMessageByBot(String robotGroup,String message){
try {
LarkRobotRequest larkRobotRequest = new LarkRobotRequest(appId, secret);
JSONObject body = new JSONObject();
body.put("msg_type","text");
JSONObject bodyDetail = new JSONObject();
bodyDetail.put("text",message);
body.put("content",bodyDetail);
buildClient(larkRobotRequest).post(robotGroup, body, AccessTokenType.Tenant);
} catch (Exception e) {
log.error("LarkRobotHelper sendMessageByBot",e);
}
}
/** /**
* *

@ -3,6 +3,7 @@ package com.ruoyi.flyingbook.LarkHelper;
import com.lark.oapi.core.request.RequestOptions; import com.lark.oapi.core.request.RequestOptions;
import com.lark.oapi.core.response.RawResponse; import com.lark.oapi.core.response.RawResponse;
import com.lark.oapi.service.bitable.v1.model.*; import com.lark.oapi.service.bitable.v1.model.*;
import com.ruoyi.flyingbook.domain.lark.LarkException;
import com.ruoyi.flyingbook.domain.lark.LarkTableFieldRequest; import com.ruoyi.flyingbook.domain.lark.LarkTableFieldRequest;
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest; import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -55,10 +56,11 @@ public class LarkTableFieldHelper extends LarkHelper {
} }
return result; return result;
}else { }else {
throw new RuntimeException(list.getMsg());
throw new RuntimeException(new LarkException("LarkTableFieldHelper.getTableFieldDetail",list.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkTableFieldHelper.getTableFieldDetail",e.getMessage(),request).getErrorMessageBody());
} }
} }

@ -2,6 +2,7 @@ package com.ruoyi.flyingbook.LarkHelper;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.lark.oapi.service.bitable.v1.model.*; import com.lark.oapi.service.bitable.v1.model.*;
import com.ruoyi.flyingbook.domain.lark.LarkException;
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest; import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -27,8 +28,8 @@ public class LarkTableHelper extends LarkHelper{
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
LarkTableHelper bk = new LarkTableHelper(); LarkTableHelper bk = new LarkTableHelper();
// map.put("a", "aaa"); // map.put("adwadawd", "aaa");
LarkTableRequest add = new LarkTableRequest(appId, secret, appToken, tableId,map); // LarkTableRequest add = new LarkTableRequest(appId, secret, appToken, tableId,map);
// CreateAppTableRecordRespBody createAppTableRecordRespBody = bk.addTableRecord(add); // CreateAppTableRecordRespBody createAppTableRecordRespBody = bk.addTableRecord(add);
// String recordId = createAppTableRecordRespBody.getRecord().getRecordId(); // String recordId = createAppTableRecordRespBody.getRecord().getRecordId();
// map.put("b", "EEE"); // map.put("b", "EEE");
@ -38,15 +39,17 @@ public class LarkTableHelper extends LarkHelper{
// ListAppTableRecordRespBody listAppTableRecordRespBody = bk.listTableRecord(add); // ListAppTableRecordRespBody listAppTableRecordRespBody = bk.listTableRecord(add);
// LarkTableRequest delete = new LarkTableRequest(appId, secret, appToken,tableId, recordId); // LarkTableRequest delete = new LarkTableRequest(appId, secret, appToken,tableId, recordId);
// bk.deleteTableRecord(delete); // bk.deleteTableRecord(delete);
AppTableCreateHeader[] fields = new AppTableCreateHeader[1]; // AppTableCreateHeader[] fields = new AppTableCreateHeader[1];
AppTableCreateHeader header1 = new AppTableCreateHeader(); // AppTableCreateHeader header1 = new AppTableCreateHeader();
header1.setType(1); // header1.setType(1);
header1.setFieldName("多行文本"); // header1.setFieldName("多行文本");
fields[0] = header1; // fields[0] = header1;
LarkTableRequest createTableReq = new LarkTableRequest(appId,secret // LarkTableRequest createTableReq = new LarkTableRequest(appId,secret
,appToken,"aaa","aaa" // ,appToken,"aaa","aaa"
,fields); // ,fields);
bk.createDataTable(createTableReq); // bk.createDataTable(createTableReq);
LarkTableRequest queryRecordDetail = new LarkTableRequest(appId, secret, "IvzSbCo8waM8was4ihpcq04Vnwe", "tbl7SlD25eSWwgU4","recd44XT5A");
GetAppTableRecordResp tableRecordDetail = bk.getTableRecordDetail(queryRecordDetail);
int i = 0; int i = 0;
} }
@ -67,7 +70,7 @@ public class LarkTableHelper extends LarkHelper{
); );
return createAppResp.getData(); return createAppResp.getData();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkTableHelper.createMultiTable",e.getMessage(),request).getErrorMessageBody());
} }
} }
@ -95,7 +98,7 @@ public class LarkTableHelper extends LarkHelper{
.build() .build()
).getData(); ).getData();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkTableHelper.createDataTable",e.getMessage(),request).getErrorMessageBody());
} }
} }
@ -115,7 +118,7 @@ public class LarkTableHelper extends LarkHelper{
.recordId(request.getRecord()). .recordId(request.getRecord()).
build()); build());
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkTableHelper.getTableRecordDetail",e.getMessage(),request).getErrorMessageBody());
} }
} }
@ -133,13 +136,10 @@ public class LarkTableHelper extends LarkHelper{
if (createAppTableRecordResp.getCode() == 0){ if (createAppTableRecordResp.getCode() == 0){
return createAppTableRecordResp.getData(); return createAppTableRecordResp.getData();
}else { }else {
throw new RuntimeException(createAppTableRecordResp.getMsg()); throw new RuntimeException(new LarkException("LarkTableHelper.addTableRecord",createAppTableRecordResp.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
Map<String,String> resultMap = new HashMap<>(); throw new RuntimeException(new LarkException("LarkTableHelper.addTableRecord",e.getMessage(),request).getErrorMessageBody());
resultMap.put("errorCode",e.getMessage());
resultMap.put("info", JSONObject.toJSONString(request));
throw new RuntimeException(JSONObject.toJSONString(resultMap));
} }
} }
@ -155,10 +155,10 @@ public class LarkTableHelper extends LarkHelper{
if (delete.getCode() == 0){ if (delete.getCode() == 0){
return delete.getData(); return delete.getData();
}else { }else {
throw new RuntimeException(delete.getMsg()); throw new RuntimeException(new LarkException("LarkTableHelper.deleteTableRecord",delete.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkTableHelper.deleteTableRecord",e.getMessage(),request).getErrorMessageBody());
} }
} }
@ -178,10 +178,10 @@ public class LarkTableHelper extends LarkHelper{
if (update.getCode() == 0){ if (update.getCode() == 0){
return update.getData(); return update.getData();
}else { }else {
throw new RuntimeException(update.getMsg()); throw new RuntimeException(new LarkException("LarkTableHelper.updateTableRecord",update.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkTableHelper.updateTableRecord",e.getMessage(),request).getErrorMessageBody());
} }
} }
@ -206,10 +206,10 @@ public class LarkTableHelper extends LarkHelper{
if (list.getCode() == 0){ if (list.getCode() == 0){
return list.getData(); return list.getData();
}else { }else {
throw new RuntimeException(list.getMsg()); throw new RuntimeException(new LarkException("LarkTableHelper.listTableRecord",list.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkTableHelper.listTableRecord",e.getMessage(),request).getErrorMessageBody());
} }
} }
} }

@ -0,0 +1,75 @@
package com.ruoyi.flyingbook.LarkHelper;
import com.lark.oapi.service.task.v1.enums.CreateTaskUserIdTypeEnum;
import com.lark.oapi.service.task.v1.model.*;
import com.ruoyi.flyingbook.domain.lark.LarkException;
import com.ruoyi.flyingbook.domain.lark.LarkTaskRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author yuxiangyong
* @create 2023-03-12 18:10
*/
@Slf4j
@Component
public class LarkTaskHelper extends LarkHelper {
public static void main(String[] args) throws Exception {
LarkTaskHelper taskHelper = new LarkTaskHelper();
// LarkTaskRequest larkRobotRequest = new LarkTaskRequest(appId, secret);
// Task task = new Task();
// task.setSummary("测试一下");
// task.setDescription("描述");
// task.setOrigin(larkRobotRequest.getDefaultOrigin());
// task.setCollaboratorIds(new String[]{"ou_cd09481727e91fce1f12b7b0ed1500d2","ou_da28bfeca28299a2eb314c6280a6905c"});
// larkRobotRequest.setTask(task);
// taskHelper.createTask(larkRobotRequest);
LarkTaskRequest larkTaskRequest = new LarkTaskRequest(appId, secret,"0148604b-9504-44d3-88fb-cde2e97fd0ee");
GetTaskRespBody taskInfo = taskHelper.getTaskInfo(larkTaskRequest);
int i = 0;
}
/**
*
*
* @return
*/
public CreateTaskRespBody createTask(LarkTaskRequest request) {
try {
CreateTaskResp createTaskResp = buildClient(request)
.task()
.task().create(
CreateTaskReq.newBuilder()
.userIdType(CreateTaskUserIdTypeEnum.OPEN_ID)
.task(request.getTask())
.build()
);
return createTaskResp.getData();
} catch (Exception e) {
throw new RuntimeException(new LarkException("LarkTaskHelper.createTask",e.getMessage(),request).getErrorMessageBody());
}
}
/**
*
*
* @return
*/
public GetTaskRespBody getTaskInfo(LarkTaskRequest request) {
try {
GetTaskResp getTaskResp = buildClient(request)
.task()
.task().get(
GetTaskReq.newBuilder()
.taskId(request.getLarkTaskId())
.build()
);
return getTaskResp.getData();
} catch (Exception e) {
throw new RuntimeException(new LarkException("LarkTaskHelper.createTask",e.getMessage(),request).getErrorMessageBody());
}
}
}

@ -7,6 +7,7 @@ import com.lark.oapi.service.authen.v1.model.CreateAccessTokenRespBody;
import com.lark.oapi.service.contact.v3.enums.BatchGetIdUserUserIdTypeEnum; import com.lark.oapi.service.contact.v3.enums.BatchGetIdUserUserIdTypeEnum;
import com.lark.oapi.service.contact.v3.model.*; import com.lark.oapi.service.contact.v3.model.*;
import com.ruoyi.flyingbook.domain.lark.LarkApprovalRequest; import com.ruoyi.flyingbook.domain.lark.LarkApprovalRequest;
import com.ruoyi.flyingbook.domain.lark.LarkException;
import com.ruoyi.flyingbook.domain.lark.LarkUserRequest; import com.ruoyi.flyingbook.domain.lark.LarkUserRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -39,10 +40,10 @@ public class LarkUserHelper extends LarkHelper{
if (getUserResp.getCode() == 0){ if (getUserResp.getCode() == 0){
return getUserResp.getData(); return getUserResp.getData();
}else { }else {
throw new RuntimeException(getUserResp.getMsg()); throw new RuntimeException(new LarkException("LarkUserHelper.getUserInfoDetail",getUserResp.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkUserHelper.getUserInfoDetail",e.getMessage(),request).getErrorMessageBody());
} }
} }
@ -66,7 +67,7 @@ public class LarkUserHelper extends LarkHelper{
) )
.getData(); .getData();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(new LarkException("LarkUserHelper.getUserToken",e.getMessage(),request).getErrorMessageBody());
} }
} }
} }

@ -0,0 +1,64 @@
package com.ruoyi.flyingbook.aop;
import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper;
import com.ruoyi.flyingbook.domain.EventLog;
import com.ruoyi.flyingbook.domain.lark.LarkException;
import com.ruoyi.flyingbook.domain.lark.LarkRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author yuxiangyong
* @create 2023-05-24 21:36
*/
@Slf4j
@Aspect
@Component
public class ErrorLogAop {
@Autowired
private LarkRobotHelper larkRobotHelper;
@Value("${lark.robot.group}")
private String ROBOT_GROUP;
/**
*
*/
@After("execution(* com.ruoyi.flyingbook.service.IEventLogService.insertEventLog(..)) && (args(dto))")
public void prePersist(EventLog dto) {
String errorMessage = dto.getErrorMessage();
if (StringUtils.isNotBlank(errorMessage)) {
LarkRequest larkRequest = new LarkRequest("a", "b");
LarkException larkException = new LarkException("",errorMessage, larkRequest);
String errorMessageBody = larkException.getErrorMessageBody();
// larkRobotHelper.sendMessageByBot(ROBOT_GROUP, errorMessageBody);
}
}
/**
*
*/
@After("execution(* com.ruoyi.flyingbook.service.IEventLogService.insertBatchEventLog(..)) && (args(dto))")
public void prePersist(List<EventLog> dto) {
List<String> errorList = dto.stream()
.filter(r -> {
return StringUtils.isNotBlank(r.getErrorMessage());
})
.map(EventLog::getErrorMessage)
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(errorList)) {
// larkRobotHelper.sendMessageByBot(ROBOT_GROUP,String.join(",",errorList));
}
}
}

@ -3,9 +3,12 @@ package com.ruoyi.flyingbook.controller;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.PdfUtils; import com.ruoyi.common.utils.PdfUtils;
import com.ruoyi.flyingbook.LarkHelper.LarkFileHelper; import com.ruoyi.flyingbook.LarkHelper.LarkFileHelper;
import com.ruoyi.flyingbook.domain.Event;
import com.ruoyi.flyingbook.domain.EventLog;
import com.ruoyi.flyingbook.domain.edi.EdiResponseVo; import com.ruoyi.flyingbook.domain.edi.EdiResponseVo;
import com.ruoyi.flyingbook.domain.edi.SyncToTableRequest; import com.ruoyi.flyingbook.domain.edi.SyncToTableRequest;
import com.ruoyi.flyingbook.edi.EdiOperateService; import com.ruoyi.flyingbook.edi.EdiOperateService;
import com.ruoyi.flyingbook.service.IEventLogService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -16,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.util.Arrays;
@Slf4j @Slf4j
@RestController @RestController
@ -29,6 +33,8 @@ public class EdiController extends BaseController {
private LarkFileHelper larkFileHelper; private LarkFileHelper larkFileHelper;
@Autowired @Autowired
ResourceLoader resourceLoader; ResourceLoader resourceLoader;
@Autowired
private IEventLogService iEventLogService;
/** /**
* *
@ -40,35 +46,41 @@ public class EdiController extends BaseController {
@RequestMapping("/createPdf") @RequestMapping("/createPdf")
public void exportPdfDemo(@RequestParam("param") String param) throws Exception { public void exportPdfDemo(@RequestParam("param") String param) throws Exception {
System.out.println(System.getProperty("user.dir")); EventLog log1 = new EventLog();
ClassPathResource classPathResource = new ClassPathResource("photo/title.png"); log1.setErrorMessage("asd");
InputStream inputStream = null; iEventLogService.insertEventLog(log1);
try { EventLog log2 = new EventLog();
inputStream = classPathResource.getInputStream(); iEventLogService.insertBatchEventLog(Arrays.asList(log1,log2));
File inuModel = new File("/");
FileUtils.copyToFile(inputStream, inuModel); // System.out.println(System.getProperty("user.dir"));
System.out.println(inuModel.getName()); // ClassPathResource classPathResource = new ClassPathResource("photo/title.png");
} catch (Exception e) { // InputStream inputStream = null;
log.error("", e); // try {
}finally { // inputStream = classPathResource.getInputStream();
if (inputStream != null){ // File inuModel = new File("/");
inputStream.close(); // FileUtils.copyToFile(inputStream, inuModel);
} // System.out.println(inuModel.getName());
} // } catch (Exception e) {
Resource resource = resourceLoader.getResource("classpath:photo/title.png"); // log.error("", e);
InputStream inputStream2 = null; // }finally {
try { // if (inputStream != null){
inputStream2 = resource.getInputStream(); // inputStream.close();
File inuModel = new File("/"); // }
FileUtils.copyToFile(inputStream, inuModel); // }
System.out.println(inuModel.getName()); // Resource resource = resourceLoader.getResource("classpath:photo/title.png");
} catch (Exception e) { // InputStream inputStream2 = null;
log.error("", e); // try {
}finally { // inputStream2 = resource.getInputStream();
if (inputStream2 != null){ // File inuModel = new File("/");
inputStream2.close(); // FileUtils.copyToFile(inputStream, inuModel);
} // System.out.println(inuModel.getName());
} // } catch (Exception e) {
// log.error("", e);
// }finally {
// if (inputStream2 != null){
// inputStream2.close();
// }
// }
// CourseFeedbackTemplateDto resultDTO = new CourseFeedbackTemplateDto(); // CourseFeedbackTemplateDto resultDTO = new CourseFeedbackTemplateDto();
// resultDTO.setProgram("program"); // resultDTO.setProgram("program");
// resultDTO.setStudentName("student"); // resultDTO.setStudentName("student");

@ -30,7 +30,10 @@ public class RequestVo {
private String errorMessage; private String errorMessage;
private Boolean stop; private Boolean stop;
/**
* LarkTask
*/
private String larkTaskId;
/** /**
* ApprovalCallback * ApprovalCallback
*/ */

@ -0,0 +1,30 @@
package com.ruoyi.flyingbook.domain.lark;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author yuxiangyong
* @create 2023-05-25 21:31
*/
@Data
@NoArgsConstructor
public class LarkException {
private String origin;
private String errorMessage;
private Object request;
public LarkException(String origin,String errorMessage, Object request) {
this.origin = origin;
this.errorMessage = errorMessage;
this.request = request;
}
public String getErrorMessageBody(){
return this.toString();
}
}

@ -0,0 +1,74 @@
package com.ruoyi.flyingbook.domain.lark;
import com.lark.oapi.service.task.v1.model.Origin;
import com.lark.oapi.service.task.v1.model.Task;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* @author yuxiangyong
* @create 2023-03-18 1:05
*/
@Data
@NoArgsConstructor
public class LarkTaskRequest extends LarkRequest{
private String larkTaskId;
/**
*
*/
private String content;
/**
*
*/
private String msgType;
/**
* id
*/
private String[] receiveIdList;
private Task task;
public LarkTaskRequest(String appId, String appSecret) {
super(appId, appSecret);
}
public LarkTaskRequest(String appId, String appSecret,Task task) {
super(appId, appSecret);
this.task = task;
}
public LarkTaskRequest(String appId, String appSecret,String larkTaskId) {
super(appId, appSecret);
this.larkTaskId = larkTaskId;
}
public LarkTaskRequest(String appId, String appSecret,String summary,String desc,String[] receiveIdList) {
super(appId, appSecret);
Task task = new Task();
task.setSummary(summary);
task.setDescription(desc);
task.setOrigin(this.getDefaultOrigin());
task.setCollaboratorIds(receiveIdList);
this.task = task;
}
public Task buildBaseTask(String summary,String desc,String[] receiveIdList){
Task task = new Task();
task.setSummary(summary);
task.setDescription(desc);
task.setOrigin(this.getDefaultOrigin());
task.setCollaboratorIds(receiveIdList);
return task;
}
public Origin getDefaultOrigin(){
Origin origin = new Origin();
origin.setPlatformI18nName("RY_TIR");
return origin;
}
}

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.enums.CallBackTypeEnum; import com.ruoyi.common.enums.CallBackTypeEnum;
import com.ruoyi.flyingbook.domain.RequestVo; import com.ruoyi.flyingbook.domain.RequestVo;
import com.ruoyi.flyingbook.strategy.callback.ApprovalCallback; import com.ruoyi.flyingbook.strategy.callback.ApprovalCallback;
import com.ruoyi.flyingbook.strategy.callback.LarkTaskCallback;
import com.ruoyi.flyingbook.strategy.callback.MultidimensionalTableCallback; import com.ruoyi.flyingbook.strategy.callback.MultidimensionalTableCallback;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -20,6 +21,8 @@ public class LarkCallBackFactory {
private MultidimensionalTableCallback multidimensionalTableCallback; private MultidimensionalTableCallback multidimensionalTableCallback;
@Autowired @Autowired
private ApprovalCallback approvalCallback; private ApprovalCallback approvalCallback;
@Autowired
private LarkTaskCallback larkTaskCallback;
public void execute(RequestVo larkRequest) { public void execute(RequestVo larkRequest) {
String message = larkRequest.getMessage(); String message = larkRequest.getMessage();
@ -44,6 +47,9 @@ public class LarkCallBackFactory {
case APPROVAL_TASK: case APPROVAL_TASK:
approvalCallback.execute(larkRequest); approvalCallback.execute(larkRequest);
break; break;
case LARK_TASK:
larkTaskCallback.execute(larkRequest);
break;
default: default:
break; break;
} }

@ -4,6 +4,7 @@ import com.ruoyi.common.enums.EventTypeEnum;
import com.ruoyi.flyingbook.domain.Event; import com.ruoyi.flyingbook.domain.Event;
import com.ruoyi.flyingbook.domain.RequestVo; import com.ruoyi.flyingbook.domain.RequestVo;
import com.ruoyi.flyingbook.strategy.operate.ApprovalCallbackOperate; import com.ruoyi.flyingbook.strategy.operate.ApprovalCallbackOperate;
import com.ruoyi.flyingbook.strategy.operate.LarkTaskCallbackOperate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -18,21 +19,27 @@ public class LarkOperateFactory {
private LarkOperateTableFactory larkOperateTableFactory; private LarkOperateTableFactory larkOperateTableFactory;
@Autowired @Autowired
private ApprovalCallbackOperate approvalCallbackOperate; private ApprovalCallbackOperate approvalCallbackOperate;
@Autowired
private LarkTaskCallbackOperate larkTaskCallbackOperate;
public void execute(Event event) { public void execute(Event event) {
EventTypeEnum eventTypeEnum = EventTypeEnum.getByCode(event.getType()); EventTypeEnum eventTypeEnum = EventTypeEnum.getByCode(event.getType());
if (eventTypeEnum == null) { if (eventTypeEnum == null) {
return; return;
} }
RequestVo request = new RequestVo();
switch (eventTypeEnum) { switch (eventTypeEnum) {
case ROW_CHANGE: case ROW_CHANGE:
larkOperateTableFactory.execute(event); larkOperateTableFactory.execute(event);
break; break;
case APPROVAL_TASK: case APPROVAL_TASK:
RequestVo request = new RequestVo();
request.setEvent(event); request.setEvent(event);
approvalCallbackOperate.execute(request); approvalCallbackOperate.execute(request);
break; break;
case LARK_TASK:
request.setEvent(event);
larkTaskCallbackOperate.execute(request);
break;
default: default:
break; break;
} }

@ -1,5 +1,6 @@
package com.ruoyi.flyingbook.factory; package com.ruoyi.flyingbook.factory;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.RedisConstants; import com.ruoyi.common.constant.RedisConstants;
import com.ruoyi.common.enums.AppType; import com.ruoyi.common.enums.AppType;
import com.ruoyi.common.enums.EventOperateStatus; import com.ruoyi.common.enums.EventOperateStatus;
@ -10,10 +11,7 @@ import com.ruoyi.flyingbook.service.IEventLogService;
import com.ruoyi.flyingbook.service.IEventService; import com.ruoyi.flyingbook.service.IEventService;
import com.ruoyi.flyingbook.service.ILarkCompanyRelationService; import com.ruoyi.flyingbook.service.ILarkCompanyRelationService;
import com.ruoyi.flyingbook.service.ILarkTableRelationService; import com.ruoyi.flyingbook.service.ILarkTableRelationService;
import com.ruoyi.flyingbook.strategy.operate.MultidimensionalTableDoubleOperate; import com.ruoyi.flyingbook.strategy.operate.*;
import com.ruoyi.flyingbook.strategy.operate.MultidimensionalTableMaintenanceRowOperate;
import com.ruoyi.flyingbook.strategy.operate.MultidimensionalTableOperate;
import com.ruoyi.flyingbook.strategy.operate.MultidimensionalTableSingleOperate;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -41,6 +39,8 @@ public class LarkOperateTableFactory {
@Resource @Resource
private MultidimensionalTableMaintenanceRowOperate maintenanceRowOperate; private MultidimensionalTableMaintenanceRowOperate maintenanceRowOperate;
@Resource @Resource
private MultidimensionalTableCreateTaskOperate multidimensionalTableCreateTaskOperate;
@Resource
protected ILarkCompanyRelationService larkCompanyRelationService; protected ILarkCompanyRelationService larkCompanyRelationService;
@Resource @Resource
protected IEventService eventService; protected IEventService eventService;
@ -52,6 +52,9 @@ public class LarkOperateTableFactory {
public void execute(Event event) { public void execute(Event event) {
try { try {
RequestVo request = buildRequest(event); RequestVo request = buildRequest(event);
if (CollectionUtils.isEmpty(request.getLarkTableRelations())){
return;
}
String cacheKey = String.format("%s_%s_%s_%s", RedisConstants.MULTIPLE_TABLE_RECORD, event.getAppToken(), event.getTableId(), event.getRecordId()); String cacheKey = String.format("%s_%s_%s_%s", RedisConstants.MULTIPLE_TABLE_RECORD, event.getAppToken(), event.getTableId(), event.getRecordId());
redisTemplate.delete(cacheKey); redisTemplate.delete(cacheKey);
switch (request.getTableRelationType()) { switch (request.getTableRelationType()) {
@ -64,12 +67,15 @@ public class LarkOperateTableFactory {
case MAINTENANCE_ROW_RELATION: case MAINTENANCE_ROW_RELATION:
maintenanceRowOperate.execute(request); maintenanceRowOperate.execute(request);
break; break;
case CREATE_TASK_BY_TABLE:
multidimensionalTableCreateTaskOperate.execute(request);
break;
default: default:
throw new RuntimeException("当前关联表类型不存在"); throw new RuntimeException("当前关联表类型不存在");
} }
} catch (Exception e) { } catch (Exception e) {
eventService.updateStatus(event.getId(), EventOperateStatus.ERROR.getCode(), event.getNumbers() + 1); eventService.updateStatus(event.getId(), EventOperateStatus.ERROR.getCode(), event.getNumbers() + 1);
EventLog eventLog = new EventLog(event.getId(), "BUILD_REQUEST", e.getMessage()); EventLog eventLog = new EventLog(event.getId(), "BUILD_REQUEST", JSONObject.toJSONString(event),"", e.getMessage());
eventLogService.insertEventLog(eventLog); eventLogService.insertEventLog(eventLog);
} }
@ -111,8 +117,12 @@ public class LarkOperateTableFactory {
.map(LarkTableRelation::getRelationType) .map(LarkTableRelation::getRelationType)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isEmpty(tableRelationTypeList) || tableRelationTypeList.size() > 1) { if (CollectionUtils.isEmpty(tableRelationTypeList)) {
String errorMessage = String.format("tableId:{}表关系未配置 或同一张表配置类型超过一种", event.getTableId()); log.info(String.format("tableId:{%s}表关系未配置", event.getTableId()));
return null;
}
if (tableRelationTypeList.size() > 1) {
String errorMessage = String.format("tableId:{%s}表配置类型超过一种", event.getTableId());
log.error("LarkOperateTableFactory.check:{}", errorMessage); log.error("LarkOperateTableFactory.check:{}", errorMessage);
throw new RuntimeException(errorMessage); throw new RuntimeException(errorMessage);
} }

@ -0,0 +1,113 @@
package com.ruoyi.flyingbook.strategy.callback;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.enums.EventOperateStatus;
import com.ruoyi.common.enums.EventOperateType;
import com.ruoyi.common.enums.EventTypeEnum;
import com.ruoyi.common.enums.FlagStatus;
import com.ruoyi.flyingbook.domain.Event;
import com.ruoyi.flyingbook.domain.EventLog;
import com.ruoyi.flyingbook.domain.RequestVo;
import com.ruoyi.flyingbook.service.IEventLogService;
import com.ruoyi.flyingbook.service.IEventService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* @author yuxiangyong
* @create 2023-03-12 15:58
*/
@Slf4j
@Service
public class LarkTaskCallback extends CallbackAbstract {
@Autowired
private IEventService eventService;
@Autowired
private IEventLogService eventLogService;
@Override
protected Boolean check(RequestVo request) {
return Boolean.TRUE;
}
@Override
protected void preOperate(RequestVo request) {
String message = request.getMessage();
JSONObject jsonObject = JSONObject.parseObject(message);
JSONObject event = jsonObject.getJSONObject("event");
request.setLarkTaskId(event.getString("task_id"));
}
@Override
protected void businessProcessing(RequestVo request) {
Event event = queryEvent(request.getAppId(),request.getFromRecordId());
//如果已经存在处理中的就不需要操作数据库了
if (event != null && EventOperateStatus.PENDING.getCode().equals(event.getOperateStatus()) && event.getNumbers() < 3){
return;
}
event = this.buildDto(request,event);
if (event.getId() == null){
eventService.insertEvent(event);
}else {
eventService.updateStatus(event.getId(),EventOperateStatus.PENDING.getCode(),0L);
}
request.setEventId(event.getId());
}
@Override
protected void endHandle(RequestVo request) {
if (request.getEventId() == null){
return;
}
EventLog eventLog = StringUtils.isBlank(request.getErrorMessage()) ?
new EventLog(request.getEventId(),EventOperateType.LARK_TASK_CALL_BACK.getCode(),request.getMessage())
: new EventLog(request.getEventId(),EventOperateType.LARK_TASK_CALL_BACK.getCode(),request.getMessage(),request.getErrorCode(),request.getErrorMessage());
eventLogService.insertEventLog(eventLog);
}
@Override
protected String buildResult(RequestVo request) {
return "";
}
@Override
protected String getName() {
return this.getClass().getSimpleName();
}
private Event queryEvent(String appId,String recordId){
Event event = new Event();
event.setAppId(appId);
event.setRecordId(recordId);
List<Event> events = eventService.selectEventList(event);
if (CollectionUtils.isNotEmpty(events)){
return events.get(0);
}
return null;
}
private Event buildDto(RequestVo request, Event event){
event = event == null ? new Event() :event;
event.setFlag(FlagStatus.OK.getCode());
event.setRecordId(request.getLarkTaskId());
event.setNumbers(0L);
event.setOperateStatus(EventOperateStatus.PENDING.getCode());
event.setCreateBy("System");
event.setCreateTime(new Date());
event.setUpdateTime(new Date());
event.setUpdateBy("System");
event.setAppId(request.getAppId());
event.setType(EventTypeEnum.LARK_TASK.getCode());
return event;
}
}

@ -13,6 +13,8 @@ import java.util.Map;
*/ */
public abstract class LarkAbstract extends LarkOperateAbstract { public abstract class LarkAbstract extends LarkOperateAbstract {
protected static final Integer SAGE_CODE = 1254043;
/** /**

@ -0,0 +1,87 @@
package com.ruoyi.flyingbook.strategy.operate;
import com.ruoyi.common.enums.EventOperateStatus;
import com.ruoyi.common.enums.EventOperateType;
import com.ruoyi.flyingbook.LarkHelper.LarkTaskHelper;
import com.ruoyi.flyingbook.domain.Event;
import com.ruoyi.flyingbook.domain.EventLog;
import com.ruoyi.flyingbook.domain.RequestVo;
import com.ruoyi.flyingbook.service.IEventLogService;
import com.ruoyi.flyingbook.service.IEventService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
*
*
* @author yuxiangyong
* @create 2023-03-13 20:47
*/
@Slf4j
@Component("LarkTaskCallbackOperate")
public class LarkTaskCallbackOperate extends LarkAbstract {
@Autowired
private IEventLogService eventLogService;
@Autowired
private LarkTaskHelper larkTaskHelper;
@Autowired
private IEventService eventService;
@Override
protected void preOperate(RequestVo request) {
Event event = request.getEvent();
if (event == null) {
throw new RuntimeException("当前事件为空");
}
}
@Override
protected void businessProcessing(RequestVo request) {
Event event = request.getEvent();
String larkTaskId = event.getRecordId();
// larkTaskHelper.createTask()
}
@Override
protected Map<String, Object> getBody(RequestVo request) {
return null;
}
@Override
protected void endHandle(RequestVo request) {
Event event = request.getEvent();
EventLog eventLog = null;
if (StringUtils.isBlank(request.getErrorMessage())) {
eventService.updateStatus(event.getId(), EventOperateStatus.SUCCESS.getCode(), event.getNumbers());
eventLog = new EventLog(event.getId(), EventOperateType.SYNC_CANDLE.getCode(), request.getMessage());
} else {
eventService.updateStatus(event.getId(), EventOperateStatus.PENDING.getCode(), event.getNumbers() + 1);
eventLog = new EventLog(event.getId(), EventOperateType.SYNC_CANDLE.getCode(), request.getMessage(), request.getErrorCode(), request.getErrorMessage());
}
if (eventLog != null) {
eventLog.setOperateInfo(request.getOperateInfo());
eventLogService.insertEventLog(eventLog);
}
}
@Override
protected String buildResult(RequestVo request) {
return null;
}
@Override
protected String getName() {
return this.getClass().getSimpleName();
}
}

@ -0,0 +1,138 @@
package com.ruoyi.flyingbook.strategy.operate;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.internal.LinkedTreeMap;
import com.lark.oapi.core.response.RawResponse;
import com.lark.oapi.service.bitable.v1.model.AppTableRecord;
import com.lark.oapi.service.bitable.v1.model.GetAppTableRecordResp;
import com.lark.oapi.service.bitable.v1.model.GetAppTableRecordRespBody;
import com.lark.oapi.service.task.v1.model.Task;
import com.ruoyi.common.enums.EventOperateStatus;
import com.ruoyi.common.enums.EventOperateType;
import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper;
import com.ruoyi.flyingbook.LarkHelper.LarkTaskHelper;
import com.ruoyi.flyingbook.domain.Event;
import com.ruoyi.flyingbook.domain.EventLog;
import com.ruoyi.flyingbook.domain.RequestVo;
import com.ruoyi.flyingbook.domain.lark.LarkException;
import com.ruoyi.flyingbook.domain.lark.LarkTableRequest;
import com.ruoyi.flyingbook.domain.lark.LarkTaskRequest;
import com.ruoyi.flyingbook.service.IEventLogService;
import com.ruoyi.flyingbook.service.IEventService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* _
*
* @author yuxiangyong
* @create 2023-03-13 20:47
*/
@Slf4j
@Component("MultidimensionalTableCreateTaskOperate")
public class MultidimensionalTableCreateTaskOperate extends LarkAbstract {
@Autowired
protected LarkTableHelper larkTableHelper;
@Autowired
protected LarkTaskHelper larkTaskHelper;
@Autowired
protected IEventService eventService;
@Autowired
protected IEventLogService eventLogService;
@Override
protected void preOperate(RequestVo request) {
}
@Override
protected void businessProcessing(RequestVo request) {
Event event = request.getEvent();
LarkTableRequest detailRequest = new LarkTableRequest(request.getAppId(), request.getAppSecret(), event.getAppToken(), event.getTableId(), event.getRecordId());
detailRequest.setSafeCode(Arrays.asList(SAGE_CODE));
GetAppTableRecordResp recordDetail = larkTableHelper.getTableRecordDetail(detailRequest);
request.setRespBody(recordDetail);
send(request);
}
@Override
protected Map<String, Object> getBody(RequestVo request) {
Map<String, Object> result = new HashMap<>();
return result;
}
private void send(RequestVo request) {
Event event = request.getEvent();
GetAppTableRecordResp respBody = request.getRespBody();
if (respBody.getCode() != 0){
throw new RuntimeException(String.format("创建任务时,表${}中不存在record{}",event.getTableId(),event.getRecordId()));
}
AppTableRecord record = respBody.getData().getRecord();
Map<String, Object> fields = record.getFields();
Object syncTaskCountObj = fields.get("批量同步任务数量");
Object taskCreatorObj = fields.get("人员");
if(syncTaskCountObj == null || taskCreatorObj == null){
return;
}
Integer syncTaskCount = Integer.valueOf(syncTaskCountObj.toString());
ArrayList<LinkedTreeMap<String,Object>> taskCreator = (ArrayList<LinkedTreeMap<String,Object>>) taskCreatorObj;
int size = taskCreator.size();
String[] createrIdList = new String[size];
for (int i = 0; i < size; i++) {
String id = String.valueOf(taskCreator.get(i).get("id"));
createrIdList[i] = id;
}
LarkTaskRequest larkTaskRequest = new LarkTaskRequest(request.getAppId(),request.getAppSecret());
Task task = larkTaskRequest.buildBaseTask("", "", new String[0]);
task.setCollaboratorIds(createrIdList);
larkTaskRequest.setTask(task);
for (int i = 0;i < syncTaskCount;i++){
String createTaskTemplate = new StringBuilder("创建任务模板").append(i).toString();
task.setSummary(createTaskTemplate);
task.setDescription(createTaskTemplate);
larkTaskHelper.createTask(larkTaskRequest);
}
request.setOperateInfo(JSONObject.toJSONString(task));
request.setEventOperateType(EventOperateType.CREATE_TASK);
}
@Override
protected void endHandle(RequestVo request) {
Event event = request.getEvent();
EventLog eventLog = null;
if (StringUtils.isBlank(request.getErrorMessage())) {
eventService.updateStatus(event.getId(), EventOperateStatus.SUCCESS.getCode(), event.getNumbers());
eventLog = new EventLog(event.getId(), request.getEventOperateType().getCode(), request.getMessage());
} else {
eventService.updateStatus(event.getId(), EventOperateStatus.PENDING.getCode(), event.getNumbers() + 1);
if (request.getEventOperateType() != null) {
eventLog = new EventLog(event.getId(), request.getEventOperateType().getCode(), request.getMessage(), request.getErrorCode(), request.getErrorMessage());
}
}
if (eventLog != null) {
eventLog.setOperateInfo(request.getOperateInfo());
eventLogService.insertEventLog(eventLog);
}
}
@Override
protected String buildResult(RequestVo request) {
return null;
}
@Override
protected String getName() {
return this.getClass().getSimpleName();
}
}
Loading…
Cancel
Save