|
@@ -5,7 +5,11 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.jfireel.expression.Expression;
|
|
|
import com.mixsmart.utils.CustomFunction;
|
|
|
+import com.mixsmart.utils.ListUtils;
|
|
|
+import com.mixsmart.utils.ReflectionUtil;
|
|
|
+import com.mixsmart.utils.StringUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.business.feign.MileageClient;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.core.tool.utils.CollectionUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
@@ -35,6 +39,7 @@ import java.util.stream.Collectors;
|
|
|
public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula> implements IFormulaService {
|
|
|
|
|
|
private final WbsParamServiceImpl wpService;
|
|
|
+ private final MileageClient mileageClient;
|
|
|
|
|
|
|
|
|
public final static String WP="WP";
|
|
@@ -42,10 +47,13 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
public final static String FC="FC.";
|
|
|
|
|
|
public static final String POLY_REG= "(avg|min|max|sum)\\(([^)]+)\\)";
|
|
|
- public static final Pattern POLY = Pattern.compile(POLY_REG);
|
|
|
+ public static final Pattern POLY = Pattern.compile(POLY_REG);
|
|
|
+ public static final Pattern MILE_P = Pattern.compile("(?<=MILE<)([^,]+),([^,]+)(?=,)");
|
|
|
+
|
|
|
@Override
|
|
|
- public void execute(List<FormData> list ){
|
|
|
- Map<Boolean,List<FormData>> map = list.stream().collect(Collectors.partitioningBy(e->e!=null&&e.getFormula().getFormula().contains("E[")));
|
|
|
+ public void execute(List<FormData> list ,Long contractId){
|
|
|
+
|
|
|
+ Map<Boolean,List<FormData>> map = list.stream().collect(Collectors.partitioningBy(e->e!=null&&e.getFormula().getFormula().contains("E[")));
|
|
|
List<FormData>total = new ArrayList<>();
|
|
|
/*用来保存所有变量*/
|
|
|
Map<String,Object> constantMap = new HashMap<>();
|
|
@@ -78,6 +86,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(total)){
|
|
|
+ /*变量环境加载*/
|
|
|
constantMap.put(WP,wpMap);
|
|
|
constantMap.put(CHAIN,trees.stream().map(WbsTree::getDeptName).collect(Collectors.toList()));
|
|
|
for(FormData fd:total){
|
|
@@ -112,9 +121,36 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if(tmp.startsWith("MILE<")){
|
|
|
+ Matcher mile=MILE_P.matcher(tmp);
|
|
|
+ List<String> zhs=new ArrayList<>();
|
|
|
+ List<String> jzs=new ArrayList<>();
|
|
|
+ if (mile.find()){
|
|
|
+ String zh= mile.group(1);
|
|
|
+ String jz= mile.group(2);
|
|
|
+ Optional<FormData> op=list.stream().filter(e->e.getCode().equals(zh)).findFirst();
|
|
|
+ if(op.isPresent()){
|
|
|
+ zhs=op.get().getValues().stream().map(ElementData::getValue).map(StringUtils::handleNull).collect(Collectors.toList());
|
|
|
+ if(zhs.size()>0){
|
|
|
+ Optional<FormData> op2=list.stream().filter(e->e.getCode().equals(jz)).findFirst();
|
|
|
+ if(op2.isPresent()){
|
|
|
+ jzs=op.get().getValues().stream().map(ElementData::getValue).map(StringUtils::handleNull).collect(Collectors.toList());
|
|
|
+ List<String> mileages = new ArrayList<>();
|
|
|
+ int size = Math.min(zhs.size(),jzs.size());
|
|
|
+ for(int i=0;i<size;i++){
|
|
|
+ String s1 =zhs.get(i);
|
|
|
+ String s2 =jzs.get(i);
|
|
|
+ if(StringUtils.isNotEmpty(s1,s2)){
|
|
|
+ mileages.add(s1+"@"+s2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ constantMap.put("MILE",mileageClient.mileage2Coordinate(mileages,contractId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
fd.getFormula().setFormula(tmp);
|
|
|
}
|
|
@@ -287,6 +323,55 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ public static final Pattern MILE_ARGS= Pattern.compile("(?<=MILE<)[^>]+(?=>)");
|
|
|
+ /**
|
|
|
+ * @Description
|
|
|
+ * @Param [fd]
|
|
|
+ * @return void
|
|
|
+ * @Author yangyj
|
|
|
+ * @Date 2022.07.08 16:39
|
|
|
+ **/
|
|
|
+ public void mileageCalc(FormData fd,List<FormData> fds,Map<String,Object> constantMap){
|
|
|
+ List<ElementData> eds = fd.getValues();
|
|
|
+ Map<String,String[]> mileages = (Map<String, String[]>) constantMap.get("mileages");
|
|
|
+ if(ListUtils.isNotEmpty(eds)){
|
|
|
+ Matcher m= MILE_ARGS.matcher(fd.getCode());
|
|
|
+ if(m.find()){
|
|
|
+ String tmp =m.group();
|
|
|
+ tmp=tmp.replace("E[","").replace("]","");
|
|
|
+ List<String> cp = Arrays.asList(tmp.split(","));
|
|
|
+ Map<String,FormData> map = new HashMap<>();
|
|
|
+ fds.forEach(e->{
|
|
|
+ if(cp.contains(e.getCode())){
|
|
|
+ map.put(e.getCode(),fd);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<ElementData> a = map.get(cp.get(0)).getValues();
|
|
|
+ List<ElementData> b = map.get(cp.get(2)).getValues();
|
|
|
+ int size=Math.min(a.size(),b.size());
|
|
|
+ for(int i=0;i<size;i++){
|
|
|
+ String k =a.get(i).getValue().toString();
|
|
|
+ String jz=b.get(i).getValue().toString();
|
|
|
+ String[] coordinate = mileages.get(k+"@"+jz);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ Set<Class<?>> classList = ReflectionUtil.getClassSetBySuper(IFcHandler.class);
|
|
|
+ List<IFcHandler> receiptHandlerList = new ArrayList<>();
|
|
|
+ if (classList.size() > 0) {
|
|
|
+ for (Class<?> clazz : classList) {
|
|
|
+ try {
|
|
|
+ receiptHandlerList.add((IFcHandler)clazz.newInstance());
|
|
|
+ } catch ( Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|