|
|
@ -6,7 +6,9 @@ import com.google.gson.internal.LinkedTreeMap;
|
|
|
|
import com.lark.oapi.service.bitable.v1.model.AppTableRecord;
|
|
|
|
import com.lark.oapi.service.bitable.v1.model.AppTableRecord;
|
|
|
|
import com.lark.oapi.service.bitable.v1.model.ListAppTableRecordRespBody;
|
|
|
|
import com.lark.oapi.service.bitable.v1.model.ListAppTableRecordRespBody;
|
|
|
|
import com.lark.oapi.service.contact.v3.model.GetUserRespBody;
|
|
|
|
import com.lark.oapi.service.contact.v3.model.GetUserRespBody;
|
|
|
|
|
|
|
|
import com.ruoyi.common.constant.EnumsConstants;
|
|
|
|
import com.ruoyi.common.enums.*;
|
|
|
|
import com.ruoyi.common.enums.*;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper;
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper;
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper;
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper;
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkUserHelper;
|
|
|
|
import com.ruoyi.flyingbook.LarkHelper.LarkUserHelper;
|
|
|
@ -77,7 +79,7 @@ public class ScheduledRemindersTask {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<EventLog> logList = new ArrayList<>();
|
|
|
|
List<EventLog> logList = new ArrayList<>();
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
// LocalDateTime now = LocalDateTime.of(2023, 5, 4, 20, 0);
|
|
|
|
// LocalDateTime now = LocalDateTime.of(2023, 4, 24, 8, 30);
|
|
|
|
for (LarkCompanyTableInfo larkCompanyTableInfo : larkList) {
|
|
|
|
for (LarkCompanyTableInfo larkCompanyTableInfo : larkList) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<LarkTableConfiguration> larkConfiguration = this.getLarkConfiguration(larkCompanyTableInfo);
|
|
|
|
List<LarkTableConfiguration> larkConfiguration = this.getLarkConfiguration(larkCompanyTableInfo);
|
|
|
@ -86,15 +88,8 @@ public class ScheduledRemindersTask {
|
|
|
|
if (subType == null) {
|
|
|
|
if (subType == null) {
|
|
|
|
throw new RuntimeException(String.format("tableId:%s 配置子类:%s 无对应策略处理逻辑", larkTableConfiguration.getLarkTableId(), larkTableConfiguration.getSubConfigType()));
|
|
|
|
throw new RuntimeException(String.format("tableId:%s 配置子类:%s 无对应策略处理逻辑", larkTableConfiguration.getLarkTableId(), larkTableConfiguration.getSubConfigType()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ConfigurationSubTypeEnum.REMINDER_AROUND.equals(subType)) {
|
|
|
|
//按类型执行消息分配动作
|
|
|
|
String script = LarkTableFilterScriptHelper.buildTimeRange(larkTableConfiguration, ConfigurationSubTypeEnum.REMINDER_BEFORE, RANGE_KEY, now);
|
|
|
|
this.allocateSendMessage(subType,now,larkTableConfiguration,logList,larkCompanyTableInfo);
|
|
|
|
this.sendMessage(script, larkCompanyTableInfo, logList, larkTableConfiguration, now);
|
|
|
|
|
|
|
|
script = LarkTableFilterScriptHelper.buildTimeRange(larkTableConfiguration, ConfigurationSubTypeEnum.REMINDER_AFTER, RANGE_KEY, now);
|
|
|
|
|
|
|
|
this.sendMessage(script, larkCompanyTableInfo, logList, larkTableConfiguration, now);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String script = LarkTableFilterScriptHelper.buildTimeRange(larkTableConfiguration, subType, RANGE_KEY, now);
|
|
|
|
|
|
|
|
this.sendMessage(script, larkCompanyTableInfo, logList, larkTableConfiguration, now);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("ScheduledRemindersTask#scheduledReminders error request:{}", JSONObject.toJSONString(larkCompanyTableInfo), e);
|
|
|
|
log.error("ScheduledRemindersTask#scheduledReminders error request:{}", JSONObject.toJSONString(larkCompanyTableInfo), e);
|
|
|
@ -107,6 +102,25 @@ public class ScheduledRemindersTask {
|
|
|
|
log.info("scheduledRemindersTask end");
|
|
|
|
log.info("scheduledRemindersTask end");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void allocateSendMessage(ConfigurationSubTypeEnum subType,LocalDateTime now,LarkTableConfiguration larkTableConfiguration,List<EventLog> logList,LarkCompanyTableInfo larkCompanyTableInfo){
|
|
|
|
|
|
|
|
String script = null;
|
|
|
|
|
|
|
|
switch (subType){
|
|
|
|
|
|
|
|
case REMINDER_AROUND:
|
|
|
|
|
|
|
|
script = LarkTableFilterScriptHelper.buildTimeRange(larkTableConfiguration, ConfigurationSubTypeEnum.REMINDER_BEFORE, RANGE_KEY, now);
|
|
|
|
|
|
|
|
this.sendMessage(script, larkCompanyTableInfo, logList, larkTableConfiguration, now);
|
|
|
|
|
|
|
|
script = LarkTableFilterScriptHelper.buildTimeRange(larkTableConfiguration, ConfigurationSubTypeEnum.REMINDER_AFTER, RANGE_KEY, now);
|
|
|
|
|
|
|
|
this.sendMessage(script, larkCompanyTableInfo, logList, larkTableConfiguration, now);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REMINDER_BEFORE:
|
|
|
|
|
|
|
|
case REMINDER_AFTER:
|
|
|
|
|
|
|
|
script = LarkTableFilterScriptHelper.buildTimeRange(larkTableConfiguration, subType, RANGE_KEY, now);
|
|
|
|
|
|
|
|
this.sendMessage(script, larkCompanyTableInfo, logList, larkTableConfiguration, now);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendMessage(String script, LarkCompanyTableInfo larkCompanyTableInfo, List<EventLog> logList, LarkTableConfiguration larkTableConfiguration, LocalDateTime now) {
|
|
|
|
private void sendMessage(String script, LarkCompanyTableInfo larkCompanyTableInfo, List<EventLog> logList, LarkTableConfiguration larkTableConfiguration, LocalDateTime now) {
|
|
|
|
String pageToken = null;
|
|
|
|
String pageToken = null;
|
|
|
|
LarkTableRequest request = this.buildRequest(larkCompanyTableInfo, script);
|
|
|
|
LarkTableRequest request = this.buildRequest(larkCompanyTableInfo, script);
|
|
|
@ -126,7 +140,7 @@ public class ScheduledRemindersTask {
|
|
|
|
for (AppTableRecord item : items) {
|
|
|
|
for (AppTableRecord item : items) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Map<String, Object> fields = item.getFields();
|
|
|
|
Map<String, Object> fields = item.getFields();
|
|
|
|
LocalDateTime localDateTime = changeLocalDateTime((Double) fields.get(RANGE_KEY));
|
|
|
|
LocalDateTime localDateTime = changeLocalDateTime(fields.get(RANGE_KEY),larkTableConfiguration);
|
|
|
|
if ((localDateTime.getHour() == now.getHour()) && localDateTime.getMinute() == now.getMinute()) {
|
|
|
|
if ((localDateTime.getHour() == now.getHour()) && localDateTime.getMinute() == now.getMinute()) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -141,7 +155,20 @@ public class ScheduledRemindersTask {
|
|
|
|
} while (StringUtils.isNotBlank(pageToken));
|
|
|
|
} while (StringUtils.isNotBlank(pageToken));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private LocalDateTime changeLocalDateTime(Double timestamp) {
|
|
|
|
private LocalDateTime changeLocalDateTime(Object timestampObj,LarkTableConfiguration larkTableConfiguration) {
|
|
|
|
|
|
|
|
String param3 = larkTableConfiguration.getParam3();
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(param3) || EnumsConstants.SCHEDULE_REMINDER_TIME.equals(param3)){
|
|
|
|
|
|
|
|
return double2LocalDateTime(timestampObj);
|
|
|
|
|
|
|
|
}else if (EnumsConstants.SCHEDULE_REMINDER_FORMULA.equals(param3)){
|
|
|
|
|
|
|
|
List<LinkedTreeMap> bodyList = (ArrayList<LinkedTreeMap>) timestampObj;
|
|
|
|
|
|
|
|
LinkedTreeMap map = bodyList.get(0);
|
|
|
|
|
|
|
|
return DateUtils.str2ldt(String.valueOf(map.get("text")),larkTableConfiguration.getParam4());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private LocalDateTime double2LocalDateTime(Object timestampObj){
|
|
|
|
|
|
|
|
Double timestamp = (Double) timestampObj;
|
|
|
|
BigDecimal bigDecimal = new BigDecimal(timestamp.toString());
|
|
|
|
BigDecimal bigDecimal = new BigDecimal(timestamp.toString());
|
|
|
|
long time = bigDecimal.longValue();
|
|
|
|
long time = bigDecimal.longValue();
|
|
|
|
Instant instant = Instant.ofEpochMilli(time);
|
|
|
|
Instant instant = Instant.ofEpochMilli(time);
|
|
|
@ -206,6 +233,10 @@ public class ScheduledRemindersTask {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (LarkTableRowRelation entry : rowRelationList) {
|
|
|
|
for (LarkTableRowRelation entry : rowRelationList) {
|
|
|
|
String msg = recursiveValue(record, entry.getFromId(), request);
|
|
|
|
String msg = recursiveValue(record, entry.getFromId(), request);
|
|
|
|
|
|
|
|
if (EnumsConstants.SCHEDULE_REMINDER_ROW_RELATION_TYPE.equals(entry.getRemark())){
|
|
|
|
|
|
|
|
LocalDateTime localDateTime = this.double2LocalDateTime(Double.valueOf(msg));
|
|
|
|
|
|
|
|
msg = DateUtils.ldt2str(localDateTime, DateUtils.YYYY_MM_DD_HH_MM_SS);
|
|
|
|
|
|
|
|
}
|
|
|
|
template = template.replaceAll(entry.getToId(), msg);
|
|
|
|
template = template.replaceAll(entry.getToId(), msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return template;
|
|
|
|
return template;
|
|
|
|