|
@@ -0,0 +1,79 @@
|
|
|
+package com.persagy.dmp.rwd.digital.service.strategy;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.annotation.AnnotationUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.persagy.dmp.common.exception.BusinessException;
|
|
|
+import com.persagy.dmp.common.helper.SpringHelper;
|
|
|
+import com.persagy.dmp.rwd.basic.constant.BusinessErrorRwdCode;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.lang.reflect.AnnotatedElement;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class CalculationRelatingContext {
|
|
|
+
|
|
|
+ private Map<String,CalculatingRelationService> beanMap;
|
|
|
+
|
|
|
+
|
|
|
+ * Description: 初始化关系计算策略类
|
|
|
+ * @return : void
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/7 15:53
|
|
|
+ * Update By lijie 2021/9/7 15:53
|
|
|
+ */
|
|
|
+ @PostConstruct
|
|
|
+ private void initCalculatingRelationClass(){
|
|
|
+ beanMap=new HashMap<>();
|
|
|
+
|
|
|
+ Map<String, CalculatingRelationService> serviceMap =
|
|
|
+ SpringHelper.getBeansOfType(CalculatingRelationService.class);
|
|
|
+ if (MapUtil.isEmpty(serviceMap)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Map.Entry<String, CalculatingRelationService>> entries = serviceMap.entrySet();
|
|
|
+ for (Map.Entry<String, CalculatingRelationService> entry : entries) {
|
|
|
+ Relation relation = AnnotationUtil.getAnnotation(entry.getValue().getClass(), Relation.class);
|
|
|
+ if (StrUtil.isBlank(relation.graphCode())
|
|
|
+ || StrUtil.isBlank(relation.relCode())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(relation.relValue())){
|
|
|
+ beanMap.put(relation.graphCode()+StrUtil.UNDERLINE
|
|
|
+ +relation.relCode()+StrUtil.UNDERLINE+relation.relValue(),entry.getValue());
|
|
|
+ }else {
|
|
|
+ beanMap.put(relation.graphCode()+StrUtil.UNDERLINE+relation.relCode(),entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Description:获取关系计算策略处理类
|
|
|
+ * @param graphCode : 图类型编码
|
|
|
+ * @param relCode : 关系编码
|
|
|
+ * @return : com.persagy.dmp.rwd.digital.service.strategy.CalculatingRelationService
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/7 15:55
|
|
|
+ * Update By lijie 2021/9/7 15:55
|
|
|
+ */
|
|
|
+ public CalculatingRelationService getCalculatingRelationService(String graphCode,String relCode,String relValue){
|
|
|
+ if (StrUtil.isBlank(graphCode)
|
|
|
+ || StrUtil.isBlank(relCode)){
|
|
|
+ throw new BusinessException(BusinessErrorRwdCode.A7307.getCode(),BusinessErrorRwdCode.A7307.getDesc());
|
|
|
+ }
|
|
|
+ String key = graphCode+StrUtil.UNDERLINE+relCode;
|
|
|
+ if (StrUtil.isNotBlank(relValue)){
|
|
|
+ key=key+StrUtil.UNDERLINE+relValue;
|
|
|
+ }
|
|
|
+ if (!beanMap.containsKey(key)){
|
|
|
+ throw new BusinessException(BusinessErrorRwdCode.A7308.getCode(),BusinessErrorRwdCode.A7308.getDesc());
|
|
|
+ }
|
|
|
+ return beanMap.get(key);
|
|
|
+ }
|
|
|
+}
|