|
@@ -21,9 +21,8 @@ import org.springblade.core.tool.api.R;
|
|
|
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.RegexUtil;
|
|
|
import org.springblade.manager.dto.FormulaBean;
|
|
|
-import org.springblade.manager.dto.ParamElements;
|
|
|
+import org.springblade.manager.dto.TreeNode;
|
|
|
import org.springblade.manager.dto.WbsParamBean;
|
|
|
import org.springblade.manager.entity.*;
|
|
|
import org.springblade.manager.service.*;
|
|
@@ -35,6 +34,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -588,4 +588,112 @@ public class WbsParamController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**按合同段或者项目刷入m_wbs_tree_contract的treeCode*/
|
|
|
+ @GetMapping("/tree-code")
|
|
|
+ public R<Object> treeCode(Long contractId,Long projectId) {
|
|
|
+ StopWatch stopWatch = new StopWatch();
|
|
|
+ stopWatch.start("treeCode刷新");
|
|
|
+ List<Long> contractIds= new ArrayList<>();
|
|
|
+ if(projectId!=null){
|
|
|
+ contractIds= this.jdbcTemplate.queryForList(" select id from m_contract_info where p_id="+projectId+" and is_deleted=0 ",Long.class);
|
|
|
+ }else if( contractId!=null){
|
|
|
+ contractIds.add(contractId);
|
|
|
+ }
|
|
|
+ if(contractIds.size()>0){
|
|
|
+ for(Long id:contractIds){
|
|
|
+ batchUpdate(id,true);
|
|
|
+ }
|
|
|
+ stopWatch.stop();
|
|
|
+ return R.success((stopWatch.getLastTaskName()+"执行用时:"+stopWatch.getTotalTimeMillis()));
|
|
|
+ }
|
|
|
+ return R.fail("项目Id格式有问题");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void batchUpdate(Long id,boolean fast){
|
|
|
+ List<Map<String,Object>> treeNodeList= this.jdbcTemplate.queryForList("select node_name name,p_key_id value, id, parent_id parentId from m_wbs_tree_contract where contract_id="+id+" and is_deleted=0 and type=1 ");
|
|
|
+ if(treeNodeList.size()>0){
|
|
|
+ Map<Long,TreeNode<Long>> treeNodeMap = new HashMap<>(treeNodeList.size()*2);
|
|
|
+ Long topId=null;
|
|
|
+ for (Map<String,Object> map:treeNodeList){
|
|
|
+ TreeNode<Long> treeNode = new TreeNode<>();
|
|
|
+ treeNode.setId(Long.parseLong(map.get("id").toString()));
|
|
|
+ treeNode.setParentId(Long.parseLong(map.get("parentId").toString()));
|
|
|
+ treeNode.setValue(Long.parseLong(map.get("value").toString()));
|
|
|
+ treeNode.setName(map.get("name").toString());
|
|
|
+ if(treeNode.getParentId().equals(0L)){
|
|
|
+ topId=treeNode.getId();
|
|
|
+ }
|
|
|
+ treeNodeMap.put(treeNode.getId(),treeNode);
|
|
|
+ }
|
|
|
+ Map<Long,List<TreeNode<Long>>> group= treeNodeMap.values().stream().collect(Collectors.groupingBy(TreeNode::getParentId));
|
|
|
+ group.forEach((k,v)->{
|
|
|
+ TreeNode<Long> tmp = treeNodeMap.get(k);
|
|
|
+ if(tmp!=null) {
|
|
|
+ tmp.setChildren(v);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ TreeNode<Long> top = treeNodeMap.get(topId);
|
|
|
+ if(fast){
|
|
|
+ List<String>sqlList=new ArrayList<>();
|
|
|
+ sqlBuilder2(top,sqlList,ZERO);
|
|
|
+ if(sqlList.size()>0){
|
|
|
+ List<List<String>> sqlListSeg = BaseUtils.splitList(sqlList, 250);
|
|
|
+ sqlListSeg.parallelStream().forEach(sql->{
|
|
|
+ try {
|
|
|
+ String joinSql=String.join(";",sql);
|
|
|
+ this.jdbcTemplate.execute(joinSql);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ List<Object[]> paramList = new ArrayList<>();
|
|
|
+ sqlBuilder(top,paramList,ZERO);
|
|
|
+ if(!paramList.isEmpty()){
|
|
|
+ List<List<Object[]>> paramListSplit=BaseUtils.splitList(paramList,1000);
|
|
|
+ String sqlTemplate="update m_wbs_tree_contract set tree_code = ? where p_key_id = ?";
|
|
|
+ paramListSplit.parallelStream().forEach(sql->{
|
|
|
+ try {
|
|
|
+ this.jdbcTemplate.batchUpdate(sqlTemplate,sql);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static String ZERO="0";
|
|
|
+ public void sqlBuilder(TreeNode<Long> top, List<Object[]>paramList, String treeCode){
|
|
|
+ if(top!=null){
|
|
|
+ paramList.add(new Object[]{treeCode,top.getValue()});
|
|
|
+ if(top.hasChildren()){
|
|
|
+ for(int i=0;i<top.getChildren().size();i++){
|
|
|
+ TreeNode<Long> child=top.getChildren().get(i);
|
|
|
+ int base=ZERO.equals(treeCode)?100:1000;
|
|
|
+ sqlBuilder(child,paramList,treeCode+String.valueOf(base+i).substring(1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ public void sqlBuilder2(TreeNode<Long> top, List<String>sqlList, String treeCode){
|
|
|
+ if(top!=null){
|
|
|
+ sqlList.add("update m_wbs_tree_contract set tree_code ='"+treeCode+"' where p_key_id="+top.getValue());
|
|
|
+ if(top.hasChildren()){
|
|
|
+ for(int i=0;i<top.getChildren().size();i++){
|
|
|
+ TreeNode<Long> child=top.getChildren().get(i);
|
|
|
+ int base=ZERO.equals(treeCode)?100:1000;
|
|
|
+ sqlBuilder2(child,sqlList,treeCode+String.valueOf(base+i).substring(1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|