Преглед изворни кода

ITP模板构件复制功能

fangpy пре 1 година
родитељ
комит
1b4dcb82d5

+ 6 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxItpTemplateNodesService.java

@@ -2,8 +2,12 @@ package com.rongwei.bscommon.sys.service;
 
 import com.rongwei.bsentity.domain.ZhcxItpTemplateNodesDo;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.rongwei.bsentity.vo.CopyNodeVo;
 import com.rongwei.bsentity.vo.ZhcxItpTemplateNodeSyncProjectVo;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * itp地图模板检验点 服务类
@@ -16,4 +20,6 @@ public interface ZhcxItpTemplateNodesService extends IService<ZhcxItpTemplateNod
 
     void itpTemplateAddNodeSyncProjects(ZhcxItpTemplateNodeSyncProjectVo zhcxItpTemplateNodeSyncProjectVo);
 
+    List<Map<String, Object>> copyItpTemplateNode(CopyNodeVo copyNodeVo);
+
 }

+ 30 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxItpProjectNodesServiceImpl.java

@@ -322,6 +322,7 @@ public class ZhcxItpProjectNodesServiceImpl extends ServiceImpl<ZhcxItpProjectNo
                     }
                 }
             });
+            // 复制当前节点到指定节点下
             ZhcxItpProjectNodesDo sourceDo = this.getById(copyNodeVo.getCopysourceid());
             List<ZhcxItpProjectNodesDo> toDos = (List<ZhcxItpProjectNodesDo>)this.listByIds(toids);
             if(toDos != null && toDos.size()>0){
@@ -335,9 +336,38 @@ public class ZhcxItpProjectNodesServiceImpl extends ServiceImpl<ZhcxItpProjectNo
                         newDo.setSortindex(new BigDecimal("0"));
                     }
                     newDo.setPid(toDo.getId());
+                    // 替换path
+                    if(StringUtils.isNotBlank(toDo.getPath()) && !"-1".equals(toDo.getPath())){
+                        newDo.setPath(toDo.getPath()+","+toDo.getId());
+                    }else{
+                        newDo.setPath(toDo.getId());
+                    }
                     toSave.add(newDo);
                 }
             }
+            // 如当前节点存在子节点则复制子节点到指定节点
+            // 获取当前源节点的子节点
+            List<ZhcxItpProjectNodesDo> cNodes = this.list(new LambdaQueryWrapper<ZhcxItpProjectNodesDo>().eq(ZhcxItpProjectNodesDo::getPid, sourceDo.getId()));
+            if(cNodes != null && cNodes.size()>0){
+                List<ZhcxItpProjectNodesDo> toSaveCNodes = new ArrayList<>();
+                for (ZhcxItpProjectNodesDo pNode : toSave) {
+                    for (ZhcxItpProjectNodesDo cNode : cNodes) {
+                        ZhcxItpProjectNodesDo newDo = new ZhcxItpProjectNodesDo();
+                        BeanUtil.copyProperties(cNode,newDo);
+                        newDo.setId(SecurityUtil.getUUID());
+                        newDo.setPid(pNode.getId());
+                        // 替换path
+                        if(StringUtils.isNotBlank(pNode.getPath()) && !"-1".equals(pNode.getPath())){
+                            newDo.setPath(pNode.getPath()+","+pNode.getId());
+                        }else{
+                            newDo.setPath(pNode.getId());
+                        }
+                        toSaveCNodes.add(newDo);
+                    }
+                }
+                toSave.addAll(toSaveCNodes);
+            }
+
 
             if(toSave != null && toSave.size()>0){
                 this.saveBatch(toSave);

+ 125 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxItpTemplateNodesServiceImpl.java

@@ -11,13 +11,16 @@ import com.rongwei.bscommon.sys.dao.ZhcxItpTemplateNodesDao;
 import com.rongwei.bscommon.sys.service.ZhcxItpTemplateNodesService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.rongwei.bsentity.domain.ZhcxProjectDeviceNumberDo;
+import com.rongwei.bsentity.vo.CopyNodeVo;
 import com.rongwei.bsentity.vo.ZhcxItpTemplateNodeSyncProjectVo;
+import com.rongwei.commonservice.service.dao.CommonSqlDao;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -36,6 +39,8 @@ public class ZhcxItpTemplateNodesServiceImpl extends ServiceImpl<ZhcxItpTemplate
     private ZhcxItpProjectNodesService zhcxItpProjectNodesService;
     @Autowired
     private ZhcxProjectDeviceNumberService zhcxProjectDeviceNumberService;
+    @Autowired
+    private CommonSqlDao commonSqlDao;
 
     /**
      * 新增的ITP模板节点同步到指定项目
@@ -186,5 +191,125 @@ public class ZhcxItpTemplateNodesServiceImpl extends ServiceImpl<ZhcxItpTemplate
         }
     }
 
+    /**
+     * 复制ITP地图模板节点
+     * @param copyNodeVo
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = RuntimeException.class)
+    public List<Map<String, Object>> copyItpTemplateNode(CopyNodeVo copyNodeVo) {
+        // 复制数据
+        if(StringUtils.isNotBlank(copyNodeVo.getCopysourceid()) && copyNodeVo.getCopytoid() != null){
+            List<ZhcxItpTemplateNodesDo> toSave = new ArrayList<>();
+
+            List<String> toids = new ArrayList<>();
+            Map<String,String> idSort = new HashMap<>();
+            copyNodeVo.getCopytoid().forEach(v->{
+                if(v.containsKey("id")){
+                    if(v.containsKey("pid")){
+                        toids.add(v.get("pid").toString());
+                        // 获取同级所有构件
+//                        List<ZhcxItpTemplateNodesDo> pcNodes = this.list(new LambdaQueryWrapper<ZhcxItpTemplateNodesDo>().eq(ZhcxItpTemplateNodesDo::getPid, v.get("pid").toString())
+//                                .orderByAsc(ZhcxItpTemplateNodesDo::getSortindex)).stream().collect(Collectors.toList());
+                        ZhcxItpTemplateNodesDo cNode = this.getById(v.get("id").toString());
+                        // 根据参数copynodezq是否为true来判断是否插入当前节点的前面
+                        // 当前节点之前
+                        String sql = "update ZHCX_ITP_TEMPLATE_NODES set SORTINDEX = SORTINDEX + 1 where ITPID='"+ copyNodeVo.getProjectid() +"' and PID='"+v.get("pid")+"'";
+                        if(v.containsKey("copynodezq") && (Boolean) v.get("copynodezq")){
+                            if(idSort.containsKey(v.get("pid").toString())){
+                                idSort.put(v.get("pid").toString(),idSort.get(v.get("pid").toString())+","+cNode.getSortindex().toString());
+                            }else{
+                                idSort.put(v.get("pid").toString(),cNode.getSortindex().toString());
+                            }
+                            sql = sql + " and SORTINDEX>=" + cNode.getSortindex().toString();
+                        }
+                        // 当前节点之后
+                        else{
+                            if(idSort.containsKey(v.get("pid").toString())){
+                                idSort.put(v.get("pid").toString(),idSort.get(v.get("pid").toString())+","+(cNode.getSortindex().add(new BigDecimal("1"))));
+                            }else{
+                                idSort.put(v.get("pid").toString(),cNode.getSortindex().add(new BigDecimal("1")).toString());
+                            }
+                            sql = sql + " and SORTINDEX>" + cNode.getSortindex().toString();
+                        }
+                        commonSqlDao.sqlUpdate(sql);
+                    }else{
+                        toids.add(v.get("id").toString());
+                        if(v.containsKey("lastsort")){
+                            idSort.put(v.get("id").toString(),v.get("lastsort").toString());
+                        }else{
+                            idSort.put(v.get("id").toString(),"0");
+                        }
+                    }
+                }
+            });
+            // 复制当前节点到指定节点下
+            ZhcxItpTemplateNodesDo sourceDo = this.getById(copyNodeVo.getCopysourceid());
+            List<ZhcxItpTemplateNodesDo> toDos = (List<ZhcxItpTemplateNodesDo>)this.listByIds(toids);
+            if(toDos != null && toDos.size()>0){
+                for (ZhcxItpTemplateNodesDo toDo : toDos) {
+                    if(idSort.containsKey(toDo.getId())){
+                        String idsort = idSort.get(toDo.getId());
+                        String[] sorts = idsort.split(",");
+                        for (String sort : sorts) {
+                            ZhcxItpTemplateNodesDo newDo = new ZhcxItpTemplateNodesDo();
+                            BeanUtil.copyProperties(sourceDo,newDo);
+                            newDo.setId(SecurityUtil.getUUID());
+                            newDo.setSortindex(new BigDecimal(sort));
+                            newDo.setPid(toDo.getId());
+                            // 替换path
+                            if(StringUtils.isNotBlank(toDo.getPath()) && !"-1".equals(toDo.getPath())){
+                                newDo.setPath(toDo.getPath()+","+toDo.getId());
+                            }else{
+                                newDo.setPath(toDo.getId());
+                            }
+                            toSave.add(newDo);
+                        }
+                    }
+                }
+            }
+            // 如当前节点存在子节点则复制子节点到指定节点
+            // 获取当前源节点的子节点
+            List<ZhcxItpTemplateNodesDo> cNodes = this.list(new LambdaQueryWrapper<ZhcxItpTemplateNodesDo>().eq(ZhcxItpTemplateNodesDo::getPid, sourceDo.getId()));
+            if(cNodes != null && cNodes.size()>0){
+                List<ZhcxItpTemplateNodesDo> toSaveCNodes = new ArrayList<>();
+                for (ZhcxItpTemplateNodesDo pNode : toSave) {
+                    for (ZhcxItpTemplateNodesDo cNode : cNodes) {
+                        ZhcxItpTemplateNodesDo newDo = new ZhcxItpTemplateNodesDo();
+                        BeanUtil.copyProperties(cNode,newDo);
+                        newDo.setId(SecurityUtil.getUUID());
+                        newDo.setPid(pNode.getId());
+                        // 替换path
+                        if(StringUtils.isNotBlank(pNode.getPath()) && !"-1".equals(pNode.getPath())){
+                            newDo.setPath(pNode.getPath()+","+pNode.getId());
+                        }else{
+                            newDo.setPath(pNode.getId());
+                        }
+                        toSaveCNodes.add(newDo);
+                    }
+                }
+                toSave.addAll(toSaveCNodes);
+            }
+
 
+            if(toSave != null && toSave.size()>0){
+                this.saveBatch(toSave);
+            }
+        }
+
+        // 返回数据
+        return getItpNodes(copyNodeVo);
+    }
+
+    /**
+     * 返回最新数据
+     * @param copyNodeVo
+     * @return
+     */
+    private List<Map<String, Object>> getItpNodes(CopyNodeVo copyNodeVo){
+        String sql = "select * from ZHCX_ITP_TEMPLATE_NODES where ITPID='"+ copyNodeVo.getProjectid() +"' and deleted='0' order by sortindex asc";
+        List<Map<String, Object>> nodes = commonSqlDao.sqlExecutu(sql);
+        return nodes;
+    }
 }

+ 17 - 0
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxItpTemplateNodesController.java

@@ -1,9 +1,17 @@
 package com.rongwei.bsserver.controller;
 
 
+import com.rongwei.bscommon.sys.service.ZhcxItpTemplateNodesService;
+import com.rongwei.bsentity.vo.CopyNodeVo;
+import com.rongwei.rwcommon.base.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * itp地图模板检验点 前端控制器
@@ -16,5 +24,14 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/zhcxItpTemplateNodes")
 public class ZhcxItpTemplateNodesController {
 
+    @Autowired
+    private ZhcxItpTemplateNodesService zhcxItpTemplateNodesService;
+
+    @RequestMapping("/copyItpTemplateNode")
+    public R copyItpTemplateNode(@RequestBody CopyNodeVo copyNodeVo){
+        List<Map<String, Object>> maps = zhcxItpTemplateNodesService.copyItpTemplateNode(copyNodeVo);
+        return R.ok(maps);
+    }
+
 }