|
|
@@ -1,10 +1,16 @@
|
|
|
package com.zhongshu.card.server.core.service.sync;
|
|
|
|
|
|
import com.github.microservice.auth.security.type.AuthType;
|
|
|
+import com.github.microservice.models.project.ProjectSyncParam;
|
|
|
+import com.github.microservice.models.type.CommonState;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
+import com.zhongshu.card.client.utils.type.OrganizationState;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
import com.zhongshu.card.server.core.event.ProjectSyncEvent;
|
|
|
+import com.zhongshu.card.server.core.httpRequest.ApiRequestService;
|
|
|
+import com.zhongshu.card.server.core.httpRequest.apiConf.APIResponseModel;
|
|
|
+import com.zhongshu.card.server.core.httpRequest.conf.IotCenterAPIConfig;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
@@ -31,10 +37,13 @@ public class ProjectSyncIotCenterService {
|
|
|
@Autowired
|
|
|
ApplicationContext applicationContext;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ApiRequestService apiRequestService;
|
|
|
+
|
|
|
public ResultContent noticeSyncProjects(List<Organization> list) {
|
|
|
if (ObjectUtils.isNotEmpty(list)) {
|
|
|
- List<String> projectIds = list.stream().map(it -> it.getOid()).collect(Collectors.toList());
|
|
|
- ProjectSyncEvent event = new ProjectSyncEvent(this, projectIds);
|
|
|
+ List<String> projectOIds = list.stream().map(it -> it.getOid()).collect(Collectors.toList());
|
|
|
+ ProjectSyncEvent event = new ProjectSyncEvent(this, projectOIds);
|
|
|
applicationContext.publishEvent(event);
|
|
|
}
|
|
|
return ResultContent.buildSuccess();
|
|
|
@@ -42,8 +51,8 @@ public class ProjectSyncIotCenterService {
|
|
|
|
|
|
public ResultContent noticeSyncProject(Organization organization) {
|
|
|
if (ObjectUtils.isNotEmpty(organization) && organization.getAuthType() == AuthType.Project) {
|
|
|
- List<String> projectIds = List.of(organization.getOid());
|
|
|
- ProjectSyncEvent event = new ProjectSyncEvent(this, projectIds);
|
|
|
+ List<String> projectOIds = List.of(organization.getOid());
|
|
|
+ ProjectSyncEvent event = new ProjectSyncEvent(this, projectOIds);
|
|
|
applicationContext.publishEvent(event);
|
|
|
}
|
|
|
return ResultContent.buildSuccess();
|
|
|
@@ -53,6 +62,31 @@ public class ProjectSyncIotCenterService {
|
|
|
@Async
|
|
|
@SneakyThrows
|
|
|
public void syncProjectInfo(ProjectSyncEvent event) {
|
|
|
-
|
|
|
+ List<String> projectOIds = event.getProjectOIds();
|
|
|
+ log.info("syncProjectInfo: {}", projectOIds.size());
|
|
|
+ if (ObjectUtils.isNotEmpty(projectOIds)) {
|
|
|
+ List<Organization> organizations = organizationDao.findByOidIn(projectOIds);
|
|
|
+ List<ProjectSyncParam.ProjectSyncInfo> list = organizations.stream().map(it -> {
|
|
|
+ ProjectSyncParam.ProjectSyncInfo info = new ProjectSyncParam.ProjectSyncInfo();
|
|
|
+ info.setCode(it.getCode());
|
|
|
+ info.setName(it.getName());
|
|
|
+ OrganizationState state = it.getState();
|
|
|
+ if (state == OrganizationState.Normal) {
|
|
|
+ info.setState(CommonState.Enable);
|
|
|
+ } else {
|
|
|
+ info.setState(CommonState.Disable);
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ ProjectSyncParam param = new ProjectSyncParam();
|
|
|
+ param.setList(list);
|
|
|
+ // 请求iot平台
|
|
|
+ APIResponseModel api = apiRequestService.sendIotCenterAPI(IotCenterAPIConfig.syncFromFullCardProjects, param);
|
|
|
+ if (api.isSuccess()) {
|
|
|
+ log.info("同步项目成功");
|
|
|
+ } else {
|
|
|
+ log.error("同步项目失败:{}", api.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|