Jelajahi Sumber

数据模型

yangyj 7 bulan lalu
induk
melakukan
03de292578
17 mengubah file dengan 171 tambahan dan 27 penghapusan
  1. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/AdvancePaymentCertificate.java
  2. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/BaseInfo.java
  3. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/ConstructionSchedule.java
  4. 145 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/DataModel.java
  5. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/InterimMeter.java
  6. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/InterimMeterPaySummary.java
  7. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/InterimPaymentCertificate.java
  8. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/InterimPaymentSummary.java
  9. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/MaterialAdvancePayment.java
  10. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/MaterialPriceDifferential.java
  11. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/MaterialsArrival.java
  12. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/MeterPeriodInfo.java
  13. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/SubInterimMeterPaySummary.java
  14. 1 1
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/SubprojectInterimPaymentSummary.java
  15. 5 7
      blade-service/blade-manager/src/main/java/com/mixsmart/utils/FormulaUtils.java
  16. 4 4
      blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeController.java
  17. 4 3
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreePrivateServiceImpl.java

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/AdvancePaymentCertificate.java

@@ -9,7 +9,7 @@ import lombok.Data;
  * @description 开工预付款支付证书
  */
 @Data
-public class AdvancePaymentCertificate {
+public class AdvancePaymentCertificate implements  DataModel{
     public static final String ID="20280000000";
     public static final String TBN="APayCert";
     public static final String TBN_CH="开工预付款支付证书";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/BaseInfo.java

@@ -12,7 +12,7 @@ import java.math.BigDecimal;
  * @description 基础信息
  */
 @Data
-public class BaseInfo  {
+public class BaseInfo  implements  DataModel{
     public static final String ID="20100000000";
     public static final String TBN="BSI";
     public static final String TBN_CH="合同信息";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/ConstructionSchedule.java

@@ -12,7 +12,7 @@ import java.util.List;
  * @description 施工进度表
  */
 @Data
-public class ConstructionSchedule {
+public class ConstructionSchedule implements  DataModel{
     public static final String ID="20320000000";
     public static final String TBN="ConSch";
     public static final String TBN_CH="施工进度表";

+ 145 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/DataModel.java

@@ -0,0 +1,145 @@
+package org.springblade.manager.vo;
+import cn.hutool.log.StaticLog;
+import com.alibaba.fastjson.annotation.JSONField;
+import org.springblade.common.utils.BaseUtils;
+import org.springblade.core.tool.utils.StringPool;
+
+import java.lang.reflect.Field;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author yangyj
+ * @Date 2023/4/22 10:55
+ * @description 数据模型接口
+ */
+public  interface DataModel {
+        List<Class<?>> classes=new ArrayList<>();
+        /*扫描路径*/
+        String PATH="org.springblade.manager.vo";
+ /*       static void main(String[] args) {
+            List<Class<?>> classes = findClassesByInterface("org.springblade.manager.vo", DataModel.class);
+            Map<String,List<WbsFormElementVO>> MODEL_MAP = new LinkedHashMap<>();
+            classes.forEach(c->{
+                MODEL_MAP.put(getStaticFieldValue(c,"ID"),toElementVos(c));
+            });
+            System.out.println();
+        }*/
+
+    String TBN_FN="TBN";
+    /*把模型类转换成共识配置选项*/
+    static List<WbsFormElementVO> toElementVos(Class<?> clazz)  {
+        List<WbsFormElementVO> list =new ArrayList<>();
+        try {
+            Field tbnField = clazz.getField(TBN_FN);
+            String TBN = (String) tbnField.get(null);
+            for (Field field : clazz.getDeclaredFields()) {
+                JSONField jf = field.getAnnotation(JSONField.class);
+                if (jf != null) {
+                    WbsFormElementVO vo = new WbsFormElementVO();
+                    vo.setEName(jf.label());
+                    vo.setTableElementKey(TBN+ StringPool.COLON +jf.name());
+                    vo.setInitTableName(TBN);
+                    vo.setId(BaseUtils.str2Long(vo.getTableElementKey()));
+                    list.add(vo);
+                }
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return list;
+    }
+      static LinkedHashMap<String,List<WbsFormElementVO>> getElements(){
+          LinkedHashMap<String,List<WbsFormElementVO>> map = new LinkedHashMap<>();
+          if(classes.size()==0) {
+              classes.addAll(findClassesByInterface(PATH, DataModel.class));
+          }
+          classes.forEach(c->{
+              map.put(getStaticFieldValue(c,"ID"),toElementVos(c));
+          });
+          return map;
+      }
+
+        static List<TreeNodeVOByTabType> getTreeNodeList(){
+            if(classes.size()==0) {
+                classes.addAll(findClassesByInterface(PATH, DataModel.class));
+            }
+        return  classes.stream().map(c -> {
+               TreeNodeVOByTabType tn = new TreeNodeVOByTabType();
+               tn.setTitle(getStaticFieldValue(c,"TBN_CH"));
+               tn.setTabType(SelectorModel.NODE_NAME);
+               tn.setParentId(SelectorModel.ID);
+               String id=getStaticFieldValue(c,"ID");
+               assert id != null;
+               tn.setId(Long.parseLong(id));
+               tn.setPrimaryKeyId(id);
+               tn.setInitTableId(id);
+               tn.setHasChildren(false);
+               tn.setInitTableName(getStaticFieldValue(c,"TBN"));
+               return tn;
+           }).collect(Collectors.toList());
+        }
+
+        /*获取静态变量值*/
+        static String getStaticFieldValue(Class<?> clazz,String fieldName){
+            try {
+                Field idField = clazz.getField(fieldName);
+                return (String)idField.get(null);
+            } catch (NoSuchFieldException | IllegalAccessException e) {
+                StaticLog.error(e.getMessage());
+            }
+            return null;
+        }
+
+        /*扫描指定包,并获取所有实现DataModel的类,按照ID排序返回*/
+        static List<Class<?>> findClassesByInterface(String packageName, Class<?> interfaceClass) {
+            List<Class<?>> targetList = new ArrayList<>();
+            Map<Class<?>, String> classIdMap = new HashMap<>();
+            try {
+                ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+                String path = packageName.replace('.', '/');
+                java.net.URL resource = classLoader.getResource(path);
+                if (resource == null) {
+                    return targetList;
+                }
+                java.io.File dir = new java.io.File(resource.getFile());
+                if (!dir.exists()) {
+                    return targetList;
+                }
+                java.io.File[] files = dir.listFiles();
+                if (files == null) {
+                    return targetList;
+                }
+                for (java.io.File file : files) {
+                    String fileName = file.getName();
+                    if (fileName.endsWith(".class")) {
+                        String className = packageName + '.' + fileName.substring(0, fileName.length() - 6);
+                        try {
+                            Class<?> clazz = Class.forName(className);
+                            if (interfaceClass.isAssignableFrom(clazz) && !clazz.isInterface()) {
+                                try {
+                                    Field idField = clazz.getField("ID");
+                                    String idValue = (String) idField.get(null);
+                                    classIdMap.put(clazz, idValue);
+                                } catch (NoSuchFieldException | IllegalAccessException e) {
+                                    StaticLog.error(e.getMessage());
+                                }
+                                targetList.add(clazz);
+                            }
+                        } catch (ClassNotFoundException e) {
+                            StaticLog.error(e.getMessage());
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                StaticLog.error(e.getMessage());
+            }
+            targetList.sort((c1, c2) -> {
+                String id1 = classIdMap.get(c1);
+                String id2 = classIdMap.get(c2);
+                return id1.compareTo(id2);
+            });
+            return targetList;
+        }
+
+}

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/InterimMeter.java

@@ -13,7 +13,7 @@ import java.util.List;
  * @description 中间计量表
  */
 @Data
-public class InterimMeter {
+public class InterimMeter implements  DataModel{
     public static final String ID="20270000000";
     public static final String TBN="IMeter";
     public static final String TBN_CH="中间计量表";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/InterimMeterPaySummary.java

@@ -9,7 +9,7 @@ import lombok.Data;
  * @description 中间计量支付汇总表
  */
 @Data
-public class InterimMeterPaySummary {
+public class InterimMeterPaySummary implements  DataModel{
     public static final String ID="20260000000";
     public static final String TBN="IMeterPaySum";
     public static final String TBN_CH="中间计量支付汇总表";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/InterimPaymentCertificate.java

@@ -13,7 +13,7 @@ import java.math.RoundingMode;
  * @description 中期支付证书
  */
 @Data
-public class InterimPaymentCertificate {
+public class InterimPaymentCertificate implements  DataModel{
     public static final String ID="20210000000";
     public static final String TBN="IPayCert";
     public static final String TBN_CH="中期支付证书";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/InterimPaymentSummary.java

@@ -14,7 +14,7 @@ import java.math.RoundingMode;
  * @description 中期支付汇总表
  */
 @Data
-public class InterimPaymentSummary {
+public class InterimPaymentSummary implements  DataModel{
     public static final String ID="20220000000";
     public static final String TBN="IPaySum";
     public static final String TBN_CH="中期支付汇总表";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/MaterialAdvancePayment.java

@@ -9,7 +9,7 @@ import lombok.Data;
  * @description 材料预付款申请单
  */
 @Data
-public class MaterialAdvancePayment {
+public class MaterialAdvancePayment implements  DataModel{
     public static final String ID="20290000000";
     public static final String TBN="MtAdPay";
     public static final String TBN_CH="材料预付款申请单";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/MaterialPriceDifferential.java

@@ -7,7 +7,7 @@ import com.alibaba.fastjson.annotation.JSONField;
  * @Date 2024/4/19 10:50
  * @description 永久性工程材料差价金额预览表
  */
-public class MaterialPriceDifferential {
+public class MaterialPriceDifferential implements  DataModel{
     public static final String ID="20310000000";
     public static final String TBN="MtPiDf";
     public static final String TBN_CH="永久性工程材料差价金额预览表";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/MaterialsArrival.java

@@ -9,7 +9,7 @@ import lombok.Data;
  * @description 工程材料到达现场计量表
  */
 @Data
-public class MaterialsArrival {
+public class MaterialsArrival implements  DataModel{
     public static final String ID="20330000000";
     public static final String TBN="MtAiv";
     public static final String TBN_CH="工程材料到达现场计量表";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/MeterPeriodInfo.java

@@ -11,7 +11,7 @@ import java.time.LocalDate;
  * @description 计量期信息
  */
 @Data
-public class MeterPeriodInfo {
+public class MeterPeriodInfo implements  DataModel{
     public static final String ID="20200000000";
     /**计量期信息表名*/
     public static final String TBN="MPI";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/SubInterimMeterPaySummary.java

@@ -17,7 +17,7 @@ import java.util.stream.Collectors;
  * @description 分项工程中期计量支付表
  */
 @Data
-public class SubInterimMeterPaySummary {
+public class SubInterimMeterPaySummary implements  DataModel{
     public static final String ID="20250000000";
     public static final String TBN="SubIMeterPaySum";
     public static final String TBN_CH="分项工程中期计量支付表";

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/SubprojectInterimPaymentSummary.java

@@ -22,7 +22,7 @@ import java.util.function.Function;
  * @description 分项工程中期支付汇总表
  */
 @Data
-public class SubprojectInterimPaymentSummary  {
+public class SubprojectInterimPaymentSummary  implements  DataModel{
     public static final String ID="20230000000";
     public static final String TBN="SubIPaySum";
     public static final String TBN_CH="分项工程中期支付汇总表";

+ 5 - 7
blade-service/blade-manager/src/main/java/com/mixsmart/utils/FormulaUtils.java

@@ -54,10 +54,7 @@ import org.springblade.manager.formula.NodeTable;
 import org.springblade.manager.formula.impl.CompositeDataAccess;
 import org.springblade.manager.formula.impl.TableElementConverter;
 import org.springblade.manager.utils.FileUtils;
-import org.springblade.manager.vo.BaseInfo;
-import org.springblade.manager.vo.InterimPaymentCertificate;
-import org.springblade.manager.vo.MeterTree;
-import org.springblade.manager.vo.WbsFormElementVO;
+import org.springblade.manager.vo.*;
 import org.springframework.core.annotation.AnnotationUtils;
 import reactor.core.publisher.Mono;
 
@@ -89,7 +86,7 @@ import static java.util.regex.Pattern.*;
 /**
  * @author yangyj
  * @Date 2022/7/14 15:55
- * @description TODO
+ * @description 公式工具类
  */
 public class FormulaUtils {
     public static final String ELE_CODE_REG= "(?<=E\\[)[^]]+(?=])";
@@ -348,7 +345,8 @@ public class FormulaUtils {
     public static final String TBN_FN="TBN";
 /*把模型类转换成共识配置选项*/
     public static List<WbsFormElementVO> toElementVos(Class<?> clazz)  {
-        List<WbsFormElementVO> vos =new ArrayList<>();
+        return DataModel.toElementVos(clazz);
+       /* List<WbsFormElementVO> vos =new ArrayList<>();
         try {
             Field tbnField = clazz.getField(TBN_FN);
             String TBN = (String) tbnField.get(null);
@@ -366,7 +364,7 @@ public class FormulaUtils {
         }catch (Exception e){
             e.printStackTrace();
         }
-        return vos;
+        return vos;*/
     }
 
     public static String getEleKey(Class<?> clazz, String fieldName){

+ 4 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeController.java

@@ -305,13 +305,12 @@ public class WbsTreeController extends BladeController {
          set.add(InterimMeter.ID);
          set.add(MaterialPriceDifferential.ID);
          set.add(MaterialsArrival.ID);*/
-
          return MODEL_MAP.containsKey(id);
      };
 
-   public final static Map<String,List<WbsFormElementVO>> MODEL_MAP = new LinkedHashMap<>();
+   public final static Map<String,List<WbsFormElementVO>> MODEL_MAP ;
     static {
-        MODEL_MAP.put(BaseInfo.ID,FormulaUtils.toElementVos(BaseInfo.class));
+      /*  MODEL_MAP.put(BaseInfo.ID,FormulaUtils.toElementVos(BaseInfo.class));
         MODEL_MAP.put(MeterPeriodInfo.ID,FormulaUtils.toElementVos(MeterPeriodInfo.class));
         MODEL_MAP.put(AdvancePaymentCertificate.ID,FormulaUtils.toElementVos(AdvancePaymentCertificate.class));
         MODEL_MAP.put(MaterialAdvancePayment.ID,FormulaUtils.toElementVos(MaterialAdvancePayment.class));
@@ -323,7 +322,8 @@ public class WbsTreeController extends BladeController {
         MODEL_MAP.put(InterimMeterPaySummary.ID,FormulaUtils.toElementVos(InterimMeterPaySummary.class));
         MODEL_MAP.put(InterimMeter.ID,FormulaUtils.toElementVos(InterimMeter.class));
         MODEL_MAP.put(MaterialPriceDifferential.ID,FormulaUtils.toElementVos(MaterialPriceDifferential.class));
-        MODEL_MAP.put(MaterialsArrival.ID,FormulaUtils.toElementVos(MaterialsArrival.class));
+        MODEL_MAP.put(MaterialsArrival.ID,FormulaUtils.toElementVos(MaterialsArrival.class));*/
+        MODEL_MAP=DataModel.getElements();
     }
     public List<WbsFormElementVO> dataModel(String id){
           return MODEL_MAP.getOrDefault(id,Collections.emptyList());

+ 4 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreePrivateServiceImpl.java

@@ -255,9 +255,10 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
             data.add(baseInfo);
         }
     }
-   public static final List<TreeNodeVOByTabType> TN_TAB_LIST ;
+   public static final List<TreeNodeVOByTabType> TN_TAB_LIST;
     static {
-        Map<String, String[]> titleMap = new LinkedHashMap<>();
+        TN_TAB_LIST=DataModel.getTreeNodeList();
+        /*Map<String, String[]> titleMap = new LinkedHashMap<>();
         titleMap.put(BaseInfo.TBN_CH, new String[]{BaseInfo.TBN, BaseInfo.ID});
         titleMap.put(AdvancePaymentCertificate.TBN_CH, new String[]{AdvancePaymentCertificate.TBN, AdvancePaymentCertificate.ID});
         titleMap.put(MaterialAdvancePayment.TBN_CH, new String[]{MaterialAdvancePayment.TBN, MaterialAdvancePayment.ID});
@@ -281,7 +282,7 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
             tn.setHasChildren(false);
             tn.setInitTableName(kv.getValue()[0]);
             return tn;
-        }).collect(Collectors.toList());
+        }).collect(Collectors.toList());*/
     }
 
     @Cacheable(cacheNames = "data-model")