csw 3 mēneši atpakaļ
vecāks
revīzija
3d06f34279

+ 6 - 0
pom.xml

@@ -74,6 +74,12 @@
             <version>1.0-SNAPSHOT</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.cwp</groupId>
+            <artifactId>IOService</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+
     </dependencies>
 
 

+ 57 - 18
src/main/java/com/ecnu/platform/cwp/CwpDataService.groovy

@@ -1,6 +1,6 @@
 package com.ecnu.platform.cwp
 
-import com.ecnu.alg.pojo.port.data.AlgCwpImportData
+import com.ecnu.alg.pojo.port.datas.AlgCwpInputData
 import com.ecnu.alg.pojo.port.inputs.AlgBollard
 import com.ecnu.alg.pojo.port.inputs.AlgCraneBase
 import com.ecnu.alg.pojo.port.inputs.AlgCranePool
@@ -47,9 +47,9 @@ class CwpDataService {
     private RedisUtil redisUtil;
 
     @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "导入CWP算法数据")
-    @Doc4MethodRes(key = "result", desc = "底图信息", refClasses = AlgCwpImportData.class)
-    AlgCwpImportData importData(Map<String, Object> map) throws Exception {
-        AlgCwpImportData algCwpImportData = new AlgCwpImportData();
+    @Doc4MethodRes(key = "result", desc = "底图信息", refClasses = AlgCwpInputData.class)
+    AlgCwpInputData importData(Map<String, Object> map) throws Exception {
+        AlgCwpInputData algCwpInputData = new AlgCwpInputData();
         List<AlgBollard> algBollardList = redisUtil.getByPrefix(AlgBollardKey + "*") as List<AlgBollard>
         Collections.sort(algBollardList, new Comparator<AlgBollard>() {
             @Override
@@ -88,7 +88,7 @@ class CwpDataService {
             }
             algVesselVisit.setBerthDirection(smartScheduleIdInfo.get("planBerthDirect") as String)
             redisUtil.set(AlgVesselVisitKey + algVesselVisit.getVesselVisitId(), algVesselVisit)
-            algCwpImportData.getAlgVesselVisitList().add(algVesselVisit)
+            algCwpInputData.getAlgVesselVisitList().add(algVesselVisit)
             vesselVisitId = algVesselVisit.getVesselVisitId();
         }
         // 解析桥机信息
@@ -107,7 +107,7 @@ class CwpDataService {
             algCraneBase.setDschMph(smartCraneBaseInfo.get("unLoadEfficiency40") as Integer)
             algCraneBase.setTandemFlag(smartCraneBaseInfo.get("tandemFlag") as String)
             redisUtil.set(AlgCraneBaseKey + algCraneBase.getCraneId(), algCraneBase)
-            algCwpImportData.getAlgCraneBaseList().add(algCraneBase)
+            algCwpInputData.getAlgCraneBaseList().add(algCraneBase)
         }
         // 解析作业工艺设置信息
         List<Map> smartCraneWorkFlowInfoList = map.get("smartCraneWorkFlowInfoList") as List<Map>
@@ -121,7 +121,7 @@ class CwpDataService {
             algWorkFlow.setTandem(smartCraneWorkFlowInfo.get("tandem") == true ? "Y" : "N")
             algWorkFlow.setLdStrategy(smartCraneWorkFlowInfo.get("ldStrategy") as String)
             redisUtil.set(AlgWorkFlowKey + algWorkFlow.getVesselVisitId() + ":" + algWorkFlow.getHatchGkey(), algWorkFlow)
-            algCwpImportData.getAlgWorkFlowList().add(algWorkFlow)
+            algCwpInputData.getAlgWorkFlowList().add(algWorkFlow)
         }
         // 船舶结构相关
         // 解析舱位信息
@@ -139,7 +139,7 @@ class CwpDataService {
             algVstHatch.setType("H")
             algVstHatch.setGapM(1.0)
             algVstHatchMap.put(algVstHatch.getGkey(), algVstHatch)
-            algCwpImportData.getAlgVstHatchList().add(algVstHatch)
+            algCwpInputData.getAlgVstHatchList().add(algVstHatch)
         }
         // 解析倍位信息
         Map<String, AlgVstBay> algVstBayMap = new HashMap<>()
@@ -156,7 +156,7 @@ class CwpDataService {
             if (algVstHatch != null) {
                 algVstHatch.getBayNos().add(algVstBay.getNo())
                 algVstHatch.getBayInfos().add(algVstBay)
-                algCwpImportData.getAlgVstBayList().add(algVstBay)
+                algCwpInputData.getAlgVstBayList().add(algVstBay)
             }
         }
         // 解析排信息
@@ -235,10 +235,10 @@ class CwpDataService {
             }
         }
         // 存入缓存
-        for (AlgVstBay algVstBay : algCwpImportData.getAlgVstBayList()) {
+        for (AlgVstBay algVstBay : algCwpInputData.getAlgVstBayList()) {
             redisUtil.set(AlgVstBayKey + algVstBay.getVesselStructGkey() + ":" + algVstBay.getGkey(), algVstBay)
         }
-        for (AlgVstHatch algVstHatch : algCwpImportData.getAlgVstHatchList()) {
+        for (AlgVstHatch algVstHatch : algCwpInputData.getAlgVstHatchList()) {
             List<AlgVstBay> bayInfos = new ArrayList<>()
             for (AlgVstBay algVstBay : algVstHatch.getBayInfos()) {
                 AlgVstBay algVstBay1 = new AlgVstBay()
@@ -260,8 +260,6 @@ class CwpDataService {
             AlgVstHatchCover algVstHatchCover = new AlgVstHatchCover()
             algVstHatchCover.setGkey(smartVpsVslHatchcoversInfo.get("hatchCoverId") as String)
             algVstHatchCover.setVesselStructGkey(smartVpsVslHatchcoversInfo.get("vesselCode") as String)
-            algVstHatchCover.setHatchCoverId(smartVpsVslHatchcoversInfo.get("hatchCoverId") as String)
-            algVstHatchCover.setHatchCoverNo(smartVpsVslHatchcoversInfo.get("hatchCoverNo") as String)
             algVstHatchCover.setOpenSeq(smartVpsVslHatchcoversInfo.get("openSeq") as Integer)
             // 查询倍位信息
             Set<String> bayNos = new HashSet<>()
@@ -281,7 +279,7 @@ class CwpDataService {
             algVstHatchCover.setDeckToRowNo(smartVpsVslHatchcoversInfo.get("deckToRowNo") as String)
             algVstHatchCover.setWeightMt(smartVpsVslHatchcoversInfo.get("weight") as Double)
             redisUtil.set(AlgVstHatchCoverKey + algVstHatchCover.getVesselStructGkey() + ":" + algVstHatchCover.getGkey(), algVstHatchCover)
-            algCwpImportData.getAlgVstHatchCoverList().add(algVstHatchCover)
+            algCwpInputData.getAlgVstHatchCoverList().add(algVstHatchCover)
         }
         // 解析桥机池信息
         String poolId = null
@@ -299,11 +297,11 @@ class CwpDataService {
                     AlgCranePool algCranePool = new AlgCranePool()
                     algCranePool.setVesselVisitId(vesselVisitId)
                     algCranePool.setCraneId(smartCranePoolInfo.get("craneNo") as String)
-                    algCwpImportData.getAlgCranePoolList().add(algCranePool)
+                    algCwpInputData.getAlgCranePoolList().add(algCranePool)
                 }
             }
         }
-        redisUtil.set(AlgCranePoolKey + vesselVisitId, algCwpImportData.getAlgCranePoolList())
+        redisUtil.set(AlgCranePoolKey + vesselVisitId, algCwpInputData.getAlgCranePoolList())
         // 解析预配/积载信息
         Map<String, List<AlgStowDetail>> algStowDetailListMap = new HashMap<>()
         List<Map> smartVesselContainerInfoList = map.get("smartVesselContainerInfoList") as List<Map>
@@ -378,7 +376,7 @@ class CwpDataService {
                 algStowDetail.setUgIsHazardous(0)
             }
             algStowDetail.setTotalWeightKg(smartVesselContainerInfo.get("weight") as Double)
-            algCwpImportData.getAlgStowDetailList().add(algStowDetail)
+            algCwpInputData.getAlgStowDetailList().add(algStowDetail)
             algStowDetailListMap.putIfAbsent(algStowDetail.getVesselVisitId(), new ArrayList<AlgStowDetail>())
             algStowDetailListMap.get(algStowDetail.getVesselVisitId()).add(algStowDetail)
         }
@@ -387,6 +385,47 @@ class CwpDataService {
         }
         // 解析属性组信息
 
-        return algCwpImportData
+        return algCwpInputData
+    }
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "查询CWP输入数据")
+    AlgCwpInputData queryAll(@BizRequestPm(key = "id", nullable = false, desc = "船舶航次主键,多个用英文逗号隔开") String id) throws Exception {
+        AlgCwpInputData algCwpInputData = new AlgCwpInputData();
+        // 查询船期信息
+        String[] ids = id.split(",");
+        for (String vesselVisitId : ids) {
+            AlgVesselVisit algVesselVisit = redisUtil.get(AlgVesselVisitKey + vesselVisitId) as AlgVesselVisit
+            algCwpInputData.getAlgVesselVisitList().add(algVesselVisit)
+        }
+        // 查询桥机信息
+        List<AlgCraneBase> algCraneBaseList = redisUtil.getByPrefix(AlgCraneBaseKey + "*") as List<AlgCraneBase>
+        algCwpInputData.setAlgCraneBaseList(algCraneBaseList)
+        // 查询作业桥机信息
+        for (String vesselVisitId : ids) {
+            List<AlgCranePool> algCranePoolList = redisUtil.get(AlgCranePoolKey + vesselVisitId) as List<AlgCranePool>
+            algCwpInputData.getAlgCranePoolList().addAll(algCranePoolList)
+        }
+        // 查询预配、积载信息
+        for (String vesselVisitId : ids) {
+            List<AlgStowDetail> algStowDetailList = redisUtil.get(AlgStowDetailKey + vesselVisitId) as List<AlgStowDetail>
+            algCwpInputData.getAlgStowDetailList().addAll(algStowDetailList)
+        }
+        // 查询船舶结构
+        // 查询倍位
+        for (AlgVesselVisit algVesselVisit : algCwpInputData.getAlgVesselVisitList()) {
+            List<AlgVstBay> algVstBayList = redisUtil.getByPrefix(AlgVstBayKey + algVesselVisit.getVesselCode() + ":*") as List<AlgVstBay>
+            algCwpInputData.getAlgVstBayList().addAll(algVstBayList)
+        }
+        // 查询舱位
+        for (AlgVesselVisit algVesselVisit : algCwpInputData.getAlgVesselVisitList()) {
+            List<AlgVstHatch> algVstHatchList = redisUtil.getByPrefix(AlgVstHatchKey + algVesselVisit.getVesselCode() + ":*") as List<AlgVstHatch>
+            algCwpInputData.getAlgVstHatchList().addAll(algVstHatchList)
+        }
+        // 查询舱盖板
+        for (AlgVesselVisit algVesselVisit : algCwpInputData.getAlgVesselVisitList()) {
+            List<AlgVstHatchCover> algVstHatchCoverList = redisUtil.getByPrefix(AlgVstHatchCoverKey + algVesselVisit.getVesselCode() + ":*") as List<AlgVstHatchCover>
+            algCwpInputData.getAlgVstHatchCoverList().addAll(algVstHatchCoverList)
+        }
+        return algCwpInputData
     }
 }

+ 22 - 0
src/main/java/com/ecnu/platform/cwp/CwpService.groovy

@@ -0,0 +1,22 @@
+package com.ecnu.platform.cwp
+
+import com.cwp.ioservice.impl.CwpDoServiceImpl
+import com.ecnu.alg.pojo.port.datas.AlgCwpInputData
+import com.ecnu.alg.pojo.port.datas.AlgCwpResultData
+import com.ecnu.alg.pojo.port.results.AlgReMessage
+import com.three.data_api.dm.annos.BizApiMethod
+import com.three.data_api.dm.annos.BizRequestPm
+import com.three.data_api.dm.constants.ThreeConstant
+
+class CwpService {
+
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "执行CWP算法")
+    AlgCwpResultData doPlanCwp(@BizRequestPm(key = "body", nullable = false, desc = "CWP算法输入数据") AlgCwpInputData algCwpInputData) {
+        AlgCwpResultData algCwpResultData = new AlgCwpResultData()
+        CwpDoServiceImpl cwpDoService = new CwpDoServiceImpl();
+        cwpDoService.doPlanCwp(algCwpInputData, algCwpResultData)
+        AlgReMessage algReMessage = algCwpResultData.getAlgReMessage()
+        algReMessage.setVersion("22222")
+        return algCwpResultData
+    }
+}

+ 4 - 2
src/main/java/com/ecnu/platform/port/CwpBlockVoService.groovy

@@ -36,8 +36,10 @@ class CwpBlockVoService {
         // 查询作业块信息
         List<AlgReCwpBlock> algReCwpBlocks = new ArrayList<>()
         for (String tmlCvGkey : tmlCvGkeys) {
-            List<AlgReCwpBlock> algReCwpBlockList = redisUtil.getByPrefix(AlgReCwpBlockKey + tmlCvGkey + ":*") as List<AlgReCwpBlock>
-            algReCwpBlocks.addAll(algReCwpBlockList)
+            List<AlgReCwpBlock> algReCwpBlockList = redisUtil.get(AlgReCwpBlockKey + tmlCvGkey) as List<AlgReCwpBlock>
+            if (algReCwpBlockList != null) {
+                algReCwpBlocks.addAll(algReCwpBlockList)
+            }
         }
         // 返回结果
         AuqResult auqResult = new AuqResult();

+ 76 - 35
src/main/java/com/ecnu/platform/service/AlgExecutionService.groovy

@@ -1,14 +1,20 @@
 package com.ecnu.platform.service
 
 import com.ecnu.alg.pojo.path.data.AlgPathStrategyInputData
-import com.ecnu.alg.pojo.path.data.AlgPathStrategyOutputData
-import com.ecnu.alg.pojo.path.inputs.AlgVehicleTask
-import com.ecnu.alg.pojo.path.results.AlgRePathResult
+import com.ecnu.alg.pojo.path.data.AlgPathStrategyResultData
+import com.ecnu.alg.pojo.path.results.AlgReMessage
+import com.ecnu.alg.pojo.port.datas.AlgCwpInputData
+import com.ecnu.alg.pojo.port.datas.AlgCwpResultData
+import com.ecnu.alg.pojo.port.results.AlgReCwp
+import com.ecnu.alg.pojo.port.results.AlgReCwpBlock
+import com.ecnu.platform.cwp.CwpDataService
+import com.ecnu.platform.path.PathStrategyDataService
 import com.three.common.constants.RedisKeyPrefix
 import com.three.common.exception.ParamException
 import com.three.common.utils.GroovyUtil
 import com.three.common.utils.GsonUtil
 import com.three.common.utils.StringUtil
+import com.three.common.vo.ResponseData
 import com.three.data_api.dm.annos.BizApiMethod
 import com.three.data_api.dm.annos.BizRequestPm
 import com.three.data_api.dm.constants.ThreeConstant
@@ -26,10 +32,11 @@ import org.springframework.http.HttpMethod
 import org.springframework.http.ResponseEntity
 import org.springframework.web.client.RestTemplate
 
-import java.lang.reflect.Method
 
 class AlgExecutionService {
 
+    public static final String AlgReCwpBlockKey = "port:AlgReCwpBlock:"
+
     private static Logger logger = LoggerFactory.getLogger(AlgExecutionService.class)
 
     @Autowired
@@ -41,11 +48,11 @@ class AlgExecutionService {
     @Autowired
     private BeanService beanService;
 
-    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "执行路线规划算法")
-    void exePathStrategy(@BizRequestPm(key = "mapId", nullable = false, desc = "底图ID") String mapId,
-                         @BizRequestPm(key = "versionGkey", nullable = false, desc = "算法版本主键") String versionGkey) {
+    @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "执行算法")
+    void exeAlg(@BizRequestPm(key = "id", nullable = false, desc = "底图ID/船舶航次主键(多个用英文逗号隔开)") String id,
+                @BizRequestPm(key = "versionGkey", nullable = false, desc = "算法版本主键") String versionGkey) {
         // 查询算法版本信息
-        Object algVersionObj = daoService.findOneByGkey(AlgVersionVoService.EN_AlgVersion, versionGkey)
+        Object algVersionObj = daoService.findOneByGkey(AlgVersionVoService.EN_AlgVersionVo, versionGkey)
         if (algVersionObj == null) {
             throw new ParamException("算法版本不存在")
         }
@@ -62,53 +69,87 @@ class AlgExecutionService {
         if (StringUtil.isBlank(interfaceName)) {
             throw new ParamException("算法版本接口名称为空")
         }
-        // 根据底图ID,查询路线规划算法需要的数据
-        Object pathStrategyDataService = beanService.getBeanById("PathStrategyDataService");
-        Method method = pathStrategyDataService.getClass().getMethod("queryAll", String.class)
-        AlgPathStrategyInputData algPathStrategyInputData = method.invoke(pathStrategyDataService, mapId) as AlgPathStrategyInputData
-        String inDataStr = GsonUtil.toJson(algPathStrategyInputData)
-        // 调用算法接口
+        // 算法调用记录
         Map<String, Object> valueMap = new HashMap<>()
         valueMap.put("versionGkey", versionGkey)
-        valueMap.put("shipId", mapId)
+        valueMap.put("shipId", id)
         valueMap.put("runVersion", GroovyUtil.getProperty(algVersionObj, "version"))
         long st = System.currentTimeMillis()
         try {
-            logger.info("路线规划算法开始执行。。。")
-            HttpHeaders headers = new HttpHeaders()
+            logger.info("算法[{}:{}]执行开始。。。", GroovyUtil.getProperty(algVersionObj, "algDefId"), GroovyUtil.getProperty(algVersionObj, "version"))
             // 获取账号token
+            HttpHeaders headers = new HttpHeaders()
             String reToken = (String) redisUtil.get(RedisKeyPrefix.AUTH_KEY_PREFIX_USER_TOKEN + LoginUserUtil.getLoginUsername() + RedisKeyPrefix.tokenKeyCon + "web");
             headers.add("Authorization", "Bearer " + reToken)
-            HttpEntity<AlgPathStrategyInputData> request = new HttpEntity<>(algPathStrategyInputData, headers)
-            RestTemplate restTemplate = new RestTemplate();
-            ResponseEntity<AlgPathStrategyOutputData> result = restTemplate.exchange(serviceAddress + "/" + interfaceName, HttpMethod.POST, request, AlgPathStrategyOutputData.class)
-            AlgPathStrategyOutputData algPathStrategyOutputData = result.getBody()
-            String outDataStr = GsonUtil.toJson(algPathStrategyOutputData);
-            valueMap.put("outData", outDataStr)
-            logger.info("路线规划算法返回结果:{}", outDataStr)
-            // 记录算法日志
-            if (algPathStrategyOutputData.getAlgReMessage() != null) {
-                valueMap.put("exeLog", algPathStrategyOutputData.getAlgReMessage().getExeLog())
-                valueMap.put("errorLog", algPathStrategyOutputData.getAlgReMessage().getErrorLog())
+            // restTemplate
+            RestTemplate restTemplate = new RestTemplate()
+            if ("PathStrategy".equals(GroovyUtil.getProperty(algVersionObj, "algDefId"))) {
+                // 根据ID,查询算法输入数据
+                PathStrategyDataService pathStrategyDataService = beanService.getBeanById(PathStrategyDataService.class.getSimpleName());
+                AlgPathStrategyInputData algPathStrategyInputData = pathStrategyDataService.queryAll(id)
+                String inDataStr = GsonUtil.toJson(algPathStrategyInputData)
+                valueMap.put("inData", inDataStr)
+                HttpEntity<AlgPathStrategyInputData> request = new HttpEntity<>(algPathStrategyInputData, headers)
+                // 调用算法
+                ResponseEntity<AlgPathStrategyResultData> result = restTemplate.exchange(serviceAddress + "/" + interfaceName, HttpMethod.POST, request, AlgPathStrategyResultData.class)
+                // 算法输出数据
+                AlgPathStrategyResultData algPathStrategyOutputData = result.getBody()
+                String outDataStr = GsonUtil.toJson(algPathStrategyOutputData);
+                valueMap.put("outData", outDataStr)
+                AlgReMessage algReMessage = algPathStrategyOutputData.getAlgReMessage()
+                // 记录算法日志
+                if (algReMessage != null) {
+                    valueMap.put("exeLog", algReMessage.getExeLog())
+                    valueMap.put("errorLog", algReMessage.getErrorLog())
+                }
+            } else if ("Cwp".equals(GroovyUtil.getProperty(algVersionObj, "algDefId"))) {
+                // 根据ID,查询算法输入数据
+                CwpDataService cwpDataService = beanService.getBeanById(CwpDataService.class.getSimpleName());
+                AlgCwpInputData algCwpInputData = cwpDataService.queryAll(id)
+                String inDataStr = GsonUtil.toJson(algCwpInputData)
+                valueMap.put("inData", inDataStr)
+                HttpEntity<AlgCwpInputData> request = new HttpEntity<>(algCwpInputData, headers)
+                // 调用算法
+                ResponseEntity<ResponseData> result = restTemplate.exchange(serviceAddress + "/" + interfaceName, HttpMethod.POST, request, ResponseData.class)
+                ResponseData responseData = result.getBody()
+                // 算法输出数据
+                String outDataStr = GsonUtil.toJson(responseData.getResult());
+                AlgCwpResultData algCwpResultData = GsonUtil.fromJsonObject(outDataStr, AlgCwpResultData.class)
+                // 将算法结果保存到缓存中
+                saveCwpResult(algCwpResultData)
+                valueMap.put("outData", outDataStr)
+                com.ecnu.alg.pojo.port.results.AlgReMessage algReMessage = algCwpResultData.getAlgReMessage()
+                // 记录算法日志
+                if (algReMessage != null) {
+                    valueMap.put("exeLog", algReMessage.getExecuteLog())
+                    valueMap.put("errorLog", algReMessage.getErrorLog())
+                }
+            } else if ("AutoStow".equals(GroovyUtil.getProperty(algVersionObj, "algDefId"))) {
+
             }
             valueMap.put("exeState", "OK")
+            logger.info("算法[{}:{}]执行结束。", GroovyUtil.getProperty(algVersionObj, "algDefId"), GroovyUtil.getProperty(algVersionObj, "version"))
         } catch (Exception e) {
-            logger.info("路线规划算法执行异常:", e)
+            logger.info("算法[{}:{}]执行异常:", GroovyUtil.getProperty(algVersionObj, "algDefId"), GroovyUtil.getProperty(algVersionObj, "version"), e)
             valueMap.put("exeState", "ERROR")
             valueMap.put("errorLog", ExceptionUtils.getStackTrace(e))
         }
         long et = System.currentTimeMillis()
         valueMap.put("costTime", et - st)
         valueMap.put("callSource", "test")
-        valueMap.put("inData", inDataStr)
         // 记录算法执行日志
         daoService.insertMetaEntityDefault(AlgExecutionLogService.EN_AlgExecutionLog, valueMap)
     }
 
-    AlgPathStrategyOutputData doPathStrategy(AlgPathStrategyInputData algPathStrategyInputData) {
-        AlgPathStrategyOutputData algPathStrategyOutputData = new AlgPathStrategyOutputData()
-        algPathStrategyOutputData.setAlgRePathResultList(new ArrayList<AlgRePathResult>())
-
-        return algPathStrategyOutputData
+    void saveCwpResult(AlgCwpResultData algCwpResultData) {
+        for (AlgReCwp algReCwp : algCwpResultData.getAlgReCwpList()) {
+            List<AlgReCwpBlock> algReCwpBlockList = algReCwp.getAlgReCwpBlockList()
+            for (AlgReCwpBlock algReCwpBlock : algReCwpBlockList) {
+                algReCwpBlock.setTmlCvGkey(algReCwp.getVesselVisitId())
+            }
+            redisUtil.set(AlgReCwpBlockKey + algReCwp.getVesselVisitId(), algReCwpBlockList)
+            // 默认取第一个结果
+            break
+        }
     }
 }