Browse Source

达梦建表接口

xuezizhuo 2 years ago
parent
commit
05827c4e65

+ 1 - 0
src/main/java/com/customer/controller/TableInfoController.java

@@ -60,6 +60,7 @@ public class TableInfoController {
         if(tableInfoService.oracleTableExist(tableName)>0){
             return AjaxResult.warn("当前数据库中表已存在");
         }
+        tableInfoService.createOracleTable(map);
         return AjaxResult.success();
     }
 

+ 9 - 0
src/main/java/com/customer/mapper/TableInfoMapper.java

@@ -89,6 +89,15 @@ public interface TableInfoMapper {
      */
     int oracleTableExist(String tableName);
 
+    /**
+     * 创建oracle数据表
+     */
+    void createOracleTable(@Param("tableName") String tableName,@Param("filedList") List<String> filedList);
+
+    /**
+     * 添加注释
+     */
+    void addOracleTableDescription(String description);
 
 
 

+ 4 - 0
src/main/java/com/customer/service/ITableInfoService.java

@@ -55,5 +55,9 @@ public interface ITableInfoService {
      */
     int oracleTableExist(String tableName);
 
+    /**
+     * 创建oracle表
+     */
+    void createOracleTable(Map<String,Object> map);
 
 }

+ 30 - 0
src/main/java/com/customer/service/impl/TableInfoServiceImpl.java

@@ -161,4 +161,34 @@ public class TableInfoServiceImpl implements ITableInfoService {
     public int oracleTableExist(String tableName) {
         return tableInfoMapper.oracleTableExist(tableName);
     }
+
+    @Override
+    public void createOracleTable(Map<String, Object> map) {
+        String tableName = (String) map.get("tableName");
+        List<TableInfo> filedList = JSON.parseArray(JSON.toJSONString(map.get("field")), TableInfo.class);
+        List<String> descriptionList = new ArrayList<>();
+        List<String> list= filedList.stream().map(filed->{
+            StringBuilder stringBuilder = new StringBuilder();
+            stringBuilder.append(filed.getFieldName()+" ")
+                    .append(filed.getFieldType()+" ");
+            if(filed.getIsPrimary()){
+                stringBuilder.append("PRIMARY KEY ");
+            }
+            if(filed.getIsNull()){
+                stringBuilder.append("NOT NULL ");
+            }
+            if(StringUtils.hasLength(filed.getFieldDescription())){
+                StringBuilder builder = new StringBuilder();
+                builder.append("comment on column ")
+                        .append(tableName)
+                        .append(".")
+                        .append(filed.getFieldName()+" is '")
+                        .append(filed.getFieldDescription()+"'");
+                descriptionList.add(builder.toString());
+            }
+            return stringBuilder.toString();
+        }).collect(Collectors.toList());
+        tableInfoMapper.createOracleTable(tableName,list);
+        descriptionList.stream().forEach(f ->tableInfoMapper.addOracleTableDescription(f));
+    }
 }

+ 0 - 6
src/main/java/com/customer/utils/DataSourceUtils.java

@@ -1,14 +1,8 @@
 package com.customer.utils;
 
-import com.customer.config.DynamicDataSource;
 import com.customer.config.GenConfig;
 import com.customer.constant.DataSourceType;
 import com.customer.pojo.DataSource;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.sql.SQLException;
 
 public class DataSourceUtils {
 

+ 12 - 0
src/main/resources/mapper/TableInfoMapper.xml

@@ -91,5 +91,17 @@
         select count(1) from user_tables where table_name=upper(#{tableName})
     </select>
 
+    <update id="createOracleTable">
+        create table ${tableName}
+        (
+            <foreach collection="filedList" item="filed" separator=",">
+                ${filed}
+            </foreach>
+        )
+    </update>
+
+    <update id="addOracleTableDescription">
+        ${description}
+    </update>
 
 </mapper>