Browse Source

清表关联wbs元素表相关

liuyc 3 years ago
parent
commit
db0756b80d

+ 18 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/dto/FormElementDTO2.java

@@ -73,6 +73,24 @@ public class FormElementDTO2 extends WbsTree {
     @ApiModelProperty(value = "元素表ids")
     private List<String> tableIds;
 
+    /**
+     * 节点ids
+     */
+    @ApiModelProperty(value = "节点ids")
+    private List<String> nodeIds;
+
+    /**
+     * 清表id
+     */
+    @ApiModelProperty(value = "清表id")
+    private Long excelTabId;
+
+    /**
+     * 提交状态 1=关联 2=新增
+     */
+    @ApiModelProperty(value = "提交状态 1=关联同步元素 2=新增")
+    private Integer submitStatus;
+
 
 
 }

+ 15 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTabRelationExcelTab.java

@@ -0,0 +1,15 @@
+package org.springblade.manager.entity;
+
+import lombok.Data;
+import java.io.Serializable;
+
+@Data
+public class WbsTabRelationExcelTab implements Serializable {
+
+    private Long id;
+
+    private Long excelTabId;
+
+    private Long wbsTabId;
+
+}

+ 33 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsFormElementController.java

@@ -33,6 +33,7 @@ import org.springblade.manager.entity.WbsFormElement;
 import org.springblade.manager.excel.*;
 import org.springblade.manager.vo.WbsFormElementVO;
 import org.springblade.manager.vo.WbsFormElementVO2;
+import org.springblade.manager.vo.WbsNodeTableVO;
 import org.springblade.manager.wrapper.WbsFormElementWrapper;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -218,13 +219,42 @@ public class WbsFormElementController extends BladeController {
      * 元素识别取消关联公有wbs表
      */
     @ApiOperationSupport(order = 10)
-    @ApiOperation(value = "元素识别取消关联公有wbs表", notes = "传入表id")
+    @ApiOperation(value = "元素识别取消关联公有wbs表", notes = "传入表id、清表id")
     @RequestMapping(value = "/cancelRelation", method = RequestMethod.GET)
-    public R cancelRelation(String id) {
-        if (wbsFormElementService.cancelRelation(id)) {
+    public R cancelRelation(String id,String excelTabId) {
+        if (wbsFormElementService.cancelRelation(id,excelTabId)) {
             return R.success("取消成功");
         }
         return R.fail(200, "操作失败");
     }
 
+    /**
+     * 元素识别关联公共WBS模板-查询节点下已关联的所有表单
+     */
+    @ApiOperationSupport(order = 11)
+    @ApiOperation(value = "元素识别关联公共WBS模板-查询节点下已关联的所有表单", notes = "传入节点id、清表id")
+    @RequestMapping(value = "/searchNodeTables", method = RequestMethod.GET)
+    public R<List<WbsNodeTableVO>> searchNodeTables(String nodeId, String excelTabId) {
+        List<WbsNodeTableVO> list = wbsFormElementService.searchNodeTables(nodeId,excelTabId);
+        if (list.size() > 0) {
+            return R.data(list, "查询成功");
+        }
+        return R.fail(200, "操作失败");
+    }
+
+    /**
+     * 元素识别关联公共WBS模板-关联Wbs元素表
+     */
+    @ApiOperationSupport(order = 12)
+    @ApiOperation(value = "元素识别关联公共WBS模板-关联Wbs元素表", notes = "传入FormElementDTO2")
+    @RequestMapping(value = "/saveRelation", method = RequestMethod.POST)
+    public R relationWbsTab(@RequestBody FormElementDTO2 formElementDTO) {
+        boolean b = wbsFormElementService.saveRelation(formElementDTO);
+        if (b) {
+            return R.data("关联成功");
+        }
+        return R.fail(200, "关联失败");
+    }
+
+
 }

+ 7 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsFormElementMapper.java

@@ -23,6 +23,7 @@ import org.apache.ibatis.annotations.Param;
 import org.springblade.manager.dto.WbsFormElementDTO;
 import org.springblade.manager.dto.WbsFormElementDTO2;
 import org.springblade.manager.entity.WbsFormElement;
+import org.springblade.manager.entity.WbsTabRelationExcelTab;
 import org.springblade.manager.entity.WbsTree;
 import org.springblade.manager.vo.WbsFormElementVO;
 
@@ -58,4 +59,10 @@ public interface WbsFormElementMapper extends BaseMapper<WbsFormElement> {
 
     void addTableFiled(String initTableName, String eKey, String initTableFiledType, Integer elementLength);
 
+    void insertWbsTabRelationExcelTab(Long id, Long excelTabId, Long wbsTabId);
+
+    Integer deleteWbsTabRelationExcelTab(String id, String excelId);
+
+    List<WbsTabRelationExcelTab> selectWbsTabRelationExcelTab(String id, String excelId);
+
 }

+ 54 - 22
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsFormElementMapper.xml

@@ -22,21 +22,28 @@
         <result column="remark" property="remark"/>
     </resultMap>
 
+    <insert id="insertWbsTabRelationExcelTab">
+        INSERT INTO m_wbs_tab_relation_excel_tab (id, excel_tab_id, wbs_tab_id)
+        VALUES (#{id}, #{excelTabId}, #{wbsTabId})
+    </insert>
+
     <update id="addTableFiled">
-        alter table ${initTableName} add ${eKey} ${initTableFiledType}(${elementLength})
+        alter table ${initTableName}
+            add ${eKey} ${initTableFiledType}(${elementLength})
     </update>
 
     <update id="createTable">
-        create table ${newTableName} (
-        `id` bigint(20) NOT NULL COMMENT '主键id',
-        `p_key_id` bigint(20) COMMENT '合同段wbs树表单的p_key_id',
-        `group_id` bigint(20) COMMENT '分组id',
-         ${sqlStr}
-         PRIMARY KEY (`id`) USING BTREE
+        create table ${newTableName}
+        (
+            `id`       bigint(20) NOT NULL COMMENT '主键id',
+            `p_key_id` bigint(20) COMMENT '合同段wbs树表单的p_key_id',
+            `group_id` bigint(20) COMMENT '分组id',
+            ${sqlStr} PRIMARY KEY (`id`) USING BTREE
         ) ENGINE=InnoDB DEFAULT CHARSET=utf8
     </update>
     <update id="alterAddFiled">
-        alter table ${tableName} add ${sqlStr}
+        alter table ${tableName}
+            add ${sqlStr}
     </update>
 
     <update id="deleteTableFiled">
@@ -51,38 +58,63 @@
         UPDATE m_wbs_tree
         SET sort = #{sort}
         WHERE id = #{id}
-        AND type = 2
-        AND status = 1
-        AND is_deleted = 0
+          AND type = 2
+          AND status = 1
+          AND is_deleted = 0
     </update>
 
+    <delete id="deleteWbsTabRelationExcelTab">
+        DELETE
+        FROM m_wbs_tab_relation_excel_tab
+        WHERE excel_tab_id = #{excelId}
+          AND wbs_tab_id = #{id}
+    </delete>
 
     <select id="selectWbsFormElementPage" resultMap="wbsFormElementResultMap">
-        select * from m_wbs_form_element where is_deleted = 0
+        select *
+        from m_wbs_form_element
+        where is_deleted = 0
     </select>
     <select id="judgeFiled" resultType="Integer">
-        select count(*) from information_schema.columns where table_name = &quot;${tableName}&quot; and column_name = &quot;${eKey}&quot;
+        select count(*)
+        from information_schema.columns
+        where table_name = &quot;${tableName}&quot;
+          and column_name = &quot;${eKey}&quot;
     </select>
 
     <select id="selectWbsTreeTableListByParentId" resultType="org.springblade.manager.dto.WbsFormElementDTO2">
-        SELECT id,dept_name AS "deptName",sort
+        SELECT id, dept_name AS "deptName", sort
         FROM m_wbs_tree
         WHERE parent_id = #{parentId}
-        AND status = 1
-        AND is_deleted = 0
-        AND type = 2
+          AND status = 1
+          AND is_deleted = 0
+          AND type = 2
         ORDER BY sort
     </select>
 
     <select id="selectDetailById" resultType="org.springblade.manager.vo.WbsFormElementVO">
-        SELECT
-        *,
-        (SELECT concat(dept_name,"_",t.e_name) FROM m_wbs_tree WHERE id = t.f_id) AS "tableElementKey"
-        FROM m_wbs_form_element t WHERE t.id = #{id} AND status = 1 AND is_deleted = 0
+        SELECT *,
+               (SELECT concat(dept_name, "_", t.e_name) FROM m_wbs_tree WHERE id = t.f_id) AS "tableElementKey"
+        FROM m_wbs_form_element t
+        WHERE t.id = #{id}
+          AND status = 1
+          AND is_deleted = 0
     </select>
 
     <select id="selectElementInTableByFid" resultType="org.springblade.manager.entity.WbsTree">
-        SELECT * FROM m_wbs_tree WHERE id = #{fId} AND type = 2 AND is_deleted=0 AND status = 1
+        SELECT *
+        FROM m_wbs_tree
+        WHERE id = #{fId}
+          AND type = 2
+          AND is_deleted = 0
+          AND status = 1
+    </select>
+
+    <select id="selectWbsTabRelationExcelTab" resultType="org.springblade.manager.entity.WbsTabRelationExcelTab">
+        SELECT * FROM m_wbs_tab_relation_excel_tab WHERE excel_tab_id = #{excelId}
+        <if test="id != null and id != ''">
+            AND wbs_tab_id = #{id}
+        </if>
     </select>
 
 </mapper>

+ 3 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeMapper.java

@@ -107,6 +107,8 @@ public interface WbsTreeMapper extends BaseMapper<WbsTree> {
 
     int deleteLogicById(@Param("id") String id);
 
-    boolean cancelRelation(String id);
+    Integer cancelRelation(String id);
+
+    List<WbsNodeTableVO> searchNodeTables(String nodeId,String excelId);
 
 }

+ 24 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeMapper.xml

@@ -443,5 +443,29 @@
         ORDER BY sort
     </select>
 
+    <select id="searchNodeTables" resultType="org.springblade.manager.vo.WbsNodeTableVO">
+        SELECT
+            wt.id AS id,
+            wt.dept_name AS tableName,
+            wt.sort AS sort,
+            wt.table_type AS tableType,
+            wt.`status` AS `status`,
+            wt.table_owner AS tableOwner,
+            wt.init_table_name AS "initTableName",
+            wt.parent_id AS "parentId",
+            wt.wbs_id AS "wbsId",
+            ( SELECT count( 1 ) FROM m_wbs_form_element WHERE f_id = wt.id ) AS "elementTotal" ,
+            ( SELECT CASE WHEN count(1) > 0 THEN 2 ELSE 1 END FROM m_wbs_tab_relation_excel_tab b WHERE wt.id = b.wbs_tab_id AND b.excel_tab_id = #{excelId}) AS "isLinkTable"
+        FROM
+            m_wbs_tree AS wt
+        WHERE
+            wt.type = 2
+          AND wt.is_deleted = 0
+          AND wt.STATUS = 1
+          AND wt.parent_id = #{nodeId}
+        ORDER BY
+            wt.sort
+    </select>
+
 
 </mapper>

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

@@ -28,6 +28,7 @@ import org.springblade.manager.excel.WbsFormElementBatchExcel;
 import org.springblade.manager.excel.WbsFormElementExcel;
 import org.springblade.manager.vo.WbsFormElementVO;
 import org.springblade.manager.vo.WbsFormElementVO2;
+import org.springblade.manager.vo.WbsNodeTableVO;
 
 import java.util.List;
 
@@ -73,6 +74,10 @@ public interface IWbsFormElementService extends BaseService<WbsFormElement> {
 
     boolean submitExcelRelationWbsTreeAndElement(FormElementDTO2 formElementDTO);
 
-    boolean cancelRelation(String id);
+    boolean cancelRelation(String id,String excelId);
+
+    List<WbsNodeTableVO> searchNodeTables(String nodeId,String excelTabId);
+
+    boolean saveRelation(FormElementDTO2 formElementDTO);
 
 }

+ 181 - 84
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsFormElementServiceImpl.java

@@ -40,6 +40,7 @@ import org.springblade.manager.dto.FormElementDTO;
 import org.springblade.manager.dto.FormElementDTO2;
 import org.springblade.manager.dto.WbsFormElementDTO2;
 import org.springblade.manager.entity.WbsFormElement;
+import org.springblade.manager.entity.WbsTabRelationExcelTab;
 import org.springblade.manager.entity.WbsTree;
 import org.springblade.manager.excel.WbsFormElementBatchExcel;
 import org.springblade.manager.excel.WbsFormElementExcel;
@@ -50,6 +51,7 @@ import org.springblade.manager.service.IWbsFormElementService;
 import org.springblade.manager.service.IWbsTreeService;
 import org.springblade.manager.vo.WbsFormElementVO;
 import org.springblade.manager.vo.WbsFormElementVO2;
+import org.springblade.manager.vo.WbsNodeTableVO;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -376,16 +378,26 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
     @Transactional(rollbackFor = Exception.class)
     public boolean submitExcelRelationWbsTreeAndElement(FormElementDTO2 formElementDTO) {
         //新增元素表、实体表
-        if (formElementDTO.getTableIds() == null) {
+        if (formElementDTO.getSubmitStatus() == 2) {
             this.saveFormElement(formElementDTO);
 
-        } else {
+        } else if (formElementDTO.getSubmitStatus() == 1) {
             //关联-在已有元素表中新增元素,在实体表中追加字段
-            List<String> tableIds = formElementDTO.getTableIds();
+            //获取当前清表关联的所有tableIds
+            List<WbsTabRelationExcelTab> WbsTabRelationExcelTabs = baseMapper.selectWbsTabRelationExcelTab(null, String.valueOf(formElementDTO.getExcelTabId()));
+            List<Long> tableIds = WbsTabRelationExcelTabs.stream().map(WbsTabRelationExcelTab::getWbsTabId).collect(Collectors.toList());
             if (tableIds.size() == 0) {
-                throw new ServiceException("请选择一张元素表进行关联");
+                throw new ServiceException("当前清表未关联元素表");
             }
-            for (String tableId : tableIds) {
+
+            for (Long tableId : tableIds) {
+                //获取当前元素表与清表关系信息
+                List<WbsTabRelationExcelTab> list = baseMapper.selectWbsTabRelationExcelTab(String.valueOf(tableId), String.valueOf(formElementDTO.getExcelTabId()));
+                if (list.size() <= 0) {
+                    //新增当前元素表与清表关系信息
+                    baseMapper.insertWbsTabRelationExcelTab(SnowFlakeUtil.getId(), formElementDTO.getExcelTabId(), tableId);
+                }
+
                 //获取当前表信息
                 WbsTree wbsTree = wbsTreeMapper.selectOne(Wrappers.<WbsTree>query().lambda().eq(WbsTree::getId, tableId));
 
@@ -410,7 +422,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
                     //新增元素到当前表中
                     wbsFormElementInfo.setEKey(key);
                     wbsFormElementInfo.setId(SnowFlakeUtil.getId());
-                    wbsFormElementInfo.setFId(tableId);
+                    wbsFormElementInfo.setFId(String.valueOf(tableId));
                     wbsFormElementInfo.setStatus(1);
                     wbsFormElementInfo.setELength(Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType())));
 
@@ -432,105 +444,128 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
         }
 
         return true;
-
     }
 
     @Override
-    public boolean cancelRelation(String id) {
-        return wbsTreeMapper.cancelRelation(id);
-    }
-
-    private boolean saveFormElement(FormElementDTO2 formElementDTO) {
-        String deptName = formElementDTO.getDeptName();
-        if (deptName.length() > 100 || deptName.length() < 1) {
-            throw new ServiceException("表名长度错误,输入范围1-100个字符长度");
-        }
-        if (formElementDTO.getElementList().size() <= 0) {
-            throw new ServiceException("操作失败,请先添加表单元素");
-        }
-        for (WbsFormElement wbsFormElement : formElementDTO.getElementList()) {
-            if (StringUtils.isEmpty(wbsFormElement.getEName()) ||
-                    StringUtils.isEmpty(String.valueOf(wbsFormElement.getEType()))) {
-                throw new ServiceException("操作失败,请完整填写元素名称与类型参数");
+    public boolean saveRelation(FormElementDTO2 formElementDTO) {
+        try {
+            //获取当前元素表与清表关系信息
+            List<WbsTabRelationExcelTab> list = baseMapper.selectWbsTabRelationExcelTab(String.valueOf(formElementDTO.getId()), String.valueOf(formElementDTO.getExcelTabId()));
+            if (list.size() <= 0) {
+                //新增当前元素表与清表关系信息
+                baseMapper.insertWbsTabRelationExcelTab(SnowFlakeUtil.getId(), formElementDTO.getExcelTabId(), formElementDTO.getId());
             }
-        }
 
-        //初始化
-        Long id = SnowFlakeUtil.getId();
-        String newTableName = "m_" + DateUtil.time() + "_" + id;
-        formElementDTO.setInitTableName(newTableName);
+            //获取当前表信息
+            WbsTree wbsTree = wbsTreeMapper.selectOne(Wrappers.<WbsTree>query().lambda().eq(WbsTree::getId, formElementDTO.getId()));
 
-        //创建元素表
-        boolean b1 = submit2(formElementDTO);
+            //获取表单下的元素信息
+            List<WbsFormElement> wbsFormElements = baseMapper.selectList(Wrappers.<WbsFormElement>query().lambda()
+                    .eq(WbsFormElement::getFId, formElementDTO.getId()));
+            Collections.reverse(wbsFormElements);
+            WbsFormElement firstWbsFormElement = wbsFormElements.stream().findFirst().orElse(wbsFormElements.get(wbsFormElements.size() - 1));
 
-        List<WbsFormElement> elementList = formElementDTO.getElementList();
-        int i = 1;
-        for (WbsFormElement wbsFormElement : elementList) {
-            //当前元素表中元素对应实体表唯一key值、fId、元素默认长度
-            wbsFormElement.setEKey("key_" + i++);
-            wbsFormElement.setId(SnowFlakeUtil.getId());
-            wbsFormElement.setFId(String.valueOf(formElementDTO.getId()));
-            wbsFormElement.setELength(Integer.valueOf(setDefaultElementLength(wbsFormElement.getEType())));
-        }
+            //去重,元素表中名称已存在的元素不添加
+            List<WbsFormElement> newList = formElementDTO.getElementList().stream().filter(a ->
+                    !wbsFormElements.stream().map(WbsFormElement::getEName).collect(Collectors.toList()).contains(a.getEName())
+            ).collect(Collectors.toList());
 
-        boolean b2 = this.saveBatch(elementList);
+            //初始化eKey字段
+            int keyNumber = Integer.parseInt(firstWbsFormElement.getEKey().split("_")[1]);
+            final int[] keyNumber1 = {1};
 
-        //找到当前元素表中所有元素
-        List<WbsFormElement> list = this.selectElementListByFid(String.valueOf(formElementDTO.getId()));
+            newList.stream().forEach(wbsFormElementInfo -> {
+                String key = "key_" + (keyNumber + keyNumber1[0]);
 
-        //初始化实体表
-        Boolean b3 = this.initTable(list, newTableName);
+                //新增元素到当前表中
+                wbsFormElementInfo.setEKey(key);
+                wbsFormElementInfo.setId(SnowFlakeUtil.getId());
+                wbsFormElementInfo.setFId(String.valueOf(formElementDTO.getId()));
+                wbsFormElementInfo.setStatus(1);
+                wbsFormElementInfo.setELength(Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType())));
 
-        if (b1 && b2 && b3) {
-            return true;
-        } else {
-            throw new ServiceException("操作失败");
-        }
+                baseMapper.insert(wbsFormElementInfo);
 
-    }
+                //追加字段到实体表中
+                wbsTreeMapper.alterTableFiled(wbsTree.getInitTableName(), key,
+                        getInitTableFiledType(wbsFormElementInfo.getEType()),
+                        Integer.valueOf(setDefaultElementLength(wbsFormElementInfo.getEType())));
 
-    private static String getPinyin(String text, String separator) {
-        //text 文本, separator 转换后添加的分隔符
-        char[] chars = text.toCharArray();
-        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
+                keyNumber1[0]++;
 
-        // 设置大小写
-        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
+            });
 
-        // 设置声调表示方法
-        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
+            //修改关联信息
+            wbsTree.setIsLinkTable(2);
+            wbsTreeMapper.updateById(wbsTree);
+        } catch (Exception e) {
+            throw new ServiceException("关联失败");
+        }
+        return true;
+    }
 
-        // 设置字母u表示方法
-        format.setVCharType(HanyuPinyinVCharType.WITH_V);
-        String[] s;
-        String rs = "";
-        try {
-            StringBuilder sb = new StringBuilder();
-            for (int i = 0; i < chars.length; i++) {
-                // 判断是否为汉字字符
-                if (String.valueOf(chars[i]).matches("[\\u4E00-\\u9FA5]+")) {
-                    s = PinyinHelper.toHanyuPinyinStringArray(chars[i], format);
-                    if (s != null) {
-                        sb.append(s[0]).append(separator);
-                        continue;
+    @Transactional(rollbackFor = Exception.class)
+    public boolean saveFormElement(FormElementDTO2 formElementDTO) {
+        //获取新增节点ids
+        List<String> nodeIds = formElementDTO.getNodeIds();
+        if (nodeIds.size() <= 0) {
+            throw new ServiceException("请至少选择一个节点进行新增操作");
+        } else {
+            try {
+                for (String nodeId : nodeIds) {
+                    String deptName = formElementDTO.getDeptName();
+                    if (deptName.length() > 100 || deptName.length() < 1) {
+                        throw new ServiceException("表名长度错误,输入范围1-100个字符长度");
+                    }
+                    if (formElementDTO.getElementList().size() <= 0) {
+                        throw new ServiceException("操作失败,请先添加表单元素");
+                    }
+                    for (WbsFormElement wbsFormElement : formElementDTO.getElementList()) {
+                        if (StringUtils.isEmpty(wbsFormElement.getEName()) ||
+                                StringUtils.isEmpty(String.valueOf(wbsFormElement.getEType()))) {
+                            throw new ServiceException("操作失败,请完整填写元素名称与类型参数");
+                        }
                     }
-                }
 
-                sb.append(chars[i]);
+                    //初始化
+                    Long id = SnowFlakeUtil.getId();
+                    String newTableName = "m_" + DateUtil.time() + "_" + id;
+                    formElementDTO.setInitTableName(newTableName);
+
+                    //设置parentId=nodeId
+                    formElementDTO.setParentId(Long.valueOf(nodeId));
+
+                    //创建元素表
+                    boolean b = submit2(formElementDTO);
+                    if (b) {
+                        List<WbsFormElement> elementList = formElementDTO.getElementList();
+                        int i = 1;
+                        for (WbsFormElement wbsFormElement : elementList) {
+                            //当前元素表中元素对应实体表唯一key值、fId、元素默认长度
+                            wbsFormElement.setEKey("key_" + i++);
+                            wbsFormElement.setId(SnowFlakeUtil.getId());
+                            wbsFormElement.setFId(String.valueOf(formElementDTO.getId()));
+                            wbsFormElement.setELength(Integer.valueOf(setDefaultElementLength(wbsFormElement.getEType())));
+                        }
+                        //新增元素
+                        this.saveBatch(elementList);
+
+                        //获取当前元素表中所有元素
+                        List<WbsFormElement> list = this.selectElementListByFid(String.valueOf(formElementDTO.getId()));
+
+                        //初始化实体表
+                        this.initTable(list, newTableName);
+
+                        //绑定与清表关系
+                        baseMapper.insertWbsTabRelationExcelTab(SnowFlakeUtil.getId(), formElementDTO.getExcelTabId(), formElementDTO.getId());
 
-                if ((i + 1 >= chars.length) || String.valueOf(chars[i + 1]).matches("[\\u4E00-\\u9FA5]+")) {
-                    sb.append(separator);
+                    }
                 }
+            } catch (Exception e) {
+                throw new ServiceException("新增元素表操作失败");
             }
-
-            rs = sb.substring(0, sb.length());
-        } catch (BadHanyuPinyinOutputFormatCombination e) {
-            e.printStackTrace();
-
         }
-
-        return rs;
-
+        return true;
     }
 
     private boolean submit2(FormElementDTO2 dept) {
@@ -558,9 +593,28 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
         dept.setDeptCategory(1);
         dept.setStatus(1);
         dept.setIsLinkTable(2);
+        dept.setId(SnowFlakeUtil.getId());
 
         return wbsTreeMapper.insert(dept) > 0;
+    }
+
+    @Override
+    public boolean cancelRelation(String id, String excelId) {
+        //查询元素表与清表关联关系
+        List<WbsTabRelationExcelTab> list = baseMapper.selectWbsTabRelationExcelTab(id, excelId);
+        if (list.size() > 0) {
+            //删除元素表与清表关联关系
+            baseMapper.deleteWbsTabRelationExcelTab(id, excelId);
+
+            //修改状态
+            wbsTreeMapper.cancelRelation(id);
+        }
+        return true;
+    }
 
+    @Override
+    public List<WbsNodeTableVO> searchNodeTables(String nodeId, String excelId) {
+        return wbsTreeMapper.searchNodeTables(nodeId, excelId);
     }
 
     public boolean syncDataFiled(String initTableName, List<WbsFormElement> listData) {
@@ -630,7 +684,6 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
         }
     }
 
-
     private String setDefaultElementLength(Integer type) {
         switch (type) {
             case 1:  //字符串
@@ -647,4 +700,48 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
         }
     }
 
+    private static String getPinyin(String text, String separator) {
+        //text 文本, separator 转换后添加的分隔符
+        char[] chars = text.toCharArray();
+        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
+
+        // 设置大小写
+        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
+
+        // 设置声调表示方法
+        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
+
+        // 设置字母u表示方法
+        format.setVCharType(HanyuPinyinVCharType.WITH_V);
+        String[] s;
+        String rs = "";
+        try {
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < chars.length; i++) {
+                // 判断是否为汉字字符
+                if (String.valueOf(chars[i]).matches("[\\u4E00-\\u9FA5]+")) {
+                    s = PinyinHelper.toHanyuPinyinStringArray(chars[i], format);
+                    if (s != null) {
+                        sb.append(s[0]).append(separator);
+                        continue;
+                    }
+                }
+
+                sb.append(chars[i]);
+
+                if ((i + 1 >= chars.length) || String.valueOf(chars[i + 1]).matches("[\\u4E00-\\u9FA5]+")) {
+                    sb.append(separator);
+                }
+            }
+
+            rs = sb.substring(0, sb.length());
+        } catch (BadHanyuPinyinOutputFormatCombination e) {
+            e.printStackTrace();
+
+        }
+
+        return rs;
+
+    }
+
 }