|
@@ -72,12 +72,12 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
public final static String CHECK_ITEMS="CKI";
|
|
|
public static final Pattern AP=Pattern.compile("(E|WP)\\[([^]']+)]");
|
|
|
public static final String IF_REG= "(?<=T\\(com.mixsmart.utils.CustomFunction\\).ifelse\\()[^,]+(?=,)";
|
|
|
+ public static final String FC_REG="T\\(com.mixsmart.utils.CustomFunction\\)\\.";
|
|
|
public static final Pattern IF = Pattern.compile(IF_REG);
|
|
|
public static final String ELE_CODE_REG= "(?<=E\\[)[^]]+(?=])";
|
|
|
public static final Pattern P = Pattern.compile(ELE_CODE_REG);
|
|
|
public static final Pattern P2= Pattern.compile("(?<=E\\[)[^];]+:[^];]+:[^];]+(?=])");
|
|
|
public static final String POLY_REG= "(quantity)\\(([^)]+)\\)";
|
|
|
- public static final Pattern POLY = Pattern.compile(POLY_REG);
|
|
|
public final static String CTI="ContractInfo";
|
|
|
public final static String PJI="ProjectInfo";
|
|
|
/**表单信息*/
|
|
@@ -234,14 +234,11 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
String key =r.substring(r.indexOf(StringPool.COLON)+1);
|
|
|
List<AppWbsTreeContractVO> nodeList = this.tec.getTableAll().stream().filter(e->e.getInitTableName().equals(tn)).collect(Collectors.toList());
|
|
|
if(Func.isNotEmpty(nodeList)){
|
|
|
+ removeList.add(r);
|
|
|
Map<String,Object> elementInfo= (Map<String, Object>) elementInfoMap.get(r);
|
|
|
String tableName = nodeList.get(0).getInitTableName();
|
|
|
- try {
|
|
|
- if(!this.tec.getCoordinateMap().containsKey(tableName)){
|
|
|
- this.tec.getCoordinateMap().put(tableName, getTableCols(nodeList.get(0).getHtmlUrl()));
|
|
|
- }
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ if(!this.tec.getCoordinateMap().containsKey(tableName)){
|
|
|
+ this.tec.getCoordinateMap().put(tableName, CustomFunction.getElementCell(nodeList.get(0).getHtmlUrl()));
|
|
|
}
|
|
|
List<Map<String,Object>> tableDatas= this.jdbcTemplate.queryForList("select * from "+tableName+" where p_key_id in("+nodeList.stream().map(AppWbsTreeContractVO::getPKeyId).map(StringUtils::handleNull).collect(Collectors.joining(","))+")");
|
|
|
fill(tableDatas,removeList,tn,key,StringUtils.handleNull(elementInfo.get("ename")));
|
|
@@ -265,11 +262,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
if(Func.isNotEmpty(targetIds)){
|
|
|
if(!this.tec.getCoordinateMap().containsKey(tn)){
|
|
|
tableNamePkIdsMaps.stream().filter(m->StringUtils.isEquals(m.get("tableName"),tn)).findAny().ifPresent(m->{
|
|
|
- try {
|
|
|
- this.tec.getCoordinateMap().put(tn,getTableCols(StringUtils.handleNull(m.get("url"))));
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ this.tec.getCoordinateMap().put(tn,CustomFunction.getElementCell(StringUtils.handleNull(m.get("url"))));
|
|
|
});
|
|
|
}
|
|
|
List<Map<String,Object>> tableDatas= this.jdbcTemplate.queryForList("select * from "+tn+" where p_key_id in ("+targetIds+")");
|
|
@@ -302,7 +295,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
if(StringUtils.isNotEmpty(values)){
|
|
|
FormData tmp=createFormDataFast(name,r,values);
|
|
|
if(tmp!=null){
|
|
|
- removeList.add(r);
|
|
|
+ //removeList.add(r);
|
|
|
this.formDataMap.put(r,tmp);
|
|
|
}
|
|
|
}
|
|
@@ -342,44 +335,12 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
}
|
|
|
FormData one= new FormData(code,eds, null,StringPool.EMPTY);
|
|
|
-// FormData one= new FormData(code, Arrays.stream(values.split("☆")).map(s->{
|
|
|
-// String[] t = s.split("_\\^_");
|
|
|
-// String[] c =t[1].split("_");
|
|
|
-// return new ElementData(0,0,t[0],Func.toInt(c[1]),Func.toInt(c[0]));
|
|
|
-// }).collect(Collectors.toList()), null,StringPool.EMPTY);
|
|
|
one.setEName(name);
|
|
|
return one;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public Map<String, String> getTableCols(String htmlUri) throws FileNotFoundException {
|
|
|
- Map<String, String> dataMap = new HashMap<>();
|
|
|
- File file1 = ResourceUtil.getFile(htmlUri);
|
|
|
- FileInputStream fileInputStream = new FileInputStream(file1);
|
|
|
- String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
- Document doc = Jsoup.parse(htmlString);
|
|
|
- Element table = doc.select("table").first();
|
|
|
- Elements trs = table.select("tr");
|
|
|
- // trs.stream().flatMap(tr->tr.select("td").stream()).filter(d->!d.children().isEmpty()).reduce()
|
|
|
- for (int i = 0; i <= trs.size() - 1; i++) {
|
|
|
- Element tr = trs.get(i);
|
|
|
- Elements tds = tr.select("td");
|
|
|
- for (int j = 0; j < tds.size(); j++) {
|
|
|
- Element data = tds.get(j);
|
|
|
- if (!data.children().isEmpty()) {
|
|
|
- String keyVal = i + "_" + j;
|
|
|
- String keyname = data.children().get(0).attr("keyname");
|
|
|
- if (org.apache.commons.lang.StringUtils.isNotEmpty(keyname)) {
|
|
|
- String[] keys = keyname.split("__");
|
|
|
- String datakey = keys[0];
|
|
|
- dataMap.merge(datakey, keyVal, (v1, v2) -> v1 + ";" + v2);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return dataMap;
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
@@ -574,14 +535,15 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
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));
|
|
|
- }
|
|
|
- }
|
|
|
+ write(fd,values);
|
|
|
+// 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<>());
|
|
@@ -619,6 +581,26 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
for(int n=0;n<fd.getValues().size();n++){
|
|
|
fd.getValues().get(n).setValue(values.get(n));
|
|
|
}
|
|
|
+ List<Object> overList=values.stream().skip(fd.getValues().size()).collect(Collectors.toList());
|
|
|
+ List<Coords> coordsList = fd.getCoordsList();
|
|
|
+ int addPage=(int)Math.ceil((double)overList.size()/(double)coordsList.size());
|
|
|
+ fd.setAddPages(addPage);
|
|
|
+ ElementData last =fd.getValues().get(fd.getValues().size()-1);
|
|
|
+ int indexBase=last.getIndex()+1;
|
|
|
+ List<ElementData> addList= new ArrayList<>();
|
|
|
+ for(int i=0;i<addPage;i++){
|
|
|
+ for(int j=0;j<coordsList.size();j++){
|
|
|
+ /*超页就尽管写进去,格式化阶段再加表*/
|
|
|
+ Coords coords = coordsList.get(j);
|
|
|
+ Object v=null;
|
|
|
+ int st=i*coordsList.size()*j;
|
|
|
+ if(st<overList.size()){
|
|
|
+ v= values.get(st);
|
|
|
+ }
|
|
|
+ addList.add(new ElementData(indexBase+i,last.getGroupId(),v,coords.getX(),coords.getY()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fd.getValues().addAll(addList);
|
|
|
}
|
|
|
|
|
|
}else{
|
|
@@ -638,33 +620,36 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
|
|
|
/**加页增容*/
|
|
|
- public void copy(FormData fd, List<Object> values){
|
|
|
- WbsTreeContract origin = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId,fd.getTableIds().get(fd.getTableIds().size()-1)));
|
|
|
+ public void copy(FormData fd){
|
|
|
+ int pageAdd=fd.getAddPages();
|
|
|
+ LinkedHashMap<String,List<KeyMapper>> tabs = this.tec.getKeyMappers().stream().collect(Collectors.groupingBy(KeyMapper::getCode,LinkedHashMap::new,Collectors.toList()));
|
|
|
+ List<KeyMapper> kms = tabs.get(fd.getCode());
|
|
|
+ KeyMapper last = kms.get(kms.size()-1);
|
|
|
+ WbsTreeContract origin = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId,last.getPkId()));
|
|
|
if(origin!=null){
|
|
|
- int pageSize = fd.getCoordsList().size();
|
|
|
- int pageAdd=(int)Math.ceil((double)(values.size()-fd.getValues().size())/(double) pageSize);
|
|
|
+ Long mark =origin.getPKeyId();
|
|
|
for(int i=0;i<pageAdd;i++){
|
|
|
/*复制表*/
|
|
|
WbsTreeContract target = new WbsTreeContract();
|
|
|
BeanUtil.copy(origin,target);
|
|
|
target.setPKeyId(SnowFlakeUtil.getId());
|
|
|
this.wbsTreeContractService.saveOrUpdate(target);
|
|
|
- tec.getKeyMappers().stream().filter(e->e.getPkId().equals(origin.getPKeyId())).findFirst().ifPresent(d->{
|
|
|
- /*添加KeyMapper映射关系*/
|
|
|
+ List<KeyMapper> allInTable=tec.getKeyMappers().stream().filter(e->e.getTableName().equals(fd.getTableName())).collect(Collectors.toList());
|
|
|
+ allInTable.forEach(e->{
|
|
|
KeyMapper km = new KeyMapper();
|
|
|
- BeanUtil.copy(d,km);
|
|
|
+ BeanUtil.copy(e,km);
|
|
|
km.setPkId(target.getPKeyId());
|
|
|
tec.getKeyMappers().add(km);
|
|
|
- tec.getTableInfoList().stream().filter(o->StringUtils.isEquals(o.getPkeyId(),origin.getPKeyId())).findFirst().ifPresent(tb->{
|
|
|
- /*表单数据复制*/
|
|
|
- TableInfo tableInfo = new TableInfo();
|
|
|
- BeanUtil.copy(tb,tableInfo);
|
|
|
- tableInfo.setDataMap(new LinkedHashMap<>());
|
|
|
- tec.getTableInfoList().add(tec.getTableInfoList().indexOf(tb)+1,tableInfo);
|
|
|
- });
|
|
|
+ });
|
|
|
+ tec.getTableInfoList().stream().filter(o->StringUtils.isEquals(o.getPkeyId(),mark)).findFirst().ifPresent(tb->{
|
|
|
+ /*表单数据复制*/
|
|
|
+ TableInfo tableInfo = new TableInfo();
|
|
|
+ BeanUtil.copy(tb,tableInfo);
|
|
|
+ tableInfo.setDataMap(new LinkedHashMap<>());
|
|
|
+ tec.getTableInfoList().add(tec.getTableInfoList().indexOf(tb)+1,tableInfo);
|
|
|
});
|
|
|
}
|
|
|
- enlarge(fd,pageAdd);
|
|
|
+ //enlarge(fd,pageAdd);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -709,6 +694,14 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ /*检查超页情况*/
|
|
|
+ LinkedHashMap<String,List<FormData>> tableElementMaps= this.formDataMap.values().stream().filter(e->e.getUpdate()==1&&e.getAddPages()>0).sorted(Comparator.comparing(FormData::getAddPages).reversed()).collect(Collectors.groupingBy(FormData::getTableName,LinkedHashMap::new,Collectors.toList()));
|
|
|
+ for(Map.Entry<String,List<FormData>> entry:tableElementMaps.entrySet()){
|
|
|
+ String tableName=entry.getKey();
|
|
|
+ FormData max= entry.getValue().get(0);
|
|
|
+ copy(max);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -725,9 +718,10 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/*当前节点的某个元素存在多种作用域的公式,作用域范围越小优先级越高*/
|
|
|
List<KeyMapper> list= listMap.stream().map(m->BeanUtil.toBean(m,KeyMapper.class)).collect(Collectors.toList());
|
|
|
String nodeIdStr=nodeIds.stream().map(Object::toString).collect(Collectors.joining(StringPool.COMMA));
|
|
|
- StringBuilder sb = new StringBuilder("select element_id elementId,formula_id formulaId,scope from m_element_formula_mapping where element_id in("+list.stream().map(KeyMapper::getFieldId).map(Func::toStr).collect(Collectors.joining(","))+") and is_deleted=0 ");
|
|
|
- sb.append(" and ( scope<2 or (scope=2 and node_id in(").append(nodeIdStr).append(")) or (scope =10 and project_id = ").append(projectId).append(") or (scope=20 and project_id =").append(projectId).append(" and node_id in (").append(nodeIdStr).append(")))");
|
|
|
- List<Map<String,Object>> efMap= this.jdbcTemplate.queryForList(sb.toString());
|
|
|
+ List<Map<String,Object>> efMap= this.jdbcTemplate.queryForList("select element_id elementId,formula_id formulaId,scope " +
|
|
|
+ "from m_element_formula_mapping " +
|
|
|
+ "where element_id in(" + list.stream().map(KeyMapper::getFieldId).map(Func::toStr).collect(Collectors.joining(",")) + ") " +
|
|
|
+ "and is_deleted=0 " + " and ( scope<2 or (scope=2 and node_id in(" + nodeIdStr + ")) or (scope =10 and project_id = " + projectId + ") or (scope=20 and project_id =" + projectId + " and node_id in (" + nodeIdStr + ")))");
|
|
|
if(Func.isNotEmpty(efMap)){
|
|
|
Map<Long,List<Map<String,Object>>> efGroup= efMap.stream().collect(Collectors.groupingBy(e->Func.toLong(e.get("elementId"))));
|
|
|
list.forEach(e->{
|
|
@@ -850,7 +844,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
Formula formula=fd.getFormula();
|
|
|
String f=formula.getFormula();
|
|
|
if (f.contains("converge")){
|
|
|
- Matcher m = RegexUtils.matcher("T\\(com.mixsmart.utils.CustomFunction\\)\\.(converge)\\(([^)]+)\\)",f);
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG+"(converge)\\(([^)]+)\\)",f);
|
|
|
while (m.find()){
|
|
|
List<FormData> target = getFormDataByCode(m.group(2));
|
|
|
Object data =target.stream().flatMap(e->e.getValues().stream()).map(ElementData::getValue).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
|
@@ -858,7 +852,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
if(f.contains("compound")){
|
|
|
- Matcher m = RegexUtils.matcher("T\\(com.mixsmart.utils.CustomFunction\\)\\.(compound)\\(([^)]+)\\)",f);
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG+"(compound)\\(([^)]+)\\)",f);
|
|
|
while (m.find()){
|
|
|
List<FormData> target = getFormDataByCode(m.group(2));
|
|
|
List<List<Object>> values=target.stream().map(e->e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList())).collect(Collectors.toList());
|
|
@@ -871,7 +865,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
if(f.contains(".option")){
|
|
|
- Matcher m = RegexUtils.matcher("T\\(com.mixsmart.utils.CustomFunction\\)\\.(optionC?)\\(([^)]+)\\)",f);
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG+"(optionC?)\\(([^)]+)\\)",f);
|
|
|
while (m.find()){
|
|
|
String[] args= m.group(2).split(",");
|
|
|
String flag=args[0];
|
|
@@ -900,9 +894,28 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if(f.contains(".ifelse")){
|
|
|
+ int max=0;
|
|
|
+ do{
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG+"(ifelse)\\(([^)]+)\\)",f);
|
|
|
+ while (m.find()){
|
|
|
+ String el=m.group();
|
|
|
+ String pstr=el.replaceAll("^"+FC_REG+"ifelse\\(","").replaceAll("\\)$","");
|
|
|
+ String pa[]=pstr.split(",");
|
|
|
+ if(pa.length==3){
|
|
|
+ Object data = Expression.parse(pa[0]+"?"+pa[1]+":"+pa[2]).calculate(createCurrentMap(el));
|
|
|
+ f=f.replace(el,putDataWithKey(data));
|
|
|
+ }else{
|
|
|
+ f=f.replace(el,"参数格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ max++;
|
|
|
+ }while (f.contains("ifelse")&&max<20);
|
|
|
+ }
|
|
|
if(f.contains("quantity")){
|
|
|
/*聚合*/
|
|
|
- Matcher m = RegexUtils.matcher("T\\(com.mixsmart.utils.CustomFunction\\)\\.(quantity)\\(([^)]+)\\)",f);
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG+"(quantity)\\(([^)]+)\\)",f);
|
|
|
while (m.find()) {
|
|
|
Object data=null;
|
|
|
List<String> codeList = getCodeList(m.group(2));
|
|
@@ -937,64 +950,51 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
|
|
|
|
|
|
+ public Map<String,Object> createCurrentMap(String el){
|
|
|
+ Map<String,Object> currentMap= new HashMap<String,Object>(this.constantMap);
|
|
|
+ List<FormData> fds= getFormDataByCode(String.join(",", getCodeByEl(el)));
|
|
|
+ if(Func.isNotEmpty(fds)){
|
|
|
+ Map<String,Object> E= (Map<String, Object>) currentMap.computeIfAbsent("E", k->new HashMap<String,Object>());
|
|
|
+ fds.forEach(e->{
|
|
|
+ E.put(e.getCode(),e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return currentMap;
|
|
|
+ }
|
|
|
+
|
|
|
public void tmpFc(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+"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 = getFormDataByCode(tf);
|
|
|
- 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);
|
|
|
+ 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 = getFormDataByCode(tf);
|
|
|
+ if(Func.isNotEmpty(target)){
|
|
|
+ if(StringUtils.isEmpty(formula.getScale())){
|
|
|
+ formula.setScale(2);
|
|
|
}
|
|
|
- }else if(f.contains(CustomFunction.CLASS_CALL+"ifelse(")){
|
|
|
- Matcher im =IF.matcher(f);
|
|
|
- while (im.find()){
|
|
|
- String rep =im.group();
|
|
|
- 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="";
|
|
|
- }
|
|
|
- }
|
|
|
+ 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()),"优良");
|
|
|
}
|
|
|
- formula.setFormula(f);
|
|
|
+ String key ="HA"+HashUtil.identityHashCode(data);
|
|
|
+ fd.getFormula().setFormula(key);
|
|
|
+ this.constantMap.put(key,data);
|
|
|
+ }else{
|
|
|
+ fd.getFormula().setFormula(StringPool.EMPTY);
|
|
|
}
|
|
|
- relyParse(fd.getFormula());
|
|
|
- StaticLog.info("聚合处理");
|
|
|
}
|
|
|
+ relyParse(fd.getFormula());
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -1012,6 +1012,18 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ public List<String> getCodeByEl(String el){
|
|
|
+ List<String> l = new ArrayList<>();
|
|
|
+ if(Func.isNotBlank(el)){
|
|
|
+ Matcher m = P.matcher(el);
|
|
|
+ while (m.find()){
|
|
|
+ String tmp =m.group().replaceAll("'","");
|
|
|
+ l.add(tmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return l;
|
|
|
+ }
|
|
|
/**把计算结果放入固定常量集,创建key来引用*/
|
|
|
public String putDataWithKey(Object data){
|
|
|
String key ="HA"+HashUtil.identityHashCode(data);
|
|
@@ -1050,29 +1062,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
|
|
|
- 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)){
|
|
|
- Pattern p = Pattern.compile("^FC\\.(\\w+)\\(([^()]+)\\)");
|
|
|
- for (Map<String,Object>map:list){
|
|
|
- Long ident = (Long) map.get("id");
|
|
|
- String formula = (String) map.get("formula");
|
|
|
- Matcher m= p.matcher(formula);
|
|
|
- if(m.find()){
|
|
|
- String change=m.group(2);
|
|
|
- String fn=m.group(1);
|
|
|
- List<String> args=Arrays.stream(change.split(",")).collect(Collectors.toList());
|
|
|
- if(args.size()<18){
|
|
|
- args.addAll(Collections.nCopies(18-args.size(),"''"));
|
|
|
- System.out.println("原:"+formula);
|
|
|
- String newFormula=("FC."+fn+"("+String.join(",",args)+")");
|
|
|
- System.out.println("改:"+newFormula);
|
|
|
- this.update(Wrappers.<Formula>lambdaUpdate().set(Formula::getFormula,newFormula).eq(Formula::getId,ident));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|