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

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

@@ -0,0 +1,30 @@
+package com.fdkankan.contro.controller;
+
+/**
+ * 用户状态
+ *
+ * @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;
+
+}

+ 5 - 0
src/main/java/com/fdkankan/contro/entity/ScenePlus.java

@@ -129,4 +129,9 @@ public class ScenePlus implements Serializable {
     private String recStatus;
 
 
+    /**
+     * 是否有平面图i识别
+     */
+    @TableField("has_floorplan_ai")
+    private Integer hasFloorplanAi;
 }

+ 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;
+}

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

@@ -0,0 +1,23 @@
+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
+@Component("MarkShapeMapper")
+public interface MarkShapeMapper extends BaseMapper<SceneMarkShape> {
+
+    List<SceneMarkShape> selectByNumAndImagePaths(@Param("num")String num, @Param("imagePaths") Set<String> imagePaths);
+
+}
+

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

@@ -0,0 +1,17 @@
+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
+@Component("SceneShapeEnumMapper")
+public interface SceneShapeEnumMapper  extends BaseMapper<SceneShapeEnum> {
+}

+ 12 - 0
src/main/java/com/fdkankan/contro/mq/service/impl/BuildSceneServiceImpl.java

@@ -476,6 +476,18 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             //江门需求,算法识别平面图
             commonService.uploadFloorplanAi(sceneCode, path);
 
+            boolean detFloorplan = false;
+            Map<String, Object> ext = message.getExt();
+            if(CollUtil.isNotEmpty(ext) && ext.containsKey("detFloorplan") && Objects.nonNull(ext.get("detFloorplan"))){
+                detFloorplan = (Boolean) ext.get("detFloorplan");
+            }
+            boolean hasFloorplanAi = commonService.detFloorPlanAi(sceneCode, path, detFloorplan);
+            if(hasFloorplanAi){
+                scenePlus.setHasFloorplanAi(CommonStatus.YES.code().intValue());
+            }else{
+                scenePlus.setHasFloorplanAi(CommonStatus.NO.code().intValue());
+            }
+
             //重置异步操作记录
             commonService.removeSceneAsynOperLog(sceneCode);
 

+ 4 - 1
src/main/java/com/fdkankan/contro/service/ICommonService.java

@@ -5,6 +5,7 @@ import com.fdkankan.contro.entity.*;
 import com.fdkankan.contro.vo.ScenePlusVO;
 import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
 
+import java.io.IOException;
 import java.util.Map;
 import java.util.Set;
 
@@ -55,5 +56,7 @@ public interface ICommonService {
 
     void sendSceneStatus(String num, String uuid, String batchId, Integer status);
 
-    void uploadFloorplanAi(String num, String path);
+    void uploadFloorplanAi(String num, String path) throws IOException;
+
+    boolean detFloorPlanAi(String num, String path, boolean detFloorplan) throws IOException;
 }

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

@@ -0,0 +1,21 @@
+package com.fdkankan.contro.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.contro.entity.SceneMarkShape;
+
+import java.util.List;
+
+/**
+ * Created by Xiewj on 2021/11/23 0026 10:14
+ */
+public interface ISceneMarkShapeService extends IService<SceneMarkShape> {
+
+    SceneMarkShape readDetectJson(String jsonPath);
+
+    List<SceneMarkShape> readDetectJsonStr(String num,String context);
+
+    SceneMarkShape findByNumAndImagePathAndType(String num, String imagePath,Integer type);
+
+    List<SceneMarkShape> findByNumAndType(String num,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);
+}

+ 69 - 6
src/main/java/com/fdkankan/contro/service/impl/CommonServiceImpl.java

@@ -3,6 +3,7 @@ package com.fdkankan.contro.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
@@ -16,6 +17,7 @@ import com.fdkankan.common.constant.SceneStatus;
 import com.fdkankan.common.constant.SpaceType;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.contro.bean.SceneJsonBean;
+import com.fdkankan.contro.controller.DetectType;
 import com.fdkankan.contro.entity.*;
 import com.fdkankan.contro.factory.UserEditData.UserEditDataHandler;
 import com.fdkankan.contro.factory.UserEditData.UserEditDataHandlerFactory;
@@ -43,6 +45,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -116,6 +119,10 @@ public class CommonServiceImpl implements ICommonService {
     private RabbitMqProducer rabbitMqProducer;
     @Autowired
     private ISceneInfoSyncMqConfigService sceneInfoSyncMqConfigService;
+    @Autowired
+    private ISceneMarkShapeService sceneMarkShapeService;
+    @Autowired
+    private SceneShapeEnumService sceneShapeEnumService;
 
     @Override
     public void uploadBuildResultData(String num, String dataSource, String version) {
@@ -569,16 +576,72 @@ public class CommonServiceImpl implements ICommonService {
     }
 
     @Override
-    public void uploadFloorplanAi(String num, String path) {
+    public void uploadFloorplanAi(String num, String path) throws IOException {
         String floorplanPath = path + "/results/floorplan/";
         List<File> files = FileUtil.loopFiles(floorplanPath);
-        if(CollUtil.isEmpty(files)){
-            return;
-        }
         String ossPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan/";
-        for (File file : files) {
-            fYunFileService.uploadFile(file.getAbsolutePath(), file.getAbsolutePath().replace(floorplanPath, ossPath));
+        if(CollUtil.isNotEmpty(files)){
+            for (File file : files) {
+                fYunFileService.uploadFile(file.getAbsolutePath(), file.getAbsolutePath().replace(floorplanPath, ossPath));
+            }
         }
+    }
+
+    @Override
+    public boolean detFloorPlanAi(String num, String path, boolean detFloorplan) throws IOException {
+        String workDir = path + "/detFloorplan/";
+        String detectPath = workDir + "detect.json";
+        try {
+            if (detFloorplan) {
+                return false;
+            }
+            SceneMarkShape sceneMarkShape = sceneMarkShapeService.readDetectJson(detectPath);
+            if (ObjectUtil.isNull(sceneMarkShape)){
+                return false;
+            }
+            sceneMarkShape.setNum(num);
+            SceneMarkShape shape = sceneMarkShapeService.findByNumAndImagePathAndType(num, sceneMarkShape.getImagePath(), DetectType.PLAN.getCode());
+            if (ObjectUtil.isNotNull(shape)){
+                sceneMarkShape.setId(shape.getId());
+                sceneMarkShape.setUpdateTime(new Date());
+                sceneMarkShapeService.updateById(sceneMarkShape);
+            }else {
+                sceneMarkShape.setCreateTime(new Date());
+                sceneMarkShape.setType(DetectType.PLAN.getCode());
+                sceneMarkShapeService.save(sceneMarkShape);
+            }
+
+            List<SceneMarkShape> sceneMarkShapes = sceneMarkShapeService.findByNumAndType(num, DetectType.PLAN.getCode());
+            for (SceneMarkShape ms : sceneMarkShapes) {
+                if (ObjectUtil.isNotEmpty(ms.getShapes())){
+                    for (JSONObject s : ms.getShapes()) {
+                        String category = s.getString("category");
+                        SceneShapeEnum sceneShapeEnum = sceneShapeEnumService.findByClassName(category);
+                        if (ObjectUtil.isNotNull(sceneShapeEnum)){
+                            s.put("name",sceneShapeEnum.getName());
+                        }
+                        if (category.contains("Tag_")){
+                            s.put("category","Tag");
+                        }
+                    }
+                }
+            }
 
+            String aiJsonKey = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "floorplan/ai.json";
+            if(CollUtil.isNotEmpty(sceneMarkShapes)){
+                fYunFileService.uploadFile(JSON.toJSONString(sceneMarkShapes).getBytes(StandardCharsets.UTF_8), aiJsonKey);
+                return true;
+            }else{
+                fYunFileService.deleteFile(aiJsonKey);
+                return false;
+            }
+        }catch (Exception e){
+            log.error("平面图ai识别处理报错", e);
+            return false;
+        }finally {
+            FileUtil.del(workDir);
+        }
     }
+
+
 }

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

@@ -0,0 +1,95 @@
+package com.fdkankan.contro.service.impl;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+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.controller.DetectType;
+import com.fdkankan.contro.entity.SceneMarkShape;
+import com.fdkankan.contro.entity.SceneShapeEnum;
+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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * Created by Xiewj on 2021/11/23 0026 10:14
+ */
+@Slf4j
+@Service
+public class SceneMarkShapeServiceImpl extends ServiceImpl<MarkShapeMapper, SceneMarkShape> implements ISceneMarkShapeService {
+    @Autowired
+    private SceneShapeEnumService sceneShapeEnumService;
+
+    @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) {
+            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;
+    }
+
+
+    @Override
+    public List<SceneMarkShape> readDetectJsonStr(String num,String context) {
+        JSONObject bbbb = JSONObject.parseObject(context);
+        JSONArray imgBoxsList = bbbb.getJSONArray("imgBoxsList");
+        List<SceneMarkShape> list = new ArrayList<>();
+        for (Object o : imgBoxsList) {
+            SceneMarkShape parse = JSONObject.toJavaObject(JSONObject.parseObject(String.valueOf(o)), SceneMarkShape.class);
+            System.out.println(parse);
+            if (ObjectUtil.isNull(parse.getShapes())){
+                return null;
+            }
+            parse.setType(DetectType.PANO.getCode());
+            parse.setNum(num);
+            List<JSONObject> shapes = parse.getShapes();
+            for (JSONObject shape : shapes) {
+                shape.remove("name");
+            }
+            list.add(parse);
+        }
+
+        return list;
+    }
+
+    @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);
+    }
+
+    @Override
+    public List<SceneMarkShape> findByNumAndType(String num,Integer type) {
+        LambdaQueryWrapper<SceneMarkShape> wrapper = Wrappers.lambdaQuery();
+        wrapper.eq(SceneMarkShape::getNum,num);
+        wrapper.eq(SceneMarkShape::getType,type);
+        return list(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));
+    }
+
+
+}