|
|
@@ -28,6 +28,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 重写设备equipment 分页同步逻辑
|
|
|
@@ -59,8 +60,8 @@ public class EquipmentSyncService {
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void saveDeviceData(List<DeviceDto> pages, String msgId) {
|
|
|
-
|
|
|
- String key = "base_info_equipment_" + DateUtil.format(new Date(), "yyyy-MM-dd");
|
|
|
+ final String organizationGuid = pages.get(0).getOrganizationGuid();
|
|
|
+ String key = "base_info_equipment_" + DateUtil.format(new Date(), "yyyy-MM-dd") + "_" + organizationGuid;
|
|
|
/**
|
|
|
* 主机可能会在短时间发送两次不同包,但是数据一样的信息过来
|
|
|
* 导致第一次执行正常,第二次执行报错。故添加一个判断限制在10分钟内有多个请求
|
|
|
@@ -80,14 +81,12 @@ public class EquipmentSyncService {
|
|
|
*/
|
|
|
Map<String, Map<String, Object>> orgs = new HashMap<>();
|
|
|
|
|
|
- Map<String, MediatorCategory> categorys = new HashMap<>();
|
|
|
- List<IotDevice> olds = new ArrayList();
|
|
|
- List<IotDevice> list = new ArrayList<>();
|
|
|
- Map<String, List<IotDevice>> rel = analysisDeviceList(pages, orgs, categorys, msgId);
|
|
|
- olds.addAll(rel.get("olds"));
|
|
|
- list.addAll(rel.get("list"));
|
|
|
+ Map<String, List<IotDevice>> rel = analysisDeviceList(pages, orgs, msgId);
|
|
|
+ final List<IotDevice> olds = rel.get("olds");
|
|
|
+ final List<IotDevice> list = rel.get("list");
|
|
|
+ final List<Long> orgIdList = rel.values().stream().flatMap(Collection::stream).map(IotDevice::getOrgId).distinct().collect(Collectors.toList());
|
|
|
//第一步逻辑删除数据,逻辑删除
|
|
|
- this.iIotDeviceService.updateDeviceDeleted();
|
|
|
+ this.iIotDeviceService.updateDeviceDeleted(orgIdList);
|
|
|
|
|
|
|
|
|
//第二步查询数据,如果存在则更新,如果不存在,则新增
|
|
|
@@ -108,7 +107,7 @@ public class EquipmentSyncService {
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- private Map<String, List<IotDevice>> analysisDeviceList(List<DeviceDto> dtos, Map<String, Map<String, Object>> orgs, Map<String, MediatorCategory> categorys, String msgId) {
|
|
|
+ private Map<String, List<IotDevice>> analysisDeviceList(List<DeviceDto> dtos, Map<String, Map<String, Object>> orgs, String msgId) {
|
|
|
Map<String, List<IotDevice>> rel = new HashMap<>();
|
|
|
|
|
|
/**
|
|
|
@@ -189,7 +188,7 @@ public class EquipmentSyncService {
|
|
|
datum.setOrg(theOrg);
|
|
|
}
|
|
|
}
|
|
|
- Map<String, Object> map = resolveDevice(datum, categorys);
|
|
|
+ Map<String, Object> map = resolveDevice(datum);
|
|
|
|
|
|
|
|
|
IotDevice device = (IotDevice) map.get("device");
|
|
|
@@ -214,7 +213,7 @@ public class EquipmentSyncService {
|
|
|
* @param datum
|
|
|
* @return
|
|
|
*/
|
|
|
- private Map<String, Object> resolveDevice(DeviceDto datum, Map<String, MediatorCategory> categorys) {
|
|
|
+ private Map<String, Object> resolveDevice(DeviceDto datum) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
IotDevice device = new IotDevice();
|
|
|
map.put("isOld", 0);
|