|
@@ -429,45 +429,55 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
List<FormData> ele = new ArrayList<>();
|
|
|
relyList.forEach(rely->{
|
|
|
FormData formData= this.tec.getFormDataMap().get(rely);
|
|
|
- if(formData!=null&&formData.getValues().stream().anyMatch(Func::isNotEmpty)){
|
|
|
+ if(formData!=null&&formData.getValues().size()>0){
|
|
|
+ /*formData.getValues().stream().anyMatch(Func::isNotEmpty)*/
|
|
|
ele.add(formData);
|
|
|
}
|
|
|
});
|
|
|
if(ele.size()<relyList.size()){
|
|
|
this.tec.getLog().append(fd.getEName()).append(fd.getFormula().getFormula().replaceAll("'", "")).append("不满足执行依赖;");
|
|
|
}
|
|
|
- LinkedHashMap<String,FormData> fdMap =new LinkedHashMap<>();
|
|
|
- ele.forEach(e->{
|
|
|
- fdMap.put(e.getCode(),e);
|
|
|
- });
|
|
|
- CompositeDataAccess cda = new CompositeDataAccess(fdMap);
|
|
|
- List<LocalVariable> local= new ArrayList<>();
|
|
|
- while (cda.hasNext()){
|
|
|
- LinkedHashMap<String,ElementData> tip= cda.next();
|
|
|
- Map<String, Object> variable = new HashMap<>(this.constantMap);
|
|
|
- Map<String,Object> E=getMap(variable,"E");
|
|
|
- int index= new ArrayList<>(tip.values()).get(0).getIndex();
|
|
|
- for(Map.Entry<String,ElementData> se:tip.entrySet()){
|
|
|
- Object value=se.getValue().getValue();
|
|
|
- if(CustomFunction.isNumber(value)){
|
|
|
- E.put(se.getKey(),StringUtils.obj2Double(value));
|
|
|
- }else{
|
|
|
- E.put(se.getKey(),value);
|
|
|
- }
|
|
|
+ if(fd.getCoordsList().size()>1&&f.split("[/+\\-*]").length>1){
|
|
|
+ LinkedHashMap<String,FormData> fdMap =new LinkedHashMap<>();
|
|
|
+ ele.forEach(e->{
|
|
|
+ fdMap.put(e.getCode(),e);
|
|
|
+ });
|
|
|
+ CompositeDataAccess cda = new CompositeDataAccess(fdMap);
|
|
|
+ List<LocalVariable> local= new ArrayList<>();
|
|
|
+ while (cda.hasNext()){
|
|
|
+ LinkedHashMap<String,ElementData> tip= cda.next();
|
|
|
+ Map<String, Object> variable = new HashMap<>(this.constantMap);
|
|
|
+ Map<String,Object> E=getMap(variable,"E");
|
|
|
+ int index= new ArrayList<>(tip.values()).get(0).getIndex();
|
|
|
+ for(Map.Entry<String,ElementData> se:tip.entrySet()){
|
|
|
+ Object value=se.getValue().getValue();
|
|
|
+ if(CustomFunction.isNumber(value)){
|
|
|
+ E.put(se.getKey(),StringUtils.obj2Double(value));
|
|
|
+ }else{
|
|
|
+ E.put(se.getKey(),value);
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ local.add(new LocalVariable(index,f,variable));
|
|
|
}
|
|
|
- local.add(new LocalVariable(index,f,variable));
|
|
|
- }
|
|
|
- if(local.size()>0){
|
|
|
- List<Object> values = slice(local,this.constantMap,f);
|
|
|
- if(values.size()>fd.getValues().size()){
|
|
|
- /*当生成的数据超过实际容量的时候,会自动合并到第一个单元格*/
|
|
|
- fd.getValues().get(0).setValue(values.stream().filter(Func::isNotEmpty).map(StringUtils::handleNull).collect(Collectors.joining("、")));
|
|
|
- }else{
|
|
|
- for(int n=0;n<values.size();n++){
|
|
|
- fd.getValues().get(n).setValue(values.get(n));
|
|
|
+ if(local.size()>0){
|
|
|
+ List<Object> values = slice(local,this.constantMap,f);
|
|
|
+ if(values.size()>fd.getValues().size()){
|
|
|
+ /*当生成的数据超过实际容量的时候,会自动合并到第一个单元格*/
|
|
|
+ fd.getValues().get(0).setValue(values.stream().filter(Func::isNotEmpty).map(StringUtils::handleNull).collect(Collectors.joining("、")));
|
|
|
+ }else{
|
|
|
+ for(int n=0;n<values.size();n++){
|
|
|
+ fd.getValues().get(n).setValue(values.get(n));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ }else{
|
|
|
+ Map<String,Object> E = (Map<String, Object>) currentMap.computeIfAbsent("E",(k)-> new HashMap<>());
|
|
|
+ ele.forEach(e->{
|
|
|
+ E.put(e.getCode(),e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()));
|
|
|
+ });
|
|
|
+ Object data =Expression.parse(formula.getFormula()).calculate(currentMap);
|
|
|
+ write(fd,data);
|
|
|
}
|
|
|
}else{
|
|
|
Object data =Expression.parse(formula.getFormula()).calculate(currentMap);
|
|
@@ -653,6 +663,113 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
* 先把公式脚本需要聚合部分预处理
|
|
|
* */
|
|
|
public void polymerization(FormData fd){
|
|
|
+ Formula formula = fd.getFormula();
|
|
|
+ if(Func.isNotEmpty(formula)){
|
|
|
+ String f=formula.getFormula();
|
|
|
+ try {
|
|
|
+ if(Func.isNotBlank(f)) {
|
|
|
+ if (f.contains(CustomFunction.CLASS_CALL+"quantity(")) {
|
|
|
+ /*聚合*/
|
|
|
+ Matcher m = POLY.matcher(f);
|
|
|
+ while (m.find()) {
|
|
|
+ Object data=null;
|
|
|
+ if(f.contains("quantity(")){
|
|
|
+ String s = m.group(2).split(",")[0].replaceAll("[E\\[\\]']","");
|
|
|
+ Map<String,List<Map<String,Object>>> textInfoMap= (Map<String, List<Map<String, Object>>>) this.constantMap.getOrDefault(TEXT_INFO_MAP,new HashMap<>());
|
|
|
+ List<Map<String,Object>> tableColKeyVal= textInfoMap.get(s);
|
|
|
+ if(Func.isNotEmpty(tableColKeyVal)){
|
|
|
+ data = tableColKeyVal.stream().map(map-> BeanUtil.toBean(JSON.parseObject(map.get("val").toString()),RangeInfo.class)).map(RangeInfo::getPass).findFirst().orElseGet(String::new);
|
|
|
+ }else{
|
|
|
+ /*手动计算*/
|
|
|
+ System.out.println("");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
+ List<String> relyList = fd.getFormula().getRelyList();
|
|
|
+ Map<String, Object> E = getMap(currentMap, "E");
|
|
|
+ for(String k:relyList){
|
|
|
+ FormData e=this.formDataMap.get(k);
|
|
|
+ if(e==null){
|
|
|
+ this.tec.getLog().append(fd.getEName()).append("缺失依赖:").append(k).append(";");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ E.put(e.getCode(),e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ data = Expression.parse(CustomFunction.CLASS_CALL + m.group()).calculate(currentMap);
|
|
|
+ }
|
|
|
+ String key ="HA"+HashUtil.identityHashCode(data);
|
|
|
+ this.constantMap.put(key,data);
|
|
|
+ f = f.replace(CustomFunction.CLASS_CALL + m.group(), key);
|
|
|
+ }
|
|
|
+ fd.getFormula().setFormula(f);
|
|
|
+ }else if(f.contains(CustomFunction.CLASS_CALL+"proportion(")||f.contains(CustomFunction.CLASS_CALL+"ladder(")||f.contains(CustomFunction.CLASS_CALL+"major(")||f.contains(CustomFunction.CLASS_CALL+"reasonable(")
|
|
|
+ ||f.contains(CustomFunction.CLASS_CALL+"goodSize(")){
|
|
|
+ String tf=f.replaceAll("^T\\(com.mixsmart.utils.CustomFunction\\)\\.\\w+\\(","").replaceAll("[)]$","");
|
|
|
+ List<FormData> target = new ArrayList<>();
|
|
|
+ String[] tfa=tf.split(",");
|
|
|
+ for(String code:tfa){
|
|
|
+ code=code.replace("E['","").replace("']","");
|
|
|
+ FormData fdt=this.formDataMap.get(code);
|
|
|
+ if(fdt!=null){
|
|
|
+ target.add(fdt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(Func.isNotEmpty(target)){
|
|
|
+ if(StringUtils.isEmpty(formula.getScale())){
|
|
|
+ formula.setScale(2);
|
|
|
+ }
|
|
|
+ Object data=null;
|
|
|
+ if(f.contains("proportion")){
|
|
|
+ data= CustomFunction.proportion(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()), "优良");
|
|
|
+ }else if(f.contains("ladder")){
|
|
|
+ data= CustomFunction.ladder(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()));
|
|
|
+ }else if(f.contains("major")){
|
|
|
+ data= CustomFunction.major(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()));
|
|
|
+ }else if(f.contains("reasonable")){
|
|
|
+ data= CustomFunction.reasonable(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()));
|
|
|
+ }else if(f.contains("goodSize")){
|
|
|
+ data= CustomFunction.goodSize(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()),"优良");
|
|
|
+ }
|
|
|
+ String key ="HA"+HashUtil.identityHashCode(data);
|
|
|
+ fd.getFormula().setFormula(key);
|
|
|
+ this.constantMap.put(key,data);
|
|
|
+ }else{
|
|
|
+ fd.getFormula().setFormula(StringPool.EMPTY);
|
|
|
+ }
|
|
|
+ }else if(f.contains(CustomFunction.CLASS_CALL+"ifelse(")){
|
|
|
+ Matcher im =IF.matcher(f);
|
|
|
+ while (im.find()){
|
|
|
+ String rep =im.group();
|
|
|
+ //Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
+ Matcher fm=P.matcher(rep);
|
|
|
+ while (fm.find()){
|
|
|
+ FormData kf= this.formDataMap.get(fm.group().replaceAll("'",""));
|
|
|
+ if(kf!=null&&!kf.empty()){
|
|
|
+ ElementData ed= kf.getValues().get(0);
|
|
|
+ if(ed!=null&&Func.isNotEmpty(ed.getValue())){
|
|
|
+ rep= rep.replace("E["+fm.group()+"]",ed.getValue().toString());
|
|
|
+ rep="'"+rep+"'";
|
|
|
+ f=f.replace(im.group(),rep);
|
|
|
+ }else{
|
|
|
+ f="";
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ f="";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ formula.setFormula(f);
|
|
|
+ }
|
|
|
+ relyParse(fd.getFormula());
|
|
|
+ StaticLog.info("聚合处理");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void polymerizationBak(FormData fd){
|
|
|
Formula formula = fd.getFormula();
|
|
|
if(Func.isNotEmpty(formula)){
|
|
|
String f=formula.getFormula();
|
|
@@ -670,7 +787,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
Map<String,List<Map<String,Object>>> textInfoMap= (Map<String, List<Map<String, Object>>>) this.constantMap.getOrDefault(TEXT_INFO_MAP,new HashMap<>());
|
|
|
List<Map<String,Object>> tableColKeyVal= textInfoMap.get(s);
|
|
|
if(Func.isNotEmpty(tableColKeyVal)){
|
|
|
- data = tableColKeyVal.stream().map(map-> BeanUtil.toBean(JSON.parseObject(map.get("val").toString()),RangeInfo.class)).map(RangeInfo::getFail).findFirst().orElseGet(String::new);
|
|
|
+ data = tableColKeyVal.stream().map(map-> BeanUtil.toBean(JSON.parseObject(map.get("val").toString()),RangeInfo.class)).map(RangeInfo::getPass).findFirst().orElseGet(String::new);
|
|
|
}else{
|
|
|
/*手动计算*/
|
|
|
System.out.println("");
|
|
@@ -762,7 +879,6 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
public void batch(){
|
|
|
List<Map<String,Object>> list = this.jdbcTemplate.queryForList("select id,formula from m_formula where (formula like '%reasonable%' or formula like '%proportion%' or formula like '%goodSize%')");
|
|
|
if(ListUtils.isNotEmpty(list)){
|