|
@@ -1,6 +1,8 @@
|
|
|
package cn.iocoder.yudao.module.pms.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
+import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotInfoSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
|
|
@@ -16,6 +18,7 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -47,14 +50,16 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
@Override
|
|
|
public void createIotInfo(IotInfoSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
|
- if (StringUtils.isBlank(createReqVO.getFilePath())) {
|
|
|
+ if (CollUtil.isEmpty(createReqVO.getFileList())) {
|
|
|
throw exception(IOT_INFO_NOT_EXISTS);
|
|
|
}
|
|
|
- List<IotInfoDO> collect = Arrays.stream(createReqVO.getFilePath().split(",")).map(path -> {
|
|
|
+ List<IotInfoDO> collect = createReqVO.getFileList().stream().map(e -> {
|
|
|
IotInfoDO iotInfo = BeanUtils.toBean(createReqVO, IotInfoDO.class);
|
|
|
- // todo iotInfo.setFilename(StringUtils.substringAfterLast(path, File.separator));
|
|
|
- iotInfo.setFilename(StringUtils.substringAfterLast(path, "/"));
|
|
|
- iotInfo.setFilePath(path);
|
|
|
+ iotInfo.setFilename(StringUtils.substringAfterLast(e.get("url"), "/"));
|
|
|
+ iotInfo.setFilePath(e.get("url"));
|
|
|
+ long size = Long.parseLong(e.get("size"));
|
|
|
+ double mb = size / (1024.0 * 1024.0);
|
|
|
+ iotInfo.setFileSize(String.format("%.2f MB", mb));
|
|
|
iotInfo.setDeleted(false);
|
|
|
return iotInfo;
|
|
|
}).collect(Collectors.toList());
|
|
@@ -69,6 +74,8 @@ public class IotInfoServiceImpl implements IotInfoService {
|
|
|
// 更新
|
|
|
IotInfoDO updateObj = BeanUtils.toBean(updateReqVO, IotInfoDO.class);
|
|
|
updateObj.setFilename(StringUtils.substringAfterLast(updateObj.getFilePath(), "/"));
|
|
|
+ updateObj.setFilePath(updateReqVO.getFilePath());
|
|
|
+ updateObj.setFileSize(String.valueOf(FileUtils.getFileSizeMB(updateReqVO.getFilePath())));
|
|
|
iotInfoMapper.updateById(updateObj);
|
|
|
}
|
|
|
|