|
|
@@ -1,6 +1,7 @@
|
|
|
package com.zhongshu.card.server.core.service.devices;
|
|
|
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.github.microservice.core.util.os.SystemUtil;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.net.ResultMessage;
|
|
|
import com.google.common.collect.Lists;
|
|
|
@@ -31,6 +32,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
@@ -39,6 +41,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -70,16 +74,20 @@ public class DevicePermissService extends SuperService {
|
|
|
private OrganizationUserDao organizationUserDao;
|
|
|
|
|
|
@Autowired
|
|
|
- private OrgUserFaceService orgUserFaceService;
|
|
|
+ private DevicePermissEventService devicePermissEventService;
|
|
|
|
|
|
@Autowired
|
|
|
- private CardInfoServiceImpl cardInfoService;
|
|
|
+ private DevicePermissIotService devicePermissIotService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private DevicePermissEventService devicePermissEventService;
|
|
|
+ //线程池
|
|
|
+ private ExecutorService executorService = Executors.newFixedThreadPool(SystemUtil.getCpuCoreCount() * 2);
|
|
|
|
|
|
@Autowired
|
|
|
- private DevicePermissIotService devicePermissIotService;
|
|
|
+ private void init(ApplicationContext applicationContext) {
|
|
|
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
+ executorService.shutdownNow();
|
|
|
+ }));
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 设备绑定用户
|
|
|
@@ -174,30 +182,35 @@ public class DevicePermissService extends SuperService {
|
|
|
@Async
|
|
|
@SneakyThrows
|
|
|
public void syncOrgUserChangeInfo(OrgUserBindUpdateSyncEvent event) {
|
|
|
- log.info("机构用户信息发生变化 syncOrgUserChangeInfo...");
|
|
|
- DataOperationType dataOperationType = event.getDataOperationType();
|
|
|
- List<String> organizationUserIds = event.getOrganizationUserIds();
|
|
|
- if (dataOperationType != null) {
|
|
|
- List<OrganizationUser> organizationUsers = organizationUserDao.findByIdIn(organizationUserIds);
|
|
|
- if (ObjectUtils.isNotEmpty(organizationUsers)) {
|
|
|
- List<DevicePermiss> list = devicePermissDao.findByOrganizationUserIn(organizationUsers);
|
|
|
- if (ObjectUtils.isEmpty(list)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (dataOperationType == DataOperationType.Update) {
|
|
|
- for (DevicePermiss permiss : list) {
|
|
|
- buildOrgUserInfo(permiss, permiss.getOrganizationUser());
|
|
|
+ executorService.execute(() -> {
|
|
|
+ log.info("机构用户信息发生变化 syncOrgUserChangeInfo...");
|
|
|
+ DataOperationType dataOperationType = event.getDataOperationType();
|
|
|
+ List<String> organizationUserIds = event.getOrganizationUserIds();
|
|
|
+ if (dataOperationType != null) {
|
|
|
+ List<OrganizationUser> organizationUsers = organizationUserDao.findByIdIn(organizationUserIds);
|
|
|
+ if (ObjectUtils.isNotEmpty(organizationUsers)) {
|
|
|
+ List<DevicePermiss> list = devicePermissDao.findByOrganizationUserIn(organizationUsers);
|
|
|
+ if (ObjectUtils.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String projectOid = organizationUsers.get(0).getProjectOid();
|
|
|
+ if (dataOperationType == DataOperationType.Update) {
|
|
|
+ for (DevicePermiss permiss : list) {
|
|
|
+ buildOrgUserInfo(permiss, permiss.getOrganizationUser());
|
|
|
+ }
|
|
|
+ devicePermissDao.saveAll(list);
|
|
|
+ // 通知权限下发用户信息 编辑
|
|
|
+ List<String> userIds = organizationUsers.stream().map(OrganizationUser::getUserId).distinct().collect(Collectors.toList());
|
|
|
+ devicePermissEventService.sendUserInfoChangeEvent(userIds, projectOid);
|
|
|
+ } else if (dataOperationType == DataOperationType.Delete) {
|
|
|
+ // 下发移除权限
|
|
|
+ devicePermissIotService.changeDeviceUser(list, 0);
|
|
|
+ // 删除
|
|
|
+ devicePermissDao.deleteAll(list);
|
|
|
}
|
|
|
- devicePermissDao.saveAll(list);
|
|
|
- } else if (dataOperationType == DataOperationType.Delete) {
|
|
|
- devicePermissDao.deleteAll(list);
|
|
|
}
|
|
|
- // 通知权限下发
|
|
|
- String projectOid = list.get(0).getProjectOid();
|
|
|
- List<String> deviceIds = list.stream().map(it -> it.getDeviceId()).collect(Collectors.toUnmodifiableList());
|
|
|
- devicePermissEventService.sendDeviceChangeEvent(deviceIds, projectOid);
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
|