|
@@ -33,6 +33,7 @@ import org.springblade.manager.vo.AppWbsTreeContractVO;
|
|
import org.springblade.manager.vo.CurrentNode;
|
|
import org.springblade.manager.vo.CurrentNode;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.context.annotation.ScopedProxyMode;
|
|
import org.springframework.context.annotation.ScopedProxyMode;
|
|
|
|
+import org.springframework.http.converter.json.MappingJacksonValue;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.context.WebApplicationContext;
|
|
import org.springframework.web.context.WebApplicationContext;
|
|
@@ -132,11 +133,12 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
/*公式参数*/
|
|
/*公式参数*/
|
|
option();
|
|
option();
|
|
/*评定表*/
|
|
/*评定表*/
|
|
- assessmentForm();
|
|
|
|
|
|
+ assessmentForm2();
|
|
}
|
|
}
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /*單元格配置信息*/
|
|
public void option(){
|
|
public void option(){
|
|
FormulaOption formulaOption = this.formulaOptionService.getById(tec.getCurrentNode().getPkId());
|
|
FormulaOption formulaOption = this.formulaOptionService.getById(tec.getCurrentNode().getPkId());
|
|
if (formulaOption != null) {
|
|
if (formulaOption != null) {
|
|
@@ -360,7 +362,95 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ public void assessmentForm2(){
|
|
|
|
+ if(!ExecuteType.INSPECTION.equals(tec.getExecuteType())){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ if (tec.getTableAll().stream().anyMatch(e -> StringUtils.isEquals(e.getTableType(), 5))) {
|
|
|
|
+ /*评定节点*/
|
|
|
|
+ FormulaDataBlock fdb = findFdb();
|
|
|
|
+ if (!StringUtils.isEquals("[]", fdb.getVal())) {
|
|
|
|
+ List<ElementBlock> elementBlockList = JSON.parseArray(fdb.getVal(), ElementBlock.class);
|
|
|
|
+ Map<String, Measurement> itemsMap = new HashMap<>();
|
|
|
|
+ tec.formDataMap.values().stream().filter(FormData::getIsCurrentNodeElement).forEach(e -> {
|
|
|
|
+ String eName = e.getEName();
|
|
|
|
+ if (eName.contains("实测") && !eName.contains("平均") && !eName.contains("合格率") && !eName.contains("判")) {
|
|
|
|
+ String point = FormulaUtils.parseItemName(eName);
|
|
|
|
+ /*评定匹配检验单的元素用相似匹配*/
|
|
|
|
+ Measurement measurement = itemsMap.computeIfAbsent(point, k -> new Measurement(point));
|
|
|
|
+ measurement.setValue(e);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (itemsMap.size() > 0) {
|
|
|
|
+ /*表内用同行匹配*/
|
|
|
|
+ List<FormData> primary = tec.getFormDataMap().values().stream().filter(FormData::getIsCurrentNodeElement).filter(v -> v.getEName().contains("率") || v.getEName().contains("判")).collect(Collectors.toList());
|
|
|
|
+ itemsMap.values().forEach(i -> {
|
|
|
|
+ FormData vf = i.getValue();
|
|
|
|
+ primary.stream().filter(p -> vf.getMaxRow().equals(p.getMaxRow()) && vf.getTableName().equals(p.getTableName())).forEach(t -> {
|
|
|
|
+ if (t.getEName().contains("合格率")) {
|
|
|
|
+ i.setPass(t);
|
|
|
|
+ } else if (t.getEName().contains("判")) {
|
|
|
|
+ i.setJudge(t);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ AtomicBoolean update = new AtomicBoolean(false);
|
|
|
|
+ itemsMap.values().stream().filter(Measurement::isMatching).forEach(t -> {
|
|
|
|
+ ElementBlock g = null;
|
|
|
|
+ FormData vfd = t.getValue();
|
|
|
|
+ if (vfd.executable() && vfd.getFormula().getRelyList() != null) {
|
|
|
|
+ List<String> relyList = vfd.getFormula().getRelyList();
|
|
|
|
+ /*先从公式去匹配*/
|
|
|
|
+ Optional<ElementBlock> op = elementBlockList.stream().filter(e -> relyList.contains(e.getCode())).findAny();
|
|
|
|
+ if (op.isPresent()) {
|
|
|
|
+ g = op.get();
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ /*只有不存在配置的前提下才能尝试自动匹配*/
|
|
|
|
+ Optional<ElementBlock> op = elementBlockList.stream().filter(w -> FormulaUtils.similarity(w.getEName(), t.getPoint()) > 0.3).max(Comparator.comparingDouble((ElementBlock b) -> FormulaUtils.similarity(b.getEName(), t.getPoint())));
|
|
|
|
+ /*相似匹配*/
|
|
|
|
+ if (op.isPresent()) {
|
|
|
|
+ g = op.get();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (g != null) {
|
|
|
|
+ List<ItemBlock> itemBlockList = g.getList();
|
|
|
|
+ int originSize = itemBlockList.size();
|
|
|
|
+ List<Long> ids =getNodeType46().stream().map(CurrentNode::getPkId).collect(Collectors.toList());
|
|
|
|
+ /*清除那些已经不存在的工序*/
|
|
|
|
+ itemBlockList.removeIf(ik -> !ids.contains(ik.getPkeyId()));
|
|
|
|
+ if (itemBlockList.size() > 0) {
|
|
|
|
+ int total = itemBlockList.stream().mapToInt(ItemBlock::getSubTotal).sum();
|
|
|
|
+ int passNum = itemBlockList.stream().mapToInt(ItemBlock::getSubPass).sum();
|
|
|
|
+ double passRate = 100 * (double) passNum / (double) total;
|
|
|
|
+ FormulaUtils.write(t.getPass(), StringUtils.number2String(passRate, 1), false);
|
|
|
|
+ if (passRate >= 60) {
|
|
|
|
+ FormulaUtils.write(t.getJudge(), "合格", false);
|
|
|
|
+ }
|
|
|
|
+// itemBlockList.sort(Comparator.comparingInt(a -> ids.indexOf(a.getPkeyId())));
|
|
|
|
+ List<String> values = itemBlockList.stream().map(ItemBlock::getData).flatMap(v -> v.stream().flatMap(Collection::stream)).map(Object::toString).collect(Collectors.toList());
|
|
|
|
+ int scale = StringUtils.getScale(values);
|
|
|
|
+ FormulaUtils.write(t.getValue(), values.stream().map(u -> StringUtils.number2String(u, scale)).collect(Collectors.toList()), true);
|
|
|
|
+//
|
|
|
|
+ }
|
|
|
|
+ t.flush();
|
|
|
|
+ if (originSize > 0 && originSize != itemBlockList.size()) {
|
|
|
|
+ g.setList(itemBlockList);
|
|
|
|
+ update.set(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (update.get()) {
|
|
|
|
+ this.formulaDataBlockService.saveOrUpdate(fdb);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
public void descendantType46(Object id, List<Map<String,Object>> listMaps){
|
|
public void descendantType46(Object id, List<Map<String,Object>> listMaps){
|
|
String sql="select p_Key_id pkId,id,node_type nodeType,table_type tableType from m_wbs_tree_contract where parent_id =? and is_deleted=0";
|
|
String sql="select p_Key_id pkId,id,node_type nodeType,table_type tableType from m_wbs_tree_contract where parent_id =? and is_deleted=0";
|
|
@@ -452,51 +542,54 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
/*数据池里面没有任何元素匹配和当前依赖匹配*/
|
|
/*数据池里面没有任何元素匹配和当前依赖匹配*/
|
|
if(Func.isNotEmpty(missingList)){
|
|
if(Func.isNotEmpty(missingList)){
|
|
StaticLog.info("需要挂载的元素{}", String.join(";", missingList));
|
|
StaticLog.info("需要挂载的元素{}", String.join(";", missingList));
|
|
- // Map<String, Object> elementInfoMap=this.getElementInfoByCodes(String.join(",",missingList));
|
|
|
|
Map<String,FormData> fdsMap = this.createFormDataByCode(String.join(",",missingList));
|
|
Map<String,FormData> fdsMap = this.createFormDataByCode(String.join(",",missingList));
|
|
/*1从当前节点其它表格中查找匹配的元素*/
|
|
/*1从当前节点其它表格中查找匹配的元素*/
|
|
List<String> removeList=new ArrayList<>();
|
|
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"))));
|
|
|
|
- });
|
|
|
|
|
|
+ /*2从当前节点的兄弟节点中查找匹配的元素*/
|
|
|
|
+ CurrentNode currentNode = tec.getCurrentNode();
|
|
|
|
+ String sql= "select c.init_table_name tableName,c.p_key_id pkeyId,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 ";
|
|
|
|
+ List<TableFormMapper> tableNamePkIdsList = this.getSqlList(sql,TableFormMapper.class);
|
|
|
|
+ if(Func.isNotEmpty(tableNamePkIdsList)) {
|
|
|
|
+ List<Long> pkeyIds=tec.getTableAll().stream().map(NodeTable::getPKeyId).collect(Collectors.toList());
|
|
|
|
+ Map<String,List<Long>>tableNamePkIdsMaps=tableNamePkIdsList.stream().filter(m->!pkeyIds.contains(m.getPkeyId())).collect(Collectors.groupingBy(TableFormMapper::getTableName,Collectors.mapping(TableFormMapper::getPkeyId,Collectors.toList())));
|
|
|
|
+ Map<String,String> tableNameUrlMaps=tableNamePkIdsList.stream().collect(Collectors.toMap(TableFormMapper::getTableName,TableFormMapper::getUrl,(p,n)->p));
|
|
|
|
+ List<FormData> fds=new ArrayList<>(fdsMap.values());
|
|
|
|
+ Map<String,List<FormData>> group = fds.stream().collect(Collectors.groupingBy(FormData::getTableName,Collectors.toList()));
|
|
|
|
+ group.forEach((k,v)->{
|
|
|
|
+ String ids =tableNamePkIdsMaps.get(k).stream().map(Objects::toString).collect(Collectors.joining(","));
|
|
|
|
+ String sqlTableDataInfo="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(sqlTableDataInfo,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()));
|
|
|
|
+ if(fd.getCellDataVoList()!=null) {
|
|
|
|
+ List<Long> pageIds = tableNamePkIdsMaps.get(fd.getTableName());
|
|
|
|
+ String coords =tec.getCoordinateMap().computeIfAbsent(fd.getTableName(), x -> FormulaUtils.getElementCell(tableNameUrlMaps.get(x))).get(fd.getKey());
|
|
|
|
+ if(Func.isNotBlank(coords)){
|
|
|
|
+ fd.flushCoords(coords);
|
|
|
|
+ }else{
|
|
|
|
+ tec.getLog().put(FormulaLog.POSITION,fd.getCode()+"("+fd.getEName()+")");
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ List<Coords> coordsList = fd.getCoordsList();
|
|
|
|
+ List<ElementData> eds = fd.getValues();
|
|
|
|
+ Map<String, Object> map = fd.getCellDataVoList().stream().collect(Collectors.toMap(e -> StringUtils.join(pageIds.indexOf(e.getPageId()), e.getX(), e.getY(), StringPool.AT), CellDataVo::getValue));
|
|
|
|
+ for (int i = 0; i < pageIds.size(); i++) {
|
|
|
|
+ for (Coords c : coordsList) {
|
|
|
|
+ String key = StringUtils.join(i, c.getX(), c.getY(), StringPool.AT);
|
|
|
|
+ eds.add(new ElementData(i, 0, map.get(key), c.getX(), c.getY()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /*数据初始化加载*/
|
|
|
|
+ fd.setInitReady(true);
|
|
|
|
+ /*备份原始数据,用于更新比较*/
|
|
|
|
+ fd.init();
|
|
}
|
|
}
|
|
- 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)){
|
|
if(Func.isNotEmpty(removeList)){
|
|
/*移除已经找到的元素数据*/
|
|
/*移除已经找到的元素数据*/
|
|
@@ -2139,12 +2232,11 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<FormData> createFormDataByTableName(String tableNames) {
|
|
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 " +
|
|
|
|
|
|
+ return 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 " +
|
|
"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" +
|
|
"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+")"
|
|
" where a.tab_en_name in( "+ tableNames+")"
|
|
, FormData.class);
|
|
, FormData.class);
|
|
- return fds;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -2164,6 +2256,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
});
|
|
});
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|