|
@@ -21,6 +21,7 @@ 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.StringPool;
|
|
|
import org.springblade.manager.dto.FormulaBean;
|
|
|
import org.springblade.manager.dto.TreeNode;
|
|
|
import org.springblade.manager.dto.WbsParamBean;
|
|
@@ -30,11 +31,16 @@ import org.springblade.manager.vo.ParamBean;
|
|
|
import org.springblade.manager.vo.ParamSearch;
|
|
|
import org.springblade.manager.wrapper.WbsParamWrapper;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.data.redis.serializer.RedisSerializer;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -50,6 +56,7 @@ public class WbsParamController {
|
|
|
private final IWbsParamService service;
|
|
|
private final JdbcTemplate jdbcTemplate;
|
|
|
private final IFormulaService formulaService;
|
|
|
+ private final StringRedisTemplate redisTemplate;
|
|
|
private final IElementFormulaMappingService elementFormulaMappingService;
|
|
|
|
|
|
|
|
@@ -593,24 +600,38 @@ public class WbsParamController {
|
|
|
public R<Object> treeCode(Long contractId,Long projectId) {
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
stopWatch.start("treeCode刷新");
|
|
|
- List<Long> contractIds= new ArrayList<>();
|
|
|
+ Set<Long> contractIds=new HashSet<>();
|
|
|
if(projectId!=null){
|
|
|
- contractIds= this.jdbcTemplate.queryForList(" select id from m_contract_info where p_id="+projectId+" and is_deleted=0 ",Long.class);
|
|
|
+ contractIds= new HashSet<>(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);
|
|
|
- }
|
|
|
+ this.treeCodeUpdate(contractIds);
|
|
|
stopWatch.stop();
|
|
|
return R.success((stopWatch.getLastTaskName()+"执行用时:"+stopWatch.getTotalTimeMillis()));
|
|
|
}
|
|
|
- return R.fail("项目Id格式有问题");
|
|
|
+ return R.fail("执行失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*把所有项目的合同段都刷新treeCode*/
|
|
|
+ @GetMapping("/tree-code-all")
|
|
|
+ public R<Object> treeCodeAll() {
|
|
|
+ return this.treeCodeUpdateProjectAllForJob();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+ @Scheduled(cron = " 0 0 3,13 * * ?")
|
|
|
+ public void job(){
|
|
|
+ System.out.println("treeCode刷新任务开始"+ LocalDateTime.now());
|
|
|
+ if(!Optional.ofNullable(System.getProperty("os.name")).orElse(StringPool.EMPTY).equals("Linux")){
|
|
|
+ this.treeCodeUpdateProjectAllForJob();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public void batchUpdate(Long id,boolean fast){
|
|
|
+
|
|
|
+ public void builder(Long id,List<String>sqlList){
|
|
|
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);
|
|
@@ -633,37 +654,39 @@ public class WbsParamController {
|
|
|
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();
|
|
|
- }
|
|
|
- });
|
|
|
+ sqlBuilder2(treeNodeMap.get(topId),sqlList,ZERO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void treeCodeUpdate(Set<Long> contractIds){
|
|
|
+ List<String>sqlList=new ArrayList<>();
|
|
|
+ contractIds.forEach(id->{
|
|
|
+ builder(id,sqlList);
|
|
|
+ });
|
|
|
+ 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();
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**批量任務*/
|
|
|
+ public R<Object> treeCodeUpdateProjectAllForJob(){
|
|
|
+ StopWatch stopWatch = new StopWatch();
|
|
|
+ stopWatch.start("全部项目treeCode刷新");
|
|
|
+ Set<Long> contractIds= new HashSet<>(this.jdbcTemplate.queryForList(" select id from m_contract_info where is_deleted=0 ",Long.class));
|
|
|
+ if(contractIds.size()>0){
|
|
|
+ this.treeCodeUpdate(contractIds);
|
|
|
+ stopWatch.stop();
|
|
|
+ return R.success((stopWatch.getLastTaskName()+"执行用时:"+stopWatch.getTotalTimeMillis()));
|
|
|
}
|
|
|
+ return R.fail("执行失败");
|
|
|
}
|
|
|
|
|
|
static String ZERO="0";
|