田源
2023-05-09 d2570148ec3884de3af721bd99c4b7acbbdee075
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.vci.ubcs.ddl.processor.ddl;
 
 
import com.vci.ubcs.ddl.mapper.DdlMSMapper;
import com.vci.ubcs.ddl.mapper.DdlMapper;
import com.vci.ubcs.starter.util.VciSpringUtil;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
/**
 * Description: SqlServer的数据库操作
 *
 * @author LiHang
 * @date 2023/4/24
 */
@Component
public class DdlMsMapperProcessor extends DdlMapperProcessor{
 
    private static DdlMapper mapper = VciSpringUtil.getBean(DdlMSMapper.class);
 
 
    public DdlMsMapperProcessor() {
        super(mapper);
        System.out.println("-----------------");
        if (mapper != null){
            System.out.println("[success]::加载Sql Server数据库DDL操作服务成功");
        }else {
            System.out.println("[fail]::加载Sql Server数据库DDL操作服务失败");
        }
    }
 
    @Override
    public boolean support(String url) {
        return "com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(url);
    }
 
    @Override
    public void modifyTableBySqlBase(String tableName, String attributeSql) {
        List<String> modifyColumnSqlList = VciBaseUtil.str2List(attributeSql);
        if (!CollectionUtils.isEmpty(modifyColumnSqlList)) {
            modifyColumnSqlList.stream().forEach(s -> {
                mapper.modifyTableBySql(tableName, s);
            });
        }
    }
 
    /**
     * 向数据库表中添加单个字段
     *
     * @param tableName    表格的名称
     * @param attributeSql 要添加的新的sql
     * @return 影响的行数
     */
    @Override
    public int addColumn2TableBySql(String tableName, String attributeSql) {
        List<String> modifyColumnSqlList = VciBaseUtil.str2List(attributeSql);
        List<Integer> result = new ArrayList<>();
        if (!CollectionUtils.isEmpty(modifyColumnSqlList)) {
            modifyColumnSqlList.stream().forEach(s -> {
                result.add(mapper.addColumn2TableBySql(tableName, s));
            });
            return result.stream().mapToInt(Integer::intValue).sum();
        }
        return 0;
    }
}