|
@@ -1,13 +1,27 @@
|
|
|
package com.zhongshu.card.server.core.service.sync;
|
|
package com.zhongshu.card.server.core.service.sync;
|
|
|
|
|
|
|
|
|
|
+import com.github.microservice.models.device.DeviceInfoSyncParam;
|
|
|
import com.github.microservice.models.device.DeviceSyncListParam;
|
|
import com.github.microservice.models.device.DeviceSyncListParam;
|
|
|
|
|
+import com.zhongshu.card.client.model.school.DeviceInfoParam;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
import com.zhongshu.card.client.service.school.DeviceInfoService;
|
|
import com.zhongshu.card.client.service.school.DeviceInfoService;
|
|
|
|
|
+import com.zhongshu.card.client.utils.type.LogsLevel;
|
|
|
|
|
+import com.zhongshu.card.client.utils.type.OrganizationRelationType;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationRelationDao;
|
|
|
|
|
+import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
|
|
+import com.zhongshu.card.server.core.domain.org.OrganizationRelation;
|
|
|
|
|
+import com.zhongshu.card.server.core.service.user.OperationLogsService;
|
|
|
|
|
+import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
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.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @author TRX
|
|
* @author TRX
|
|
|
* @date 2024/6/27
|
|
* @date 2024/6/27
|
|
@@ -22,6 +36,12 @@ public class DeviceSyncFromIotService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
OrganizationDao organizationDao;
|
|
OrganizationDao organizationDao;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ OrganizationRelationDao organizationRelationDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ OperationLogsService operationLogsService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 物联网同步设备
|
|
* 物联网同步设备
|
|
|
*
|
|
*
|
|
@@ -29,7 +49,45 @@ public class DeviceSyncFromIotService {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public ResultContent syncFromIotDevices(DeviceSyncListParam param) {
|
|
public ResultContent syncFromIotDevices(DeviceSyncListParam param) {
|
|
|
|
|
+ log.info("syncFromIotDevices");
|
|
|
|
|
+ List<DeviceInfoSyncParam> list = param.getList();
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
|
|
+ for (DeviceInfoSyncParam deviceInfoSyncParam : list) {
|
|
|
|
|
+ String projectInfoCode = deviceInfoSyncParam.getProjectInfoCode();
|
|
|
|
|
+ List<OrganizationRelation> organizationRelations = new ArrayList<>();
|
|
|
|
|
+ // 查询学校绑定的项目
|
|
|
|
|
+ if (StringUtils.isNotEmpty(projectInfoCode)) {
|
|
|
|
|
+ Organization project = organizationDao.findTopByCode(projectInfoCode);
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(project)) {
|
|
|
|
|
+ organizationRelations =
|
|
|
|
|
+ organizationRelationDao.findByRelOrganizationAndRelationType(project, OrganizationRelationType.SchoolToProject);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(organizationRelations)) {
|
|
|
|
|
+ for (OrganizationRelation relation : organizationRelations) {
|
|
|
|
|
+ // 没有关联的学校信息
|
|
|
|
|
+ DeviceInfoParam deviceInfoParam = new DeviceInfoParam();
|
|
|
|
|
+ BeanUtils.copyProperties(deviceInfoSyncParam, deviceInfoParam);
|
|
|
|
|
+ // 设置学校的Oid
|
|
|
|
|
+ deviceInfoParam.setOid(relation.getMainOrganization().getOid());
|
|
|
|
|
+ ResultContent resultContent = deviceInfoService.addDeviceInfo(deviceInfoParam);
|
|
|
|
|
+ if (resultContent.isSuccess()) {
|
|
|
|
|
+ operationLogsService.addLogs("", LogsLevel.Middle);
|
|
|
|
|
+ } else {
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 没有关联的学校信息
|
|
|
|
|
+ DeviceInfoParam deviceInfoParam = new DeviceInfoParam();
|
|
|
|
|
+ BeanUtils.copyProperties(deviceInfoSyncParam, deviceInfoParam);
|
|
|
|
|
+ ResultContent content = deviceInfoService.addDeviceInfo(deviceInfoParam);
|
|
|
|
|
+ if (content.isFailed()) {
|
|
|
|
|
+ log.error("同步设备出错: {}", content.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|
|
|
|
|
|