yangyj 2 жил өмнө
parent
commit
4cf6ee0537

+ 3 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/dto/FormData.java

@@ -3,6 +3,7 @@ package org.springblade.manager.dto;
 import lombok.Data;
 import org.springblade.manager.entity.Formula;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -53,6 +54,8 @@ public class FormData {
      */
     private  Integer groupId;
 
+    private List<String> rely = new ArrayList<>();
+
     public FormData() {
     }
     public FormData(String code, List<List<Object>> values, Formula formula, Integer groupId) {

+ 4 - 0
blade-service/blade-business/pom.xml

@@ -60,6 +60,10 @@
             <version>2.9.1.RELEASE</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>org.springblade</groupId>
+            <artifactId>blade-starter-excel</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 3 - 0
blade-service/blade-business/src/main/java/org/springblade/business/controller/MileageController.java

@@ -13,10 +13,12 @@ import org.springblade.business.dto.MileagexyDTO;
 import org.springblade.business.entity.Mileage;
 import org.springblade.business.entity.MileagePart;
 import org.springblade.business.entity.Mileagexy;
+import org.springblade.business.excel.MileageExcel;
 import org.springblade.business.service.impl.MileagePartService;
 import org.springblade.business.service.impl.MileagexyService;
 import org.springblade.business.utils.MileageUtill;
 import org.springblade.business.vo.MileageVo;
+import org.springblade.core.excel.util.ExcelUtil;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.secure.utils.AuthUtil;
@@ -127,6 +129,7 @@ public class MileageController {
     public R importXy(@RequestParam("file") MultipartFile file, String projectId,String partId,String contractId ) throws Exception {
         if(file != null&&Func.isNotEmpty(partId)) {
             if(Pattern.matches(".+(\\.xls)x?$", Objects.requireNonNull(file.getOriginalFilename()).toLowerCase(Locale.ROOT))) {
+              List<MileageExcel> data = ExcelUtil.read(file,MileageExcel.class);
              return   R.success(this.service.importMileagexy(file,AuthUtil.getUserId(),projectId,contractId,partId));
             } else {
                return   R.fail("文件格式不正确,请上传Excel文件");

+ 3 - 1
blade-service/blade-business/src/main/java/org/springblade/business/excel/DatumPointExcel.java

@@ -6,6 +6,8 @@ import com.alibaba.excel.annotation.write.style.ContentRowHeight;
 import com.alibaba.excel.annotation.write.style.HeadRowHeight;
 import lombok.Data;
 
+import java.io.Serializable;
+
 /**
  * @author yangyj
  * @Date 2022/6/9 10:59
@@ -15,7 +17,7 @@ import lombok.Data;
 @ColumnWidth(16)
 @HeadRowHeight(20)
 @ContentRowHeight(18)
-public class DatumPointExcel {
+public class DatumPointExcel implements Serializable {
     @ExcelProperty(value = "名称")
     private String name;
     @ExcelProperty(value = "高程")

+ 3 - 1
blade-service/blade-business/src/main/java/org/springblade/business/excel/DatumPointxyExcel.java

@@ -7,6 +7,8 @@ import com.alibaba.excel.annotation.write.style.HeadRowHeight;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import java.io.Serializable;
+
 /**
  * @author yangyj
  * @Date 2022/6/9 11:01
@@ -16,7 +18,7 @@ import lombok.EqualsAndHashCode;
 @ColumnWidth(16)
 @HeadRowHeight(20)
 @ContentRowHeight(18)
-public class DatumPointxyExcel {
+public class DatumPointxyExcel implements Serializable {
     @ExcelProperty(value = "名称")
     private String name;
     @ExcelProperty(value = "x坐标")

+ 50 - 0
blade-service/blade-business/src/main/java/org/springblade/business/excel/MileageExcel.java

@@ -0,0 +1,50 @@
+package org.springblade.business.excel;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.ContentRowHeight;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author yangyj
+ * @Date 2022/6/29 17:29
+ * @description TODO
+ */
+@Data
+@ColumnWidth(16)
+@HeadRowHeight(20)
+@ContentRowHeight(18)
+public class MileageExcel implements Serializable {
+    private static final long serialVersionUID = 1L;
+    @ExcelProperty(value = "类型")
+    private String type;
+    @ExcelProperty(value = "开始里程")
+    private Double value;
+    @ExcelProperty(value = "X")
+    private Double x;
+    @ExcelProperty(value = "Y")
+    private Double y;
+    @ExcelProperty(value = "半径")
+    private Double r;
+    @ExcelProperty(value = "转向")
+    private String swing;
+    @ExcelProperty(value = "线长度")
+    private Double l;
+    @ExcelProperty(value = "方位角(度)")
+    private Integer du;
+    @ExcelProperty(value = "方位角(分)")
+    private Integer fen;
+    @ExcelProperty(value = "方位角(秒)")
+    private Double miao;
+    @ExcelProperty(value = "断链前里程")
+    private Double dlq;
+    @ExcelProperty(value = "断链后里程")
+    private Double dlh;
+    @ExcelProperty(value = "结束半径")
+    private Double r2;
+    @ExcelProperty(value = "顺序")
+    private Integer orderNum;
+}

+ 3 - 2
blade-service/blade-manager/src/main/java/com/mixsmart/utils/CustomFunction.java

@@ -798,7 +798,8 @@ public class CustomFunction {
 	public static Object avg( List<Object> list) {
 		 if(list!=null){
 			 if(list.stream().noneMatch(CustomFunction::isNotNumber)){
-			       return list.stream().map(String::valueOf).mapToDouble(Double::parseDouble).average();
+				   OptionalDouble opd =  list.stream().map(String::valueOf).mapToDouble(Double::parseDouble).average();
+			       return  opd.orElse(0);
 			 }
 		 }
 	     return null;
@@ -2202,7 +2203,7 @@ public class CustomFunction {
 		if(CollectionUtil.isNotEmpty(nodes)&& Func.isNotBlank(param)){
 			List<String> result = new ArrayList<>();
 			param=param.replaceAll("(?i:c)","");
-			List<String> list = Arrays.asList(param.split("-"));
+			List<String> list = Arrays.asList(param.split("[^.\\d]"));
 			List<Integer> index =list.stream().map(Integer::parseInt).collect(Collectors.toList());
 			for(Integer i:index){
 				result.add(nodes.get(i));

+ 38 - 18
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -46,8 +46,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
             List<FormData>total = new ArrayList<>();
             /*用来保存所有变量*/
             Map<String,Object> variables = new HashMap<>();
-
-            Map<String,Object> currentMap = new HashMap<>();
+            Map<String,Object> constantMap = new HashMap<>();
             /*预设变量start*/
             List<WbsTree> trees = new ArrayList<>();
             for(int i=0;i<6;i++){
@@ -77,10 +76,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
              }
 
             if(CollectionUtil.isNotEmpty(total)){
-                currentMap.put(WP,wpMap);
-                currentMap.put(CHAIN,trees.stream().map(WbsTree::getDeptName).collect(Collectors.toList()));
-                Map<String,Object> E=new HashMap<>();
-                currentMap.put("E",E);
+                constantMap.put(WP,wpMap);
+                constantMap.put(CHAIN,trees.stream().map(WbsTree::getDeptName).collect(Collectors.toList()));
                 for(FormData fd:total){
                       /*存入数据*/
                       if(CollectionUtil.isNotEmpty(fd.getValues())){
@@ -88,7 +85,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                            for(int i=0;i<fd.getValues().size();i++){
                               tmpMap.put("p"+i,fd.getValues().get(i));
                            }
-                          E.put(fd.getCode(),fd.getValues().get(0));
+                          variables.put(fd.getCode(),fd.getValues().get(0));
+
                            Map<String,Object> tableMap = (Map<String, Object>) variables.get(fd.getCode());
                            if(tableMap==null){
                                tableMap= new HashMap<>();
@@ -106,6 +104,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                        Matcher m2 = P.matcher(tmp);
                     while (m2.find()){
                         tmp= tmp.replace(m2.group(),"'"+m2.group()+"'");
+                        fd.getRely().add(m2.group());
                     }
                       fd.getFormula().setFormula(tmp);
                 }
@@ -113,46 +112,67 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                 /*集合公式预处理*/
                 for(FormData fd:total){
                     String formula=fd.getFormula().getFormula();
+                    Map<String,Object> currentMap = new HashMap<>(constantMap);
+                    currentMap.put("E",variables);
                     if(formula.contains(CustomFunction.CLASS_CALL+"avg(")||formula.contains(CustomFunction.CLASS_CALL+"min(")||formula.contains(CustomFunction.CLASS_CALL+"max(")||formula.contains(CustomFunction.CLASS_CALL+"sum(")){
                         Matcher m = POLY.matcher(formula);
                         while (m.find()){
-                            Object data =   Expression.parse(m.group()).calculate(currentMap);
-                            formula = formula.replace(m.group(),data.toString());
+                            Object data =   Expression.parse(CustomFunction.CLASS_CALL+m.group()).calculate(currentMap);
+                            formula = formula.replace(CustomFunction.CLASS_CALL+m.group(),data.toString());
+                            fd.getFormula().setFormula(formula);
                         }
                     }
                 }
                 for(FormData fd:total){
                     if(Func.isNotBlank(fd.getFormula().getFormula())){
-                        Object data =   Expression.parse(fd.getFormula().getFormula()).calculate(currentMap);
-                        fd.getValues().add(new ArrayList<>(Collections.singletonList(data)));
+                           Map<String, Object> currentMap = new HashMap<>();
+                           Map<String,Object> elementMap = getMap(variables,"E");
+                           Map<String,Object> tmp = getMap(currentMap,"E");
+                           for(String key:fd.getRely()){
+                               tmp.put(key,elementMap.get(key));
+                           }
+                          System.out.println(slice(currentMap,constantMap,fd.getFormula().getFormula()));
                     }
                 }
             }
         System.out.println("执行结束");
     }
 
+    public  Map<String,Object> getMap(Map<String,Object> variables,String key){
+        Map<String,Object> CNDMap = (Map<String, Object>) variables.get(key);
+        if(CNDMap==null){
+            CNDMap = new HashMap<>();
+            variables.put(key,CNDMap);
+        }
+        CNDMap.put("A",100);
+        return CNDMap;
+    }
 
-    public static List<Object> slice(Map<String,Object> variables,String formula){
-        int min =0;
+    public  List<Object> slice(Map<String,Object> variables,Map<String,Object> constantMap,String formula){
+        int min =1;
         List<Object> result = new ArrayList<>();
         Map<String,Object> currentMap = new HashMap<>();
         Map<String,List<Object>> massMap = new HashMap<>();
-        for(Map.Entry<String,Object> entry:variables.entrySet()){
+        Map<String,Object> E=getMap(variables,"E");
+        Map<String,Object> E2=getMap(currentMap,"E");
+
+        for(Map.Entry<String,Object> entry:E.entrySet()){
                 if(entry.getValue() instanceof  List){
                     List<Object> tmp = (List<Object>) entry.getValue();
-                    if(min==0){
-                        min=tmp.size();
+                    if(min==1){
+                        min= Math.max(tmp.size(), 1);
                     }else{
                         min= Math.min(min,tmp.size());
                     }
                     massMap.put(entry.getKey(),tmp);
                 }else{
-                    currentMap.put(entry.getKey(),entry.getValue());
+                    E2.put(entry.getKey(),entry.getValue());
                 }
         }
+         currentMap.putAll(constantMap);
         for(int i=0;i<min;i++){
             for(Map.Entry<String,List<Object>> e:massMap.entrySet()){
-                currentMap.put(e.getKey(),e.getValue().get(i));
+                E2.put(e.getKey(),e.getValue().get(i));
             }
             Object data  = Expression.parse(formula).calculate(currentMap);
             result.add(data);