|
|
@ -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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|