Browse Source

feat: 可见光转红外开始和终止接口初步搞定

WANGKANG 9 months ago
parent
commit
76d143356e

+ 5 - 2
taais-admin/src/main/resources/application-dev.yml

@@ -1,6 +1,9 @@
 server:
 server:
-  video_stable_start_url: http://localhost:11001/video_stable
-  video_stable_stop_url: http://localhost:11001/video_stable_stop
+  video_stable_start_url: http://localhost:11002/video_stable
+  video_stable_stop_url: http://localhost:11002/video_stable_stop
+  to_infrared_start_url: http://localhost:11002/to_infrared
+  to_infrared_stop_url: http://localhost:11002/to_infrared_stop
+
 # 数据源配置
 # 数据源配置
 spring:
 spring:
   datasource:
   datasource:

+ 21 - 16
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/PublicController.java

@@ -2,12 +2,11 @@ package com.taais.biz.controller;
 
 
 import com.taais.biz.constant.BizConstant;
 import com.taais.biz.constant.BizConstant;
 import com.taais.biz.domain.bo.TargetIdentificationSubtaskDetailsBo;
 import com.taais.biz.domain.bo.TargetIdentificationSubtaskDetailsBo;
+import com.taais.biz.domain.bo.ToInfraredBo;
+import com.taais.biz.domain.bo.ToInfraredStartResultBo;
 import com.taais.biz.domain.bo.VideoStableStartResultBo;
 import com.taais.biz.domain.bo.VideoStableStartResultBo;
 import com.taais.biz.domain.dto.TaskResultDTO;
 import com.taais.biz.domain.dto.TaskResultDTO;
-import com.taais.biz.service.IAlgorithmBizProcessService;
-import com.taais.biz.service.IAlgorithmDataProcessService;
-import com.taais.biz.service.IAlgorithmTaskService;
-import com.taais.biz.service.IVideoStableService;
+import com.taais.biz.service.*;
 import com.taais.biz.service.impl.TargetIdentificationSubtaskDetailsServiceImpl;
 import com.taais.biz.service.impl.TargetIdentificationSubtaskDetailsServiceImpl;
 import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.log.annotation.Log;
 import com.taais.common.log.annotation.Log;
@@ -34,6 +33,8 @@ public class PublicController extends BaseController {
     private static final Logger log = LoggerFactory.getLogger(PublicController.class);
     private static final Logger log = LoggerFactory.getLogger(PublicController.class);
     @Resource
     @Resource
     private IVideoStableService videoStableService;
     private IVideoStableService videoStableService;
+    @Resource
+    private IToInfraredService toInfraredService;
 
 
     @Resource
     @Resource
     IAlgorithmDataProcessService dataProcessService;
     IAlgorithmDataProcessService dataProcessService;
@@ -47,19 +48,18 @@ public class PublicController extends BaseController {
     private IAlgorithmTaskService algorithmTaskService;
     private IAlgorithmTaskService algorithmTaskService;
 
 
 
 
-
     // todo: 2024080906
     // todo: 2024080906
     @PostMapping("/taskResult")
     @PostMapping("/taskResult")
     public CommonResult<Void> taskResult(@RequestBody TaskResultDTO resultDTO) {
     public CommonResult<Void> taskResult(@RequestBody TaskResultDTO resultDTO) {
-        log.info("taskResult start,params:{}",resultDTO);
+        log.info("taskResult start,params:{}", resultDTO);
         String errorMsg = checkDTO(resultDTO);
         String errorMsg = checkDTO(resultDTO);
-        if(StringUtils.isNotEmpty(errorMsg)){
-            log.error("taskResult error,{}",errorMsg);
+        if (StringUtils.isNotEmpty(errorMsg)) {
+            log.error("taskResult error,{}", errorMsg);
             return CommonResult.fail(errorMsg);
             return CommonResult.fail(errorMsg);
         }
         }
         String bizType = resultDTO.getBizType();
         String bizType = resultDTO.getBizType();
-        if(BizConstant.TYPE_DATA_BIZ_PROCESS.equals(bizType)){
-            //errorMsg = bizProcessService.taskResult(resultDTO);
+        if (BizConstant.TYPE_DATA_BIZ_PROCESS.equals(bizType)) {
+            // errorMsg = bizProcessService.taskResult(resultDTO);
             TargetIdentificationSubtaskDetailsBo detailsBo = detailsService.getById(resultDTO.getBizId());
             TargetIdentificationSubtaskDetailsBo detailsBo = detailsService.getById(resultDTO.getBizId());
             detailsBo.setStatus(resultDTO.getStatus() != 200 ? BizConstant.TASK_STATUS_FAILED :
             detailsBo.setStatus(resultDTO.getStatus() != 200 ? BizConstant.TASK_STATUS_FAILED :
                 resultDTO.getMsg().contains("finish") ? BizConstant.TASK_STATUS_SUCCEED : BizConstant.TASK_STATUS_PROCESSING);
                 resultDTO.getMsg().contains("finish") ? BizConstant.TASK_STATUS_SUCCEED : BizConstant.TASK_STATUS_PROCESSING);
@@ -67,11 +67,11 @@ public class PublicController extends BaseController {
         } else if (BizConstant.TYPE_DATA_PROCESS.equals(bizType)) {
         } else if (BizConstant.TYPE_DATA_PROCESS.equals(bizType)) {
             errorMsg = dataProcessService.taskResult(resultDTO);
             errorMsg = dataProcessService.taskResult(resultDTO);
         } else {
         } else {
-            log.error("这种情况是不可能发生的,参数:{}",resultDTO);
+            log.error("这种情况是不可能发生的,参数:{}", resultDTO);
             return CommonResult.fail("这种情况是不可能发生的");
             return CommonResult.fail("这种情况是不可能发生的");
         }
         }
 
 
-        if(StringUtils.isNotEmpty(errorMsg)){
+        if (StringUtils.isNotEmpty(errorMsg)) {
             return CommonResult.fail(errorMsg);
             return CommonResult.fail(errorMsg);
         }
         }
         return CommonResult.success();
         return CommonResult.success();
@@ -79,16 +79,16 @@ public class PublicController extends BaseController {
 
 
     private String checkDTO(TaskResultDTO resultDTO) {
     private String checkDTO(TaskResultDTO resultDTO) {
         Integer status = resultDTO.getStatus();
         Integer status = resultDTO.getStatus();
-        if(status != 200 && status != 500){
+        if (status != 200 && status != 500) {
             return "status 只能是200或500";
             return "status 只能是200或500";
         }
         }
         Long bizId = resultDTO.getBizId();
         Long bizId = resultDTO.getBizId();
-        if(bizId == null){
+        if (bizId == null) {
             return "bizId 不能为null";
             return "bizId 不能为null";
         }
         }
         String bizType = resultDTO.getBizType();
         String bizType = resultDTO.getBizType();
-        if(!BizConstant.TYPE_DATA_BIZ_PROCESS.equals(bizType) && !BizConstant.TYPE_DATA_PROCESS.equals(bizType)){
-            return "status 只能是"+BizConstant.TYPE_DATA_BIZ_PROCESS+"或"+BizConstant.TYPE_DATA_PROCESS;
+        if (!BizConstant.TYPE_DATA_BIZ_PROCESS.equals(bizType) && !BizConstant.TYPE_DATA_PROCESS.equals(bizType)) {
+            return "status 只能是" + BizConstant.TYPE_DATA_BIZ_PROCESS + "或" + BizConstant.TYPE_DATA_PROCESS;
         }
         }
         return null;
         return null;
     }
     }
@@ -103,4 +103,9 @@ public class PublicController extends BaseController {
     public CommonResult getResult(@Valid @RequestBody VideoStableStartResultBo videoStableStartResultBo) {
     public CommonResult getResult(@Valid @RequestBody VideoStableStartResultBo videoStableStartResultBo) {
         return videoStableService.getResult(videoStableStartResultBo);
         return videoStableService.getResult(videoStableStartResultBo);
     }
     }
+
+    @PostMapping("/toInfrared/get_result")
+    public CommonResult getResult(@Valid @RequestBody ToInfraredStartResultBo toInfraredStartResultBo) {
+        return toInfraredService.getResult(toInfraredStartResultBo);
+    }
 }
 }

+ 11 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/ToInfraredController.java

@@ -105,4 +105,15 @@ public class ToInfraredController extends BaseController {
         }
         }
         return CommonResult.success();
         return CommonResult.success();
     }
     }
+
+    @GetMapping("/start/{id}")
+    public CommonResult start(@PathVariable("id") Long id) {
+        return toInfraredService.start(id);
+    }
+
+    @GetMapping("/stop/{id}")
+    public CommonResult stop(@PathVariable("id") Long id) {
+        return toInfraredService.stop(id);
+    }
+
 }
 }

+ 25 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/bo/ToInfraredStartResultBo.java

@@ -0,0 +1,25 @@
+package com.taais.biz.domain.bo;
+
+import jakarta.validation.constraints.NotNull;
+import lombok.*;
+
+/**
+ * @Datetime : 2023/12/5 12:13
+ * @Author : WANGKANG
+ * @Email : 1686617586@qq.com
+ * @File : ToInfraredStartResultBo.java
+ * @Brief :
+ * Copyright 2023 WANGKANG, All Rights Reserved.
+ */
+@Builder
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode()
+public class ToInfraredStartResultBo {
+    @NotNull(message = "status不能为空")
+    private String status;
+    private String msg;
+    @NotNull(message = "id不能为空")
+    private Long id;
+}

+ 7 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/IToInfraredService.java

@@ -3,7 +3,9 @@ package com.taais.biz.service;
 
 
 import com.taais.biz.domain.ToInfrared;
 import com.taais.biz.domain.ToInfrared;
 import com.taais.biz.domain.bo.ToInfraredBo;
 import com.taais.biz.domain.bo.ToInfraredBo;
+import com.taais.biz.domain.bo.ToInfraredStartResultBo;
 import com.taais.biz.domain.vo.ToInfraredVo;
 import com.taais.biz.domain.vo.ToInfraredVo;
+import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.core.core.page.PageResult;
 import com.taais.common.core.core.page.PageResult;
 import com.taais.common.orm.core.service.IBaseService;
 import com.taais.common.orm.core.service.IBaseService;
 
 
@@ -64,4 +66,9 @@ public interface IToInfraredService extends IBaseService<ToInfrared> {
      */
      */
     boolean deleteByIds(Long[] ids);
     boolean deleteByIds(Long[] ids);
 
 
+    CommonResult start(Long id);
+
+    CommonResult stop(Long id);
+
+    CommonResult getResult(ToInfraredStartResultBo toInfraredStartResultBo);
 }
 }

+ 83 - 2
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/ToInfraredServiceImpl.java

@@ -3,19 +3,25 @@ package com.taais.biz.service.impl;
 import java.nio.file.Path;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.mybatisflex.core.paginate.Page;
 import com.mybatisflex.core.paginate.Page;
 import com.mybatisflex.core.query.QueryWrapper;
 import com.mybatisflex.core.query.QueryWrapper;
+import com.taais.biz.constant.BizConstant;
+import com.taais.biz.domain.*;
 import com.taais.biz.domain.ToInfrared;
 import com.taais.biz.domain.ToInfrared;
-import com.taais.biz.domain.Video2image;
 import com.taais.biz.domain.bo.ToInfraredBo;
 import com.taais.biz.domain.bo.ToInfraredBo;
+import com.taais.biz.domain.bo.ToInfraredStartResultBo;
+import com.taais.biz.domain.bo.VideoStableStartResultBo;
 import com.taais.biz.domain.vo.ToInfraredVo;
 import com.taais.biz.domain.vo.ToInfraredVo;
 import com.taais.biz.mapper.ToInfraredMapper;
 import com.taais.biz.mapper.ToInfraredMapper;
 import com.taais.biz.service.IToInfraredService;
 import com.taais.biz.service.IToInfraredService;
+import com.taais.biz.utils.ZipUtils;
 import com.taais.common.core.config.TaaisConfig;
 import com.taais.common.core.config.TaaisConfig;
 import com.taais.common.core.constant.Constants;
 import com.taais.common.core.constant.Constants;
+import com.taais.common.core.core.domain.CommonResult;
 import com.taais.common.core.utils.MapstructUtils;
 import com.taais.common.core.utils.MapstructUtils;
 import com.taais.common.core.utils.StringUtils;
 import com.taais.common.core.utils.StringUtils;
 import com.taais.common.orm.core.page.PageQuery;
 import com.taais.common.orm.core.page.PageQuery;
@@ -25,12 +31,13 @@ import com.taais.system.domain.vo.SysOssVo;
 import com.taais.system.service.ISysOssService;
 import com.taais.system.service.ISysOssService;
 import jakarta.annotation.Resource;
 import jakarta.annotation.Resource;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
 import static com.taais.biz.constant.BizConstant.VideoStatus.NOT_START;
 import static com.taais.biz.constant.BizConstant.VideoStatus.NOT_START;
 import static com.taais.biz.domain.table.ToInfraredTableDef.TO_INFRARED;
 import static com.taais.biz.domain.table.ToInfraredTableDef.TO_INFRARED;
-import static com.taais.biz.service.impl.VideoStableServiceImpl.removeFileExtension;
+import static com.taais.biz.service.impl.VideoStableServiceImpl.*;
 
 
 /**
 /**
  * 可见光转红外Service业务层处理
  * 可见光转红外Service业务层处理
@@ -40,6 +47,12 @@ import static com.taais.biz.service.impl.VideoStableServiceImpl.removeFileExtens
  */
  */
 @Service
 @Service
 public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToInfrared> implements IToInfraredService {
 public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToInfrared> implements IToInfraredService {
+    @Value("${server.to_infrared_start_url}")
+    private String to_infrared_start_url;
+
+    @Value("${server.to_infrared_stop_url}")
+    private String to_infrared_stop_url;
+
     @Autowired
     @Autowired
     private ISysOssService ossService;
     private ISysOssService ossService;
 
 
@@ -188,4 +201,72 @@ public class ToInfraredServiceImpl extends BaseServiceImpl<ToInfraredMapper, ToI
         return this.removeByIds(Arrays.asList(ids));
         return this.removeByIds(Arrays.asList(ids));
     }
     }
 
 
+    @Override
+    public CommonResult start(Long id) {
+        ToInfrared toInfrared = getById(id);
+
+        SysOssVo inputOssEntity = ossService.getById(toInfrared.getInputOssId());
+
+        String filePath = inputOssEntity.getFileName();
+        String localPath = TaaisConfig.getProfile();
+        String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
+
+        String fileName = StringUtils.substringAfterLast(filePath, "/");
+        String fileName_without_suffix = removeFileExtension(fileName);
+
+        Path path = Paths.get(resourcePath);
+        Path inputPath = path.resolveSibling(fileName_without_suffix + "_images");
+        Path outputPath = path.resolveSibling(fileName_without_suffix + "_stable");
+
+        makeDir(inputPath.toString());
+        makeDir(outputPath.toString());
+
+        ZipUtils.unzip(resourcePath, inputPath.toString());
+
+        toInfrared.setInputPath(inputPath.toString());
+        toInfrared.setOutputPath(outputPath.toString());
+
+        toInfrared.setStartTime(new Date());
+
+        HttpResponseEntity responseEntity = sendPostMsg(to_infrared_start_url, toInfrared);
+        if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
+            toInfrared.setStatus(BizConstant.VideoStatus.RUNNING);
+            updateById(toInfrared);
+            return CommonResult.success("任务开始成功,请等待完成");
+        } else {
+            return CommonResult.fail("任务开始失败,请检查!");
+        }
+    }
+
+    @Override
+    public CommonResult stop(Long id) {
+        ToInfrared toInfrared = getById(id);
+
+        HttpResponseEntity responseEntity = sendPostMsg(to_infrared_stop_url, toInfrared);
+        if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
+            toInfrared.setStatus(BizConstant.VideoStatus.INTERRUPTED);
+            updateById(toInfrared);
+            return CommonResult.fail("终止任务成功");
+        } else {
+            return CommonResult.fail("终止任务失败");
+        }
+    }
+
+    @Override
+    public CommonResult getResult(ToInfraredStartResultBo toInfraredStartResultBo) {
+        Long id = toInfraredStartResultBo.getId();
+        String status = toInfraredStartResultBo.getStatus();
+        String msg = toInfraredStartResultBo.getMsg();
+        ToInfrared toInfrared = getById(id);
+        toInfrared.setLog(msg);
+        toInfrared.setStatus("200".equals(status) ? BizConstant.VideoStatus.END : BizConstant.VideoStatus.FAILED);
+        toInfrared.setEndTime(new Date());
+        try {
+            toInfrared.setCostSecond((toInfrared.getEndTime().getTime() - toInfrared.getStartTime().getTime()) / 1000);
+        } catch (Exception e) {
+            toInfrared.setCostSecond(null);
+        }
+        updateById(toInfrared);
+        return CommonResult.success();
+    }
 }
 }

+ 4 - 5
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/VideoStableServiceImpl.java

@@ -238,17 +238,16 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
         updateById(videoStable);
         updateById(videoStable);
 
 
         HttpResponseEntity responseEntity = sendPostMsg(video_stable_start_url, videoStable);
         HttpResponseEntity responseEntity = sendPostMsg(video_stable_start_url, videoStable);
-        if (responseEntity.getStatus() == 200) {
+        if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
+            return CommonResult.success("任务开始成功,请等待完成");
+        } else {
             videoStable.setStatus(BizConstant.VideoStatus.FAILED);
             videoStable.setStatus(BizConstant.VideoStatus.FAILED);
             updateById(videoStable);
             updateById(videoStable);
-            return CommonResult.success("任务开始成功,请等待完成");
-        }
-        else {
             return CommonResult.fail("任务开始失败,请检查!");
             return CommonResult.fail("任务开始失败,请检查!");
         }
         }
     }
     }
 
 
-    public HttpResponseEntity sendPostMsg(String url, Object obj) {
+    public static HttpResponseEntity sendPostMsg(String url, Object obj) {
         log.info("sendMsg: {} - {}", url, JsonUtils.toJsonString(obj));
         log.info("sendMsg: {} - {}", url, JsonUtils.toJsonString(obj));
 
 
         CloseableHttpClient httpClient = HttpClients.createDefault();
         CloseableHttpClient httpClient = HttpClients.createDefault();