日历同步

于相涌/robot_optimize
YXY 1 year ago
parent 085b806494
commit 0e2d9934c8

@ -6,6 +6,7 @@ import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Date; import java.util.Date;
@ -149,9 +150,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
} }
public static LocalDateTime long2ldt(long time) { public static LocalDateTime long2ldt(long time) {
Instant instant = Instant.ofEpochMilli(time); return LocalDateTime.ofInstant(Instant.ofEpochSecond(time), ZoneOffset.ofHours(8));
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
} }
public static String long2Str(long time, String pattern) { public static String long2Str(long time, String pattern) {

@ -36,7 +36,7 @@ public class LarkApprovalHelper extends LarkHelper{
if (getInstanceResp.getCode() == 0){ if (getInstanceResp.getCode() == 0){
return getInstanceResp.getData(); return getInstanceResp.getData();
}else { }else {
throw new RuntimeException(new LarkException("LarkApprovalHelper.getApprovalInfoDetail", JSONObject.toJSONString(getInstanceResp.getError()),request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkApprovalHelper.getApprovalInfoDetail", getInstanceResp.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkApprovalHelper.getApprovalInfoDetail",e.getMessage(),request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkApprovalHelper.getApprovalInfoDetail",e.getMessage(),request).getErrorMessageBody());

@ -1,8 +1,6 @@
package com.ruoyi.flyingbook.LarkHelper; package com.ruoyi.flyingbook.LarkHelper;
import com.alibaba.fastjson.JSONObject;
import com.lark.oapi.core.response.EmptyData; import com.lark.oapi.core.response.EmptyData;
import com.lark.oapi.service.calendar.v4.enums.BatchDeleteCalendarEventAttendeeUserIdTypeEnum;
import com.lark.oapi.service.calendar.v4.model.*; import com.lark.oapi.service.calendar.v4.model.*;
import com.ruoyi.flyingbook.domain.lark.LarkCalendarRequest; import com.ruoyi.flyingbook.domain.lark.LarkCalendarRequest;
import com.ruoyi.flyingbook.domain.lark.LarkException; import com.ruoyi.flyingbook.domain.lark.LarkException;
@ -42,7 +40,7 @@ public class LarkCalendarHelper extends LarkHelper {
if (primary.getCode() == 0) { if (primary.getCode() == 0) {
return primary.getData(); return primary.getData();
} else { } else {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", JSONObject.toJSONString(primary.getError()), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", primary.getMsg(), request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", e.getMessage(), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", e.getMessage(), request).getErrorMessageBody());
@ -67,10 +65,10 @@ public class LarkCalendarHelper extends LarkHelper {
if (list.getCode() == 0) { if (list.getCode() == 0) {
return list.getData(); return list.getData();
} else { } else {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", JSONObject.toJSONString(list.getError()), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.getCalendarDetail", list.getMsg(), request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", e.getMessage(), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.getCalendarDetail", e.getMessage(), request).getErrorMessageBody());
} }
} }
@ -112,10 +110,10 @@ public class LarkCalendarHelper extends LarkHelper {
if (createCalendarEventResp.getCode() == 0) { if (createCalendarEventResp.getCode() == 0) {
return createCalendarEventResp.getData(); return createCalendarEventResp.getData();
} else { } else {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", JSONObject.toJSONString(createCalendarEventResp.getError()), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.createCalendarDetail", createCalendarEventResp.getMsg(), request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", e.getMessage(), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.createCalendarDetail", e.getMessage(), request).getErrorMessageBody());
} }
} }
@ -136,6 +134,7 @@ public class LarkCalendarHelper extends LarkHelper {
.summary(request.getSummary()) .summary(request.getSummary())
.needNotification(request.getNeedNotification()) .needNotification(request.getNeedNotification())
.attendeeAbility(request.getAttendeeAbility()) .attendeeAbility(request.getAttendeeAbility())
.description(request.getDesc())
.startTime( .startTime(
TimeInfo.newBuilder() TimeInfo.newBuilder()
.timezone(request.getTimeZone()) .timezone(request.getTimeZone())
@ -156,10 +155,10 @@ public class LarkCalendarHelper extends LarkHelper {
if (patch.getCode() == 0) { if (patch.getCode() == 0) {
return patch.getData(); return patch.getData();
} else { } else {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", JSONObject.toJSONString(patch.getError()), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.updateCalendarDetail", patch.getMsg(), request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", e.getMessage(), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.updateCalendarDetail", e.getMessage(), request).getErrorMessageBody());
} }
} }
@ -188,10 +187,10 @@ public class LarkCalendarHelper extends LarkHelper {
if (createCalendarEventAttendeeResp.getCode() == 0) { if (createCalendarEventAttendeeResp.getCode() == 0) {
return createCalendarEventAttendeeResp.getData(); return createCalendarEventAttendeeResp.getData();
} else { } else {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", JSONObject.toJSONString(createCalendarEventAttendeeResp.getError()), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.attendeesCalendarDetail", createCalendarEventAttendeeResp.getMsg(), request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", e.getMessage(), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.attendeesCalendarDetail", e.getMessage(), request).getErrorMessageBody());
} }
} }
@ -208,10 +207,10 @@ public class LarkCalendarHelper extends LarkHelper {
BatchDeleteCalendarEventAttendeeReq.newBuilder() BatchDeleteCalendarEventAttendeeReq.newBuilder()
.calendarId(request.getCalendarId()) .calendarId(request.getCalendarId())
.eventId(request.getEventId()) .eventId(request.getEventId())
.userIdType(BatchDeleteCalendarEventAttendeeUserIdTypeEnum.USER_ID)
.batchDeleteCalendarEventAttendeeReqBody( .batchDeleteCalendarEventAttendeeReqBody(
BatchDeleteCalendarEventAttendeeReqBody.newBuilder() BatchDeleteCalendarEventAttendeeReqBody.newBuilder()
.deleteIds(request.getCalendarEventDeleteArray()) .deleteIds(request.getCalendarEventDeleteArray())
.needNotification(Boolean.FALSE)
.build() .build()
) )
.build() .build()
@ -220,10 +219,10 @@ public class LarkCalendarHelper extends LarkHelper {
if (batchDeleteCalendarEventAttendeeResp.getCode() == 0) { if (batchDeleteCalendarEventAttendeeResp.getCode() == 0) {
return batchDeleteCalendarEventAttendeeResp.getData(); return batchDeleteCalendarEventAttendeeResp.getData();
} else { } else {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", JSONObject.toJSONString(batchDeleteCalendarEventAttendeeResp.getError()), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.unAttendeesCalendarDetail", batchDeleteCalendarEventAttendeeResp.getMsg(), request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkCalendarHelper.getPrimaryCalendar", e.getMessage(), request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkCalendarHelper.unAttendeesCalendarDetail", e.getMessage(), request).getErrorMessageBody());
} }
} }

@ -8,6 +8,7 @@ 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;
import com.lark.oapi.service.im.v1.model.CreateMessageResp; import com.lark.oapi.service.im.v1.model.CreateMessageResp;
import com.lark.oapi.service.im.v1.model.CreateMessageRespBody; import com.lark.oapi.service.im.v1.model.CreateMessageRespBody;
import com.ruoyi.flyingbook.domain.lark.LarkException;
import com.ruoyi.flyingbook.domain.lark.LarkRobotRequest; 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;
@ -70,7 +71,7 @@ public class LarkRobotHelper extends LarkHelper{
if (createMessageResp.getCode() == 0){ if (createMessageResp.getCode() == 0){
return createMessageResp.getData(); return createMessageResp.getData();
}else { }else {
throw new RuntimeException(createMessageResp.getMsg()); throw new RuntimeException(new LarkException("LarkRobotHelper.sendUserMessage", createMessageResp.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage());

@ -68,7 +68,11 @@ public class LarkTableHelper extends LarkHelper{
) )
.build() .build()
); );
if (createAppResp.getCode() == 0){
return createAppResp.getData(); return createAppResp.getData();
}else {
throw new RuntimeException(new LarkException("LarkTableHelper.createMultiTable", createAppResp.getMsg(),request).getErrorMessageBody());
}
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkTableHelper.createMultiTable",e.getMessage(),request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkTableHelper.createMultiTable",e.getMessage(),request).getErrorMessageBody());
} }
@ -81,7 +85,7 @@ public class LarkTableHelper extends LarkHelper{
*/ */
public CreateAppTableRespBody createDataTable(LarkTableRequest request) { public CreateAppTableRespBody createDataTable(LarkTableRequest request) {
try { try {
return buildClient(request).bitable().appTable().create( CreateAppTableResp createAppTableResp = buildClient(request).bitable().appTable().create(
CreateAppTableReq.newBuilder() CreateAppTableReq.newBuilder()
.appToken(request.getAppToken()) .appToken(request.getAppToken())
.createAppTableReqBody( .createAppTableReqBody(
@ -96,7 +100,12 @@ public class LarkTableHelper extends LarkHelper{
.build() .build()
) )
.build() .build()
).getData(); );
if (createAppTableResp.getCode() == 0){
return createAppTableResp.getData();
}else {
throw new RuntimeException(new LarkException("LarkTableHelper.createDataTable", createAppTableResp.getMsg(),request).getErrorMessageBody());
}
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkTableHelper.createDataTable",e.getMessage(),request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkTableHelper.createDataTable",e.getMessage(),request).getErrorMessageBody());
} }
@ -110,13 +119,17 @@ public class LarkTableHelper extends LarkHelper{
*/ */
public GetAppTableRecordResp getTableRecordDetail(LarkTableRequest request) { public GetAppTableRecordResp getTableRecordDetail(LarkTableRequest request) {
try { try {
return buildClient(request).bitable().appTableRecord().get( GetAppTableRecordResp getAppTableRecordResp = buildClient(request).bitable().appTableRecord().get(
GetAppTableRecordReq GetAppTableRecordReq
.newBuilder() .newBuilder()
.appToken(request.getAppToken()) .appToken(request.getAppToken())
.tableId(request.getAppTable()) .tableId(request.getAppTable())
.recordId(request.getRecord()). .recordId(request.getRecord()).
build()); build());
if (getAppTableRecordResp.getCode() != 0){
throw new RuntimeException(new LarkException("LarkTableHelper.getTableRecordDetail", getAppTableRecordResp.getMsg(),request).getErrorMessageBody());
}
return getAppTableRecordResp;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkTableHelper.getTableRecordDetail",e.getMessage(),request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkTableHelper.getTableRecordDetail",e.getMessage(),request).getErrorMessageBody());
} }

@ -51,7 +51,7 @@ public class LarkTaskHelper extends LarkHelper {
if (createTaskResp.getCode() == 0){ if (createTaskResp.getCode() == 0){
return createTaskResp.getData(); return createTaskResp.getData();
}else { }else {
throw new RuntimeException(new LarkException("LarkTaskHelper.createTask", JSONObject.toJSONString(createTaskResp.getError()),request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkTaskHelper.createTask", createTaskResp.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkTaskHelper.createTask",e.getMessage(),request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkTaskHelper.createTask",e.getMessage(),request).getErrorMessageBody());
@ -75,7 +75,7 @@ public class LarkTaskHelper extends LarkHelper {
if (getTaskResp.getCode() == 0){ if (getTaskResp.getCode() == 0){
return getTaskResp.getData(); return getTaskResp.getData();
}else { }else {
throw new RuntimeException(new LarkException("LarkTaskHelper.createTask", JSONObject.toJSONString(getTaskResp.getError()),request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkTaskHelper.createTask", getTaskResp.getMsg(),request).getErrorMessageBody());
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(new LarkException("LarkTaskHelper.createTask",e.getMessage(),request).getErrorMessageBody()); throw new RuntimeException(new LarkException("LarkTaskHelper.createTask",e.getMessage(),request).getErrorMessageBody());

@ -1,9 +1,11 @@
package com.ruoyi.flyingbook.aop; package com.ruoyi.flyingbook.aop;
import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper; import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper;
import com.ruoyi.flyingbook.domain.Event;
import com.ruoyi.flyingbook.domain.EventLog; import com.ruoyi.flyingbook.domain.EventLog;
import com.ruoyi.flyingbook.domain.lark.LarkException; import com.ruoyi.flyingbook.domain.lark.LarkException;
import com.ruoyi.flyingbook.domain.lark.LarkRequest; import com.ruoyi.flyingbook.domain.lark.LarkRequest;
import com.ruoyi.flyingbook.mapper.EventMapper;
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;
@ -14,6 +16,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -27,6 +31,8 @@ public class ErrorLogAop {
@Autowired @Autowired
private LarkRobotHelper larkRobotHelper; private LarkRobotHelper larkRobotHelper;
@Autowired
private EventMapper eventMapper;
@Value("${lark.robot.group}") @Value("${lark.robot.group}")
private String ROBOT_GROUP; private String ROBOT_GROUP;
@ -38,10 +44,13 @@ public class ErrorLogAop {
public void prePersist(EventLog dto) { public void prePersist(EventLog dto) {
String errorMessage = dto.getErrorMessage(); String errorMessage = dto.getErrorMessage();
if (StringUtils.isNotBlank(errorMessage)) { if (StringUtils.isNotBlank(errorMessage)) {
Event event = eventMapper.selectEventById(dto.getEventId());
if (event != null && event.getNumbers() != null && event.getNumbers() <= 1) {
LarkRequest larkRequest = new LarkRequest("a", "b"); LarkRequest larkRequest = new LarkRequest("a", "b");
LarkException larkException = new LarkException("",errorMessage, larkRequest); LarkException larkException = new LarkException("", errorMessage, larkRequest);
String errorMessageBody = larkException.getErrorMessageBody(); String errorMessageBody = larkException.getErrorMessageBody();
// larkRobotHelper.sendMessageByBot(ROBOT_GROUP, errorMessageBody); larkRobotHelper.sendMessageByBot(ROBOT_GROUP, errorMessageBody);
}
} }
} }
@ -50,14 +59,32 @@ public class ErrorLogAop {
*/ */
@After("execution(* com.ruoyi.flyingbook.service.IEventLogService.insertBatchEventLog(..)) && (args(dto))") @After("execution(* com.ruoyi.flyingbook.service.IEventLogService.insertBatchEventLog(..)) && (args(dto))")
public void prePersist(List<EventLog> dto) { public void prePersist(List<EventLog> dto) {
List<Long> eventIdList = dto.stream()
.filter(r -> {
return StringUtils.isNotBlank(r.getErrorMessage()) && r.getEventId() != null;
})
.map(EventLog::getEventId)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(eventIdList)){
return;
}
List<Event> list = eventMapper.selectEventByIdList(eventIdList);
Map<Long, Event> eventMap = list.stream()
.filter(r -> {
return r.getNumbers() != null && r.getNumbers() <= 1;
}).collect(Collectors.toMap(Event::getId, Function.identity(), (k1, k2) -> k1));
if (eventMap == null || eventMap.isEmpty()){
return;
}
List<String> errorList = dto.stream() List<String> errorList = dto.stream()
.filter(r -> { .filter(r -> {
return StringUtils.isNotBlank(r.getErrorMessage()); return StringUtils.isNotBlank(r.getErrorMessage()) && eventMap.containsKey(r.getEventId());
}) })
.map(EventLog::getErrorMessage) .map(EventLog::getErrorMessage)
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(errorList)) { if (CollectionUtils.isNotEmpty(errorList)) {
// larkRobotHelper.sendMessageByBot(ROBOT_GROUP,String.join(",",errorList)); larkRobotHelper.sendMessageByBot(ROBOT_GROUP,String.join(",",errorList));
} }
} }

@ -36,6 +36,7 @@ public class LarkCalendarRequest extends LarkRequest {
* *
*/ */
private String summary; private String summary;
private String desc;
/** /**
* *
@ -88,28 +89,16 @@ public class LarkCalendarRequest extends LarkRequest {
this.eventId = eventId; this.eventId = eventId;
} }
/**
*
*/
public LarkCalendarRequest(String appId, String appSecret, String calendarId, String summary, String startDate, String endDate) {
super(appId, appSecret);
this.calendarId = calendarId;
this.summary = summary;
this.startDate = startDate;
this.endDate = endDate;
this.timeZone = "Asia/Shanghai";
this.needNotification = Boolean.FALSE;
this.attendeeAbility = CalendarEventEventAttendeeAbilityEnum.CANSEEOTHERS;
}
/** /**
* * /
*/ */
public LarkCalendarRequest(String appId, String appSecret, String calendarId, String eventId, String summary, String startDate, String endDate) { public LarkCalendarRequest(String appId, String appSecret, String calendarId, String eventId, String summary,String desc, String startDate, String endDate) {
super(appId, appSecret); super(appId, appSecret);
this.calendarId = calendarId; this.calendarId = calendarId;
this.eventId = eventId; this.eventId = eventId;
this.summary = summary; this.summary = summary;
this.desc = desc;
this.startDate = startDate; this.startDate = startDate;
this.endDate = endDate; this.endDate = endDate;
this.timeZone = "Asia/Shanghai"; this.timeZone = "Asia/Shanghai";
@ -144,6 +133,7 @@ public class LarkCalendarRequest extends LarkRequest {
for (int i = 0; i < followerIdList.size(); i++) { for (int i = 0; i < followerIdList.size(); i++) {
CalendarEventAttendee calendarEventAttendee = new CalendarEventAttendee(); CalendarEventAttendee calendarEventAttendee = new CalendarEventAttendee();
calendarEventAttendee.setIsOptional(Boolean.TRUE); calendarEventAttendee.setIsOptional(Boolean.TRUE);
calendarEventAttendee.setType("user");
calendarEventAttendee.setUserId(followerIdList.get(i)); calendarEventAttendee.setUserId(followerIdList.get(i));
calendarEventAttendee.setOperateId(operateId); calendarEventAttendee.setOperateId(operateId);
calendarEventAttendees[i] = calendarEventAttendee; calendarEventAttendees[i] = calendarEventAttendee;

@ -24,6 +24,8 @@ public class LarkException {
this.request = request; this.request = request;
} }
public String getErrorMessageBody(){ public String getErrorMessageBody(){
return this.toString(); return this.toString();
} }

@ -21,6 +21,7 @@ public interface EventMapper
* @return * @return
*/ */
public Event selectEventById(Long id); public Event selectEventById(Long id);
public List<Event> selectEventByIdList(@Param("idList") List<Long> idList);
/** /**
* *

@ -2,9 +2,7 @@ package com.ruoyi.flyingbook.strategy.operate;
import cn.hutool.core.io.unit.DataUnit; import cn.hutool.core.io.unit.DataUnit;
import com.lark.oapi.service.calendar.v4.model.*; import com.lark.oapi.service.calendar.v4.model.*;
import com.lark.oapi.service.task.v1.model.Due; import com.lark.oapi.service.task.v1.model.*;
import com.lark.oapi.service.task.v1.model.GetTaskRespBody;
import com.lark.oapi.service.task.v1.model.Task;
import com.ruoyi.common.enums.*; import com.ruoyi.common.enums.*;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.flyingbook.LarkHelper.LarkCalendarHelper; import com.ruoyi.flyingbook.LarkHelper.LarkCalendarHelper;
@ -22,7 +20,9 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*; import java.util.*;
@ -72,9 +72,17 @@ public class LarkTaskCallbackOperate extends LarkAbstract {
GetTaskRespBody taskInfo = larkTaskHelper.getTaskInfo(getTaskRequest); GetTaskRespBody taskInfo = larkTaskHelper.getTaskInfo(getTaskRequest);
Task task = taskInfo.getTask(); Task task = taskInfo.getTask();
//任务的关注人及负责人取交集 //任务的关注人及负责人取交集
String[] collaboratorIds = task.getCollaboratorIds(); Collaborator[] collaborators = task.getCollaborators();
String operator = collaboratorIds[0]; String[] collaboratorIds = new String[collaborators.length];
String[] followerIds = task.getFollowerIds(); for (int i = 0; i < collaborators.length; i++) {
collaboratorIds[i] = collaborators[i].getId();
}
String operator = collaborators[0].getId();
Follower[] followers = task.getFollowers();
String[] followerIds = new String[collaborators.length];
for (int i = 0; i < followers.length; i++) {
followerIds[i] = followers[i].getId();
}
//待绑定日程用户 //待绑定日程用户
String[] taskFollowerArray = getArrayIntersection(collaboratorIds, followerIds); String[] taskFollowerArray = getArrayIntersection(collaboratorIds, followerIds);
//待解除绑定日程用户 //待解除绑定日程用户
@ -85,36 +93,15 @@ public class LarkTaskCallbackOperate extends LarkAbstract {
String calendarId = getCalendarInfo(request.getAppId(), request.getAppSecret()); String calendarId = getCalendarInfo(request.getAppId(), request.getAppSecret());
String eventId = null; String eventId = null;
if (taskCalendarRelation == null){ if (taskCalendarRelation == null){
//关系为空,创建日程 LarkCalendarRequest calendarRequest = this.createOrUpdateCalendar(task,calendarId,eventId,request.getAppId(),request.getAppSecret());
String summary = task.getSummary();
if (StringUtils.isNotBlank(task.getCompleteTime()) && !task.getCompleteTime().equals("0")){
summary += "✔";
}
Due due = task.getDue();
LarkCalendarRequest calendarRequest = null;
if (due == null){
String time = DateUtils.ldt2str(LocalDateTime.now(), DateUtils.YYYY_MM_DD);
calendarRequest = new LarkCalendarRequest(request.getAppId(), request.getAppSecret(), calendarId, summary, task.getDescription(), time, time);
}else {
Boolean isAllDay = due.getIsAllDay();
Long time = Long.valueOf(due.getTime());
if (isAllDay){
String allDay = DateUtils.long2Str(time, DateUtils.YYYY_MM_DD);
calendarRequest = new LarkCalendarRequest(request.getAppId(), request.getAppSecret(), calendarId, summary, task.getDescription(), allDay, allDay);
}else {
LocalDateTime localDateTime = DateUtils.long2ldt(time);
LocalDateTime startTime = localDateTime.minusHours(2L);
calendarRequest = new LarkCalendarRequest(request.getAppId(), request.getAppSecret(), calendarId, summary, task.getDescription(), null, null);
calendarRequest.setStartDateStamp(String.valueOf(DateUtils.ldt2Long(startTime)));
calendarRequest.setEndDateStamp(due.getTime());
}
}
CreateCalendarEventRespBody calendarDetail = larkCalendarHelper.createCalendarDetail(calendarRequest); CreateCalendarEventRespBody calendarDetail = larkCalendarHelper.createCalendarDetail(calendarRequest);
eventId = calendarDetail.getEvent().getEventId(); eventId = calendarDetail.getEvent().getEventId();
//任务日历关系实体 //任务日历关系实体
this.buildTaskCalendarRelation(larkTaskId,eventId); this.buildTaskCalendarRelation(larkTaskId,eventId);
}else { }else {
eventId = taskCalendarRelation.getToId(); eventId = taskCalendarRelation.getToId();
LarkCalendarRequest update = this.createOrUpdateCalendar(task,calendarId,eventId,request.getAppId(),request.getAppSecret());
larkCalendarHelper.updateCalendarDetail(update);
LarkCalendarRequest calendarRequest = new LarkCalendarRequest(request.getAppId(), request.getAppSecret(), calendarId, eventId); LarkCalendarRequest calendarRequest = new LarkCalendarRequest(request.getAppId(), request.getAppSecret(), calendarId, eventId);
ListCalendarEventAttendeeRespBody calendarDetail = larkCalendarHelper.getCalendarDetail(calendarRequest); ListCalendarEventAttendeeRespBody calendarDetail = larkCalendarHelper.getCalendarDetail(calendarRequest);
for (CalendarEventAttendee item : calendarDetail.getItems()) { for (CalendarEventAttendee item : calendarDetail.getItems()) {
@ -129,8 +116,34 @@ public class LarkTaskCallbackOperate extends LarkAbstract {
LarkCalendarRequest add = new LarkCalendarRequest(request.getAppId(), request.getAppSecret(), calendarId, eventId, Arrays.asList(taskFollowerArray), operator); LarkCalendarRequest add = new LarkCalendarRequest(request.getAppId(), request.getAppSecret(), calendarId, eventId, Arrays.asList(taskFollowerArray), operator);
larkCalendarHelper.attendeesCalendarDetail(add); larkCalendarHelper.attendeesCalendarDetail(add);
} }
}
private LarkCalendarRequest createOrUpdateCalendar(Task task,String calendarId,String eventId,String appId,String appSecret){
//关系为空,创建日程
String summary = task.getSummary();
if (StringUtils.isNotBlank(task.getCompleteTime()) && !task.getCompleteTime().equals("0")){
summary += "✔";
}
Due due = task.getDue();
LarkCalendarRequest calendarRequest = null;
if (due == null || due.getTime().equals("0")){
String time = DateUtils.ldt2str(LocalDateTime.now(), DateUtils.YYYY_MM_DD);
calendarRequest = new LarkCalendarRequest(appId, appSecret, calendarId,eventId, summary, task.getDescription(), time, time);
}else {
Boolean isAllDay = due.getIsAllDay();
Long time = Long.valueOf(due.getTime());
if (isAllDay){
String allDay = DateUtils.long2Str(time, DateUtils.YYYY_MM_DD);
calendarRequest = new LarkCalendarRequest(appId, appSecret, calendarId,eventId, summary, task.getDescription(), allDay, allDay);
}else {
LocalDateTime localDateTime = DateUtils.long2ldt(time);
LocalDateTime startTime = localDateTime.minusHours(2L);
calendarRequest = new LarkCalendarRequest(appId, appSecret, calendarId,eventId, summary, task.getDescription(), null, null);
calendarRequest.setStartDateStamp(String.valueOf(DateUtils.ldt2Long(startTime)).substring(0,10));
calendarRequest.setEndDateStamp(due.getTime());
}
}
return calendarRequest;
} }
/** /**
@ -141,8 +154,11 @@ public class LarkTaskCallbackOperate extends LarkAbstract {
LarkTableRowRelation rowRelation = new LarkTableRowRelation(); LarkTableRowRelation rowRelation = new LarkTableRowRelation();
rowRelation.setFlag(FlagStatus.OK.getCode()); rowRelation.setFlag(FlagStatus.OK.getCode());
rowRelation.setType(TableDetailRelationTypeEnum.TASK_CALENDAR.getCode()); rowRelation.setType(TableDetailRelationTypeEnum.TASK_CALENDAR.getCode());
rowRelation.setSubType(TableDetailRelationTypeEnum.TASK_CALENDAR.getCode());
rowRelation.setFromId(larkTaskId); rowRelation.setFromId(larkTaskId);
rowRelation.setToId(eventId); rowRelation.setToId(eventId);
rowRelation.setCreateBy("system");
rowRelation.setCreateTime(new Date());
larkTableRowRelationService.insertLarkTableRowRelation(rowRelation); larkTableRowRelationService.insertLarkTableRowRelation(rowRelation);
} }

@ -58,6 +58,14 @@
where id = #{id} where id = #{id}
</select> </select>
<select id="selectEventByIdList" resultMap="EventResult">
<include refid="selectEventVo"/>
where id in
<foreach item="id" collection="idList" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insertEvent" parameterType="com.ruoyi.flyingbook.domain.Event" useGeneratedKeys="true" keyProperty="id"> <insert id="insertEvent" parameterType="com.ruoyi.flyingbook.domain.Event" useGeneratedKeys="true" keyProperty="id">
insert into event insert into event
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">

Loading…
Cancel
Save