Browse Source

相同通知内容在未被处理前仅触发一次

master
sige 1 year ago
parent
commit
374e1678ec
  1. 2
      Readme.md
  2. BIN
      app.db
  3. 80
      src/main/java/com/iflytop/digester/underframework/dao/model/UfMdbNotification.java

2
Readme.md

@ -6,3 +6,5 @@
MQTT 服务器管理员账号 :admin/[admin@emqx]
MQTT 服务器安装路径 : C:/Program File (x86)/emqx-5.3.2-windows-amd64

BIN
app.db

80
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<String, Object> 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<String,Object> 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);
}
}
Loading…
Cancel
Save