Эх сурвалжийг харах

Merge branch 'test-merge' of http://219.151.181.73:3000/zhuwei/bladex into test-merge

lvy 2 сар өмнө
parent
commit
d3a14dd510
20 өөрчлөгдсөн 2395 нэмэгдсэн , 146 устгасан
  1. 12 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/ProjectInfo.java
  2. 7 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTreeContract.java
  3. 7 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTreePrivate.java
  4. 142 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTreeSynchronousRecord.java
  5. 55 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/enums/WbsSyncTypeEnum.java
  6. 27 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/WbsTreeSynchronousRecordVo.java
  7. 44 0
      blade-service/blade-business/src/main/java/org/springblade/business/controller/InformationWriteQueryController.java
  8. 11 9
      blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java
  9. 1 1
      blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreePrivateController.java
  10. 139 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeSynchronousRecordController.java
  11. 6 2
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ArchiveTreeContractMapper.xml
  12. 21 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeSynchronousRecordMapper.java
  13. 30 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeSynchronousRecordMapper.xml
  14. 1 1
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/IWbsTreePrivateService.java
  15. 25 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/WbsTreeSynchronousRecordService.java
  16. 14 32
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java
  17. 96 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousEViSaServiceImpl.java
  18. 1276 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousServiceImpl.java
  19. 216 101
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreePrivateServiceImpl.java
  20. 265 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeSynchronousRecordServiceImpl.java

+ 12 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/ProjectInfo.java

@@ -198,5 +198,17 @@ public class ProjectInfo extends BaseEntity {
     @ApiModelProperty(value = "模板引用 1.模版节点 2.底层节点")
     private Integer templateType;
 
+    /**
+     * 施工后缀
+     */
+    @ApiModelProperty(value = "施工后缀")
+    private String sgSuffix;
+
+    /**
+     * 监理前缀
+     */
+    @ApiModelProperty(value = "监理后缀")
+    private String jlSuffix;
+
 
 }

+ 7 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTreeContract.java

@@ -1,5 +1,8 @@
 package org.springblade.manager.entity;
 
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import io.swagger.annotations.ApiModelProperty;
@@ -23,8 +26,12 @@ public class WbsTreeContract extends BaseEntity {
      * 主键id
      */
     @ApiModelProperty(value = "主键id")
+    @TableId(value = "p_key_id", type = IdType.INPUT)
     private Long pKeyId;
 
+    @TableField
+    private Long id;
+
 
     @ApiModelProperty(value = "新节点Id")
     private Long pId;

+ 7 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTreePrivate.java

@@ -1,5 +1,8 @@
 package org.springblade.manager.entity;
 
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import io.swagger.annotations.ApiModelProperty;
@@ -20,9 +23,13 @@ public class WbsTreePrivate extends BaseEntity {
     /**
      * 主键
      */
+    @TableId(value = "p_key_id", type = IdType.INPUT)
     @JsonProperty(value = "pKeyId")
     private Long pKeyId;
 
+    @TableField
+    private Long id;
+
     @ApiModelProperty(value = "pid")
     private Long pId;
 

+ 142 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTreeSynchronousRecord.java

@@ -0,0 +1,142 @@
+package org.springblade.manager.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * WBS同步记录表
+ *
+ * @author LHB
+ * @TableName m_wbs_tree_synchronous_record
+ */
+@TableName(value = "m_wbs_tree_synchronous_record")
+@Data
+public class WbsTreeSynchronousRecord {
+    /**
+     * id111
+     */
+    @TableId
+    private Long id;
+
+    /**
+     * 项目id
+     */
+    private Long projectId;
+
+    /**
+     * 项目名称
+     */
+    private String projectName;
+
+
+    @TableField("`range`")
+    private Integer range;
+    /**
+     * 同步范围名称
+     */
+    private String rangeName;
+    /**
+     * 合同段范围 逗号拼接的编号 101.未填报 102.已填报-未上报 103.未上报 104.待审批 105.已审批
+     */
+    private String contractRange;
+    /**
+     * 合同段范围名称
+     */
+    private String contractRangeName;
+
+    /**
+     * 同步源Id
+     */
+    private Long templateId;
+
+    /**
+     * 同步源名称
+     */
+    private String templateName;
+
+    /**
+     * 同步类型 逗号拼接的编号 1.新增表单 2.清表配置 3.元素配置 4.电签配置 5.公式配置 6.默认值配置 7.表单排序
+     */
+    private String type;
+
+    /**
+     * 同步类型名称
+     */
+    private String typeName;
+
+    /**
+     * 同步节点id 多个节点
+     */
+    private String nodeId;
+
+    /**
+     * 同步节点名称
+     */
+    private String nodeName;
+    /**
+     * 表单Ids     range = 4 强制同步时  当前数据为同步源
+     */
+    private String formIds;
+    /**
+     * 同步节点数量
+     */
+    private Integer nodeNum;
+    /**
+     * 已同步数量
+     */
+    private Integer nodeNumEnd;
+
+    /**
+     * 是否删除(0-未删除,1-删除)
+     */
+    private Integer isDeleted;
+
+    /**
+     * 状态(0-未同步,1-正在同步,2-已同步,3-同步失败)
+     */
+    private Integer status;
+    /**
+     * 状态(0-未同步,1-正在同步,2-已同步,3-同步失败)
+     */
+    @TableField(exist = false)
+    private String statusName;
+    /**
+     * 错误信息
+     */
+    @TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
+    private String errorMsg;
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 创建人
+     */
+    private String createUser;
+
+    /**
+     * 创建人id
+     */
+    private Long createUserId;
+
+    /**
+     * 修改时间
+     */
+    private Date updateTime;
+
+    /**
+     * 修改人
+     */
+    private String updateUser;
+
+    /**
+     * 修改人id
+     */
+    private Long updateUserId;
+}

+ 55 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/enums/WbsSyncTypeEnum.java

@@ -0,0 +1,55 @@
+package org.springblade.manager.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import org.springblade.core.tool.utils.ObjectUtil;
+
+/**
+ * @author LHB
+ */
+@Getter
+@AllArgsConstructor
+public enum WbsSyncTypeEnum {
+    UNKNOWN(-1, ""),
+    INSERT_FORM(1, "新增表单"),
+    CLEAR_TABLE_CONFIG(2, "清表配置"),
+    ELEMENT_CONFIG(3, "元素配置"),
+    E_VISA_CONFIG(4, "电签配置"),
+    FORMULA_CONFIG(5, "公式配置"),
+    DEFAULT_VALUE_CONFIG(6, "默认值配置"),
+    FORM_SORT(7, "表单排序"),
+    /**
+     * 合同段同步范围
+     */
+    NOT_FILLED_IN(101, "未填报"),
+    ALREADY_FILLED_IN_NOT_REPORTED(102, "已填报-未上报"),
+    NOT_REPORTED(103, "未上报"),
+    PENDING_APPROVAL(104, "待审批"),
+    APPROVED(105, "已审批"),
+    ;
+
+    /**
+     * 编码
+     */
+    public Integer code;
+
+    /**
+     * 描述
+     */
+    private String desc;
+
+    /**
+     * 根据编码获取枚举描述
+     */
+    public static String getByCode(int code) {
+        // 判断code
+        if(ObjectUtil.isNotEmpty(code)){
+            for (StorageTypeEnum storageTypeEnum : StorageTypeEnum.values()) {
+                if (storageTypeEnum.getCode() == code) {
+                    return storageTypeEnum.getDesc();
+                }
+            }
+        }
+        return WbsSyncTypeEnum.UNKNOWN.getDesc();
+    }
+}

+ 27 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/WbsTreeSynchronousRecordVo.java

@@ -0,0 +1,27 @@
+package org.springblade.manager.vo;
+
+import lombok.Data;
+
+/**
+ *
+ * @author LHB
+ */
+@Data
+public class WbsTreeSynchronousRecordVo {
+    /**
+     * id
+     */
+    private Long id;
+    /**
+     * 项目名称
+     */
+    private String name;
+    /**
+     * wbsId
+     */
+    private String wbsId;
+    /**
+     * type = 1 公共  type = 2 私有
+     */
+    private Integer type;
+}

+ 44 - 0
blade-service/blade-business/src/main/java/org/springblade/business/controller/InformationWriteQueryController.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.google.common.collect.Lists;
 import io.swagger.annotations.*;
@@ -188,6 +189,49 @@ public class InformationWriteQueryController extends BladeController {
         return R.data(300, null, "未找到文件题名");
     }
 
+    @PostMapping("/flushQueryName")
+    @ApiModelProperty(value = "刷新文件题名")
+    @ApiOperationSupport(order = 28)
+    public R<Boolean> flushQueryName(@RequestParam String ids){
+        if(ids==null){
+            throw new ServiceException("请选择要刷新的文件");
+        }
+        List<Long> idList = Arrays.stream(ids.split(","))
+            .map(Long::valueOf)
+            .collect(Collectors.toList());
+        List<InformationQuery> queryList = this.informationQueryService.list(Wrappers.<InformationQuery>lambdaQuery()
+            .select(InformationQuery::getId, InformationQuery::getName,InformationQuery::getProjectId,InformationQuery::getClassify,InformationQuery::getStatus).in(InformationQuery::getId, idList));
+        String sgSuffix="";
+        String jlSuffix="";
+        if(queryList.size()>0){
+            String sql1="Select sg_suffix,jl_suffix from m_project_info where id="+queryList.get(0).getProjectId()+" and is_deleted=0";
+            List<ProjectInfo> projectInfos = jdbcTemplate.query(sql1, new BeanPropertyRowMapper<>(ProjectInfo.class));
+            if(projectInfos.size()>0){
+                sgSuffix=projectInfos.get(0).getSgSuffix()==null?"":projectInfos.get(0).getSgSuffix();
+                jlSuffix=projectInfos.get(0).getJlSuffix()==null?"":projectInfos.get(0).getJlSuffix();
+            }
+            for (InformationQuery query : queryList) {
+                if(query.getClassify()!=null&&query.getClassify()==1&&StringUtils.isNotEmpty(sgSuffix)){
+                   if(!query.getName().endsWith(sgSuffix)){
+                       query.setName(query.getName()+sgSuffix);
+                   }
+                }else if(query.getClassify()!=null&&query.getClassify()==2&&StringUtils.isNotEmpty(jlSuffix)){
+                    if(!query.getName().endsWith(jlSuffix)){
+                        query.setName(query.getName()+jlSuffix);
+                    }
+                }
+            }
+        }
+        List<InformationQuery> taskList = queryList.stream().filter(o -> o.getStatus() == 1 || o.getStatus() == 2).collect(Collectors.toList());
+        if(taskList.size()>0){
+            for (InformationQuery query : taskList) {
+                String update="update u_task set task_name='"+query.getName()+"' where form_data_id='"+query.getId()+"' and is_deleted=0";
+                jdbcTemplate.update(update);
+            }
+        }
+        return R.status(this.informationQueryService.updateBatchById(queryList));
+    }
+
     /**
      * 初始化合同段导图树
      */

+ 11 - 9
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -597,7 +597,7 @@ public class ExcelTabController extends BladeController {
 
                     for (WbsFormElement elementInfo : elementList) {
                         String ysName = elementInfo.getEName();
-                        if (titleName.equals(ysName)) {
+                         if (titleName.equals(ysName)) {
                             lastName = elementInfo.getEName();
                             attrInfo = elementInfo.getEKey() + "__" + i + "_" + j;
 
@@ -609,7 +609,8 @@ public class ExcelTabController extends BladeController {
                             is_true = true;
                             break;
                         } else {
-                            if (MathUtil.sim(titleName, ysName) > maxScore) {
+                             List<String> list = Arrays.asList(titleName.split("_"));
+                             if (list.contains(ysName)) {
                                 attrInfo = elementInfo.getEKey() + "__" + i + "_" + j;
 
                                 filedType = WbsElementUtil.getInitTableFiledType(elementInfo.getEType());
@@ -619,6 +620,7 @@ public class ExcelTabController extends BladeController {
                                 lastName = ysName;
                                 maxScore = MathUtil.sim(titleName, ysName);
                                 is_true = true;
+                                break;
                             }
                         }
                     }
@@ -1245,10 +1247,10 @@ public class ExcelTabController extends BladeController {
                                         if (x1 - xx2 <= 1 && y1 == yy2) {
                                             inputText = name;
                                         } else {
-                                            inputText += name + "_";
+                                            inputText += name + "_" +name;
                                         }
                                     } else {
-                                        inputText += name + "_";
+                                        inputText += "_" +name;
                                     }
                                 } else {
                                     if (x1 - xx2 <= 1 && y1 == yy2) {
@@ -1267,14 +1269,14 @@ public class ExcelTabController extends BladeController {
                                 int yy1 = Integer.parseInt(top.get(k).get("y1"));
                                 int yy2 = Integer.parseInt(top.get(k).get("y2"));
                                 if (!StringUtil.isNumeric(name) && name.length() <= 20) {
-                                    inputText += name + "_";
+                                    inputText += "_" + name;
                                 }
                             }
                         }
-
-                        if (inputText != null && inputText != "" && inputText.indexOf("_") >= 0) {
-                            inputText = inputText.substring(0, inputText.lastIndexOf("_"));
-                        }
+                        //这段代码含义未知
+//                        if (inputText != null && inputText != "" && inputText.indexOf("_") >= 0) {
+//                            inputText = inputText.substring(0, inputText.lastIndexOf("_"));
+//                        }
 
                         // 质检表特殊处理匹配
 

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreePrivateController.java

@@ -576,7 +576,7 @@ public class WbsTreePrivateController extends BladeController {
     @ApiOperation(value = "同步项目下节点下的元素表", notes = "传入节点primaryKeyId")
     @RequestMapping(value = "/sync-node-table", method = RequestMethod.POST)
     public R syncNodeTable(@RequestParam String primaryKeyId) {
-        return R.status(wbsTreePrivateService.syncNodeTable(primaryKeyId));
+        return R.status(wbsTreePrivateService.syncNodeTable(primaryKeyId,null));
     }
 
     /**

+ 139 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeSynchronousRecordController.java

@@ -0,0 +1,139 @@
+package org.springblade.manager.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.manager.entity.ProjectInfo;
+import org.springblade.manager.entity.WbsTreePrivate;
+import org.springblade.manager.entity.WbsTreeSynchronousRecord;
+import org.springblade.manager.service.WbsTreeSynchronousRecordService;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.tool.api.R;
+import org.springblade.manager.vo.WbsTreeSynchronousRecordVo;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * WBS同步记录表(MWbsTreeSynchronousRecord)表控制层
+ *
+ * @author makejava
+ * @since 2025-05-15 13:50:25
+ */
+@RestController
+@RequestMapping("/synchronousRecord")
+public class WbsTreeSynchronousRecordController {
+    /**
+     * 服务对象
+     */
+    @Resource
+    private WbsTreeSynchronousRecordService mWbsTreeSynchronousRecordService;
+
+    /**
+     * 分页查询所有数据
+     *
+     * @param record 查询对象
+     * @param query  分页对象
+     * @return 所有数据
+     */
+    @GetMapping("/page")
+    public R<IPage<WbsTreeSynchronousRecord>> selectAll(WbsTreeSynchronousRecord record, Query query) {
+        LambdaQueryWrapper<WbsTreeSynchronousRecord> lambda = new QueryWrapper().lambda();
+        lambda
+                .eq(record.getProjectId() != null, WbsTreeSynchronousRecord::getProjectId, record.getProjectId())
+                .eq(record.getStatus() != null, WbsTreeSynchronousRecord::getStatus, record.getStatus())
+                .eq(record.getRange() != null, WbsTreeSynchronousRecord::getRange, record.getRange());
+        if (!StringUtil.isBlank(record.getType())) {
+            lambda.apply("FIND_IN_SET({0},type)", record.getType());
+        }
+        IPage<WbsTreeSynchronousRecord> page = mWbsTreeSynchronousRecordService.page(Condition.getPage(query), lambda);
+        for (WbsTreeSynchronousRecord pageRecord : page.getRecords()) {
+            switch (pageRecord.getStatus()) {
+                case 0:
+                    pageRecord.setStatusName("待同步");
+                    break;
+                case 1:
+                    pageRecord.setStatusName("正在同步");
+                    break;
+                case 2:
+                    pageRecord.setStatusName("已同步");
+                    break;
+                case 3:
+                    pageRecord.setStatusName("同步失败");
+                    break;
+                default:
+                    break;
+            }
+        }
+        return R.data(page);
+    }
+
+    /**
+     * 通过主键查询单条数据
+     *
+     * @param id 主键
+     * @return 单条数据
+     */
+    @GetMapping("getById")
+    public R<WbsTreeSynchronousRecord> selectOne(@RequestParam Long id) {
+        return R.data(this.mWbsTreeSynchronousRecordService.getById(id));
+    }
+
+
+    /**
+     * 新增数据
+     *
+     * @param mWbsTreeSynchronousRecord 实体对象
+     * @return 新增结果
+     */
+    @PostMapping("add")
+    public R<WbsTreeSynchronousRecord> insert(@RequestBody WbsTreeSynchronousRecord mWbsTreeSynchronousRecord) {
+        if (StringUtil.isBlank(mWbsTreeSynchronousRecord.getType())) {
+            return R.fail("请选择同步类型");
+        }
+        if (mWbsTreeSynchronousRecord.getRange() == null) {
+            return R.fail("请选择同步范围");
+        }
+
+        if (mWbsTreeSynchronousRecord.getRange() == 2 && StringUtil.isBlank(mWbsTreeSynchronousRecord.getContractRange())) {
+            return R.fail("请选择合同同步范围");
+        }
+        if (mWbsTreeSynchronousRecord.getProjectId() == null) {
+            return R.fail("项目Id为空");
+        }
+        if (mWbsTreeSynchronousRecord.getRange() == 1 && mWbsTreeSynchronousRecord.getTemplateId() == null) {
+            return R.fail("同步源为空");
+        }
+
+        return R.data(this.mWbsTreeSynchronousRecordService.insert(mWbsTreeSynchronousRecord));
+    }
+
+    /**
+     * 认证接口是否正在同步
+     */
+    @PostMapping("getNodeStatus")
+    public R<WbsTreeSynchronousRecord> getNodeStatus(@RequestParam Long id) {
+        return R.data(this.mWbsTreeSynchronousRecordService.getNodeStatus(id));
+    }
+
+
+    /**
+     * 获取当前项目的模板项目
+     *
+     * @param nodeIds 节点ids 逗号拼接
+     */
+    @GetMapping("getTempProject")
+    public R<List<WbsTreeSynchronousRecordVo>> getProjectTemplate(@RequestParam String nodeIds) {
+        if (StringUtil.isBlank(nodeIds)) {
+            return R.fail("参数不能为空");
+        }
+        return R.data(this.mWbsTreeSynchronousRecordService.getProjectTemplate(nodeIds));
+    }
+
+}
+

+ 6 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ArchiveTreeContractMapper.xml

@@ -231,9 +231,13 @@
         d.contract_id,
         (SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM m_archive_tree_contract WHERE parent_id = d.id and is_deleted = 0 and project_id = #{projectId})
         AS "has_children",
-        (SELECT  count(1)  FROM m_archive_tree_contract WHERE  is_deleted = 0 and project_id = #{projectId} and ancestors like CONCAT('%',d.id,'%')
+        (SELECT  count(1)  FROM m_archive_tree_contract a
+                        inner join u_archive_file b on b.node_id = a.id and b.is_deleted = a.is_deleted and b.project_id = a.project_id and (b.is_auto_file is null or b.is_auto_file != 1)
+                           WHERE  a.is_deleted = 0
+                             and a.project_id = #{projectId}
+                             and a.ancestors like CONCAT('%',d.id,'%')
         <if test="code!=null and code!=''">
-            AND (tree_code = #{code} or tree_code = #{contractId} or parent_id = 0)
+            AND (a.tree_code = #{code} or a.tree_code = #{contractId} or a.parent_id = 0)
         </if>
         ) as tree_number
         FROM

+ 21 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeSynchronousRecordMapper.java

@@ -0,0 +1,21 @@
+package org.springblade.manager.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.ibatis.annotations.Param;
+import org.springblade.manager.entity.WbsTreeSynchronousRecord;
+
+/**
+* @author LHB
+* @description 针对表【m_wbs_tree_synchronous_record(WBS同步记录表)】的数据库操作Mapper
+* @createDate 2025-05-15 13:52:09
+* @Entity generator.domain.MWbsTreeSynchronousRecord
+*/
+public interface WbsTreeSynchronousRecordMapper extends BaseMapper<WbsTreeSynchronousRecord> {
+
+}
+
+
+
+

+ 30 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeSynchronousRecordMapper.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.springblade.manager.mapper.WbsTreeSynchronousRecordMapper">
+
+    <resultMap id="BaseResultMap" type="org.springblade.manager.entity.WbsTreeSynchronousRecord">
+            <id property="id" column="id" />
+            <result property="projectId" column="project_id" />
+            <result property="projectName" column="project_name" />
+            <result property="range" column="range" />
+            <result property="source" column="source" />
+            <result property="type" column="type" />
+            <result property="nodeId" column="node_id" />
+            <result property="nodeName" column="node_name" />
+            <result property="isDeleted" column="is_deleted" />
+            <result property="createTime" column="create_time" />
+            <result property="createUser" column="create_user" />
+            <result property="createUserId" column="create_user_id" />
+            <result property="updateTime" column="update_time" />
+            <result property="updateUser" column="update_user" />
+            <result property="updateUserId" column="update_user_id" />
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,project_id,project_name,range,source,type,
+        node_id,node_name,is_deleted,create_time,create_user,
+        create_user_id,update_time,update_user,update_user_id
+    </sql>
+</mapper>

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IWbsTreePrivateService.java

@@ -65,7 +65,7 @@ public interface IWbsTreePrivateService extends BaseService<WbsTreePrivate> {
     void eVisInfoRepeatDel(String pid);
 
     boolean syncNodeTable(String primaryKeyId);
-    List<WbsTreePrivate> syncNodeTable(String primaryKeyIdm,String a);
+    boolean syncNodeTable(String primaryKeyIdm,String a);
 
     R addWbsTreeContractInfo(String nodeId, String primaryKeyIds, Long contractId);
 

+ 25 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/WbsTreeSynchronousRecordService.java

@@ -0,0 +1,25 @@
+package org.springblade.manager.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.springblade.core.mp.support.Query;
+import org.springblade.manager.entity.ProjectInfo;
+import org.springblade.manager.entity.WbsTreePrivate;
+import org.springblade.manager.entity.WbsTreeSynchronousRecord;
+import org.springblade.manager.vo.WbsTreeSynchronousRecordVo;
+
+import java.util.List;
+
+/**
+* @author LHB
+* @description 针对表【m_wbs_tree_synchronous_record(WBS同步记录表)】的数据库操作Service
+* @createDate 2025-05-15 13:52:09
+*/
+public interface WbsTreeSynchronousRecordService extends IService<WbsTreeSynchronousRecord> {
+
+    WbsTreeSynchronousRecord insert(WbsTreeSynchronousRecord mWbsTreeSynchronousRecord);
+
+    List<WbsTreeSynchronousRecordVo> getProjectTemplate(String nodeIds);
+
+    WbsTreeSynchronousRecord getNodeStatus(Long id);
+}

+ 14 - 32
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -1246,22 +1246,13 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                     if (wbsTreeContractByP != null) {
                         //处理文件提名
                         String fileName = this.wbsParamService.createFileTitle(wbsTreeContractByP);
-                        String sql="select template_type from m_contract_info where id="+wbsTreeContractByP.getContractId();
-                        Integer type = jdbcTemplate.query(sql, rs -> {
-                            if (rs.next()) {
-                                return rs.getObject(1, Integer.class);
-                            } else {
-                                return 0; // 默认值
-                            }
-                        });
-                        if(type==2){
-                            if(wbsTreeContractByP.getMajorDataType()!=null&&wbsTreeContractByP.getMajorDataType()==4){
-                                if(tableInfo.getClassify()!=null&&tableInfo.getClassify().equals("1")){
-                                    //查询是否是底层节点
-                                    fileName=fileName+"检验申请批复单及附件";
-                                }else {
-                                    fileName=fileName+"抽检记录";
-                                }
+                        String sql1="Select sg_suffix,jl_suffix from m_project_info where id="+wbsTreeContractByP.getProjectId()+" and is_deleted=0";
+                        List<ProjectInfo> query = jdbcTemplate.query(sql1, new BeanPropertyRowMapper<>(ProjectInfo.class));
+                        if(query.size()>0){
+                            if(tableInfo.getClassify()!=null&&tableInfo.getClassify().equals("1")){
+                                fileName=fileName+(query.get(0).getSgSuffix()==null?"":query.get(0).getSgSuffix());
+                            }else {
+                                fileName=fileName+(query.get(0).getJlSuffix()==null?"":query.get(0).getJlSuffix());
                             }
                         }
                         //huangjn 保存成功后调用生成资料查询列表数据
@@ -1300,22 +1291,13 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                         .eq(WbsTreeContract::getId, wbsTreeContract.getParentId()).eq(WbsTreeContract::getContractId, wbsTreeContract.getContractId()));
                 //处理文件提名
                 fileName1= this.wbsParamService.createFileTitle(wbsTreeContractByP);
-                String sql="select template_type from m_contract_info where id="+wbsTreeContractByP.getContractId();
-                Integer type = jdbcTemplate.query(sql, rs -> {
-                    if (rs.next()) {
-                        return rs.getObject(1, Integer.class);
-                    } else {
-                        return 0; // 默认值
-                    }
-                });
-                if(type==2){
-                    if(wbsTreeContractByP.getMajorDataType()!=null&&wbsTreeContractByP.getMajorDataType()==4){
-                        if(tableInfoList.get(0).getClassify()!=null&&tableInfoList.get(0).getClassify().equals("1")){
-                            //查询是否是底层节点
-                            fileName1=fileName1+"检验申请批复单及附件";
-                        }else {
-                            fileName1=fileName1+"抽检记录";
-                        }
+                String sql1="Select sg_suffix,jl_suffix from m_project_info where id="+wbsTreeContractByP.getProjectId()+" and is_deleted=0";
+                List<ProjectInfo> query = jdbcTemplate.query(sql1, new BeanPropertyRowMapper<>(ProjectInfo.class));
+                if(query.size()>0){
+                    if(tableInfoList.get(0).getClassify()!=null&&tableInfoList.get(0).getClassify().equals("1")){
+                        fileName1=fileName1+(query.get(0).getSgSuffix()==null?"":query.get(0).getSgSuffix());
+                    }else {
+                        fileName1=fileName1+(query.get(0).getJlSuffix()==null?"":query.get(0).getJlSuffix());
                     }
                 }
                 //huangjn 保存成功后调用生成资料查询列表数据

+ 96 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousEViSaServiceImpl.java

@@ -0,0 +1,96 @@
+package org.springblade.manager.service.impl;
+
+import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import org.springblade.manager.entity.TextdictInfo;
+import org.springblade.manager.entity.WbsTreeContract;
+import org.springblade.manager.entity.WbsTreePrivate;
+import org.springblade.manager.entity.WbsTreeSynchronousRecord;
+import org.springblade.manager.mapper.TextdictInfoMapper;
+import org.springblade.manager.mapper.WbsTreeContractMapper;
+import org.springblade.manager.mapper.WbsTreePrivateMapper;
+import org.springblade.manager.mapper.WbsTreeSynchronousRecordMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @author LHB
+ */
+@Service
+public class WbsSynchronousEViSaServiceImpl {
+
+    @Autowired
+    private WbsTreePrivateMapper wbsTreePrivateMapper;
+    @Autowired
+    private WbsTreeContractMapper wbsTreeContractMapper;
+    //电签
+    @Autowired
+    private TextdictInfoMapper textdictInfoMapper;
+    @Autowired
+    private WbsTreeSynchronousRecordMapper synchronousRecordMapper;
+
+    @Transactional(rollbackFor = Exception.class)
+    public void updateTextDictInfo(Long projectId, List<Long> editPrivateIds, List<TextdictInfo> addData) {
+        //删除 需要新增的节点的电签和默认值
+        textdictInfoMapper.delete(Wrappers.<TextdictInfo>lambdaQuery()
+                .eq(TextdictInfo::getProjectId, projectId)
+                .in(TextdictInfo::getTabId, editPrivateIds));
+
+        textdictInfoMapper.insertBatchSomeColumn(addData);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public void updateSyncPrivateForm(String htmlUrl, List<Long> collect, Long id) {
+        wbsTreePrivateMapper.update(null, Wrappers.<WbsTreePrivate>lambdaUpdate()
+                .set(WbsTreePrivate::getHtmlUrl, htmlUrl)
+                .in(WbsTreePrivate::getPKeyId, collect)
+        );
+        synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                .set(WbsTreeSynchronousRecord::getStatus, 2)
+                .set(WbsTreeSynchronousRecord::getErrorMsg, null)
+                .set(WbsTreeSynchronousRecord::getNodeNumEnd, 1)
+                .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                .eq(WbsTreeSynchronousRecord::getId, id));
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public void syncPrivateForceForm(WbsTreePrivate wbsTreePrivate, String nodeId, Long id) {
+        wbsTreePrivateMapper.update(null, Wrappers.<WbsTreePrivate>lambdaUpdate()
+                .set(WbsTreePrivate::getExcelId, wbsTreePrivate.getExcelId())
+                .set(WbsTreePrivate::getInitTableName, wbsTreePrivate.getInitTableName())
+                .set(WbsTreePrivate::getHtmlUrl, wbsTreePrivate.getHtmlUrl())
+                .in(WbsTreePrivate::getPKeyId, nodeId)
+        );
+        synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                .set(WbsTreeSynchronousRecord::getStatus, 2)
+                .set(WbsTreeSynchronousRecord::getErrorMsg, null)
+                .set(WbsTreeSynchronousRecord::getNodeNumEnd, 1)
+                .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                .eq(WbsTreeSynchronousRecord::getId, id));
+    }
+
+
+    @Transactional(rollbackFor = Exception.class)
+    public void updatePrivate(Long createUserId, List<WbsTreePrivate> list ) {
+        for (WbsTreePrivate treePrivate : list) {
+            treePrivate.setUpdateTime(DateTime.now());
+            treePrivate.setUpdateUser(createUserId);
+            wbsTreePrivateMapper.updateById(treePrivate);
+        }
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    public void updateContract(Long createUserId, List<WbsTreeContract> list) {
+        for (WbsTreeContract treeContract : list) {
+            treeContract.setUpdateTime(DateTime.now());
+            treeContract.setUpdateUser(createUserId);
+            wbsTreeContractMapper.updateById(treeContract);
+        }
+    }
+}

+ 1276 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousServiceImpl.java

@@ -0,0 +1,1276 @@
+package org.springblade.manager.service.impl;
+
+import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.ObjectUtils;
+import org.springblade.business.entity.InformationQuery;
+import org.springblade.common.constant.CommonConstant;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.log.publisher.ErrorLogPublisher;
+import org.springblade.core.tool.utils.*;
+import org.springblade.manager.entity.*;
+import org.springblade.manager.enums.WbsSyncTypeEnum;
+import org.springblade.manager.mapper.*;
+import org.springblade.system.cache.ParamCache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.IOException;
+import java.rmi.ServerException;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * Wbs 同步功能Service
+ *
+ * @author LHB
+ */
+@Service
+public class WbsSynchronousServiceImpl {
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+    //实体表
+    @Autowired
+    private TableInfoMapper tableInfoMapper;
+    //清表
+    @Autowired
+    private ExcelTabMapper excelTabMapper;
+
+    //电签同步事务类
+    @Autowired
+    private WbsSynchronousEViSaServiceImpl wbsSynchronousEViSaService;
+    //电签
+    @Autowired
+    private TextdictInfoMapper textdictInfoMapper;
+    //合同wbs
+    @Autowired
+    private WbsTreeContractMapper wbsTreeContractMapper;
+    //合同
+    @Autowired
+    private ContractInfoMapper contractInfoMapper;
+    //项目wbs
+    @Autowired
+    private WbsTreePrivateMapper wbsTreePrivateMapper;
+    //系统wbs
+    @Autowired
+    private WbsTreeMapper wbsTreeMapper;
+    //项目
+    @Autowired
+    private ProjectInfoMapper projectInfoMapper;
+    //同步信息
+    @Autowired
+    private WbsTreeSynchronousRecordMapper synchronousRecordMapper;
+
+
+    @Async("taskExecutor1")
+    public void syncExecute(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
+        // 类型枚举 WbsSyncTypeEnum.ALREADY_FILLED_IN_NOT_REPORTED
+        //范围 1.项目,2.合同
+        //
+        try {
+            Integer range = wbsTreeSynchronousRecord.getRange();
+            switch (range) {
+                case 1:
+                    //同步项目
+                    insertPrivateNode(wbsTreeSynchronousRecord);
+                    break;
+                case 2:
+                    //同步合同段
+                    insertContractNode(wbsTreeSynchronousRecord);
+                    break;
+                case 3:
+                    //同步元素相同的所有表单
+                    syncPrivateAllForm(wbsTreeSynchronousRecord);
+                    break;
+                case 4:
+                    //强制同步表单
+                    syncPrivateForceForm(wbsTreeSynchronousRecord);
+                    break;
+                default:
+                    throw new ServiceException("同步类型错误");
+            }
+        } catch (Exception e) {
+            synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                    .set(WbsTreeSynchronousRecord::getStatus, 3)
+                    .set(WbsTreeSynchronousRecord::getErrorMsg, e.getMessage())
+                    .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                    .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
+            ErrorLogPublisher.publishEvent(e, null);
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 同步所有相同元素的表单
+     *
+     * @param wbsTreeSynchronousRecord
+     */
+    private void syncPrivateAllForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
+        String nodeId = wbsTreeSynchronousRecord.getNodeId();
+        WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(nodeId);
+        if (wbsTreePrivate == null) {
+            throw new ServiceException("节点/表单 不存在");
+        }
+        String initTableName = wbsTreePrivate.getInitTableName();
+        if (StringUtil.isBlank(initTableName)) {
+            throw new ServiceException("表单未绑定实体表");
+        }
+        //在指定项目下指定实体表相同的数据
+        List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                .eq(WbsTreePrivate::getProjectId, wbsTreePrivate.getProjectId())
+                .ne(WbsTreePrivate::getPKeyId, nodeId)
+                .eq(WbsTreePrivate::getInitTableName, initTableName)
+        );
+        if (CollectionUtil.isEmpty(wbsTreePrivates)) {
+            throw new ServiceException("当前项目没有相同实体表的其他表单");
+        }
+        //清表也相同的数据
+        List<WbsTreePrivate> collect = wbsTreePrivates.stream().filter(f ->
+                Objects.equals(f.getExcelId(), wbsTreePrivate.getExcelId())
+        ).collect(Collectors.toList());
+        //清表不同的数据
+        List<WbsTreePrivate> noExcelIdEq = wbsTreePrivates.stream().filter(f -> !Objects.equals(f.getExcelId(), wbsTreePrivate.getExcelId())).collect(Collectors.toList());
+        if (CollectionUtil.isNotEmpty(noExcelIdEq)) {
+            StringBuilder sb = new StringBuilder();
+            for (WbsTreePrivate treePrivate : noExcelIdEq) {
+                List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery().in(WbsTreePrivate::getPKeyId, Func.toLongList(treePrivate.getAncestorsPId())));
+                List<String> nodeNames = list.stream().map(WbsTreePrivate::getNodeName).collect(Collectors.toList());
+
+                sb.append(StringUtil.join(nodeNames, "/")).append(";");
+            }
+            throw new ServiceException("清表绑定错误:" + sb);
+        }
+        List<Long> ids = collect.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
+        //修改数据
+        wbsSynchronousEViSaService.updateSyncPrivateForm(wbsTreePrivate.getHtmlUrl(), ids, wbsTreeSynchronousRecord.getId());
+    }
+
+    /**
+     * 强制同步表单
+     *
+     * @param wbsTreeSynchronousRecord
+     */
+    private void syncPrivateForceForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
+        String nodeId = wbsTreeSynchronousRecord.getNodeId();
+        if (nodeId.contains(",")) {
+            throw new ServiceException("不能选中多个节点");
+        }
+        String formIds = wbsTreeSynchronousRecord.getFormIds();
+        //选中的表单
+        WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(formIds);
+        if (wbsTreePrivate == null) {
+            throw new ServiceException("表单不存在");
+        }
+        wbsSynchronousEViSaService.syncPrivateForceForm(wbsTreePrivate, nodeId, wbsTreeSynchronousRecord.getId());
+    }
+
+    /**
+     * 项目同步 获取源节点数据和当前节点数据
+     *
+     * @param wbsTreeSynchronousRecord
+     */
+    public void insertPrivateNode(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) throws IOException {
+        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+        //同步类型 1.新增表单,2.新增节点,3.删除节点,4.删除表单,5.修改节点,6.修改表单,7.修改节点表单
+        String type = wbsTreeSynchronousRecord.getType();
+        Set<Integer> collect = Arrays.stream(type.split(","))
+                .map(Integer::parseInt)
+                .collect(Collectors.toSet());
+
+        // 选中节点
+        String nodeId = wbsTreeSynchronousRecord.getNodeId();
+        if (StringUtil.isBlank(nodeId)) {
+            return;
+        }
+        String[] nodeIds = nodeId.split(",");
+        //选中表单
+        String formIds = wbsTreeSynchronousRecord.getFormIds();
+        Set<Long> formList = StringUtil.isNotBlank(formIds)
+                ? Arrays.stream(formIds.split(",")).map(Long::parseLong).collect(Collectors.toSet())
+                : Collections.emptySet();
+
+        //获取项目信息
+        ProjectInfo projectInfo = projectInfoMapper.selectOne(Wrappers.<ProjectInfo>lambdaQuery()
+                .eq(ProjectInfo::getId, wbsTreeSynchronousRecord.getProjectId()));
+        //模板项目信息
+        ProjectInfo tempProject = projectInfoMapper.selectOne(Wrappers.<ProjectInfo>lambdaQuery()
+                .eq(ProjectInfo::getId, wbsTreeSynchronousRecord.getTemplateId()));
+
+        List<WbsTreePrivate> editData = new ArrayList<>();
+
+        for (String primaryKeyId : nodeIds) {
+            if (StringUtils.isNotEmpty(primaryKeyId)) {
+                //获取当前节点对应节点信息
+                WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
+                        .eq(WbsTreePrivate::getPKeyId, primaryKeyId));
+                if (wbsTreePrivate == null) {
+                    throw new ServiceException("当前节点不存在");
+                }
+                //当前项目绑定的是公有模板还是私有项目
+                Boolean isPublic = false;
+
+                if (tempProject == null) {
+                    isPublic = true;
+                }
+
+                //当前项目模板对应的节点信息
+                List<WbsTreePrivate> templateNodes = new ArrayList<>();
+                //质检
+                //当前节点引用的模板为公有模板
+
+                if (isPublic) {
+                    //获取模板中当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
+                    LambdaQueryWrapper<WbsTree> wrapperTree = Wrappers.lambdaQuery();
+                    wrapperTree
+                            .eq(WbsTree::getIsDeleted, 0)
+                            .eq(WbsTree::getType, 2)
+                            .apply("FIND_IN_SET({0},ancestors)", wbsTreePrivate.getTreePId());
+                    //模板节点的所有子节点信息
+                    List<WbsTree> wbsTrees = wbsTreeMapper.selectList(wrapperTree);
+                    //3、获取需要新增的节点或者表单节点信息 以及他们对应的父级节点信息--------------------------------------------------------------------------------------------
+                    if (CollectionUtil.isEmpty(wbsTrees)) {
+                        throw new ServiceException("模板节点未找到");
+                    }
+                    templateNodes = BeanUtil.copyProperties(wbsTrees, WbsTreePrivate.class);
+                    templateNodes.forEach(f -> {
+                        f.setPKeyId(f.getId());
+                        f.setTreePId(f.getId());
+                    });
+
+                } else {
+                    //获取当前选中节点与私有模板对应的节点信息 父级模板项目的当前选中节点
+                    WbsTreePrivate wbsTreePrivateRoot = wbsTreePrivateMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
+                            .eq(WbsTreePrivate::getProjectId, wbsTreeSynchronousRecord.getTemplateId())
+                            .eq(WbsTreePrivate::getTreePId, wbsTreePrivate.getTreePId()));
+
+                    //获取模板中当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
+                    LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
+                    wrapperPrivate
+                            .eq(WbsTreePrivate::getProjectId, wbsTreePrivateRoot.getProjectId())
+                            .eq(WbsTreePrivate::getType, 2)
+                            .eq(WbsTreePrivate::getIsDeleted, 0);
+                    //判断如果为顶级顶级节点
+                    if (wbsTreePrivate.getTreePId() != 0) {
+                        wrapperPrivate.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivateRoot.getPKeyId());
+                    }
+                    templateNodes = wbsTreePrivateMapper.selectList(wrapperPrivate);
+                }
+
+                if (CollectionUtil.isEmpty(templateNodes)) {
+                    throw new ServiceException("模板节点未找到");
+                }
+
+
+                //2、获取当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
+                LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
+                wrapperPrivate
+                        .eq(WbsTreePrivate::getWbsId, wbsTreePrivate.getWbsId())
+                        .eq(WbsTreePrivate::getIsDeleted, 0);
+                //判断如果为顶级顶级节点
+                if (wbsTreePrivate.getTreePId() != 0) {
+                    wrapperPrivate.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivate.getPKeyId());
+                }
+
+                //当前表节点下的节点信息
+                List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(wrapperPrivate);
+                //把选中节点也加进去 方便后面使用
+                wbsTreePrivates.add(wbsTreePrivate);
+
+                if (wbsTreePrivates.isEmpty()) {
+                    throw new ServiceException("项目节点未找到");
+                }
+
+                //获取id 和 tree_p_id 组成的集合
+                Set<Long> ids = wbsTreePrivates.stream().map(WbsTreePrivate::getTreePId).collect(Collectors.toSet());
+                //3.1筛选出需要新增的节点
+                List<WbsTreePrivate> addPrivateNodes = templateNodes.stream()
+                        .filter(f -> !ids.contains(f.getTreePId()))
+                        .collect(Collectors.toList());
+
+                //新增数据二次筛选  只保留任务选中的表单   但可能新增的数据包含新节点
+                if (CollectionUtil.isNotEmpty(formList)) {
+                    addPrivateNodes = addPrivateNodes.stream().filter(f -> f.getType() == 1 || formList.contains(f.getPKeyId())).collect(Collectors.toList());
+                }
+
+                //筛选出需要更新的节点  同时做数据隔离
+                List<WbsTreePrivate> editPrivateNodes = new ArrayList<>();
+                for (WbsTreePrivate templateNode : templateNodes) {
+                    //数据修复-----------------------------------------------------------------------------------------------------------------------------------开始
+                    if (!isPublic && templateNode.getType() == 2 && collect.contains(2)) {
+                        boolean isUpdate = false;
+                        if (templateNode.getExcelId() != null) {
+                            ExcelTab excelTab = excelTabMapper.selectOne(Wrappers.<ExcelTab>lambdaQuery()
+                                    .select(ExcelTab::getTabId)
+                                    .eq(ExcelTab::getId, templateNode.getExcelId()));
+                            if (excelTab == null) {
+                                throw new ServerException(templateNode.getNodeName() + " excel未知");
+                            }
+                            if (StringUtil.isBlank(templateNode.getInitTableName())) {
+                                TableInfo tableInfo = tableInfoMapper.selectOne(Wrappers.<TableInfo>lambdaQuery()
+                                        .select(TableInfo::getId)
+                                        .eq(TableInfo::getId, excelTab.getTabId()));
+                                if (tableInfo == null) {
+                                    throw new ServerException(templateNode.getNodeName() + " 实体表未知");
+                                }
+                                templateNode.setInitTableName(tableInfo.getTabEnName());
+                                isUpdate = true;
+                            }
+                            if (StringUtil.isBlank(templateNode.getHtmlUrl())) {
+                                List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                                        .eq(WbsTreePrivate::getExcelId, templateNode.getExcelId())
+                                        .eq(WbsTreePrivate::getInitTableName, templateNode.getInitTableName())
+                                        .eq(WbsTreePrivate::getProjectId, templateNode.getProjectId()));
+                                if (CollectionUtil.isNotEmpty(list)) {
+                                    templateNode.setHtmlUrl(list.get(0).getHtmlUrl());
+                                    isUpdate = true;
+                                } else {
+                                    throw new ServerException(templateNode.getNodeName() + " html不存在");
+                                }
+                            }
+                        } else if (StringUtil.isNotBlank(templateNode.getInitTableName())) {
+                            TableInfo tableInfo = tableInfoMapper.selectOne(Wrappers.<TableInfo>lambdaQuery()
+                                    .select(TableInfo::getId)
+                                    .eq(TableInfo::getTabEnName, templateNode.getInitTableName()));
+                            if (tableInfo == null) {
+                                throw new ServerException(templateNode.getNodeName() + " 实体表未知");
+                            }
+                            if (templateNode.getExcelId() == null) {
+                                ExcelTab excelTab = excelTabMapper.selectOne(Wrappers.<ExcelTab>lambdaQuery()
+                                        .select(ExcelTab::getId)
+                                        .eq(ExcelTab::getTabId, tableInfo.getId()));
+                                if (excelTab == null) {
+                                    throw new ServerException(templateNode.getNodeName() + " excel未知");
+                                }
+                                templateNode.setExcelId(excelTab.getId());
+                                isUpdate = true;
+                            }
+                            if (StringUtil.isBlank(templateNode.getHtmlUrl())) {
+                                List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                                        .eq(WbsTreePrivate::getInitTableName, templateNode.getInitTableName())
+                                        .eq(WbsTreePrivate::getExcelId, templateNode.getExcelId())
+                                        .eq(WbsTreePrivate::getProjectId, templateNode.getProjectId()));
+                                if (CollectionUtil.isNotEmpty(list)) {
+                                    templateNode.setHtmlUrl(list.get(0).getHtmlUrl());
+                                    isUpdate = true;
+                                } else {
+                                    throw new ServerException(templateNode.getNodeName() + " html不存在");
+                                }
+                            }
+                        } else if (StringUtil.isNotBlank(templateNode.getHtmlUrl())) {
+                            List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                                    .eq(WbsTreePrivate::getInitTableName, templateNode.getInitTableName())
+                                    .eq(WbsTreePrivate::getExcelId, templateNode.getExcelId())
+                                    .eq(WbsTreePrivate::getProjectId, templateNode.getProjectId()));
+                            if (CollectionUtil.isNotEmpty(list)) {
+                                templateNode.setExcelId(templateNode.getExcelId() == null ? list.get(0).getExcelId() : templateNode.getExcelId());
+                                templateNode.setInitTableName(templateNode.getInitTableName() == null ? list.get(0).getInitTableName() : templateNode.getInitTableName());
+                                isUpdate = true;
+                            } else {
+                                throw new ServerException(templateNode.getNodeName() + " html不存在");
+                            }
+                        }
+                        if (isUpdate) {
+                            wbsTreePrivateMapper.update(templateNode, Wrappers.<WbsTreePrivate>lambdaUpdate()
+                                    .eq(WbsTreePrivate::getPKeyId, templateNode.getPKeyId()));
+                        }
+                    }
+                    //数据修复-----------------------------------------------------------------------------------------------------------------------------------完成
+                    //更新只跟新表单
+                    for (WbsTreePrivate editPrivateNode : wbsTreePrivates) {
+                        // 判断模板表与项目表 html是否一致
+                        if (ObjectUtils.equals(templateNode.getTreePId(), editPrivateNode.getTreePId()) && templateNode.getType() == 2) {
+                            //清表
+                            if (collect.contains(2)) {
+                                //绑定清表
+                                editPrivateNode.setExcelId(templateNode.getExcelId());
+                                //绑定实体表
+                                editPrivateNode.setInitTableName(templateNode.getInitTableName());
+
+                                if (StringUtil.isBlank(templateNode.getHtmlUrl())) {
+                                    throw new ServiceException(templateNode.getNodeName() + "HTML文件不存在");
+                                }
+                                //封装Html路径 根据模板html copy一份到自己项目节点上
+                                String[] split = templateNode.getHtmlUrl().split("/");
+                                String htmlUrl = file_path + "privateUrlCopy/" + projectInfo.getId() + "/" + split[split.length - 1];
+                                File file_in = ResourceUtil.getFile(templateNode.getHtmlUrl());
+                                if (!file_in.exists() || file_in.length() == 0) {
+                                    //如果本地服务器上没有
+                                    throw new ServiceException(templateNode.getNodeName() + "HTML文件不存在");
+                                }
+                                File file_out = ResourceUtil.getFile(htmlUrl);
+                                //查询父级文件夹
+                                File fileParent = file_out.getParentFile();
+                                if (!fileParent.exists()) {
+                                    fileParent.mkdirs();
+                                }
+                                file_out.createNewFile();
+                                FileUtil.copy(file_in, file_out);
+                                editPrivateNode.setHtmlUrl(htmlUrl);
+                            }
+
+
+                            if (templateNode.getExcelId() != null) {
+                                editPrivateNode.setIsLinkTable(2);
+                            }
+
+                            //元素 是与表绑定的
+                            if (collect.contains(3)) {
+                                editPrivateNode.setInitTableName(templateNode.getInitTableName());
+                            }
+
+
+                            //排序
+                            if (collect.contains(7)) {
+                                editPrivateNode.setSort(templateNode.getSort());
+                            }
+
+                            //手动选中的表单 进行筛选
+                            if (CollectionUtil.isNotEmpty(formList)) {
+                                if (formList.contains(templateNode.getPKeyId())) {
+                                    if (collect.contains(2) || collect.contains(3) || collect.contains(4) || collect.contains(5) || collect.contains(6) || collect.contains(7)) {
+                                        editPrivateNodes.add(editPrivateNode);
+                                    }
+                                }
+                            } else {
+                                if (collect.contains(2) || collect.contains(3) || collect.contains(4) || collect.contains(5) || collect.contains(6) || collect.contains(7)) {
+                                    editPrivateNodes.add(editPrivateNode);
+                                }
+                            }
+                        }
+                    }
+                }
+
+                //转List做排序
+                List<Integer> arrayList = new ArrayList<>(collect);
+                Collections.sort(arrayList);
+                for (Integer i : arrayList) {
+                    switch (i) {
+                        //添加表单
+                        case 1:
+                            insertPrivateForm(wbsTreeSynchronousRecord, wbsTreePrivates, addPrivateNodes);
+                            break;
+                        //清表
+                        case 2:
+                            //元素
+                        case 3:
+                            //公式配置
+                        case 5:
+                            //排序
+                        case 7:
+                            //元素配置
+                            editData.addAll(editPrivateNodes);
+                            break;
+                        //电签 如果有数据 与节点绑定
+                        case 4:
+                            //默认值  如果有数据 与节点绑定
+                        case 6:
+                            //现在电签使用的是模糊匹配 如果电签匹配方式改为精确匹配 则需要使用该功能
+//                            updateEViSa(collect, wbsTreeSynchronousRecord.getTemplateId(), projectInfo.getId(), templateNodes, editPrivateNodes);
+                            break;
+                        default:
+                            break;
+                    }
+                }
+            }
+        }
+        //更新数据的同时统计最小节点数量
+        Map<Long, List<WbsTreePrivate>> collect1 = editData.stream().collect(Collectors.groupingBy(WbsTreePrivate::getPId));
+        Set<Long> pIds = collect1.keySet();
+        Integer nodeNumEnd = 0;
+        for (Long pId : pIds) {
+            nodeNumEnd++;
+            //更新最新节点
+            wbsSynchronousEViSaService.updatePrivate(wbsTreeSynchronousRecord.getCreateUserId(), collect1.get(pId));
+
+            synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                    .set(WbsTreeSynchronousRecord::getNodeNumEnd, nodeNumEnd)
+                    .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                    .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
+        }
+        synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                .set(WbsTreeSynchronousRecord::getStatus, 2)
+                .set(WbsTreeSynchronousRecord::getErrorMsg, null)
+                .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
+    }
+
+
+    /**
+     * 合同段同步 获取源节点数据和当前节点数据
+     */
+    public void insertContractNode(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
+        //同步类型 1.新增表单,2.新增节点,3.删除节点,4.删除表单,5.修改节点,6.修改表单,7.修改节点表单
+        String type = wbsTreeSynchronousRecord.getType();
+        Set<Integer> collect = Arrays.stream(type.split(","))
+                .map(Integer::parseInt)
+                .collect(Collectors.toSet());
+
+        // 选中节点
+        String nodeId = wbsTreeSynchronousRecord.getNodeId();
+        if (StringUtil.isBlank(nodeId)) {
+            return;
+        }
+        String[] nodeIds = nodeId.split(",");
+        //选中表单
+        String formIds = wbsTreeSynchronousRecord.getFormIds();
+        Set<Long> formList = StringUtil.isNotBlank(formIds)
+                ? Arrays.stream(formIds.split(",")).map(Long::parseLong).collect(Collectors.toSet())
+                : Collections.emptySet();
+
+        /**
+         * 合同段选择的类型
+         *  质检系统 101.未填报 102.已填报-未上报 104.待审批 105.已审批
+         *  试验系统 103.未上报 104.待审批 105.已审批
+         *  计量系统 103.未上报 104.待审批 105.已审批
+         */
+        String contractRange = wbsTreeSynchronousRecord.getContractRange();
+        Set<Integer> contractRanges = StringUtil.isNotBlank(contractRange)
+                ? Arrays.stream(contractRange.split(",")).map(Integer::parseInt).collect(Collectors.toSet())
+                : Collections.emptySet();
+
+
+        //获取当前项目所有合同---------------------------------------------------------------------------------------------------
+        List<ContractInfo> contractInfos = contractInfoMapper.selectContractIdByProjectId(String.valueOf(wbsTreeSynchronousRecord.getProjectId()));
+
+        List<WbsTreeContract> editData = new ArrayList<>();
+        for (String primaryKeyId : nodeIds) {
+
+            //获取当前节点对应节点信息
+            WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
+                    .eq(WbsTreePrivate::getPKeyId, primaryKeyId));
+            //如果wbs类型为空 则放弃该同步
+            if (StringUtil.isBlank(wbsTreePrivate.getWbsType())) {
+                throw new ServiceException("系统类型未知");
+            }
+
+            //当前项目选中的节点 获取当前节点的所有子节点数据
+            //1、获取当前节点的子节点 表单的数据------------------------------------------------------------------------------------------------------------------------
+            LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
+            wrapperPrivate
+                    .eq(WbsTreePrivate::getWbsId, wbsTreePrivate.getWbsId())
+                    .eq(WbsTreePrivate::getType, 2)
+                    .eq(WbsTreePrivate::getIsDeleted, 0)
+                    .apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivate.getPKeyId());
+            //当前项目的子节点数据
+            List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(wrapperPrivate);
+            wbsTreePrivates.add(wbsTreePrivate);
+
+            if (wbsTreePrivates.isEmpty()) {
+                throw new ServiceException("无法找到模板对应节点,请检查模板节点");
+            }
+
+            //合同同步
+            for (ContractInfo contractInfo : contractInfos) {
+                //获取合同下当前节点的数据
+                List<WbsTreeContract> startContacts = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
+                        .eq(WbsTreeContract::getContractId, contractInfo.getId())
+                        .eq(WbsTreeContract::getIsTypePrivatePid, primaryKeyId));
+                //如果没有查询到,表示该合同下不存在该节点
+                if (CollectionUtil.isEmpty(startContacts)) {
+                    //不能抛异常  不然就会中止程序  开发阶段先抛异常,后续统一处理
+                    throw new ServiceException("当前节点不存在");
+                }
+                for (WbsTreeContract wbsTreeContract : startContacts) {
+                    //获取合同 当前节点的所有子节点数据
+                    LambdaQueryWrapper<WbsTreeContract> wrapperContract = Wrappers.lambdaQuery();
+                    wrapperContract
+                            .eq(WbsTreeContract::getContractId, contractInfo.getId())
+                            .eq(WbsTreeContract::getIsDeleted, 0)
+                            .apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreeContract.getPKeyId());
+                    wrapperContract.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreeContract.getPKeyId());
+
+                    //当前合同的子节点数据
+                    List<WbsTreeContract> wbsTreeContracts = wbsTreeContractMapper.selectList(wrapperContract);
+                    wbsTreeContracts.add(wbsTreeContract);
+
+                    HashMap<Long, Integer> informationQueryMap = new HashMap<>();
+                    //查询质检合同节点填表信息
+                    String sql = "SELECT  b.wbs_id, b.STATUS  FROM" +
+                            "( SELECT p_key_id FROM m_wbs_tree_contract WHERE is_deleted = 0 AND contract_id = " + contractInfo.getId() + " AND FIND_IN_SET( " + wbsTreeContract.getPKeyId() + ", ancestors_p_id ) ) a" +
+                            " INNER JOIN (  SELECT  c.wbs_id, c.STATUS FROM u_information_query c" +
+                            " JOIN ( SELECT wbs_id, MAX( update_time ) AS max_update_time FROM u_information_query WHERE contract_id = " + contractInfo.getId() + " GROUP BY wbs_id ) subquery ON c.wbs_id = subquery.wbs_id " +
+                            " AND c.update_time = subquery.max_update_time WHERE  c.contract_id = " + contractInfo.getId() + " and c.is_deleted = 0 ) b ON a.p_key_id = b.wbs_id";
+
+                    List<InformationQuery> informationQueries = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(InformationQuery.class));
+                    //质检节点填报信息
+
+                    for (InformationQuery informationQuery : informationQueries) {
+                        informationQueryMap.put(informationQuery.getWbsId(), informationQuery.getStatus());
+                    }
+
+
+                    //合同段节点对应的项目id
+                    List<Long> typePrivateIds = wbsTreeContracts.stream().map(WbsTreeContract::getIsTypePrivatePid).collect(Collectors.toList());
+
+                    //需要新增的表单
+                    List<WbsTreePrivate> addPrivateNodes = wbsTreePrivates.stream().filter(f -> !typePrivateIds.contains(f.getPKeyId())).collect(Collectors.toList());
+
+                    //如果没有选中 则默认同步所有
+                    if (CollectionUtil.isNotEmpty(formList)) {
+                        //二次筛选  只保留任务选中的表单   但可能新增的数据包含新节点
+                        addPrivateNodes = addPrivateNodes.stream().filter(f -> formList.contains(f.getPKeyId())).collect(Collectors.toList());
+                    }
+
+                    //筛选出需要更新的节点  同时做数据隔离
+                    List<WbsTreeContract> editContractNodes = new ArrayList<>();
+                    for (WbsTreePrivate templateNode : wbsTreePrivates) {
+                        //更新只跟新表单
+                        for (WbsTreeContract editContractNode : wbsTreeContracts) {
+
+                            // 判断模板表与项目表 html是否一致
+                            if (ObjectUtils.equals(templateNode.getPKeyId(), editContractNode.getIsTypePrivatePid())) {
+                                if (templateNode.getType() == 2) {
+                                    //同步范围 当前节点是否允许修改
+                                    Boolean isSync = false;
+                                    if (CollectionUtil.isNotEmpty(contractRanges)) {
+                                        switch (Integer.valueOf(wbsTreePrivate.getWbsType())) {
+                                            //质检
+                                            case 1:
+                                                Integer submit = informationQueryMap.get(editContractNode.getPKeyId());
+
+                                                if (submit == null && contractRanges.contains(WbsSyncTypeEnum.NOT_FILLED_IN.code)) {
+                                                    //未审批 101
+                                                    isSync = true;
+                                                } else {
+                                                    if (submit == null) {
+                                                        throw new ServiceException(wbsTreeContract.getNodeName() + "--下表单未查到填报信息");
+                                                    }
+                                                    if (submit == 0 && contractRanges.contains(WbsSyncTypeEnum.ALREADY_FILLED_IN_NOT_REPORTED.code)) {
+                                                        //已填报-未上报 102
+                                                        isSync = true;
+                                                    } else if (submit == 1 && contractRanges.contains(WbsSyncTypeEnum.PENDING_APPROVAL.code)) {
+                                                        //待审批 104
+                                                        isSync = true;
+                                                    } else if (submit == 2 && contractRanges.contains(WbsSyncTypeEnum.APPROVED.code)) {
+                                                        //已审批 105
+                                                        isSync = true;
+                                                    }
+                                                }
+                                                break;
+                                            //试验
+                                            case 2:
+                                                break;
+                                            //计量
+                                            case 3:
+                                                break;
+                                            //日志
+                                            case 4:
+                                                break;
+                                            //征地拆迁
+                                            case 5:
+                                                break;
+                                            default:
+                                                break;
+                                        }
+                                    } else {
+                                        isSync = true;
+                                    }
+
+
+                                    //清表 公式 元素
+                                    if (collect.contains(2) || collect.contains(3) || collect.contains(5)) {
+                                        editContractNode.setExcelId(templateNode.getExcelId());
+                                        editContractNode.setInitTableName(templateNode.getInitTableName());
+                                        editContractNode.setHtmlUrl(templateNode.getHtmlUrl());
+                                        if (templateNode.getExcelId() != null) {
+                                            editContractNode.setIsLinkTable(2);
+                                        }
+                                    }
+                                    //排序
+                                    if (collect.contains(7)) {
+                                        editContractNode.setSort(templateNode.getSort());
+                                    }
+
+                                    //手动选中的表单 进行筛选
+                                    if (CollectionUtil.isNotEmpty(formList)) {
+                                        if (formList.contains(templateNode.getPKeyId())) {
+                                            if (collect.contains(2) || collect.contains(3) || collect.contains(4) || collect.contains(5) || collect.contains(6) || collect.contains(7)) {
+                                                if (isSync) {
+                                                    editContractNodes.add(editContractNode);
+                                                }
+
+                                            }
+                                        }
+                                    } else {
+                                        if (collect.contains(2) || collect.contains(3) || collect.contains(4) || collect.contains(5) || collect.contains(6) || collect.contains(7)) {
+                                            if (isSync) {
+                                                editContractNodes.add(editContractNode);
+                                            }
+                                        }
+                                    }
+                                    //找到了某个选中节点下与项目节点想同的节点了  提前结束循环,节省资源
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                    //修改数据二次筛选  只保留任务选中的表单   但可能新增的数据包含新节点
+                    if (CollectionUtil.isNotEmpty(formList)) {
+                        editContractNodes = editContractNodes.stream().filter(f -> formList.contains(f.getPKeyId())).collect(Collectors.toList());
+                    }
+
+                    //合同段新增节点
+                    List<WbsTreeContract> addContractNode = null;
+                    if (addPrivateNodes != null) {
+                        addContractNode = BeanUtil.copyProperties(addPrivateNodes, WbsTreeContract.class);
+                    }
+
+                    //转类型排序
+                    List<Integer> integers = new ArrayList<>(collect);
+                    Collections.sort(integers);
+                    for (Integer i : integers) {
+                        switch (i) {
+                            //添加表单
+                            case 1:
+                                insertContractForm(wbsTreeSynchronousRecord, contractInfo, wbsTreeContracts, addContractNode);
+                                //如果同时选择新增表单和其他的同步类型  在操作其他类型的时候需要添加新的表单
+//                                    if (CollectionUtil.isNotEmpty(addContractNode)) {
+//                                        editContractNodes.addAll(addContractNode.stream().filter(f -> f.getType() == 2).collect(Collectors.toList()));
+//                                    }
+                                break;
+                            //清表配置
+                            case 2:
+                                //元素配置
+                            case 3:
+                                //公式配置
+                            case 5:
+                                //排序
+                            case 7:
+                                editData.addAll(editContractNodes);
+                                break;
+                            default:
+                                break;
+                        }
+                    }
+                }
+            }
+
+        }
+
+
+        //合同段同步同时记录数量
+        Map<Long, List<WbsTreeContract>> collect1 = editData.stream().collect(Collectors.groupingBy(WbsTreeContract::getPId));
+        Set<Long> pIds = collect1.keySet();
+        Integer nodeNumEnd = 0;
+
+        for (Long pId : pIds) {
+            nodeNumEnd++;
+            wbsSynchronousEViSaService.updateContract(wbsTreeSynchronousRecord.getCreateUserId(), collect1.get(pId));
+            synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                    .set(WbsTreeSynchronousRecord::getNodeNumEnd, nodeNumEnd)
+                    .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                    .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
+        }
+
+        synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                .set(WbsTreeSynchronousRecord::getStatus, 2)
+                .set(WbsTreeSynchronousRecord::getErrorMsg, null)
+                .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
+    }
+
+
+    /**
+     * 项目
+     * 类型 1 添加表单
+     *
+     * @param wbsTreeSynchronousRecord 同步任务
+     * @param wbsTreePrivates          当前项目对应节点的子节点
+     * @param addPrivateNodes          需要新增的节点
+     */
+    public void insertPrivateForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord, List<WbsTreePrivate> wbsTreePrivates, List<WbsTreePrivate> addPrivateNodes) {
+        List<WbsTreePrivate> addData = new ArrayList<>();
+
+        //------------------------------------------------新增-------------------------------------------------------------------------
+        if (CollectionUtil.isNotEmpty(addPrivateNodes)) {
+            //先给每个新增节点赋唯一id,项目id,父级id
+            addPrivateNodes.forEach(f -> f.setPKeyId(SnowFlakeUtil.getId()));
+
+            //给每一个节点的父级id
+            for (WbsTreePrivate addPrivateNode : addPrivateNodes) {
+                if (addPrivateNode.getParentId() == 0) {
+                    continue;
+                }
+
+                //查询出当前模板节点的父节点 去获取对应项目节点  如果父节点为0就跳过
+                List<WbsTreePrivate> addPrivateParentNodes = wbsTreePrivates.stream().filter(f -> f.getTreePId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
+                //如果没有数据  就表示这条数据的父节点也时新增节点 就需要从新增节点集合中找父级节点
+                if (addPrivateParentNodes.isEmpty()) {
+                    addPrivateParentNodes = addPrivateNodes.stream().filter(f -> f.getTreePId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
+                }
+                //如果现在还找不到当前节点的父节点就表示数据有问题
+                if (addPrivateParentNodes.isEmpty()) {
+                    throw new ServiceException(addPrivateNode.getNodeName() + "-找不到父节点");
+                }
+                //当前新增节点的父节点
+                WbsTreePrivate parent = addPrivateParentNodes.get(0);
+
+                addPrivateNode.setPId(parent.getPKeyId());
+                addPrivateNode.setWbsId(parent.getWbsId());
+                addPrivateNode.setWbsType(parent.getWbsType());
+                addPrivateNode.setIsAddConceal(0);
+                addPrivateNode.setProjectId(wbsTreePrivates.get(0).getProjectId());
+                //TODO 后续如果把p_key_id改成了id做 唯一id
+                addPrivateNode.setTreePId(addPrivateNode.getTreePId());
+                //后续如果使用id做当前表主键 则先在赋值treePid之后再去赋值id    addPrivateNode.setId(SnowFlakeUtil.getId());
+                //更新创建时间
+                addPrivateNode.setCreateTime(DateTime.now());
+                addPrivateNode.setCreateUser(wbsTreeSynchronousRecord.getCreateUserId());
+                addData.add(addPrivateNode);
+            }
+        }
+        //设置html_url----------------------------------------------------------------------------------------------------------
+        //如果有新增的数据 旧设置html_url
+        if (CollectionUtil.isNotEmpty(addData)) {
+            try {
+                String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+                Set<String> urls = new HashSet<>();
+                for (WbsTreePrivate tree : addData) {
+                    if (org.apache.commons.lang3.StringUtils.isNotBlank(tree.getHtmlUrl())) {
+                        String[] split = tree.getHtmlUrl().split("/");
+                        String htmlUrl = file_path + "privateUrlCopy/" + wbsTreePrivates.get(0).getProjectId() + "/" + split[split.length - 1];
+                        if (!urls.contains(tree.getHtmlUrl())) {
+                            urls.add(tree.getHtmlUrl());
+                            File file_in = ResourceUtil.getFile(tree.getHtmlUrl());
+                            if (!file_in.exists() || file_in.length() == 0) {
+                                //如果本地服务器上没有
+                                throw new ServiceException(tree.getNodeName() + "HTML文件不存在");
+                            }
+                            File file_out = ResourceUtil.getFile(htmlUrl);
+                            //查询父级文件夹
+                            File fileParent = file_out.getParentFile();
+                            if (!fileParent.exists()) {
+                                fileParent.mkdirs();
+                            }
+                            file_out.createNewFile();
+                            FileUtil.copy(file_in, file_out);
+                        }
+                        tree.setHtmlUrl(htmlUrl);
+                    }
+                }
+            } catch (ServiceException e) {
+                throw new ServiceException(e.getMessage());
+            } catch (Exception e) {
+                e.printStackTrace();
+                throw new ServiceException("重置表单路径错误");
+            }
+
+            //查询出当前项目所有节点---------------------------------------------------------------------------------------------------
+            List<WbsTreePrivate> addList = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                    .select(WbsTreePrivate::getPKeyId, WbsTreePrivate::getPId)
+                    .eq(WbsTreePrivate::getIsDeleted, 0)
+                    .eq(WbsTreePrivate::getProjectId, addData.get(0).getProjectId()));
+
+            addList.addAll(addData);
+            //组合祖级路径 根据当前选中节点为开始
+            Map<Long, WbsTreePrivate> collect = addList.stream().collect(Collectors.toMap(WbsTreePrivate::getPKeyId, Function.identity()));
+
+            addData.forEach(node -> {
+                String correctAncestors = createAncestorsPId(node, collect);
+                node.setAncestorsPId(correctAncestors);
+            });
+
+            //新增-----------------------------------------------------------------------------------------------------------------
+            List<List<WbsTreePrivate>> partition = Lists.partition(addData, 1000);
+            Integer count = 0;
+            for (List<WbsTreePrivate> data : partition) {
+                //单个批次一个事务,只会回滚当前批次数据
+                Integer i = wbsTreePrivateMapper.insertBatchSomeColumn(data);
+                //如果失败  -- - - - - 继续执行   或者把当前节点的p_key_id 记录到某个地方 方便后续处理
+                if (i == 0) {
+                    List<Long> collect1 = addData.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
+                    //这里可以保存到数据库指定错误日志表
+                    throw new ServiceException("重置表单路径错误:" + StringUtil.join(collect1, ","));
+                }
+
+                count += i;
+            }
+        }
+    }
+
+    /**
+     * 合同段添加表单
+     * 合同段添加表单
+     *
+     * @param wbsTreeSynchronousRecord 同步任务
+     * @param contractInfo             合同段信息
+     * @param wbsTreeContracts         当前合同节点数据
+     * @param addContractNodes         新增节点数据
+     */
+    public void insertContractForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord, ContractInfo contractInfo, List<WbsTreeContract> wbsTreeContracts, List<WbsTreeContract> addContractNodes) {
+        List<WbsTreeContract> addData = new ArrayList<>();
+
+
+        if (CollectionUtil.isNotEmpty(addContractNodes)) {
+
+            //选给新增的节点赋值
+            addContractNodes.forEach(f -> {
+                f.setIsTypePrivatePid(f.getPKeyId());
+                f.setPKeyId(SnowFlakeUtil.getId());
+            });
+
+            for (WbsTreeContract addContractNode : addContractNodes) {
+                if (addContractNode.getParentId() == 0) {
+                    continue;
+                }
+
+                //查询出当前模板节点的父节点 去获取对应项目节点  如果父节点为0就跳过
+                List<WbsTreeContract> addContractParentNodes = wbsTreeContracts.stream().filter(f -> Objects.equals(f.getTreePId(), addContractNode.getParentId())).collect(Collectors.toList());
+
+                //如果没有数据  就表示这条数据的父节点也时新增节点 就需要从新增节点集合中找父级节点
+                if (addContractParentNodes.isEmpty()) {
+                    addContractParentNodes = addContractNodes.stream().filter(f -> f.getTreePId().equals(addContractNode.getParentId())).collect(Collectors.toList());
+                }
+                //如果现在还找不到当前节点的父节点就表示数据有问题
+                if (addContractParentNodes.isEmpty()) {
+                    //TODO
+                    throw new ServiceException(addContractNode.getNodeName() + "-找不到父节点");
+                }
+                //当前新增节点的父节点
+                WbsTreeContract parent = addContractParentNodes.get(0);
+
+                addContractNode.setIsBussShow(1);
+                addContractNode.setIsDeleted(0);
+                addContractNode.setStatus(1);
+                addContractNode.setParentId(parent.getId());
+                addContractNode.setAncestors(parent.getAncestors() + "," + parent.getId());
+                //TODO
+                addContractNode.setTreePId(addContractNode.getTreePId());
+                //TODO
+                addContractNode.setPId(parent.getPKeyId());
+                //TODO
+                addContractNode.setContractId(parent.getContractId());
+                addContractNode.setContractId(String.valueOf(contractInfo.getId()));
+                //更新创建时间
+                addContractNode.setCreateTime(DateTime.now());
+                addContractNode.setCreateUser(wbsTreeSynchronousRecord.getCreateUserId());
+            }
+            addData.addAll(addContractNodes);
+        }
+
+
+        //查询出当前项目所有节点---------------------------------------------------------------------------------------------------
+        List<WbsTreeContract> addList = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
+                .select(WbsTreeContract::getPKeyId, WbsTreeContract::getPId)
+                .eq(WbsTreeContract::getIsDeleted, 0)
+                .eq(WbsTreeContract::getContractId, contractInfo.getId()));
+
+        addList.addAll(addData);
+
+
+        //组合祖级路径 根据当前选中节点为开始
+        Map<Long, WbsTreeContract> collect = addList.stream().collect(Collectors.toMap(WbsTreeContract::getPKeyId, Function.identity()));
+
+        addData.forEach(node -> {
+            //通过转换为WbsTreePrivate的方式 去获取祖级节点
+            String correctAncestors = createAncestorsPId(node, collect);
+            node.setAncestorsPId(correctAncestors);
+        });
+
+        //新增-----------------------------------------------------------------------------------------------------------------
+        List<List<WbsTreeContract>> partition = Lists.partition(addData, 1000);
+        for (List<WbsTreeContract> data : partition) {
+            //单个批次一个事务,只会回滚当前批次数据
+            Integer i = wbsTreeContractMapper.insertBatchSomeColumn(data);
+            //如果失败  -- - - - - 继续执行   或者把当前节点的p_key_id 记录到某个地方 方便后续处理
+            if (i == 0) {
+                List<Long> collect1 = addData.stream().map(WbsTreeContract::getPKeyId).collect(Collectors.toList());
+                //这里可以保存到数据库指定错误日志表
+            }
+        }
+    }
+
+
+    /**
+     * 项目同步电签
+     *
+     * @param collect          需要修改的节点
+     * @param templateId       同步源项目ID
+     * @param projectId        当前项目ID
+     * @param editPrivateNodes 模板对应的节点
+     * @param editPrivateNodes 需要修改的节点
+     */
+    private void updateEViSa(Set<Integer> collect, Long templateId, Long projectId, List<WbsTreePrivate> treePrivates, List<WbsTreePrivate> editPrivateNodes) {
+
+        //判断 如果模板项目为公共项目  则无法同步电签
+        ProjectInfo projectInfo = projectInfoMapper.selectById(projectId);
+
+        if (projectInfo != null && ("private").equals(projectInfo.getReferenceWbsTemplateType()) && projectInfo.getReferenceWbsTemplateId() != null) {
+
+
+            //封装  源Pkeyid  修改pKeyId
+            Map<Long, Long> tempMap = new HashMap<>();
+
+            //模板的主键ids
+            List<Long> tempPKeyIds = new ArrayList<>();
+            List<Long> editPKeyIds = new ArrayList<>();
+
+
+            for (WbsTreePrivate tempPrivate : treePrivates) {
+                for (WbsTreePrivate editPrivate : editPrivateNodes) {
+                    if (Objects.equals(tempPrivate.getTreePId(), editPrivate.getTreePId())) {
+                        //封装  源Pkeyid  修改pKeyId
+                        tempMap.put(tempPrivate.getPKeyId(), editPrivate.getPKeyId());
+                        //记录
+                        tempPKeyIds.add(tempPrivate.getPKeyId());
+
+                        break;
+                    }
+                }
+
+            }
+
+            //源项目电签和默认值信息
+            List<TextdictInfo> tempTextDictInfo = textdictInfoMapper.selectList(Wrappers.<TextdictInfo>lambdaQuery()
+                    .eq(TextdictInfo::getProjectId, templateId)
+                    .eq(TextdictInfo::getIsDeleted, 0)
+                    .in(TextdictInfo::getTabId, tempPKeyIds)
+                    .in(TextdictInfo::getType, 2, 4, 6));
+            if (CollectionUtil.isEmpty(tempTextDictInfo)) {
+                throw new ServiceException("源数据无电签及默认值配置");
+            }
+            Map<Integer, List<TextdictInfo>> tempTextDictInfoMap = tempTextDictInfo.stream().collect(Collectors.groupingBy(TextdictInfo::getType));
+
+
+            List<TextdictInfo> tempViSa = new ArrayList<>();
+            //电签
+            if (collect.contains(3)) {
+                //个人电签
+                List<TextdictInfo> tempMyViSa = tempTextDictInfoMap.get(2);
+                if (CollectionUtil.isNotEmpty(tempMyViSa)) {
+                    tempViSa.addAll(tempMyViSa);
+
+                }
+                //企业电签
+                List<TextdictInfo> tempEnterViSa = tempTextDictInfoMap.get(6);
+                if (CollectionUtil.isNotEmpty(tempEnterViSa)) {
+                    tempViSa.addAll(tempEnterViSa);
+                }
+
+            }
+            //默认值
+            if (collect.contains(5)) {
+                List<TextdictInfo> tempDefault = tempTextDictInfoMap.get(4);
+                if (CollectionUtil.isNotEmpty(tempDefault)) {
+                    tempViSa.addAll(tempDefault);
+                }
+            }
+
+
+            List<TextdictInfo> addData = new ArrayList<>();
+            //新增电签
+            if (CollectionUtil.isNotEmpty(tempViSa)) {
+                for (TextdictInfo textdictInfo : tempViSa) {
+                    textdictInfo.setId(SnowFlakeUtil.getId());
+                    textdictInfo.setProjectId(String.valueOf(projectId));
+
+                    //根据源id找对应的修改pKid
+                    Long tabId = Long.valueOf(textdictInfo.getTabId());
+                    Long editId = tempMap.get(tabId);
+                    if (editId == null) {
+                        continue;
+                    }
+
+                    textdictInfo.setTabId(String.valueOf(editId));
+
+                    addData.add(textdictInfo);
+                }
+            }
+            if (CollectionUtil.isNotEmpty(addData)) {
+                //删除 需要新增的节点的电签和默认值
+                List<Long> editPrivateIds = editPrivateNodes.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
+                //调用其他类使事务生效
+                wbsSynchronousEViSaService.updateTextDictInfo(projectId, editPrivateIds, addData);
+            }
+        } else {
+            throw new ServiceException("模板为公共项目,无法同步电签");
+        }
+    }
+
+
+    /**
+     * 20250414-lhb-新增
+     * 创建祖级路径
+     * <p>
+     * 该方法用于构建给定节点的祖先路径标识符(PId)字符串
+     * 它通过追溯节点的父节点,直到达到根节点或满足特定条件为止
+     *
+     * @param node    WbsTreeContract类型的节点,表示需要构建路径的起始节点
+     * @param nodeMap 一个映射,其键为节点ID,值为WbsTreeContract类型的节点对象,用于快速查找节点
+     * @return 返回一个字符串,表示构建的祖先路径标识符序列,以逗号分隔
+     */
+    private String createAncestorsPId(WbsTreePrivate node, Map<Long, WbsTreePrivate> nodeMap) {
+        // 初始化路径列表,用于存储祖先节点的ID
+        List<Long> path = new ArrayList<>();
+        // 从给定的节点开始
+        WbsTreePrivate current = node;
+        // 初始化访问集合,用于检测循环引用
+        Set<Long> visited = new HashSet<>();
+
+        while (true) {
+            // 检查当前节点是否为根节点或无效节点
+            if (current == null || current.getPId() == null ||
+                    current.getPId() == 0 || current.getPId().equals(current.getPKeyId())) {
+                break;
+            }
+
+            // 检测循环引用
+            if (visited.contains(current.getPId())) {
+                break;
+            }
+            // 将当前节点的ID添加到已访问集合中
+            visited.add(current.getPKeyId());
+
+            // 从映射中获取当前节点的父节点
+            current = nodeMap.get(current.getPId());
+            // 如果父节点存在,则将其ID添加到路径列表的开头
+            if (current != null) {
+                path.add(0, current.getPKeyId());
+            }
+
+            // 安全限制,防止路径过长导致性能问题
+            if (path.size() > 50) {
+                break;
+            }
+        }
+        // 将根节点ID(0)添加到路径的最前面,表示路径的起点
+        path.add(0, 0L);
+        // 将路径列表转换为字符串并返回
+        return String.join(",", path.stream().map(String::valueOf).toArray(String[]::new));
+    }
+
+    /**
+     * 20250414-lhb-新增
+     * 创建祖级路径
+     * <p>
+     * 该方法用于构建给定节点的祖先路径标识符(PId)字符串
+     * 它通过追溯节点的父节点,直到达到根节点或满足特定条件为止
+     *
+     * @param node    WbsTreeContract类型的节点,表示需要构建路径的起始节点
+     * @param nodeMap 一个映射,其键为节点ID,值为WbsTreeContract类型的节点对象,用于快速查找节点
+     * @return 返回一个字符串,表示构建的祖先路径标识符序列,以逗号分隔
+     */
+    private String createAncestorsPId(WbsTreeContract node, Map<Long, WbsTreeContract> nodeMap) {
+        // 初始化路径列表,用于存储祖先节点的ID
+        List<Long> path = new ArrayList<>();
+        // 从给定的节点开始
+        WbsTreeContract current = node;
+        // 初始化访问集合,用于检测循环引用
+        Set<Long> visited = new HashSet<>();
+
+        while (true) {
+            // 检查当前节点是否为根节点或无效节点
+            if (current == null || current.getPId() == null ||
+                    current.getPId() == 0 || current.getPId().equals(current.getPKeyId())) {
+                break;
+            }
+
+            // 检测循环引用
+            if (visited.contains(current.getPId())) {
+                break;
+            }
+            // 将当前节点的ID添加到已访问集合中
+            visited.add(current.getPKeyId());
+
+            // 从映射中获取当前节点的父节点
+            current = nodeMap.get(current.getPId());
+            // 如果父节点存在,则将其ID添加到路径列表的开头
+            if (current != null) {
+                path.add(0, current.getPKeyId());
+            }
+
+            // 安全限制,防止路径过长导致性能问题
+            if (path.size() > 50) {
+                break;
+            }
+        }
+        // 将根节点ID(0)添加到路径的最前面,表示路径的起点
+        path.add(0, 0L);
+        // 将路径列表转换为字符串并返回
+        return String.join(",", path.stream().map(String::valueOf).toArray(String[]::new));
+    }
+
+
+    /**
+     * 获取指定节点的所有最新节点
+     */
+    public Set<Long> getMinNodes(WbsTreeSynchronousRecord record) {
+
+        Set<Long> collect = null;
+        try {
+
+
+            collect = new HashSet<>();
+            Integer range = record.getRange();
+            String nodeId = record.getNodeId();
+            if (range == 1) {
+                if (StringUtil.isNotBlank(record.getFormIds())) {
+                    List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                            .select(WbsTreePrivate::getPKeyId, WbsTreePrivate::getPId)
+                            .eq(WbsTreePrivate::getIsDeleted, 0)
+                            .eq(WbsTreePrivate::getType, 2)
+                            .eq(WbsTreePrivate::getProjectId, record.getProjectId())
+                            .in(WbsTreePrivate::getPKeyId, Func.toLongList(record.getFormIds())));
+                    collect = list.stream().map(WbsTreePrivate::getPId).collect(Collectors.toSet());
+                } else {
+
+                    Set<Long> split = Arrays.stream(nodeId.split(","))
+                            .map(Long::parseLong)
+                            .collect(Collectors.toSet());
+                    for (Long id : split) {
+                        List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                                .select(WbsTreePrivate::getPKeyId, WbsTreePrivate::getPId)
+                                .eq(WbsTreePrivate::getIsDeleted, 0)
+                                .eq(WbsTreePrivate::getType, 2)
+                                .apply("find_in_set({0},ancestors_p_id)", id));
+                        collect.addAll(wbsTreePrivates.stream().map(WbsTreePrivate::getPId).collect(Collectors.toSet()));
+                    }
+                }
+                return collect;
+            }
+            if (range == 2) {
+                if (StringUtil.isNotBlank(record.getFormIds())) {
+                    List<WbsTreeContract> list = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
+                            .select(WbsTreeContract::getPKeyId, WbsTreeContract::getPId)
+                            .eq(WbsTreeContract::getIsDeleted, 0)
+                            .eq(WbsTreeContract::getProjectId, record.getProjectId())
+                            .in(WbsTreeContract::getIsTypePrivatePid, Func.toLongList(record.getFormIds())));
+                    collect = list.stream().map(WbsTreeContract::getPId).collect(Collectors.toSet());
+                } else {
+
+                    List<WbsTreeContract> initNode = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
+                            .select(WbsTreeContract::getPKeyId, WbsTreeContract::getPId)
+                            .eq(WbsTreeContract::getIsDeleted, 0)
+                            .eq(WbsTreeContract::getProjectId, record.getProjectId())
+                            .in(WbsTreeContract::getIsTypePrivatePid, Func.toLongList(record.getNodeId())));
+
+                    for (WbsTreeContract wbsTreeContract : initNode) {
+                        List<WbsTreeContract> wbsTreeContracts = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
+                                .select(WbsTreeContract::getPKeyId, WbsTreeContract::getPId)
+                                .eq(WbsTreeContract::getIsDeleted, 0)
+                                .eq(WbsTreeContract::getType, 2)
+                                .eq(WbsTreeContract::getProjectId, record.getProjectId())
+                                .apply("find_in_set({0},ancestors_p_id)", wbsTreeContract.getPKeyId()));
+                        collect.addAll(wbsTreeContracts.stream().map(WbsTreeContract::getPId).collect(Collectors.toSet()));
+                    }
+                }
+            }
+        } catch (ServiceException e) {
+            throw new ServiceException(e.getMessage());
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new ServiceException("系统错误");
+        }
+        return collect;
+    }
+}

+ 216 - 101
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreePrivateServiceImpl.java

@@ -1536,125 +1536,204 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
         }
     }
 
-
-    public List<WbsTreePrivate> syncNodeTable(String primaryKeyId, String projectId) {
+    /**
+     * 多节点同步
+     *
+     * @param primaryKeyId
+     * @param projectId
+     * @return
+     */
+    public boolean syncNodeTable(String primaryKeyId, String projectId) {
 
         if (StringUtils.isNotEmpty(primaryKeyId)) {
             //获取当前节点对应节点信息
             WbsTreePrivate wbsTreePrivate = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, primaryKeyId));
 
-            //当前节点对应的模板节点信息
-            WbsTree wbsTreeTemplate = wbsTreeMapper.selectOne(Wrappers.<WbsTree>lambdaQuery()
-                    .eq(WbsTree::getId, wbsTreePrivate.getTreePId()));
-
             //获取项目信息
             ProjectInfo projectInfo = projectInfoMapper.selectOne(Wrappers.<ProjectInfo>lambdaQuery().eq(ProjectInfo::getId, wbsTreePrivate.getProjectId()));
 
+            //当前项目模板对应的节点信息
+
+            List<WbsTreePrivate> templateNodes = new ArrayList<>();
+
             //结果集
             List<WbsTreePrivate> addData = new ArrayList<>();
+            List<WbsTreePrivate> editData = new ArrayList<>();
             //质检
-            if (("1").equals(wbsTreePrivate.getWbsType())) {
-                //当前节点引用的模板为公有模板
-                if (("public").equals(projectInfo.getReferenceWbsTemplateType())) {
-
-                    //模板节点的所有子节点信息
-                    List<WbsTree> wbsTrees = null;
-                    //当前节点信息
-                    List<WbsTreePrivate> wbsTreePrivates = null;
-                    //判断是否为最顶级节点
-                    if (wbsTreeTemplate.getParentId() == 0) {
-                        //如果时最顶级节点  就获取所有节点信息
-                        wbsTrees = wbsTreeMapper.selectList(Wrappers.<WbsTree>lambdaQuery()
-                                .eq(WbsTree::getWbsId, wbsTreePrivate.getWbsId())
-                                .eq(WbsTree::getIsDeleted, 0));
-                    } else {
-                        //获取列明
-                        String fieldName = LambdaUtil.getFieldName(WbsTree::getAncestors);
-                        wbsTrees = wbsTreeMapper.selectList(Wrappers.<WbsTree>lambdaQuery()
-                                .eq(WbsTree::getIsDeleted, 0)
-                                .apply("FIND_IN_SET({0}," + fieldName + ")", wbsTreeTemplate.getId()));
-                    }
+            //当前节点引用的模板为公有模板
 
+            if (("public").equals(projectInfo.getReferenceWbsTemplateType())) {
+                //当前节点对应的模板节点信息
+                WbsTree wbsTreeTemplate = wbsTreeMapper.selectOne(Wrappers.<WbsTree>lambdaQuery()
+                        .eq(WbsTree::getId, wbsTreePrivate.getTreePId()));
 
-                    //2、获取当前节点下的节点信息
-                    if (wbsTreePrivate.getTreePId() == 0) {
-                        wbsTreePrivates = baseMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
-                                .eq(WbsTreePrivate::getWbsId, wbsTreePrivate.getWbsId())
-                                .eq(WbsTreePrivate::getIsDeleted, 0));
-                    } else {
-                        //获取列明
-                        wbsTreePrivates = baseMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
-                                .eq(WbsTreePrivate::getIsDeleted, 0)
-                                .apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivate.getPId()));
-                    }
+                //模板节点的所有子节点信息
+                List<WbsTree> wbsTrees = null;
+                //当前节点信息
 
-                    if (wbsTreePrivates.isEmpty()) {
-                        throw new ServiceException("无法找到模板对应节点,请检查模板节点");
-                    }
-                    //3、获取需要新增的节点或者表单节点信息 以及他们对应的父级节点信息
+                //获取模板中当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
+                LambdaQueryWrapper<WbsTree> wrapperTree = Wrappers.lambdaQuery();
+                wrapperTree.eq(WbsTree::getWbsId, wbsTreePrivate.getWbsId())
+                        .eq(WbsTree::getIsDeleted, 0);
+                if (wbsTreeTemplate.getParentId() != 0) {
+                    wrapperTree.apply("FIND_IN_SET({0},ancestors)", wbsTreeTemplate.getId());
+                }
+                wbsTrees = wbsTreeMapper.selectList(wrapperTree);
+                //3、获取需要新增的节点或者表单节点信息 以及他们对应的父级节点信息--------------------------------------------------------------------------------------------
+                if (CollectionUtil.isEmpty(wbsTrees)) {
+                    throw new ServiceException("模板节点未找到");
+                }
+                wbsTrees.add(wbsTreeTemplate);
+                templateNodes = BeanUtil.copyProperties(wbsTrees, WbsTreePrivate.class);
 
 
-                    //获取id 和 tree_p_id 组成的集合
-                    Set<Long> ids = wbsTreePrivates.stream()
-                            .flatMap(p -> Stream.of(p.getId(), p.getTreePId()))
-                            .collect(Collectors.toSet());
+            } else if (("private").equals(projectInfo.getReferenceWbsTemplateType())) {
+                //根据wbsTreePrivate的wbsId=私有引用的pKeyId来获取引用树根节点
+                WbsTreePrivate wbsTreePrivateRoot = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
+                        .eq(WbsTreePrivate::getPKeyId, wbsTreePrivate.getWbsId()));
+
+                //获取当前选中节点与私有模板对应的节点信息 父级模板项目的当前选中节点
+                wbsTreePrivateRoot = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
+                        .eq(WbsTreePrivate::getProjectId, wbsTreePrivateRoot.getProjectId())
+                        .eq(WbsTreePrivate::getTreePId, wbsTreePrivate.getTreePId()));
+
+                //获取模板中当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
+                LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
+                wrapperPrivate.eq(WbsTreePrivate::getProjectId, wbsTreePrivateRoot.getProjectId())
+                        .eq(WbsTreePrivate::getIsDeleted, 0);
+                //判断如果为顶级顶级节点
+                if (wbsTreePrivate.getTreePId() != 0) {
+                    wrapperPrivate.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivateRoot.getPKeyId());
+                }
+                templateNodes = baseMapper.selectList(wrapperPrivate);
+                templateNodes.add(wbsTreePrivate);
+            }
+
+            if (CollectionUtil.isEmpty(templateNodes)) {
+                throw new ServiceException("未找到模板对应节点");
+            }
 
 
-                    //3.1筛选出需要新增的节点
-                    List<WbsTree> addNodes = wbsTrees.stream()
-                            .filter(f -> !ids.contains(f.getId()))
-                            .collect(Collectors.toList());
+            //2、获取当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
+            LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
+            wrapperPrivate.eq(WbsTreePrivate::getWbsId, wbsTreePrivate.getWbsId()).eq(WbsTreePrivate::getIsDeleted, 0);
+            //判断如果为顶级顶级节点
+            if (wbsTreePrivate.getTreePId() != 0) {
+                wrapperPrivate.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivate.getPKeyId());
+            }
+            List<WbsTreePrivate> wbsTreePrivates = baseMapper.selectList(wrapperPrivate);
+            wbsTreePrivates.add(wbsTreePrivate);
+            if (wbsTreePrivates.isEmpty()) {
+                throw new ServiceException("无法找到模板对应节点,请检查模板节点");
+            }
+            //获取id 和 tree_p_id 组成的集合
+            Set<Long> ids = wbsTreePrivates.stream().map(WbsTreePrivate::getTreePId).collect(Collectors.toSet());
+            //3.1筛选出需要新增的节点
+            List<WbsTreePrivate> addPrivateNodes = templateNodes.stream()
+                    .filter(f -> !ids.contains(f.getId()))
+                    .collect(Collectors.toList());
 
-                    //将要新增的项目节点
-                    List<WbsTreePrivate> addPrivateNodes = BeanUtil.copyProperties(addNodes, WbsTreePrivate.class);
+            //3.2筛选出需要修改的节点
+            List<WbsTreePrivate> editPrivateNodes = templateNodes.stream()
+                    .filter(f -> ids.contains(f.getId()))
+                    .collect(Collectors.toList());
 
 
-                    //先给每个新增节点赋唯一id,项目id,父级id
-                    addPrivateNodes.forEach(f -> f.setPKeyId(SnowFlakeUtil.getId()));
+            //------------------------------------------------新增-------------------------------------------------------------------------
+            if (CollectionUtil.isNotEmpty(addPrivateNodes)) {
+                //将要新增的项目节点----------------------------------------------------------------------------------------------------
 
+                //先给每个新增节点赋唯一id,项目id,父级id
+                addPrivateNodes.forEach(f -> f.setPKeyId(SnowFlakeUtil.getId()));
 
-                    for (WbsTreePrivate addPrivateNode : addPrivateNodes) {
-                        if (addPrivateNode.getParentId() == 0) {
-                            continue;
-                        }
+                //给每一个节点的父级id
+                for (WbsTreePrivate addPrivateNode : addPrivateNodes) {
+                    if (addPrivateNode.getParentId() == 0) {
+                        continue;
+                    }
 
-                        //查询出当前模板节点的父节点 去获取对应项目节点  如果父节点为0就跳过
-                        List<WbsTreePrivate> addPrivateParentNodes = wbsTreePrivates.stream().filter(f -> f.getId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
-                        //如果没有数据  就表示这条数据的父节点也时新增节点 就需要从新增节点集合中找父级节点
-                        if (addPrivateParentNodes.isEmpty()) {
-                            addPrivateParentNodes = addPrivateNodes.stream().filter(f -> f.getId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
-                        }
-                        //如果现在还找不到当前节点的父节点就表示数据有问题
-                        if (addPrivateParentNodes.isEmpty()) {
-                            //TODO
-                            continue;
-                        }
+                    //查询出当前模板节点的父节点 去获取对应项目节点  如果父节点为0就跳过
+                    List<WbsTreePrivate> addPrivateParentNodes = wbsTreePrivates.stream().filter(f -> f.getTreePId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
+                    //如果没有数据  就表示这条数据的父节点也时新增节点 就需要从新增节点集合中找父级节点
+                    if (addPrivateParentNodes.isEmpty()) {
+                        addPrivateParentNodes = addPrivateNodes.stream().filter(f -> f.getId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
+                    }
+                    //如果现在还找不到当前节点的父节点就表示数据有问题
+                    if (addPrivateParentNodes.isEmpty()) {
+                        //TODO
+                        continue;
+                    }
+                    //当前新增节点的父节点
+                    WbsTreePrivate parent = addPrivateParentNodes.get(0);
+
+                    addPrivateNode.setPId(parent.getPKeyId());
+                    addPrivateNode.setWbsType(wbsTreePrivate.getWbsType());
+                    addPrivateNode.setIsAddConceal(0);
+                    addPrivateNode.setProjectId(wbsTreePrivate.getProjectId());
+                    //TODO 后续如果把p_key_id改成了id做 唯一id
+                    addPrivateNode.setTreePId(addPrivateNode.getId());
+                    //后续如果使用id做当前表主键 则先在赋值treePid之后再去赋值id    addPrivateNode.setId(SnowFlakeUtil.getId());
+                }
+                addData.addAll(addPrivateNodes);
+            }
+
+            //------------------------------------------------编辑-------------------------------------------------------------------------
+            /**
+             * 编辑情况下
+             *  type == 1 修改基础信息
+             *  type == 2
+             */
+            if (CollectionUtil.isNotEmpty(editPrivateNodes)) {
+                Map<Long, WbsTreePrivate> editMap = wbsTreePrivates.stream().collect(Collectors.toMap(WbsTreePrivate::getId, Function.identity()));
+                for (WbsTreePrivate editNode : editPrivateNodes) {
+                    //获取旧节点
+                    WbsTreePrivate oldNode = editMap.get(editNode.getId());
+                    //
+                    if (oldNode == null) {
+                        throw new ServiceException("数据问题");
+                    }
+
+                    oldNode.setNodeType(editNode.getNodeType());
+                    oldNode.setNodeName(editNode.getNodeName());
+                    oldNode.setSort(editNode.getSort());
+                    oldNode.setRemark(editNode.getRemark());
+                    oldNode.setInitTableId(editNode.getInitTableId());
+                    oldNode.setExcelId(editNode.getExcelId());
+                    oldNode.setIsExistForm(editNode.getIsExistForm());
+                    oldNode.setHtmlUrl(editNode.getHtmlUrl());
+                    oldNode.setFillRate(editNode.getFillRate());
+
+
+                    //普通节点
+                    if (editNode.getType() == 1) {
+                        //判断是否被修改过
 
-                        WbsTreePrivate parent = addPrivateParentNodes.get(0);
-                        addPrivateNode.setPId(parent.getPKeyId());
-                        addPrivateNode.setIsAddConceal(0);
-                        addPrivateNode.setProjectId(wbsTreePrivate.getProjectId());
-                        //TODO 后续如果把p_key_id改成了id做 唯一id
-                        addPrivateNode.setTreePId(addPrivateNode.getId());
 
                     }
-                    addData.addAll(addPrivateNodes);
+                    //元素表单节点
+                    if (editNode.getType() == 2) {
+                        //判断是否关联过清表
+                        if(oldNode.getIsLinkTable() == 2){
+
+                        }
+
+                    }
+                    //是否需要编辑元素表单数据???
+                    editData.add(oldNode);
                 }
             }
 
 
-            //通过递归的方式去获取祖级路径
-
-            if (addData.isEmpty()) {
-                return null;
-            } else {
+            //设置html_url----------------------------------------------------------------------------------------------------------
+            //如果有新增的数据 旧设置html_url
+            if (CollectionUtil.isNotEmpty(addData)) {
                 try {
                     String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
                     Set<String> urls = new HashSet<>();
                     for (WbsTreePrivate tree : addData) {
                         if (org.apache.commons.lang3.StringUtils.isNotBlank(tree.getHtmlUrl())) {
                             String[] split = tree.getHtmlUrl().split("/");
-                            String htmlUrl = file_path + "privateUrlCopy/" + tree.getPdfUrl() + "/" + split[split.length - 1];
+                            String htmlUrl = file_path + "privateUrlCopy/" + projectInfo.getId() + "/" + split[split.length - 1];
                             if (!urls.contains(tree.getHtmlUrl())) {
                                 urls.add(tree.getHtmlUrl());
                                 File file_in = ResourceUtil.getFile(tree.getHtmlUrl());
@@ -1670,32 +1749,68 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
                 } catch (Exception e) {
                     throw new ServiceException("重置表单路径错误");
                 }
-            }
-
+                //查询出当前项目所有节点---------------------------------------------------------------------------------------------------
+                List<WbsTreePrivate> addList = baseMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                        .eq(WbsTreePrivate::getIsDeleted, 0)
+                        .eq(WbsTreePrivate::getProjectId, wbsTreePrivate.getProjectId()));
 
-            //查询出当前项目所有节点
-            List<WbsTreePrivate> addList = baseMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
-                    .eq(WbsTreePrivate::getIsDeleted, 0)
-                    .eq(WbsTreePrivate::getProjectId, wbsTreePrivate.getProjectId()));
+                addList.addAll(addData);
+                //组合祖级路径 根据当前选中节点为开始
+                Map<Long, WbsTreePrivate> collect = addList.stream().collect(Collectors.toMap(WbsTreePrivate::getPKeyId, Function.identity()));
 
-            addList.addAll(addData);
-            //组合祖级路径 根据当前选中节点为开始
-            Map<Long, WbsTreePrivate> collect = addList.stream().collect(Collectors.toMap(WbsTreePrivate::getPKeyId, Function.identity()));
+                addData.forEach(node -> {
+                    String correctAncestors = createAncestorsPId(node, collect);
+                    node.setAncestorsPId(correctAncestors);
+                });
 
-            addData.forEach(node -> {
-                String correctAncestors = createAncestorsPId(node, collect);
-                node.setAncestorsPId(correctAncestors);
-            });
+                //新增-----------------------------------------------------------------------------------------------------------------
+                List<List<WbsTreePrivate>> partition = Lists.partition(addData, 1000);
+                for (List<WbsTreePrivate> data : partition) {
+                    //单个批次一个事务,只会回滚当前批次数据
+                    boolean b = this.insertBatch(data, 1000);
+                    //如果失败  -- - - - - 继续执行   或者把当前节点的p_key_id 记录到某个地方 方便后续处理
+                    if (!b) {
+                        List<Long> collect1 = addData.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
+                        //这里可以保存到数据库指定错误日志表
+
+                        throw new ServiceException("新增节点失败,请联系后台人员");
+                    }
+                }
+            } else if (CollectionUtil.isNotEmpty(editData)) {
+
+                //修改-----------------------------------------------------------------------------------------------------------------
+                List<List<WbsTreePrivate>> edits = Lists.partition(editData, 1000);
+                for (List<WbsTreePrivate> data : edits) {
+                    //单个批次一个事务,只会回滚当前批次数据
+                    boolean b = this.saveOrUpdateBatch(data, 1000);
+                    //如果失败  -- - - - - 继续执行   或者把当前节点的p_key_id 记录到某个地方 方便后续处理
+                    if (!b) {
+                        //这里可以保存到数据库指定错误日志表
+                        throw new ServiceException("修改节点失败,请联系后台人员");
+                    }
+                }
+            }
+            return true;
+        } else {
+            throw new ServiceException("未传指定参数,请联系后台人员");
+        }
+    }
 
+    /**
+     * 同步指定节点数据到合同段
+     */
+    public void syncNodeTable(Long primaryKeyId) {
+        //1、新增
+        //2、修改排序、基础信息和地址
+        if (primaryKeyId == null) {
+            //获取当前节点对应节点信息
+            WbsTreePrivate wbsTreePrivate = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, primaryKeyId));
 
-            List<List<WbsTreePrivate>> partition = Lists.partition(addData, 1000);
-            for (List<WbsTreePrivate> wbsTreePrivates : partition) {
-                this.insertBatch(wbsTreePrivates, 1000);
-            }
 
-            return addData;
         }
-        return null;
+
+        //获取当前节点下的数据
+
     }
 
 

+ 265 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeSynchronousRecordServiceImpl.java

@@ -0,0 +1,265 @@
+package org.springblade.manager.service.impl;
+
+import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.redisson.api.RedissonClient;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.secure.utils.SecureUtil;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.manager.entity.*;
+import org.springblade.manager.mapper.*;
+import org.springblade.manager.service.WbsTreeSynchronousRecordService;
+import org.springblade.manager.vo.WbsTreeSynchronousRecordVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author LHB
+ * @description 针对表【m_wbs_tree_synchronous_record(WBS同步记录表)】的数据库操作Service实现
+ * @createDate 2025-05-15 13:52:09
+ */
+@Service
+public class WbsTreeSynchronousRecordServiceImpl extends ServiceImpl<WbsTreeSynchronousRecordMapper, WbsTreeSynchronousRecord>
+        implements WbsTreeSynchronousRecordService {
+
+    @Autowired
+    private WbsTreePrivateMapper wbsTreePrivateMapper;
+
+    @Autowired
+    private WbsSynchronousServiceImpl wbsSynchronousService;
+
+    @Autowired
+    private WbsTreeMapper wbsTreeMapper;
+    @Autowired
+    private ProjectInfoMapper projectInfoMapper;
+    @Autowired
+    private WbsInfoMapper wbsInfoMapper;
+
+    @Override
+    public WbsTreeSynchronousRecord insert(WbsTreeSynchronousRecord mWbsTreeSynchronousRecord) {
+        //新增之前  判断当前选中节点是否在同步列表中,因为是多节点 所有要查询所有同项目下的同步节点再获取所有子节点 判断当前选中节点是否在这一批次当中
+        List<WbsTreeSynchronousRecord> wbsTreeSynchronousRecords = baseMapper.selectList(new QueryWrapper<WbsTreeSynchronousRecord>().lambda()
+                .select(WbsTreeSynchronousRecord::getNodeId)
+                .eq(WbsTreeSynchronousRecord::getProjectId, mWbsTreeSynchronousRecord.getProjectId())
+                .eq(WbsTreeSynchronousRecord::getIsDeleted, 0)
+                .in(WbsTreeSynchronousRecord::getStatus, 0, 1));
+        List<String> nodeIds = wbsTreeSynchronousRecords.stream().map(WbsTreeSynchronousRecord::getNodeId).collect(Collectors.toList());
+
+        //所有子节点集合
+        List<Long> privateIds = new ArrayList<>();
+        //通过 ancestors_p_id 查询所有 非表单子节点
+        for (String nodeId : nodeIds) {
+            String[] split = nodeId.split(",");
+            for (String s : split) {
+                List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(new QueryWrapper<WbsTreePrivate>().lambda()
+                        .select(WbsTreePrivate::getPKeyId)
+                        .eq(WbsTreePrivate::getIsDeleted, 0)
+                        .apply("find_in_set({0},ancestors_p_id)", s)
+                );
+                privateIds.add(Long.valueOf(s));
+                privateIds.addAll(wbsTreePrivates.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList()));
+
+
+                //  //判断节点类型  如果是试验或计量则不允许添加合同合同段
+                WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(nodeId);
+                if (mWbsTreeSynchronousRecord.getRange() == 2 && wbsTreePrivate != null && !Objects.equals(wbsTreePrivate.getWbsType(), 1)) {
+                    throw new ServiceException(wbsTreePrivate.getNodeName() + " 节点不是质检类型,无法同步合同段");
+                }
+            }
+        }
+
+
+        //记录选中节点下的表单数
+        String[] newNodeIds = mWbsTreeSynchronousRecord.getNodeId().split(",");
+        for (String newNodeId : newNodeIds) {
+            Long nodeIdLong = Long.valueOf(newNodeId);
+            if (privateIds.contains(nodeIdLong)) {
+                throw new ServiceException("当前选中节点正在同步,请勿重复同步");
+            }
+        }
+
+        //模板项目信息
+        ProjectInfo tempProject = projectInfoMapper.selectOne(Wrappers.<ProjectInfo>lambdaQuery()
+                .eq(ProjectInfo::getId, mWbsTreeSynchronousRecord.getTemplateId()));
+        //当前项目绑定的是公有模板还是私有项目
+        if (mWbsTreeSynchronousRecord.getRange() == 1 && tempProject == null && (
+                mWbsTreeSynchronousRecord.getType().contains("2") ||
+                        mWbsTreeSynchronousRecord.getType().contains("3") ||
+                        mWbsTreeSynchronousRecord.getType().contains("4") ||
+                        mWbsTreeSynchronousRecord.getType().contains("5") ||
+                        mWbsTreeSynchronousRecord.getType().contains("6"))) {
+            throw new ServiceException("模板为公共模板,无法选择");
+        }
+
+
+        //获取项目名称
+        ProjectInfo projectInfo = projectInfoMapper.selectById(mWbsTreeSynchronousRecord.getProjectId());
+        if (projectInfo == null) {
+            throw new ServiceException("项目不存在");
+        }
+        mWbsTreeSynchronousRecord.setId(SnowFlakeUtil.getId());
+        mWbsTreeSynchronousRecord.setProjectName(projectInfo.getProjectName());
+
+        if (mWbsTreeSynchronousRecord.getRange() == 1 || mWbsTreeSynchronousRecord.getRange() == 2) {
+            Set<Long> minNodes = wbsSynchronousService.getMinNodes(mWbsTreeSynchronousRecord);
+            mWbsTreeSynchronousRecord.setNodeNum(minNodes.size());
+        }
+        //类型为3 、 4
+        if (mWbsTreeSynchronousRecord.getRange() == 3) {
+            mWbsTreeSynchronousRecord.setRangeName("单表单同步");
+            mWbsTreeSynchronousRecord.setNodeNum(1);
+        }
+        if (mWbsTreeSynchronousRecord.getRange() == 4) {
+            mWbsTreeSynchronousRecord.setRangeName("单表强制同步");
+            mWbsTreeSynchronousRecord.setNodeNum(1);
+            if (StringUtil.isBlank(mWbsTreeSynchronousRecord.getFormIds())) {
+                throw new ServiceException("请选择表单");
+            }
+        }
+        mWbsTreeSynchronousRecord.setNodeNumEnd(0);
+        List<Long> collect = Arrays.stream(mWbsTreeSynchronousRecord.getNodeId().split(",")).map(Long::parseLong).collect(Collectors.toList());
+        //节点名称
+        List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                .select(WbsTreePrivate::getPKeyId, WbsTreePrivate::getNodeName)
+                .in(WbsTreePrivate::getPKeyId, collect));
+        List<String> nodeNames = list.stream().map(WbsTreePrivate::getNodeName).collect(Collectors.toList());
+        mWbsTreeSynchronousRecord.setNodeName(String.join(",", nodeNames));
+
+        //获取当前用户
+        BladeUser user = SecureUtil.getUser();
+        mWbsTreeSynchronousRecord.setCreateUserId(user.getUserId());
+        mWbsTreeSynchronousRecord.setCreateUser(user.getNickName());
+        //新增
+        baseMapper.insert(mWbsTreeSynchronousRecord);
+
+        return mWbsTreeSynchronousRecord;
+    }
+
+    @Override
+    public WbsTreeSynchronousRecord getNodeStatus(Long id) {
+        WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(id);
+        if (wbsTreePrivate == null) {
+            throw new ServiceException("节点不存在");
+        }
+
+
+        //新增之前  判断当前选中节点是否在同步列表中,因为是多节点 所有要查询所有同项目下的同步节点再获取所有子节点 判断当前选中节点是否在这一批次当中
+        List<WbsTreeSynchronousRecord> wbsTreeSynchronousRecords = baseMapper.selectList(new QueryWrapper<WbsTreeSynchronousRecord>().lambda()
+                .eq(WbsTreeSynchronousRecord::getProjectId, wbsTreePrivate.getProjectId())
+                .eq(WbsTreeSynchronousRecord::getIsDeleted, 0)
+                .in(WbsTreeSynchronousRecord::getStatus, 0, 1));
+        for (WbsTreeSynchronousRecord wbsTreeSynchronousRecord : wbsTreeSynchronousRecords) {
+
+
+            List<Long> privateIds = new ArrayList<>();
+
+            String nodeId = wbsTreeSynchronousRecord.getNodeId();
+            String[] split = nodeId.split(",");
+            for (String s : split) {
+                List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(new QueryWrapper<WbsTreePrivate>().lambda()
+                        .select(WbsTreePrivate::getPKeyId)
+                        .eq(WbsTreePrivate::getIsDeleted, 0)
+                        .apply("find_in_set({0},ancestors_p_id)", s)
+                );
+                privateIds.add(Long.valueOf(s));
+                privateIds.addAll(wbsTreePrivates.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList()));
+            }
+            if (privateIds.size() > 0 && privateIds.contains(id)) {
+                return wbsTreeSynchronousRecord;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public List<WbsTreeSynchronousRecordVo> getProjectTemplate(String nodeIds) {
+
+        String nodeId = nodeIds.split(",")[0];
+        //选中节点
+        WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(nodeId);
+        List<WbsTreeSynchronousRecordVo> returnData = new ArrayList<>();
+        //获取当前项目的初始节点
+        WbsTreePrivate start = wbsTreePrivateMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
+                .eq(WbsTreePrivate::getProjectId, wbsTreePrivate.getProjectId())
+                .eq(WbsTreePrivate::getParentId, 0)
+                .last("limit 1")
+        );
+        //私有项目
+        List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                .eq(WbsTreePrivate::getTreePId, start.getTreePId()));
+        for (WbsTreePrivate treePrivate : list) {
+            //过滤当前项目
+            if (Objects.equals(treePrivate.getProjectId(), wbsTreePrivate.getProjectId())) {
+                continue;
+            }
+
+            ProjectInfo projectInfo2 = projectInfoMapper.selectById(treePrivate.getProjectId());
+            if (projectInfo2 == null) {
+                continue;
+            }
+            WbsTreeSynchronousRecordVo wbsTreeSynchronousRecordVo = new WbsTreeSynchronousRecordVo();
+            wbsTreeSynchronousRecordVo.setId(projectInfo2.getId());
+            wbsTreeSynchronousRecordVo.setName(projectInfo2.getProjectName());
+            wbsTreeSynchronousRecordVo.setType(2);
+            wbsTreeSynchronousRecordVo.setWbsId(wbsTreePrivate.getWbsId());
+            returnData.add(wbsTreeSynchronousRecordVo);
+        }
+        //公共项目
+        WbsTree wbsTree = wbsTreeMapper.selectById(start.getId());
+        WbsInfo wbsInfo = wbsInfoMapper.selectById(wbsTree.getWbsId());
+        WbsTreeSynchronousRecordVo wbsTreeSynchronousRecordVo = new WbsTreeSynchronousRecordVo();
+        wbsTreeSynchronousRecordVo.setId(Long.valueOf(nodeId));
+        wbsTreeSynchronousRecordVo.setName(wbsInfo.getWbsName());
+        wbsTreeSynchronousRecordVo.setType(1);
+        returnData.add(wbsTreeSynchronousRecordVo);
+
+        return returnData;
+    }
+
+    /**
+     * 同步节点表单
+     * 定时检查同步任务,状态为1的数据如果最后更新时间与当前时间超过10分钟,则修改状态为1
+     */
+    @Scheduled(fixedDelay = 10000)
+    public void syncInit() {
+        List<WbsTreeSynchronousRecord> wbsTreeSynchronousRecords = baseMapper.selectList(new QueryWrapper<WbsTreeSynchronousRecord>().lambda()
+                .in(WbsTreeSynchronousRecord::getStatus, 0, 1)
+                .eq(WbsTreeSynchronousRecord::getIsDeleted, 0)
+                .orderByAsc(WbsTreeSynchronousRecord::getCreateTime)
+                .last("limit 10")
+        );
+
+        for (WbsTreeSynchronousRecord wbsTreeSynchronousRecord : wbsTreeSynchronousRecords) {
+            if (wbsTreeSynchronousRecord.getStatus() == 1) {
+                if (wbsTreeSynchronousRecord.getUpdateTime().getTime() + 600000 < System.currentTimeMillis()) {
+                    baseMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                            .set(WbsTreeSynchronousRecord::getStatus, 0)
+                            .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
+                }
+                continue;
+            }
+
+            //通过线程池执行同步任务
+            wbsSynchronousService.syncExecute(wbsTreeSynchronousRecord);
+
+            //修改数据状态为正在同步
+            baseMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                    .set(WbsTreeSynchronousRecord::getStatus, 1)
+                    .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                    .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
+        }
+    }
+}
+
+
+
+