dengsixing 5 месяцев назад
Родитель
Сommit
b509963ada

+ 30 - 0
src/main/java/com/fdkankan/contro/constant/DetectType.java

@@ -0,0 +1,30 @@
+package com.fdkankan.contro.constant;
+
+/**
+ * 用户状态
+ *
+ * @author fdkk
+ */
+public enum DetectType
+{
+    PANO(1, "全景图识别"), PLAN(2, "平面图识别");
+
+    private final Integer code;
+    private final String info;
+
+    DetectType(Integer code, String info)
+    {
+        this.code = code;
+        this.info = info;
+    }
+
+    public Integer getCode()
+    {
+        return code;
+    }
+
+    public String getInfo()
+    {
+        return info;
+    }
+}

+ 78 - 0
src/main/java/com/fdkankan/contro/entity/SceneMarkShape.java

@@ -0,0 +1,78 @@
+package com.fdkankan.contro.entity;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * <p>
+ * 场景标记多边形识别数据
+ * </p>
+ *
+ * @author Xiewj
+ * @date 2023/3/30
+ */
+@Data
+@TableName(value = "t_scene_mark_shape",autoResultMap = true)
+@Accessors(chain = true)
+public class SceneMarkShape implements Serializable {
+
+      /**
+       * 主键
+       */
+      @TableId(value = "id", type = IdType.AUTO)
+      private Long id;
+
+      @TableField("version")
+      private String version;
+      @TableField(typeHandler = FastjsonTypeHandler.class, value = "flag")
+      private JSONObject flag;
+
+      @TableField(typeHandler = FastjsonTypeHandler.class, value = "shapes")
+      private List<JSONObject> shapes;
+
+      @TableField("image_path")
+      private String imagePath;
+      @TableField("image_height")
+      private Integer imageHeight;
+      @TableField("image_width")
+      private Integer imageWidth;
+      @TableField("num")
+      private String num;
+      /**
+       * 0不需要 1需要
+       */
+      @TableField("re_train")
+      private Integer reTrain;
+      /**
+       * 0需要训练 1已经训练过
+       */
+      @TableField("to_train")
+      private Integer toTrain;
+
+      @TableField("create_time")
+      private Date createTime;
+
+      @TableField("update_time")
+      private Date updateTime;
+
+      /**
+       * 记录的状态,A: 生效,I: 禁用
+       */
+      @TableField("rec_status")
+      @TableLogic(value = "A", delval = "I")
+      private String recStatus;
+
+      /**
+       * 推理类型 1,全景图识别 2,平面图识别
+       */
+      @TableField("type")
+      private Integer type;
+
+}

+ 61 - 0
src/main/java/com/fdkankan/contro/entity/SceneShapeEnum.java

@@ -0,0 +1,61 @@
+package com.fdkankan.contro.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+
+/**
+ * 标注框模型表
+ *
+ * @author Xiewj
+ * @since 2023-11-09 11:53
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@TableName("t_scene_shape_enum")
+public class SceneShapeEnum {
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 属性名
+     */
+    private String name;
+
+    /**
+     * 类名
+     */
+    private String className;
+
+    /**
+     * 资源类型ID
+     */
+    private String resourceId;
+
+    /**
+     * 设备类型ID
+     */
+    private String typeId;
+
+    /**
+     * 记录的状态,A: 生效,I: 禁用
+     */
+    private String recStatus;
+
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+}

+ 20 - 0
src/main/java/com/fdkankan/contro/mapper/MarkShapeMapper.java

@@ -0,0 +1,20 @@
+package com.fdkankan.contro.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fdkankan.contro.entity.SceneMarkShape;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/22
+ */
+@Mapper
+public interface MarkShapeMapper extends BaseMapper<SceneMarkShape> {
+
+}
+

+ 16 - 0
src/main/java/com/fdkankan/contro/mapper/SceneShapeEnumMapper.java

@@ -0,0 +1,16 @@
+package com.fdkankan.contro.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fdkankan.contro.entity.SceneShapeEnum;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Component;
+
+/**
+* 标注框模型表 Mapper
+*
+* @author Xiewj
+* @since 2023-11-09 11:53
+*/
+@Mapper
+public interface SceneShapeEnumMapper extends BaseMapper<SceneShapeEnum> {
+}

+ 11 - 0
src/main/java/com/fdkankan/contro/service/IAiService.java

@@ -0,0 +1,11 @@
+package com.fdkankan.contro.service;
+
+import com.fdkankan.contro.entity.SceneMarkShape;
+
+public interface IAiService {
+
+    void detectScenePano(String num, String path);
+
+    SceneMarkShape readDetectJson(String jsonPath);
+
+}

+ 13 - 0
src/main/java/com/fdkankan/contro/service/ISceneMarkShapeService.java

@@ -0,0 +1,13 @@
+package com.fdkankan.contro.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.contro.entity.SceneMarkShape;
+
+/**
+ * Created by Xiewj on 2021/11/23 0026 10:14
+ */
+public interface ISceneMarkShapeService extends IService<SceneMarkShape> {
+    SceneMarkShape findByNumAndImagePathAndType(String num, String imagePath,Integer type);
+
+}

+ 16 - 0
src/main/java/com/fdkankan/contro/service/SceneShapeEnumService.java

@@ -0,0 +1,16 @@
+package com.fdkankan.contro.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.contro.entity.SceneShapeEnum;
+
+/**
+ * 标注框模型表 服务类接口
+ *
+ * @author Xiewj
+ * @since 2023-11-09 11:53
+ */
+public interface SceneShapeEnumService extends IService<SceneShapeEnum> {
+
+      SceneShapeEnum findByClassName(String className);
+}

+ 111 - 0
src/main/java/com/fdkankan/contro/service/impl/AiServiceImpl.java

@@ -0,0 +1,111 @@
+package com.fdkankan.contro.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.contro.constant.DetectType;
+import com.fdkankan.contro.entity.SceneMarkShape;
+import com.fdkankan.contro.entity.SceneShapeEnum;
+import com.fdkankan.contro.service.*;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import com.fdkankan.model.constants.ConstantFilePath;
+import com.fdkankan.model.constants.UploadFilePath;
+import com.fdkankan.model.utils.ComputerUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@Service
+public class AiServiceImpl implements IAiService {
+
+    @Autowired
+    private IScenePlusService scenePlusService;
+    @Autowired
+    private IScenePlusExtService scenePlusExtService;
+    @Resource
+    private FYunFileServiceInterface fYunFileService;
+    @Autowired
+    private SceneShapeEnumService sceneShapeEnumService;
+    @Autowired
+    private ISceneMarkShapeService sceneMarkShapeService;
+
+    @Override
+    public void detectScenePano(String num, String path) {
+
+        String resultsPath = path + File.separator + "results" + File.separator;
+        String highPath = resultsPath + "high" + File.separator;
+        String aiWorkPath = highPath + "ai" + File.separator;
+        List<File> highImgs = FileUtil.loopFiles(highPath);
+        if(CollUtil.isEmpty(highImgs)){
+            return;
+        }
+
+        for (File file : highImgs) {
+            String absolutePath = file.getAbsolutePath();
+            try {
+                String name = FileUtil.getName(absolutePath);
+                String prefix = FileUtil.getPrefix(name);
+                String outPath = aiWorkPath + prefix + File.separator;
+                String detectPath = outPath + "detect.json";
+                String cutImagesPath = outPath + "cut_images";
+                if(!ComputerUtil.checkComputeCompleted(detectPath, 5, 200)){
+                    continue;
+                }
+                SceneMarkShape sceneMarkShape = readDetectJson(detectPath);
+                if (ObjectUtil.isNotNull(sceneMarkShape)){
+                    sceneMarkShape.setNum(num);
+                    SceneMarkShape shape = sceneMarkShapeService.findByNumAndImagePathAndType(num, sceneMarkShape.getImagePath(), DetectType.PANO.getCode());
+                    if (ObjectUtil.isNotNull(shape)){
+                        sceneMarkShape.setId(shape.getId());
+                        sceneMarkShape.setUpdateTime(new Date());
+                        sceneMarkShapeService.updateById(sceneMarkShape);
+                    }else {
+                        sceneMarkShape.setCreateTime(new Date());
+                        sceneMarkShape.setType(DetectType.PANO.getCode());
+                        sceneMarkShapeService.save(sceneMarkShape);
+                    }
+                }
+                if (FileUtil.exist(cutImagesPath)){
+                    //上传这个文件夹所有的文件
+                    List<File> files = FileUtil.loopFiles(cutImagesPath);
+                    String keyPath =  String.format(UploadFilePath.IMG_VIEW_PATH, num) + "cut_images/";
+                    files.forEach(v -> fYunFileService.uploadFile(v.getAbsolutePath(),keyPath+v.getName()));
+                }
+
+            }catch (Exception e){
+                log.error("ai识别报错,inPath:{}", absolutePath, e);
+            }
+        }
+    }
+
+    @Override
+    public SceneMarkShape readDetectJson(String jsonPath) {
+        String strings = FileUtil.readString(jsonPath, "UTF-8");
+        JSONObject bbbb = JSONObject.parseObject(strings);
+        SceneMarkShape parse = JSONObject.toJavaObject(bbbb, SceneMarkShape.class);
+        System.out.println(parse);
+        if (ObjectUtil.isNull(parse.getShapes())){
+            return null;
+        }
+        List<JSONObject> shapes = parse.getShapes();
+        for (JSONObject shape : shapes) {
+            shape.remove("name");
+            SceneShapeEnum category = sceneShapeEnumService.findByClassName(shape.getString("category"));
+            if (ObjectUtil.isNull(category)){
+                SceneShapeEnum sceneShapeEnum = new SceneShapeEnum();
+                sceneShapeEnum.setName(shape.getString("name"));
+                sceneShapeEnum.setClassName(shape.getString("category"));
+                sceneShapeEnumService.save(sceneShapeEnum);
+            }
+        }
+        return parse;
+    }
+
+}

+ 35 - 0
src/main/java/com/fdkankan/contro/service/impl/SceneMarkShapeServiceImpl.java

@@ -0,0 +1,35 @@
+package com.fdkankan.contro.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.contro.entity.SceneMarkShape;
+import com.fdkankan.contro.mapper.MarkShapeMapper;
+import com.fdkankan.contro.service.ISceneMarkShapeService;
+import com.fdkankan.contro.service.SceneShapeEnumService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * Created by Xiewj on 2021/11/23 0026 10:14
+ */
+@Slf4j
+@Service
+public class SceneMarkShapeServiceImpl extends ServiceImpl<MarkShapeMapper, SceneMarkShape> implements ISceneMarkShapeService {
+
+    @Autowired
+    SceneShapeEnumService sceneShapeEnumService;
+
+    @Override
+    public SceneMarkShape findByNumAndImagePathAndType(String num, String imagePath, Integer type) {
+        LambdaQueryWrapper<SceneMarkShape> wrapper = Wrappers.lambdaQuery();
+        wrapper.eq(SceneMarkShape::getNum,num);
+        wrapper.eq(SceneMarkShape::getImagePath,imagePath);
+        wrapper.eq(SceneMarkShape::getType,type);
+        return getOne(wrapper);
+    }
+
+
+}

+ 24 - 0
src/main/java/com/fdkankan/contro/service/impl/SceneShapeEnumServiceImpl.java

@@ -0,0 +1,24 @@
+package com.fdkankan.contro.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.contro.entity.SceneShapeEnum;
+import com.fdkankan.contro.mapper.SceneShapeEnumMapper;
+import com.fdkankan.contro.service.SceneShapeEnumService;
+import org.springframework.stereotype.Service;
+
+/**
+ * 标注框模型表 服务实现类
+ *
+ * @author Xiewj
+ * @since 2023-11-09 11:53
+ */
+@Service
+public class SceneShapeEnumServiceImpl extends ServiceImpl<SceneShapeEnumMapper, SceneShapeEnum> implements SceneShapeEnumService {
+    @Override
+    public SceneShapeEnum findByClassName(String className) {
+        return this.getOne(new LambdaQueryWrapper<SceneShapeEnum>().eq(SceneShapeEnum::getClassName, className));
+    }
+
+
+}