Parcourir la source

Merge branch 'develop_1016' into develop

# Conflicts:
#	taais-common/taais-common-core/src/main/java/com/taais/common/core/utils/file/MimeTypeUtils.java
#	taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/DataAugmentationServiceImpl.java
#	taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/DataServiceImpl.java
allen il y a 6 mois
Parent
commit
11991a377a

+ 1 - 1
taais-common/taais-common-core/src/main/java/com/taais/common/core/utils/file/MimeTypeUtils.java

@@ -37,7 +37,7 @@ public class MimeTypeUtils {
         // pdf
         "pdf",
         // pt
-        "pt",
+        "pt", "pth",
         // mat
         "mat"
     };

+ 8 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/AlgorithmModelController.java

@@ -3,6 +3,8 @@ package com.taais.biz.controller;
 import java.util.List;
 
 import com.taais.biz.service.impl.AlgorithmModelServiceImpl;
+import com.taais.system.domain.vo.SysOssVo;
+import com.taais.system.service.ISysOssService;
 import lombok.RequiredArgsConstructor;
 import jakarta.servlet.http.HttpServletResponse;
 import cn.dev33.satoken.annotation.SaCheckPermission;
@@ -69,6 +71,9 @@ public class AlgorithmModelController extends BaseController {
         return CommonResult.success(algorithmModelService.getModelByAlgorithmId(id));
     }
 
+    @Resource
+    private ISysOssService sysOssService;
+
     /**
      * 新增算法模型配置
      */
@@ -77,6 +82,9 @@ public class AlgorithmModelController extends BaseController {
     @RepeatSubmit()
     @PostMapping
     public CommonResult<Void> add(@Validated @RequestBody AlgorithmModelBo algorithmModelBo) {
+        String modelAddress = algorithmModelBo.getModelAddress();
+        SysOssVo vo = sysOssService.getById(Long.parseLong(modelAddress));
+        algorithmModelBo.setModelAddress("/profile" + vo.getUrl().split("/profile")[1]);
         boolean inserted = algorithmModelService.insert(algorithmModelBo);
         if (!inserted) {
             return CommonResult.fail("新增算法模型配置记录失败!");

+ 4 - 4
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/DataAugmentationController.java

@@ -155,10 +155,10 @@ public class DataAugmentationController extends BaseController {
         }
     }
 
-     @PostMapping("/get_result")
-     public CommonResult getResult(@Valid @RequestBody VideoStableStartResultBo videoStableStartResultBo) {
-         return dataAugmentationService.getResult(videoStableStartResultBo);
-     }
+    @PostMapping("/get_result")
+    public CommonResult getResult(@Valid @RequestBody VideoStableStartResultBo videoStableStartResultBo) {
+        return dataAugmentationService.getResult(videoStableStartResultBo);
+    }
 
     @GetMapping("/start/{id}")
     public CommonResult start(@PathVariable("id") Long id) {

+ 63 - 164
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/DataServiceImpl.java

@@ -1,23 +1,20 @@
 package com.taais.biz.service.impl;
-import java.util.Date;
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpUtil;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.mybatisflex.core.paginate.Page;
 import com.mybatisflex.core.query.QueryWrapper;
-import com.taais.biz.constant.BizConstant;
 import com.taais.biz.domain.Data;
-import com.taais.biz.domain.bo.DataAmplificationTaskBo;
 import com.taais.biz.domain.bo.DataBo;
 import com.taais.biz.domain.vo.BatchDataResult;
 import com.taais.biz.domain.dto.DataAmplifyDto;
-import com.taais.biz.domain.vo.DataAmplificationTaskVo;
 import com.taais.biz.domain.vo.DataSelectVo;
 import com.taais.biz.domain.vo.DataVo;
 import com.taais.biz.mapper.DataMapper;
-import com.taais.biz.service.IDataAmplificationTaskService;
 import com.taais.biz.service.IDataService;
 import com.taais.common.core.config.TaaisConfig;
 import com.taais.common.core.core.domain.CommonResult;
@@ -37,7 +34,6 @@ import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
@@ -52,9 +48,7 @@ import java.time.Instant;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 import static com.taais.biz.domain.table.DataTableDef.DATA;
@@ -73,17 +67,14 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
     private static final String ZIP = ".zip";
     private static final String RAR = ".rar";
     private static final String TXT = ".txt";
-    private static final String[] VALID_EXTENSIONS = {".jpg", ".jpeg", ".png"};
-    private static final String PYTHON_DATA_AMPLIFY_API = "http://127.0.0.1:11001/augment";
+    private static final String[] VALID_EXTENSIONS = {".jpg", ".jpeg", ".png", ".bmp"};
+    private static final String PYTHON_DATA_AMPLIFY_API = "http://127.0.0.1:9096/api/data/amplify";
     private static final String RESULT_CODE = "status";
     private static final String RESULT_STATUS = "200";
     private static final String AMPLIFY = "/AMPLIFY/";
     @Resource
     private DataMapper dataMapper;
 
-    @Resource
-    private IDataAmplificationTaskService dataAmplificationTaskService;
-
     @Override
     public QueryWrapper query() {
         return super.query().from(DATA);
@@ -257,13 +248,18 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
                 countSize.getAndIncrement();
             });
             //是否选择已标注,如果已标注则需要检测所有图片是否标注
-            if (!labeledList.isEmpty() && labeled) {
+            if (!labeledList.isEmpty()) {
                 // 已标注数量
                 long unmarkedCount = labeledList.stream().filter(Boolean.FALSE::equals).count();
                 // 未标注数量
                 long markedCount = labeledList.stream().filter(Boolean.TRUE::equals).count();
                 // 如果存在未标注的数据,则返回错误信息
-                if (unmarkedCount > 0) {
+                if (unmarkedCount > 0 && labeled) {
+                    String format = String.format("错误: 已标注文件 %d 个,未标注文件 %d 个", markedCount, unmarkedCount);
+                    return CommonResult.fail(format);
+                }
+
+                if (markedCount > 0 && !labeled) {
                     String format = String.format("错误: 已标注文件 %d 个,未标注文件 %d 个", markedCount, unmarkedCount);
                     return CommonResult.fail(format);
                 }
@@ -280,16 +276,58 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
     @Override
     @Transactional
     public CommonResult<Boolean> dataAmplify(DataAmplifyDto dataAmplifyDto) {
-        DataAmplifyDto amplifyDto = new DataAmplifyDto();
-        DataAmplificationTaskBo dataAmplificationTaskBo = new DataAmplificationTaskBo();
-        dataAmplificationTaskBo.setName(amplifyDto.getTaskName());
-        dataAmplificationTaskBo.setStatus(BizConstant.TASK_STATUS_PENDING);
-        dataAmplificationTaskBo.setDataBatchNums(amplifyDto.getBatchNum());
-        dataAmplificationTaskBo.setAugmentationType(amplifyDto.getAugmentationType());
-        dataAmplificationTaskBo.setParameters(JsonUtils.toJsonString(amplifyDto.getOtherParams()));
-        dataAmplificationTaskBo.setDelFlag(0);
-        dataAmplificationTaskService.insert(dataAmplificationTaskBo);
-        return this.amplifyForData(dataAmplificationTaskBo.getId().toString());
+        //根据批次号获取该批次的所有文件数据
+        QueryWrapper query = query();
+        query.eq(Data::getBatchNum, dataAmplifyDto.getBatchNum());
+        List<Data> dataList = dataMapper.selectListByQuery(query);
+        if (dataList.isEmpty()) {
+            return CommonResult.fail("该批次下没有文件数据,请重新选择批次!");
+        }
+        //TODO: 此处需要定义任务开始,把相关任务信息添加上(任务名称、任务开始时间、任务类型),然后再处理文件。
+
+        List<Data> dataListInfo = dataList.stream().filter(data -> !StringUtils.isEmpty(data.getUrl())).toList();
+        if (dataListInfo.isEmpty()) {
+            return CommonResult.fail("该批次下没有文件数据,请重新选择批次!");
+        }
+        String filePath = TaaisConfig.getUploadPath();
+        LocalDate currentDate = LocalDate.now();
+        // 定义日期格式器
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
+        String formattedDate = currentDate.format(formatter);
+        filePath = filePath + File.separator + formattedDate;
+        String finalFilePath = filePath;
+        dataListInfo.forEach(dataInfo -> {
+            try {
+                //循环调用Python扩增接口
+                Map<String, Object> bodyJson = new HashMap<>();
+                bodyJson.put("augmentationType", dataAmplifyDto.getAugmentationType());
+                bodyJson.put("inputImagePath", dataInfo.getUrl());
+                String outputImagePath = finalFilePath + AMPLIFY + System.currentTimeMillis();
+                File desc = new File(outputImagePath);
+                if (!desc.exists()) {
+                    log.info("创建文件目录: {}", desc.mkdirs());
+                }
+                bodyJson.put("outputImagePath", outputImagePath);
+                bodyJson.put("otherParams", dataAmplifyDto.getOtherParams());
+                //实际请求接口,接口未提供,暂且注释
+//                String response = HttpRequest.post(PYTHON_DATA_AMPLIFY_API)
+//                        .body(JsonUtils.toJsonString(bodyJson))
+//                        .execute().body();
+                String response = "{\"status\":200,\"msg\":\"扩增成功\"}";
+                ObjectMapper objectMapper = new ObjectMapper();
+                JsonNode rootNode = objectMapper.readTree(response);
+                String resultCode = rootNode.path(RESULT_CODE).asText();
+                //判断接口是否响应成功
+                if (!RESULT_STATUS.equals(resultCode)) {
+                    throw new RuntimeException("调用Python接口返回扩增失败");
+                }
+                //处理当前目录文件,并进行入库
+                saveDataInfo(outputImagePath, dataInfo);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+        return CommonResult.fail("该批次下没有文件数据,请重新选择批次!");
     }
 
     private void initFileInfo(String dest, List<File> extractedImagesFileList, boolean directory, String fileName) {
@@ -361,8 +399,6 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
     public boolean update(DataBo dataBo) {
         Data data = MapstructUtils.convert(dataBo, Data.class);
         if (ObjectUtil.isNotNull(data) && ObjectUtil.isNotNull(data.getId())) {
-            // 不更新采集时间
-            data.setGatherTime(null);
             boolean updated = this.updateById(data);
             //新增之后清除缓存
             deleteFormSelectKey();
@@ -405,143 +441,6 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
         return cacheList;
     }
 
-    @Override
-    @Transactional
-    public CommonResult<Boolean> amplifyForData(String id) {
-        DataAmplificationTaskVo taskVo = dataAmplificationTaskService.selectById(Long.valueOf(id));
-        DataAmplifyDto dataAmplifyDto = new DataAmplifyDto();
-        dataAmplifyDto.setId(taskVo.getId().toString());
-        dataAmplifyDto.setAugmentationType(taskVo.getAugmentationType());
-        List<Map<String, String>> maps = JsonUtils.parseArray(taskVo.getParameters(), Map.class);
-        dataAmplifyDto.setOtherParams(maps);
-        dataAmplifyDto.setBatchNum(taskVo.getDataBatchNums());
-        return this.doAmplify(dataAmplifyDto);
-    }
-
-    @Value("${taais.profile}")
-    private String profile;
-
-    private CommonResult<Boolean> doAmplify(DataAmplifyDto dataAmplifyDto) {
-        this.updateEmp(Long.valueOf(dataAmplifyDto.getId()));
-        String[] split = dataAmplifyDto.getBatchNum().split(",");
-        for (String batchNum : split) {
-            QueryWrapper query = query();
-            query.eq(Data::getBatchNum, batchNum);
-            List<Data> dataList = dataMapper.selectListByQuery(query);
-            if (dataList.isEmpty()) {
-                this.updateFail(Long.valueOf(dataAmplifyDto.getId()));
-                continue;
-            }
-
-            List<Data> dataListInfo = dataList.stream().filter(data -> !StringUtils.isEmpty(data.getUrl())).toList();
-            if (dataListInfo.isEmpty()) {
-                this.updateFail(Long.valueOf(dataAmplifyDto.getId()));
-                continue;
-            }
-            String filePath = TaaisConfig.getUploadPath();
-            LocalDate currentDate = LocalDate.now();
-            // 定义日期格式器
-            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
-            String formattedDate = currentDate.format(formatter);
-            filePath = filePath + File.separator + formattedDate;
-            String finalFilePath = filePath;
-            Map<String, String> otherParams = new HashMap<>();
-            for (Map<String, String> param : dataAmplifyDto.getOtherParams()) {
-                otherParams.put(param.get("agName"), param.get("defaultValue"));
-            }
-            Map<String, String> param = dataAmplifyDto.getOtherParams()
-                .stream().collect(Collectors.toMap(item -> item.get("agName"), item -> item.get("defaultValue")));
-            dataListInfo.forEach(dataInfo -> {
-                try {
-                    boolean success = true;
-                    String message = "";
-                    Date startTime = new Date();
-
-                    //循环调用Python扩增接口
-                    Map<String, Object> bodyJson = new HashMap<>();
-                    bodyJson.put("bizType", "数据扩增");
-                    bodyJson.put("bizId", dataAmplifyDto.getId());
-                    bodyJson.put("augmentationType", dataAmplifyDto.getAugmentationType());
-                    bodyJson.put("inputImagePath", dataInfo.getUrl());
-                    String outputImagePath = finalFilePath + AMPLIFY + System.currentTimeMillis();
-                    File desc = new File(outputImagePath);
-                    if (!desc.exists()) {
-                        log.info("创建文件目录: {}", desc.mkdirs());
-                    }
-                    bodyJson.put("outputImagePath", outputImagePath);
-                    bodyJson.put("otherParams", otherParams);
-                    String logPath = profile + "/task/log/" + dataAmplifyDto.getId() + "_log.log";
-                    System.out.println("logPath===>" + logPath);
-                    bodyJson.put("logPath", logPath);
-                    //实际请求接口,接口未提供,暂且注释
-                    String response = HttpRequest.post(PYTHON_DATA_AMPLIFY_API)
-                        .body(JsonUtils.toJsonString(bodyJson))
-                        .execute().body();
-//                String response = "{\"status\":200,\"msg\":\"扩增成功\"}";
-                    ObjectMapper objectMapper = new ObjectMapper();
-                    JsonNode rootNode = objectMapper.readTree(response);
-                    String resultCode = rootNode.path(RESULT_CODE).asText();
-                    //判断接口是否响应成功
-                    if (!RESULT_STATUS.equals(resultCode)) {
-                        success = false;
-                    }
-                    message = rootNode.path("msg").asText();
-                    //处理当前目录文件,并进行入库
-                    saveDataInfo(outputImagePath, dataInfo);
-
-                    DataAmplificationTaskVo taskVo = dataAmplificationTaskService.selectById(Long.valueOf(dataAmplifyDto.getId()));
-                    Date endTime = new Date();
-                    DataAmplificationTaskBo update = new DataAmplificationTaskBo();
-                    if (taskVo.getInputImagePath() != null) {
-                        update.setInputImagePath(taskVo.getInputImagePath()+"|" + dataInfo.getUrl());
-                    } else {
-                        update.setInputImagePath(dataInfo.getUrl());
-                    }
-                    if (taskVo.getOutputImagePath() != null) {
-                        update.setOutputImagePath(taskVo.getOutputImagePath()+"|" + outputImagePath);
-                    } else {
-                        update.setOutputImagePath(outputImagePath);
-                    }
-                    update.setId(Long.valueOf(dataAmplifyDto.getId()));
-                    update.setStartTime(startTime);
-                    update.setEndTime(endTime);
-                    update.setCostSecond((int) (endTime.getTime() - startTime.getTime()));
-                    update.setStatus(success ? BizConstant.TASK_STATUS_SUCCEED : BizConstant.TASK_STATUS_FAILED);
-                    update.setLog(taskVo.getLog() + "|" + message);
-                    update.setVersion(taskVo.getVersion());
-                    update.setRemarks(taskVo.getRemarks() + "|" + (int) (endTime.getTime() - startTime.getTime()));
-                    dataAmplificationTaskService.update(update);
-                } catch (Exception e) {
-                    throw new RuntimeException(e);
-                }
-            });
-        }
-        //根据批次号获取该批次的所有文件数据
-        return CommonResult.success();
-    }
-
-    private void updateEmp(Long id) {
-        DataAmplificationTaskVo taskVo = dataAmplificationTaskService.selectById(id);
-        DataAmplificationTaskBo update = new DataAmplificationTaskBo();
-        update.setOutputImagePath("");
-        update.setInputImagePath("");
-        update.setId(id);
-        update.setLog("");
-        update.setVersion(taskVo.getVersion());
-        update.setRemarks("");
-        dataAmplificationTaskService.update(update);
-    }
-
-    private void updateFail(Long id) {
-        DataAmplificationTaskVo taskVo = dataAmplificationTaskService.selectById(id);
-        DataAmplificationTaskBo update = new DataAmplificationTaskBo();
-        update.setId(taskVo.getId());
-        update.setStatus(BizConstant.TASK_STATUS_FAILED);
-        update.setLog(taskVo.getLog() + "|" + "该批次下没有文件数据,请重新选择批次!");
-        update.setVersion(taskVo.getVersion());
-        dataAmplificationTaskService.update(update);
-    }
-
 
     /**
      * 解析目标目录所有文件,进行文件更名并入库

+ 7 - 2
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/TargetIdentificationSubtaskServiceImpl.java

@@ -228,7 +228,12 @@ public class TargetIdentificationSubtaskServiceImpl extends BaseServiceImpl<Targ
                     hasModelProperty = true;
                     _modelId = object.getString("modelId");
                 }
-                algorithmRequestDto.getOtherParams().put(object.getString("agName"), object.getString("defaultValue"));
+                String value = object.getString("defaultValue");
+                if(NumberUtils.isCreatable(value)){
+                    algorithmRequestDto.getOtherParams().put(object.getString("agName"), NumberUtils.createNumber(value));
+                } else {
+                    algorithmRequestDto.getOtherParams().put(object.getString("agName"), value);
+                }
             }
         } catch (Exception e) {
             log.error(e.getMessage());
@@ -256,7 +261,7 @@ public class TargetIdentificationSubtaskServiceImpl extends BaseServiceImpl<Targ
             return;
         }
         // send http
-        System.out.println("todo request: " + algorithmRequestDto.toString());
+        log.info("todo request: " + algorithmRequestDto);
 
         try {
             String res = HttpUtil.post(url, JSONUtil.toJsonStr(algorithmRequestDto));