diff --git a/Readme.md b/Readme.md index dfe89ab..c06cc5b 100644 --- a/Readme.md +++ b/Readme.md @@ -6,3 +6,5 @@ MQTT 服务器管理员账号 :admin/[admin@emqx] +MQTT 服务器安装路径 : C:/Program File (x86)/emqx-5.3.2-windows-amd64 + diff --git a/app.db b/app.db index f30aaad..1236bce 100644 Binary files a/app.db and b/app.db differ diff --git a/src/main/java/com/iflytop/digester/underframework/dao/model/UfMdbNotification.java b/src/main/java/com/iflytop/digester/underframework/dao/model/UfMdbNotification.java index 48ff79a..318167f 100644 --- a/src/main/java/com/iflytop/digester/underframework/dao/model/UfMdbNotification.java +++ b/src/main/java/com/iflytop/digester/underframework/dao/model/UfMdbNotification.java @@ -2,9 +2,9 @@ package com.iflytop.digester.underframework.dao.model; import com.iflytop.digester.underframework.dao.record.UfActiveRecord; import com.iflytop.digester.underframework.dao.record.UfActiveRecordField; import com.iflytop.digester.underframework.util.UfJsonHelper; - +import org.springframework.util.DigestUtils; +import java.text.SimpleDateFormat; import java.util.Map; - public class UfMdbNotification extends UfActiveRecord { @UfActiveRecordField public String type; @@ -12,66 +12,48 @@ public class UfMdbNotification extends UfActiveRecord { public String data; @UfActiveRecordField public String status; + @UfActiveRecordField + public String hash; + @UfActiveRecordField + public String time; // get table name public static String getTableName() { return "app_notifications"; } -// -// // notify action -// public static void taskAction(DiTask task, String action ) { -// DiMdbNotification.taskAction(task, action, ""); -// } -// -// // notify action -// public static void taskAction( DiTask task, String action, Object data ) { -// Map notifyData = Map.of( -// "action", action, -// "data", data, -// "task", task.getUUID() -// ); -// var notification = new DiMdbNotification(); -// notification.type = "task-action"; -// notification.data = DiJsonHelper.objectToJson(notifyData); -// notification.status = "new"; -// notification.save(); -// } -// -// // notify error -// public static void taskError( DiTask task, String error ) { -// var notification = new DiMdbNotification(); -// notification.type = "task-error"; -// notification.data = error; -// notification.status = "new"; -// notification.save(); -// } -// -// // notify warning -// public static void warning( String message ) { -// var notification = new DiMdbNotification(); -// notification.type = "warning"; -// notification.data = message; -// notification.status = "new"; -// notification.save(); -// } - // notify error - public static void error( String message, Object ... args ) { - var notification = new UfMdbNotification(); - notification.type = "error"; - notification.data = String.format(message, args); + // create notification + private static void createNotification( String type, String data ) { + var hash = DigestUtils.md5DigestAsHex(data.getBytes()); + + // check if exists, ignore if exists + var notification = UfActiveRecord.findOne(UfMdbNotification.class, Map.of( + "hash", hash, "status", "new" + )); + if ( null != notification ) { + return ; + } + + notification = new UfMdbNotification(); + notification.type = type; + notification.data = data; notification.status = "new"; + notification.hash = hash; + + var dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + notification.time = dateFormatter.format(System.currentTimeMillis()); notification.save(); } + // notify error + public static void error( String message, Object ... args ) { + createNotification("error", String.format(message, args)); + } + // notify action public static void action( String action, Map params) { var data = Map.of("action", action, "params", params); var dataJson = UfJsonHelper.objectToJson(data); - var notification = new UfMdbNotification(); - notification.type = "action"; - notification.data = dataJson; - notification.status = "new"; - notification.save(); + createNotification("action", dataJson); } }