diff --git a/backend/src/main/java/io/dataease/ext/CleaningRebotMapper.java b/backend/src/main/java/io/dataease/ext/CleaningRebotMapper.java
new file mode 100644
index 0000000000..16361cefe6
--- /dev/null
+++ b/backend/src/main/java/io/dataease/ext/CleaningRebotMapper.java
@@ -0,0 +1,26 @@
+package io.dataease.ext;
+
+public interface CleaningRebotMapper {
+
+ int delFloatingDept();
+
+ void updateUserDept();
+
+ void delFloatingRoleMapping();
+
+ void delFloatingPanelShare();
+
+ void delFloatingTargetShare();
+
+ void delFloatingPanelStore();
+
+ void delFloatingTargetStore();
+
+ void delFloatingPanelLink();
+
+ void delFloatingPanelLinkMapping();
+
+ void delFloatingCreatorLink();
+
+ void delFloatingCreatorLinkMapping();
+}
diff --git a/backend/src/main/java/io/dataease/ext/CleaningRebotMapper.xml b/backend/src/main/java/io/dataease/ext/CleaningRebotMapper.xml
new file mode 100644
index 0000000000..b4efc734b2
--- /dev/null
+++ b/backend/src/main/java/io/dataease/ext/CleaningRebotMapper.xml
@@ -0,0 +1,114 @@
+
+
+
+
+
+ delete
+ from sys_dept
+ where pid not in (select * from (select dept_id from sys_dept) a)
+ and pid != 0;
+
+
+
+ update sys_user
+ set dept_id = 0
+ where dept_id is not null
+ and dept_id not in (select * from (select dept_id from sys_dept) a)
+ and dept_id != 0;
+
+
+
+ delete
+ from sys_users_roles
+ where user_id not in (select * from (select u.user_id from sys_user u) a)
+ or role_id not in (select * from (select r.role_id from sys_role r) b);
+
+
+
+ delete
+ from panel_share
+ where share_id in (select *
+ from (SELECT s.share_id
+ FROM panel_share s
+ left join panel_group p on s.panel_group_id = p.id
+ where p.id is null) a)
+
+
+
+ delete
+ from panel_share
+ where share_id in (select share_id
+ from (select s.share_id,
+ (
+ CASE s.type
+ WHEN 0 THEN (select nick_name from sys_user where user_id = s.target_id)
+ WHEN 1 THEN (select name from sys_role where role_id = s.target_id)
+ WHEN 2 THEN (select name from sys_dept where dept_id = s.target_id)
+ END
+ ) as target_name
+ from panel_share s) query_temp
+ where target_name is null)
+
+
+
+ delete
+ from panel_store
+ where store_id in (select *
+ from (SELECT s.store_id
+ FROM panel_store s
+ left join panel_group p on s.panel_group_id = p.id
+ where p.id is null) a)
+
+
+
+ delete
+ from panel_store
+ where store_id in (select *
+ from (SELECT s.store_id
+ FROM panel_store s
+ left join sys_user u on s.user_id = u.user_id
+ where u.user_id is null) a)
+
+
+
+ delete
+ from panel_link
+ where resource_id in (select *
+ from (SELECT l.resource_id
+ FROM panel_link l
+ left join panel_group p on l.resource_id = p.id
+ where p.id is null) a);
+
+
+
+
+ delete
+ from panel_link_mapping
+ where id in (select *
+ from (SELECT m.id
+ FROM panel_link_mapping m
+ left join panel_group p on m.resource_id = p.id
+ where p.id is null) a);
+
+
+
+ delete
+ from panel_link
+ where resource_id in (select *
+ from (SELECT l.resource_id
+ FROM panel_link l
+ left join sys_user u on l.user_id = u.user_id
+ where u.user_id is null) a);
+
+
+
+
+ delete
+ from panel_link_mapping
+ where id in (select *
+ from (SELECT m.resource_id
+ FROM panel_link_mapping m
+ left join sys_user u on m.user_id = u.user_id
+ where u.user_id is null) a);
+
+
diff --git a/backend/src/main/java/io/dataease/ext/ExtPanelShareMapper.xml b/backend/src/main/java/io/dataease/ext/ExtPanelShareMapper.xml
index 779de83551..1bb175b653 100644
--- a/backend/src/main/java/io/dataease/ext/ExtPanelShareMapper.xml
+++ b/backend/src/main/java/io/dataease/ext/ExtPanelShareMapper.xml
@@ -3,20 +3,20 @@
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
@@ -27,10 +27,10 @@
-
+
delete from panel_share
where share_id in
-
+
#{shareId}
@@ -81,43 +81,47 @@
-
-
-
diff --git a/backend/src/main/java/io/dataease/listener/CleaningRobotListener.java b/backend/src/main/java/io/dataease/listener/CleaningRobotListener.java
new file mode 100644
index 0000000000..59b7032301
--- /dev/null
+++ b/backend/src/main/java/io/dataease/listener/CleaningRobotListener.java
@@ -0,0 +1,26 @@
+package io.dataease.listener;
+
+import io.dataease.commons.utils.LogUtil;
+import io.dataease.service.CleaningRebotService;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+@Component
+public class CleaningRobotListener implements ApplicationListener {
+
+ @Resource
+ private CleaningRebotService cleaningRebotService;
+
+ @Override
+ public void onApplicationEvent(ApplicationReadyEvent event) {
+ try {
+ cleaningRebotService.execute();
+ } catch (Exception e) {
+ LogUtil.error(e.getMessage(), e);
+ }
+
+ }
+}
diff --git a/backend/src/main/java/io/dataease/service/CleaningRebotService.java b/backend/src/main/java/io/dataease/service/CleaningRebotService.java
new file mode 100644
index 0000000000..1c45468ce1
--- /dev/null
+++ b/backend/src/main/java/io/dataease/service/CleaningRebotService.java
@@ -0,0 +1,37 @@
+package io.dataease.service;
+
+import io.dataease.ext.CleaningRebotMapper;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+
+@Service
+public class CleaningRebotService {
+
+ @Value("${dataease.clean-nobody-link:false}")
+ private Boolean cleanNobodyLink;
+
+ @Resource
+ private CleaningRebotMapper cleaningRebotMapper;
+
+ public void execute() {
+ int floatDept = 0;
+ do {
+ floatDept = cleaningRebotMapper.delFloatingDept();
+ } while (floatDept > 0);
+ cleaningRebotMapper.updateUserDept();
+ cleaningRebotMapper.delFloatingRoleMapping();
+ cleaningRebotMapper.delFloatingPanelShare();
+ cleaningRebotMapper.delFloatingTargetShare();
+ cleaningRebotMapper.delFloatingPanelStore();
+ cleaningRebotMapper.delFloatingTargetStore();
+ cleaningRebotMapper.delFloatingPanelLink();
+ cleaningRebotMapper.delFloatingPanelLinkMapping();
+ if (cleanNobodyLink) {
+ cleaningRebotMapper.delFloatingCreatorLink();
+ cleaningRebotMapper.delFloatingCreatorLinkMapping();
+ }
+ }
+}