|
@@ -1,5 +1,7 @@
|
|
|
package org.springblade.manager.controller;
|
|
|
|
|
|
+import cn.hutool.core.date.StopWatch;
|
|
|
+import cn.hutool.log.StaticLog;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -47,7 +49,7 @@ public class WbsParamController {
|
|
|
private final JdbcTemplate jdbcTemplate;
|
|
|
private final IFormulaService formulaService;
|
|
|
private final IElementFormulaMappingService elementFormulaMappingService;
|
|
|
- private final IWbsTreeService wbsTreeService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 保存或修改
|
|
@@ -403,5 +405,52 @@ public class WbsParamController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/del-duplicate")
|
|
|
+ public R<Object> duplicate() {
|
|
|
+ try {
|
|
|
+ StopWatch stopWatch = new StopWatch();
|
|
|
+ stopWatch.start("节点参数查重及删除");
|
|
|
+ List<Map<String,Object>> mapList= this.jdbcTemplate.queryForList("select node_id nodeId,k,count(*) num from m_wbs_param where is_deleted=0 and type=1 GROUP BY node_id,k HAVING count(*)>2");
|
|
|
+ if(!mapList.isEmpty()){
|
|
|
+ List<WbsParam> list = this.service.list(Wrappers.<WbsParam>lambdaQuery().in(WbsParam::getNodeId,mapList.stream().map(m->m.get("nodeId")).collect(Collectors.toList())));
|
|
|
+ List<Long> removeWpIds= new ArrayList<>();
|
|
|
+ List<Long> removeMapingIds=new ArrayList<>();
|
|
|
+ List<Long> removeFormulaIds = new ArrayList<>();
|
|
|
+ Map<Long,Map<String,List<WbsParam>>> group= list.stream().collect(Collectors.groupingBy(WbsParam::getNodeId,LinkedHashMap::new,Collectors.groupingBy(WbsParam::getK)));
|
|
|
+ group.values().forEach(m->{
|
|
|
+ m.forEach((k,v)->{
|
|
|
+ List<Map<String,Object>> relationMap= this.jdbcTemplate.queryForList("select a.id paramId,b.id mappingId,b.formula_id formulaId from m_wbs_param a join m_element_formula_mapping b on a.id=b.param_id where b.scope=35 and a.id in("+v.stream().map(WbsParam::getId).map(String::valueOf).collect(Collectors.joining("','","'","'"))+") order by b.update_time desc");
|
|
|
+ if(!relationMap.isEmpty()){
|
|
|
+ Object id=relationMap.get(0).get("paramId");
|
|
|
+ removeWpIds.addAll(v.stream().map(WbsParam::getId).filter(eId ->!StringUtils.isNotEquals(id, eId)).collect(Collectors.toList()));
|
|
|
+ /*同一道工序下,一个节点参数可能会关联多个元素,除了保留参数关联的以外全部添加到待删除列表*/
|
|
|
+ relationMap.stream().filter(x->StringUtils.isNotEquals(x.get("paramId"),id)).forEach(e->{
|
|
|
+ removeMapingIds.add(Long.parseLong(e.get("mappingId").toString()));
|
|
|
+ removeFormulaIds.add(Long.parseLong(e.get("formulaId").toString()));
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ removeWpIds.addAll(v.stream().skip(1).map(WbsParam::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ System.out.println("查找到重复参数"+list.size()+"个");
|
|
|
+ System.out.println("待删除参数"+removeWpIds.size()+"个");
|
|
|
+ System.out.println("待删除中间关联"+removeMapingIds.size()+"个");
|
|
|
+ System.out.println("待删除公式"+removeFormulaIds.size()+"个");
|
|
|
+ Map<String,Integer> result = new HashMap<>();
|
|
|
+ result.put("查找到重复参数",list.size());
|
|
|
+ result.put("待删除参数",removeWpIds.size());
|
|
|
+ result.put("待删除中间关联",removeMapingIds.size());
|
|
|
+ result.put("待删除公式",removeFormulaIds.size());
|
|
|
+ stopWatch.stop();
|
|
|
+ Long totalTime = stopWatch.getTotalTimeMillis();
|
|
|
+ StaticLog.info("公式执行用时:{}", totalTime);
|
|
|
+ return R.data(result);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return R.fail("执行异常");
|
|
|
+ }
|
|
|
|
|
|
}
|