Ver Fonte

删除群组

刘俊驰 há 9 meses atrás
pai
commit
dfe8ad99ff

+ 8 - 0
mec-application/src/main/java/com/ym/mec/web/controller/ImGroupController.java

@@ -368,4 +368,12 @@ public class ImGroupController extends BaseController {
 		return succeed();
 	}
 
+
+    @GetMapping("/deleteGroup")
+    public Object deleteGroup() {
+        ExecutorService executor = Executors.newSingleThreadExecutor();
+        executor.execute(() -> imGroupService.deleteGroup());
+        return succeed();
+    }
+
 }

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/MusicGroupDao.java

@@ -542,4 +542,6 @@ public interface MusicGroupDao extends BaseDAO<String, MusicGroup> {
     List<ExportMusicGroupEchelonDataDto> queryCoopEchelonData(@Param("organIds") List<Integer> organIds);
 
     List<ExportMusicGroupEchelonDataDto> queryMusicGroupEchelonData(@Param("musicGroupIds") List<String> musicGroupIds);
+
+    List<String> getDelImGroupId();
 }

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ImGroupService.java

@@ -222,4 +222,9 @@ public interface ImGroupService extends BaseService<String, ImGroup> {
     com.yonge.mongodb.PageInfo<HistoryMessageTencentWrapper.HistoryMessageTencent> historyMessage(HistoryMessageTencentWrapper.HistoryMessageTencentQuery query);
 
     Map<String,ImGroup> getMapByIds(List<String> groupIdList);
+
+    void deleteGroup();
+
+    @Transactional(rollbackFor = Exception.class)
+    void delGroup(String imGroupId);
 }

+ 53 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImGroupServiceImpl.java

@@ -13,7 +13,6 @@ import com.microsvc.toolkit.middleware.im.message.GroupMemberWrapper;
 import com.microsvc.toolkit.middleware.im.message.MessageWrapper;
 import com.microsvc.toolkit.middleware.im.message.TencentRequest;
 import com.ym.mec.auth.api.entity.SysUser;
-import com.ym.mec.auth.api.enums.SysUserType;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.ImGroupDto;
 import com.ym.mec.biz.dal.dto.ImGroupMemberDto;
@@ -142,6 +141,9 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
     @Autowired
     private HistoryMessageTenantService historyMessageTencentService;
 
+    @Autowired
+    private ImGroupService imGroupService;
+
     @Override
     public BaseDAO<String, ImGroup> getDAO() {
         return imGroupDao;
@@ -1855,6 +1857,56 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
         return imGroups.stream().collect(Collectors.toMap(ImGroup::getId, item -> item));
     }
 
+    @Override
+    public void deleteGroup() {
+
+        // 100个线程的无界线程池
+        ThreadPoolExecutor executorService =  new ThreadPoolExecutor(100, 100,
+            0L, TimeUnit.MILLISECONDS,
+            new LinkedBlockingQueue<Runnable>());
+
+        log.info("-------------------------------deleteGroup start---------------------------");
+
+
+        List<String> imGroupIds =
+            musicGroupDao.getDelImGroupId();
+        for (String imGroupId : imGroupIds) {
+            executorService.execute(() -> {
+                imGroupService.delGroup(imGroupId);
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    log.error("线程等待异常", e);
+                }
+            });
+        }
+
+        while (executorService.getQueue().size() > 0) {
+            try {
+                log.info("线程池中正在执行的任务数量:{},等待数量:{}", executorService.getActiveCount(),executorService.getQueue().size());
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+                log.error("线程等待异常", e);
+            }
+        }
+        executorService.shutdown();
+        log.info("------------------------------- deleteGroup end---------------------------");
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void delGroup(String imGroupId) {
+        if (StringUtils.isEmpty(imGroupId)) {
+            return;
+        }
+        try {
+            imGroupCoreService.groupDismiss(imGroupId);
+        } catch (Exception e) {
+            log.error("删除群组失败:{}",imGroupId, e);
+            throw new BizException("删除群组失败");
+        }
+    }
+
     private TencentRequest.MessageBody getTimGifElem(String remoteUr,int size,int width,int height) {
         if (StringUtils.isEmpty(remoteUr) && size == 0 && width == 0 && height == 0) {
             return null;

+ 7 - 0
mec-biz/src/main/resources/config/mybatis/MusicGroupMapper.xml

@@ -1316,4 +1316,11 @@
         </foreach>
         group by sr.music_group_id_,st.current_grade_num_ order by sr.music_group_id_,st.current_grade_num_
     </select>
+
+    <select id="getDelImGroupId" resultType="java.lang.String">
+        select distinct ig.id_ from music_group mg
+                             left join class_group cg ON cg.music_group_id_ = mg.id_
+                             left join im_group ig ON ig.id_ = cg.id_
+        where mg.status_ IN ('CANCELED','CLOSE') and cg.group_type_ = 'MUSIC';
+    </select>
 </mapper>