|
@@ -15,7 +15,6 @@ import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springblade.common.utils.BaseUtils;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
-import org.springblade.core.mp.base.BaseEntity;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.*;
|
|
@@ -88,6 +87,9 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/**公式参数*/
|
|
|
public final static String FMOT="OP";
|
|
|
|
|
|
+ /**是否使用新流程*/
|
|
|
+ public final static boolean isNew=false;
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -99,6 +101,13 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
this.init().sort().pre().special().calculate().format();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void execute2(TableElementConverter tec) {
|
|
|
+ this.tec=tec;
|
|
|
+ /*初始化变量>>依赖排序>>预处理>>特殊公式>>通用公式执行>>数据格式化*/
|
|
|
+ this.init2().sort().pre().special().calculate().format();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public IFormulaService init() {
|
|
|
/*基础数据*/
|
|
@@ -113,6 +122,20 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
return this;
|
|
|
}
|
|
|
+ @Override
|
|
|
+ public IFormulaService init2(){
|
|
|
+ /*基础数据*/
|
|
|
+ baseData();
|
|
|
+ if(ExecuteType.INSPECTION.equals(tec.getExecuteType())) {
|
|
|
+ /*依赖加载*/
|
|
|
+ checkingMissingList();
|
|
|
+ /*公式参数*/
|
|
|
+ option();
|
|
|
+ /*评定表*/
|
|
|
+ assessmentForm();
|
|
|
+ }
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
public void option(){
|
|
|
FormulaOption formulaOption = this.formulaOptionService.getById(tec.getCurrentNode().getPkId());
|
|
@@ -121,20 +144,14 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/* public void textInfo(){
|
|
|
- List<Map<String,Object>> textInfoMap= this.jdbcTemplate.queryForList("SELECT b.tab_id pkId,b.col_name val ,CONCAT(a.init_table_name,':',b.col_key)code from m_wbs_tree_contract a inner join m_textdict_info b on a.p_key_id=b.tab_id " +
|
|
|
- "where a.p_key_id in("+this.tec.getTableAll().stream().map(NodeTable::getPKeyId).map(Func::toStr).collect(Collectors.joining(","))+") and b.type=8 ");
|
|
|
- if(Func.isNotEmpty(textInfoMap)){
|
|
|
- Map<String,List<Map<String,Object>>> tmap = textInfoMap.stream().collect(Collectors.groupingBy(m->m.get("code").toString()));
|
|
|
- tec.constantMap.put(TEXT_INFO_MAP,tmap);
|
|
|
- }
|
|
|
- }*/
|
|
|
+
|
|
|
|
|
|
|
|
|
public void baseData(){
|
|
|
- List<FormData> list =this.tec.getFds();
|
|
|
+ /*List<FormData> list =this.tec.getFds();*/
|
|
|
CurrentNode one=this.tec.getCurrentNode();
|
|
|
- tec.formDataList=list;
|
|
|
+ /*tec.formDataList=list;*/
|
|
|
+ /*预设关键字*/
|
|
|
keyWord(tec.constantMap);
|
|
|
|
|
|
/*wbs节点链*/
|
|
@@ -158,25 +175,42 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
|
|
|
|
|
|
- /**补充确实的原始依赖*/
|
|
|
+ /**补充缺失的元素依赖*/
|
|
|
public void checkingMissingList(){
|
|
|
List<String> missingList = new ArrayList<>();
|
|
|
- tec.formDataList.forEach(fd->{
|
|
|
- if(fd.executable()){
|
|
|
- relyParse(fd.getFormula());
|
|
|
- Formula f= fd.getFormula();
|
|
|
- List<String> relyList=f.getRelyList();
|
|
|
- if(Func.isNotEmpty(relyList)){
|
|
|
- relyList.forEach(r->{
|
|
|
- if(tec.formDataMap.values().stream().map(FormData::getCode).noneMatch(k->StringUtils.isEquals(k,r))){
|
|
|
- missingList.add(r);
|
|
|
- }
|
|
|
- });
|
|
|
+ if(isNew){
|
|
|
+ tec.formDataList.forEach(fd->{
|
|
|
+ if (fd.executable()) {
|
|
|
+ relyParse(fd.getFormula());
|
|
|
+ Formula f = fd.getFormula();
|
|
|
+ List<String> relyList = f.getRelyList();
|
|
|
+ if (Func.isNotEmpty(relyList)) {
|
|
|
+ relyList.forEach(r -> {
|
|
|
+ if (!tec.formDataMap.containsKey(r)) {
|
|
|
+ missingList.add(r);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- missingFill(missingList);
|
|
|
+ });
|
|
|
+ missingFill2(missingList);
|
|
|
+ }else {
|
|
|
+ tec.formDataList.forEach(fd -> {
|
|
|
+ if (fd.executable()) {
|
|
|
+ relyParse(fd.getFormula());
|
|
|
+ Formula f = fd.getFormula();
|
|
|
+ List<String> relyList = f.getRelyList();
|
|
|
+ if (Func.isNotEmpty(relyList)) {
|
|
|
+ relyList.forEach(r -> {
|
|
|
+ if (tec.formDataMap.values().stream().map(FormData::getCode).noneMatch(k -> StringUtils.isEquals(k, r))) {
|
|
|
+ missingList.add(r);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ missingFill(missingList);
|
|
|
+ }
|
|
|
if(Func.isNotEmpty(missingList)){
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
missingList.stream().collect(Collectors.groupingBy(s->s.split(StringPool.COLON)[0])).forEach((k,v)->{
|
|
@@ -187,6 +221,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
public FormulaDataBlock findFdb(){
|
|
|
/*查找第一个包含分项评定子节点的父节点*/
|
|
|
Long ancestor=findFirstParentId();
|
|
@@ -412,6 +448,62 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ public void missingFill2(List<String> missingList){
|
|
|
+ /*数据池里面没有任何元素匹配和当前依赖匹配*/
|
|
|
+ if(Func.isNotEmpty(missingList)){
|
|
|
+ StaticLog.info("需要挂载的元素{}", String.join(";", missingList));
|
|
|
+ // Map<String, Object> elementInfoMap=this.getElementInfoByCodes(String.join(",",missingList));
|
|
|
+ Map<String,FormData> fdsMap = this.createFormDataByCode(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);
|
|
|
+ FormData fd= fdsMap.get(r);
|
|
|
+ /* if (tec.getTableAll().stream().anyMatch(e->StringUtils.isEquals(e.getInitTableName(),fd.getTableName()))) {
|
|
|
+ removeList.add(r);
|
|
|
+ String tableName = fd.getTableName();
|
|
|
+ if (!tec.getCoordinateMap().containsKey(tableName)) {
|
|
|
+ tec.getCoordinateMap().put(tableName, FormulaUtils.getElementCell());
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> tableDatas = this.jdbcTemplate.queryForList("select * from " + tableName + " where p_key_id in(" + nodeList.stream().map(NodeTable::getPKeyId).map(StringUtils::handleNull).collect(Collectors.joining(",")) + ")");
|
|
|
+ fill(tableDatas, removeList, tn, key, StringUtils.handleNull(elementInfo.get("ename")));
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ if (Func.isNotEmpty(removeList)) {
|
|
|
+ /*移除已经找到的元素数据*/
|
|
|
+ missingList.removeIf(removeList::contains);
|
|
|
+ }
|
|
|
+ if(Func.isNotEmpty(missingList)){
|
|
|
+ /*2从当前节点的兄弟节点中查找匹配的元素*/
|
|
|
+ CurrentNode currentNode = tec.getCurrentNode();
|
|
|
+ List<Map<String,Object>> tableNamePkIdsMaps= this.jdbcTemplate.queryForList("select c.init_table_name tableName,c.p_key_id pkId,c.html_url url from (select b.id from m_wbs_tree_contract a join m_wbs_tree_contract b on (a.contract_id=b.contract_id and b.ancestors like CONCAT(a.ancestors,'%')) where a.p_key_id="+currentNode.getPkId()+" and b.is_deleted=0 and b.node_type=6 ORDER BY b.sort) k join m_wbs_tree_contract c on c.parent_id = k.id where c.contract_id="+tec.getContractId()+" and c.is_deleted=0 ");
|
|
|
+ if(Func.isNotEmpty(tableNamePkIdsMaps)){
|
|
|
+ // removeList.clear();
|
|
|
+ missingList.forEach(miss->{
|
|
|
+ /* Map<String,Object> elementInfo= (Map<String, Object>) elementInfoMap.get(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(","));
|
|
|
+ if(Func.isNotEmpty(targetIds)){
|
|
|
+ if(!this.tec.getCoordinateMap().containsKey(tn)){
|
|
|
+ tableNamePkIdsMaps.stream().filter(m->StringUtils.isEquals(m.get("tableName"),tn)).findAny().ifPresent(m->{
|
|
|
+ this.tec.getCoordinateMap().put(tn,FormulaUtils.getElementCell(StringUtils.handleNull(m.get("url"))));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ List<Map<String,Object>> tableDatas= this.jdbcTemplate.queryForList("select * from "+tn+" where p_key_id in ("+targetIds+")");
|
|
|
+ String tmp =elementInfo==null?"":StringUtils.handleNull(elementInfo.get("ename"));
|
|
|
+ fill(tableDatas,removeList,tn,key,tmp);
|
|
|
+ }*/
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(Func.isNotEmpty(removeList)){
|
|
|
+ /*移除已经找到的元素数据*/
|
|
|
+ missingList.removeIf(removeList::contains);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public void fill(List<Map<String,Object>> tableDatas,List<String> removeList,String tn,String key,String name){
|
|
|
if(Func.isNotEmpty(tableDatas)){
|
|
@@ -514,28 +606,54 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
this.tec.getLog().put(FormulaLog.PARAM,result.entrySet().stream().map(p->logMap.get(p.getKey())+":"+p.getValue()).collect(Collectors.joining(";")));
|
|
|
/*元素动态绑定*/
|
|
|
+ /*绑定节点参数公式*/
|
|
|
+ this.bindParamFormula(total);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void bindParamFormula(List<WbsParam> total){
|
|
|
Map<String,Formula> formulaIdMap = this.wpService.formulaKeyMap(total.stream().map(WbsParam::getK).collect(Collectors.toList()));
|
|
|
- /**查找无绑定公式且单元格只有一个的当前表单元素*/
|
|
|
- List<FormData> notFormulaFds=tec.formDataMap.values().stream().filter(e->e.getIsCurrentNodeElement()&&e.getFormula()==null&&e.getCoordsList().size()==1).collect(Collectors.toList());
|
|
|
- if(notFormulaFds.size()>0){
|
|
|
- notFormulaFds.forEach(e->{
|
|
|
- /*执行列表里不存在,且元素的名称和节点参数名称匹配成功,暂时用参数名称是否包含元素名称作为匹配规则*/
|
|
|
- total.stream().filter(p->e.getEName().contains(p.getName().replaceAll("【[\\u4E00-\\u9FFF]+】|\\s+",""))&&!tec.formDataList.contains(e)).findAny().ifPresent(d->{
|
|
|
- Formula tf= formulaIdMap.get(d.getK());
|
|
|
- if(tf!=null&&e.getId()!=null) {
|
|
|
- e.setFormula(tf);
|
|
|
- tec.formDataList.add(e);
|
|
|
- ElementFormulaMapping efm = new ElementFormulaMapping();
|
|
|
- efm.setScope(FormulaBean.PARAM);
|
|
|
- efm.setParamId(d.getId());
|
|
|
- efm.setElementId(e.getId());
|
|
|
- efm.setFormulaId(tf.getId());
|
|
|
- this.elementFormulaMappingService.save(efm);
|
|
|
- }
|
|
|
+ /*查找无绑定公式且单元格只有一个的当前表单元素*/
|
|
|
+ if(isNew){
|
|
|
+ List<FormData> notFormulaFds= tec.formDataList.stream().filter(e->e.getIsCurrentSubmitElement()&&e.getFormula()==null&&e.getCoordsList().size()==1).collect(Collectors.toList());
|
|
|
+ if(notFormulaFds.size()>0){
|
|
|
+ notFormulaFds.forEach(e->{
|
|
|
+ /*执行列表里不存在,且元素的名称和节点参数名称匹配成功,暂时用参数名称是否包含元素名称作为匹配规则*/
|
|
|
+ total.stream().filter(p->e.getEName().contains(p.getName().replaceAll("【[\\u4E00-\\u9FFF]+】|\\s+",""))&&!tec.formDataList.contains(e)).findAny().ifPresent(d->{
|
|
|
+ Formula tf= formulaIdMap.get(d.getK());
|
|
|
+ if(tf!=null&&e.getId()!=null) {
|
|
|
+ e.setFormula(tf);
|
|
|
+ ElementFormulaMapping efm = new ElementFormulaMapping();
|
|
|
+ efm.setScope(FormulaBean.PARAM);
|
|
|
+ efm.setParamId(d.getId());
|
|
|
+ efm.setElementId(e.getId());
|
|
|
+ efm.setFormulaId(tf.getId());
|
|
|
+ this.elementFormulaMappingService.save(efm);
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ List<FormData> notFormulaFds=tec.formDataMap.values().stream().filter(e->e.getIsCurrentNodeElement()&&e.getFormula()==null&&e.getCoordsList().size()==1).collect(Collectors.toList());
|
|
|
+ if(notFormulaFds.size()>0){
|
|
|
+ notFormulaFds.forEach(e->{
|
|
|
+ /*执行列表里不存在,且元素的名称和节点参数名称匹配成功,暂时用参数名称是否包含元素名称作为匹配规则*/
|
|
|
+ total.stream().filter(p->e.getEName().contains(p.getName().replaceAll("【[\\u4E00-\\u9FFF]+】|\\s+",""))&&!tec.formDataList.contains(e)).findAny().ifPresent(d->{
|
|
|
+ Formula tf= formulaIdMap.get(d.getK());
|
|
|
+ if(tf!=null&&e.getId()!=null) {
|
|
|
+ e.setFormula(tf);
|
|
|
+ tec.formDataList.add(e);
|
|
|
+ ElementFormulaMapping efm = new ElementFormulaMapping();
|
|
|
+ efm.setScope(FormulaBean.PARAM);
|
|
|
+ efm.setParamId(d.getId());
|
|
|
+ efm.setElementId(e.getId());
|
|
|
+ efm.setFormulaId(tf.getId());
|
|
|
+ this.elementFormulaMappingService.save(efm);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -1543,10 +1661,11 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
List<Map<String,Object>> listMap = listMap(ids,ExecuteType.TESTING);
|
|
|
List<KeyMapper> list= listMap.stream().map(m->BeanUtil.toBean(m,KeyMapper.class)).collect(Collectors.toList());
|
|
|
if(Func.isNotEmpty(listMap)){
|
|
|
+ WbsTreePrivate wtp= this.wbsTreePrivateService.getOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId,nodeId));
|
|
|
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).distinct().map(Func::toStr).collect(Collectors.joining(",")) + ") " +
|
|
|
- "and is_deleted=0 " + " and ( scope<2 or (scope =10 and project_id = " + projectId + ") )");
|
|
|
+ "and is_deleted=0 " + " and ( scope<2 or (scope =10 and project_id = " + projectId + ") or (scope=20 and project_id =" + projectId + " and node_id="+wtp.getId()+"))");
|
|
|
setFormula(list,efMap);
|
|
|
if(list.size()>0){
|
|
|
return list;
|
|
@@ -2003,8 +2122,48 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, FormData> createFormDataByCode(String codes) {
|
|
|
+ if(Func.isNotBlank(codes)) {
|
|
|
+ List<String> codeList = Arrays.asList(codes.split(StringPool.COMMA));
|
|
|
+ String tableNames = codeList.stream().map(e->e.split(StringPool.COLON)[0]).collect(Collectors.joining(","));
|
|
|
+ /*select d.id,c.tab_ch_name tableChName,d.e_type eType,d.e_name eName,d.e_length eLength,d.e_allow_deviation eAllowDeviation,CONCAT(c.tab_en_name,':',d.e_key) code */
|
|
|
+ List<FormData> fds =createFormDataByTableName(tableNames);
|
|
|
+ if(fds!=null){
|
|
|
+ return fds.stream().filter(e->codeList.contains(e.getCode())).collect(Collectors.toMap(FormData::getCode,f->f));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FormData> createFormDataByTableName(String tableNames) {
|
|
|
+ List<FormData> fds =this.getSqlList("select b.id, CONCAT(a.tab_en_name,':',b.e_key) code,a.tab_ch_name tableChName,b.e_name eName ,b.e_allow_deviation eAllowDeviation ,b.e_length eLength,c.dict_value eType " +
|
|
|
+ "from m_table_info a JOIN m_wbs_form_element b on a.id=b.f_id and b.is_deleted=0 " +
|
|
|
+ "LEFT JOIN (select dict_key, dict_value from blade_dict where code ='data_type' and parent_id > 0 and is_sealed = 0 and is_deleted = 0 )c on b.e_type=c.dict_key" +
|
|
|
+ " where a.tab_en_name in( "+ tableNames+")"
|
|
|
+ , FormData.class);
|
|
|
+ return fds;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void loadElementData(List<FormData> curFormDatas, Map<String, List<Long>> tableNamePkeyIdMap) {
|
|
|
+ Map<String,List<FormData>> group = curFormDatas.stream().collect(Collectors.groupingBy(FormData::getTableName,Collectors.toList()));
|
|
|
+ group.forEach((k,v)->{
|
|
|
+ String ids =tableNamePkeyIdMap.get(k).stream().map(Objects::toString).collect(Collectors.joining(","));
|
|
|
+ String sql="select id,p_key_id pageId,tab_key tabKey ,key_val value from table_data_info where p_key_id in("+ids+")";
|
|
|
+ List<CellDataVo> list= this.getSqlList(sql,CellDataVo.class);
|
|
|
+ if(list!=null){
|
|
|
+ Set<String> set= v.stream().map(FormData::getTableName).collect(Collectors.toSet());
|
|
|
+ Map<String, List<CellDataVo>> targetGroup=list.stream().filter(e->set.contains(e.getKey())).collect(Collectors.groupingBy(CellDataVo::getKey,Collectors.toList()));
|
|
|
+ for(FormData fd:v){
|
|
|
+ fd.setCellDataVoList(targetGroup.get(fd.getKey()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|