|
@@ -247,7 +247,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
String rep =im.group();
|
|
|
Matcher fm=P.matcher(rep);
|
|
|
while (fm.find()){
|
|
|
- rep=rep.replace(fm.group(),"'+"+fm.group()+"+'");
|
|
|
+ rep=rep.replace(fm.group(),"'"+fm.group()+"'");
|
|
|
}
|
|
|
tmp=tmp.replace(im.group(),rep);
|
|
|
}
|
|
@@ -295,45 +295,50 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
Formula formula =fd.getFormula();
|
|
|
String f=formula.getFormula();
|
|
|
if(Func.isNotBlank(f)){
|
|
|
- /*聚合运算*/
|
|
|
- polymerization();
|
|
|
- Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
- List<String> relyList = fd.getFormula().getRelyList();
|
|
|
- if(CollectionUtil.isNotEmpty(relyList)){
|
|
|
- List<FormData> ele = this.formDataList.stream().filter(e->relyList.contains(e.getCode())&&e.getValues().stream().anyMatch(Func::isNotEmpty)).collect(Collectors.toList());
|
|
|
- if(ele.size()<relyList.size()){
|
|
|
- System.out.println(formula.getFormula()+"不满足依赖要求");
|
|
|
- }
|
|
|
- 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");
|
|
|
- for(Map.Entry<String,ElementData> se:tip.entrySet()){
|
|
|
- E.put(se.getKey(),se.getValue().getValue());
|
|
|
+ try{
|
|
|
+ /*聚合运算*/
|
|
|
+ polymerization();
|
|
|
+ Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
+ List<String> relyList = fd.getFormula().getRelyList();
|
|
|
+ if(CollectionUtil.isNotEmpty(relyList)){
|
|
|
+ List<FormData> ele = this.formDataList.stream().filter(e->relyList.contains(e.getCode())&&e.getValues().stream().anyMatch(Func::isNotEmpty)).collect(Collectors.toList());
|
|
|
+ if(ele.size()<relyList.size()){
|
|
|
+ System.out.println(formula.getFormula()+"不满足依赖要求");
|
|
|
}
|
|
|
- local.add(new LocalVariable(0,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));
|
|
|
+ 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");
|
|
|
+ for(Map.Entry<String,ElementData> se:tip.entrySet()){
|
|
|
+ E.put(se.getKey(),se.getValue().getValue());
|
|
|
+ }
|
|
|
+ local.add(new LocalVariable(0,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));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ }else{
|
|
|
+ Object data =Expression.parse(formula.getFormula()).calculate(currentMap);
|
|
|
+ write(fd,data);
|
|
|
}
|
|
|
- }else{
|
|
|
- Object data =Expression.parse(formula.getFormula()).calculate(currentMap);
|
|
|
- write(fd,data);
|
|
|
+ }catch (Exception e){
|
|
|
+ write(fd,e.getMessage());
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
/*数量不相等*/
|
|
|
fd.setUpdate(1);
|
|
@@ -354,7 +359,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
- if(fd.getFormula().getOutm().equals(Formula.FULL)){
|
|
|
+ if(Formula.FULL.equals(fd.getFormula().getOutm())){
|
|
|
/*填充策略*/
|
|
|
fd.getValues().forEach(e->e.setValue(data));
|
|
|
}else{
|
|
@@ -395,18 +400,24 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
|
public List<KeyMapper> getKeyMapperList(List<Long> ids) {
|
|
|
- List<Map<String,Object>> listMap = this.jdbcTemplate.queryForList("select b.init_table_name as tableName,a.p_key_id as pkId ,c.e_key as field,c.id as fieldId,d.scope,d.formula_id as formulaId " +
|
|
|
+// List<Map<String,Object>> listMap = this.jdbcTemplate.queryForList("select b.init_table_name as tableName,a.p_key_id as pkId ,c.e_key as field,c.id as fieldId,d.scope,d.formula_id as formulaId " +
|
|
|
+// "from m_wbs_tree_contract a " +
|
|
|
+// "INNER JOIN m_wbs_tree b on (a.old_id=b.id or a.id=b.id) " +
|
|
|
+// "INNER JOIN m_wbs_form_element c on c.f_id=b.init_table_id " +
|
|
|
+// "left JOIN m_element_formula_mapping d on c.id=d.element_id " +
|
|
|
+// "where a.p_key_id in("+ids.stream().map(String::valueOf).collect(Collectors.joining(","))+") " +
|
|
|
+// "ORDER BY b.init_table_name,d.scope");
|
|
|
+ List<Map<String,Object>> listMap = this.jdbcTemplate.queryForList(" select a.init_table_name as tableName,a.p_key_id as pkId ,c.e_key as field,c.e_name as eName,c.id as fieldId ,d.scope,d.formula_id as formulaId " +
|
|
|
"from m_wbs_tree_contract a " +
|
|
|
- "INNER JOIN m_wbs_tree b on (a.old_id=b.id or a.id=b.id) " +
|
|
|
- "INNER JOIN m_wbs_form_element c on c.f_id=b.init_table_id " +
|
|
|
- "left JOIN m_element_formula_mapping d on c.id=d.element_id " +
|
|
|
- "where a.p_key_id in("+ids.stream().map(String::valueOf).collect(Collectors.joining(","))+") " +
|
|
|
- "ORDER BY b.init_table_name,d.scope");
|
|
|
+ "inner join m_table_info b on a.init_table_name=b.tab_en_name " +
|
|
|
+ "INNER JOIN m_wbs_form_element c on b.id=c.f_id " +
|
|
|
+ "left join m_element_formula_mapping d on c.id=d.element_id " +
|
|
|
+ "where a.p_key_id in("+ids.stream().map(String::valueOf).collect(Collectors.joining(","))+") ORDER BY a.init_table_name,d.scope");
|
|
|
/*当前节点的参数可以是私有级和公有级*/
|
|
|
|
|
|
if(Func.isNotEmpty(listMap)){
|
|
|
/*根据元素id分组*/
|
|
|
- Map<Long,List<KeyMapper>> groupList= listMap.stream().map(m->BeanUtil.toBean(m, KeyMapper.class)).collect(Collectors.groupingBy(KeyMapper::getFieldId,LinkedHashMap::new,Collectors.toList()));
|
|
|
+ Map<Long,List<KeyMapper>> groupList= listMap.stream().map(m->BeanUtil.toBean(m,KeyMapper.class)).collect(Collectors.groupingBy(KeyMapper::getFieldId,LinkedHashMap::new,Collectors.toList()));
|
|
|
Set<KeyMapper> set = new HashSet<>(groupList.size()*2);
|
|
|
for(Map.Entry<Long,List<KeyMapper>>entry:groupList.entrySet()){
|
|
|
entry.getValue().stream().max(Comparator.comparing(KeyMapper::getScope)).ifPresent(set::add);
|