csw 4 months ago
parent
commit
6aa22c92c5

+ 6 - 0
pom.xml

@@ -68,6 +68,12 @@
         <!--<version>1.0</version>-->
         <!--</dependency>-->
 
+        <dependency>
+            <groupId>com.ecnu.pojo</groupId>
+            <artifactId>ecnu-alg-pojo</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+
     </dependencies>
 
 

+ 2 - 2
sql/db.sql

@@ -39,8 +39,8 @@ CREATE TABLE ALG_VERSION (
      THIRD_GKEY           VARCHAR(50) NOT NULL                            COMMENT '第三方主键',
      ALG_GKEY             VARCHAR(50) NOT NULL                            COMMENT '算法主键',
      VERSION              VARCHAR(100)                                    COMMENT '在用版本号',
-     IS_CALL              tinyint(1)                                      COMMENT '是否调用',
-     IS_ONLINE            tinyint(1)                                      COMMENT '是否在线',
+     IS_CALL              tinyint(1)  default 0                           COMMENT '是否调用',
+     IS_ONLINE            tinyint(1)  default 0                           COMMENT '是否在线',
      SERVICE_ID           VARCHAR(100)                                    COMMENT '算法服务ID',
      SERVICE_ADDRESS      VARCHAR(500)                                    COMMENT '服务地址信息',
      REQUEST_MODE         VARCHAR(100)                                    COMMENT '请求方式',

+ 4 - 2
src/main/java/com/ecnu/platform/service/AlgExecutionLogService.groovy

@@ -35,9 +35,11 @@ class AlgExecutionLogService extends BaseEntityServiceImpl {
             throw new ParamException("分页参数(" + ParamName.pageSize + "," + ParamName.pageIndex + ")不可以为空")
         }
         if (StringUtil.isNotBlankStr(map.get("versionGkey"))) {
-            Map<String, Object> simpleFilter = new HashMap<>();
+            if (map.get("simpleFilter") == null) {
+                map.put("simpleFilter", new HashMap())
+            }
+            Map<String, Object> simpleFilter = map.get("simpleFilter") as Map<String, Object>;
             simpleFilter.put("versionGkey", map.get("versionGkey"))
-            map.put("simpleFilter", simpleFilter)
         }
         return daoService.findAuq(EN_AlgExeLogVo, map)
     }

+ 41 - 0
src/main/java/com/ecnu/platform/service/AlgVersionVoService.groovy

@@ -1,6 +1,7 @@
 package com.ecnu.platform.service
 
 import com.three.common.exception.ParamException
+import com.three.common.utils.GroovyUtil
 import com.three.common.utils.StringUtil
 import com.three.common.vo.SelectOption
 import com.three.data_api.dm.annos.BizApiMethod
@@ -51,11 +52,21 @@ class AlgVersionVoService extends BaseEntityServiceImpl {
 
     @Override
     void create(Map<String, Object> map) throws Exception {
+        // 获取入参值Map
+        Map paras = (map.get("paras") as List<Map>)[0]
+        if (StringUtil.isNotBlank(paras.get("isOnline")) && 1== paras.get("isOnline")) {
+            checkOnline(paras.get("algGkey") as String, null)
+        }
         super.create(map)
     }
 
     @Override
     void update(Map<String, Object> map) throws Exception {
+        // 获取入参值Map
+        Map paras = (map.get("paras") as List<Map>)[0]
+        if (StringUtil.isNotBlank(paras.get("isOnline")) && 1== paras.get("isOnline")) {
+            checkOnline(paras.get("algGkey") as String, paras.get("gkey") as String)
+        }
         super.update(map)
     }
 
@@ -68,4 +79,34 @@ class AlgVersionVoService extends BaseEntityServiceImpl {
     void recover(Map<String, Object> map) throws Exception {
         super.recover(map)
     }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "修改算法在线状态")
+    void updateOnline(@BizRequestPm(key = "gkey", nullable = false, desc = "算法版本主键") String gkey) throws Exception {
+        Object object = findOneObject(EN_AlgVersion, gkey)
+        // 如果将是否在线状态设置成1,则需要校验该算法是否已经存在其他第三方的算法在线
+        int flag = (int) GroovyUtil.getProperty(object, "isOnline")
+        if (flag == 0) {
+            checkOnline(GroovyUtil.getProperty(object, "algGkey") as String, null)
+            flag = 1
+        } else {
+            flag = 0
+        }
+        Map<String, Object> valueMap = new HashMap<>()
+        valueMap.put("isOnline", flag)
+        daoService.updateMetaEntityByGkey(EN_AlgVersion, valueMap, gkey)
+    }
+
+    private checkOnline(String algGkey, String gkey) {
+        Map whereValueMap = new HashMap()
+        whereValueMap.put("algGkey", algGkey)
+        String sql = "select gkey from ALG_VERSION where IS_DELETED = 0 and ALG_GKEY = :algGkey and IS_ONLINE = 1"
+        if (StringUtil.isNotBlank(gkey)) {
+            sql += " and gkey != :gkey"
+            whereValueMap.put("gkey", gkey)
+        }
+        List<Object> objectList = daoService.findListWithSql(EN_AlgVersion, sql, null, whereValueMap)
+        if (objectList.size() > 0) {
+            throw new ParamException("已经存在其他第三方算法在线")
+        }
+    }
 }

+ 178 - 0
src/main/java/com/ecnu/platform/service/PathStrategyDataService.groovy

@@ -0,0 +1,178 @@
+package com.ecnu.platform.service
+
+import com.ecnu.alg.pojo.path.inputs.AlgBaseMap
+import com.ecnu.alg.pojo.path.inputs.AlgBaseMapArea
+import com.ecnu.alg.pojo.path.inputs.AlgObstacle
+import com.ecnu.alg.pojo.path.inputs.AlgParkSpace
+import com.ecnu.alg.pojo.path.inputs.AlgVehicle
+import com.ecnu.alg.pojo.path.inputs.AlgVehicleTask
+import com.three.common.exception.ParamException
+import com.three.data_api.dm.annos.BizApiMethod
+import com.three.data_api.dm.annos.BizRequestPm
+import com.three.data_api.dm.annos.Doc4MethodRes
+import com.three.data_api.dm.constants.ThreeConstant
+import com.three.redis.utils.RedisUtil
+import org.springframework.beans.factory.annotation.Autowired
+
+class PathStrategyDataService {
+
+    public static final String AlgBaseMapKey = "path:AlgBaseMap:"
+    public static final String AlgVehicleKey = "path:AlgVehicle:"
+    public static final String AlgBaseMapAreaKey = "path:AlgBaseMapArea:"
+    public static final String AlgObstacleKey = "path:AlgObstacle:"
+    public static final String AlgParkSpaceKey = "path:AlgParkSpace:"
+    public static final String AlgVehicleTaskKey = "path:AlgVehicleTask:"
+
+    public static final String conn = "-"
+
+    @Autowired
+    private RedisUtil redisUtil;
+
+//    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "初始化底图信息")
+//    @Doc4MethodRes(key = "result", desc = "底图信息", refClasses = AlgBaseMap.class)
+//    AlgBaseMap initBaseMap(@BizRequestPm(key = "id", nullable = false, desc = "底图ID") String id,
+//                           @BizRequestPm(key = "name", nullable = false, desc = "底图名称") String name,
+//                           @BizRequestPm(key = "pcsBorder", nullable = false, desc = "平面坐标边界") String pcsBorder) throws Exception {
+//        AlgBaseMap algBaseMap = new AlgBaseMap()
+//        algBaseMap.setId(id)
+//        algBaseMap.setName(name)
+//        algBaseMap.setPcsBorder(pcsBorder)
+//        return algBaseMap
+//    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "初始化底图信息")
+    @Doc4MethodRes(key = "result", desc = "底图信息", refClasses = AlgBaseMap.class)
+    AlgBaseMap initBaseMap(@BizRequestPm(key = "body", nullable = false, desc = "底图信息") AlgBaseMap algBaseMap) throws Exception {
+        redisUtil.set(AlgBaseMapKey + algBaseMap.getId(), algBaseMap)
+        return algBaseMap
+    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "查询所有底图信息")
+    @Doc4MethodRes(key = "result", desc = "底图信息", refClasses = AlgBaseMap.class)
+    List<AlgBaseMap> queryAllBaseMap(Map<String, Object> map) throws Exception {
+        redisUtil.getByPrefix(AlgBaseMapKey + "*") as List<AlgBaseMap>
+    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "查询所有底图要素")
+    @Doc4MethodRes(key = "result", desc = "底图要素信息", refClasses = [AlgVehicle.class, AlgBaseMapArea.class, AlgObstacle.class, AlgParkSpace.class])
+    Map<String, Object> queryAllElement(@BizRequestPm(key = "mapId", nullable = false, desc = "底图ID") String mapId) throws Exception {
+        Map<String, Object> reMap = new HashMap<>()
+        List<AlgVehicle> algVehicleList = redisUtil.getByPrefix(AlgVehicleKey + mapId + conn + "*") as List<AlgVehicle>
+        List<AlgBaseMapArea> algBaseMapAreaList = redisUtil.getByPrefix(AlgBaseMapAreaKey + mapId + conn + "*") as List<AlgBaseMapArea>
+        List<AlgObstacle> algObstacleList = redisUtil.getByPrefix(AlgObstacleKey + mapId + conn + "*") as List<AlgObstacle>
+        List<AlgParkSpace> algParkSpaceList = redisUtil.getByPrefix(AlgParkSpaceKey + mapId + conn + "*") as List<AlgParkSpace>
+        reMap.put("algVehicleList", algVehicleList)
+        reMap.put("algBaseMapAreaList", algBaseMapAreaList)
+        reMap.put("algObstacleList", algObstacleList)
+        reMap.put("algParkSpaceList", algParkSpaceList)
+        return reMap;
+    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "新增选取点")
+    void createPoint(@BizRequestPm(key = "mapId", nullable = false, desc = "底图ID") String mapId,
+                     @BizRequestPm(key = "position", nullable = false, desc = "坐标点") String position,
+                     @BizRequestPm(key = "elementType", nullable = false, desc = "点类型") String elementType,
+                     @BizRequestPm(key = "id", nullable = false, desc = "编号") String id) throws Exception {
+        AlgVehicle algVehicle = new AlgVehicle();
+        algVehicle.setMapId(mapId)
+        algVehicle.setVehicleNo(id)
+        algVehicle.setCurPosition(position)
+        redisUtil.set(AlgVehicleKey + mapId + conn + id, algVehicle)
+    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "新增绘制矩形")
+    void createRectangle(@BizRequestPm(key = "mapId", nullable = false, desc = "底图ID") String mapId,
+                         @BizRequestPm(key = "position", nullable = false, desc = "矩形坐标") String position,
+                         @BizRequestPm(key = "elementType", nullable = false, desc = "点类型") String elementType,
+                         @BizRequestPm(key = "id", nullable = false, desc = "编号") String id,
+                         @BizRequestPm(key = "name", desc = "名称") String name) throws Exception {
+        if ("parkSpace".equals(elementType)) {
+            AlgParkSpace algParkSpace = new AlgParkSpace();
+            algParkSpace.setMapId(mapId)
+            algParkSpace.setId(id)
+            algParkSpace.setPcsBorder(position)
+            redisUtil.set(AlgParkSpaceKey + mapId + conn + id, algParkSpace)
+        } else if ("obstacle".equals(elementType)) {
+            AlgObstacle algObstacle = new AlgObstacle();
+            algObstacle.setMapId(mapId)
+            algObstacle.setId(id)
+            algObstacle.setName(name)
+            algObstacle.setPcsBorder(position)
+            redisUtil.set(AlgObstacleKey + mapId + conn + id, algObstacle)
+        } else if ("baseMapArea".equals(elementType)) {
+            AlgBaseMapArea algBaseMapArea = new AlgBaseMapArea();
+            algBaseMapArea.setMapId(mapId)
+            algBaseMapArea.setId(id)
+            algBaseMapArea.setPcsBorder(position)
+            redisUtil.set(AlgBaseMapAreaKey + mapId + conn + id, algBaseMapArea)
+        } else {
+            throw new ParamException("类型(" + elementType + ")暂不支持")
+        }
+    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "新增绘制区域")
+    void createRegion(@BizRequestPm(key = "mapId", nullable = false, desc = "底图ID") String mapId,
+                      @BizRequestPm(key = "position", nullable = false, desc = "区域坐标") String position,
+                      @BizRequestPm(key = "elementType", nullable = false, desc = "点类型") String elementType,
+                      @BizRequestPm(key = "id", nullable = false, desc = "编号") String id,
+                      @BizRequestPm(key = "name", desc = "名称") String name) throws Exception {
+        if ("parkSpace".equals(elementType)) {
+            AlgParkSpace algParkSpace = new AlgParkSpace();
+            algParkSpace.setMapId(mapId)
+            algParkSpace.setId(id)
+            algParkSpace.setPcsBorder(position)
+            redisUtil.set(AlgParkSpaceKey + mapId + conn + id, algParkSpace)
+        } else if ("obstacle".equals(elementType)) {
+            AlgObstacle algObstacle = new AlgObstacle();
+            algObstacle.setMapId(mapId)
+            algObstacle.setId(id)
+            algObstacle.setName(name)
+            algObstacle.setPcsBorder(position)
+            redisUtil.set(AlgObstacleKey + mapId + conn + id, algObstacle)
+        } else if ("baseMapArea".equals(elementType)) {
+            AlgBaseMapArea algBaseMapArea = new AlgBaseMapArea();
+            algBaseMapArea.setMapId(mapId)
+            algBaseMapArea.setId(id)
+            algBaseMapArea.setPcsBorder(position)
+            redisUtil.set(AlgBaseMapAreaKey + mapId + conn + id, algBaseMapArea)
+        } else {
+            throw new ParamException("类型(" + elementType + ")暂不支持")
+        }
+    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "删除元素")
+    void deleteElement(@BizRequestPm(key = "mapId", nullable = false, desc = "底图ID") String mapId,
+                       @BizRequestPm(key = "elementType", nullable = false, desc = "底图要素类型") String elementType,
+                       @BizRequestPm(key = "id", nullable = false, desc = "编号") String id) throws Exception {
+        if ("parkSpace".equals(elementType)) {
+            redisUtil.del(AlgParkSpaceKey + mapId + conn + id)
+        } else if ("obstacle".equals(elementType)) {
+            redisUtil.del(AlgObstacleKey + mapId + conn + id)
+        } else if ("baseMapArea".equals(elementType)) {
+            redisUtil.del(AlgBaseMapAreaKey + mapId + conn + id)
+        } else {
+            throw new ParamException("类型(" + elementType + ")暂不支持")
+        }
+    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "新增车辆任务")
+    void createVehicleTask(@BizRequestPm(key = "mapId", nullable = false, desc = "底图ID") String mapId,
+                           @BizRequestPm(key = "vehicleNo", nullable = false, desc = "车辆编号") String vehicleNo,
+                           @BizRequestPm(key = "startPosition", nullable = false, desc = "起点位置") String startPosition,
+                           @BizRequestPm(key = "endPosition", nullable = false, desc = "终点位置") String endPosition) throws Exception {
+        AlgVehicleTask algVehicleTask = new AlgVehicleTask();
+        algVehicleTask.setMapId(mapId)
+        algVehicleTask.setVehicleNo(vehicleNo)
+        algVehicleTask.setStartPosition(startPosition)
+        algVehicleTask.setEndPosition(endPosition)
+        redisUtil.set(AlgVehicleTaskKey + mapId + conn + vehicleNo, algVehicleTask)
+    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "查询车辆任务")
+    @Doc4MethodRes(key = "result", desc = "底图信息", refClasses = AlgVehicleTask.class)
+    AlgVehicleTask queryVehicleTask(@BizRequestPm(key = "mapId", nullable = false, desc = "底图ID") String mapId,
+                                    @BizRequestPm(key = "vehicleNo", nullable = false, desc = "车辆编号") String vehicleNo) throws Exception {
+        return redisUtil.getByPrefix(AlgVehicleTaskKey + mapId + conn + vehicleNo) as AlgVehicleTask
+    }
+
+}