3131import org .jetlinks .core .device .session .DeviceSessionEvent ;
3232import org .jetlinks .core .message .codec .DefaultTransport ;
3333import org .jetlinks .core .rpc .RpcManager ;
34- import org .jetlinks .core .server .session .DeviceSession ;
35- import org .jetlinks .core .server .session .DeviceSessionProvider ;
36- import org .jetlinks .core .server .session .LostDeviceSession ;
37- import org .jetlinks .core .server .session .PersistentSession ;
34+ import org .jetlinks .core .server .session .*;
3835import org .jetlinks .core .utils .Reactors ;
3936import org .jetlinks .core .utils .RecyclerUtils ;
4037import org .jetlinks .community .codec .Serializers ;
@@ -202,19 +199,19 @@ public void init() {
202199 if (ctx .hasKey (PersistenceDeviceSessionManager .class )) {
203200 return Mono .empty ();
204201 }
205- //持久化
206- if (event .getSession ().isWrapFrom (PersistentSession .class )) {
207- if (event .getType () == DeviceSessionEvent .Type .unregister ) {
208- return removePersistentSession (event .getSession ().unwrap (PersistentSession .class ));
209- }
210- } else if (recordHistory ) {
202+ boolean isPersistent
203+ = !(event .getSession () instanceof ChildrenDeviceSession )
204+ && event .getSession ().isWrapFrom (PersistentSession .class );
205+
206+ if (recordHistory && !isPersistent ) {
211207 //记录历史设备
212208 if (event .getType () == DeviceSessionEvent .Type .register ) {
213209 return this
214210 .operateInStore (
215211 () -> history ,
216- history -> history .put (event .getSession ().getDeviceId (),
217- event .getSession ().connectTime ())
212+ history -> history
213+ .put (event .getSession ().getDeviceId (),
214+ event .getSession ().connectTime ())
218215 )
219216 .then ();
220217 }
@@ -227,6 +224,10 @@ public void init() {
227224 .then ();
228225 }
229226 }
227+ if (event .getType () == DeviceSessionEvent .Type .unregister && isPersistent && !isShutdown ()) {
228+ return removePersistentSession (event .getSession ().unwrap (PersistentSession .class ));
229+ }
230+
230231 return Mono .empty ();
231232 }))
232233 );
0 commit comments