|
|
@@ -1,16 +1,20 @@
|
|
|
package com.zhongshu.card.server.core.service.school;
|
|
|
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.github.microservice.models.device.DeviceInfoSyncParam;
|
|
|
import com.zhongshu.card.client.model.school.*;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
import com.zhongshu.card.client.ret.ResultMessage;
|
|
|
import com.zhongshu.card.client.service.school.DeviceInfoService;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.dao.school.AreaDao;
|
|
|
import com.zhongshu.card.server.core.dao.school.DeviceInfoDao;
|
|
|
+import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
import com.zhongshu.card.server.core.domain.school.Area;
|
|
|
import com.zhongshu.card.server.core.domain.school.BookInfo;
|
|
|
import com.zhongshu.card.server.core.domain.school.DeviceInfo;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.service.org.OrganizationServiceImpl;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
@@ -21,6 +25,10 @@ import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* @author TRX
|
|
|
* @date 2024/6/14
|
|
|
@@ -38,6 +46,36 @@ public class DeviceInfoServiceImpl extends SuperService implements DeviceInfoSer
|
|
|
@Autowired
|
|
|
AreaDao areaDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrganizationServiceImpl organizationServiceImpl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步设备 (设备基础信息)
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultContent syncDeviceInfo(DeviceInfoSyncParam param) {
|
|
|
+ Assert.hasText(param.getDeviceId(), "deviceId不能为空");
|
|
|
+ // 设备号
|
|
|
+ String deviceId = param.getDeviceId();
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceInfo)) {
|
|
|
+ } else {
|
|
|
+ deviceInfo = new DeviceInfo();
|
|
|
+ initEntityNoCheckOid(deviceInfo);
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(param, deviceInfo, "id");
|
|
|
+ deviceInfo.setProjectInfoName(organizationServiceImpl.getOrgNameByCode(param.getProjectInfoCode()));
|
|
|
+ deviceInfoDao.save(deviceInfo);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 添加-编辑设备
|
|
|
*
|
|
|
@@ -48,26 +86,14 @@ public class DeviceInfoServiceImpl extends SuperService implements DeviceInfoSer
|
|
|
public ResultContent addDeviceInfo(DeviceInfoParam param) {
|
|
|
initDefaultUserAndOidNoExcept(param);
|
|
|
Assert.hasText(param.getDeviceId(), "deviceId不能为空");
|
|
|
- String oid = param.getOid();
|
|
|
- if(StringUtils.isEmpty(oid)) {
|
|
|
- return ResultContent.buildFail("oid不能为空");
|
|
|
- }
|
|
|
String deviceId = param.getDeviceId();
|
|
|
- DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceIdAndOid(deviceId, oid);
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
if (ObjectUtils.isNotEmpty(deviceInfo)) {
|
|
|
-
|
|
|
} else {
|
|
|
deviceInfo = new DeviceInfo();
|
|
|
}
|
|
|
BeanUtils.copyProperties(param, deviceInfo, "id");
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(param.getAreaId())) {
|
|
|
- Area area = areaDao.findTopById(param.getAreaId());
|
|
|
- if (ObjectUtils.isEmpty(area)) {
|
|
|
- return ResultContent.buildFail(String.format("区域ID不存在:%s", param.getAreaId()));
|
|
|
- }
|
|
|
- deviceInfo.setArea(area);
|
|
|
- }
|
|
|
+ deviceInfo.setProjectInfoName(organizationServiceImpl.getOrgNameByCode(param.getProjectInfoCode()));
|
|
|
deviceInfoDao.save(deviceInfo);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
@@ -118,22 +144,49 @@ public class DeviceInfoServiceImpl extends SuperService implements DeviceInfoSer
|
|
|
return ResultContent.buildSuccess(model);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResultContent<DeviceInfoMoreModel> getDeviceDetailByDeviceId(String deviceId) {
|
|
|
+ DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
|
|
|
+ DeviceInfoMoreModel model = null;
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceInfo)) {
|
|
|
+ model = toMoreModel(deviceInfo);
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultContent<List<DeviceInfoMoreModel>> getDeviceDetailByDeviceIdLike(String deviceId) {
|
|
|
+ List<DeviceInfoMoreModel> models = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotEmpty(deviceId)) {
|
|
|
+ List<DeviceInfo> list = deviceInfoDao.findTop10ByDeviceIdLike(deviceId);
|
|
|
+ if (ObjectUtils.isNotEmpty(list)) {
|
|
|
+ models = list.stream().map(this::toMoreModel).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(models);
|
|
|
+ }
|
|
|
+
|
|
|
public DeviceInfoMoreModel toMoreModel(DeviceInfo entity) {
|
|
|
DeviceInfoMoreModel model = null;
|
|
|
if (ObjectUtils.isEmpty(entity)) {
|
|
|
model = new DeviceInfoMoreModel();
|
|
|
- BeanUtils.copyProperties(entity, model);
|
|
|
- model.setArea(areaService.toModel(entity.getArea()));
|
|
|
+ DeviceInfoModel deviceInfoModel = toModel(entity);
|
|
|
+ BeanUtils.copyProperties(deviceInfoModel, model);
|
|
|
}
|
|
|
return model;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设备基础信息
|
|
|
+ *
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public DeviceInfoModel toModel(DeviceInfo entity) {
|
|
|
DeviceInfoModel model = null;
|
|
|
if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
model = new DeviceInfoModel();
|
|
|
BeanUtils.copyProperties(entity, model);
|
|
|
- model.setArea(areaService.toModel(entity.getArea()));
|
|
|
}
|
|
|
return model;
|
|
|
}
|