Просмотр исходного кода

feat: 目标检测功能基本搭建

WANGKANG 9 месяцев назад
Родитель
Сommit
10876eb57e

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

@@ -1,10 +1,9 @@
 server:
   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
-  track_sequence_start_url: http://localhost:11003/track_sequence
   track_sequence_stop_url: http://localhost:11003/track_sequence_stop
+  target_detection_stop_url: http://localhost:11003/target_detection_stop
 
 # 数据源配置
 spring:

+ 119 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/TargetDetectionController.java

@@ -0,0 +1,119 @@
+package com.taais.biz.controller;
+
+import java.util.List;
+
+import lombok.RequiredArgsConstructor;
+import jakarta.servlet.http.HttpServletResponse;
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.validation.annotation.Validated;
+import com.taais.common.core.core.domain.CommonResult;
+import com.taais.common.excel.utils.ExcelUtil;
+import com.taais.common.log.annotation.Log;
+import com.taais.common.log.enums.BusinessType;
+import com.taais.common.web.annotation.RepeatSubmit;
+import com.taais.common.web.core.BaseController;
+import jakarta.annotation.Resource;
+import com.taais.biz.domain.vo.TargetDetectionVo;
+import com.taais.biz.domain.bo.TargetDetectionBo;
+import com.taais.biz.service.ITargetDetectionService;
+
+import com.taais.common.core.core.page.PageResult;
+
+/**
+ * 目标检测Controller
+ *
+ * @author wangkang
+ * 2024-09-29
+ */
+@Validated
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/demo/TargetDetection")
+public class TargetDetectionController extends BaseController {
+    @Resource
+    private ITargetDetectionService targetDetectionService;
+
+    /**
+     * 查询目标检测列表
+     */
+    @SaCheckPermission("demo:TargetDetection:list")
+    @GetMapping("/list")
+    public CommonResult<PageResult<TargetDetectionVo>> list(TargetDetectionBo targetDetectionBo) {
+        return CommonResult.success(targetDetectionService.selectPage(targetDetectionBo));
+    }
+
+    /**
+     * 导出目标检测列表
+     */
+    @SaCheckPermission("demo:TargetDetection:export")
+    @Log(title = "目标检测", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, TargetDetectionBo targetDetectionBo) {
+        List<TargetDetectionVo> list = targetDetectionService.selectList(targetDetectionBo);
+        ExcelUtil.exportExcel(list, "目标检测", TargetDetectionVo.class, response);
+    }
+
+    /**
+     * 获取目标检测详细信息
+     */
+    @SaCheckPermission("demo:TargetDetection:query")
+    @GetMapping(value = "/{id}")
+    public CommonResult<TargetDetectionVo> getInfo(@PathVariable Long id) {
+        return CommonResult.success(targetDetectionService.selectById(id));
+    }
+
+    /**
+     * 新增目标检测
+     */
+    @SaCheckPermission("demo:TargetDetection:add")
+    @Log(title = "目标检测", businessType = BusinessType.INSERT)
+    @RepeatSubmit()
+    @PostMapping
+    public CommonResult<Void> add(@Validated @RequestBody TargetDetectionBo targetDetectionBo) {
+        boolean inserted = targetDetectionService.insert(targetDetectionBo);
+        if (!inserted) {
+            return CommonResult.fail("新增目标检测记录失败!");
+        }
+        return CommonResult.success();
+    }
+
+    /**
+     * 修改目标检测
+     */
+    @SaCheckPermission("demo:TargetDetection:edit")
+    @Log(title = "目标检测", businessType = BusinessType.UPDATE)
+    @RepeatSubmit()
+    @PutMapping
+    public CommonResult<Void> edit(@Validated @RequestBody TargetDetectionBo targetDetectionBo) {
+        Boolean updated = targetDetectionService.update(targetDetectionBo);
+        if (!updated) {
+            return CommonResult.fail("修改目标检测记录失败!");
+        }
+        return CommonResult.success();
+    }
+
+    /**
+     * 删除目标检测
+     */
+    @SaCheckPermission("demo:TargetDetection:remove")
+    @Log(title = "目标检测", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}")
+    public CommonResult<Void> remove(@PathVariable Long[] ids) {
+        boolean deleted = targetDetectionService.deleteByIds(ids);
+        if (!deleted) {
+            return CommonResult.fail("删除目标检测记录失败!");
+        }
+        return CommonResult.success();
+    }
+
+    @GetMapping("/start/{id}")
+    public CommonResult start(@PathVariable("id") Long id) {
+        return targetDetectionService.start(id);
+    }
+
+    @GetMapping("/stop/{id}")
+    public CommonResult stop(@PathVariable("id") Long id) {
+        return targetDetectionService.stop(id);
+    }
+}

+ 81 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/TargetDetection.java

@@ -0,0 +1,81 @@
+package com.taais.biz.domain;
+
+import java.util.Date;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.mybatisflex.annotation.Column;
+import com.mybatisflex.annotation.Id;
+import com.mybatisflex.annotation.Table;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serial;
+import com.taais.common.orm.core.domain.BaseEntity;
+
+/**
+ * 目标检测对象 target_detection
+ *
+ * @author wangkang
+ * 2024-09-29
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Table(value = "target_detection")
+public class TargetDetection extends BaseEntity
+    {
+@Serial
+private static final long serialVersionUID = 1L;
+
+    /** ID */
+    @Id
+    private Long id;
+
+    /** 任务名称 */
+    private String name;
+
+    /** 状态
+0:未开始
+1:进行中
+2:完成
+3:失败
+4:中断 */
+    private String status;
+
+    /** 开始时间 */
+    private Date startTime;
+
+    /** 结束时间 */
+    private Date endTime;
+
+    /** 耗时 */
+    private Long costSecond;
+
+    /** 日志 */
+    private String log;
+
+    /** 备注 */
+    private String remarks;
+
+    /** $column.columnComment */
+    @Column(isLogicDelete = true)
+    private Integer delFlag;
+
+    /** $column.columnComment */
+    private String url;
+
+    /** $column.columnComment */
+    private Long inputOssId;
+
+    /** 输入路径 */
+    private String inputPath;
+
+    /** 输出路径 */
+    private String outputPath;
+
+    /** zip文件输出路径 */
+    private String zipFilePath;
+
+    /** 模型的id */
+    private Long algorithmModelId;
+
+
+}

+ 101 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/bo/TargetDetectionBo.java

@@ -0,0 +1,101 @@
+package com.taais.biz.domain.bo;
+
+import com.taais.biz.domain.TargetDetection;
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import jakarta.validation.constraints.*;
+import java.util.Date;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.taais.common.orm.core.domain.BaseEntity;
+
+/**
+ * 目标检测业务对象 target_detection
+ *
+ * @author wangkang
+ * @date 2024-09-29
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@AutoMapper(target = TargetDetection.class, reverseConvertGenerate = false)
+public class TargetDetectionBo extends BaseEntity{
+    /**
+     * ID
+     */
+    private Long id;
+
+    /**
+     * 任务名称
+     */
+    @NotBlank(message = "任务名称不能为空")
+    private String name;
+
+    /**
+     * 状态
+        0:未开始
+        1:进行中
+        2:完成
+        3:失败
+        4:中断
+             */
+    private String status;
+
+    /**
+     * 开始时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date startTime;
+
+    /**
+     * 结束时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date endTime;
+
+    /**
+     * 耗时
+     */
+    private Long costSecond;
+
+    /**
+     * 日志
+     */
+    private String log;
+
+    /**
+     * 备注
+     */
+    private String remarks;
+
+    /**
+     * $column.columnComment
+     */
+    private String url;
+
+    /**
+     * $column.columnComment
+     */
+    @NotNull(message = "图片集不能为空")
+    private Long inputOssId;
+
+    /**
+     * 输入路径
+     */
+    private String inputPath;
+
+    /**
+     * 输出路径
+     */
+    private String outputPath;
+
+    /**
+     * zip文件输出路径
+     */
+    private String zipFilePath;
+
+    /**
+     * 模型的id
+     */
+    @NotNull(message = "模型的id不能为空")
+    private Long algorithmModelId;
+}

+ 123 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/vo/TargetDetectionImportVo.java

@@ -0,0 +1,123 @@
+package com.taais.biz.domain.vo;
+
+import java.util.Date;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.taais.common.excel.annotation.ExcelDictFormat;
+import com.taais.common.excel.convert.ExcelDictConvert;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+import lombok.NoArgsConstructor;
+
+/**
+ * 目标检测导入视图对象 target_detection
+ *
+ * @author wangkang
+ * @date 2024-09-29
+ */
+
+@Data
+@NoArgsConstructor
+public class TargetDetectionImportVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+
+    /**
+     * 任务名称
+     */
+    @ExcelProperty(value = "任务名称")
+    private String name;
+
+    /**
+     * 状态
+     * 0:未开始
+     * 1:进行中
+     * 2:完成
+     * 3:失败
+     * 4:中断
+     */
+    @ExcelProperty(value = "状态")
+    private String status;
+
+    /**
+     * 开始时间
+     */
+    @ExcelProperty(value = "开始时间")
+    private Date startTime;
+
+    /**
+     * 结束时间
+     */
+    @ExcelProperty(value = "结束时间")
+    private Date endTime;
+
+    /**
+     * 耗时
+     */
+    @ExcelProperty(value = "耗时")
+    private Long costSecond;
+
+    /**
+     * 日志
+     */
+    @ExcelProperty(value = "日志")
+    private String log;
+
+    /**
+     * 备注
+     */
+    @ExcelProperty(value = "备注")
+    private String remarks;
+
+    /**
+     * $column.columnComment
+     */
+    @ExcelProperty(value = "${column.columnComment}")
+    private Integer delFlag;
+
+    /**
+     * $column.columnComment
+     */
+    @ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
+    private String url;
+
+    /**
+     * $column.columnComment
+     */
+    @ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
+    private Long inputOssId;
+
+    /**
+     * 输入路径
+     */
+    @ExcelProperty(value = "输入路径")
+    private String inputPath;
+
+    /**
+     * 输出路径
+     */
+    @ExcelProperty(value = "输出路径")
+    private String outputPath;
+
+    /**
+     * zip文件输出路径
+     */
+    @ExcelProperty(value = "zip文件输出路径")
+    private String zipFilePath;
+
+    /**
+     * 模型的id
+     */
+    @ExcelProperty(value = "模型的id")
+    private Long algorithmModelId;
+
+
+}

+ 133 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/vo/TargetDetectionVo.java

@@ -0,0 +1,133 @@
+package com.taais.biz.domain.vo;
+
+import java.util.Date;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.taais.biz.domain.TargetDetection;
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.taais.common.excel.annotation.ExcelDictFormat;
+import com.taais.common.excel.convert.ExcelDictConvert;
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+import com.taais.common.orm.core.domain.BaseEntity;
+
+/**
+ * 目标检测视图对象 target_detection
+ *
+ * @author wangkang
+ * @date 2024-09-29
+ */
+@Data
+@ExcelIgnoreUnannotated
+@EqualsAndHashCode(callSuper = true)
+@AutoMapper(target = TargetDetection.class)
+public class TargetDetectionVo extends BaseEntity implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * ID
+     */
+    @ExcelProperty(value = "ID")
+    private Long id;
+
+    /**
+     * 任务名称
+     */
+    @ExcelProperty(value = "任务名称")
+    private String name;
+
+    /**
+     * 状态
+     * 0:未开始
+     * 1:进行中
+     * 2:完成
+     * 3:失败
+     * 4:中断
+     */
+    @ExcelProperty(value = "状态")
+    private String status;
+
+    /**
+     * 开始时间
+     */
+    @ExcelProperty(value = "开始时间")
+    private Date startTime;
+
+    /**
+     * 结束时间
+     */
+    @ExcelProperty(value = "结束时间")
+    private Date endTime;
+
+    /**
+     * 耗时
+     */
+    @ExcelProperty(value = "耗时")
+    private Long costSecond;
+
+    /**
+     * 日志
+     */
+    @ExcelProperty(value = "日志")
+    private String log;
+
+    /**
+     * 备注
+     */
+    @ExcelProperty(value = "备注")
+    private String remarks;
+
+    /**
+     * $column.columnComment
+     */
+    @ExcelProperty(value = "${column.columnComment}")
+    private Integer delFlag;
+
+    /**
+     * $column.columnComment
+     */
+    @ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
+    private String url;
+
+    /**
+     * $column.columnComment
+     */
+    @ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
+    private Long inputOssId;
+
+    /**
+     * 输入路径
+     */
+    @ExcelProperty(value = "输入路径")
+    private String inputPath;
+
+    /**
+     * 输出路径
+     */
+    @ExcelProperty(value = "输出路径")
+    private String outputPath;
+
+    /**
+     * zip文件输出路径
+     */
+    @ExcelProperty(value = "zip文件输出路径")
+    private String zipFilePath;
+
+    /**
+     * 模型的id
+     */
+    @ExcelProperty(value = "模型的id")
+    private Long algorithmModelId;
+
+
+}

+ 119 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/listener/TargetDetectionImportListener.java

@@ -0,0 +1,119 @@
+package com.taais.biz.listener;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.taais.common.core.exception.ServiceException;
+import com.taais.common.core.utils.SpringUtils;
+import com.taais.common.core.utils.ValidatorUtils;
+import com.taais.common.excel.core.ExcelListener;
+import com.taais.common.excel.core.ExcelResult;
+import com.taais.biz.domain.bo.TargetDetectionBo;
+import com.taais.biz.domain.vo.TargetDetectionImportVo;
+import com.taais.biz.domain.vo.TargetDetectionVo;
+import com.taais.biz.service.ITargetDetectionService;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.List;
+
+/**
+ * 目标检测自定义导入
+ *
+ * @author wangkang
+ */
+@Slf4j
+public class TargetDetectionImportListener extends AnalysisEventListener<TargetDetectionImportVo> implements ExcelListener<TargetDetectionImportVo> {
+    private final ITargetDetectionService targetDetectionService;
+
+    private final Boolean isUpdateSupport;
+    private int successNum = 0;
+    private int failureNum = 0;
+    private final StringBuilder successMsg = new StringBuilder();
+    private final StringBuilder failureMsg = new StringBuilder();
+
+    public TargetDetectionImportListener(Boolean isUpdateSupport) {
+        this.targetDetectionService = SpringUtils.getBean(ITargetDetectionService.class);
+        this.isUpdateSupport = isUpdateSupport;
+    }
+
+    @Override
+    public void invoke(TargetDetectionImportVo targetDetectionVo, AnalysisContext context) {
+        try {
+
+            TargetDetectionBo targetDetectionBo = BeanUtil.toBean(targetDetectionVo, TargetDetectionBo.class);
+
+            //TODO:根据某个字段,查询数据库表中是否存在记录,不存在就新增,存在就更新
+            TargetDetectionVo targetDetectionVo1 = null;
+
+            //targetDetectionVo1 = targetDetectionService.selectBySomefield(targetDetectionVo.getSomefield());
+            if (ObjectUtil.isNull(targetDetectionVo1)) {
+                //不存在就新增
+                targetDetectionBo.setVersion(0);
+                ValidatorUtils.validate(targetDetectionBo);
+                boolean inserted = targetDetectionService.insert(targetDetectionBo);
+
+                if (inserted) {
+                    successNum++;
+                    successMsg.append("<br/>").append(successNum).append("、目标检测 记录导入成功");
+                    return;
+                } else {
+                    failureNum++;
+                    failureMsg.append("<br/>").append(failureNum).append("、目标检测 记录导入失败");
+                    return;
+                }
+            } else if (isUpdateSupport) {
+                //存在就更新
+                targetDetectionBo.setId(targetDetectionVo1.getId());//主键
+                targetDetectionBo.setVersion(targetDetectionVo1.getVersion());
+                boolean updated = targetDetectionService.update(targetDetectionBo);
+                if (updated) {
+                    successNum++;
+                    successMsg.append("<br/>").append(successNum).append("、目标检测 记录更新成功");
+                    return;
+                } else {
+                    failureNum++;
+                    failureMsg.append("<br/>").append(failureNum).append("、目标检测 记录更新失败");
+                    return;
+                }
+            }
+        } catch (Exception e) {
+            failureNum++;
+            String msg = "<br/>" + failureNum + "、目标检测 记录导入失败:";
+            failureMsg.append(msg).append(e.getMessage());
+            log.error(msg, e);
+        }
+    }
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext context) {
+
+    }
+
+    @Override
+    public ExcelResult<TargetDetectionImportVo> getExcelResult() {
+        return new ExcelResult<>() {
+
+            @Override
+            public String getAnalysis() {
+                if (failureNum > 0) {
+                    failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据没有成功导入,错误如下:");
+                    throw new ServiceException(failureMsg.toString());
+                } else {
+                    successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
+                }
+                return successMsg.toString();
+            }
+
+            @Override
+            public List<TargetDetectionImportVo> getList() {
+                return null;
+            }
+
+            @Override
+            public List<String> getErrorList() {
+                return null;
+            }
+        };
+    }
+}

+ 16 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/mapper/TargetDetectionMapper.java

@@ -0,0 +1,16 @@
+package com.taais.biz.mapper;
+
+import com.mybatisflex.core.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import com.taais.biz.domain.TargetDetection;
+
+/**
+ * 目标检测Mapper接口
+ *
+ * @author wangkang
+ * 2024-09-29
+ */
+@Mapper
+public interface TargetDetectionMapper extends BaseMapper<TargetDetection> {
+
+}

+ 70 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/ITargetDetectionService.java

@@ -0,0 +1,70 @@
+package com.taais.biz.service;
+
+import java.util.List;
+
+import com.taais.biz.domain.TargetDetection;
+import com.taais.biz.domain.vo.TargetDetectionVo;
+import com.taais.biz.domain.bo.TargetDetectionBo;
+import com.taais.common.core.core.domain.CommonResult;
+import com.taais.common.orm.core.service.IBaseService;
+import com.taais.common.core.core.page.PageResult;
+
+/**
+ * 目标检测Service接口
+ *
+ * @author wangkang
+ * 2024-09-29
+ */
+public interface ITargetDetectionService extends IBaseService<TargetDetection> {
+    /**
+     * 查询目标检测
+     *
+     * @param id 目标检测主键
+     * @return 目标检测
+     */
+        TargetDetectionVo selectById(Long id);
+
+    /**
+     * 查询目标检测列表
+     *
+     * @param targetDetectionBo 目标检测Bo
+     * @return 目标检测集合
+     */
+    List<TargetDetectionVo> selectList(TargetDetectionBo targetDetectionBo);
+
+    /**
+     * 分页查询目标检测列表
+     *
+     * @param targetDetectionBo 目标检测Bo
+     * @return 分页目标检测集合
+     */
+    PageResult<TargetDetectionVo> selectPage(TargetDetectionBo targetDetectionBo);
+
+    /**
+     * 新增目标检测
+     *
+     * @param targetDetectionBo 目标检测Bo
+     * @return 结果:true 操作成功,false 操作失败
+     */
+    boolean insert(TargetDetectionBo targetDetectionBo);
+
+    /**
+     * 修改目标检测
+     *
+     * @param targetDetectionBo 目标检测Bo
+     * @return 结果:true 更新成功,false 更新失败
+     */
+    boolean update(TargetDetectionBo targetDetectionBo);
+
+    /**
+     * 批量删除目标检测
+     *
+     * @param ids 需要删除的目标检测主键集合
+     * @return 结果:true 删除成功,false 删除失败
+     */
+    boolean deleteByIds(Long[] ids);
+
+    CommonResult start(Long id);
+
+    CommonResult stop(Long id);
+}

+ 277 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/TargetDetectionServiceImpl.java

@@ -0,0 +1,277 @@
+package com.taais.biz.service.impl;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Date;
+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.biz.constant.BizConstant;
+import com.taais.biz.domain.*;
+import com.taais.biz.domain.vo.StartToInfraredTask;
+import com.taais.biz.mapper.ToInfraredMapper;
+import com.taais.biz.utils.ZipUtils;
+import com.taais.common.core.config.TaaisConfig;
+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.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.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import com.taais.biz.mapper.TargetDetectionMapper;
+import com.taais.biz.domain.bo.TargetDetectionBo;
+import com.taais.biz.domain.vo.TargetDetectionVo;
+import com.taais.biz.service.ITargetDetectionService;
+
+import static com.taais.biz.constant.BizConstant.VideoStatus.NOT_START;
+import static com.taais.biz.domain.table.TargetDetectionTableDef.TARGET_DETECTION;
+import static com.taais.biz.service.impl.VideoStableServiceImpl.*;
+import static com.taais.biz.service.impl.VideoStableServiceImpl.sendPostMsg;
+
+/**
+ * 目标检测Service业务层处理
+ *
+ * @author wangkang
+ * 2024-09-29
+ */
+@Service
+public class TargetDetectionServiceImpl extends BaseServiceImpl<TargetDetectionMapper, TargetDetection> implements ITargetDetectionService {
+    @Value("${server.target_detection_stop_url}")
+    private String target_detection_stop_url;
+
+    @Resource
+    private TargetDetectionMapper targetDetectionMapper;
+    @Autowired
+    private ISysOssService ossService;
+
+    @Autowired
+    private AlgorithmConfigTrackServiceImpl algorithmConfigTrackService;
+    @Autowired
+    private AlgorithmModelTrackServiceImpl algorithmModelTrackService;
+
+    @Override
+    public QueryWrapper query() {
+        return super.query().from(TARGET_DETECTION);
+    }
+
+    private QueryWrapper buildQueryWrapper(TargetDetectionBo targetDetectionBo) {
+        QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
+        queryWrapper.and(TARGET_DETECTION.NAME.like
+            (targetDetectionBo.getName()));
+        queryWrapper.and(TARGET_DETECTION.STATUS.eq
+            (targetDetectionBo.getStatus()));
+        queryWrapper.and(TARGET_DETECTION.START_TIME.eq
+            (targetDetectionBo.getStartTime()));
+        queryWrapper.and(TARGET_DETECTION.END_TIME.eq
+            (targetDetectionBo.getEndTime()));
+        queryWrapper.and(TARGET_DETECTION.COST_SECOND.eq
+            (targetDetectionBo.getCostSecond()));
+        queryWrapper.and(TARGET_DETECTION.LOG.eq
+            (targetDetectionBo.getLog()));
+        queryWrapper.and(TARGET_DETECTION.REMARKS.eq
+            (targetDetectionBo.getRemarks()));
+        queryWrapper.and(TARGET_DETECTION.URL.eq
+            (targetDetectionBo.getUrl()));
+        queryWrapper.and(TARGET_DETECTION.INPUT_OSS_ID.eq
+            (targetDetectionBo.getInputOssId()));
+        queryWrapper.and(TARGET_DETECTION.INPUT_PATH.eq
+            (targetDetectionBo.getInputPath()));
+        queryWrapper.and(TARGET_DETECTION.OUTPUT_PATH.eq
+            (targetDetectionBo.getOutputPath()));
+        queryWrapper.and(TARGET_DETECTION.ZIP_FILE_PATH.eq
+            (targetDetectionBo.getZipFilePath()));
+        queryWrapper.and(TARGET_DETECTION.ALGORITHM_MODEL_ID.eq
+            (targetDetectionBo.getAlgorithmModelId()));
+
+        return queryWrapper;
+    }
+
+    /**
+     * 查询目标检测
+     *
+     * @param id 目标检测主键
+     * @return 目标检测
+     */
+    @Override
+    public TargetDetectionVo selectById(Long id) {
+        return this.getOneAs(query().where(TARGET_DETECTION.ID.eq(id)), TargetDetectionVo.class);
+
+    }
+
+    /**
+     * 查询目标检测列表
+     *
+     * @param targetDetectionBo 目标检测Bo
+     * @return 目标检测集合
+     */
+    @Override
+    public List<TargetDetectionVo> selectList(TargetDetectionBo targetDetectionBo) {
+        QueryWrapper queryWrapper = buildQueryWrapper(targetDetectionBo);
+        return this.listAs(queryWrapper, TargetDetectionVo.class);
+    }
+
+    /**
+     * 分页查询目标检测列表
+     *
+     * @param targetDetectionBo 目标检测Bo
+     * @return 分页目标检测集合
+     */
+    @Override
+    public PageResult<TargetDetectionVo> selectPage(TargetDetectionBo targetDetectionBo) {
+        QueryWrapper queryWrapper = buildQueryWrapper(targetDetectionBo);
+        Page<TargetDetectionVo> page = this.pageAs(PageQuery.build(), queryWrapper, TargetDetectionVo.class);
+        return PageResult.build(page);
+    }
+
+    /**
+     * 新增目标检测
+     *
+     * @param targetDetectionBo 目标检测Bo
+     * @return 结果:true 操作成功,false 操作失败
+     */
+    @Override
+    public boolean insert(TargetDetectionBo targetDetectionBo) {
+        // 检查input_oss_id是否存在
+        if (ObjectUtil.isNull(targetDetectionBo.getInputOssId())) {
+            return false;
+        }
+
+        SysOssVo ossEntity = ossService.getById(targetDetectionBo.getInputOssId());
+        if (ObjectUtil.isNull(ossEntity)) {
+            return false;
+        }
+
+        TargetDetection targetDetection = new TargetDetection();
+
+        targetDetection.setInputOssId(targetDetectionBo.getInputOssId());
+        targetDetection.setUrl(ossEntity.getUrl());
+
+        String filePath = ossEntity.getFileName();
+        String localPath = TaaisConfig.getProfile();
+        String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
+        targetDetection.setInputPath(resourcePath);
+
+        String fileName = StringUtils.substringAfterLast(filePath, "/");
+        String fileName_without_suffix = removeFileExtension(fileName);
+
+        Path path = Paths.get(resourcePath);
+        Path outPath = path.resolveSibling(fileName_without_suffix + "_images" + System.currentTimeMillis());
+        targetDetection.setOutputPath(outPath.toString());
+
+        targetDetection.setZipFilePath(path.resolveSibling(fileName_without_suffix + ".zip").toString());
+
+        targetDetection.setName(targetDetectionBo.getName());
+        targetDetection.setStatus(NOT_START);
+        targetDetection.setRemarks(targetDetectionBo.getRemarks());
+
+        targetDetection.setAlgorithmModelId(targetDetectionBo.getAlgorithmModelId());
+
+        return this.save(targetDetection);// 使用全局配置的雪花算法主键生成器生成ID值
+    }
+
+    /**
+     * 修改目标检测
+     *
+     * @param targetDetectionBo 目标检测Bo
+     * @return 结果:true 更新成功,false 更新失败
+     */
+    @Override
+    public boolean update(TargetDetectionBo targetDetectionBo) {
+        TargetDetection targetDetection = MapstructUtils.convert(targetDetectionBo, TargetDetection.class);
+        if (ObjectUtil.isNotNull(targetDetection) && ObjectUtil.isNotNull(targetDetection.getId())) {
+            boolean updated = this.updateById(targetDetection);
+            return updated;
+        }
+        return false;
+    }
+
+    /**
+     * 批量删除目标检测
+     *
+     * @param ids 需要删除的目标检测主键集合
+     * @return 结果:true 删除成功,false 删除失败
+     */
+    @Transactional
+    @Override
+    public boolean deleteByIds(Long[] ids) {
+        return this.removeByIds(Arrays.asList(ids));
+    }
+
+    @Override
+    public CommonResult start(Long id) {
+        TargetDetection targetDetection = getById(id);
+
+        SysOssVo inputOssEntity = ossService.getById(targetDetection.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 + "_to_infrared");
+
+        makeDir(inputPath.toString());
+        makeDir(outputPath.toString());
+
+        ZipUtils.unzip(resourcePath, inputPath.toString());
+
+        targetDetection.setInputPath(inputPath.toString());
+        targetDetection.setOutputPath(outputPath.toString());
+
+        targetDetection.setStartTime(new Date());
+
+        AlgorithmModelTrack algorithmModelTrack = algorithmModelTrackService.getById(targetDetection.getAlgorithmModelId());
+        AlgorithmConfigTrack algorithmConfigTrack = algorithmConfigTrackService.getById(algorithmModelTrack.getAlgorithmId());
+
+        StartToInfraredTask startToInfraredTask = new StartToInfraredTask();
+        startToInfraredTask.setBizId(targetDetection.getId());
+
+        // if (algorithmConfigTrack.getType() == AlgorithmType.TRAIN) {
+        startToInfraredTask.setModel_path(algorithmModelTrack.getModelAddress());
+        // }
+
+        startToInfraredTask.setOtherParams(algorithmConfigTrack.getParameterConfig());
+        startToInfraredTask.setSource_dir(targetDetection.getInputPath());
+        startToInfraredTask.setResult_dir(targetDetection.getOutputPath());
+
+        HttpResponseEntity responseEntity = sendPostMsg(algorithmConfigTrack.getAlgorithmAddress(), startToInfraredTask);
+        if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
+            targetDetection.setStatus(BizConstant.VideoStatus.RUNNING);
+            updateById(targetDetection);
+            return CommonResult.success("任务开始成功,请等待完成");
+        } else {
+            targetDetection.setStatus(BizConstant.VideoStatus.FAILED);
+            updateById(targetDetection);
+            return CommonResult.fail("任务开始失败,请检查!");
+        }
+    }
+
+    @Override
+    public CommonResult stop(Long id) {
+        TargetDetection targetDetection = getById(id);
+
+        HttpResponseEntity responseEntity = sendPostMsg(target_detection_stop_url, targetDetection);
+        if (ObjectUtil.isNotNull(responseEntity) && responseEntity.getStatus() == 200) {
+            targetDetection.setStatus(BizConstant.VideoStatus.INTERRUPTED);
+            updateById(targetDetection);
+            return CommonResult.fail("终止任务成功");
+        } else {
+            return CommonResult.fail("终止任务失败");
+        }
+    }
+}

+ 0 - 4
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/TrackSequenceServiceImpl.java

@@ -51,10 +51,6 @@ import static com.taais.biz.service.impl.VideoStableServiceImpl.makeDir;
  */
 @Service
 public class TrackSequenceServiceImpl extends BaseServiceImpl<TrackSequenceMapper, TrackSequence> implements ITrackSequenceService {
-
-    @Value("${server.track_sequence_start_url}")
-    private String track_sequence_start_url;
-
     @Value("${server.track_sequence_stop_url}")
     private String track_sequence_stop_url;
 

+ 7 - 0
taais-modules/taais-biz/src/main/resources/mapper/demo/TargetDetectionMapper.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.taais.biz.mapper.TargetDetectionMapper">
+
+</mapper>