|
@@ -7,15 +7,13 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.jfireel.expression.Expression;
|
|
import com.jfireel.expression.Expression;
|
|
import com.mixsmart.utils.*;
|
|
import com.mixsmart.utils.*;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
+import org.jsoup.Jsoup;
|
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
|
+import org.jsoup.nodes.Element;
|
|
|
|
+import org.jsoup.select.Elements;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
-import org.springblade.core.tool.utils.BeanUtil;
|
|
|
|
-import org.springblade.core.tool.utils.CollectionUtil;
|
|
|
|
-import org.springblade.core.tool.utils.Func;
|
|
|
|
-import org.springblade.core.tool.utils.StringPool;
|
|
|
|
-import org.springblade.manager.dto.ElementData;
|
|
|
|
-import org.springblade.manager.dto.FormData;
|
|
|
|
-import org.springblade.manager.dto.LocalVariable;
|
|
|
|
-import org.springblade.manager.dto.RangeInfo;
|
|
|
|
|
|
+import org.springblade.core.tool.utils.*;
|
|
|
|
+import org.springblade.manager.dto.*;
|
|
import org.springblade.manager.entity.ContractInfo;
|
|
import org.springblade.manager.entity.ContractInfo;
|
|
import org.springblade.manager.entity.Formula;
|
|
import org.springblade.manager.entity.Formula;
|
|
import org.springblade.manager.entity.WbsParam;
|
|
import org.springblade.manager.entity.WbsParam;
|
|
@@ -30,6 +28,10 @@ import org.springblade.manager.vo.AppWbsTreeContractVO;
|
|
import org.springblade.manager.vo.CurrentNode;
|
|
import org.springblade.manager.vo.CurrentNode;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
@@ -57,6 +59,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
private List<FormData> formDataList;
|
|
private List<FormData> formDataList;
|
|
private Map<Long,Map<String,Object>> crossDataMap;
|
|
private Map<Long,Map<String,Object>> crossDataMap;
|
|
private Map<String,FormData> formDataMap;
|
|
private Map<String,FormData> formDataMap;
|
|
|
|
+ private Map<String,Map<String,Object>> tableDataMaps;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -99,7 +102,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public IFormulaService init() {
|
|
public IFormulaService init() {
|
|
- this.formDataMap=new HashMap<>();
|
|
|
|
|
|
+ this.tableDataMaps=new HashMap<>();
|
|
|
|
+ this.formDataMap=this.tec.getFormDataMap();
|
|
this.crossDataMap=new HashMap<>();
|
|
this.crossDataMap=new HashMap<>();
|
|
List<FormData> list =this.tec.getFds();
|
|
List<FormData> list =this.tec.getFds();
|
|
Long contractId=this.tec.getContractId();
|
|
Long contractId=this.tec.getContractId();
|
|
@@ -126,45 +130,22 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
/*通过判断元素名称来确定,加入汇总公式延后执行*/
|
|
/*通过判断元素名称来确定,加入汇总公式延后执行*/
|
|
this.constantMap.put("tableNames",tableList.stream().map(WbsTreeContract::getFullName).collect(Collectors.toList()));
|
|
this.constantMap.put("tableNames",tableList.stream().map(WbsTreeContract::getFullName).collect(Collectors.toList()));
|
|
/*检查是否有跨节点数据*/
|
|
/*检查是否有跨节点数据*/
|
|
- List<FormData> crossNodeFd=new ArrayList<>();
|
|
|
|
|
|
+ List<String> missingList = new ArrayList<>();
|
|
this.formDataList.forEach(fd->{
|
|
this.formDataList.forEach(fd->{
|
|
if(fd.executable()){
|
|
if(fd.executable()){
|
|
- Matcher matcher=P2.matcher(fd.getFormula().getFormula());
|
|
|
|
- while (matcher.find()){
|
|
|
|
- String[] arr = matcher.group().split(StringPool.COLON);
|
|
|
|
- if(arr.length>=3){
|
|
|
|
- List<WbsTreeContract> targets=this.wbsTreeContractService.list(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getContractId,info.getId()).eq(WbsTreeContract::getId,Long.parseLong(arr[0])));
|
|
|
|
- /*暂时先只取第一个满足条件的*/
|
|
|
|
- if(Func.isNotEmpty(targets)){
|
|
|
|
- WbsTreeContract cross = targets.get(0);
|
|
|
|
- Map<String,Object> dataMap= this.crossDataMap.computeIfAbsent(cross.getPKeyId(),(k)->{List<Map<String,Object>> dmap=this.jdbcTemplate.queryForList("select * from " + arr[1] + " where p_key_id=" + k);
|
|
|
|
- if(Func.isNotEmpty(dmap)){
|
|
|
|
- return dmap.get(0);
|
|
|
|
- }else{
|
|
|
|
- return new HashMap<>();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if(dataMap.size()>0){
|
|
|
|
- String v= StringUtils.handleNull(dataMap.get(arr[2]));
|
|
|
|
- if(StringUtils.isNotEmpty(v)){
|
|
|
|
- crossNodeFd.add(new FormData(matcher.group(), Arrays.stream(v.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));
|
|
|
|
- }else{
|
|
|
|
- crossNodeFd.add(new FormData(matcher.group(),new ArrayList<>(),null,StringPool.EMPTY));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ relyParse(fd.getFormula());
|
|
|
|
+ Formula f= fd.getFormula();
|
|
|
|
+ List<String> relyList=f.getRelyList();
|
|
|
|
+ if(Func.isNotEmpty(relyList)){
|
|
|
|
+ relyList.forEach(r->{
|
|
|
|
+ if(this.formDataMap.values().stream().map(FormData::getCode).noneMatch(k->StringUtils.isEquals(k,r))){
|
|
|
|
+ missingList.add(r);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- if(!crossNodeFd.isEmpty()){
|
|
|
|
- System.out.println("跨节点元素:"+crossNodeFd.stream().map(FormData::getCode).collect(Collectors.joining(",")));
|
|
|
|
- this.formDataList.addAll(crossNodeFd);
|
|
|
|
- }
|
|
|
|
|
|
+ missingFill(missingList);
|
|
/*实测值参数*/
|
|
/*实测值参数*/
|
|
List<Map<String,Object>> textInfoMap= this.jdbcTemplate.queryForList("SELECT b.tab_id pkId, b.col_key ekey,b.col_name val ,c.init_table_name tableName " +
|
|
List<Map<String,Object>> textInfoMap= this.jdbcTemplate.queryForList("SELECT b.tab_id pkId, b.col_key ekey,b.col_name val ,c.init_table_name tableName " +
|
|
"from m_wbs_tree_contract a " +
|
|
"from m_wbs_tree_contract a " +
|
|
@@ -179,9 +160,152 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void vs(FormData fd){
|
|
|
|
+ List<FormData> crossNodeFd=new ArrayList<>();
|
|
|
|
+ Matcher matcher=P2.matcher(fd.getFormula().getFormula());
|
|
|
|
+ while (matcher.find()){
|
|
|
|
+ String[] arr = matcher.group().split(StringPool.COLON);
|
|
|
|
+ if(arr.length>=3){
|
|
|
|
+ List<WbsTreeContract> targets=this.wbsTreeContractService.list(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getContractId,this.tec.getContractId()).eq(WbsTreeContract::getId,Long.parseLong(arr[0])));
|
|
|
|
+ /*暂时先只取第一个满足条件的*/
|
|
|
|
+ if(Func.isNotEmpty(targets)){
|
|
|
|
+ WbsTreeContract cross = targets.get(0);
|
|
|
|
+ Map<String,Object> dataMap= this.crossDataMap.computeIfAbsent(cross.getPKeyId(),(k)->{List<Map<String,Object>> dmap=this.jdbcTemplate.queryForList("select * from " + arr[1] + " where p_key_id=" + k);
|
|
|
|
+ if(Func.isNotEmpty(dmap)){
|
|
|
|
+ return dmap.get(0);
|
|
|
|
+ }else{
|
|
|
|
+ return new HashMap<>();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if(dataMap.size()>0){
|
|
|
|
+ String v= StringUtils.handleNull(dataMap.get(arr[2]));
|
|
|
|
+ if(StringUtils.isNotEmpty(v)){
|
|
|
|
+ crossNodeFd.add(new FormData(matcher.group(), Arrays.stream(v.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));
|
|
|
|
+ }else{
|
|
|
|
+ crossNodeFd.add(new FormData(matcher.group(),new ArrayList<>(),null,StringPool.EMPTY));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void missingFill(List<String> missingList){
|
|
|
|
+ /*数据池里面没有任何元素匹配和当前依赖匹配*/
|
|
|
|
+ if(Func.isNotEmpty(missingList)){
|
|
|
|
+ StaticLog.info("缺失元素{}", String.join(";", missingList));
|
|
|
|
+ /*1从当前节点其它表格中查找匹配的元素*/
|
|
|
|
+ List<String> removeList=new ArrayList<>();
|
|
|
|
+ for(String r:missingList){
|
|
|
|
+ String tn = r.substring(0,r.indexOf(StringPool.COLON));
|
|
|
|
+ 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)){
|
|
|
|
+ String tableName = nodeList.get(0).getInitTableName();
|
|
|
|
+ try {
|
|
|
|
+ if(!this.tec.getCoordinateMap().containsKey(tableName)){
|
|
|
|
+ this.tec.getCoordinateMap().put(tableName, getTableCols(nodeList.get(0), null));
|
|
|
|
+ }
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(Func.isNotEmpty(removeList)){
|
|
|
|
+ /*移除已经找到的元素数据*/
|
|
|
|
+ missingList.removeIf(removeList::contains);
|
|
|
|
+ }
|
|
|
|
+ if(Func.isNotEmpty(missingList)){
|
|
|
|
+ /*2从当前节点的兄弟节点中查找匹配的元素*/
|
|
|
|
+ CurrentNode currentNode = this.tec.getCurrentNode();
|
|
|
|
+ List<Map<String,Object>> tableNamePkIdsMaps= this.jdbcTemplate.queryForList("select c.init_table_name tableName,c.p_key_id pkId from (select b.id from (select * from m_wbs_tree_contract where p_key_id="+currentNode.getPkId()+") a join m_wbs_tree_contract b on b.parent_id=a.parent_id where b.contract_id="+this.tec.getContractId()+" and b.is_deleted=0) k join m_wbs_tree_contract c on c.parent_id = k.id where c.contract_id="+this.tec.getContractId()+" and c.is_deleted=0 ");
|
|
|
|
+ if(Func.isNotEmpty(tableNamePkIdsMaps)){
|
|
|
|
+ removeList.clear();
|
|
|
|
+ missingList.forEach(miss->{
|
|
|
|
+ String tn = miss.substring(0,miss.indexOf(StringPool.COLON));
|
|
|
|
+ String key =miss.substring(miss.indexOf(StringPool.COLON)+1);
|
|
|
|
+ String targetIds=tableNamePkIdsMaps.stream().filter(m->StringUtils.isEquals(m.get("tableName"),tn)).map(m->m.get("pkId")).map(StringUtils::handleNull).collect(Collectors.joining(","));
|
|
|
|
+ List<Map<String,Object>> tableDatas= this.jdbcTemplate.queryForList("select * from "+tn+" p_key_id in ("+targetIds+")");
|
|
|
|
+ fill(tableDatas,removeList,tn,key);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(Func.isNotEmpty(removeList)){
|
|
|
|
+ /*移除已经找到的元素数据*/
|
|
|
|
+ missingList.removeIf(removeList::contains);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void fill(List<Map<String,Object>> tableDatas,List<String> removeList,String tn,String key){
|
|
|
|
+ if(Func.isNotEmpty(tableDatas)){
|
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
|
+ tableDatas.forEach(m->{
|
|
|
|
+ for(Map.Entry<String,Object> entry:m.entrySet()){
|
|
|
|
+ map.merge(entry.getKey(), entry.getValue(), (v1, v2) -> v1 + ";" + v2);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ this.tableDataMaps.put(tn,map);
|
|
|
|
+ String values= StringUtils.handleNull(map.get(key));
|
|
|
|
+ String r= tn+key;
|
|
|
|
+ if(StringUtils.isNotEmpty(values)){
|
|
|
|
+ FormData tmp=createFormDataFast(r,values);
|
|
|
|
+ if(tmp!=null){
|
|
|
|
+ removeList.add(r);
|
|
|
|
+ this.formDataMap.put(r,tmp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public FormData createFormDataFast(String code,String values){
|
|
|
|
+ if(StringUtils.isNotEmpty(code,values)){
|
|
|
|
+ return 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);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, String> getTableCols(AppWbsTreeContractVO wbsTreeContract, String colkey) throws FileNotFoundException {
|
|
|
|
+ Map<String, String> dataMap = new HashMap<>();
|
|
|
|
+ if (Func.isEmpty(wbsTreeContract.getHtmlUrl())) {
|
|
|
|
+ return dataMap;
|
|
|
|
+ }
|
|
|
|
+ File file1 = ResourceUtil.getFile(wbsTreeContract.getHtmlUrl());
|
|
|
|
+ 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");
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
- /**引入关键字*/
|
|
|
|
|
|
+ /**引入关键字*/
|
|
public void keyWord(Map<String,Object> constantMap){
|
|
public void keyWord(Map<String,Object> constantMap){
|
|
CustomFunction.KEYWORD_SET.forEach(e->{
|
|
CustomFunction.KEYWORD_SET.forEach(e->{
|
|
constantMap.put(e,e);
|
|
constantMap.put(e,e);
|
|
@@ -211,6 +335,23 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
result.put(p.getK(),p.getV());
|
|
result.put(p.getK(),p.getV());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ /*元素动态绑定*/
|
|
|
|
+ this.formDataMap.values().stream().filter(e->e.getIsCurrentNodeElement()&&e.getFormula()==null).forEach(e->{
|
|
|
|
+ /*执行列表里不存在,且元素的名称和节点参数名称匹配成功*/
|
|
|
|
+ total.stream().filter(p->e.getEName().contains(p.getName())&&!this.formDataList.contains(e)).findAny().ifPresent(d->{
|
|
|
|
+ Formula formula=new Formula();
|
|
|
|
+ formula.setOutm(Formula.FULL);
|
|
|
|
+ if(RegexUtil.match(ParamElements.LEVEL_REG,d.getV())){
|
|
|
|
+ /*取层级*/
|
|
|
|
+ formula.setFormula("FC.tree(trees,WP["+d.getK()+"])");
|
|
|
|
+ }else{
|
|
|
|
+ /*直接取数*/
|
|
|
|
+ formula.setFormula("WP["+d.getK()+"]");
|
|
|
|
+ }
|
|
|
|
+ e.setFormula(formula);
|
|
|
|
+ this.formDataList.add(e);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -304,11 +445,18 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
if(Func.isNotBlank(f)){
|
|
if(Func.isNotBlank(f)){
|
|
try{
|
|
try{
|
|
/*聚合运算*/
|
|
/*聚合运算*/
|
|
- polymerization();
|
|
|
|
|
|
+ polymerization(fd);
|
|
Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
List<String> relyList = fd.getFormula().getRelyList();
|
|
List<String> relyList = fd.getFormula().getRelyList();
|
|
if(CollectionUtil.isNotEmpty(relyList)){
|
|
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());
|
|
|
|
|
|
+// List<FormData> ele = this.formDataList.stream().filter(e->relyList.contains(e.getCode())&&e.getValues().stream().anyMatch(Func::isNotEmpty)).collect(Collectors.toList());
|
|
|
|
+ List<FormData> ele = new ArrayList<>();
|
|
|
|
+ relyList.forEach(rely->{
|
|
|
|
+ FormData formData= this.tec.getFormDataMap().get(rely);
|
|
|
|
+ if(formData!=null&&formData.getValues().stream().anyMatch(Func::isNotEmpty)){
|
|
|
|
+ ele.add(formData);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
if(ele.size()<relyList.size()){
|
|
if(ele.size()<relyList.size()){
|
|
System.out.println(formula.getFormula()+"不满足依赖要求");
|
|
System.out.println(formula.getFormula()+"不满足依赖要求");
|
|
}
|
|
}
|
|
@@ -322,6 +470,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
LinkedHashMap<String,ElementData> tip= cda.next();
|
|
LinkedHashMap<String,ElementData> tip= cda.next();
|
|
Map<String, Object> variable = new HashMap<>(this.constantMap);
|
|
Map<String, Object> variable = new HashMap<>(this.constantMap);
|
|
Map<String,Object> E=getMap(variable,"E");
|
|
Map<String,Object> E=getMap(variable,"E");
|
|
|
|
+ int index= new ArrayList<>(tip.values()).get(0).getIndex();
|
|
for(Map.Entry<String,ElementData> se:tip.entrySet()){
|
|
for(Map.Entry<String,ElementData> se:tip.entrySet()){
|
|
Object value=se.getValue().getValue();
|
|
Object value=se.getValue().getValue();
|
|
if(CustomFunction.isNumber(value)){
|
|
if(CustomFunction.isNumber(value)){
|
|
@@ -331,13 +480,10 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
- local.add(new LocalVariable(0,f,variable));
|
|
|
|
|
|
+ local.add(new LocalVariable(index,f,variable));
|
|
}
|
|
}
|
|
if(local.size()>0){
|
|
if(local.size()>0){
|
|
List<Object> values = slice(local,this.constantMap,f);
|
|
List<Object> values = slice(local,this.constantMap,f);
|
|
- if(StringUtils.isNotEmpty(formula.getScale())){
|
|
|
|
- values= values.stream().map(e->StringUtils.number2String(e,formula.getScale())).collect(Collectors.toList());
|
|
|
|
- }
|
|
|
|
if(values.size()>fd.getValues().size()){
|
|
if(values.size()>fd.getValues().size()){
|
|
/*当生成的数据超过实际容量的时候,会自动合并到第一个单元格*/
|
|
/*当生成的数据超过实际容量的时候,会自动合并到第一个单元格*/
|
|
fd.getValues().get(0).setValue(values.stream().filter(Func::isNotEmpty).map(StringUtils::handleNull).collect(Collectors.joining("、")));
|
|
fd.getValues().get(0).setValue(values.stream().filter(Func::isNotEmpty).map(StringUtils::handleNull).collect(Collectors.joining("、")));
|
|
@@ -402,14 +548,19 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void format() {
|
|
public void format() {
|
|
|
|
+ /*数据格式化*/
|
|
for(FormData fd:this.formDataList){
|
|
for(FormData fd:this.formDataList){
|
|
if(fd.verify()){
|
|
if(fd.verify()){
|
|
/*保留小数位*/
|
|
/*保留小数位*/
|
|
- Formula f = fd.getFormula();
|
|
|
|
- Integer scale =f.getScale();
|
|
|
|
- if(StringUtils.isNumber(scale)&&!fd.empty()){
|
|
|
|
- fd.setValues(fd.getValues().stream().peek(e-> e.setValue(StringUtils.number2String(e.getValue(),scale))).collect(Collectors.toList()));
|
|
|
|
- }
|
|
|
|
|
|
+ if(!fd.empty()&&fd.getValues().stream().map(ElementData::getValue).anyMatch(StringUtils::isDouble)){
|
|
|
|
+ Formula f = fd.getFormula();
|
|
|
|
+ Integer scale =f.getScale();
|
|
|
|
+ if(scale==null){
|
|
|
|
+ scale=2;
|
|
|
|
+ }
|
|
|
|
+ Integer finalScale = scale;
|
|
|
|
+ fd.setValues(fd.getValues().stream().peek(e->{if(StringUtils.isDouble(e.getValue())){e.setValue(StringUtils.number2String(e.getValue(),finalScale));}}).collect(Collectors.toList()));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -521,7 +672,14 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
List<String> l = new ArrayList<>();
|
|
List<String> l = new ArrayList<>();
|
|
Matcher m = P.matcher(f.getFormula());
|
|
Matcher m = P.matcher(f.getFormula());
|
|
while (m.find()){
|
|
while (m.find()){
|
|
- l.add(m.group().replaceAll("'",""));
|
|
|
|
|
|
+ String tmp =m.group().replaceAll("'","");
|
|
|
|
+ String cp=tmp;
|
|
|
|
+ if(tmp.indexOf(StringPool.COLON)!=tmp.lastIndexOf(StringPool.COLON)){
|
|
|
|
+ tmp=tmp.substring(tmp.indexOf(":")+1);
|
|
|
|
+ /*移除跨节点标识*/
|
|
|
|
+ f.setFormula(f.getFormula().replace(cp,tmp));
|
|
|
|
+ }
|
|
|
|
+ l.add(tmp);
|
|
}
|
|
}
|
|
if(l.size()>0){
|
|
if(l.size()>0){
|
|
f.setRely(String.join(",", l));
|
|
f.setRely(String.join(",", l));
|
|
@@ -537,81 +695,85 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
/**
|
|
/**
|
|
* 先把公式脚本需要聚合部分预处理
|
|
* 先把公式脚本需要聚合部分预处理
|
|
* */
|
|
* */
|
|
- public void polymerization(){
|
|
|
|
- for(FormData fd:this.formDataList){
|
|
|
|
- Formula formula = fd.getFormula();
|
|
|
|
- if(Func.isNotEmpty(formula)){
|
|
|
|
- String f=formula.getFormula();
|
|
|
|
- try {
|
|
|
|
- if(Func.isNotBlank(f)) {
|
|
|
|
- if (f.contains(CustomFunction.CLASS_CALL + "checkpoints(") ||f.contains(CustomFunction.CLASS_CALL + "avg(") || f.contains(CustomFunction.CLASS_CALL + "min(") || f.contains(CustomFunction.CLASS_CALL + "max(") || f.contains(CustomFunction.CLASS_CALL + "sum(")
|
|
|
|
- ||f.contains(CustomFunction.CLASS_CALL+"quantity(")||f.contains(CustomFunction.CLASS_CALL+"listAt(")||f.contains(CustomFunction.CLASS_CALL+"join(")||f.contains(CustomFunction.CLASS_CALL+"repeat(")||f.contains(CustomFunction.CLASS_CALL+"removeEmpty(")
|
|
|
|
- ) {
|
|
|
|
- /*聚合*/
|
|
|
|
- Matcher m = POLY.matcher(f);
|
|
|
|
- while (m.find()) {
|
|
|
|
- Object data=null;
|
|
|
|
- if(f.contains("quantity(")){
|
|
|
|
- String s = m.group(1).replace("'","");
|
|
|
|
- Map<String,List<Map<String,Object>>> tmap= (Map<String, List<Map<String, Object>>>) this.constantMap.getOrDefault("tmap",new HashMap<>());
|
|
|
|
- List<Map<String,Object>> tableColKeyVal= tmap.get(s);
|
|
|
|
- if(Func.isNotEmpty(tableColKeyVal)){
|
|
|
|
- data = tableColKeyVal.stream().map(map->{RangeInfo rangeInfo=BeanUtil.toBean((Map) map.get("val"), RangeInfo.class);return rangeInfo.getSize();}).collect(Collectors.toList());
|
|
|
|
- }else{
|
|
|
|
- /*手动计算*/
|
|
|
|
- System.out.println("");
|
|
|
|
- }
|
|
|
|
|
|
+ public void polymerization(FormData fd){
|
|
|
|
+// for(FormData fd:this.formDataList){
|
|
|
|
+// Formula formula = fd.getFormula();
|
|
|
|
+// }
|
|
|
|
+ Formula formula = fd.getFormula();
|
|
|
|
+ if(Func.isNotEmpty(formula)){
|
|
|
|
+ String f=formula.getFormula();
|
|
|
|
+ try {
|
|
|
|
+ if(Func.isNotBlank(f)) {
|
|
|
|
+ if (f.contains(CustomFunction.CLASS_CALL + "checkpoints(") ||f.contains(CustomFunction.CLASS_CALL + "avg(") || f.contains(CustomFunction.CLASS_CALL + "min(") || f.contains(CustomFunction.CLASS_CALL + "max(") || f.contains(CustomFunction.CLASS_CALL + "sum(")
|
|
|
|
+ ||f.contains(CustomFunction.CLASS_CALL+"quantity(")||f.contains(CustomFunction.CLASS_CALL+"listAt(")||f.contains(CustomFunction.CLASS_CALL+"join(")||f.contains(CustomFunction.CLASS_CALL+"repeat(")||f.contains(CustomFunction.CLASS_CALL+"removeEmpty(")
|
|
|
|
+ ) {
|
|
|
|
+ /*聚合*/
|
|
|
|
+ Matcher m = POLY.matcher(f);
|
|
|
|
+ while (m.find()) {
|
|
|
|
+ Object data=null;
|
|
|
|
+ if(f.contains("quantity(")){
|
|
|
|
+ String s = m.group(1).replace("'","");
|
|
|
|
+ Map<String,List<Map<String,Object>>> tmap= (Map<String, List<Map<String, Object>>>) this.constantMap.getOrDefault("tmap",new HashMap<>());
|
|
|
|
+ List<Map<String,Object>> tableColKeyVal= tmap.get(s);
|
|
|
|
+ if(Func.isNotEmpty(tableColKeyVal)){
|
|
|
|
+ data = tableColKeyVal.stream().map(map->{RangeInfo rangeInfo=BeanUtil.toBean((Map) map.get("val"), RangeInfo.class);return rangeInfo.getSize();}).collect(Collectors.toList());
|
|
}else{
|
|
}else{
|
|
- Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
|
- List<String> relyList = fd.getFormula().getRelyList();
|
|
|
|
- List<FormData> tmp = this.formDataList.stream().filter(e -> relyList.contains(e.getCode())).collect(Collectors.toList());
|
|
|
|
- Map<String, Object> E = getMap(currentMap, "E");
|
|
|
|
- tmp.forEach(e -> E.put(e.getCode(), e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList())));
|
|
|
|
- data = Expression.parse(CustomFunction.CLASS_CALL + m.group()).calculate(currentMap);
|
|
|
|
|
|
+ /*手动计算*/
|
|
|
|
+ System.out.println("");
|
|
}
|
|
}
|
|
- 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{
|
|
|
|
+ Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
|
+ List<String> relyList = fd.getFormula().getRelyList();
|
|
|
|
+ List<FormData> tmp = this.formDataList.stream().filter(e -> relyList.contains(e.getCode())).collect(Collectors.toList());
|
|
|
|
+ Map<String, Object> E = getMap(currentMap, "E");
|
|
|
|
+ tmp.forEach(e -> E.put(e.getCode(), e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList())));
|
|
|
|
+ data = Expression.parse(CustomFunction.CLASS_CALL + m.group()).calculate(currentMap);
|
|
}
|
|
}
|
|
- }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);
|
|
|
|
- }
|
|
|
|
|
|
+ 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)){
|
|
|
|
- Object data=null;
|
|
|
|
- if(f.contains("proportion")){
|
|
|
|
- data= CustomFunction.proportion(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0)).collect(Collectors.toList()), "优良");
|
|
|
|
- }else if(f.contains("ladder")){
|
|
|
|
- data= CustomFunction.ladder(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0)).collect(Collectors.toList()));
|
|
|
|
- }else if(f.contains("major")){
|
|
|
|
- data= CustomFunction.major(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0)).collect(Collectors.toList()));
|
|
|
|
- }else if(f.contains("reasonable")){
|
|
|
|
- data= CustomFunction.reasonable(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0)).collect(Collectors.toList()));
|
|
|
|
- }else if(f.contains("goodSize")){
|
|
|
|
- data= CustomFunction.goodSize(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0)).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(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);
|
|
}
|
|
}
|
|
- relyParse(fd.getFormula());
|
|
|
|
- System.out.println("聚合处理");
|
|
|
|
}
|
|
}
|
|
- }catch (Exception e){
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ relyParse(fd.getFormula());
|
|
|
|
+ StaticLog.info("聚合处理");
|
|
}
|
|
}
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|