|
|
@ -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); |
|
|
|
} |
|
|
|
} |