| | |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.cron.CronUtil; |
| | | import com.google.common.collect.Sets; |
| | | import com.product.administration.config.SystemCode; |
| | | import com.product.common.collect.SetUtils; |
| | | import com.product.quartz.util.CronUtils; |
| | | import com.product.util.SystemParamReplace; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | /** |
| | | * 预警-给定uuid单个预警,通常为定时任务触发 |
| | | * |
| | | * @param uuid |
| | | */ |
| | | public void triggerSingleWarningTask(String uuid) { |
| | |
| | | |
| | | /** |
| | | * 单个预警 |
| | | * |
| | | * @param fseWarningConfig |
| | | */ |
| | | private void singleWarningTask(FieldSetEntity fseWarningConfig) { |
| | |
| | | |
| | | String flowCode = fseWarningConfig.getString(CmnConst.FLOW_CODE); //流程type_code |
| | | String flowParam = fseWarningConfig.getString(CmnConst.FLOW_PARAM); //流程参数转换 |
| | | |
| | | //获取发送消息频率 |
| | | Double cronExpression = fseWarningConfig.getDouble("reminder_frequency"); |
| | | |
| | | //发送消息的频率 1.23 小数点前面代表天 小数点后面代表小时 |
| | | double seconds = 0; |
| | | if (cronExpression != null && cronExpression > 0) { |
| | | |
| | | //将发送消息频率转换为小时 |
| | | double hours = cronExpression * 24; |
| | | //将发送消息频率转换为分钟 |
| | | double minutes = hours * 60; |
| | | //将发送消息频率转换为秒 |
| | | seconds = minutes * 60; |
| | | } |
| | | |
| | | |
| | | Map<String, String> tableNameAndAlias = new HashMap<>(); //相关表名-->表别名,tableName-->tableName1 |
| | | Map<String, String> fieldAndAlias = new HashMap<>(); //相关字段-->字段别名,tableName.fieldName-->tableName1fieldName |
| | |
| | | //查询符合预警的数据 |
| | | DataTableEntity dtService = baseDao.listTable(serviceSQL.toString(), new Object[]{}); |
| | | if (!BaseUtil.dataTableIsEmpty(dtService)) { |
| | | List<String> collect = dtService.getData().stream().map(item -> item.getString(mainTableAlias + "uuid")).collect(Collectors.toList()); |
| | | //预警uuid |
| | | String warnUUID = fseWarningConfig.getUUID(); |
| | | //将预警uuid放到collect 的第一个 |
| | | |
| | | collect.add(0, warnUUID); |
| | | StringBuilder sql = new StringBuilder(); |
| | | //查询是否已经存在预警如有相同data_uuid的数据查询出最近的一条根据预警时间字段 early_warning_datetime |
| | | // SELECT e.* |
| | | // FROM product_sys_early_warning_info e |
| | | // JOIN ( |
| | | // SELECT data_uuid, MAX(early_warning_datetime) AS latest_datetime |
| | | // FROM product_sys_early_warning_info |
| | | // GROUP BY data_uuid |
| | | // ) AS latest |
| | | // ON e.data_uuid = latest.data_uuid AND e.early_warning_datetime = latest.latest_datetime; |
| | | sql.append("SELECT e.* FROM product_sys_early_warning_info e JOIN ("); |
| | | sql.append("SELECT data_uuid, MAX(early_warning_datetime) AS latest_datetime FROM product_sys_early_warning_info "); |
| | | sql.append(" where early_warning_uuid=? and (").append(BaseUtil.buildQuestionMarkFilter("data_uuid", collect.size(), true)).append(") "); |
| | | sql.append("GROUP BY data_uuid) AS latest ON e.data_uuid = latest.data_uuid AND e.early_warning_datetime = latest.latest_datetime"); |
| | | DataTableEntity dt = baseDao.listTable(sql.toString(), collect.toArray()); |
| | | |
| | | Map<String, FieldSetEntity> ff = new HashMap<>(); |
| | | if (!DataTableEntity.isEmpty(dt)) { |
| | | for (int j = 0; j < dt.getRows(); j++) { |
| | | FieldSetEntity fse = dt.getFieldSetEntity(j); |
| | | ff.put(fse.getString("data_uuid"), fse); |
| | | } |
| | | } |
| | | |
| | | //以data_uuid 进行分组 |
| | | for (int j = 0; j < dtService.getRows(); j++) { |
| | | FieldSetEntity fseService = dtService.getFieldSetEntity(j); |
| | | |
| | | //业务uuid |
| | | String serviceId = fseService.getString(mainTableAlias + "uuid"); |
| | | //预警uuid |
| | | String warnUUID = fseWarningConfig.getUUID(); |
| | | |
| | | if (ff.containsKey(serviceId) && StringUtils.isEmpty(cronExpression)) { |
| | | //如果已经存在预警信息 根据cron表达式判断是否需要再次预警 |
| | | Date preTime = ff.get(serviceId).getDate("early_warning_datetime"); |
| | | if (preTime != null) { |
| | | long time = new Date().getTime() - preTime.getTime(); |
| | | if (time < seconds * 1000) { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //信息接收人 |
| | | Set<String> receiverSet = Sets.newTreeSet(); |
| | |
| | | |
| | | /** |
| | | * 根据提醒内容中的表属性,进行拼接成标准格式 |
| | | * |
| | | * @param content 预警内容 |
| | | * @param concatField 组合字段 |
| | | * @param tableNameAndAlias 表名及别名 |
| | |
| | | |
| | | /** |
| | | * 根据提醒内容中的表属性,进行拼接成标准格式 |
| | | * |
| | | * @param flowParam 预警内容 |
| | | * @param concatField 组合字段 |
| | | * @param tableNameAndAlias 表名及别名 |
| | |
| | | |
| | | /** |
| | | * 根据表名和字段的获取对应参照 |
| | | * |
| | | * @param tableAndField 表别名.字段名 |
| | | * @return 参照名 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 生成关联SQL |
| | | * |
| | | * @param tableNameAndAlias |
| | | * @param subTable 当前表 |
| | | * @return |
| | |
| | | |
| | | /** |
| | | * 参照替换 |
| | | * |
| | | * @param referenceName |
| | | * @param originValue |
| | | * @param fseData |
| | |
| | | |
| | | /** |
| | | * 解析条件表达式 |
| | | * |
| | | * @param warnCOnditon |
| | | * @param tableNameAndAlias |
| | | * @return |
| | |
| | | |
| | | /** |
| | | * 预警发邮件解析 |
| | | * |
| | | * @param content |
| | | * @param receiver |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 预警发短信解析 |
| | | * |
| | | * @param content |
| | | * @param receiver |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 自动发起流程 |
| | | * |
| | | * @param flowCode |
| | | * @param flowParam |
| | | * @param fseService |