Commit d29fc189 by huangjy

Merge remote-tracking branch 'origin/dev' into dev

parents 89cc73e3 b1a0a64a
...@@ -123,4 +123,11 @@ public class PlatSpaceController { ...@@ -123,4 +123,11 @@ public class PlatSpaceController {
return ApiResponseUtils.success(data); return ApiResponseUtils.success(data);
} }
@ApiOperation("修复空间层级数据")
@GetMapping("fixPlacePath")
public ApiResponseEntity<String> fixPlacePath(@RequestParam String spaceId) {
spaceService.fixPlacePath(spaceId);
return ApiResponseUtils.success();
}
} }
...@@ -3,6 +3,7 @@ package com.makeit.service.platform.device.impl; ...@@ -3,6 +3,7 @@ package com.makeit.service.platform.device.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -682,21 +683,34 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev ...@@ -682,21 +683,34 @@ public class PlatDeviceServiceImpl extends ServiceImpl<PlatDeviceMapper, PlatDev
String deviceId = dto.getDeviceId(); String deviceId = dto.getDeviceId();
UserServerInfo usrServerInfo = dto.getUsrServerInfo(); UserServerInfo usrServerInfo = dto.getUsrServerInfo();
log.info("写入设备属性请求参数:{}",JSON.toJSONString(dto)); log.info("写入设备属性请求参数:{}",JSON.toJSONString(dto));
String value = JSON.toJSONString(usrServerInfo);
boolean needWrite = true;
List<PlatDeviceOther> platDeviceOtherList = platDeviceOtherService.list(new QueryWrapper<PlatDeviceOther>().lambda()
.eq(PlatDeviceOther::getOriDeviceId, deviceId));
if (CollectionUtils.isNotEmpty(platDeviceOtherList)) {
PlatDeviceOther platDeviceOther = platDeviceOtherList.get(0);
UserServerInfo existInfo = new UserServerInfo();
existInfo.setAddr(platDeviceOther.getProtocolAddress());
existInfo.setPort(platDeviceOther.getProtocolPort() != null ? Integer.valueOf(platDeviceOther.getProtocolPort()) : null);
existInfo.setUsername(platDeviceOther.getProtocolAccount());
existInfo.setPassword(platDeviceOther.getProtocolPassword());
String jsonString = JSON.toJSONString(existInfo);
needWrite = !value.equals(jsonString);
}
if (needWrite) {
ThreadUtil.sleep(200); // 受限于设备不支持同时写入 稍微延迟一点执行(前端先修改属性再修改网络信息)
Map<String, Object> map = Maps.newHashMap(); Map<String, Object> map = Maps.newHashMap();
map.put("usrServerInfo",JSON.toJSONString(usrServerInfo)); map.put("usrServerInfo", value);
/* String result = devicePropertiesOperateService.deviceWriteAttr(deviceId, map); String result = devicePropertiesOperateService.deviceWriteAttr(deviceId, map);
if (StringUtils.isNotEmpty(result)) { if (StringUtils.isNotEmpty(result)) {
throw new RuntimeException("设备写入失败:" + result); throw new RuntimeException("设备写入失败:" + result);
}*/ }
List<PlatDeviceOther> platDeviceOtherList = platDeviceOtherService.list(new QueryWrapper<PlatDeviceOther>().lambda() }
.eq(PlatDeviceOther::getOriDeviceId, deviceId));
for (PlatDeviceOther platDeviceOther : platDeviceOtherList) { for (PlatDeviceOther platDeviceOther : platDeviceOtherList) {
platDeviceOther.setProtocolAccount(usrServerInfo.getUsername()); platDeviceOther.setProtocolAccount(usrServerInfo.getUsername());
platDeviceOther.setProtocolPassword(usrServerInfo.getPassword()); platDeviceOther.setProtocolPassword(usrServerInfo.getPassword());
platDeviceOther.setProtocolAddress(usrServerInfo.getAddr()); platDeviceOther.setProtocolAddress(usrServerInfo.getAddr());
platDeviceOther.setProtocolPort(usrServerInfo.getPort() == null ? "" : usrServerInfo.getPort().toString()); platDeviceOther.setProtocolPort(usrServerInfo.getPort() == null ? "" : usrServerInfo.getPort().toString());
platDeviceOther.setSecureId(usrServerInfo.getSecureId());
platDeviceOther.setSecureKey(usrServerInfo.getSecureKey());
platDeviceOtherService.updateById(platDeviceOther); platDeviceOtherService.updateById(platDeviceOther);
} }
} }
......
...@@ -96,4 +96,6 @@ public interface PlatSpaceService extends IService<PlatSpace> { ...@@ -96,4 +96,6 @@ public interface PlatSpaceService extends IService<PlatSpace> {
List<PlatSpace> listChildAndOrgIds(List<String> spaceIds, List<String> orgIds); List<PlatSpace> listChildAndOrgIds(List<String> spaceIds, List<String> orgIds);
void fixPlacePath(String spaceId);
} }
...@@ -70,7 +70,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace ...@@ -70,7 +70,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
private void check(PlatSpaceAddDTO dto) { private void check(PlatSpaceAddDTO dto) {
if (StrUtil.isNotBlank(dto.getParentPath()) if (StrUtil.isNotBlank(dto.getParentPath())
&& dto.getParentPath().split(",").length >= 4) { && dto.getParentPath().split(",").length > 4) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL); throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL);
} }
...@@ -224,8 +224,8 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace ...@@ -224,8 +224,8 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
private void checkAndUpdateSonSpace(PlatSpace space) { private void checkAndUpdateSonSpace(PlatSpace space) {
String parentPath = space.getParentPath(); String parentPath = space.getParentPath();
int level = StrUtil.isBlank(parentPath) ? 0 : parentPath.split(",").length; int level = StrUtil.isBlank(parentPath) ? 1 : parentPath.split(",").length + 1;
if (level > 3) { if (level > 4) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL); throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL);
} }
String spaceId = space.getId(); String spaceId = space.getId();
...@@ -238,16 +238,14 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace ...@@ -238,16 +238,14 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
if (StrUtil.isBlank(s.getParentPath())) { if (StrUtil.isBlank(s.getParentPath())) {
return; return;
} }
List<String> parentSpaceIds = Lists.newArrayList(s.getParentPath().split(",")); int maxSpacePath = getMaxSpacePath(s.getParentPath(), spaceId);
parentSpaceIds.remove(space.getId()); if (maxSpacePath > maxLength.get()) {
if (parentSpaceIds.size() > maxLength.get()) { maxLength.set(maxSpacePath);
maxLength.set(parentSpaceIds.size());
} }
maxLength.set(parentSpaceIds.size());
}); });
sonLevel = maxLength.get(); sonLevel = maxLength.get();
} }
if (level + sonLevel > 3) { if (level + sonLevel > 4) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL); throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_OVER_LEVEL);
} }
// 更新下级空间的parentPath // 更新下级空间的parentPath
...@@ -268,6 +266,12 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace ...@@ -268,6 +266,12 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
} }
private Integer getMaxSpacePath(String path, String splitSpace) {
List<String> pathList = Arrays.asList(path.split(","));
return pathList.size() - pathList.indexOf(splitSpace);
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void del(String id) { public void del(String id) {
...@@ -1093,7 +1097,48 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace ...@@ -1093,7 +1097,48 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
return data; return data;
} }
@Override
public void fixPlacePath(String spaceId) {
PlatSpace space = getById(spaceId);
if (space == null || StrUtil.isNotBlank(space.getParentId())) {
return;
}
List<PlatSpace> allList = new ArrayList<>();
recursionSetParentPath(spaceId, space.getParentPath(), allList);
if (CollUtil.isNotEmpty(allList)) {
updateBatchById(allList);
}
// fixAllSpacePath();
}
private void fixAllSpacePath() {
List<PlatSpace> allData = list();
List<PlatSpace> firstSpaceList = allData.stream().filter(f -> StrUtil.isBlank(f.getParentId())
&& StrUtil.isBlank(f.getParentPath())).collect(Collectors.toList());
if (CollUtil.isEmpty(firstSpaceList)) {
return;
}
firstSpaceList.forEach(f -> {
List<PlatSpace> allList = new ArrayList<>();
recursionSetParentPath(f.getId(), f.getParentPath(), allList);
if (CollUtil.isNotEmpty(allList)) {
updateBatchById(allList);
}
});
}
private void recursionSetParentPath(String spaceId, String parentPath, List<PlatSpace> allList) {
List<PlatSpace> firstSonList = list(Wrappers.<PlatSpace>lambdaQuery().eq(PlatSpace::getParentId, spaceId));
if (CollUtil.isEmpty(firstSonList)) {
return;
}
firstSonList.forEach(s -> {
s.setParentPath(StrUtil.isNotBlank(parentPath) ? parentPath + "," + s.getParentId() : spaceId);
allList.add(s);
recursionSetParentPath(s.getId(), s.getParentPath(), allList);
});
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment