Browse Source

修改wbs节点树导入BUG

liuyc 3 years ago
parent
commit
4956e05f7a

+ 10 - 11
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeController.java

@@ -232,11 +232,11 @@ public class WbsTreeController extends BladeController {
     @ApiOperation(value = "编辑表单元素批量修改", notes = "传入WbsFormElement")
     @ApiOperation(value = "编辑表单元素批量修改", notes = "传入WbsFormElement")
     @ApiImplicitParam(name = "ids", value = "元素的id集合", required = true)
     @ApiImplicitParam(name = "ids", value = "元素的id集合", required = true)
     @Transactional(rollbackFor = Exception.class)
     @Transactional(rollbackFor = Exception.class)
-    public R updateBatchElements(@RequestBody List<WbsFormElement> wbsFormElementList,@RequestParam("initTableName") String initTableName) {
+    public R updateBatchElements(@RequestBody List<WbsFormElement> wbsFormElementList, @RequestParam("initTableName") String initTableName) {
         boolean b = wbsFormElementService.updateBatchById(wbsFormElementList);
         boolean b = wbsFormElementService.updateBatchById(wbsFormElementList);
         if (b) {
         if (b) {
             //同步修改实体表类型字段类型
             //同步修改实体表类型字段类型
-            wbsFormElementService.updateAndSyn(wbsFormElementList,initTableName);
+            wbsFormElementService.updateAndSyn(wbsFormElementList, initTableName);
             return R.success("修改成功");
             return R.success("修改成功");
         }
         }
         return R.fail("修改失败");
         return R.fail("修改失败");
@@ -263,21 +263,20 @@ public class WbsTreeController extends BladeController {
     @RequestMapping(value = "/import-wbsTree", method = RequestMethod.POST)
     @RequestMapping(value = "/import-wbsTree", method = RequestMethod.POST)
     public R importWbsTree(@RequestPart("excelFile") MultipartFile excelFile,
     public R importWbsTree(@RequestPart("excelFile") MultipartFile excelFile,
                            @RequestPart("wbsTreeFu") WbsTree wbsTreeFu) throws IOException {
                            @RequestPart("wbsTreeFu") WbsTree wbsTreeFu) throws IOException {
-        /*二级节点是否已导入相同excel模板*/
         Long parentId = wbsTreeFu.getParentId();
         Long parentId = wbsTreeFu.getParentId();
         WbsTree wbsTree1 = wbsTreeService.getById(parentId);
         WbsTree wbsTree1 = wbsTreeService.getById(parentId);
         if (wbsTree1.getProjectNodeId().equals(parentId)) {
         if (wbsTree1.getProjectNodeId().equals(parentId)) {
-            return R.fail("该节点下已存工程节点数据,请重新选择节点导入!");
+            /*覆盖*/
+            wbsTreeService.deleteBatchByProjectNodeId(wbsTree1.getProjectNodeId());
+            wbsTreeService.importWbsTree(excelFile, wbsTreeFu, wbsTree1);
+            return R.success("覆盖导入成功");
+        } else {
+            //新增
+            wbsTreeService.importWbsTree(excelFile, wbsTreeFu, wbsTree1);
+            return R.success("新增导入成功");
         }
         }
-        //导入
-        Boolean b = wbsTreeService.importWbsTree(excelFile, wbsTreeFu, wbsTree1);
-        if (b) {
-            return R.success("导入成功");
-        }
-        return R.fail("导入失败");
     }
     }
 
 
-
 }
 }
 
 
 
 

+ 11 - 5
blade-service/blade-manager/src/main/java/org/springblade/manager/excel/WbsExcelUtil.java

@@ -267,17 +267,23 @@ public class WbsExcelUtil {
 
 
     /**
     /**
      * 获取path路径
      * 获取path路径
+     *
      * @param file
      * @param file
      * @return
      * @return
      * @throws IOException
      * @throws IOException
      */
      */
     public static File convert(MultipartFile file) throws IOException {
     public static File convert(MultipartFile file) throws IOException {
         File convFile = new File(Objects.requireNonNull(Objects.requireNonNull(file.getOriginalFilename())));
         File convFile = new File(Objects.requireNonNull(Objects.requireNonNull(file.getOriginalFilename())));
-        convFile.createNewFile();
-        FileOutputStream fos = new FileOutputStream(convFile);
-        fos.write(file.getBytes());
-        fos.close();
+        FileOutputStream fos = null;
+        try {
+            convFile.createNewFile();
+            fos = new FileOutputStream(convFile);
+            fos.write(file.getBytes());
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            fos.close();
+        }
         return convFile;
         return convFile;
-
     }
     }
 }
 }

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

@@ -113,4 +113,6 @@ public interface WbsTreeMapper extends BaseMapper<WbsTree> {
 
 
     List<WbsTree> selectIsTable(Long tableParentId);
     List<WbsTree> selectIsTable(Long tableParentId);
 
 
+    int deleteBatchProjectNodeId(Long projectNodeId);
+
 }
 }

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

@@ -112,6 +112,10 @@
         create table ${tableName} as select * from m_wbs_tree WHERE 1=2
         create table ${tableName} as select * from m_wbs_tree WHERE 1=2
     </update>
     </update>
 
 
+    <delete id="deleteBatchProjectNodeId">
+        delete from m_wbs_tree where project_node_id = #{projectNodeId} and id &lt;&gt; #{projectNodeId}
+    </delete>
+
     <select id="selectWbsTreePage" resultMap="wbsTreeResultMap">
     <select id="selectWbsTreePage" resultMap="wbsTreeResultMap">
         select * from m_wbs_tree where is_deleted = 0
         select * from m_wbs_tree where is_deleted = 0
     </select>
     </select>

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

@@ -16,12 +16,10 @@
  */
  */
 package org.springblade.manager.service;
 package org.springblade.manager.service;
 
 
-import io.swagger.models.auth.In;
 import org.springblade.core.mp.base.BaseService;
 import org.springblade.core.mp.base.BaseService;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.api.R;
 import org.springblade.manager.dto.FormElementDTO;
 import org.springblade.manager.dto.FormElementDTO;
-import org.springblade.manager.dto.WbsFormElementDTO;
 import org.springblade.manager.dto.WbsTreeContractDTO;
 import org.springblade.manager.dto.WbsTreeContractDTO;
 import org.springblade.manager.entity.WbsFormElement;
 import org.springblade.manager.entity.WbsFormElement;
 import org.springblade.manager.entity.WbsTree;
 import org.springblade.manager.entity.WbsTree;
@@ -98,5 +96,5 @@ public interface IWbsTreeService extends BaseService<WbsTree> {
 
 
     R saveFormElement(FormElementDTO formElementDTO);
     R saveFormElement(FormElementDTO formElementDTO);
 
 
-
+    int deleteBatchByProjectNodeId(Long projectNodeId);
 }
 }

+ 7 - 5
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsFormElementServiceImpl.java

@@ -175,7 +175,9 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
         long newFiled = Long.parseLong(substring) + 1;
         long newFiled = Long.parseLong(substring) + 1;
         String substring1 = "key_" + newFiled;
         String substring1 = "key_" + newFiled;
         wbsFormElement.setEKey(substring1);
         wbsFormElement.setEKey(substring1);
-
+        if (wbsFormElement.getEType() == 4) {
+            wbsFormElement.setELength(0);
+        }
         int insert = baseMapper.insert(wbsFormElement);
         int insert = baseMapper.insert(wbsFormElement);
         if (insert > 0) {
         if (insert > 0) {
             String newName = wbsFormElement.getEKey();
             String newName = wbsFormElement.getEKey();
@@ -189,7 +191,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
             } else if ("decimal".equals(fieldType)) {
             } else if ("decimal".equals(fieldType)) {
                 sbr1.append(" " + fieldType + "(" + wbsFormElement.getELength() + ")");
                 sbr1.append(" " + fieldType + "(" + wbsFormElement.getELength() + ")");
             } else if ("datetime".equals(fieldType)) {
             } else if ("datetime".equals(fieldType)) {
-                sbr1.append(" " + fieldType + "(" + wbsFormElement.getELength() + ")");
+                sbr1.append(" " + fieldType + "(" + 0 + ")");
             }
             }
             String sql = newName + " " + sbr1;
             String sql = newName + " " + sbr1;
             baseMapper.alterAddFiled(sql, tableName);
             baseMapper.alterAddFiled(sql, tableName);
@@ -208,19 +210,19 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
     }
     }
 
 
     @Override
     @Override
-    public boolean updateAndSyn(List<WbsFormElement> wbsFormElementList,String initTableName) {
+    public boolean updateAndSyn(List<WbsFormElement> wbsFormElementList, String initTableName) {
         QueryWrapper<WbsFormElement> queryWrapper = new QueryWrapper<>();
         QueryWrapper<WbsFormElement> queryWrapper = new QueryWrapper<>();
         String fId = "";
         String fId = "";
         for (WbsFormElement wbsFormElement : wbsFormElementList) {
         for (WbsFormElement wbsFormElement : wbsFormElementList) {
             fId = wbsFormElement.getFId();
             fId = wbsFormElement.getFId();
         }
         }
-        queryWrapper.eq("f_id",fId);
+        queryWrapper.eq("f_id", fId);
         List<WbsFormElement> wbsFormElements = baseMapper.selectList(queryWrapper);
         List<WbsFormElement> wbsFormElements = baseMapper.selectList(queryWrapper);
         for (WbsFormElement wbsFormElement : wbsFormElements) {
         for (WbsFormElement wbsFormElement : wbsFormElements) {
             String eKey = wbsFormElement.getEKey();
             String eKey = wbsFormElement.getEKey();
             Integer eLength = wbsFormElement.getELength();
             Integer eLength = wbsFormElement.getELength();
             String eType = judgeDataType(wbsFormElement.getEType());
             String eType = judgeDataType(wbsFormElement.getEType());
-            baseMapper.updateFiledType(initTableName,eKey,eType,eLength);
+            baseMapper.updateFiledType(initTableName, eKey, eType, eLength);
         }
         }
         return true;
         return true;
     }
     }

+ 13 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeServiceImpl.java

@@ -216,13 +216,16 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
             });
             });
         }
         }
         //修改根节点ProjectNodeId
         //修改根节点ProjectNodeId
-        int row = baseMapper.updateById(wbsTree1);
-        if (row > 0) {
-            return true;
+        baseMapper.updateById(wbsTree1);
+        File file2 = new File(canonicalPath);
+        if (file2.isFile() && file2.exists()) {
+            System.gc();    //回收资源
+            file2.delete();
         }
         }
-        return false;
+        return true;
     }
     }
 
 
+
     private WbsTree importTree(WbsTree wbsTreeZi) {
     private WbsTree importTree(WbsTree wbsTreeZi) {
         //查重
         //查重
         QueryWrapper<WbsTree> queryWrapper = new QueryWrapper<>();
         QueryWrapper<WbsTree> queryWrapper = new QueryWrapper<>();
@@ -246,6 +249,12 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
         return wbsTrees;
         return wbsTrees;
     }
     }
 
 
+    @Override
+    public int deleteBatchByProjectNodeId(Long projectNodeId) {
+        return baseMapper.deleteBatchProjectNodeId(projectNodeId);
+    }
+
+
     private boolean updateDate(String ancestors, Long id) {
     private boolean updateDate(String ancestors, Long id) {
         Integer row = baseMapper.updateById2(ancestors, id);
         Integer row = baseMapper.updateById2(ancestors, id);
         if (row > 0) {
         if (row > 0) {