|
@@ -499,6 +499,10 @@ public class FormulaController {
|
|
|
@PostMapping("/chart-init")
|
|
|
@ApiOperationSupport(order = 11)
|
|
|
public R<Object> chartInit(@RequestBody ChartOption option){
|
|
|
+ /*1.获取公式配置,如果存在子公式,则一直查找到最终公式*/
|
|
|
+ /*2.查找所有依赖元素的所有数据,按表单排序*/
|
|
|
+ /*3.计算结果*/
|
|
|
+ /*4.查找当前表对应返回配置模版结合计算结果生成option*/
|
|
|
Long pkeyId=option.getPkeyId();
|
|
|
String id=option.getId();
|
|
|
WbsTreePrivate wtp = this.wbsTreePrivateService.getOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId,pkeyId));
|
|
@@ -572,5 +576,77 @@ public class FormulaController {
|
|
|
return R.data("{}");
|
|
|
}
|
|
|
|
|
|
+ public Formula formulaAct(Long pkeyId){
|
|
|
+ List<Map<String,Object>> configList= this.jdbcTemplate.queryForList("select d.rely,d.formula ,b.e_key ekey from m_wbs_tree_private a join m_wbs_form_element b on a.init_table_id=b.f_id join m_element_formula_mapping c on b.id=c.element_id join m_formula d on c.formula_id=d.id where p_key_id="+pkeyId+" and b.is_deleted=0 and d.formula like 'FC.chart%' limit 1");
|
|
|
+ if(Func.isNotEmpty(configList)) {
|
|
|
+ Map<String, Object> config = configList.get(0);
|
|
|
+ String relyStr=config.get("rely").toString();
|
|
|
+ String[] rely = relyStr.split(",");
|
|
|
+ String ky=rely[0].split(":")[1];
|
|
|
+ String kx=rely[1].split(":")[1];
|
|
|
+ Formula formulaY =new Formula();
|
|
|
+ formulaY.setFormula(config.get("formula").toString());
|
|
|
+ formulaY.setRely(relyStr);
|
|
|
+ formulaY.setFormula(nest(formulaY.getFormula(),formulaY.getRely()));
|
|
|
+ this.service.relyParse(formulaY);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description 根据元素码和当前工序pkeyId返回元素数据
|
|
|
+ * @Param [codes, pkeyId]
|
|
|
+ * @return java.util.Map<java.lang.String,java.util.List<org.springblade.manager.dto.ElementData>>
|
|
|
+ * @Author yangyj
|
|
|
+ * @Date 2023.08.01 14:53
|
|
|
+ **/
|
|
|
+ public Map<String,List<ElementData>> getDataFromCodes(List<String> codes,WbsTreePrivate wtp,String id){
|
|
|
+ String s = codes.stream().collect(Collectors.joining("','","'","'"));
|
|
|
+ List<Map<String,Object>> listMap = this.jdbcTemplate.queryForList("select a.id elementId,a.e_key ekey,a.e_name eName,b.init_table_name tableName,b.html_url url,b.p_key_id pkeyId,b.node_name nodeName,CONCAT(b.init_table_name,':',a.e_key) tk from m_wbs_form_element a join m_wbs_tree_private b on a.f_id=b.init_table_id where b.parent_id="+wtp.getParentId()
|
|
|
+ +" and b.project_id="+wtp.getProjectId()+" and b.is_deleted=0 and a.is_deleted=0 and CONCAT(b.init_table_name,':',a.e_key) in("+s+") ORDER BY b.sort,b.create_time");
|
|
|
+ if(listMap.size()>codes.size()){
|
|
|
+ Map<String,Map<String,String>> coordsMap = new HashMap<>();
|
|
|
+ for(Map<String,Object> m:listMap){
|
|
|
+ String tableName = m.get("tableName").toString();
|
|
|
+ if(!coordsMap.containsKey(tableName)){
|
|
|
+ coordsMap.put(tableName,FormulaUtils.getElementCell(m.get("url").toString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String,List<Map<String,Object>>> group= listMap.stream().collect(Collectors.groupingBy(m->m.get("tableName").toString()));
|
|
|
+ Map<String,String> codeDataMap= new HashMap<>();
|
|
|
+ group.forEach((k,v)->{
|
|
|
+ String sql ="select "+ v.stream().map(m->m.get("ekey").toString()).distinct().collect(Collectors.joining(","))+" from "
|
|
|
+ +k+" where p_key_id in("+v.stream().map(m->m.get("pkeyId").toString()).distinct().collect(Collectors.joining(","))
|
|
|
+ +" and group id ="+id;
|
|
|
+ List<Map<String,Object>> dataListMap = this.jdbcTemplate.queryForList(sql);
|
|
|
+ if(dataListMap.size()>0){
|
|
|
+ for(Map<String,Object> dm:listMap){
|
|
|
+ dm.forEach((ek,ev)->{
|
|
|
+ codeDataMap.merge(k+":"+ek,ev.toString(),(v1,v2)->v1+";;"+v2);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ Map<String,List<ElementData>> result = new HashMap<>();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String nest(String formula,String rely){
|
|
|
+ if(Func.isNotBlank(rely)) {
|
|
|
+ String s = Arrays.stream(rely.replaceAll("[\\s]+", "").split(",")).collect(Collectors.joining(",',", "'", "'"));
|
|
|
+ List<Map<String, Object>> listMap = this.jdbcTemplate.queryForList("select CONCAT(a.tab_en_name,':',b.e_key) ek,b.id,b.e_name ename,c.formula_id formulaId,d.formula,d.rely from m_table_info a join m_wbs_form_element b on a.id=b.f_id join m_element_formula_mapping c on b.id=c.element_id left join m_formula d on c.formula_id=d.id where concat(a.tab_en_name,':',b.e_key) in(" + s + ") and b.is_deleted =0 and c.is_deleted=0 ");
|
|
|
+ for (Map<String, Object> m : listMap) {
|
|
|
+ if (StringUtils.isNotEmpty(m.get("formulaId"))) {
|
|
|
+ String ek = m.get("ek").toString();
|
|
|
+ String formulaSub = nest(m.get("formula").toString(), m.get("rely").toString());
|
|
|
+ formula = formula.replace(ek, formulaSub);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return formula;
|
|
|
+ }
|
|
|
|
|
|
}
|