From 76024840b2ffdc48257f1ef0fc6b30154a461934 Mon Sep 17 00:00:00 2001 From: YXY <932687738@qq.com> Date: Thu, 20 Apr 2023 22:12:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=9E=E4=B9=A6=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/ConfigurationSubTypeEnum.java | 40 ++++++ .../common/enums/ConfigurationTypeEnum.java | 29 ++++ .../ruoyi/common/enums/EventOperateType.java | 3 +- .../common/enums/TemplateSubTypeEnum.java | 38 ++++++ .../ruoyi/common/enums/TemplateTypeEnum.java | 29 ++++ .../com/ruoyi/common/enums/TimeUnitEnum.java | 43 ++++++ .../script/LarkTableFilterScriptHelper.java | 63 ++++++--- .../domain/LarkTableConfiguration.java | 37 +++++ .../ruoyi/flyingbook/domain/LarkTemplate.java | 39 ++++++ .../mapper/LarkTableConfigurationMapper.java | 63 +++++++++ .../flyingbook/mapper/LarkTemplateMapper.java | 63 +++++++++ .../ILarkTableConfigurationService.java | 63 +++++++++ .../service/ILarkTemplateService.java | 62 +++++++++ .../LarkTableConfigurationServiceImpl.java | 97 ++++++++++++++ .../service/impl/LarkTemplateServiceImpl.java | 97 ++++++++++++++ .../mapper/LarkTableConfigurationMapper.xml | 111 +++++++++++++++ .../resources/mapper/LarkTemplateMapper.xml | 96 +++++++++++++ .../quartz/task/ScheduledRemindersTask.java | 126 +++++++++++++++--- 18 files changed, 1065 insertions(+), 34 deletions(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/ConfigurationSubTypeEnum.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/ConfigurationTypeEnum.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/TemplateSubTypeEnum.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/TemplateTypeEnum.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/TimeUnitEnum.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkTableConfiguration.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkTemplate.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkTableConfigurationMapper.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkTemplateMapper.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkTableConfigurationService.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkTemplateService.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkTableConfigurationServiceImpl.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkTemplateServiceImpl.java create mode 100644 ruoyi-flyingbook/src/main/resources/mapper/LarkTableConfigurationMapper.xml create mode 100644 ruoyi-flyingbook/src/main/resources/mapper/LarkTemplateMapper.xml diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/ConfigurationSubTypeEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/ConfigurationSubTypeEnum.java new file mode 100644 index 0000000..6c41bd3 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/ConfigurationSubTypeEnum.java @@ -0,0 +1,40 @@ +package com.ruoyi.common.enums; + +/** + * 机器人模板 + * + * @author ruoyi + */ +public enum ConfigurationSubTypeEnum { + /** + * + */ + REMINDER_BEFORE("REMINDER_BEFORE", "发生前提醒"), + REMINDER_AFTER("REMINDER_AFTER", "发生后提醒"), + REMINDER_AROUND("REMINDER_AROUND", "发生前后提醒"); + + private final String code; + private final String info; + + ConfigurationSubTypeEnum(String code, String info) { + this.code = code; + this.info = info; + } + + public String getCode() { + return code; + } + + public String getInfo() { + return info; + } + + public static ConfigurationSubTypeEnum getByCode(String code){ + for (ConfigurationSubTypeEnum value : ConfigurationSubTypeEnum.values()) { + if (value.getCode().equals(code)){ + return value; + } + } + return null; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/ConfigurationTypeEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/ConfigurationTypeEnum.java new file mode 100644 index 0000000..17ac6c2 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/ConfigurationTypeEnum.java @@ -0,0 +1,29 @@ +package com.ruoyi.common.enums; + +/** + * 机器人模板 + * + * @author ruoyi + */ +public enum ConfigurationTypeEnum { + /** + * + */ + SCHEDULE_REMINDER("SCHEDULE_REMINDER", "定时提醒配置"); + + private final String code; + private final String info; + + ConfigurationTypeEnum(String code, String info) { + this.code = code; + this.info = info; + } + + public String getCode() { + return code; + } + + public String getInfo() { + return info; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/EventOperateType.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/EventOperateType.java index 9b8680e..fa628c3 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/enums/EventOperateType.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/EventOperateType.java @@ -14,7 +14,8 @@ public enum EventOperateType { UPDATE("UPDATE", "更新"), DELETE("DELETE", "删除"), STOP("STOP", "终止"), - SYNC_MAIL("SYNC_MAIL", "同步邮件"),; + SYNC_MAIL("SYNC_MAIL", "同步邮件"), + SCHEDULE_REMINDER("SCHEDULE_REMINDER", "定时提醒"); private final String code; private final String info; diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/TemplateSubTypeEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/TemplateSubTypeEnum.java new file mode 100644 index 0000000..a60178b --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/TemplateSubTypeEnum.java @@ -0,0 +1,38 @@ +package com.ruoyi.common.enums; + +/** + * 机器人模板 + * + * @author ruoyi + */ +public enum TemplateSubTypeEnum { + /** + * + */ + TEXT("text", "文本文档"); + + private final String code; + private final String info; + + TemplateSubTypeEnum(String code, String info) { + this.code = code; + this.info = info; + } + + public String getCode() { + return code; + } + + public String getInfo() { + return info; + } + + public static TemplateSubTypeEnum getByCode(String code){ + for (TemplateSubTypeEnum value : TemplateSubTypeEnum.values()) { + if (value.getCode().equals(code)){ + return value; + } + } + return null; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/TemplateTypeEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/TemplateTypeEnum.java new file mode 100644 index 0000000..d86e771 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/TemplateTypeEnum.java @@ -0,0 +1,29 @@ +package com.ruoyi.common.enums; + +/** + * 机器人模板 + * + * @author ruoyi + */ +public enum TemplateTypeEnum { + /** + * + */ + SCHEDULED_REMINDER("SCHEDULED_REMINDER", "定时提醒"); + + private final String code; + private final String info; + + TemplateTypeEnum(String code, String info) { + this.code = code; + this.info = info; + } + + public String getCode() { + return code; + } + + public String getInfo() { + return info; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/TimeUnitEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/TimeUnitEnum.java new file mode 100644 index 0000000..49c8086 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/TimeUnitEnum.java @@ -0,0 +1,43 @@ +package com.ruoyi.common.enums; + +/** + * 时间单位 + * + * @author ruoyi + */ +public enum TimeUnitEnum { + /** + * + */ + YEAR("YEAR", "年"), + MONTH("MONTH", "月"), + DAY("DAY", "日"), + HOUR("HOUR", "时"), + MINUTE("MINUTE", "分"), + SECOND("SECOND", "秒"); + + private final String code; + private final String info; + + TimeUnitEnum(String code, String info) { + this.code = code; + this.info = info; + } + + public String getCode() { + return code; + } + + public String getInfo() { + return info; + } + + public static TimeUnitEnum getByCode(String code){ + for (TimeUnitEnum value : TimeUnitEnum.values()) { + if (value.getCode().equals(code)){ + return value; + } + } + return null; + } +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/script/LarkTableFilterScriptHelper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/script/LarkTableFilterScriptHelper.java index 7274a69..3cdd605 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/script/LarkTableFilterScriptHelper.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/script/LarkTableFilterScriptHelper.java @@ -1,5 +1,10 @@ package com.ruoyi.flyingbook.LarkHelper.script; +import com.ruoyi.common.enums.ConfigurationSubTypeEnum; +import com.ruoyi.common.enums.TimeUnitEnum; +import com.ruoyi.flyingbook.domain.LarkTableConfiguration; +import org.apache.commons.lang3.StringUtils; + import java.time.LocalDateTime; /** @@ -8,23 +13,49 @@ import java.time.LocalDateTime; */ public class LarkTableFilterScriptHelper { - public static String buildTimeRange(String paramCode, LocalDateTime fromTime) { + /** + * param1 时间 + * param2 时间单位 + */ + public static String buildTimeRange(LarkTableConfiguration larkTableConfiguration,ConfigurationSubTypeEnum subType, String paramCode, LocalDateTime fromTime) { + + Long minute = getMinute(larkTableConfiguration); + switch (subType) { + case REMINDER_BEFORE: + fromTime = fromTime.minusMinutes(minute); + break; + case REMINDER_AFTER: + fromTime = fromTime.plusMinutes(minute); + break; + default: + break; + } String range = fromTime.getMinute() >= 30 ? ">=" : "<"; - return String.format("AND(YEAR(CurrentValue.[%s]) = %s," + - "MONTH(CurrentValue.[%s]) = %s," + - "DAY(CurrentValue.[%s]) = %s," + - "HOUR(CurrentValue.[%s]) = %s," + - "MINUTE(CurrentValue.[%s]) %s 30)", - paramCode, - fromTime.getYear(), - paramCode, - fromTime.getMonth().getValue(), - paramCode, - fromTime.getDayOfMonth(), - paramCode, - fromTime.getHour(), - paramCode, - range); + StringBuilder sb = new StringBuilder("AND("); + sb.append(String.format("YEAR(CurrentValue.[%s]) = %s",paramCode,fromTime.getYear())).append(","); + sb.append(String.format("MONTH(CurrentValue.[%s]) = %s",paramCode,fromTime.getMonth().getValue())).append(","); + sb.append(String.format("DAY(CurrentValue.[%s]) = %s",paramCode,fromTime.getDayOfMonth())); + sb.append(String.format("HOUR(CurrentValue.[%s]) = %s",paramCode,fromTime.getHour())); + sb.append(String.format("HOUR(CurrentValue.[%s]) %s 30",paramCode,range)); + sb.append(")"); + return sb.toString(); + } + + private static Long getMinute(LarkTableConfiguration larkTableConfiguration){ + TimeUnitEnum timeUnit = TimeUnitEnum.getByCode(larkTableConfiguration.getParam2()); + if (timeUnit == null){ + throw new RuntimeException(String.format("tableId:%s 配置时间单位:%s不存在",larkTableConfiguration.getLarkTableId(),larkTableConfiguration.getParam2())); + } + Long value = Long.valueOf(larkTableConfiguration.getParam1()); + Long minute = 0L; + switch (timeUnit){ + case HOUR: + minute = value * 60; + break; + case MINUTE: + minute = value; + } + return minute; } } diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkTableConfiguration.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkTableConfiguration.java new file mode 100644 index 0000000..27771e5 --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkTableConfiguration.java @@ -0,0 +1,37 @@ +package com.ruoyi.flyingbook.domain; + +import com.ruoyi.common.core.domain.BaseEntity; +import lombok.Data; + +/** + * @author ruoyi + * @date 2023-04-20 + */ +@Data +public class LarkTableConfiguration extends BaseEntity { + private static final long serialVersionUID = 1L; + + private Long id; + /** + * 飞书多维表的id + */ + private Long larkTableId; + + /** + * 配置类型 + * @see com.ruoyi.common.enums.ConfigurationTypeEnum + */ + private String configType; + + /** + * 配置类型子类 + * @see com.ruoyi.common.enums.ConfigurationSubTypeEnum + */ + private String subConfigType; + + private String param1; + private String param2; + private String param3; + private String param4; + private Long flag; +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkTemplate.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkTemplate.java new file mode 100644 index 0000000..1157899 --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkTemplate.java @@ -0,0 +1,39 @@ +package com.ruoyi.flyingbook.domain; + +import lombok.Data; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * @author ruoyi + * @date 2023-04-20 + */ +@Data +public class LarkTemplate extends BaseEntity { + private static final long serialVersionUID = 1L; + + private Long id; + + /** + * 飞书多维表的id + */ + private Long larkTableId; + + /** + * 模板类型 + * @see com.ruoyi.common.enums.TemplateTypeEnum + */ + private String templateType; + + /** + * 模板类型子类 + * @see com.ruoyi.common.enums.TemplateSubTypeEnum + */ + private String subTemplateType; + + /** + * 模板内容 + */ + private String templateContent; + + private Long flag; +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkTableConfigurationMapper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkTableConfigurationMapper.java new file mode 100644 index 0000000..d2740bd --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkTableConfigurationMapper.java @@ -0,0 +1,63 @@ +package com.ruoyi.flyingbook.mapper; + + +import com.ruoyi.flyingbook.domain.LarkTableConfiguration; + +import java.util.List; + +/** + * 【请填写功能名称】Mapper接口 + * + * @author ruoyi + * @date 2023-04-20 + */ +public interface LarkTableConfigurationMapper +{ + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 【请填写功能名称】 + */ + public LarkTableConfiguration selectLarkTableConfigurationById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param larkTableConfiguration 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectLarkTableConfigurationList(LarkTableConfiguration larkTableConfiguration); + + /** + * 新增【请填写功能名称】 + * + * @param larkTableConfiguration 【请填写功能名称】 + * @return 结果 + */ + public int insertLarkTableConfiguration(LarkTableConfiguration larkTableConfiguration); + + /** + * 修改【请填写功能名称】 + * + * @param larkTableConfiguration 【请填写功能名称】 + * @return 结果 + */ + public int updateLarkTableConfiguration(LarkTableConfiguration larkTableConfiguration); + + /** + * 删除【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 结果 + */ + public int deleteLarkTableConfigurationById(Long id); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + public int deleteLarkTableConfigurationByIds(Long[] ids); +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkTemplateMapper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkTemplateMapper.java new file mode 100644 index 0000000..a9ed696 --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkTemplateMapper.java @@ -0,0 +1,63 @@ +package com.ruoyi.flyingbook.mapper; + + +import com.ruoyi.flyingbook.domain.LarkTemplate; + +import java.util.List; + +/** + * 【请填写功能名称】Mapper接口 + * + * @author ruoyi + * @date 2023-04-20 + */ +public interface LarkTemplateMapper +{ + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 【请填写功能名称】 + */ + public LarkTemplate selectLarkTemplateById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param larkTemplate 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectLarkTemplateList(LarkTemplate larkTemplate); + + /** + * 新增【请填写功能名称】 + * + * @param larkTemplate 【请填写功能名称】 + * @return 结果 + */ + public int insertLarkTemplate(LarkTemplate larkTemplate); + + /** + * 修改【请填写功能名称】 + * + * @param larkTemplate 【请填写功能名称】 + * @return 结果 + */ + public int updateLarkTemplate(LarkTemplate larkTemplate); + + /** + * 删除【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 结果 + */ + public int deleteLarkTemplateById(Long id); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + public int deleteLarkTemplateByIds(Long[] ids); +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkTableConfigurationService.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkTableConfigurationService.java new file mode 100644 index 0000000..86d810f --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkTableConfigurationService.java @@ -0,0 +1,63 @@ +package com.ruoyi.flyingbook.service; + + +import com.ruoyi.flyingbook.domain.LarkTableConfiguration; + +import java.util.List; + +/** + * 【请填写功能名称】Service接口 + * + * @author ruoyi + * @date 2023-04-20 + */ +public interface ILarkTableConfigurationService +{ + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 【请填写功能名称】 + */ + public LarkTableConfiguration selectLarkTableConfigurationById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param larkTableConfiguration 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectLarkTableConfigurationList(LarkTableConfiguration larkTableConfiguration); + + /** + * 新增【请填写功能名称】 + * + * @param larkTableConfiguration 【请填写功能名称】 + * @return 结果 + */ + public int insertLarkTableConfiguration(LarkTableConfiguration larkTableConfiguration); + + /** + * 修改【请填写功能名称】 + * + * @param larkTableConfiguration 【请填写功能名称】 + * @return 结果 + */ + public int updateLarkTableConfiguration(LarkTableConfiguration larkTableConfiguration); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】ID + * @return 结果 + */ + public int deleteLarkTableConfigurationByIds(Long[] ids); + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】ID + * @return 结果 + */ + public int deleteLarkTableConfigurationById(Long id); +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkTemplateService.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkTemplateService.java new file mode 100644 index 0000000..aa6ce0d --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkTemplateService.java @@ -0,0 +1,62 @@ +package com.ruoyi.flyingbook.service; + + +import com.ruoyi.flyingbook.domain.LarkTemplate; + +import java.util.List; + +/** + * 【请填写功能名称】Service接口 + * + * @author ruoyi + * @date 2023-04-20 + */ +public interface ILarkTemplateService { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 【请填写功能名称】 + */ + public LarkTemplate selectLarkTemplateById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param larkTemplate 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectLarkTemplateList(LarkTemplate larkTemplate); + + /** + * 新增【请填写功能名称】 + * + * @param larkTemplate 【请填写功能名称】 + * @return 结果 + */ + public int insertLarkTemplate(LarkTemplate larkTemplate); + + /** + * 修改【请填写功能名称】 + * + * @param larkTemplate 【请填写功能名称】 + * @return 结果 + */ + public int updateLarkTemplate(LarkTemplate larkTemplate); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】ID + * @return 结果 + */ + public int deleteLarkTemplateByIds(Long[] ids); + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】ID + * @return 结果 + */ + public int deleteLarkTemplateById(Long id); +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkTableConfigurationServiceImpl.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkTableConfigurationServiceImpl.java new file mode 100644 index 0000000..f1b6655 --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkTableConfigurationServiceImpl.java @@ -0,0 +1,97 @@ +package com.ruoyi.flyingbook.service.impl; + +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.flyingbook.domain.LarkTableConfiguration; +import com.ruoyi.flyingbook.mapper.LarkTableConfigurationMapper; +import com.ruoyi.flyingbook.service.ILarkTableConfigurationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 【请填写功能名称】Service业务层处理 + * + * @author ruoyi + * @date 2023-04-20 + */ +@Service +public class LarkTableConfigurationServiceImpl implements ILarkTableConfigurationService +{ + @Autowired + private LarkTableConfigurationMapper larkTableConfigurationMapper; + + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 【请填写功能名称】 + */ + @Override + public LarkTableConfiguration selectLarkTableConfigurationById(Long id) + { + return larkTableConfigurationMapper.selectLarkTableConfigurationById(id); + } + + /** + * 查询【请填写功能名称】列表 + * + * @param larkTableConfiguration 【请填写功能名称】 + * @return 【请填写功能名称】 + */ + @Override + public List selectLarkTableConfigurationList(LarkTableConfiguration larkTableConfiguration) + { + return larkTableConfigurationMapper.selectLarkTableConfigurationList(larkTableConfiguration); + } + + /** + * 新增【请填写功能名称】 + * + * @param larkTableConfiguration 【请填写功能名称】 + * @return 结果 + */ + @Override + public int insertLarkTableConfiguration(LarkTableConfiguration larkTableConfiguration) + { + larkTableConfiguration.setCreateTime(DateUtils.getNowDate()); + return larkTableConfigurationMapper.insertLarkTableConfiguration(larkTableConfiguration); + } + + /** + * 修改【请填写功能名称】 + * + * @param larkTableConfiguration 【请填写功能名称】 + * @return 结果 + */ + @Override + public int updateLarkTableConfiguration(LarkTableConfiguration larkTableConfiguration) + { + larkTableConfiguration.setUpdateTime(DateUtils.getNowDate()); + return larkTableConfigurationMapper.updateLarkTableConfiguration(larkTableConfiguration); + } + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】ID + * @return 结果 + */ + @Override + public int deleteLarkTableConfigurationByIds(Long[] ids) + { + return larkTableConfigurationMapper.deleteLarkTableConfigurationByIds(ids); + } + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】ID + * @return 结果 + */ + @Override + public int deleteLarkTableConfigurationById(Long id) + { + return larkTableConfigurationMapper.deleteLarkTableConfigurationById(id); + } +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkTemplateServiceImpl.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkTemplateServiceImpl.java new file mode 100644 index 0000000..7502f97 --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkTemplateServiceImpl.java @@ -0,0 +1,97 @@ +package com.ruoyi.flyingbook.service.impl; + +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.flyingbook.domain.LarkTemplate; +import com.ruoyi.flyingbook.mapper.LarkTemplateMapper; +import com.ruoyi.flyingbook.service.ILarkTemplateService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 【请填写功能名称】Service业务层处理 + * + * @author ruoyi + * @date 2023-04-20 + */ +@Service +public class LarkTemplateServiceImpl implements ILarkTemplateService +{ + @Autowired + private LarkTemplateMapper larkTemplateMapper; + + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 【请填写功能名称】 + */ + @Override + public LarkTemplate selectLarkTemplateById(Long id) + { + return larkTemplateMapper.selectLarkTemplateById(id); + } + + /** + * 查询【请填写功能名称】列表 + * + * @param larkTemplate 【请填写功能名称】 + * @return 【请填写功能名称】 + */ + @Override + public List selectLarkTemplateList(LarkTemplate larkTemplate) + { + return larkTemplateMapper.selectLarkTemplateList(larkTemplate); + } + + /** + * 新增【请填写功能名称】 + * + * @param larkTemplate 【请填写功能名称】 + * @return 结果 + */ + @Override + public int insertLarkTemplate(LarkTemplate larkTemplate) + { + larkTemplate.setCreateTime(DateUtils.getNowDate()); + return larkTemplateMapper.insertLarkTemplate(larkTemplate); + } + + /** + * 修改【请填写功能名称】 + * + * @param larkTemplate 【请填写功能名称】 + * @return 结果 + */ + @Override + public int updateLarkTemplate(LarkTemplate larkTemplate) + { + larkTemplate.setUpdateTime(DateUtils.getNowDate()); + return larkTemplateMapper.updateLarkTemplate(larkTemplate); + } + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】ID + * @return 结果 + */ + @Override + public int deleteLarkTemplateByIds(Long[] ids) + { + return larkTemplateMapper.deleteLarkTemplateByIds(ids); + } + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】ID + * @return 结果 + */ + @Override + public int deleteLarkTemplateById(Long id) + { + return larkTemplateMapper.deleteLarkTemplateById(id); + } +} diff --git a/ruoyi-flyingbook/src/main/resources/mapper/LarkTableConfigurationMapper.xml b/ruoyi-flyingbook/src/main/resources/mapper/LarkTableConfigurationMapper.xml new file mode 100644 index 0000000..05f587d --- /dev/null +++ b/ruoyi-flyingbook/src/main/resources/mapper/LarkTableConfigurationMapper.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + select id, lark_table_id, config_type, sub_config_type, param1, param2, param3, param4, create_by, create_time, update_by, update_time, flag, remark from lark_table_configuration + + + + + + + + insert into lark_table_configuration + + lark_table_id, + config_type, + sub_config_type, + param1, + param2, + param3, + param4, + create_by, + create_time, + update_by, + update_time, + flag, + remark, + + + #{larkTableId}, + #{configType}, + #{subConfigType}, + #{param1}, + #{param2}, + #{param3}, + #{param4}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{flag}, + #{remark}, + + + + + update lark_table_configuration + + lark_table_id = #{larkTableId}, + config_type = #{configType}, + sub_config_type = #{subConfigType}, + param1 = #{param1}, + param2 = #{param2}, + param3 = #{param3}, + param4 = #{param4}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + flag = #{flag}, + remark = #{remark}, + + where id = #{id} + + + + delete from lark_table_configuration where id = #{id} + + + + delete from lark_table_configuration where id in + + #{id} + + + \ No newline at end of file diff --git a/ruoyi-flyingbook/src/main/resources/mapper/LarkTemplateMapper.xml b/ruoyi-flyingbook/src/main/resources/mapper/LarkTemplateMapper.xml new file mode 100644 index 0000000..51f938e --- /dev/null +++ b/ruoyi-flyingbook/src/main/resources/mapper/LarkTemplateMapper.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + select id, lark_table_id, template_type, sub_template_type, template_content, create_by, create_time, update_by, update_time, flag, remark from lark_template + + + + + + + + insert into lark_template + + lark_table_id, + template_type, + sub_template_type, + template_content, + create_by, + create_time, + update_by, + update_time, + flag, + remark, + + + #{larkTableId}, + #{templateTypeEnum}, + #{subTemplateType}, + #{templateContent}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{flag}, + #{remark}, + + + + + update lark_template + + lark_table_id = #{larkTableId}, + template_type = #{templateTypeEnum}, + sub_template_type = #{subTemplateType}, + template_content = #{templateContent}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + flag = #{flag}, + remark = #{remark}, + + where id = #{id} + + + + delete from lark_template where id = #{id} + + + + delete from lark_template where id in + + #{id} + + + \ No newline at end of file diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/ScheduledRemindersTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/ScheduledRemindersTask.java index 82c6823..367738e 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/ScheduledRemindersTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/ScheduledRemindersTask.java @@ -1,15 +1,21 @@ package com.ruoyi.quartz.task; +import cn.hutool.extra.template.Template; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.lark.oapi.service.bitable.v1.model.ListAppTableRecordRespBody; -import com.ruoyi.common.enums.AppType; -import com.ruoyi.common.enums.FlagStatus; -import com.ruoyi.common.enums.TableRelationTypeEnum; +import com.ruoyi.common.enums.*; import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper; import com.ruoyi.flyingbook.LarkHelper.script.LarkTableFilterScriptHelper; +import com.ruoyi.flyingbook.domain.EventLog; import com.ruoyi.flyingbook.domain.LarkCompanyTableInfo; +import com.ruoyi.flyingbook.domain.LarkTableConfiguration; +import com.ruoyi.flyingbook.domain.LarkTemplate; import com.ruoyi.flyingbook.domain.lark.LarkTableRequest; +import com.ruoyi.flyingbook.mapper.EventLogMapper; +import com.ruoyi.flyingbook.mapper.LarkTableConfigurationMapper; import com.ruoyi.flyingbook.mapper.LarkTableRelationMapper; +import com.ruoyi.flyingbook.mapper.LarkTemplateMapper; import com.ruoyi.quartz.helper.OkHttpHelper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; @@ -18,8 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -38,6 +44,12 @@ public class ScheduledRemindersTask { @Autowired private LarkTableHelper larkTableHelper; + @Autowired + private LarkTemplateMapper larkTemplateMapper; + @Autowired + private LarkTableConfigurationMapper larkTableConfigurationMapper; + @Autowired + private EventLogMapper eventLogMapper; /**查询分页大小*/ private static final Integer PAGE_SIZE = 20; @@ -51,33 +63,113 @@ public class ScheduledRemindersTask { if (CollectionUtils.isEmpty(larkList)){ return; } - String script = LarkTableFilterScriptHelper.buildTimeRange(RANGE_KEY,LocalDateTime.now()); + List logList = new ArrayList<>(); for (LarkCompanyTableInfo larkCompanyTableInfo : larkList) { try { - this.sendMessage(script,larkCompanyTableInfo); + List larkConfiguration = this.getLarkConfiguration(larkCompanyTableInfo); + for (LarkTableConfiguration larkTableConfiguration : larkConfiguration) { + ConfigurationSubTypeEnum subType = ConfigurationSubTypeEnum.getByCode(larkTableConfiguration.getSubConfigType()); + if (subType == null){ + 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,LocalDateTime.now()); + this.sendMessage(script,larkCompanyTableInfo,logList); + script = LarkTableFilterScriptHelper.buildTimeRange(larkTableConfiguration,ConfigurationSubTypeEnum.REMINDER_AFTER,RANGE_KEY,LocalDateTime.now()); + this.sendMessage(script,larkCompanyTableInfo,logList); + }else { + String script = LarkTableFilterScriptHelper.buildTimeRange(larkTableConfiguration,subType,RANGE_KEY,LocalDateTime.now()); + this.sendMessage(script,larkCompanyTableInfo,logList); + } + } }catch (Exception e){ - //todo yxy 记录日志 + log.error("ScheduledRemindersTask#scheduledReminders error request:{}",JSONObject.toJSONString(larkCompanyTableInfo),e); + new EventLog(larkCompanyTableInfo.getId(),EventOperateType.SCHEDULE_REMINDER.getCode(), JSONObject.toJSONString(larkCompanyTableInfo),null,e.getMessage()); } - + } + if (CollectionUtils.isNotEmpty(logList)){ + eventLogMapper.insertBatchEventLog(logList); } log.info("scheduledRemindersTask end"); } - private void sendMessage(String script,LarkCompanyTableInfo larkCompanyTableInfo){ + private void sendMessage(String script,LarkCompanyTableInfo larkCompanyTableInfo,List logList){ String pageToken = null; LarkTableRequest request = this.buildRequest(larkCompanyTableInfo, script); + LarkTemplate template = this.getTemplate(larkCompanyTableInfo); do { - ListAppTableRecordRespBody respBody = larkTableHelper.listTableRecord(request); - pageToken = respBody.getPageToken(); - Arrays.stream(respBody.getItems()).forEach(r -> { - Map fields = r.getFields(); - JSONObject msg = new JSONObject(); - - OkHttpHelper.post(larkCompanyTableInfo.getToAppToken(),msg.toString()); - }); + JSONObject msg = new JSONObject(); + try { + ListAppTableRecordRespBody respBody = larkTableHelper.listTableRecord(request); + pageToken = respBody.getPageToken(); + Arrays.stream(respBody.getItems()).forEach(r -> { + Map fields = r.getFields(); + JSONObject msg = this.buildMsg(larkCompanyTableInfo,fields, template); + OkHttpHelper.post(larkCompanyTableInfo.getToAppToken(),msg.toString()); + }); + new EventLog(larkCompanyTableInfo.getId(),EventOperateType.SCHEDULE_REMINDER.getCode(), msg.toString()); + }catch (Exception e){ + log.error("ScheduledRemindersTask#scheduledReminders error request tableId:{} msg:{}",JSONObject.toJSONString(larkCompanyTableInfo),msg.toString(),e); + new EventLog(larkCompanyTableInfo.getId(),EventOperateType.SCHEDULE_REMINDER.getCode(), msg.toString(),null,e.getMessage()); + } }while (StringUtils.isNotBlank(pageToken)); } + private LarkTemplate getTemplate(LarkCompanyTableInfo larkCompanyTableInfo){ + LarkTemplate larkTemplate = new LarkTemplate(); + larkTemplate.setTemplateType(TemplateTypeEnum.SCHEDULED_REMINDER.getCode()); + larkTemplate.setFlag(FlagStatus.OK.getCode()); + larkTemplate.setLarkTableId(larkCompanyTableInfo.getId()); + List larkTemplates = larkTemplateMapper.selectLarkTemplateList(larkTemplate); + if (CollectionUtils.isEmpty(larkTemplates)){ + throw new RuntimeException(String.format("当前tableId:%s %s类型的模板配置不存在",larkCompanyTableInfo.getId(),larkTemplate.getTemplateType())); + } + if (larkTemplates.size() > 1){ + throw new RuntimeException(String.format("当前tableId:%s %s类型存在多个有效的模板配置",larkCompanyTableInfo.getId(),larkTemplate.getTemplateType())); + } + return larkTemplates.get(0); + } + + private List getLarkConfiguration(LarkCompanyTableInfo larkCompanyTableInfo){ + List configurationList = new ArrayList<>(); + LarkTableConfiguration query = new LarkTableConfiguration(); + query.setLarkTableId(larkCompanyTableInfo.getId()); + query.setFlag(FlagStatus.OK.getCode()); + query.setConfigType(ConfigurationTypeEnum.SCHEDULE_REMINDER.getCode()); + configurationList = larkTableConfigurationMapper.selectLarkTableConfigurationList(query); + if (CollectionUtils.isEmpty(configurationList)){ + throw new RuntimeException(String.format("当前tableId:%s 无定时提醒配置",larkCompanyTableInfo.getId())); + } + return configurationList; + } + + private JSONObject buildMsg(LarkCompanyTableInfo larkCompanyTableInfo,Map fields, LarkTemplate template){ + JSONObject msg = new JSONObject(); + TemplateSubTypeEnum templateSubTypeEnum = TemplateSubTypeEnum.getByCode(template.getSubTemplateType()); + if (templateSubTypeEnum == null){ + throw new RuntimeException(String.format("当前tableId:%s 模板类型%s对应策略不存在",larkCompanyTableInfo.getId(),template.getSubTemplateType())); + } + switch (templateSubTypeEnum){ + case TEXT: + msg.put("msg_type",templateSubTypeEnum.getCode()); + String templateContent = template.getTemplateContent(); + JSONArray people = JSONObject.parseArray(String.valueOf(fields.get("人员"))); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < people.size(); i++) { + JSONObject jsonObject = people.getJSONObject(i); + sb.append(String.format("%s",jsonObject.getString("id"),jsonObject.getString("name"))); + } + templateContent.replaceAll("@name",sb.toString()).replaceAll("#name",String.valueOf(fields.get("学生姓名"))); + JSONObject content = new JSONObject(); + content.put("text",sb.append(templateContent).toString()); + msg.put("content",content); + break; + default: + break; + } + return msg; + } + private List getLarkList() { List larkCompanyTableInfos = larkTableRelationMapper.queryListJoinLarkCompany(FlagStatus.OK.getCode(), AppType.SCHEDULED_REMINDERS.getCode(), TableRelationTypeEnum.SYNC_EMAIL.getCode()); return larkCompanyTableInfos.stream()