1、aop切面拦截异常信息并发送机器人消息
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
2、根据飞书表格创建飞书任务 3、飞书任务回调(未完成)于相涌/robot_optimize
parent
ffe7e238f2
commit
40f1f3deef
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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…
Reference in new issue