|
@@ -1,6 +1,7 @@
|
|
|
package cn.iocoder.yudao.module.pms.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
@@ -12,12 +13,14 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotTreeDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotInfoMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotTreeMapper;
|
|
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -55,45 +58,49 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
private DeptApi deptApi;
|
|
|
@Autowired
|
|
|
private IotTreeMapper iotTreeMapper;
|
|
|
+ @Autowired
|
|
|
+ private IotDeviceMapper iotDeviceMapper;
|
|
|
|
|
|
@Override
|
|
|
public List<IotInfoRespVO> getChildContentFile(Long classId) {
|
|
|
List<IotTreeDO> contents = iotTreeMapper.selectList("parent_id", classId);
|
|
|
List<IotInfoDO> files = iotInfoMapper.selectList("class_id", classId);
|
|
|
+ List<IotInfoRespVO> contentVos = dealFileVo(contents, files);
|
|
|
+ return contentVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<IotInfoRespVO> dealFileVo(List<IotTreeDO> contents, List<IotInfoDO> files){
|
|
|
List<IotInfoRespVO> contentVos = contents.stream().map(e -> {
|
|
|
IotInfoRespVO iotInfoRespVO = new IotInfoRespVO();
|
|
|
iotInfoRespVO.setFilename(e.getName());
|
|
|
iotInfoRespVO.setId(e.getId());
|
|
|
iotInfoRespVO.setFileType("content");//设置为文件夹
|
|
|
-// if (Objects.nonNull(e.get())) {
|
|
|
-// IotDeviceDO iotDevice = iotDeviceService.getIotDevice(e.getDeviceId());
|
|
|
-// if (Objects.nonNull(iotDevice)) {
|
|
|
-// iotInfoRespVO.setDeviceName(iotDevice.getDeviceName());
|
|
|
+// if (Objects.nonNull(e.getDeptId())) {
|
|
|
+// DeptRespDTO dept = deptApi.getDept(e.getDeptId());
|
|
|
+// if (Objects.nonNull(dept)) {
|
|
|
+// iotInfoRespVO.setDeptName(dept.getName());
|
|
|
// }
|
|
|
// }
|
|
|
- if (Objects.nonNull(e.getDeptId())) {
|
|
|
- DeptRespDTO dept = deptApi.getDept(e.getDeptId());
|
|
|
- if (Objects.nonNull(dept)) {
|
|
|
- iotInfoRespVO.setDeptName(dept.getName());
|
|
|
- }
|
|
|
- }
|
|
|
+ iotInfoRespVO.setDeptName(e.getDeptName());
|
|
|
return iotInfoRespVO;
|
|
|
}).collect(Collectors.toList());
|
|
|
List<IotInfoRespVO> fileVos = files.stream().map(e -> {
|
|
|
IotInfoRespVO iotInfoRespVO = new IotInfoRespVO();
|
|
|
BeanUtils.copyProperties(e, iotInfoRespVO);
|
|
|
- if (Objects.nonNull(e.getDeviceId())) {
|
|
|
- IotDeviceDO iotDevice = iotDeviceService.getIotDevice(e.getDeviceId());
|
|
|
- if (Objects.nonNull(iotDevice)) {
|
|
|
- iotInfoRespVO.setDeviceName(iotDevice.getDeviceName());
|
|
|
- }
|
|
|
- }
|
|
|
- if (Objects.nonNull(e.getDeptId())) {
|
|
|
- DeptRespDTO dept = deptApi.getDept(e.getDeptId());
|
|
|
- if (Objects.nonNull(dept)) {
|
|
|
- iotInfoRespVO.setDeptName(dept.getName());
|
|
|
- }
|
|
|
- }
|
|
|
+// if (Objects.nonNull(e.getDeviceId())) {
|
|
|
+// IotDeviceDO iotDevice = iotDeviceService.getIotDevice(e.getDeviceId());
|
|
|
+// if (Objects.nonNull(iotDevice)) {
|
|
|
+// iotInfoRespVO.setDeviceName(iotDevice.getDeviceName());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (Objects.nonNull(e.getDeptId())) {
|
|
|
+// DeptRespDTO dept = deptApi.getDept(e.getDeptId());
|
|
|
+// if (Objects.nonNull(dept)) {
|
|
|
+// iotInfoRespVO.setDeptName(dept.getName());
|
|
|
+// }
|
|
|
+// }
|
|
|
+ iotInfoRespVO.setDeviceCode(e.getDeviceCode());
|
|
|
+ iotInfoRespVO.setDeptName(e.getDeptName());
|
|
|
String docOrPdf = StringUtils.substringAfterLast(iotInfoRespVO.getFilename(), ".");
|
|
|
iotInfoRespVO.setFileClassify(docOrPdf);
|
|
|
iotInfoRespVO.setFileType("file");
|
|
@@ -103,6 +110,20 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
return contentVos;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<IotInfoRespVO> getAllChildContentFile(Long classId) {
|
|
|
+ List<IotTreeDO> contents = iotTreeService.getChildTreeList(ImmutableList.of(classId));
|
|
|
+// if (CollUtil.isNotEmpty(contents)) {
|
|
|
+ List<Long> contentIds = contents.stream().map(IotTreeDO::getId).collect(Collectors.toList());
|
|
|
+ IotInfoPageReqVO infoPageReqVO = new IotInfoPageReqVO();
|
|
|
+ infoPageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ List<IotInfoDO> files = iotInfoMapper.selectPage(infoPageReqVO, contentIds).getList();
|
|
|
+// }
|
|
|
+ List<IotInfoRespVO> infoRespVOS = dealFileVo(contents, files);
|
|
|
+ return infoRespVOS;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void createIotInfo(IotInfoSaveReqVO createReqVO) {
|
|
@@ -110,11 +131,27 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
// if (CollUtil.isEmpty(createReqVO.getFileList())) {
|
|
|
// throw exception(IOT_INFO_NOT_EXISTS);
|
|
|
// }
|
|
|
+ Long deptId;
|
|
|
+ Long deviceId;
|
|
|
Long classId = createReqVO.getClassId();
|
|
|
- IotDeviceDO iotDevice = iotDeviceService.getIotDevice(createReqVO.getDeviceId());
|
|
|
- Long deptId = iotDevice.getDeptId();
|
|
|
+ String deviceCode = "";
|
|
|
+ String deptName = "";
|
|
|
+ if (Objects.nonNull(createReqVO.getDeviceId())) {
|
|
|
+ IotDeviceDO iotDevice = iotDeviceService.getIotDevice(createReqVO.getDeviceId());
|
|
|
+ deptId = iotDevice.getDeptId();
|
|
|
+ deviceCode = iotDevice.getDeviceCode();
|
|
|
+ } else {
|
|
|
+ IotTreeDO iotTreeDO = iotTreeMapper.selectById(createReqVO.getClassId());
|
|
|
+ deptId = iotTreeDO.getDeptId();
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(deptId)) {
|
|
|
+ DeptRespDTO dept = deptApi.getDept(deptId);
|
|
|
+ if (Objects.nonNull(dept)) {
|
|
|
+ deptName = dept.getName();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- importFileTree(createReqVO.getFolderJson(), classId, deptId, iotDevice.getId());
|
|
|
+ importFileTree(createReqVO.getFolderJson(), classId, deptId, createReqVO.getDeviceId(), deviceCode, deptName);
|
|
|
|
|
|
// List<IotInfoDO> collect = createReqVO.getFileList().stream().map(e -> {
|
|
|
// IotInfoDO iotInfo = BeanUtils.toBean(createReqVO, IotInfoDO.class);
|
|
@@ -241,7 +278,7 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
|
|
|
|
|
|
|
|
|
- public void importFileTree(String jsonData, Long parentId, Long deptId, Long deviceId) {
|
|
|
+ public void importFileTree(String jsonData, Long parentId, Long deptId, Long deviceId, String deviceCode, String deptName) {
|
|
|
try {
|
|
|
// 解析JSON数组
|
|
|
JsonNode rootNode = objectMapper.readTree(jsonData);
|
|
@@ -252,13 +289,13 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
JsonNode folderStructureNode = itemNode.get("folderStructure");
|
|
|
Long fileClassId = null;
|
|
|
if (folderStructureNode != null) {
|
|
|
- fileClassId = processFolderStructure(folderStructureNode, parentId, deptId);
|
|
|
+ fileClassId = processFolderStructure(folderStructureNode, parentId, deptId, deviceCode, deptName);
|
|
|
}
|
|
|
|
|
|
// todo 处理文件
|
|
|
JsonNode filesNode = itemNode.get("files");
|
|
|
if (filesNode != null && filesNode.isArray()&&Objects.nonNull(fileClassId)) {
|
|
|
- processFiles(filesNode, parentId, fileClassId, deviceId, deptId);
|
|
|
+ processFiles(filesNode, parentId, fileClassId, deviceId, deptId, deviceCode, deptName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -316,7 +353,7 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
* @param deptId 部门ID
|
|
|
* @return 遇到包含"."的文件夹时返回其parentId,否则返回null
|
|
|
*/
|
|
|
- private Long processFolderStructure(JsonNode folderStructureNode, Long parentId, Long deptId) {
|
|
|
+ private Long processFolderStructure(JsonNode folderStructureNode, Long parentId, Long deptId, String deviceCode, String deptName) {
|
|
|
Iterator<String> fieldNames = folderStructureNode.fieldNames();
|
|
|
|
|
|
while (fieldNames.hasNext()) {
|
|
@@ -342,6 +379,8 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
folder.setDeleted(false);
|
|
|
folder.setType("file");
|
|
|
folder.setDeptId(deptId);
|
|
|
+ folder.setDeviceCode(deviceCode);
|
|
|
+ folder.setDeptName(deptName);
|
|
|
iotTreeMapper.insert(folder);
|
|
|
currentNodeId = folder.getId();
|
|
|
}
|
|
@@ -350,7 +389,7 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
JsonNode childrenNode = folderNode.get("children");
|
|
|
if (childrenNode != null && !childrenNode.isNull() && !childrenNode.isEmpty()) {
|
|
|
// 递归调用,如果子节点处理中返回了parentId,则向上传递
|
|
|
- Long result = processFolderStructure(childrenNode, currentNodeId, deptId);
|
|
|
+ Long result = processFolderStructure(childrenNode, currentNodeId, deptId, deviceCode, deptName);
|
|
|
if (result != null) {
|
|
|
return result; // 子节点处理中遇到了目标,返回结果
|
|
|
}
|
|
@@ -364,7 +403,7 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
/**
|
|
|
* 处理文件
|
|
|
*/
|
|
|
- private void processFiles(JsonNode filesNode, Long rootParentId,Long fileClassId, Long deviceId, Long deptId) {
|
|
|
+ private void processFiles(JsonNode filesNode, Long rootParentId,Long fileClassId, Long deviceId, Long deptId, String deviceCode, String deptName) {
|
|
|
for (JsonNode fileNode : filesNode) {
|
|
|
String path = fileNode.get("path").asText();
|
|
|
String filePath = fileNode.get("filePath").asText();
|
|
@@ -390,6 +429,8 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
info.setClassId(fileClassId);
|
|
|
info.setFilename(fileName);
|
|
|
info.setDeleted(false);
|
|
|
+ info.setDeviceCode(deviceCode);
|
|
|
+ info.setDeptName(deptName);
|
|
|
info.setFileType("file");
|
|
|
if (fileName.contains("jpg")||fileName.contains("jpeg")||fileName.contains("png")||fileName.contains("gif")) {
|
|
|
info.setFileType("pic");
|