瀏覽代碼

ITP地图引用复制功能

fangpy 1 年之前
父節點
當前提交
10d33939d2

+ 6 - 0
business-common/pom.xml

@@ -40,5 +40,11 @@
             <version>${mysql.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.dameng</groupId>
+            <artifactId>DmJdbcDriver18</artifactId>
+            <version>8.1.1.193</version>
+        </dependency>
+
     </dependencies>
 </project>

+ 3 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxItpTemplateService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.rongwei.bsentity.vo.CopyAddTemplateVo;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -18,4 +19,6 @@ public interface ZhcxItpTemplateService extends IService<ZhcxItpTemplateDo> {
 
     void copyAddTemplateNodes(CopyAddTemplateVo copyAddTemplate);
 
+    List<Map<String, Object>> copyNodesSave(CopyAddTemplateVo copyAddTemplate);
+
 }

+ 59 - 4
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxItpTemplateServiceImpl.java

@@ -1,5 +1,6 @@
 package com.rongwei.bscommon.sys.service.impl;
 
+import cn.hutool.core.collection.ListUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.rongwei.bscommon.sys.service.ZhcxItpTemplateNodesService;
 import com.rongwei.bsentity.domain.ZhcxItpTemplateDo;
@@ -8,9 +9,11 @@ import com.rongwei.bscommon.sys.service.ZhcxItpTemplateService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.rongwei.bsentity.domain.ZhcxItpTemplateNodesDo;
 import com.rongwei.bsentity.vo.CopyAddTemplateVo;
+import com.rongwei.commonservice.service.dao.CommonSqlDao;
 import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
+import org.apache.commons.collections.ListUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -31,6 +34,8 @@ public class ZhcxItpTemplateServiceImpl extends ServiceImpl<ZhcxItpTemplateDao,
 
     @Autowired
     private ZhcxItpTemplateNodesService zhcxItpTemplateNodesService;
+    @Autowired
+    private CommonSqlDao commonSqlDao;
 
     /**
      * 复制新增的引用所有子节点
@@ -38,6 +43,8 @@ public class ZhcxItpTemplateServiceImpl extends ServiceImpl<ZhcxItpTemplateDao,
      */
     @Override
     public void copyAddTemplateNodes(CopyAddTemplateVo copyAddTemplate) {
+        // 待复制保存的子节点
+        List<ZhcxItpTemplateNodesDo> toCopySaveNodes = new ArrayList<>();
         if(StringUtils.isBlank(copyAddTemplate.getTargetTmpId())){
             throw new CustomException("数据有问题,ID没有值");
         }
@@ -51,8 +58,6 @@ public class ZhcxItpTemplateServiceImpl extends ServiceImpl<ZhcxItpTemplateDao,
                         new LambdaQueryWrapper<ZhcxItpTemplateNodesDo>().eq(ZhcxItpTemplateNodesDo::getItpid,copyAddTemplate.getTargetTmpId()));
                 // 过滤出当前ITP地图模板所有根节点
                 List<ZhcxItpTemplateNodesDo> rootTargetNodes = targetNodesDos.stream().filter(v -> v.getPid().equals("-1")).collect(Collectors.toList());
-                // 待复制保存的子节点
-                List<ZhcxItpTemplateNodesDo> toCopySaveNodes = new ArrayList<>();
                 // 存放老ID和新ID的Map,方便后面的归属大构件ID替换
                 Map<String,String> oldNewId = new HashMap<>();
                 for (ZhcxItpTemplateNodesDo copyNodesDo : copyNodesDos) {
@@ -92,9 +97,59 @@ public class ZhcxItpTemplateServiceImpl extends ServiceImpl<ZhcxItpTemplateDao,
                         copyNodesDo.setPid(oldNewId.get(copyNodesDo.getPid()));
                     }
                 }
-                // 保存最终数据
-                zhcxItpTemplateNodesService.saveBatch(toCopySaveNodes);
             }
         }
+        // 保存数据
+        if(toCopySaveNodes != null && toCopySaveNodes.size()>0){
+            // 保存最终数据
+            zhcxItpTemplateNodesService.saveBatch(toCopySaveNodes);
+        }
+    }
+
+    /**
+     * 更换层级引用复制节点并保存层级引用、并返回数据
+     * @param copyAddTemplate
+     */
+    @Override
+    public List<Map<String, Object>> copyNodesSave(CopyAddTemplateVo copyAddTemplate){
+        if(StringUtils.isNotBlank(copyAddTemplate.getTargetTmpId()) && copyAddTemplate.getTmpIds() != null && copyAddTemplate.getTmpIds().size()>0){
+            ZhcxItpTemplateDo templateDo = this.getById(copyAddTemplate.getTargetTmpId());
+            List<String> newTempIds = new ArrayList<>();
+
+            String tmpids = "";
+            for (String tmpId : copyAddTemplate.getTmpIds()) {
+                if("".equals(tmpids)){
+                    tmpids = tmpId;
+                }else{
+                    tmpids = tmpids + "," + tmpId;
+                }
+                if(StringUtils.isBlank(templateDo.getTmpid()) || templateDo.getTmpid().indexOf(tmpId) == -1){
+                    newTempIds.add(tmpId);
+                }
+            }
+            String tmpnames = "";
+            for (String tmpName : copyAddTemplate.getTmpNames()) {
+                if("".equals(tmpnames)){
+                    tmpnames = tmpName;
+                }else{
+                    tmpnames = tmpnames + "," + tmpName;
+                }
+            }
+            // 复制节点层级
+            CopyAddTemplateVo newCopyAddTemplate = new CopyAddTemplateVo();
+            newCopyAddTemplate.setTargetTmpId(copyAddTemplate.getTargetTmpId());
+            newCopyAddTemplate.setTmpIds(newTempIds);
+            this.copyAddTemplateNodes(newCopyAddTemplate);
+            // 保存模板引用
+            ZhcxItpTemplateDo zhcxItpTemplate = new ZhcxItpTemplateDo();
+            zhcxItpTemplate.setId(copyAddTemplate.getTargetTmpId());
+            zhcxItpTemplate.setTmpid(tmpids);
+            zhcxItpTemplate.setTmpname(tmpnames);
+            this.updateById(zhcxItpTemplate);
+        }
+        // 返回数据
+        String sql = "select * from zhcx_itp_template_nodes where ITPID='"+ copyAddTemplate.getTargetTmpId() +"' and deleted='0' order by sortindex asc";
+        List<Map<String, Object>> nodes = commonSqlDao.sqlExecutu(sql);
+        return nodes;
     }
 }

+ 2 - 0
business-entity/src/main/java/com/rongwei/bsentity/vo/CopyAddTemplateVo.java

@@ -9,4 +9,6 @@ public class CopyAddTemplateVo {
     private String targetTmpId;
 
     private List<String> tmpIds;
+
+    private List<String> tmpNames;
 }

+ 127 - 0
business-server/src/main/java/com/rongwei/bsserver/config/NClobTypeHandler.java

@@ -0,0 +1,127 @@
+package com.rongwei.bsserver.config;
+
+import com.alibaba.druid.pool.DruidDataSource;
+import com.alibaba.druid.proxy.jdbc.NClobProxyImpl;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.sql.*;
+
+/**
+ *
+ *@AUTHOR:赵常飞
+ *@date 2023/10/10 16:50
+ */
+@MappedTypes(Clob.class)
+@MappedJdbcTypes(JdbcType.CLOB)
+@Component
+public class NClobTypeHandler extends BaseTypeHandler<String> {
+    @Autowired
+    private DruidDataSource datasource;
+
+    @Override
+    public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
+        StringReader reader=new StringReader(parameter);
+        ps.setCharacterStream(i,reader,parameter.length());
+    }
+
+    @Override
+    public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
+        String dbType = datasource.getDbType();
+        String clobToString="";
+        try {
+            switch (dbType) {
+                //达梦数据库
+                case "dm":
+                    NClobProxyImpl aa=(NClobProxyImpl) rs.getObject(columnName);
+                    if(aa != null){
+                        Clob rawClob = aa.getRawClob();
+                        clobToString = ClobToString(rawClob);
+                    }
+                    break;
+                default:
+                    clobToString="长文本类型,无法显示";
+                    break;
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return clobToString;
+    }
+
+    @Override
+    public String getNullableResult(ResultSet rs, int i) throws SQLException {
+        String dbType = datasource.getDbType();
+        String clobToString="";
+        try {
+            switch (dbType) {
+                case "dm":
+                    NClobProxyImpl aa=(NClobProxyImpl) rs.getObject(i);
+                    if(aa != null){
+                        Clob rawClob = aa.getRawClob();
+                        clobToString = ClobToString(rawClob);
+                    }
+                    break;
+                default:
+                    clobToString="长文本类型,无法显示";
+                    break;
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return clobToString;
+    }
+
+    @Override
+    public String getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
+        String dbType = datasource.getDbType();
+        String clobToString="";
+        try {
+            switch (dbType) {
+                case "dm":
+                    NClobProxyImpl aa=(NClobProxyImpl) callableStatement.getObject(i);
+                    if(aa != null){
+                        Clob rawClob = aa.getRawClob();
+                        clobToString = ClobToString(rawClob);
+                    }
+                    break;
+                default:
+                    clobToString="长文本类型,无法显示";
+                    break;
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return clobToString;
+    }
+
+
+    private String ClobToString(Clob clob) throws SQLException, IOException {
+        String reString = "";
+        Reader is = clob.getCharacterStream();// 得到流
+        BufferedReader br = new BufferedReader(is);
+        String s = br.readLine();
+        StringBuffer sb = new StringBuffer();
+        while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
+            sb.append(s);
+            s = br.readLine();
+        }
+        reString = sb.toString();
+        return reString;
+    }
+}
+

+ 7 - 0
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxItpTemplateController.java

@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -32,5 +33,11 @@ public class ZhcxItpTemplateController {
         return R.ok();
     }
 
+    @RequestMapping("/copyNodesSave")
+    public R copyNodesSave(@RequestBody CopyAddTemplateVo copyAddTemplate){
+        List<Map<String, Object>> maps = zhcxItpTemplateService.copyNodesSave(copyAddTemplate);
+        return R.ok(maps);
+    }
+
 }