|
@@ -1,17 +1,23 @@
|
|
|
package com.taais.biz.service.impl;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.mybatisflex.core.paginate.Page;
|
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
|
+import com.taais.common.core.config.TaaisConfig;
|
|
|
+import com.taais.common.core.constant.Constants;
|
|
|
import com.taais.common.core.utils.MapstructUtils;
|
|
|
import com.taais.common.core.utils.StringUtils;
|
|
|
import com.taais.common.orm.core.page.PageQuery;
|
|
|
import com.taais.common.core.core.page.PageResult;
|
|
|
import com.taais.common.orm.core.service.impl.BaseServiceImpl;
|
|
|
+import com.taais.system.domain.vo.SysOssVo;
|
|
|
+import com.taais.system.service.ISysOssService;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import com.taais.biz.mapper.DataSeqMapper;
|
|
@@ -19,7 +25,9 @@ import com.taais.biz.domain.DataSeq;
|
|
|
import com.taais.biz.domain.bo.DataSeqBo;
|
|
|
import com.taais.biz.domain.vo.DataSeqVo;
|
|
|
import com.taais.biz.service.IDataSeqService;
|
|
|
+
|
|
|
import static com.taais.biz.domain.table.DataSeqTableDef.DATA_SEQ;
|
|
|
+import static com.taais.biz.utils.ZipUtils.unzip;
|
|
|
|
|
|
/**
|
|
|
* 数据管理Service业务层处理
|
|
@@ -29,6 +37,8 @@ import static com.taais.biz.domain.table.DataSeqTableDef.DATA_SEQ;
|
|
|
*/
|
|
|
@Service
|
|
|
public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq> implements IDataSeqService {
|
|
|
+ @Autowired
|
|
|
+ private ISysOssService ossService;
|
|
|
@Resource
|
|
|
private DataSeqMapper dataSeqMapper;
|
|
|
|
|
@@ -40,31 +50,33 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
|
|
|
private QueryWrapper buildQueryWrapper(DataSeqBo dataSeqBo) {
|
|
|
QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
|
|
|
queryWrapper.and(DATA_SEQ.NAME.like
|
|
|
- (dataSeqBo.getName()));
|
|
|
+ (dataSeqBo.getName()));
|
|
|
queryWrapper.and(DATA_SEQ.DATA_TYPE.eq
|
|
|
- (dataSeqBo.getDataType()));
|
|
|
+ (dataSeqBo.getDataType()));
|
|
|
queryWrapper.and(DATA_SEQ.FILE_TYPE.eq
|
|
|
- (dataSeqBo.getFileType()));
|
|
|
+ (dataSeqBo.getFileType()));
|
|
|
queryWrapper.and(DATA_SEQ.OBJECT_TYPE.eq
|
|
|
- (dataSeqBo.getObjectType()));
|
|
|
+ (dataSeqBo.getObjectType()));
|
|
|
queryWrapper.and(DATA_SEQ.OBJECT_SUBTYPE.eq
|
|
|
- (dataSeqBo.getObjectSubtype()));
|
|
|
+ (dataSeqBo.getObjectSubtype()));
|
|
|
queryWrapper.and(DATA_SEQ.BATCH_NUM.eq
|
|
|
- (dataSeqBo.getBatchNum()));
|
|
|
+ (dataSeqBo.getBatchNum()));
|
|
|
queryWrapper.and(DATA_SEQ.SCENE.eq
|
|
|
- (dataSeqBo.getScene()));
|
|
|
+ (dataSeqBo.getScene()));
|
|
|
queryWrapper.and(DATA_SEQ.DATA_SOURCE.eq
|
|
|
- (dataSeqBo.getDataSource()));
|
|
|
+ (dataSeqBo.getDataSource()));
|
|
|
queryWrapper.and(DATA_SEQ.GATHER_TIME.eq
|
|
|
- (dataSeqBo.getGatherTime()));
|
|
|
+ (dataSeqBo.getGatherTime()));
|
|
|
queryWrapper.and(DATA_SEQ.GATHER_SPOT.eq
|
|
|
- (dataSeqBo.getGatherSpot()));
|
|
|
+ (dataSeqBo.getGatherSpot()));
|
|
|
queryWrapper.and(DATA_SEQ.URL.eq
|
|
|
- (dataSeqBo.getUrl()));
|
|
|
+ (dataSeqBo.getUrl()));
|
|
|
queryWrapper.and(DATA_SEQ.LOG.eq
|
|
|
- (dataSeqBo.getLog()));
|
|
|
+ (dataSeqBo.getLog()));
|
|
|
queryWrapper.and(DATA_SEQ.REMARKS.eq
|
|
|
- (dataSeqBo.getRemarks()));
|
|
|
+ (dataSeqBo.getRemarks()));
|
|
|
+ queryWrapper.and(DATA_SEQ.SUBSYSTEM.eq
|
|
|
+ (dataSeqBo.getSubsystem()));
|
|
|
|
|
|
return queryWrapper;
|
|
|
}
|
|
@@ -77,7 +89,7 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
|
|
|
*/
|
|
|
@Override
|
|
|
public DataSeqVo selectById(Long id) {
|
|
|
- return this.getOneAs(query().where(DATA_SEQ.ID.eq(id)), DataSeqVo.class);
|
|
|
+ return this.getOneAs(query().where(DATA_SEQ.ID.eq(id)), DataSeqVo.class);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -90,7 +102,7 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
|
|
|
@Override
|
|
|
public List<DataSeqVo> selectList(DataSeqBo dataSeqBo) {
|
|
|
QueryWrapper queryWrapper = buildQueryWrapper(dataSeqBo);
|
|
|
- return this.listAs(queryWrapper, DataSeqVo.class);
|
|
|
+ return this.listAs(queryWrapper, DataSeqVo.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -102,7 +114,7 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
|
|
|
@Override
|
|
|
public PageResult<DataSeqVo> selectPage(DataSeqBo dataSeqBo) {
|
|
|
QueryWrapper queryWrapper = buildQueryWrapper(dataSeqBo);
|
|
|
- Page<DataSeqVo> page = this.pageAs(PageQuery.build(), queryWrapper, DataSeqVo.class);
|
|
|
+ Page<DataSeqVo> page = this.pageAs(PageQuery.build(), queryWrapper, DataSeqVo.class);
|
|
|
return PageResult.build(page);
|
|
|
}
|
|
|
|
|
@@ -114,9 +126,28 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean insert(DataSeqBo dataSeqBo) {
|
|
|
- DataSeq dataSeq =MapstructUtils.convert(dataSeqBo, DataSeq. class);
|
|
|
+ // 检查input_oss_id是否存在
|
|
|
+ if (ObjectUtil.isNull(dataSeqBo.getInputOssId())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ SysOssVo ossEntity = ossService.getById(dataSeqBo.getInputOssId());
|
|
|
+ if (ObjectUtil.isNull(ossEntity)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ DataSeq dataSeq = MapstructUtils.convert(dataSeqBo, DataSeq.class);
|
|
|
+
|
|
|
+ String filePath = ossEntity.getFileName();
|
|
|
+ String localPath = TaaisConfig.getProfile();
|
|
|
+ String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
|
|
|
+ dataSeq.setFilePath(resourcePath);
|
|
|
|
|
|
- return this.save(dataSeq);//使用全局配置的雪花算法主键生成器生成ID值
|
|
|
+ String unzipPath = resourcePath.substring(0, resourcePath.lastIndexOf(".")) + "_unzip";
|
|
|
+ unzip(dataSeq.getFilePath(), unzipPath);
|
|
|
+ dataSeq.setUnzipPath(unzipPath);
|
|
|
+
|
|
|
+ dataSeq.setUrl(ossEntity.getUrl());
|
|
|
+ return this.save(dataSeq);// 使用全局配置的雪花算法主键生成器生成ID值
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -127,10 +158,10 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean update(DataSeqBo dataSeqBo) {
|
|
|
- DataSeq dataSeq =MapstructUtils.convert(dataSeqBo, DataSeq. class);
|
|
|
- if (ObjectUtil.isNotNull(dataSeq) && ObjectUtil.isNotNull(dataSeq.getId())){
|
|
|
+ DataSeq dataSeq = MapstructUtils.convert(dataSeqBo, DataSeq.class);
|
|
|
+ if (ObjectUtil.isNotNull(dataSeq) && ObjectUtil.isNotNull(dataSeq.getId())) {
|
|
|
boolean updated = this.updateById(dataSeq);
|
|
|
- return updated;
|
|
|
+ return updated;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -147,4 +178,44 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
|
|
|
return this.removeByIds(Arrays.asList(ids));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<String> getAllImages(Long inputOdssId) {
|
|
|
+ // 检查input_oss_id是否存在
|
|
|
+ if (ObjectUtil.isNull(inputOdssId)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ SysOssVo ossEntity = ossService.getById(inputOdssId);
|
|
|
+ if (ObjectUtil.isNull(ossEntity)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String filePath = ossEntity.getFileName();
|
|
|
+ String localPath = TaaisConfig.getProfile();
|
|
|
+ String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
|
|
|
+ String unzipPath = resourcePath.substring(0, resourcePath.lastIndexOf(".")) + "_unzip";
|
|
|
+
|
|
|
+ String urlPrefix = ossEntity.getUrl().substring(0, ossEntity.getUrl().lastIndexOf(".")) + "_unzip";
|
|
|
+
|
|
|
+ // 列出unzipPath下所有图片文件
|
|
|
+ File directory = new File(unzipPath);
|
|
|
+ File[] files = directory.listFiles();
|
|
|
+ List<String> imageList = Arrays.asList(files).stream().filter(file -> file.isFile() && isImageFile(file)).map(file -> urlPrefix + "/" + file.getName()).toList();
|
|
|
+ return imageList;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 常见图片格式的后缀
|
|
|
+ private static final String[] IMAGE_EXTENSIONS = {
|
|
|
+ ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".tif", ".webp"
|
|
|
+ };
|
|
|
+
|
|
|
+ // 判断文件是否为常见图片格式
|
|
|
+ private static boolean isImageFile(File file) {
|
|
|
+ String fileName = file.getName().toLowerCase();
|
|
|
+ for (String extension : IMAGE_EXTENSIONS) {
|
|
|
+ if (fileName.endsWith(extension)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|