ludc
2023-04-26 7f0570d20aac189f1b170942bd7100b281a1c824
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package com.vci.ubcs.ddl.processor.dll;
 
import com.vci.ubcs.ddl.mapper.DllMapper;
import com.vci.ubcs.omd.vo.OmdBtmTypeAttributeVO;
import org.apache.commons.lang3.StringUtils;
 
import java.util.List;
 
/**
 * Description:DLL的处理接口
 *
 * @author LiHang
 * @date 2023/4/24
 */
public abstract class DllMapperProcessor implements DllBehavior {
 
    private DllMapper mapper;
 
    public DllMapperProcessor(DllMapper mapper) {
        this.mapper = mapper;
    }
 
    public abstract boolean support(String url);
 
    public int createViewBySql(String viewCreateSql) {
        return mapper.createViewBySql(viewCreateSql);
    }
 
 
    public int createTableBySql(String tableName, String attributeSql) {
        return mapper.createTableBySql(tableName, attributeSql);
    }
 
 
    public int commentTable(String tableName, String comment) {
        return mapper.commentTable(tableName, comment);
    }
 
 
    public int commentColumnTable(String tableName, String columnName, String comment) {
        return mapper.commentColumnTable(tableName, columnName, comment);
    }
 
 
    public int modifyTableBySql(String tableName, String attributeSql) {
        return mapper.modifyTableBySql(tableName, attributeSql);
    }
 
 
    public int addColumn2TableBySql(String tableName, String attributeSql) {
        return mapper.addColumn2TableBySql(tableName, attributeSql);
    }
 
 
    public int dropTable(String tableName) {
        return mapper.dropTable(tableName);
    }
 
 
    public int checkTableExist(String tableName) {
        return mapper.checkTableExist(tableName);
    }
 
 
    public int countAll(String tableName) {
        return mapper.countAll(tableName);
    }
 
    /**
     * 处理整数类型的sql转换
     *
     * @param attributeVO 属性
     * @return sql
     */
    @Override
    public String dealNumberCreateSql(OmdBtmTypeAttributeVO attributeVO) {
        StringBuilder snb = new StringBuilder().append(NUMBER + SPACE);
        dealDefaultAndNull(attributeVO);
        return snb.toString();
    }
 
    /**
     * 调用处理默认值和非空
     *
     * @param attributeVO 属性
     * @return 执行结果
     */
    @Override
    public String dealDefaultAndNull(OmdBtmTypeAttributeVO attributeVO) {
        String value = "";
        if (StringUtils.isNotBlank(attributeVO.getDefaultValue())) {
            value += dealDefaultValue(attributeVO.getDefaultValue());
        }
 
        if (!attributeVO.isNullableFlag()){
            value += dealNullableSql(attributeVO);
        }
        return value;
    }
 
    /**
     * 处理默认值
     *
     * @return sql
     */
    @Override
    public String dealDefaultValue(String defualValule) {
        return DEFAULT + SPACE + defualValule + SPACE;
    }
 
    /**
     * 处理浮点数类型的sql转换
     *
     * @param attributeVO 属性
     * @return sql
     */
    @Override
    public String dealDoubleCreateSql(OmdBtmTypeAttributeVO attributeVO) {
        Integer length = attributeVO.getPrecisionLength();
        if(length == null || length == 0){
            length = 20;
        }
        Integer scaleLength = attributeVO.getScaleLength();
        if(scaleLength == null){
            scaleLength = 2;
        }
        StringBuilder sb = new StringBuilder().append(NUMBER).append("(").append(String.valueOf(length.intValue()))
            .append(",").append(String.valueOf(scaleLength.intValue()))
            .append(")").append(SPACE);
        sb.append(dealDefaultAndNull(attributeVO));
        return sb.toString();
    }
 
    /**
     * 处理非空
     *
     * @return sql
     */
    @Override
    public String dealNullableSql(OmdBtmTypeAttributeVO attributeVO) {
        if (!attributeVO.isNullableFlag()) {
            return SPACE + "not null" + SPACE;
        }
        return "";
    }
 
    /**
     * 处理布尔类型的sql转换
     *
     * @param attributeVO 属性
     * @return sql
     */
    @Override
    public String dealBooleanCreateSql(OmdBtmTypeAttributeVO attributeVO) {
        return "VARCHAR (5) " + SPACE + dealDefaultAndNull(attributeVO);
    }
 
    /**
     * 处理日期时间类型的sql转换
     *
     * @param attributeVO 属性
     * @return sql
     */
    @Override
    public String dealDateTimeCreateSql(OmdBtmTypeAttributeVO attributeVO) {
        return "DATETIME" + SPACE + dealDefaultAndNull(attributeVO);
    }
 
    /**
     * 处理字符串类型的sql转换
     *
     * @param attributeVO 属性
     * @return sql
     */
    @Override
    public String dealStringCreateSql(OmdBtmTypeAttributeVO attributeVO) {
        StringBuilder sb = new StringBuilder();
        Integer length2 = attributeVO.getAttributeLength();
        if (length2 == null) {
            length2 = 250;
        }
        sb.append("VARCHAR").append("(").
            append(String.valueOf(length2.intValue())).append(")").append(SPACE);
        if (OID.equalsIgnoreCase(attributeVO.getId())) {
            sb.append(" primary key ");
            //强制设置OID为主键
        }
        sb.append(dealDefaultAndNull(attributeVO));
        return sb.toString();
    }
}