|
@@ -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;
|
|
|
+ }
|
|
|
}
|