public JSONObject saveFolderPermission() {
...
Set<String> oldUsernames = folderEnterprise.getUsernameSet();
Set<String> oldOrgIds = folderEnterprise.getOrgIdsSet();
Set<String> usernames = new HashSet<>();
Set<String> orgIds = new HashSet<>();
storageService.usernamesAndOrgIdsDeal(usernames, orgIds, sharedToUserArray, sharedToDeptArray);
folderEnterprise.setFolderPermissions(JSONObject.parseObject(folderPermissions));
folderEnterprise.setUsernameSet(usernames);
folderEnterprise.setOrgIdsSet(orgIds);
folderService.save(folderEnterprise);
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicInteger total = new AtomicInteger();
ThreadLocalContext localContext = ThreadLocalContextHolder.getContext();
MultiThread.pool.execute(() -> {
ThreadLocalContext threadLocalContext = ThreadLocalContextHolder.getContext();
MultiThread.multiThreadInit(threadLocalContext, localContext);
Set<String> totalUsernamesSet = noticeService.getUserNameSet(Joiner.on(",").join(usernames), Joiner.on(",").join(orgIds));
total.set(totalUsernamesSet.size());
countDownLatch.countDown();
});
MultiThread.pool.execute(() -> {
try {
countDownLatch.await();
ThreadLocalContext threadLocalContext = ThreadLocalContextHolder.getContext();
MultiThread.multiThreadInit(threadLocalContext, localContext);
if (folderEnterprise.getParent() == null) {
Set<String> resultUsernames = new HashSet<>();
Set<String> resultOrgIds = new HashSet<>();
//新增成员发送通知
resultUsernames.addAll(usernames);
resultUsernames.removeAll(oldUsernames);
for (String username : resultUsernames) {
for (int i = 0; i < sharedToUserArray.size(); i++) {
JSONObject sharedToUser = sharedToUserArray.getJSONObject(i);
String inUsername = sharedToUser.getString("username");
if (inUsername.equals(username)) {
noticeService.sendMessage(username, null, "", true, folderEnterprise.formatJson(), MessageTemplateEnum.levelOneFolderPermissionAdd, folderService.genLevelOneFolderPermissionAddParams(folderEnterprise, sharedToUser, total.get()));
break;
}
}
}
resultOrgIds.addAll(orgIds);
resultOrgIds.removeAll(oldOrgIds);
for (String orgId : resultOrgIds) {
for (int i = 0; i < sharedToDeptArray.size(); i++) {
JSONObject sharedToDept = sharedToDeptArray.getJSONObject(i);
String id = sharedToDept.getString("id");
if (id.equals(orgId)) {
noticeService.sendMessage(null, orgId, "", true, folderEnterprise.formatJson(), MessageTemplateEnum.levelOneFolderPermissionAdd, folderService.genLevelOneFolderPermissionAddParams(folderEnterprise, sharedToDept, total.get()));
break;
}
}
}
//修改成员权限发送通知
//删除成员权限发送通知
}
} catch (InterruptedException e) {
e.printStackTrace();
}
});
return formatResult(null);
}
public class MultiThread implements Runnable {
public static ThreadPoolExecutor pool = new ThreadPoolExecutor(2, Integer.MAX_VALUE, 5, TimeUnit.MINUTES, new LinkedBlockingQueue<>());
@Override
public void run() {
}
}