1821349743@qq.com
2023-02-20 93dd9bc3f16b0f626761ec624f2dc78037568897
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package com.product.data.entity;
 
import com.product.common.lang.StringUtils;
import com.product.core.entity.FieldSetEntity;
import com.product.data.config.CmnConst;
 
import java.util.Date;
 
/**
 * @Author cheng
 * @Date 2022/2/11 9:38
 * @Desc 执行记录
 */
public class SyncExecuteRecordEntity {
    /**
     * 同步任务uuid
     */
    private String syncTaskUuid;
    /**
     * 同步类型
     */
    private int syncType;
    /**
     * 开始索引位置
     */
    private int startPosition = -1;
    /**
     * 结束索引位置
     */
    private int endPosition = -1;
    /**
     * 增量数量
     */
    private int increaseNumber = 0;
    /**
     * 更新数量
     */
    private int updateNumber = 0;
    /**
     * 错误数量
     */
    private int errorNumber = 0;
    /**
     * 错误信息
     */
    private StringBuilder errorInfo;
    /**
     * 执行完成时间 (来源数据库系统时间戳)
     */
    private Object finishSourceTime;
 
 
    private FieldSetEntity logRecord;
    /**
     * 插入查询条件(增量)
     * 用于更新完成后使用
     */
    private String insertQueryFilter;
    /**
     * 更新查询条件(增量)
     * 用于更新完成后使用
     */
    private String updateQueryFilter;
 
 
    public SyncExecuteRecordEntity(String syncTaskUuid, int syncType) {
        this.syncTaskUuid = syncTaskUuid;
        this.syncType = syncType;
 
    }
 
    public String getRecordUuid() {
        return this.logRecord != null ? this.logRecord.getUUID() : null;
    }
 
    public SyncExecuteRecordEntity(FieldSetEntity fse) {
        this.logRecord = fse;
        this.syncTaskUuid = fse.getString("sync_task_uuid");
        this.syncType = fse.getInteger("sync_type");
        this.startPosition = fse.getInteger("start_position");
        this.endPosition = fse.getInteger("end_position");
        this.increaseNumber = fse.getInteger("increase_number");
        this.updateNumber = fse.getInteger("update_number");
        this.errorNumber = fse.getInteger("error_number");
        Date finish_source_time = fse.getDate("finish_source_time");
        if (finish_source_time != null) {
            this.finishSourceTime = fse.getObject("finish_source_time");
        }
        String error_info = fse.getString("error_info");
        if (!StringUtils.isEmpty(error_info)) {
            this.errorInfo = new StringBuilder(error_info);
        }
 
    }
 
    public String getInsertQueryFilter() {
        return insertQueryFilter;
    }
 
    public void setInsertQueryFilter(String insertQueryFilter) {
        this.insertQueryFilter = insertQueryFilter;
    }
 
    public String getUpdateQueryFilter() {
        return updateQueryFilter;
    }
 
    public void setUpdateQueryFilter(String updateQueryFilter) {
        this.updateQueryFilter = updateQueryFilter;
    }
 
    public void setStartPosition(int startPosition) {
        this.startPosition = startPosition;
        if (startPosition >= endPosition && endPosition != -1) {
            this.startPosition = endPosition;
        }
        if (logRecord != null) {
            this.logRecord.setValue("start_position", this.startPosition);
        }
    }
 
    public void setEndPosition(int endPosition) {
        this.endPosition = endPosition;
        if (startPosition >= endPosition) {
            startPosition = endPosition;
        }
        if (logRecord != null) {
            this.logRecord.setValue("end_position", this.endPosition);
        }
    }
 
    public FieldSetEntity getRecord(int endPosition, Long finishSourceTime) {
        this.endPosition = endPosition;
        if (startPosition >= endPosition) {
            startPosition = endPosition;
        }
        this.finishSourceTime = finishSourceTime;
        if (this.logRecord == null) {
            this.logRecord = new FieldSetEntity();
            this.logRecord.setTableName(CmnConst.TABLE_SYNC_MANAGER_LOG);
            this.logRecord.setValue(CmnConst.CREATED_BY, 1);
            this.logRecord.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
            this.logRecord.setValue(CmnConst.ORG_LEVEL_UUID, "/");
        } else {
            this.logRecord.setValue(CmnConst.UPDATED_BY, 1);
            this.logRecord.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
        }
        this.logRecord.setValue("sync_task_uuid", this.syncTaskUuid);
        this.logRecord.setValue("sync_type", this.syncType);
        this.logRecord.setValue("start_position", this.startPosition);
        this.logRecord.setValue("end_position", this.endPosition);
        this.logRecord.setValue("increase_number", this.increaseNumber);
        this.logRecord.setValue("update_number", this.updateNumber);
        this.logRecord.setValue("error_number", this.errorNumber);
        this.logRecord.setValue("error_info", this.errorInfo != null ? this.errorInfo.toString() : null);
        this.logRecord.setValue("finish_source_time", this.finishSourceTime);
        return this.logRecord;
    }
 
    public void addIncreaseNumber(int number) {
        this.increaseNumber += number;
        if (logRecord != null) {
            this.logRecord.setValue("increase_number", this.increaseNumber);
        }
    }
 
    public void addErrorNumber(int number) {
        this.errorNumber += number;
        if (logRecord != null) {
            this.logRecord.setValue("error_number", this.errorNumber);
        }
    }
 
    public void addUpdateNumber(int number) {
        this.updateNumber += number;
        if (logRecord != null) {
            this.logRecord.setValue("update_number", this.updateNumber);
        }
    }
 
    public void addErrorInfo(String errorMsg) {
        if (this.errorInfo == null) {
            errorInfo = new StringBuilder();
        }
        if (errorMsg.length() > 0) {
            errorInfo.append("\n");
        }
        errorInfo.append(errorMsg);
        if (logRecord != null) {
            this.logRecord.setValue("error_info", this.errorInfo != null ? this.errorInfo.toString() : null);
        }
 
    }
 
    public String getSyncTaskUuid() {
        return syncTaskUuid;
    }
 
    public int getSyncType() {
        return syncType;
    }
 
    public int getStartPosition() {
        return startPosition;
    }
 
    public int getEndPosition() {
        return endPosition;
    }
 
    public int getIncreaseNumber() {
        return increaseNumber;
    }
 
    public int getUpdateNumber() {
        return updateNumber;
    }
 
    public int getErrorNumber() {
        return errorNumber;
    }
 
    public StringBuilder getErrorInfo() {
        return errorInfo;
    }
 
    public Object getFinishSourceTime() {
        return finishSourceTime;
    }
 
    public FieldSetEntity getLogRecord() {
        return logRecord;
    }
}