TRX 1 tahun lalu
induk
melakukan
88b06c1789

+ 39 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DevicePermissEventService.java

@@ -55,6 +55,9 @@ public class DevicePermissEventService {
     @Autowired
     private DevicePermissService devicePermissService;
 
+    @Autowired
+    private ApplicationContext applicationContext;
+
     @Autowired
     private void init(ApplicationContext applicationContext) {
         Runtime.getRuntime().addShutdownHook(new Thread(() -> {
@@ -62,6 +65,42 @@ public class DevicePermissEventService {
         }));
     }
 
+    /**
+     * 通知用户关联信息发送变化
+     *
+     * @param userId
+     * @param projectOid
+     */
+    public void sendUserInfoChangeEvent(String userId, String projectOid) {
+        UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
+                List.of(userId), projectOid);
+        applicationContext.publishEvent(event);
+    }
+
+    /**
+     * 通知用户关联信息发送变化
+     *
+     * @param userIds
+     * @param projectOid
+     */
+    public void sendUserInfoChangeEvent(List<String> userIds, String projectOid) {
+        UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
+                userIds, projectOid);
+        applicationContext.publishEvent(event);
+    }
+
+    /**
+     * 设备信息发送变化
+     *
+     * @param deviceIds
+     * @param projectOid
+     */
+    public void sendDeviceChangeEvent(List<String> deviceIds, String projectOid) {
+        DevicePermissChangeEvent event = new DevicePermissChangeEvent(this,
+                deviceIds, projectOid);
+        applicationContext.publishEvent(event);
+    }
+
     @EventListener(classes = DevicePermissChangeEvent.class)
     @SneakyThrows
     public void devicePermissChange(DevicePermissChangeEvent event) {

+ 10 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DevicePermissService.java

@@ -88,6 +88,9 @@ public class DevicePermissService extends SuperService {
     @Autowired
     private CardInfoServiceImpl cardInfoService;
 
+    @Autowired
+    private DevicePermissEventService devicePermissEventService;
+
     /**
      * 设备绑定用户
      *
@@ -187,6 +190,9 @@ public class DevicePermissService extends SuperService {
             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());
@@ -195,6 +201,10 @@ public class DevicePermissService extends SuperService {
                 } 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);
             }
         }
     }

+ 11 - 26
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/projectAbout/CardInfoServiceImpl.java

@@ -30,9 +30,9 @@ import com.zhongshu.card.server.core.domain.org.UserAccount;
 import com.zhongshu.card.server.core.domain.school.CardInfo;
 import com.zhongshu.card.server.core.domain.school.CardInfoLossRecord;
 import com.zhongshu.card.server.core.domain.school.CardInfoPool;
-import com.zhongshu.card.server.core.event.DevicePermissChangeEvent;
 import com.zhongshu.card.server.core.event.UserInfoChangeSyncEvent;
 import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.service.devices.DevicePermissEventService;
 import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
 import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
 import com.zhongshu.card.server.core.service.orgManager.OrganizationManagerServiceImpl;
@@ -111,6 +111,9 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
     @Autowired
     ApplicationContext applicationContext;
 
+    @Autowired
+    private DevicePermissEventService devicePermissEventService;
+
     /**
      * 添加或修改卡片信息
      *
@@ -271,9 +274,7 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
         cardInfoPoolDao.save(cardInfoPool);
 
         // 用户卡片增多
-        UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
-                List.of(cardInfo.getUserId()), cardInfo.getProjectOid());
-        applicationContext.publishEvent(event);
+        devicePermissEventService.sendUserInfoChangeEvent(cardInfo.getUserId(), cardInfo.getProjectOid());
         return ResultContent.buildSuccess();
     }
 
@@ -302,9 +303,7 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
         }
 
         // 用户可用卡片减少
-        UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
-                List.of(cardInfo.getUserId()), cardInfo.getProjectOid());
-        applicationContext.publishEvent(event);
+        devicePermissEventService.sendUserInfoChangeEvent(cardInfo.getUserId(), cardInfo.getProjectOid());
         return ResultContent.buildSuccess();
     }
 
@@ -472,9 +471,7 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
         cardInfoLossRecordDao.save(cardInfoLossRecord);
 
         // 卡片信息发送变化
-        UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
-                List.of(cardInfo.getUserId()), cardInfo.getProjectOid());
-        applicationContext.publishEvent(event);
+        devicePermissEventService.sendUserInfoChangeEvent(cardInfo.getUserId(), cardInfo.getProjectOid());
         return ResultContent.buildSuccess();
     }
 
@@ -510,9 +507,7 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
         cardInfoLossRecord.setOperationType(CardOperationType.Enable);
         cardInfoLossRecordDao.save(cardInfoLossRecord);
         // 卡片信息发送变化
-        UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
-                List.of(cardInfo.getUserId()), cardInfo.getProjectOid());
-        applicationContext.publishEvent(event);
+        devicePermissEventService.sendUserInfoChangeEvent(cardInfo.getUserId(), cardInfo.getProjectOid());
         return ResultContent.buildSuccess();
     }
 
@@ -575,9 +570,7 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
         cardInfoLossRecordDao.save(cardInfoLossRecord);
 
         // 用户可用卡片发生变化
-        UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
-                List.of(cardInfo.getUserId()), cardInfo.getProjectOid());
-        applicationContext.publishEvent(event);
+        devicePermissEventService.sendUserInfoChangeEvent(cardInfo.getUserId(), cardInfo.getProjectOid());
         return ResultContent.buildSuccess();
     }
 
@@ -687,9 +680,7 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
         cardInfoLossRecord.setOperationType(CardOperationType.Enable);
         cardInfoLossRecordDao.save(cardInfoLossRecord);
 
-        UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
-                List.of(cardInfo.getUserId()), cardInfo.getProjectOid());
-        applicationContext.publishEvent(event);
+        devicePermissEventService.sendUserInfoChangeEvent(cardInfo.getUserId(), cardInfo.getProjectOid());
         return ResultContent.buildSuccess();
     }
 
@@ -840,9 +831,7 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
                         bindCardFromPoolByOrgId(bind2OrgUserParam.getPoolId(), bind2OrgUserParam.getId(), bind2OrgUserParam.getRemark());
                     }
 
-                    UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
-                            userIds, projectOid);
-                    applicationContext.publishEvent(event);
+                    devicePermissEventService.sendUserInfoChangeEvent(userIds, projectOid);
                 }
                 model.setSuccess(cardInfoPools.size());
                 model.setFailDetails(failDetails);
@@ -958,10 +947,6 @@ public class CardInfoServiceImpl extends SuperService implements CardInfoService
         ExcelUtils.commonExecuteExcel(request, response, execlParam);
     }
 
-    public void sendUserInfoChangeEvent(){
-
-    }
-
     //----------------------------园区卡片操作 end --------------------------
 
     // 简单的信息

+ 5 - 3
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/projectAbout/OrgUserFaceService.java

@@ -8,6 +8,7 @@ import com.zhongshu.card.server.core.dao.projectAbout.OrgUserFaceDao;
 import com.zhongshu.card.server.core.domain.projectAbout.OrgUserFace;
 import com.zhongshu.card.server.core.event.UserInfoChangeSyncEvent;
 import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.service.devices.DevicePermissEventService;
 import com.zhongshu.card.server.core.util.BeanUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
@@ -37,6 +38,9 @@ public class OrgUserFaceService extends SuperService {
     @Autowired
     private ApplicationContext applicationContext;
 
+    @Autowired
+    private DevicePermissEventService devicePermissEventService;
+
     /**
      * 保存用户人脸信息
      *
@@ -67,9 +71,7 @@ public class OrgUserFaceService extends SuperService {
         orgUserFaceDao.save(orgUserFace);
 
         // 通知人脸信息发送变化
-        UserInfoChangeSyncEvent event = new UserInfoChangeSyncEvent(this,
-                List.of(orgUserFace.getUserId()), orgUserFace.getProjectOid());
-        applicationContext.publishEvent(event);
+        devicePermissEventService.sendUserInfoChangeEvent(orgUserFace.getUserId(), orgUserFace.getProjectOid());
         return ResultContent.buildSuccess();
     }