|
@@ -9,8 +9,10 @@ import com.jfireel.expression.node.CalculateNode;
|
|
|
import com.mixsmart.utils.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
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;
|
|
@@ -20,6 +22,7 @@ import org.springblade.manager.entity.WbsParam;
|
|
|
import org.springblade.manager.entity.WbsTreeContract;
|
|
|
import org.springblade.manager.formula.Container;
|
|
|
import org.springblade.manager.formula.FormulaStrategyFactory;
|
|
|
+import org.springblade.manager.formula.KeyMapper;
|
|
|
import org.springblade.manager.formula.impl.CompositeDataAccess;
|
|
|
import org.springblade.manager.formula.impl.TableElementConverter;
|
|
|
import org.springblade.manager.mapper.FormulaMapper;
|
|
@@ -44,7 +47,6 @@ import java.util.stream.Collectors;
|
|
|
public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula> implements IFormulaService {
|
|
|
|
|
|
private final IWbsParamService wpService;
|
|
|
- private final IWbsTreeContractService treeContractService;
|
|
|
private final FormulaStrategyFactory formulaStrategyFactory;
|
|
|
private final IContractInfoService contractInfoService;
|
|
|
private final IProjectInfoService projectInfoService;
|
|
@@ -67,6 +69,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
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= "(checkpoints|avg|min|max|sum|join|repeat|removeEmpty|listAt)\\(([^)]+)\\)";
|
|
|
public static final Pattern POLY = Pattern.compile(POLY_REG);
|
|
|
public final static String CTI="ContractInfo";
|
|
@@ -96,7 +99,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
|
public void execute(TableElementConverter tec) {
|
|
|
- WbsTreeContract one= this.treeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId,tec.getNodeId()));
|
|
|
+ WbsTreeContract one= this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId,tec.getNodeId()));
|
|
|
this.execute(tec.getFds(),tec.getContractId(),Func.isNotEmpty(one.getOldId())?Long.parseLong(one.getOldId()):one.getParentId(),one.getPKeyId());
|
|
|
}
|
|
|
|
|
@@ -119,20 +122,47 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/*表格名称*/
|
|
|
List<WbsTreeContract> tableList =wbsTreeContractService.searchNodeAllTable(primaryKeyId.toString(), "1", contractId.toString(),info.getPId());
|
|
|
this.env.constantMap.put(TABLE_LIST,tableList);
|
|
|
-// List<String> tableNames=this.jdbcTemplate.queryForList("SELECT "+
|
|
|
-// " wt.node_name " +
|
|
|
-// " FROM m_wbs_tree_private AS wt" +
|
|
|
-// " WHERE wt.type = 2" +
|
|
|
-// " AND wt.is_deleted = 0" +
|
|
|
-// " AND wt.parent_id = "+primaryKeyId +
|
|
|
-// " AND wt.wbs_id = "+nodes.get(0).getWbsId() +
|
|
|
-// " AND wt.project_id ="+ info.getPId()+
|
|
|
-// " ORDER BY wt.sort, wt.node_name, wt.create_time",String.class);
|
|
|
+ /*通过判断元素名称来确定,加入汇总公式延后执行*/
|
|
|
this.env.constantMap.put("tableNames",tableList.stream().map(WbsTreeContract::getFullName).collect(Collectors.toList()));
|
|
|
+ /*检查是否有跨节点数据*/
|
|
|
+ List<FormData> crossNodeFd=new ArrayList<>();
|
|
|
+ this.env.formDataList.forEach(fd->{
|
|
|
+ if(fd.executable()){
|
|
|
+ Matcher matcher=P2.matcher(fd.getFormula().getFormula());
|
|
|
+ while (matcher.find()){
|
|
|
+ String[] arr = matcher.group().split(StringPool.COLON);
|
|
|
+ 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.env.crossDataMap.computeIfAbsent(cross.getPKeyId(),(k)->this.jdbcTemplate.queryForMap("select * from " + arr[1] + " where p_key_id=" + k));
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(!crossNodeFd.isEmpty()){
|
|
|
+ System.out.println("跨节点元素:"+crossNodeFd.stream().map(FormData::getCode).collect(Collectors.joining(",")));
|
|
|
+ this.env.formDataList.addAll(crossNodeFd);
|
|
|
+ }
|
|
|
/*检查项目*/
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**引入关键字*/
|
|
|
public void keyWord(Map<String,Object> constantMap){
|
|
|
CustomFunction.KEYWORD_SET.forEach(e->{
|
|
@@ -354,6 +384,40 @@ 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,c.p_key_id as pkId ,a.e_key as field,a.id as fieldId,d.scope,d.formula_id as formulaId " +
|
|
|
+ "from m_wbs_form_element a " +
|
|
|
+ "INNER JOIN m_wbs_tree b on a.f_id=b.init_table_id " +
|
|
|
+ "INNER JOIN m_wbs_tree_contract c on (c.old_id=b.id or c.id=b.id) " +
|
|
|
+ "INNER JOIN m_element_formula_mapping d on a.id=d.element_id " +
|
|
|
+ "where c.p_key_id in("+ids.stream().map(String::valueOf).collect(Collectors.joining(","))+") " +
|
|
|
+ "ORDER BY b.init_table_name,d.scope");
|
|
|
+ if(Func.isNotEmpty(listMap)){
|
|
|
+ Map<Long,List<KeyMapper>> groupList= listMap.stream().map(m->BeanUtil.toBean(m, KeyMapper.class)).collect(Collectors.groupingBy(KeyMapper::getFormulaId,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);
|
|
|
+ }
|
|
|
+ if(set.size()>0){
|
|
|
+ return new ArrayList<>(set);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Formula> getFormulaList(List<KeyMapper> keyMapperList) {
|
|
|
+ if(Func.isNotEmpty(keyMapperList)){
|
|
|
+ List<Formula> result = this.listByIds(keyMapperList.stream().map(KeyMapper::getFormulaId).collect(Collectors.toList()));
|
|
|
+ if(Func.isNotEmpty(result)){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public Map<String,Object> getMap(Map<String,Object> main,String key){
|
|
|
Map<String,Object> CNDMap = (Map<String, Object>) main.get(key);
|
|
|
if(CNDMap==null){
|