@ -3,10 +3,12 @@ package com.kanglai.push.util;
@@ -3,10 +3,12 @@ package com.kanglai.push.util;
import com.blankj.utilcode.util.CacheDiskUtils ;
import com.blankj.utilcode.util.MapUtils ;
import com.google.gson.Gson ;
import com.google.gson.reflect.TypeToken ;
import com.kanglai.push.constant.CacheConstant ;
import com.kanglai.push.entity.LocalPushChatMsg ;
import com.kanglai.push.entity.User ;
import java.lang.reflect.Type ;
import java.util.Map ;
import java.util.Objects ;
@ -19,13 +21,15 @@ public class HistoryMsgUtil {
@@ -19,13 +21,15 @@ public class HistoryMsgUtil {
public Map < String , LocalPushChatMsg > select ( ) {
String localHistoryMsgJson = CacheDiskUtils . getInstance ( ) . getString ( user . getId ( ) . concat ( user . getUserType ( ) ) , "" ) ;
return ( Map < String , LocalPushChatMsg > ) new Gson ( ) . fromJson ( localHistoryMsgJson , Map . class ) ;
Type type = new TypeToken < Map < String , LocalPushChatMsg > > ( ) { } . getType ( ) ;
return new Gson ( ) . fromJson ( localHistoryMsgJson , type ) ;
}
public void put ( String key , LocalPushChatMsg value ) {
Objects . requireNonNull ( key ) ;
String localHistoryMsgJson = CacheDiskUtils . getInstance ( ) . getString ( user . getId ( ) . concat ( user . getUserType ( ) ) , "" ) ;
Map < String , LocalPushChatMsg > localHistoryMsg = Objects . requireNonNullElse ( ( Map < String , LocalPushChatMsg > ) new Gson ( ) . fromJson ( localHistoryMsgJson , Map . class ) , MapUtils . newHashMap ( ) ) ;
Type type = new TypeToken < Map < String , LocalPushChatMsg > > ( ) { } . getType ( ) ;
Map < String , LocalPushChatMsg > localHistoryMsg = Objects . requireNonNullElse ( new Gson ( ) . fromJson ( localHistoryMsgJson , type ) , MapUtils . newHashMap ( ) ) ;
localHistoryMsg . put ( key , value ) ;
String newLocalHistoryMsgJson = new Gson ( ) . toJson ( localHistoryMsg ) ;
CacheDiskUtils . getInstance ( ) . put ( user . getId ( ) . concat ( user . getUserType ( ) ) , newLocalHistoryMsgJson ) ;
@ -34,7 +38,8 @@ public class HistoryMsgUtil {
@@ -34,7 +38,8 @@ public class HistoryMsgUtil {
public void del ( String key ) {
Objects . requireNonNull ( key ) ;
String localHistoryMsgJson = CacheDiskUtils . getInstance ( ) . getString ( user . getId ( ) . concat ( user . getUserType ( ) ) , "" ) ;
Map < String , LocalPushChatMsg > localHistoryMsg = Objects . requireNonNullElse ( ( Map < String , LocalPushChatMsg > ) new Gson ( ) . fromJson ( localHistoryMsgJson , Map . class ) , MapUtils . newHashMap ( ) ) ;
Type type = new TypeToken < Map < String , LocalPushChatMsg > > ( ) { } . getType ( ) ;
Map < String , LocalPushChatMsg > localHistoryMsg = Objects . requireNonNullElse ( new Gson ( ) . fromJson ( localHistoryMsgJson , type ) , MapUtils . newHashMap ( ) ) ;
localHistoryMsg . remove ( key ) ;
String newLocalHistoryMsgJson = new Gson ( ) . toJson ( localHistoryMsg ) ;
CacheDiskUtils . getInstance ( ) . put ( user . getId ( ) . concat ( user . getUserType ( ) ) , newLocalHistoryMsgJson ) ;