合并分支 'test' 到 'master'
Test 查看合并请求 !1
正在显示
100 个修改的文件
包含
3253 行增加
和
132 行删除
| @@ -3,13 +3,12 @@ ENV APP_DIR $GOPATH/src/character-library-metadata-bastion | @@ -3,13 +3,12 @@ ENV APP_DIR $GOPATH/src/character-library-metadata-bastion | ||
| 3 | RUN mkdir -p $APP_DIR | 3 | RUN mkdir -p $APP_DIR |
| 4 | WORKDIR $APP_DIR/ | 4 | WORKDIR $APP_DIR/ |
| 5 | COPY ./pkg pkg | 5 | COPY ./pkg pkg |
| 6 | -COPY ./conf conf | 6 | +COPY ./config config |
| 7 | COPY ./go.mod go.mod | 7 | COPY ./go.mod go.mod |
| 8 | -COPY ./go.sum go.sum | ||
| 9 | COPY ./main.go main.go | 8 | COPY ./main.go main.go |
| 10 | RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"] | 9 | RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"] |
| 11 | ENV GO111MODULE on | 10 | ENV GO111MODULE on |
| 12 | -ENV GOPROXY https://goproxy.io | 11 | +ENV GOPROXY https://goproxy.cn |
| 13 | RUN ["go","mod","tidy"] | 12 | RUN ["go","mod","tidy"] |
| 14 | RUN ["ls"] | 13 | RUN ["ls"] |
| 15 | RUN ["go","build"] | 14 | RUN ["go","build"] |
| @@ -3,9 +3,450 @@ | @@ -3,9 +3,450 @@ | ||
| 3 | ## 源文件管理 | 3 | ## 源文件管理 |
| 4 | 4 | ||
| 5 | - 文件列表 - list | 5 | - 文件列表 - list |
| 6 | -- 上传 - 上传oss / 创建file | 6 | +- 上传 - 上传 oss / 创建 file |
| 7 | - 加载 - loadDataTable | 7 | - 加载 - loadDataTable |
| 8 | - 编辑 - editDataTable | 8 | - 编辑 - editDataTable |
| 9 | - 持久化 - flushDataTable | 9 | - 持久化 - flushDataTable |
| 10 | - 导出 - url | 10 | - 导出 - url |
| 11 | - 删除 - delete | 11 | - 删除 - delete |
| 12 | +- 操作日志 - log | ||
| 13 | + | ||
| 14 | +- editDataTable params 列表 | ||
| 15 | + | ||
| 16 | +### 加载表格数据 loadDataTable - 查询 | ||
| 17 | + | ||
| 18 | +```json | ||
| 19 | +{ | ||
| 20 | + "fileId": 1, | ||
| 21 | + "where": [ | ||
| 22 | + { | ||
| 23 | + "field": { | ||
| 24 | + "index": 1, | ||
| 25 | + "name": "产品名称" | ||
| 26 | + }, | ||
| 27 | + "in": ["a", "b"], | ||
| 28 | + "ex": ["c", "d"], | ||
| 29 | + "sort": ["a", "asc"] | ||
| 30 | + } | ||
| 31 | + ] | ||
| 32 | +} | ||
| 33 | +``` | ||
| 34 | + | ||
| 35 | +### 编辑表格 editDataTable | ||
| 36 | + | ||
| 37 | +```json | ||
| 38 | +{ | ||
| 39 | + "field": { | ||
| 40 | + "index": 1, | ||
| 41 | + "name": "产品名称" | ||
| 42 | + }, | ||
| 43 | + "operation": { | ||
| 44 | + "desc": ["拆分", "按字符数"], | ||
| 45 | + "code": "split_by_char_number" | ||
| 46 | + }, | ||
| 47 | + "params": [] | ||
| 48 | +} | ||
| 49 | +``` | ||
| 50 | + | ||
| 51 | +精简 | ||
| 52 | + | ||
| 53 | +```json | ||
| 54 | +{ | ||
| 55 | + "field": "产品名称", | ||
| 56 | + "desc": ["拆分", "按字符数"], | ||
| 57 | + "operationCode": "split_by_char_number", | ||
| 58 | + "params": [] | ||
| 59 | +} | ||
| 60 | +``` | ||
| 61 | + | ||
| 62 | +`params 列表` | ||
| 63 | + | ||
| 64 | +### 数据展示 | ||
| 65 | + | ||
| 66 | +```json | ||
| 67 | +{ | ||
| 68 | + "code": 0, | ||
| 69 | + "data": { | ||
| 70 | + "dataFields": [ | ||
| 71 | + { | ||
| 72 | + "index": 1, | ||
| 73 | + "name": "产品名称", | ||
| 74 | + "type": "string" | ||
| 75 | + }, | ||
| 76 | + { | ||
| 77 | + "index": 2, | ||
| 78 | + "name": "产品数量", | ||
| 79 | + "type": "int" | ||
| 80 | + } | ||
| 81 | + ], | ||
| 82 | + "dataRows": [ | ||
| 83 | + ["素面", 200], | ||
| 84 | + ["冻豆腐", 400], | ||
| 85 | + ["冻豆腐1", 300], | ||
| 86 | + ["冻豆2", "A"] | ||
| 87 | + ], | ||
| 88 | + "total": 100, | ||
| 89 | + "pageNumber": 1, | ||
| 90 | + "inValidCells": [ | ||
| 91 | + { | ||
| 92 | + "x": 1, | ||
| 93 | + "y": 3, | ||
| 94 | + "error": "不是一个有效的数值" | ||
| 95 | + } | ||
| 96 | + ] | ||
| 97 | + }, | ||
| 98 | + "msg": "ok" | ||
| 99 | +} | ||
| 100 | +``` | ||
| 101 | + | ||
| 102 | +## 表关联关系 | ||
| 103 | + | ||
| 104 | +- [x] 可追加数据的表列表 /tables/search-appended-list | ||
| 105 | +- [x] 校验文件列表 /files/search-verified-file | ||
| 106 | +- [x] 匹配方案列表 /mapping-rule-config/search | ||
| 107 | +- [x] 匹配方案主表 /mapping-rule-config/prepare //主表 校验表 主表字段 校验文件表字段 | ||
| 108 | +- [x] 匹配方案添加 /mapping-rule-config/ | ||
| 109 | +- [x] 匹配方案删除 /mapping-rule-config/:id | ||
| 110 | +- [x] 追加数据到表格 /append-data-to-table // 验证是否追加过 | ||
| 111 | +- [ ] 取消校验中的文件 /cancel-verifying-file // | ||
| 112 | + | ||
| 113 | +- [x] 表结构更新 /tables/update-table-struct | ||
| 114 | +- [x] 表结构添加 /tables/add-table-struct | ||
| 115 | +- [x] 分表列表 /tables/search | ||
| 116 | +- [x] 表复制 /tables/copy-data-table | ||
| 117 | +- [x] 表删除 /tables/:id // 若是删除主表,需级联删除关联的分表,删除内容包括表数据及表结构;? 分表的副表是否要删除 | ||
| 118 | +- [x] 表详情 /tables/:id // 表结构 | ||
| 119 | +- [x] 表更新 /tables/:id // 表结构、分表才可以编辑 | ||
| 120 | + | ||
| 121 | +- [x] 日志搜索 /log/search | ||
| 122 | +- [x] 校验步骤日志 /log/verified-step-Log | ||
| 123 | + | ||
| 124 | +## 数据预览 | ||
| 125 | + | ||
| 126 | +- [x] 表数据预览(格式) /table/preview | ||
| 127 | +- [x] 表数据自定义查询 /table/preview where conditions 升序、降序 包含、不包含 | ||
| 128 | +- [x] 表数据字段可选值搜索 /table/field-optional 文本匹配 | ||
| 129 | +- [x] 表数据更新、添加、删除 /table/row-data-mutation | ||
| 130 | +- [x] 表数据导出 /table/export-table | ||
| 131 | + | ||
| 132 | +## 数据验证 | ||
| 133 | + | ||
| 134 | +- [x] 文件验证 /data/edit-data-table | ||
| 135 | + | ||
| 136 | +## 底层字库接口 | ||
| 137 | + | ||
| 138 | +- [x] 数据预览 1 | ||
| 139 | +- [x] 表格编辑 1 | ||
| 140 | +- [x] 保存校验文件 (文件地址) 1 | ||
| 141 | +- [x] 生成主表 1 | ||
| 142 | +- [x] 表复制 (副表)1 | ||
| 143 | +- [x] 追加数据 (主表、副表) | ||
| 144 | +- [ ] 表删除 (主表、副表)~~、分表~~ | ||
| 145 | +- [x] 表拆分 1 | ||
| 146 | +- [x] 更新表结构(分表)1 | ||
| 147 | +- [x] 编辑、添加、删除表数据(副表) 1 | ||
| 148 | +- [ ] 取消校验 | ||
| 149 | + | ||
| 150 | +## 定时作业 | ||
| 151 | + | ||
| 152 | +- [x] 隔天清理校验中的文件 | ||
| 153 | +- [x] 隔天清理 public 临时文件 | ||
| 154 | + | ||
| 155 | +## 表数据导出 | ||
| 156 | + | ||
| 157 | +- [ ] 加锁,只允许当前用户同时只能发起一次导出命令 ,3min 过期 | ||
| 158 | +- [ ] 单次拉取数量 MR | ||
| 159 | + - [ ] 100W .. | ||
| 160 | + - [ ] 50W 120s 读取数据库:30s 保存文件:10s 下载:30M/500K=60S;RAR 压缩 24M/500k=50S | ||
| 161 | + - [ ] 20W .. | ||
| 162 | + - [ ] 10W .. | ||
| 163 | +- [ ] 保存单个文件、压缩 | 保存多个文件、压缩 | ||
| 164 | + | ||
| 165 | +## 讨论事项 | ||
| 166 | + | ||
| 167 | +- [ ] 校验动作,参数模型讨论 | ||
| 168 | +- [ ] 校验日志错误(标红) | ||
| 169 | +- [ ] 校验完毕应答实体,类型修改即使错误,也要返回修改完毕的表 | ||
| 170 | + | ||
| 171 | +## 参数说明 | ||
| 172 | + | ||
| 173 | +### 通用格式 | ||
| 174 | + | ||
| 175 | +```json | ||
| 176 | +{ | ||
| 177 | + "objectId": 1, | ||
| 178 | + "processFields": [], | ||
| 179 | + "action": "xx", | ||
| 180 | + "params": {} | ||
| 181 | +} | ||
| 182 | +``` | ||
| 183 | + | ||
| 184 | +processFields:操作字段 | ||
| 185 | + | ||
| 186 | +### 常规 | ||
| 187 | + | ||
| 188 | +1. 删除列 | ||
| 189 | + | ||
| 190 | +```json | ||
| 191 | +{ | ||
| 192 | + "action": "remove-column", | ||
| 193 | + "params": {} | ||
| 194 | +} | ||
| 195 | +``` | ||
| 196 | + | ||
| 197 | +2. 复制列 | ||
| 198 | + | ||
| 199 | +```json | ||
| 200 | +{ | ||
| 201 | + "action": "copy-column", | ||
| 202 | + "params": {} | ||
| 203 | +} | ||
| 204 | +``` | ||
| 205 | + | ||
| 206 | +3. 重命名 | ||
| 207 | + | ||
| 208 | +```json | ||
| 209 | +{ | ||
| 210 | + "action": "rename-column", | ||
| 211 | + "params": { | ||
| 212 | + "newColumnName": "新的列名称" | ||
| 213 | + } | ||
| 214 | +} | ||
| 215 | +``` | ||
| 216 | + | ||
| 217 | +4. 替换值 | ||
| 218 | + | ||
| 219 | +```json | ||
| 220 | +{ | ||
| 221 | + "action": "replace-column", | ||
| 222 | + "params": { | ||
| 223 | + "replaceMethod": "replace", | ||
| 224 | + "searchValue": "搜索值", | ||
| 225 | + "replaceValue": "替换值" | ||
| 226 | + } | ||
| 227 | +} | ||
| 228 | +``` | ||
| 229 | + | ||
| 230 | +参数说明 | ||
| 231 | + | ||
| 232 | +``` | ||
| 233 | +replaceMethod: 替换方法(1.replace:替换值 2.add-prefix:添加前缀 3.add-postfix:添加后缀 4.remove-prefix:去除前缀 5.remove-postfix:去除后缀 6.remove-chars:去除固定字符 7.clean:清除) | ||
| 234 | +searchValue: 搜索值-replace,remove-prefix,remove-postfix,remove-chars参数 | ||
| 235 | +replaceValue: 替换值-replace,add-prefix,add-postfix参数 | ||
| 236 | +``` | ||
| 237 | + | ||
| 238 | +### 格式 formatMethod | ||
| 239 | + | ||
| 240 | +1. 大写 | ||
| 241 | + | ||
| 242 | +```json | ||
| 243 | +{ | ||
| 244 | + "action": "format-column", | ||
| 245 | + "params": { | ||
| 246 | + "formatMethod": "upper" | ||
| 247 | + } | ||
| 248 | +} | ||
| 249 | +``` | ||
| 250 | + | ||
| 251 | +参数说明 | ||
| 252 | + | ||
| 253 | +``` | ||
| 254 | +formatMethod: 格式化方法(1.upper:大写2.lower:小写3.capitalize:首字母大写4.strip:修整) | ||
| 255 | +``` | ||
| 256 | + | ||
| 257 | +2. 小写 | ||
| 258 | + | ||
| 259 | +```json | ||
| 260 | +{ | ||
| 261 | + "action": "format-column", | ||
| 262 | + "params": { | ||
| 263 | + "formatMethod": "lower" | ||
| 264 | + } | ||
| 265 | +} | ||
| 266 | +``` | ||
| 267 | + | ||
| 268 | +3. 首字母大写 | ||
| 269 | + | ||
| 270 | +```json | ||
| 271 | +{ | ||
| 272 | + "action": "format-column", | ||
| 273 | + "params": { | ||
| 274 | + "formatMethod": "capitalize" | ||
| 275 | + } | ||
| 276 | +} | ||
| 277 | +``` | ||
| 278 | + | ||
| 279 | +4. 清除 | ||
| 280 | + | ||
| 281 | +```json | ||
| 282 | +{ | ||
| 283 | + "action": "replace-column", | ||
| 284 | + "params": { | ||
| 285 | + "replaceMethod": "clean" | ||
| 286 | + } | ||
| 287 | +} | ||
| 288 | +``` | ||
| 289 | + | ||
| 290 | +5. 修整 | ||
| 291 | + | ||
| 292 | +```json | ||
| 293 | +{ | ||
| 294 | + "action": "format-column", | ||
| 295 | + "params": { | ||
| 296 | + "formatMethod": "strip" | ||
| 297 | + } | ||
| 298 | +} | ||
| 299 | +``` | ||
| 300 | + | ||
| 301 | +6. 添加前缀 | ||
| 302 | + | ||
| 303 | +```json | ||
| 304 | +{ | ||
| 305 | + "action": "replace-column", | ||
| 306 | + "params": { | ||
| 307 | + "replaceMethod": "add-prefix", | ||
| 308 | + "replaceValue": "前缀值" | ||
| 309 | + } | ||
| 310 | +} | ||
| 311 | +``` | ||
| 312 | + | ||
| 313 | +7. 添加后缀 | ||
| 314 | + | ||
| 315 | +```json | ||
| 316 | +{ | ||
| 317 | + "action": "replace-column", | ||
| 318 | + "params": { | ||
| 319 | + "replaceMethod": "add-postfix", | ||
| 320 | + "replaceValue": "后缀值" | ||
| 321 | + } | ||
| 322 | +} | ||
| 323 | +``` | ||
| 324 | + | ||
| 325 | +8. 去除前缀 | ||
| 326 | + | ||
| 327 | +```json | ||
| 328 | +{ | ||
| 329 | + "action": "replace-column", | ||
| 330 | + "params": { | ||
| 331 | + "replaceMethod": "remove-prefix", | ||
| 332 | + "searchValue": "前缀值" | ||
| 333 | + } | ||
| 334 | +} | ||
| 335 | +``` | ||
| 336 | + | ||
| 337 | +9. 去除后最 | ||
| 338 | + | ||
| 339 | +```json | ||
| 340 | +{ | ||
| 341 | + "action": "replace-column", | ||
| 342 | + "params": { | ||
| 343 | + "replaceMethod": "remove-postfix", | ||
| 344 | + "searchValue": "后缀值" | ||
| 345 | + } | ||
| 346 | +} | ||
| 347 | +``` | ||
| 348 | + | ||
| 349 | +10. 去除固定字符 | ||
| 350 | + | ||
| 351 | +```json | ||
| 352 | +{ | ||
| 353 | + "action": "replace-column", | ||
| 354 | + "params": { | ||
| 355 | + "replaceMethod": "remove-chars", | ||
| 356 | + "searchValue": "字符" | ||
| 357 | + } | ||
| 358 | +} | ||
| 359 | +``` | ||
| 360 | + | ||
| 361 | +### 拆分 split-column | ||
| 362 | + | ||
| 363 | +1. 按分隔符 | ||
| 364 | + | ||
| 365 | +```json | ||
| 366 | +{ | ||
| 367 | + "action": "split-column", | ||
| 368 | + "params": { | ||
| 369 | + "splitMethod": "separator", | ||
| 370 | + "separator": "|", | ||
| 371 | + "splitDirection": "left", | ||
| 372 | + "splitCount": "1" | ||
| 373 | + } | ||
| 374 | +} | ||
| 375 | +``` | ||
| 376 | + | ||
| 377 | +参数说明 | ||
| 378 | + | ||
| 379 | +``` | ||
| 380 | +separator: 分割符号 ‘|’ | ||
| 381 | +splitDirection: 拆分方向(1.left:从左边 2.right:从右边) | ||
| 382 | +splitCount: 拆分次数 | ||
| 383 | +``` | ||
| 384 | + | ||
| 385 | +2. 按字符数 | ||
| 386 | + | ||
| 387 | +```json | ||
| 388 | +{ | ||
| 389 | + "action": "split-column", | ||
| 390 | + "params": { | ||
| 391 | + "splitMethod": "char-length", | ||
| 392 | + "splitDirection": "left", | ||
| 393 | + "charLength": "10", | ||
| 394 | + "splitCount": "1" | ||
| 395 | + } | ||
| 396 | +} | ||
| 397 | +``` | ||
| 398 | + | ||
| 399 | +参数说明 | ||
| 400 | + | ||
| 401 | +``` | ||
| 402 | +charLength: 字符长度-char-length专属参数 | ||
| 403 | +splitDirection: 拆分方向(1.left:从左边 2.right:从右边) | ||
| 404 | +splitCount: 拆分次数 (拆分策略是重复时:值0或者非1整数) | ||
| 405 | +``` | ||
| 406 | + | ||
| 407 | +### 提取 extract-column | ||
| 408 | + | ||
| 409 | +1. 按日期 | ||
| 410 | + | ||
| 411 | +```json | ||
| 412 | +{ | ||
| 413 | + "action": "extract-column", | ||
| 414 | + "params": { | ||
| 415 | + "extractMethod": "by-date" | ||
| 416 | + } | ||
| 417 | +} | ||
| 418 | +``` | ||
| 419 | + | ||
| 420 | +参数说明 | ||
| 421 | + | ||
| 422 | +``` | ||
| 423 | +extractMethod: 提取方法(1.by-date:按日期 2.by-number:按数值) | ||
| 424 | +``` | ||
| 425 | + | ||
| 426 | +2. 按数值 action | ||
| 427 | + | ||
| 428 | +```json | ||
| 429 | +{ | ||
| 430 | + "action": "extract-column", | ||
| 431 | + "params": { | ||
| 432 | + "extractMethod": "by-number" | ||
| 433 | + } | ||
| 434 | +} | ||
| 435 | +``` | ||
| 436 | + | ||
| 437 | +### 修改字段类型 | ||
| 438 | + | ||
| 439 | +```json | ||
| 440 | +{ | ||
| 441 | + "action": "convert-column-type", | ||
| 442 | + "params": { | ||
| 443 | + "convertType": "STRING" | ||
| 444 | + } | ||
| 445 | +} | ||
| 446 | +``` | ||
| 447 | + | ||
| 448 | +参数说明 | ||
| 449 | + | ||
| 450 | +``` | ||
| 451 | +convertType:转换类型 STRING 数值: INT 小数: FLOAT 日期: DATE 时间: DATETIME | ||
| 452 | +``` |
| 1 | -POSTGRESQL_DB_NAME = allied_creation_dev | 1 | +POSTGRESQL_DB_NAME = allied_creation_test |
| 2 | POSTGRESQL_HOST = 114.55.200.59 | 2 | POSTGRESQL_HOST = 114.55.200.59 |
| 3 | POSTGRESQL_PORT = 31543 | 3 | POSTGRESQL_PORT = 31543 |
| 4 | POSTGRESQL_USER = postgres | 4 | POSTGRESQL_USER = postgres |
| @@ -9,3 +9,12 @@ HTTP_PORT = 8081 | @@ -9,3 +9,12 @@ HTTP_PORT = 8081 | ||
| 9 | ENABLE_KAFKA_LOG11 = true | 9 | ENABLE_KAFKA_LOG11 = true |
| 10 | HTTPS_PORT = 8143 | 10 | HTTPS_PORT = 8143 |
| 11 | ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com | 11 | ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com |
| 12 | +# AUTH_SERVER_HOST = http://127.0.0.1:8081 | ||
| 13 | +BYTE_CORE_HOST = http://47.97.5.102:8303 | ||
| 14 | +METADATA_BASTION_HOST = http://106.75.231.90:9999 | ||
| 15 | + | ||
| 16 | +STARROCKS_DB_NAME = character_library | ||
| 17 | +STARROCKS_USER = root | ||
| 18 | +STARROCKS_PASSWORD = eagle1010 | ||
| 19 | +STARROCKS_HOST = 220.250.41.79 | ||
| 20 | +STARROCKS_PORT = 9030 |
deploy/db/db_script_v1.0.1.sql
0 → 100644
| 1 | +/*1.初始化索引*/ | ||
| 2 | + | ||
| 3 | +/*files*/ | ||
| 4 | +CREATE INDEX IF NOT EXISTS idx_files_company_id_file_type ON metadata.files USING btree((context->>'companyId'),file_type); | ||
| 5 | +CREATE INDEX IF NOT EXISTS idx_files_source_file_id ON metadata.files USING btree(source_file_id); | ||
| 6 | + | ||
| 7 | +/*tables*/ | ||
| 8 | +CREATE INDEX IF NOT EXISTS idx_tables_company_id_table_type ON metadata.tables USING btree((context->>'companyId'),table_type); | ||
| 9 | +CREATE INDEX IF NOT EXISTS idx_tables_parent_id ON metadata.tables USING btree(parent_id); | ||
| 10 | + | ||
| 11 | +/*logs*/ | ||
| 12 | +CREATE INDEX IF NOT EXISTS idx_logs_company_id_log_type_source_id ON metadata.logs USING btree((context->>'companyId'),log_type,source_id); | ||
| 13 | +CREATE INDEX IF NOT EXISTS idx_logs_company_id_object_name ON metadata.logs USING btree((context->>'companyId'),object_name); | ||
| 14 | +CREATE INDEX IF NOT EXISTS idx_logs_company_id_object_type ON metadata.logs USING btree((context->>'companyId'),object_type); | ||
| 15 | +CREATE INDEX IF NOT EXISTS idx_logs_company_id_operation_type ON metadata.logs USING btree((context->>'companyId'),operation_type); | ||
| 16 | +CREATE INDEX IF NOT EXISTS idx_logs_company_id_content ON metadata.logs USING btree((context->>'companyId'),content); | ||
| 17 | +CREATE INDEX IF NOT EXISTS idx_logs_company_id_operator_name ON metadata.logs USING btree((context->>'companyId'),operator_name); | ||
| 18 | +CREATE INDEX IF NOT EXISTS idx_logs_company_id_created_at ON metadata.logs USING btree((context->>'companyId'),created_at); | ||
| 19 | + | ||
| 20 | +/*mapping_rules*/ | ||
| 21 | +CREATE INDEX IF NOT EXISTS idx_mapping_rules_company_id_table_id_file_id ON metadata.mapping_rules USING btree((context->>'companyId'),table_id,file_id); |
| @@ -2,7 +2,7 @@ apiVersion: v1 | @@ -2,7 +2,7 @@ apiVersion: v1 | ||
| 2 | kind: Service | 2 | kind: Service |
| 3 | metadata: | 3 | metadata: |
| 4 | name: character-library-metadata-bastion | 4 | name: character-library-metadata-bastion |
| 5 | - namespace: <replace-your-k8s-namespace> | 5 | + namespace: mmm-suplus-dev |
| 6 | labels: | 6 | labels: |
| 7 | k8s-app: character-library-metadata-bastion | 7 | k8s-app: character-library-metadata-bastion |
| 8 | spec: | 8 | spec: |
| @@ -17,7 +17,7 @@ apiVersion: extensions/v1beta1 | @@ -17,7 +17,7 @@ apiVersion: extensions/v1beta1 | ||
| 17 | kind: Deployment | 17 | kind: Deployment |
| 18 | metadata: | 18 | metadata: |
| 19 | name: character-library-metadata-bastion | 19 | name: character-library-metadata-bastion |
| 20 | - namespace: <replace-your-k8s-namespace> | 20 | + namespace: mmm-suplus-dev |
| 21 | labels: | 21 | labels: |
| 22 | k8s-app: character-library-metadata-bastion | 22 | k8s-app: character-library-metadata-bastion |
| 23 | spec: | 23 | spec: |
| @@ -52,12 +52,69 @@ spec: | @@ -52,12 +52,69 @@ spec: | ||
| 52 | - mountPath: /opt/logs | 52 | - mountPath: /opt/logs |
| 53 | name: accesslogs | 53 | name: accesslogs |
| 54 | env: | 54 | env: |
| 55 | + - name: POSTGRESQL_DB_NAME | ||
| 56 | + valueFrom: | ||
| 57 | + configMapKeyRef: | ||
| 58 | + name: suplus-config | ||
| 59 | + key: postgresqlalliedcreation.dbname | ||
| 60 | + - name: POSTGRESQL_USER | ||
| 61 | + valueFrom: | ||
| 62 | + configMapKeyRef: | ||
| 63 | + name: suplus-config | ||
| 64 | + key: postgresql.user | ||
| 65 | + - name: POSTGRESQL_PASSWORD | ||
| 66 | + valueFrom: | ||
| 67 | + configMapKeyRef: | ||
| 68 | + name: suplus-config | ||
| 69 | + key: postgresql.password | ||
| 70 | + - name: POSTGRESQL_HOST | ||
| 71 | + valueFrom: | ||
| 72 | + configMapKeyRef: | ||
| 73 | + name: suplus-config | ||
| 74 | + key: postgresql.host | ||
| 75 | + - name: POSTGRESQL_PORT | ||
| 76 | + valueFrom: | ||
| 77 | + configMapKeyRef: | ||
| 78 | + name: suplus-config | ||
| 79 | + key: postgresql.port | ||
| 80 | + - name: REDIS_HOST | ||
| 81 | + valueFrom: | ||
| 82 | + configMapKeyRef: | ||
| 83 | + name: suplus-config | ||
| 84 | + key: redis.ip | ||
| 85 | + - name: REDIS_PORT | ||
| 86 | + valueFrom: | ||
| 87 | + configMapKeyRef: | ||
| 88 | + name: suplus-config | ||
| 89 | + key: redis.port | ||
| 90 | + - name: REDIS_AUTH | ||
| 91 | + value: "" | ||
| 55 | - name: LOG_LEVEL | 92 | - name: LOG_LEVEL |
| 56 | value: "debug" | 93 | value: "debug" |
| 57 | - name: ERROR_BASE_CODE | 94 | - name: ERROR_BASE_CODE |
| 58 | value: "1" | 95 | value: "1" |
| 59 | - name: ERROR_BASE_CODE_MULTIPLE | 96 | - name: ERROR_BASE_CODE_MULTIPLE |
| 60 | - value: "1000" | 97 | + value: "2000" |
| 98 | + - name: ENABLE_KAFKA_LOG | ||
| 99 | + value: "true" | ||
| 100 | + - name: HTTP_PORT | ||
| 101 | + value: "8082" | ||
| 102 | + - name: SERVICE_ENV | ||
| 103 | + value: "dev" | ||
| 104 | + - name: METADATA_BASTION_HOST | ||
| 105 | + value: "http://character-library-metadata-bastion-dev.fjmaimaimai.com" | ||
| 106 | + - name: BYTE_CORE_HOST | ||
| 107 | + value: "http://47.97.5.102:8303" | ||
| 108 | + - name: STARROCKS_HOST | ||
| 109 | + value: "220.250.41.79" | ||
| 110 | + - name: STARROCKS_PORT | ||
| 111 | + value: "9030" | ||
| 112 | + - name: STARROCKS_DB_NAME | ||
| 113 | + value: "character_library_standard" | ||
| 114 | + - name: STARROCKS_USER | ||
| 115 | + value: "root" | ||
| 116 | + - name: STARROCKS_PASSWORD | ||
| 117 | + value: "eagle1010" | ||
| 61 | volumes: | 118 | volumes: |
| 62 | - name: accesslogs | 119 | - name: accesslogs |
| 63 | emptyDir: {} | 120 | emptyDir: {} |
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | export PATH=/root/local/bin:$PATH | 2 | export PATH=/root/local/bin:$PATH |
| 3 | -kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | 3 | +kubectl -n mmm-suplus-dev get pods | grep -q character-library-metadata-bastion |
| 4 | if [ "$?" == "1" ];then | 4 | if [ "$?" == "1" ];then |
| 5 | kubectl create -f /tmp/dev/character-library-metadata-bastion/character-library-metadata-bastion.yaml --record | 5 | kubectl create -f /tmp/dev/character-library-metadata-bastion/character-library-metadata-bastion.yaml --record |
| 6 | - kubectl -n <replace-your-k8s-namespace> get svc | grep -q character-library-metadata-bastion | 6 | + kubectl -n mmm-suplus-dev get svc | grep -q character-library-metadata-bastion |
| 7 | if [ "$?" == "0" ];then | 7 | if [ "$?" == "0" ];then |
| 8 | echo "character-library-metadata-bastion service install success!" | 8 | echo "character-library-metadata-bastion service install success!" |
| 9 | else | 9 | else |
| 10 | echo "character-library-metadata-bastion service install fail!" | 10 | echo "character-library-metadata-bastion service install fail!" |
| 11 | fi | 11 | fi |
| 12 | - kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | 12 | + kubectl -n mmm-suplus-dev get pods | grep -q character-library-metadata-bastion |
| 13 | if [ "$?" == "0" ];then | 13 | if [ "$?" == "0" ];then |
| 14 | echo "character-library-metadata-bastion deployment install success!" | 14 | echo "character-library-metadata-bastion deployment install success!" |
| 15 | else | 15 | else |
| @@ -17,24 +17,24 @@ if [ "$?" == "1" ];then | @@ -17,24 +17,24 @@ if [ "$?" == "1" ];then | ||
| 17 | fi | 17 | fi |
| 18 | else | 18 | else |
| 19 | kubectl delete -f /tmp/dev/character-library-metadata-bastion/character-library-metadata-bastion.yaml | 19 | kubectl delete -f /tmp/dev/character-library-metadata-bastion/character-library-metadata-bastion.yaml |
| 20 | - kubectl -n <replace-your-k8s-namespace> get svc | grep -q character-library-metadata-bastion | 20 | + kubectl -n mmm-suplus-dev get svc | grep -q character-library-metadata-bastion |
| 21 | while [ "$?" == "0" ] | 21 | while [ "$?" == "0" ] |
| 22 | do | 22 | do |
| 23 | - kubectl -n <replace-your-k8s-namespace> get svc | grep -q character-library-metadata-bastion | 23 | + kubectl -n mmm-suplus-dev get svc | grep -q character-library-metadata-bastion |
| 24 | done | 24 | done |
| 25 | - kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | 25 | + kubectl -n mmm-suplus-dev get pods | grep -q character-library-metadata-bastion |
| 26 | while [ "$?" == "0" ] | 26 | while [ "$?" == "0" ] |
| 27 | do | 27 | do |
| 28 | - kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | 28 | + kubectl -n mmm-suplus-dev get pods | grep -q character-library-metadata-bastion |
| 29 | done | 29 | done |
| 30 | kubectl create -f /tmp/dev/character-library-metadata-bastion/character-library-metadata-bastion.yaml --record | 30 | kubectl create -f /tmp/dev/character-library-metadata-bastion/character-library-metadata-bastion.yaml --record |
| 31 | - kubectl -n <replace-your-k8s-namespace> get svc | grep -q character-library-metadata-bastion | 31 | + kubectl -n mmm-suplus-dev get svc | grep -q character-library-metadata-bastion |
| 32 | if [ "$?" == "0" ];then | 32 | if [ "$?" == "0" ];then |
| 33 | echo "character-library-metadata-bastion service update success!" | 33 | echo "character-library-metadata-bastion service update success!" |
| 34 | else | 34 | else |
| 35 | echo "character-library-metadata-bastion service update fail!" | 35 | echo "character-library-metadata-bastion service update fail!" |
| 36 | fi | 36 | fi |
| 37 | - kubectl -n <replace-your-k8s-namespace> get pods | grep -q character-library-metadata-bastion | 37 | + kubectl -n mmm-suplus-dev get pods | grep -q character-library-metadata-bastion |
| 38 | if [ "$?" == "0" ];then | 38 | if [ "$?" == "0" ];then |
| 39 | echo "character-library-metadata-bastion deployment update success!" | 39 | echo "character-library-metadata-bastion deployment update success!" |
| 40 | else | 40 | else |
deploy/k8s/test/.gitkeep
0 → 100644
| 1 | +apiVersion: v1 | ||
| 2 | +kind: Service | ||
| 3 | +metadata: | ||
| 4 | + name: character-library-metadata-bastion | ||
| 5 | + namespace: mmm-suplus-test | ||
| 6 | + labels: | ||
| 7 | + k8s-app: character-library-metadata-bastion | ||
| 8 | +spec: | ||
| 9 | + ports: | ||
| 10 | + - name: "http" | ||
| 11 | + port: 80 | ||
| 12 | + targetPort: 8082 | ||
| 13 | + selector: | ||
| 14 | + k8s-app: character-library-metadata-bastion | ||
| 15 | +--- | ||
| 16 | +apiVersion: extensions/v1beta1 | ||
| 17 | +kind: Deployment | ||
| 18 | +metadata: | ||
| 19 | + name: character-library-metadata-bastion | ||
| 20 | + namespace: mmm-suplus-test | ||
| 21 | + labels: | ||
| 22 | + k8s-app: character-library-metadata-bastion | ||
| 23 | +spec: | ||
| 24 | + replicas: 1 | ||
| 25 | + template: | ||
| 26 | + metadata: | ||
| 27 | + labels: | ||
| 28 | + k8s-app: character-library-metadata-bastion | ||
| 29 | + spec: | ||
| 30 | + affinity: | ||
| 31 | + nodeAffinity: | ||
| 32 | + preferredDuringSchedulingIgnoredDuringExecution: | ||
| 33 | + - preference: {} | ||
| 34 | + weight: 100 | ||
| 35 | + requiredDuringSchedulingIgnoredDuringExecution: | ||
| 36 | + nodeSelectorTerms: | ||
| 37 | + - matchExpressions: | ||
| 38 | + - key: kubernetes.io/hostname | ||
| 39 | + operator: In | ||
| 40 | + values: | ||
| 41 | + - cn-hangzhou.i-bp1djh1xn7taumbue1ze | ||
| 42 | + - cn-hangzhou.i-bp1djh1xn7taumbue1zd | ||
| 43 | + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb | ||
| 44 | + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy | ||
| 45 | + containers: | ||
| 46 | + - name: character-library-metadata-bastion | ||
| 47 | + image: 192.168.0.243:5000/mmm/character-library-metadata-bastion:dev | ||
| 48 | + imagePullPolicy: Always | ||
| 49 | + ports: | ||
| 50 | + - containerPort: 8082 | ||
| 51 | + volumeMounts: | ||
| 52 | + - mountPath: /opt/logs | ||
| 53 | + name: accesslogs | ||
| 54 | + env: | ||
| 55 | + - name: POSTGRESQL_DB_NAME | ||
| 56 | + valueFrom: | ||
| 57 | + configMapKeyRef: | ||
| 58 | + name: suplus-config | ||
| 59 | + key: postgresqlalliedcreation.dbname | ||
| 60 | + - name: POSTGRESQL_USER | ||
| 61 | + valueFrom: | ||
| 62 | + configMapKeyRef: | ||
| 63 | + name: suplus-config | ||
| 64 | + key: postgresql.user | ||
| 65 | + - name: POSTGRESQL_PASSWORD | ||
| 66 | + valueFrom: | ||
| 67 | + configMapKeyRef: | ||
| 68 | + name: suplus-config | ||
| 69 | + key: postgresql.password | ||
| 70 | + - name: POSTGRESQL_HOST | ||
| 71 | + valueFrom: | ||
| 72 | + configMapKeyRef: | ||
| 73 | + name: suplus-config | ||
| 74 | + key: postgresql.host | ||
| 75 | + - name: POSTGRESQL_PORT | ||
| 76 | + valueFrom: | ||
| 77 | + configMapKeyRef: | ||
| 78 | + name: suplus-config | ||
| 79 | + key: postgresql.port | ||
| 80 | + - name: REDIS_HOST | ||
| 81 | + valueFrom: | ||
| 82 | + configMapKeyRef: | ||
| 83 | + name: suplus-config | ||
| 84 | + key: redis.ip | ||
| 85 | + - name: REDIS_PORT | ||
| 86 | + valueFrom: | ||
| 87 | + configMapKeyRef: | ||
| 88 | + name: suplus-config | ||
| 89 | + key: redis.port | ||
| 90 | + - name: REDIS_AUTH | ||
| 91 | + value: "" | ||
| 92 | + - name: LOG_LEVEL | ||
| 93 | + value: "debug" | ||
| 94 | + - name: ERROR_BASE_CODE | ||
| 95 | + value: "1" | ||
| 96 | + - name: ERROR_BASE_CODE_MULTIPLE | ||
| 97 | + value: "2000" | ||
| 98 | + - name: ENABLE_KAFKA_LOG | ||
| 99 | + value: "false" | ||
| 100 | + - name: HTTP_PORT | ||
| 101 | + value: "8082" | ||
| 102 | + - name: SERVICE_ENV | ||
| 103 | + value: "test" | ||
| 104 | + - name: METADATA_BASTION_HOST | ||
| 105 | + value: "http://character-library-metadata-bastion-test.fjmaimaimai.com" | ||
| 106 | + - name: BYTE_CORE_HOST | ||
| 107 | + value: "http://47.97.5.102:8303" | ||
| 108 | + - name: STARROCKS_HOST | ||
| 109 | + value: "220.250.41.79" | ||
| 110 | + - name: STARROCKS_PORT | ||
| 111 | + value: "9030" | ||
| 112 | + - name: STARROCKS_DB_NAME | ||
| 113 | + value: "character_library" | ||
| 114 | + - name: STARROCKS_USER | ||
| 115 | + value: "root" | ||
| 116 | + - name: STARROCKS_PASSWORD | ||
| 117 | + value: "eagle1010" | ||
| 118 | + volumes: | ||
| 119 | + - name: accesslogs | ||
| 120 | + emptyDir: {} |
deploy/k8s/test/install.sh
0 → 100644
| 1 | +#!/bin/bash | ||
| 2 | +export PATH=/root/local/bin:$PATH | ||
| 3 | +kubectl -n mmm-suplus-test get pods | grep -q character-library-metadata-bastion | ||
| 4 | +if [ "$?" == "1" ];then | ||
| 5 | + kubectl create -f /tmp/test/character-library-metadata-bastion/character-library-metadata-bastion.yaml --record | ||
| 6 | + kubectl -n mmm-suplus-test get svc | grep -q character-library-metadata-bastion | ||
| 7 | + if [ "$?" == "0" ];then | ||
| 8 | + echo "character-library-metadata-bastion service install success!" | ||
| 9 | + else | ||
| 10 | + echo "character-library-metadata-bastion service install fail!" | ||
| 11 | + fi | ||
| 12 | + kubectl -n mmm-suplus-test get pods | grep -q character-library-metadata-bastion | ||
| 13 | + if [ "$?" == "0" ];then | ||
| 14 | + echo "character-library-metadata-bastion deployment install success!" | ||
| 15 | + else | ||
| 16 | + echo "character-library-metadata-bastion deployment install fail!" | ||
| 17 | + fi | ||
| 18 | +else | ||
| 19 | + kubectl delete -f /tmp/test/character-library-metadata-bastion/character-library-metadata-bastion.yaml | ||
| 20 | + kubectl -n mmm-suplus-test get svc | grep -q character-library-metadata-bastion | ||
| 21 | + while [ "$?" == "0" ] | ||
| 22 | + do | ||
| 23 | + kubectl -n mmm-suplus-test get svc | grep -q character-library-metadata-bastion | ||
| 24 | + done | ||
| 25 | + kubectl -n mmm-suplus-test get pods | grep -q character-library-metadata-bastion | ||
| 26 | + while [ "$?" == "0" ] | ||
| 27 | + do | ||
| 28 | + kubectl -n mmm-suplus-test get pods | grep -q character-library-metadata-bastion | ||
| 29 | + done | ||
| 30 | + kubectl create -f /tmp/test/character-library-metadata-bastion/character-library-metadata-bastion.yaml --record | ||
| 31 | + kubectl -n mmm-suplus-test get svc | grep -q character-library-metadata-bastion | ||
| 32 | + if [ "$?" == "0" ];then | ||
| 33 | + echo "character-library-metadata-bastion service update success!" | ||
| 34 | + else | ||
| 35 | + echo "character-library-metadata-bastion service update fail!" | ||
| 36 | + fi | ||
| 37 | + kubectl -n mmm-suplus-test get pods | grep -q character-library-metadata-bastion | ||
| 38 | + if [ "$?" == "0" ];then | ||
| 39 | + echo "character-library-metadata-bastion deployment update success!" | ||
| 40 | + else | ||
| 41 | + echo "character-library-metadata-bastion deployment update fail!" | ||
| 42 | + fi | ||
| 43 | +fi |
| 1 | +version: v1 | ||
| 2 | +kind: HttpApi | ||
| 3 | +metadata: | ||
| 4 | + service: log | ||
| 5 | + path: /logs | ||
| 6 | + endpoints: | ||
| 7 | + - method: createLog | ||
| 8 | + route: | ||
| 9 | + post: / | ||
| 10 | + - method: updateLog | ||
| 11 | + route: | ||
| 12 | + put: /{logId} | ||
| 13 | + - method: getLog | ||
| 14 | + route: | ||
| 15 | + get: /{logId} | ||
| 16 | + - method: removeLog | ||
| 17 | + route: | ||
| 18 | + delete: /{logId} | ||
| 19 | + - method: listLog | ||
| 20 | + route: | ||
| 21 | + get: / | ||
| 22 | + params: | ||
| 23 | + - name: offset | ||
| 24 | + - name: limit | ||
| 25 | + - method: searchLog | ||
| 26 | + route: | ||
| 27 | + post: /search |
| 1 | +version: v1 | ||
| 2 | +kind: HttpApi | ||
| 3 | +metadata: | ||
| 4 | + service: mappingRule | ||
| 5 | + path: /mapping-rules | ||
| 6 | + endpoints: | ||
| 7 | + - method: createMappingRule | ||
| 8 | + route: | ||
| 9 | + post: / | ||
| 10 | + - method: updateMappingRule | ||
| 11 | + route: | ||
| 12 | + put: /{mappingRuleId} | ||
| 13 | + - method: getMappingRule | ||
| 14 | + route: | ||
| 15 | + get: /{mappingRuleId} | ||
| 16 | + - method: removeMappingRule | ||
| 17 | + route: | ||
| 18 | + delete: /{mappingRuleId} | ||
| 19 | + - method: listMappingRule | ||
| 20 | + route: | ||
| 21 | + get: / | ||
| 22 | + params: | ||
| 23 | + - name: offset | ||
| 24 | + - name: limit | ||
| 25 | + - method: search | ||
| 26 | + route: | ||
| 27 | + post: /search | ||
| 28 | + - method: prepare | ||
| 29 | + route: | ||
| 30 | + post: /prepare |
| 1 | +version: v1 | ||
| 2 | +kind: HttpApi | ||
| 3 | +metadata: | ||
| 4 | + service: querySet | ||
| 5 | + path: /query-sets | ||
| 6 | + endpoints: | ||
| 7 | + - method: createQuerySet | ||
| 8 | + route: | ||
| 9 | + post: / | ||
| 10 | + - method: updateQuerySet | ||
| 11 | + route: | ||
| 12 | + put: /{Id} | ||
| 13 | + - method: getQuerySet | ||
| 14 | + route: | ||
| 15 | + get: /{Id} | ||
| 16 | + - method: removeQuerySet | ||
| 17 | + route: | ||
| 18 | + delete: /{Id} | ||
| 19 | + - method: listQuerySet | ||
| 20 | + route: | ||
| 21 | + get: / | ||
| 22 | + params: | ||
| 23 | + - name: offset | ||
| 24 | + - name: limit | ||
| 25 | + - method: changeStatus | ||
| 26 | + route: | ||
| 27 | + post: /change-status | ||
| 28 | + - method: copy | ||
| 29 | + route: | ||
| 30 | + post: /copy | ||
| 31 | + - method: dependencyGraph | ||
| 32 | + route: | ||
| 33 | + post: /dependency-ggraph | ||
| 34 | + - method: move | ||
| 35 | + route: | ||
| 36 | + post: /move | ||
| 37 | + - method: rename | ||
| 38 | + route: | ||
| 39 | + post: /rename | ||
| 40 | + - method: searchQuerySet | ||
| 41 | + route: | ||
| 42 | + post: /search |
| 1 | +version: v1 | ||
| 2 | +kind: HttpApi | ||
| 3 | +metadata: | ||
| 4 | + service: table | ||
| 5 | + path: /tables | ||
| 6 | + endpoints: | ||
| 7 | + - method: createTable | ||
| 8 | + route: | ||
| 9 | + post: / | ||
| 10 | + - method: updateTable | ||
| 11 | + route: | ||
| 12 | + put: /{tableId} | ||
| 13 | + - method: getTable | ||
| 14 | + route: | ||
| 15 | + get: /{tableId} | ||
| 16 | + - method: removeTable | ||
| 17 | + route: | ||
| 18 | + delete: /{tableId} | ||
| 19 | + - method: listTable | ||
| 20 | + route: | ||
| 21 | + get: / | ||
| 22 | + params: | ||
| 23 | + - name: offset | ||
| 24 | + - name: limit | ||
| 25 | + - method: splitDataTable | ||
| 26 | + route: | ||
| 27 | + post: /split-data-table | ||
| 28 | + - method: batchEditSubTable | ||
| 29 | + route: | ||
| 30 | + post: /batch-edit-sub-table | ||
| 31 | + - method: copyDataTable | ||
| 32 | + route: | ||
| 33 | + post: /copy-data-table | ||
| 34 | + - method: search | ||
| 35 | + route: | ||
| 36 | + post: /search |
| 1 | +version: v1 | ||
| 2 | +kind: Schema | ||
| 3 | +metadata: | ||
| 4 | + name: mappingRule | ||
| 5 | + description: 匹配规则配置 | ||
| 6 | + attributes: | ||
| 7 | + - ref: mappingRuleId | ||
| 8 | + required: true | ||
| 9 | + - ref: name | ||
| 10 | + required: true | ||
| 11 | + - ref: tableId | ||
| 12 | + required: true | ||
| 13 | + - ref: fileId | ||
| 14 | + required: true | ||
| 15 | + - ref: mainTableFields | ||
| 16 | + required: true | ||
| 17 | + - ref: verifiedFileFields | ||
| 18 | + required: true | ||
| 19 | + - ref: mappingFields | ||
| 20 | + required: true | ||
| 21 | + - ref: createdAt | ||
| 22 | + required: true | ||
| 23 | + - ref: updatedAt | ||
| 24 | + required: true | ||
| 25 | + - ref: deletedAt | ||
| 26 | + required: true |
| 1 | +version: v1 | ||
| 2 | +kind: Schema | ||
| 3 | +metadata: | ||
| 4 | + name: querySet | ||
| 5 | + description: 查询集合 | ||
| 6 | + attributes: | ||
| 7 | + - ref: querySetId | ||
| 8 | + required: true | ||
| 9 | + - ref: type | ||
| 10 | + required: true | ||
| 11 | + - ref: flag | ||
| 12 | + required: true | ||
| 13 | + - ref: name | ||
| 14 | + required: true | ||
| 15 | + - ref: pinName | ||
| 16 | + required: true | ||
| 17 | + - ref: parentId | ||
| 18 | + required: true | ||
| 19 | + - ref: status | ||
| 20 | + required: true | ||
| 21 | + - ref: querySetInfo | ||
| 22 | + required: true | ||
| 23 | + - ref: queryComponents | ||
| 24 | + required: true | ||
| 25 | + - ref: sort | ||
| 26 | + required: true | ||
| 27 | + - ref: createdAt | ||
| 28 | + required: true | ||
| 29 | + - ref: updatedAt | ||
| 30 | + required: true | ||
| 31 | + - ref: deletedAt | ||
| 32 | + required: true | ||
| 33 | + - ref: context | ||
| 34 | + required: true |
| 1 | +version: v1 | ||
| 2 | +kind: Method | ||
| 3 | +metadata: | ||
| 4 | + name: createLog | ||
| 5 | + type: command | ||
| 6 | + description: 创建日志服务 | ||
| 7 | + payload: | ||
| 8 | + - ref: objectName | ||
| 9 | + required: true | ||
| 10 | + - ref: objectType | ||
| 11 | + required: true | ||
| 12 | + - ref: operationType | ||
| 13 | + required: true | ||
| 14 | + - ref: content | ||
| 15 | + required: true | ||
| 16 | + - ref: operatorName | ||
| 17 | + required: true | ||
| 18 | + result: | ||
| 19 | + - name: log | ||
| 20 | + type: | ||
| 21 | + schema: log | ||
| 22 | + required: true |
| 1 | +version: v1 | ||
| 2 | +kind: Method | ||
| 3 | +metadata: | ||
| 4 | + name: listLog | ||
| 5 | + type: query | ||
| 6 | + description: 返回日志服务列表 | ||
| 7 | + payload: | ||
| 8 | + - ref: offset | ||
| 9 | + required: true | ||
| 10 | + - ref: limit | ||
| 11 | + required: true | ||
| 12 | + result: | ||
| 13 | + - ref: count | ||
| 14 | + required: true | ||
| 15 | + - name: logs | ||
| 16 | + type: | ||
| 17 | + array: log | ||
| 18 | + required: true |
| 1 | +version: v1 | ||
| 2 | +kind: Method | ||
| 3 | +metadata: | ||
| 4 | + name: listMappingRule | ||
| 5 | + type: query | ||
| 6 | + description: 返回匹配规则服务列表 | ||
| 7 | + payload: | ||
| 8 | + - ref: offset | ||
| 9 | + required: true | ||
| 10 | + - ref: limit | ||
| 11 | + required: true | ||
| 12 | + result: | ||
| 13 | + - ref: count | ||
| 14 | + required: true | ||
| 15 | + - name: mappingRules | ||
| 16 | + type: | ||
| 17 | + array: mappingRule | ||
| 18 | + required: true |
| 1 | +version: v1 | ||
| 2 | +kind: Method | ||
| 3 | +metadata: | ||
| 4 | + name: copy | ||
| 5 | + type: command | ||
| 6 | + description: 移动 | ||
| 7 | + payload: | ||
| 8 | + - ref: flag | ||
| 9 | + required: true | ||
| 10 | + - ref: parentId | ||
| 11 | + required: true | ||
| 12 | + - ref: name | ||
| 13 | + required: true | ||
| 14 | + - ref: querySetId | ||
| 15 | + required: true | ||
| 16 | + result: | ||
| 17 | + - name: querySet | ||
| 18 | + type: | ||
| 19 | + schema: querySet | ||
| 20 | + required: true |
| 1 | +version: v1 | ||
| 2 | +kind: Method | ||
| 3 | +metadata: | ||
| 4 | + name: createQuerySet | ||
| 5 | + type: command | ||
| 6 | + description: 创建查询集合服务 | ||
| 7 | + payload: | ||
| 8 | + - ref: type | ||
| 9 | + required: true | ||
| 10 | + - ref: flag | ||
| 11 | + required: true | ||
| 12 | + - ref: name | ||
| 13 | + required: true | ||
| 14 | + - ref: parentId | ||
| 15 | + required: false | ||
| 16 | + result: | ||
| 17 | + - name: querySet | ||
| 18 | + type: | ||
| 19 | + schema: querySet | ||
| 20 | + required: true |
| 1 | +version: v1 | ||
| 2 | +kind: Method | ||
| 3 | +metadata: | ||
| 4 | + name: listQuerySet | ||
| 5 | + type: query | ||
| 6 | + description: 返回查询集合服务列表 | ||
| 7 | + payload: | ||
| 8 | + - ref: offset | ||
| 9 | + required: true | ||
| 10 | + - ref: limit | ||
| 11 | + required: true | ||
| 12 | + result: | ||
| 13 | + - ref: count | ||
| 14 | + required: true | ||
| 15 | + - name: querySets | ||
| 16 | + type: | ||
| 17 | + array: querySet | ||
| 18 | + required: true |
| 1 | +version: v1 | ||
| 2 | +kind: Method | ||
| 3 | +metadata: | ||
| 4 | + name: searchQuerySet | ||
| 5 | + type: query | ||
| 6 | + description: 返回查询集合服务列表 | ||
| 7 | + payload: | ||
| 8 | + - ref: offset | ||
| 9 | + required: true | ||
| 10 | + - ref: limit | ||
| 11 | + required: true | ||
| 12 | + result: | ||
| 13 | + - ref: count | ||
| 14 | + required: true | ||
| 15 | + - name: querySets | ||
| 16 | + type: | ||
| 17 | + array: querySet | ||
| 18 | + required: true |
| 1 | +version: v1 | ||
| 2 | +kind: Method | ||
| 3 | +metadata: | ||
| 4 | + name: listTable | ||
| 5 | + type: query | ||
| 6 | + description: 返回表服务列表 | ||
| 7 | + payload: | ||
| 8 | + - ref: offset | ||
| 9 | + required: true | ||
| 10 | + - ref: limit | ||
| 11 | + required: true | ||
| 12 | + result: | ||
| 13 | + - ref: count | ||
| 14 | + required: true | ||
| 15 | + - name: tables | ||
| 16 | + type: | ||
| 17 | + array: table | ||
| 18 | + required: true |
| @@ -3,32 +3,45 @@ module gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion | @@ -3,32 +3,45 @@ module gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion | ||
| 3 | go 1.16 | 3 | go 1.16 |
| 4 | 4 | ||
| 5 | require ( | 5 | require ( |
| 6 | - github.com/Shopify/sarama v1.25.0 | ||
| 7 | github.com/ajg/form v1.5.1 // indirect | 6 | github.com/ajg/form v1.5.1 // indirect |
| 8 | github.com/beego/beego/v2 v2.0.1 | 7 | github.com/beego/beego/v2 v2.0.1 |
| 8 | + github.com/bwmarrin/snowflake v0.3.0 | ||
| 9 | + github.com/dgrijalva/jwt-go v3.2.0+incompatible | ||
| 10 | + github.com/extrame/xls v0.0.1 | ||
| 9 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | 11 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect |
| 10 | github.com/fatih/structs v1.1.0 // indirect | 12 | github.com/fatih/structs v1.1.0 // indirect |
| 11 | github.com/gavv/httpexpect v2.0.0+incompatible | 13 | github.com/gavv/httpexpect v2.0.0+incompatible |
| 12 | - github.com/go-pg/pg/v10 v10.9.0 | ||
| 13 | - github.com/go-redis/redis v6.15.9+incompatible // indirect | ||
| 14 | - github.com/go-redis/redis/v7 v7.4.1 // indirect | ||
| 15 | - github.com/golang/snappy v0.0.3 // indirect | ||
| 16 | - github.com/google/go-cmp v0.5.6 // indirect | 14 | + github.com/go-pg/pg/v10 v10.10.6 |
| 15 | + github.com/go-redis/redis v6.15.9+incompatible | ||
| 17 | github.com/google/go-querystring v1.1.0 // indirect | 16 | github.com/google/go-querystring v1.1.0 // indirect |
| 18 | - github.com/google/uuid v1.3.0 // indirect | 17 | + github.com/google/gofuzz v1.2.0 |
| 18 | + github.com/google/uuid v1.3.0 | ||
| 19 | + github.com/gookit/event v1.0.6 | ||
| 19 | github.com/imkira/go-interpol v1.1.0 // indirect | 20 | github.com/imkira/go-interpol v1.1.0 // indirect |
| 20 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 | 21 | github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 |
| 21 | github.com/moul/http2curl v1.0.0 // indirect | 22 | github.com/moul/http2curl v1.0.0 // indirect |
| 22 | - github.com/onsi/ginkgo v1.15.2 | ||
| 23 | - github.com/onsi/gomega v1.11.0 | 23 | + github.com/onsi/ginkgo v1.16.5 |
| 24 | + github.com/onsi/gomega v1.18.1 | ||
| 25 | + github.com/patrickmn/go-cache v2.1.0+incompatible | ||
| 24 | github.com/sergi/go-diff v1.2.0 // indirect | 26 | github.com/sergi/go-diff v1.2.0 // indirect |
| 27 | + github.com/shopspring/decimal v1.3.1 | ||
| 25 | github.com/smartystreets/goconvey v1.7.2 // indirect | 28 | github.com/smartystreets/goconvey v1.7.2 // indirect |
| 29 | + github.com/stretchr/testify v1.7.1 | ||
| 26 | github.com/valyala/fasthttp v1.38.0 // indirect | 30 | github.com/valyala/fasthttp v1.38.0 // indirect |
| 27 | github.com/xeipuuv/gojsonschema v1.2.0 // indirect | 31 | github.com/xeipuuv/gojsonschema v1.2.0 // indirect |
| 32 | + github.com/xuri/excelize/v2 v2.6.0 | ||
| 28 | github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect | 33 | github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect |
| 29 | github.com/yudai/gojsondiff v1.0.0 // indirect | 34 | github.com/yudai/gojsondiff v1.0.0 // indirect |
| 30 | github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect | 35 | github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect |
| 31 | github.com/yudai/pp v2.0.1+incompatible // indirect | 36 | github.com/yudai/pp v2.0.1+incompatible // indirect |
| 37 | + github.com/zeromicro/go-zero v1.3.4 | ||
| 38 | + golang.org/x/text v0.3.7 | ||
| 39 | + gorm.io/driver/mysql v1.3.6 | ||
| 40 | + gorm.io/driver/postgres v1.3.9 | ||
| 41 | + gorm.io/gorm v1.23.8 | ||
| 32 | ) | 42 | ) |
| 33 | 43 | ||
| 34 | -replace github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 | 44 | +replace ( |
| 45 | + github.com/extrame/xls v0.0.1 => github.com/tiptok/xls v1.0.1 | ||
| 46 | + github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 | ||
| 47 | +) |
| @@ -3,18 +3,21 @@ package main | @@ -3,18 +3,21 @@ package main | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | "github.com/beego/beego/v2/server/web" | 5 | "github.com/beego/beego/v2/server/web" |
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/crontab" | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" |
| 7 | - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" | ||
| 8 | - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
| 9 | - "time" | ||
| 10 | - | ||
| 11 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | 8 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" |
| 12 | - _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" | 9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" |
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" | ||
| 13 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" | 11 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" |
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" | ||
| 13 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
| 14 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | 14 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" |
| 15 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego" | 15 | _ "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego" |
| 16 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/event" | ||
| 16 | ) | 17 | ) |
| 17 | 18 | ||
| 19 | +const Version = "v1.2.0" | ||
| 20 | + | ||
| 18 | func main() { | 21 | func main() { |
| 19 | defer func() { | 22 | defer func() { |
| 20 | if r := recover(); r != nil { | 23 | if r := recover(); r != nil { |
| @@ -24,8 +27,17 @@ func main() { | @@ -24,8 +27,17 @@ func main() { | ||
| 24 | 27 | ||
| 25 | log.InitLogHook(constant.ENABLE_KAFKA_LOG, true) | 28 | log.InitLogHook(constant.ENABLE_KAFKA_LOG, true) |
| 26 | redis.InitRedis() | 29 | redis.InitRedis() |
| 27 | - | ||
| 28 | - time.Sleep(time.Second) | 30 | + redis.InitZeroCoreRedis() |
| 31 | + pg.Init() | ||
| 32 | + if err := starrocks.Init(); err != nil { | ||
| 33 | + log.Logger.Error(err.Error()) | ||
| 34 | + } | ||
| 35 | + cron := crontab.NewCrontabService(nil) | ||
| 36 | + cron.StartCrontabTask() | ||
| 37 | + defer cron.StopCrontabTask() | ||
| 38 | + event.Start() | ||
| 39 | + log.Logger.Info("Service:" + constant.SERVICE_NAME) | ||
| 40 | + log.Logger.Info("Version:" + Version) | ||
| 29 | log.Logger.Info("server start!") | 41 | log.Logger.Info("server start!") |
| 30 | web.Run() | 42 | web.Run() |
| 31 | log.Logger.Info("server stop!") | 43 | log.Logger.Info("server stop!") |
pkg/application/crontab/crontab.go
0 → 100644
| 1 | +package crontab | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "fmt" | ||
| 6 | + "github.com/beego/beego/v2/task" | ||
| 7 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 8 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" | ||
| 13 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
| 14 | + "io/fs" | ||
| 15 | + "os" | ||
| 16 | + "path/filepath" | ||
| 17 | + "time" | ||
| 18 | +) | ||
| 19 | + | ||
| 20 | +type CrontabService struct { | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +func NewCrontabService(options map[string]interface{}) *CrontabService { | ||
| 24 | + newCrontabService := &CrontabService{} | ||
| 25 | + return newCrontabService | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func (crontabService *CrontabService) initTask() { | ||
| 29 | + autoRemoveExpiredTemporaryFile := task.NewTask("定时清理过期临时文件记录", "0 10 */1 * * *", AutoRemoveExpiredTemporaryFile) | ||
| 30 | + task.AddTask("autoRemoveExpiredTemporaryFile", autoRemoveExpiredTemporaryFile) | ||
| 31 | + | ||
| 32 | + autoRemovePublicDownloadFile := task.NewTask("定时清理缓存文件", "0 20 */1 * * *", AutoRemovePublicDownloadFile) | ||
| 33 | + task.AddTask("autoRemovePublicDownloadFile", autoRemovePublicDownloadFile) | ||
| 34 | + | ||
| 35 | + autoRemoveTemporaryTable := task.NewTask("定时清理临时表", "0 57 */1 * * *", AutoRemoveTemporaryTable) | ||
| 36 | + task.AddTask("autoRemoveTemporaryTable", autoRemoveTemporaryTable) | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +func (crontabService *CrontabService) StartCrontabTask() { | ||
| 40 | + crontabService.initTask() | ||
| 41 | + task.StartTask() | ||
| 42 | + log.Logger.Info("crontab start!") | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +func (crontabService *CrontabService) StopCrontabTask() { | ||
| 46 | + task.StopTask() | ||
| 47 | + log.Logger.Info("crontab stop!") | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +func AutoRemoveExpiredTemporaryFile(ctx context.Context) error { | ||
| 51 | + | ||
| 52 | + defer func() { | ||
| 53 | + if r := recover(); r != nil { | ||
| 54 | + log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时清理过期临时文件记录"}) | ||
| 55 | + } | ||
| 56 | + }() | ||
| 57 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 58 | + if err != nil { | ||
| 59 | + return err | ||
| 60 | + } | ||
| 61 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 62 | + return err | ||
| 63 | + } | ||
| 64 | + defer func() { | ||
| 65 | + if err != nil { | ||
| 66 | + log.Logger.Error("【定时清理过期临时文件记录】 失败:" + err.Error()) | ||
| 67 | + } | ||
| 68 | + transactionContext.RollbackTransaction() | ||
| 69 | + }() | ||
| 70 | + | ||
| 71 | + log.Logger.Debug("【定时清理过期临时文件记录】 启动") | ||
| 72 | + end := xtime.New(time.Now()).BeginningOfDay().Add(-time.Hour * 6) | ||
| 73 | + begin := end.AddDate(0, 0, -7) | ||
| 74 | + fileRepository, _, _ := factory.FastPgFile(transactionContext, 0) | ||
| 75 | + _, files, err := fileRepository.Find(map[string]interface{}{"limit": 100, "fileType": domain.TemporaryFile.ToString(), "updatedAtBegin": begin, "updatedAtEnd": end}) | ||
| 76 | + if err != nil { | ||
| 77 | + return err | ||
| 78 | + } | ||
| 79 | + deleteFileService, _ := factory.CreateDeleteFileService(transactionContext) | ||
| 80 | + if err = deleteFileService.DeleteFiles(&domain.Context{ | ||
| 81 | + OperatorName: "系统", | ||
| 82 | + }, files...); err != nil { | ||
| 83 | + return err | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
| 87 | + return err | ||
| 88 | + } | ||
| 89 | + return nil | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +func AutoRemovePublicDownloadFile(ctx context.Context) error { | ||
| 93 | + var err error | ||
| 94 | + defer func() { | ||
| 95 | + if r := recover(); r != nil { | ||
| 96 | + log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时清理缓存文件"}) | ||
| 97 | + } | ||
| 98 | + }() | ||
| 99 | + defer func() { | ||
| 100 | + if err != nil { | ||
| 101 | + log.Logger.Error("【定时清理缓存文件】 失败:" + err.Error()) | ||
| 102 | + } | ||
| 103 | + }() | ||
| 104 | + log.Logger.Debug("【定时清理缓存文件】 启动") | ||
| 105 | + root := "public" | ||
| 106 | + end := xtime.New(time.Now()).BeginningOfDay().AddDate(0, 0, -1) | ||
| 107 | + err = filepath.Walk(root, func(path string, info fs.FileInfo, err error) error { | ||
| 108 | + t := info.ModTime() | ||
| 109 | + if !info.IsDir() && xtime.Before(t, end) { | ||
| 110 | + err = os.Remove(path) | ||
| 111 | + if err != nil { | ||
| 112 | + return err | ||
| 113 | + } | ||
| 114 | + log.Logger.Info(fmt.Sprintf("[%v] 删除文件:%v 大小:%v 路径:%v 文件创建时间:%v", "系统", info.Name(), info.Size(), path, info.ModTime())) | ||
| 115 | + return nil | ||
| 116 | + } | ||
| 117 | + return nil | ||
| 118 | + }) | ||
| 119 | + if err != nil { | ||
| 120 | + return err | ||
| 121 | + } | ||
| 122 | + return nil | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | +func AutoRemoveTemporaryTable(ctx context.Context) error { | ||
| 126 | + defer func() { | ||
| 127 | + if r := recover(); r != nil { | ||
| 128 | + log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时清理过期临时文件记录"}) | ||
| 129 | + } | ||
| 130 | + }() | ||
| 131 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 132 | + if err != nil { | ||
| 133 | + return err | ||
| 134 | + } | ||
| 135 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 136 | + return err | ||
| 137 | + } | ||
| 138 | + defer func() { | ||
| 139 | + if err != nil { | ||
| 140 | + log.Logger.Error("【定时清理临时表】 失败:" + err.Error()) | ||
| 141 | + } | ||
| 142 | + transactionContext.RollbackTransaction() | ||
| 143 | + }() | ||
| 144 | + | ||
| 145 | + log.Logger.Debug("【定时清理临时表】 启动") | ||
| 146 | + end := xtime.New(time.Now()).BeginningOfDay().Add(-time.Hour * 12) | ||
| 147 | + begin := end.AddDate(0, 0, -7) | ||
| 148 | + | ||
| 149 | + tableRepository, _, _ := factory.FastPgTable(transactionContext, 0) | ||
| 150 | + _, tables, err := tableRepository.Find(map[string]interface{}{"beginTime": begin, "endTime": end, "tableTypes": []string{domain.TemporaryTable.ToString()}}) | ||
| 151 | + if err != nil { | ||
| 152 | + return nil | ||
| 153 | + } | ||
| 154 | + for i, t := range tables { | ||
| 155 | + if err = dao.TableDelete(transactionContext.(*pgTransaction.TransactionContext), t.TableId, domain.TemporaryTable); err != nil { | ||
| 156 | + log.Logger.Error(err.Error()) | ||
| 157 | + return nil | ||
| 158 | + } | ||
| 159 | + log.Logger.Info(fmt.Sprintf("序号:%d 清理临时表 %v", i, t.SQLName)) | ||
| 160 | + if err = starrocks.DropView(starrocks.DB, t.SQLName); err != nil { | ||
| 161 | + log.Logger.Error(err.Error()) | ||
| 162 | + return nil | ||
| 163 | + } | ||
| 164 | + } | ||
| 165 | + //if err = dao.TableDeleteByTime(transactionContext.(*pgTransaction.TransactionContext), domain.TemporaryTable, begin, end); err != nil { | ||
| 166 | + // return err | ||
| 167 | + //} | ||
| 168 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
| 169 | + return err | ||
| 170 | + } | ||
| 171 | + return nil | ||
| 172 | +} |
pkg/application/event/service/event.go
0 → 100644
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/core/application" | ||
| 5 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/event/command" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | ||
| 8 | + tablecommand "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command" | ||
| 9 | + tableservice "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/service" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/cache" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type TableEventService struct { | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (tableEventService *TableEventService) Handler(ctx *domain.Context, cmd *command.TableEventCommand) (interface{}, error) { | ||
| 19 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 20 | + if err != nil { | ||
| 21 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 22 | + } | ||
| 23 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 24 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 25 | + } | ||
| 26 | + defer func() { | ||
| 27 | + transactionContext.RollbackTransaction() | ||
| 28 | + }() | ||
| 29 | + | ||
| 30 | + data := cmd.EventTable | ||
| 31 | + tableId := 0 | ||
| 32 | + switch data.Type { | ||
| 33 | + case domain.TableDataImportEvent, domain.TableDataEditEvent, domain.TableDeleteEvent: | ||
| 34 | + tableId = data.Table.TableId | ||
| 35 | + case domain.QuerySetUpdateEvent: | ||
| 36 | + tableId = data.QuerySet.QuerySetInfo.BindTableId | ||
| 37 | + } | ||
| 38 | + if tableId == 0 { | ||
| 39 | + return nil, nil | ||
| 40 | + } | ||
| 41 | + // tableId 相关联的 | ||
| 42 | + tableRepository, _, _ := factory.FastPgTable(transactionContext, 0) | ||
| 43 | + _, tables, err := tableRepository.Find(map[string]interface{}{"context": data.Context, "tableTypesNotIn": []string{domain.TemporaryTable.ToString(), domain.ExcelTable.ToString()}}) | ||
| 44 | + if err != nil { | ||
| 45 | + return nil, err | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + tableDependencyService, _ := domainService.NewTableDependencyService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 49 | + tableDependTree := tableDependencyService.TableDependTree(tables, tableId) | ||
| 50 | + tree := tableDependTree.Tree | ||
| 51 | + | ||
| 52 | + tableService := tableservice.NewTableService(nil) | ||
| 53 | + for i := range tree { | ||
| 54 | + cache.DefaultDataTableCacheService.DeleteDataTable(tree[i]) | ||
| 55 | + // fresh cache | ||
| 56 | + tableService.TablePreview(data.Context, &tablecommand.TablePreviewCommand{ | ||
| 57 | + TableId: tree[i], | ||
| 58 | + ObjectType: domain.ObjectMetaTable, | ||
| 59 | + PageSize: 10000, | ||
| 60 | + PageNumber: 0, | ||
| 61 | + UseCache: true, | ||
| 62 | + }) | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 66 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 67 | + } | ||
| 68 | + return nil, nil | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +func NewTableEventService(options map[string]interface{}) *TableEventService { | ||
| 72 | + svr := &TableEventService{} | ||
| 73 | + return svr | ||
| 74 | +} |
| 1 | package factory | 1 | package factory |
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/core/application" | ||
| 5 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +func FastLog(transactionContext application.TransactionContext, logType domain.LogType, sourceId int, logEntry domainService.Log) error { | ||
| 11 | + logService, _ := domainService.NewPGLogService(transactionContext.(*pg.TransactionContext)) | ||
| 12 | + return logService.Log(logType, sourceId, logEntry) | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +func CreateLoadDataTableService(transactionContext application.TransactionContext) (domain.PreviewDataTableService, error) { | ||
| 16 | + return domainService.NewLoadDataTableService(transactionContext.(*pg.TransactionContext)) | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func CreateEditDataTableService(transactionContext application.TransactionContext) (domain.EditDataTableService, error) { | ||
| 20 | + return domainService.NewEditDataTableService(transactionContext.(*pg.TransactionContext)) | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +func CreateFlushDataTableService(transactionContext application.TransactionContext) (domain.FlushDataTableService, error) { | ||
| 24 | + return domainService.NewFlushDataTableService(transactionContext.(*pg.TransactionContext)) | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +func CreateDeleteFileService(transactionContext application.TransactionContext) (domain.DeleteFileService, error) { | ||
| 28 | + return domainService.NewDeleteFileService(transactionContext.(*pg.TransactionContext)) | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +func CreateGenerateMainTableService(transactionContext application.TransactionContext) (domain.GenerateMainTableService, error) { | ||
| 32 | + return domainService.NewGenerateMainTableService(transactionContext.(*pg.TransactionContext)) | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +func CreateCopyDataTableService(transactionContext application.TransactionContext) (domain.CopyDataTableService, error) { | ||
| 36 | + return domainService.NewCopyDataTableService(transactionContext.(*pg.TransactionContext)) | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +func CreateDeleteDataTableService(transactionContext application.TransactionContext) (domain.DeleteDataTableService, error) { | ||
| 40 | + return domainService.NewDeleteDataTableService(transactionContext.(*pg.TransactionContext)) | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +func CreateUpdateTableStructService(transactionContext application.TransactionContext) (domain.UpdateTableStructService, error) { | ||
| 44 | + return domainService.NewUpdateTableStructService(transactionContext.(*pg.TransactionContext)) | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +func CreateAddTableStructService(transactionContext application.TransactionContext) (domain.AddTableStructService, error) { | ||
| 48 | + return domainService.NewAddTableStructService(transactionContext.(*pg.TransactionContext)) | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +func CreateAppendDataToTableService(transactionContext application.TransactionContext) (domain.AppendDataToTableService, error) { | ||
| 52 | + return domainService.NewAppendDataToTableService(transactionContext.(*pg.TransactionContext)) | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +func CreateTableEditDataService(transactionContext application.TransactionContext) (domain.TableEditDataService, error) { | ||
| 56 | + return domainService.NewTableEditDataService(transactionContext.(*pg.TransactionContext)) | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +// 字库核心 | ||
| 60 | +func CreateByteCoreService(transactionContext application.TransactionContext) (domain.ByteLibService, error) { | ||
| 61 | + return domainService.ByteCore, nil | ||
| 62 | +} |
pkg/application/factory/fast.go
0 → 100644
| 1 | +package factory | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/core/application" | ||
| 5 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +func FastError(err error) error { | ||
| 12 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) { | ||
| 16 | + var err error | ||
| 17 | + // 待优化分批下载,压缩 | ||
| 18 | + var dataTable *domain.DataTable | ||
| 19 | + dataTable, err = starrocks.Query(options, starrocks.WrapQueryFuncWithDB(starrocks.DB)) | ||
| 20 | + if err != nil { | ||
| 21 | + return nil, err | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + dataTable.Total, err = starrocks.WrapQueryCountWithDB(options, starrocks.DB)() | ||
| 25 | + if err != nil { | ||
| 26 | + return nil, err | ||
| 27 | + } | ||
| 28 | + return dataTable, nil | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +func FastQuerySetServices(transactionContext application.TransactionContext) (*domainService.QuerySetService, error) { | ||
| 32 | + return domainService.NewQuerySetService(transactionContext.(*pgTransaction.TransactionContext)) | ||
| 33 | +} |
| 1 | +package factory | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/core/application" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +// FastPgFile 快速返回文件对象 | ||
| 9 | +// | ||
| 10 | +// transactionContext 事务 | ||
| 11 | +// id 对象唯一标识 | ||
| 12 | +func FastPgFile(transactionContext application.TransactionContext, id int) (domain.FileRepository, *domain.File, error) { | ||
| 13 | + var rep domain.FileRepository | ||
| 14 | + var mod *domain.File | ||
| 15 | + var err error | ||
| 16 | + if value, err := CreateFileRepository(map[string]interface{}{ | ||
| 17 | + "transactionContext": transactionContext, | ||
| 18 | + }); err != nil { | ||
| 19 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 20 | + } else { | ||
| 21 | + rep = value | ||
| 22 | + } | ||
| 23 | + if id > 0 { | ||
| 24 | + if mod, err = rep.FindOne(map[string]interface{}{"fileId": id}); err != nil { | ||
| 25 | + if err == domain.ErrorNotFound { | ||
| 26 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该文件不存在") | ||
| 27 | + } | ||
| 28 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + //if err = fastPgDataAuth(transactionContext, mod, options...); err != nil { | ||
| 32 | + // return nil, nil, err | ||
| 33 | + //} | ||
| 34 | + return rep, mod, err | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// FastPgTable 快速返回表格对象 | ||
| 38 | +// | ||
| 39 | +// transactionContext 事务 | ||
| 40 | +// id 对象唯一标识 | ||
| 41 | +func FastPgTable(transactionContext application.TransactionContext, id int) (domain.TableRepository, *domain.Table, error) { | ||
| 42 | + var rep domain.TableRepository | ||
| 43 | + var mod *domain.Table | ||
| 44 | + var err error | ||
| 45 | + if value, err := CreateTableRepository(map[string]interface{}{ | ||
| 46 | + "transactionContext": transactionContext, | ||
| 47 | + }); err != nil { | ||
| 48 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 49 | + } else { | ||
| 50 | + rep = value | ||
| 51 | + } | ||
| 52 | + if id > 0 { | ||
| 53 | + if mod, err = rep.FindOne(map[string]interface{}{"tableId": id}); err != nil { | ||
| 54 | + if err == domain.ErrorNotFound { | ||
| 55 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该表格不存在") | ||
| 56 | + } | ||
| 57 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + return rep, mod, err | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +// FastPgLog 快速返回日志对象 | ||
| 64 | +// | ||
| 65 | +// transactionContext 事务 | ||
| 66 | +// id 对象唯一标识 | ||
| 67 | +func FastPgLog(transactionContext application.TransactionContext, id int) (domain.LogRepository, *domain.Log, error) { | ||
| 68 | + var rep domain.LogRepository | ||
| 69 | + var mod *domain.Log | ||
| 70 | + var err error | ||
| 71 | + if value, err := CreateLogRepository(map[string]interface{}{ | ||
| 72 | + "transactionContext": transactionContext, | ||
| 73 | + }); err != nil { | ||
| 74 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 75 | + } else { | ||
| 76 | + rep = value | ||
| 77 | + } | ||
| 78 | + if id > 0 { | ||
| 79 | + if mod, err = rep.FindOne(map[string]interface{}{"logId": id}); err != nil { | ||
| 80 | + if err == domain.ErrorNotFound { | ||
| 81 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该日志不存在") | ||
| 82 | + } | ||
| 83 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + return rep, mod, err | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +// FastPgMappingRule 快速返回匹配规则对象 | ||
| 90 | +// | ||
| 91 | +// transactionContext 事务 | ||
| 92 | +// id 对象唯一标识 | ||
| 93 | +func FastPgMappingRule(transactionContext application.TransactionContext, id int) (domain.MappingRuleRepository, *domain.MappingRule, error) { | ||
| 94 | + var rep domain.MappingRuleRepository | ||
| 95 | + var mod *domain.MappingRule | ||
| 96 | + var err error | ||
| 97 | + if value, err := CreateMappingRuleRepository(map[string]interface{}{ | ||
| 98 | + "transactionContext": transactionContext, | ||
| 99 | + }); err != nil { | ||
| 100 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 101 | + } else { | ||
| 102 | + rep = value | ||
| 103 | + } | ||
| 104 | + if id > 0 { | ||
| 105 | + if mod, err = rep.FindOne(map[string]interface{}{"mappingRuleId": id}); err != nil { | ||
| 106 | + if err == domain.ErrorNotFound { | ||
| 107 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该匹配规则不存在") | ||
| 108 | + } | ||
| 109 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + return rep, mod, err | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +// FastPgQuerySet 快速返回查询集合 | ||
| 116 | +// | ||
| 117 | +// transactionContext 事务 | ||
| 118 | +// id 对象唯一标识 | ||
| 119 | +func FastPgQuerySet(transactionContext application.TransactionContext, id int) (domain.QuerySetRepository, *domain.QuerySet, error) { | ||
| 120 | + var rep domain.QuerySetRepository | ||
| 121 | + var mod *domain.QuerySet | ||
| 122 | + var err error | ||
| 123 | + if value, err := CreateQuerySetRepository(map[string]interface{}{ | ||
| 124 | + "transactionContext": transactionContext, | ||
| 125 | + }); err != nil { | ||
| 126 | + return nil, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 127 | + } else { | ||
| 128 | + rep = value | ||
| 129 | + } | ||
| 130 | + if id > 0 { | ||
| 131 | + if mod, err = rep.FindOne(map[string]interface{}{"querySetId": id}); err != nil { | ||
| 132 | + if err == domain.ErrorNotFound { | ||
| 133 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该查询集合不存在") | ||
| 134 | + } | ||
| 135 | + return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + return rep, mod, err | ||
| 139 | +} |
| @@ -29,3 +29,19 @@ func CreateFileRepository(options map[string]interface{}) (domain.FileRepository | @@ -29,3 +29,19 @@ func CreateFileRepository(options map[string]interface{}) (domain.FileRepository | ||
| 29 | } | 29 | } |
| 30 | return repository.NewFileRepository(transactionContext) | 30 | return repository.NewFileRepository(transactionContext) |
| 31 | } | 31 | } |
| 32 | + | ||
| 33 | +func CreateMappingRuleRepository(options map[string]interface{}) (domain.MappingRuleRepository, error) { | ||
| 34 | + var transactionContext *pg.TransactionContext | ||
| 35 | + if value, ok := options["transactionContext"]; ok { | ||
| 36 | + transactionContext = value.(*pg.TransactionContext) | ||
| 37 | + } | ||
| 38 | + return repository.NewMappingRuleRepository(transactionContext) | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +func CreateQuerySetRepository(options map[string]interface{}) (domain.QuerySetRepository, error) { | ||
| 42 | + var transactionContext *pg.TransactionContext | ||
| 43 | + if value, ok := options["transactionContext"]; ok { | ||
| 44 | + transactionContext = value.(*pg.TransactionContext) | ||
| 45 | + } | ||
| 46 | + return repository.NewQuerySetRepository(transactionContext) | ||
| 47 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 6 | + "reflect" | ||
| 7 | + "strings" | ||
| 8 | + | ||
| 9 | + "github.com/beego/beego/v2/core/validation" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type AppendDataToTableCommand struct { | ||
| 13 | + // 文件ID | ||
| 14 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
| 15 | + // 文件ID | ||
| 16 | + TableId int `cname:"表ID" json:"tableId" valid:"Required"` | ||
| 17 | + // 校验文件列 | ||
| 18 | + MappingFields []*domain.MappingField `json:"mappingFields"` | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +func (cmd *AppendDataToTableCommand) Valid(validation *validation.Validation) { | ||
| 22 | + | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func (cmd *AppendDataToTableCommand) ValidateCommand() error { | ||
| 26 | + valid := validation.Validation{} | ||
| 27 | + b, err := valid.Valid(cmd) | ||
| 28 | + if err != nil { | ||
| 29 | + return err | ||
| 30 | + } | ||
| 31 | + if !b { | ||
| 32 | + elem := reflect.TypeOf(cmd).Elem() | ||
| 33 | + for _, validErr := range valid.Errors { | ||
| 34 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 35 | + if isExist { | ||
| 36 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 37 | + } else { | ||
| 38 | + return fmt.Errorf(validErr.Message) | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + return nil | ||
| 43 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type CancelVerifyingFileCommand struct { | ||
| 12 | + // 文件ID | ||
| 13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (cmd *CancelVerifyingFileCommand) Valid(validation *validation.Validation) { | ||
| 17 | + | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (cmd *CancelVerifyingFileCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(cmd) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(cmd).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type CheckFileVerifyStatusCommand struct { | ||
| 12 | + // 文件ID | ||
| 13 | + FileId int `cname:"文件ID" json:"objectId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (cmd *CheckFileVerifyStatusCommand) Valid(validation *validation.Validation) { | ||
| 17 | + | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (cmd *CheckFileVerifyStatusCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(cmd) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(cmd).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
| @@ -2,6 +2,8 @@ package command | @@ -2,6 +2,8 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 6 | + "path/filepath" | ||
| 5 | "reflect" | 7 | "reflect" |
| 6 | "strings" | 8 | "strings" |
| 7 | 9 | ||
| @@ -13,12 +15,16 @@ type CreateFileCommand struct { | @@ -13,12 +15,16 @@ type CreateFileCommand struct { | ||
| 13 | Name string `cname:"名称" json:"name" valid:"Required"` | 15 | Name string `cname:"名称" json:"name" valid:"Required"` |
| 14 | // 文件地址 | 16 | // 文件地址 |
| 15 | Url string `cname:"文件地址" json:"url" valid:"Required"` | 17 | Url string `cname:"文件地址" json:"url" valid:"Required"` |
| 16 | - // 文件大小 | 18 | + // 文件大小 单位KB |
| 17 | FileSize int `cname:"文件大小" json:"fileSize" valid:"Required"` | 19 | FileSize int `cname:"文件大小" json:"fileSize" valid:"Required"` |
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | func (createFileCommand *CreateFileCommand) Valid(validation *validation.Validation) { | 22 | func (createFileCommand *CreateFileCommand) Valid(validation *validation.Validation) { |
| 21 | - validation.SetError("CustomValid", "未实现的自定义认证") | 23 | + ext := filepath.Ext(createFileCommand.Name) |
| 24 | + if !(ext == domain.XLS || ext == domain.XLSX) { | ||
| 25 | + validation.Error(fmt.Sprintf("仅支持文件格式 xls 、 xlsx")) | ||
| 26 | + return | ||
| 27 | + } | ||
| 22 | } | 28 | } |
| 23 | 29 | ||
| 24 | func (createFileCommand *CreateFileCommand) ValidateCommand() error { | 30 | func (createFileCommand *CreateFileCommand) ValidateCommand() error { |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -9,12 +10,26 @@ import ( | @@ -9,12 +10,26 @@ import ( | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type EditDataTableCommand struct { | 12 | type EditDataTableCommand struct { |
| 12 | - // 文件ID | ||
| 13 | - FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | 13 | + //// 文件ID |
| 14 | + //FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
| 15 | + // | ||
| 16 | + //Fields []*domain.Field | ||
| 17 | + domain.EditTableRequest | ||
| 14 | } | 18 | } |
| 15 | 19 | ||
| 16 | func (editDataTableCommand *EditDataTableCommand) Valid(validation *validation.Validation) { | 20 | func (editDataTableCommand *EditDataTableCommand) Valid(validation *validation.Validation) { |
| 17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 21 | + if len(editDataTableCommand.ProcessFieldNames) == 0 { |
| 22 | + validation.Error("未选择操作列") | ||
| 23 | + return | ||
| 24 | + } | ||
| 25 | + if len(editDataTableCommand.Action) == 0 { | ||
| 26 | + validation.Error("未知操作类型:" + editDataTableCommand.Action) | ||
| 27 | + return | ||
| 28 | + } | ||
| 29 | + if editDataTableCommand.FileId == 0 { | ||
| 30 | + validation.Error("文件ID不能为空") | ||
| 31 | + return | ||
| 32 | + } | ||
| 18 | } | 33 | } |
| 19 | 34 | ||
| 20 | func (editDataTableCommand *EditDataTableCommand) ValidateCommand() error { | 35 | func (editDataTableCommand *EditDataTableCommand) ValidateCommand() error { |
pkg/application/file/command/export_file.go
0 → 100644
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type ExportFileCommand struct { | ||
| 12 | + // 文件ID | ||
| 13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (cmd *ExportFileCommand) Valid(validation *validation.Validation) { | ||
| 17 | + | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (cmd *ExportFileCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(cmd) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(cmd).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
| @@ -10,11 +10,15 @@ import ( | @@ -10,11 +10,15 @@ import ( | ||
| 10 | 10 | ||
| 11 | type FlushDataTableCommand struct { | 11 | type FlushDataTableCommand struct { |
| 12 | // 文件ID | 12 | // 文件ID |
| 13 | - FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | 13 | + ObjectId int `cname:"文件ID" json:"objectId" valid:"Required"` |
| 14 | + // 记录数 | ||
| 15 | + //RowCount int `cname:"记录数" json:"rowCount" valid:"Required"` | ||
| 16 | + // 数据列 | ||
| 17 | + //DataFields []*domain.Field `cname:"数据列" json:"fields" valid:"Required"` | ||
| 14 | } | 18 | } |
| 15 | 19 | ||
| 16 | func (flushDataTableCommand *FlushDataTableCommand) Valid(validation *validation.Validation) { | 20 | func (flushDataTableCommand *FlushDataTableCommand) Valid(validation *validation.Validation) { |
| 17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 21 | + |
| 18 | } | 22 | } |
| 19 | 23 | ||
| 20 | func (flushDataTableCommand *FlushDataTableCommand) ValidateCommand() error { | 24 | func (flushDataTableCommand *FlushDataTableCommand) ValidateCommand() error { |
| @@ -11,10 +11,12 @@ import ( | @@ -11,10 +11,12 @@ import ( | ||
| 11 | type GenerateMainTableCommand struct { | 11 | type GenerateMainTableCommand struct { |
| 12 | // 文件ID | 12 | // 文件ID |
| 13 | FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | 13 | FileId int `cname:"文件ID" json:"fileId" valid:"Required"` |
| 14 | + // 表名 | ||
| 15 | + TableName string `cname:"表名" json:"tableName" valid:"Required"` | ||
| 14 | } | 16 | } |
| 15 | 17 | ||
| 16 | func (generateMainTableCommand *GenerateMainTableCommand) Valid(validation *validation.Validation) { | 18 | func (generateMainTableCommand *GenerateMainTableCommand) Valid(validation *validation.Validation) { |
| 17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 19 | + |
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | func (generateMainTableCommand *GenerateMainTableCommand) ValidateCommand() error { | 22 | func (generateMainTableCommand *GenerateMainTableCommand) ValidateCommand() error { |
| @@ -2,6 +2,7 @@ package command | @@ -2,6 +2,7 @@ package command | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 5 | "reflect" | 6 | "reflect" |
| 6 | "strings" | 7 | "strings" |
| 7 | 8 | ||
| @@ -10,11 +11,18 @@ import ( | @@ -10,11 +11,18 @@ import ( | ||
| 10 | 11 | ||
| 11 | type LoadDataTableCommand struct { | 12 | type LoadDataTableCommand struct { |
| 12 | // 文件ID | 13 | // 文件ID |
| 13 | - FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | 14 | + FileId int `cname:"文件ID" json:"objectId" valid:"Required"` |
| 15 | + Fields []*domain.Field `json:"fields"` | ||
| 16 | + domain.Where | ||
| 14 | } | 17 | } |
| 15 | 18 | ||
| 16 | func (loadDataTableCommand *LoadDataTableCommand) Valid(validation *validation.Validation) { | 19 | func (loadDataTableCommand *LoadDataTableCommand) Valid(validation *validation.Validation) { |
| 17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 20 | + if loadDataTableCommand.PageNumber == 0 { |
| 21 | + loadDataTableCommand.PageNumber = 1 | ||
| 22 | + } | ||
| 23 | + if loadDataTableCommand.PageSize == 0 { | ||
| 24 | + loadDataTableCommand.PageSize = 20 | ||
| 25 | + } | ||
| 18 | } | 26 | } |
| 19 | 27 | ||
| 20 | func (loadDataTableCommand *LoadDataTableCommand) ValidateCommand() error { | 28 | func (loadDataTableCommand *LoadDataTableCommand) ValidateCommand() error { |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type PrepareTemporaryFileCommand struct { | ||
| 12 | + // 文件ID | ||
| 13 | + FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (cmd *PrepareTemporaryFileCommand) Valid(validation *validation.Validation) { | ||
| 17 | + | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (cmd *PrepareTemporaryFileCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(cmd) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(cmd).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
| @@ -14,7 +14,7 @@ type RemoveFileCommand struct { | @@ -14,7 +14,7 @@ type RemoveFileCommand struct { | ||
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | func (removeFileCommand *RemoveFileCommand) Valid(validation *validation.Validation) { | 16 | func (removeFileCommand *RemoveFileCommand) Valid(validation *validation.Validation) { |
| 17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | func (removeFileCommand *RemoveFileCommand) ValidateCommand() error { | 20 | func (removeFileCommand *RemoveFileCommand) ValidateCommand() error { |
pkg/application/file/dto/datatable_dto.go
0 → 100644
| 1 | +package dto | ||
| 2 | + | ||
| 3 | +import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 4 | + | ||
| 5 | +type DataTableDto struct { | ||
| 6 | + FileId int `json:"fileId"` | ||
| 7 | + DataFields []*Field `json:"dataFields"` | ||
| 8 | + DataRows [][]interface{} `json:"dataRows"` | ||
| 9 | + Total int `json:"total"` | ||
| 10 | + PageNumber int `json:"pageNumber"` | ||
| 11 | + InValidCells []InValidCell `json:"inValidCells"` | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +type Field struct { | ||
| 15 | + // 索引序号 | ||
| 16 | + // Index int `json:"index"` | ||
| 17 | + // 名称 | ||
| 18 | + Name string `json:"name"` | ||
| 19 | + // 对应数据库类型 | ||
| 20 | + Type string `json:"type"` | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +type InValidCell struct { | ||
| 24 | + X int `json:"x"` | ||
| 25 | + Y int `json:"y"` | ||
| 26 | + Error string `json:"error"` | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +func NewDataTableDtoDemo(fileId int) DataTableDto { | ||
| 30 | + return DataTableDto{ | ||
| 31 | + DataFields: []*Field{ | ||
| 32 | + { | ||
| 33 | + //Index: 1, | ||
| 34 | + Name: "产品名称", | ||
| 35 | + Type: domain.String.ToString(), | ||
| 36 | + }, | ||
| 37 | + { | ||
| 38 | + //Index: 2, | ||
| 39 | + Name: "产品数量", | ||
| 40 | + Type: domain.Int.ToString(), | ||
| 41 | + }, | ||
| 42 | + }, | ||
| 43 | + DataRows: [][]interface{}{ | ||
| 44 | + {"素面", 200}, | ||
| 45 | + {"冻豆腐", 400}, | ||
| 46 | + {"冻豆腐1", 300}, | ||
| 47 | + {"冻豆2", "A"}, | ||
| 48 | + }, | ||
| 49 | + InValidCells: []InValidCell{ | ||
| 50 | + { | ||
| 51 | + X: 1, | ||
| 52 | + Y: 3, | ||
| 53 | + Error: "不是一个有效的数值", | ||
| 54 | + }, | ||
| 55 | + }, | ||
| 56 | + PageNumber: 1, | ||
| 57 | + Total: 100, | ||
| 58 | + FileId: fileId, | ||
| 59 | + } | ||
| 60 | +} |
| 1 | +package dto | ||
| 2 | + | ||
| 3 | +import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 4 | + | ||
| 5 | +type EditDataTableDto struct { | ||
| 6 | + Code int `json:"errNo,omitempty"` | ||
| 7 | + Error string `json:"errMsg,omitempty"` | ||
| 8 | + InValidCells []domain.InValidCell `json:"inValidCells,omitempty"` | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +func (d *EditDataTableDto) Load(m *domain.DataEditDataTable) *EditDataTableDto { | ||
| 12 | + d.Error = "" | ||
| 13 | + if len(m.InValidCells) > 0 { | ||
| 14 | + d.Error = "类型转换错误" | ||
| 15 | + d.Code = 1001 // 1001:类型转换错误 | ||
| 16 | + } | ||
| 17 | + //d.InValidCells = m.InValidCells | ||
| 18 | + return d | ||
| 19 | +} |
pkg/application/file/dto/file_dto.go
0 → 100644
| 1 | +package dto | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type FileDto struct { | ||
| 9 | + // 文件ID | ||
| 10 | + FileId int `json:"fileId"` | ||
| 11 | + // 名称 | ||
| 12 | + Name string `json:"name"` | ||
| 13 | + // 文件地址 | ||
| 14 | + Url string `json:"url"` | ||
| 15 | + // 文件类型 | ||
| 16 | + FileType string `json:"fileType"` | ||
| 17 | + // 后缀扩展 | ||
| 18 | + Ext string `json:"ext"` | ||
| 19 | + // 创建时间 | ||
| 20 | + Time string `json:"time"` | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +func (d *FileDto) Load(f *domain.File) { | ||
| 24 | + d.FileId = f.FileId | ||
| 25 | + d.Name = f.FileInfo.Name | ||
| 26 | + d.Url = f.FileInfo.Url | ||
| 27 | + d.FileType = f.FileType | ||
| 28 | + d.Ext = f.FileInfo.Ext | ||
| 29 | + d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05") | ||
| 30 | +} |
pkg/application/file/query/search_file.go
0 → 100644
| 1 | +package query | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 6 | + "reflect" | ||
| 7 | + "strings" | ||
| 8 | + | ||
| 9 | + "github.com/beego/beego/v2/core/validation" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type SearchFileQuery struct { | ||
| 13 | + // 查询偏离量 | ||
| 14 | + // Offset int `cname:"查询偏离量" json:"offset"` | ||
| 15 | + // 查询限制 | ||
| 16 | + Limit int `cname:"查询限制" json:"limit"` | ||
| 17 | + // 页码 | ||
| 18 | + // PageNumber int `cname:"页码" json:"pageNumber,omitempty"` | ||
| 19 | + // 页数 | ||
| 20 | + FileName string `cname:"文件名称" json:"fileName,omitempty"` | ||
| 21 | + PageSize int `cname:"页数" json:"pageSize,omitempty"` | ||
| 22 | + LastId int `cname:"最后一条记录ID" json:"lastId"` | ||
| 23 | + FileType domain.FileType `cname:"文件类型" json:"fileType" valid:"Required"` | ||
| 24 | + Context *domain.Context | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +func (cmd *SearchFileQuery) Valid(validation *validation.Validation) { | ||
| 28 | + cmd.Limit = cmd.PageSize | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +func (cmd *SearchFileQuery) ValidateQuery() error { | ||
| 32 | + valid := validation.Validation{} | ||
| 33 | + b, err := valid.Valid(cmd) | ||
| 34 | + if err != nil { | ||
| 35 | + return err | ||
| 36 | + } | ||
| 37 | + if !b { | ||
| 38 | + elem := reflect.TypeOf(cmd).Elem() | ||
| 39 | + for _, validErr := range valid.Errors { | ||
| 40 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 41 | + if isExist { | ||
| 42 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 43 | + } else { | ||
| 44 | + return fmt.Errorf(validErr.Message) | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + return nil | ||
| 49 | +} |
pkg/application/file/service/data_table.go
0 → 100644
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "bytes" | ||
| 5 | + "fmt" | ||
| 6 | + "github.com/beego/beego/v2/client/httplib" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel" | ||
| 8 | + "time" | ||
| 9 | + | ||
| 10 | + "github.com/linmadan/egglib-go/core/application" | ||
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | ||
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" | ||
| 13 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/dto" | ||
| 14 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 15 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" | ||
| 16 | +) | ||
| 17 | + | ||
| 18 | +// FilePreview 加载表格数据 | ||
| 19 | +func (fileService *FileService) FilePreview(ctx *domain.Context, loadDataTableCommand *command.LoadDataTableCommand) (interface{}, error) { | ||
| 20 | + if err := loadDataTableCommand.ValidateCommand(); err != nil { | ||
| 21 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 22 | + } | ||
| 23 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 24 | + if err != nil { | ||
| 25 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 26 | + } | ||
| 27 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 28 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 29 | + } | ||
| 30 | + defer func() { | ||
| 31 | + transactionContext.RollbackTransaction() | ||
| 32 | + }() | ||
| 33 | + | ||
| 34 | + loadDataTableService, _ := factory.CreateLoadDataTableService(transactionContext) | ||
| 35 | + data, err := loadDataTableService.Preview(ctx, loadDataTableCommand.FileId, loadDataTableCommand.Fields, loadDataTableCommand.Where) | ||
| 36 | + if err != nil { | ||
| 37 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 41 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + return data, nil | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +// PrepareTemporaryFile 准备临时文件 | ||
| 48 | +func (fileService *FileService) PrepareTemporaryFile(ctx *domain.Context, cmd *command.PrepareTemporaryFileCommand) (interface{}, error) { | ||
| 49 | + if err := cmd.ValidateCommand(); err != nil { | ||
| 50 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 51 | + } | ||
| 52 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 53 | + if err != nil { | ||
| 54 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 55 | + } | ||
| 56 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 57 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 58 | + } | ||
| 59 | + defer func() { | ||
| 60 | + transactionContext.RollbackTransaction() | ||
| 61 | + }() | ||
| 62 | + | ||
| 63 | + loadDataTableService, _ := factory.CreateLoadDataTableService(transactionContext) | ||
| 64 | + data, err := loadDataTableService.CreateTemporaryFile(ctx, cmd.FileId) | ||
| 65 | + if err != nil { | ||
| 66 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 70 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + fileDto := &dto.FileDto{} | ||
| 74 | + fileDto.Load(data) | ||
| 75 | + return fileDto, nil | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +// EditDataTable 编辑表格数据 | ||
| 79 | +func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTableCommand *command.EditDataTableCommand) (interface{}, error) { | ||
| 80 | + if err := editDataTableCommand.ValidateCommand(); err != nil { | ||
| 81 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 82 | + } | ||
| 83 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 84 | + if err != nil { | ||
| 85 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 86 | + } | ||
| 87 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 88 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 89 | + } | ||
| 90 | + defer func() { | ||
| 91 | + transactionContext.RollbackTransaction() | ||
| 92 | + }() | ||
| 93 | + | ||
| 94 | + cache := redis.NewFileCacheService() | ||
| 95 | + temporaryFile, err := cache.Get(redis.KeyTemporaryFileInfo(editDataTableCommand.FileId)) | ||
| 96 | + if err != nil { | ||
| 97 | + return nil, factory.FastError(err) | ||
| 98 | + } | ||
| 99 | + editDataTableCommand.Fields = temporaryFile.Fields | ||
| 100 | + editDataTableCommand.ProcessFields = temporaryFile.MatchFields(editDataTableCommand.ProcessFieldNames) | ||
| 101 | + if len(editDataTableCommand.ProcessFields) == 0 { | ||
| 102 | + return nil, factory.FastError(fmt.Errorf("请至少选择一个数据列")) | ||
| 103 | + } | ||
| 104 | + // allowAction := func(fields []*domain.Field, action string) error { | ||
| 105 | + // for _, f := range fields { | ||
| 106 | + // if f.SQLType != string(domain.String) && | ||
| 107 | + // !(action == domain.RemoveColumn || action == domain.CopyColumn || action == domain.RenameColumn || action == domain.ConvertColumnType) { | ||
| 108 | + // return fmt.Errorf("列【%v】必须先转字符串类型",f.Name) | ||
| 109 | + // } | ||
| 110 | + // } | ||
| 111 | + // return nil | ||
| 112 | + // } | ||
| 113 | + // if err = allowAction(editDataTableCommand.ProcessFields, editDataTableCommand.Action); err != nil { | ||
| 114 | + // return nil, factory.FastError(err) | ||
| 115 | + // } | ||
| 116 | + editDataTableService, _ := factory.CreateEditDataTableService(transactionContext) | ||
| 117 | + response, err := editDataTableService.Edit(ctx, editDataTableCommand.EditTableRequest) | ||
| 118 | + if err != nil { | ||
| 119 | + return nil, factory.FastError(err) | ||
| 120 | + } | ||
| 121 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 122 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 123 | + } | ||
| 124 | + return (&dto.EditDataTableDto{}).Load(response), nil | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +// FlushDataTable 持久化表格数据 | ||
| 128 | +func (fileService *FileService) FlushDataTable(ctx *domain.Context, flushDataTableCommand *command.FlushDataTableCommand) (interface{}, error) { | ||
| 129 | + if err := flushDataTableCommand.ValidateCommand(); err != nil { | ||
| 130 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 131 | + } | ||
| 132 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 133 | + if err != nil { | ||
| 134 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 135 | + } | ||
| 136 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 137 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 138 | + } | ||
| 139 | + defer func() { | ||
| 140 | + transactionContext.RollbackTransaction() | ||
| 141 | + }() | ||
| 142 | + flushDataTableService, _ := factory.CreateFlushDataTableService(transactionContext) | ||
| 143 | + cache := redis.NewFileCacheService() | ||
| 144 | + temporaryFile, err := cache.Get(redis.KeyTemporaryFileInfo(flushDataTableCommand.ObjectId)) | ||
| 145 | + if err != nil { | ||
| 146 | + return nil, factory.FastError(err) | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + if _, err := flushDataTableService.Flush(ctx, flushDataTableCommand.ObjectId, &domain.Table{ | ||
| 150 | + DataFields: temporaryFile.Fields, | ||
| 151 | + RowCount: temporaryFile.Total, | ||
| 152 | + }); err != nil { | ||
| 153 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 154 | + } | ||
| 155 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 156 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 157 | + } | ||
| 158 | + return struct{}{}, nil | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | +// GenerateMainTable 生成主表 | ||
| 162 | +func (fileService *FileService) GenerateMainTable(ctx *domain.Context, generateMainTableCommand *command.GenerateMainTableCommand) (interface{}, error) { | ||
| 163 | + if err := generateMainTableCommand.ValidateCommand(); err != nil { | ||
| 164 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 165 | + } | ||
| 166 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 167 | + if err != nil { | ||
| 168 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 169 | + } | ||
| 170 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 171 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 172 | + } | ||
| 173 | + defer func() { | ||
| 174 | + transactionContext.RollbackTransaction() | ||
| 175 | + }() | ||
| 176 | + | ||
| 177 | + generateMainTableService, _ := factory.CreateGenerateMainTableService(transactionContext) | ||
| 178 | + _, err = generateMainTableService.GenerateTable(ctx, generateMainTableCommand.FileId, generateMainTableCommand.TableName) | ||
| 179 | + if err != nil { | ||
| 180 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 181 | + } | ||
| 182 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 183 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 184 | + } | ||
| 185 | + return struct{}{}, nil | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +// AppendDataToTable 追加数据 | ||
| 189 | +func (fileService *FileService) AppendDataToTable(ctx *domain.Context, cmd *command.AppendDataToTableCommand) (interface{}, error) { | ||
| 190 | + if err := cmd.ValidateCommand(); err != nil { | ||
| 191 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 192 | + } | ||
| 193 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 194 | + if err != nil { | ||
| 195 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 196 | + } | ||
| 197 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 198 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 199 | + } | ||
| 200 | + defer func() { | ||
| 201 | + transactionContext.RollbackTransaction() | ||
| 202 | + }() | ||
| 203 | + | ||
| 204 | + generateMainTableService, _ := factory.CreateAppendDataToTableService(transactionContext) | ||
| 205 | + result, err := generateMainTableService.AppendData(ctx, cmd.FileId, cmd.TableId, cmd.MappingFields) | ||
| 206 | + if err != nil { | ||
| 207 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 208 | + } | ||
| 209 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 210 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 211 | + } | ||
| 212 | + return result, nil | ||
| 213 | +} | ||
| 214 | + | ||
| 215 | +// ExportFile 文件下载 | ||
| 216 | +func (fileService *FileService) ExportFile(ctx *domain.Context, cmd *command.ExportFileCommand) (interface{}, error) { | ||
| 217 | + if err := cmd.ValidateCommand(); err != nil { | ||
| 218 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 219 | + } | ||
| 220 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 221 | + if err != nil { | ||
| 222 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 223 | + } | ||
| 224 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 225 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 226 | + } | ||
| 227 | + defer func() { | ||
| 228 | + transactionContext.RollbackTransaction() | ||
| 229 | + }() | ||
| 230 | + | ||
| 231 | + _, file, err := factory.FastPgFile(transactionContext, cmd.FileId) | ||
| 232 | + if err != nil { | ||
| 233 | + return nil, factory.FastError(err) | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + var response = struct { | ||
| 237 | + Url string `json:"url"` | ||
| 238 | + Ext string `json:"ext"` | ||
| 239 | + FileName string `json:"fileName"` | ||
| 240 | + }{} | ||
| 241 | + if file.FileType == domain.SourceFile.ToString() { | ||
| 242 | + response.Url = file.FileInfo.Url | ||
| 243 | + response.Ext = domain.XLSX | ||
| 244 | + response.FileName = file.FileInfo.Name | ||
| 245 | + return response, nil | ||
| 246 | + } | ||
| 247 | + _, table, err := factory.FastPgTable(transactionContext, file.FileInfo.TableId) | ||
| 248 | + if err != nil { | ||
| 249 | + return nil, factory.FastError(err) | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + f, err := httplib.Get(file.FileInfo.Url).Bytes() | ||
| 253 | + if err != nil { | ||
| 254 | + return nil, factory.FastError(err) | ||
| 255 | + } | ||
| 256 | + reader := bytes.NewReader(f) | ||
| 257 | + var importer *excel.Importer = excel.NewExcelImportByFile(file.FileInfo.Ext) | ||
| 258 | + data, err := importer.OpenExcelFromIoReader(reader) | ||
| 259 | + if err != nil { | ||
| 260 | + return nil, factory.FastError(err) | ||
| 261 | + } | ||
| 262 | + filename := fmt.Sprintf("%v_%v.xlsx", file.FileInfo.Name, time.Now().Format("060102150405")) | ||
| 263 | + path := fmt.Sprintf("public/%v", filename) | ||
| 264 | + writerTo := excel.NewXLXSWriterTo(importer.Reader().Header().Columns, data) | ||
| 265 | + writerTo.ToInterfaces = domain.MakeToInterfaces(table.DataFields) | ||
| 266 | + if err := writerTo.Save(path); err != nil { | ||
| 267 | + return nil, factory.FastError(err) | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + response.Url = domain.DownloadUrl(filename) | ||
| 271 | + response.FileName = file.FileInfo.Name | ||
| 272 | + response.Ext = domain.XLSX | ||
| 273 | + | ||
| 274 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 275 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 276 | + } | ||
| 277 | + return response, nil | ||
| 278 | +} |
| @@ -2,12 +2,18 @@ package service | @@ -2,12 +2,18 @@ package service | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "path/filepath" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 5 | "github.com/linmadan/egglib-go/core/application" | 8 | "github.com/linmadan/egglib-go/core/application" |
| 6 | "github.com/linmadan/egglib-go/utils/tool_funs" | 9 | "github.com/linmadan/egglib-go/utils/tool_funs" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" |
| 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" | 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" |
| 12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/dto" | ||
| 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query" | 13 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/query" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 14 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
| 15 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService" | ||
| 16 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" | ||
| 11 | ) | 17 | ) |
| 12 | 18 | ||
| 13 | // 文件服务 | 19 | // 文件服务 |
| @@ -15,7 +21,7 @@ type FileService struct { | @@ -15,7 +21,7 @@ type FileService struct { | ||
| 15 | } | 21 | } |
| 16 | 22 | ||
| 17 | // 创建文件服务 | 23 | // 创建文件服务 |
| 18 | -func (fileService *FileService) CreateFile(createFileCommand *command.CreateFileCommand) (interface{}, error) { | 24 | +func (fileService *FileService) CreateFile(ctx *domain.Context, createFileCommand *command.CreateFileCommand) (interface{}, error) { |
| 19 | if err := createFileCommand.ValidateCommand(); err != nil { | 25 | if err := createFileCommand.ValidateCommand(); err != nil { |
| 20 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 26 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 21 | } | 27 | } |
| @@ -29,90 +35,47 @@ func (fileService *FileService) CreateFile(createFileCommand *command.CreateFile | @@ -29,90 +35,47 @@ func (fileService *FileService) CreateFile(createFileCommand *command.CreateFile | ||
| 29 | defer func() { | 35 | defer func() { |
| 30 | transactionContext.RollbackTransaction() | 36 | transactionContext.RollbackTransaction() |
| 31 | }() | 37 | }() |
| 32 | - newFile := &domain.File{ | ||
| 33 | - //Name: createFileCommand.Name, | ||
| 34 | - //Url: createFileCommand.Url, | ||
| 35 | - //FileSize: createFileCommand.FileSize, | ||
| 36 | - } | ||
| 37 | - var fileRepository domain.FileRepository | ||
| 38 | - if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
| 39 | - "transactionContext": transactionContext, | ||
| 40 | - }); err != nil { | ||
| 41 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 42 | - } else { | ||
| 43 | - fileRepository = value | 38 | + fileInfo := &domain.FileInfo{ |
| 39 | + Name: domain.FileName(createFileCommand.Name), | ||
| 40 | + Url: createFileCommand.Url, | ||
| 41 | + FileSize: createFileCommand.FileSize, | ||
| 42 | + Ext: filepath.Ext(createFileCommand.Name), | ||
| 44 | } | 43 | } |
| 45 | - if file, err := fileRepository.Save(newFile); err != nil { | ||
| 46 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 47 | - } else { | ||
| 48 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 49 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 50 | - } | ||
| 51 | - return file, nil | ||
| 52 | - } | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -// 编辑表格数据 | ||
| 56 | -func (fileService *FileService) EditDataTable(editDataTableCommand *command.EditDataTableCommand) (interface{}, error) { | ||
| 57 | - if err := editDataTableCommand.ValidateCommand(); err != nil { | ||
| 58 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 59 | - } | ||
| 60 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 61 | - if err != nil { | ||
| 62 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 63 | - } | ||
| 64 | - if err := transactionContext.StartTransaction(); err != nil { | ||
| 65 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 66 | - } | ||
| 67 | - defer func() { | ||
| 68 | - transactionContext.RollbackTransaction() | ||
| 69 | - }() | ||
| 70 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 71 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 72 | - } | ||
| 73 | - return nil, nil | ||
| 74 | -} | 44 | + newFile := &domain.File{ |
| 45 | + FileType: domain.SourceFile.ToString(), | ||
| 46 | + FileInfo: fileInfo, | ||
| 47 | + SourceFileId: 0, | ||
| 48 | + //Operator: "", | ||
| 49 | + CreatedAt: time.Now(), | ||
| 50 | + UpdatedAt: time.Now(), | ||
| 51 | + Context: ctx, | ||
| 52 | + } | ||
| 53 | + fileRepository, _, _ := factory.FastPgFile(transactionContext, 0) | ||
| 75 | 54 | ||
| 76 | -// 持久化表格数据 | ||
| 77 | -func (fileService *FileService) FlushDataTable(flushDataTableCommand *command.FlushDataTableCommand) (interface{}, error) { | ||
| 78 | - if err := flushDataTableCommand.ValidateCommand(); err != nil { | ||
| 79 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 80 | - } | ||
| 81 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 82 | - if err != nil { | ||
| 83 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 84 | - } | ||
| 85 | - if err := transactionContext.StartTransaction(); err != nil { | ||
| 86 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 55 | + // 文件名相同进行替换 |
| 56 | + if oldFile, findOldFileErr := fileRepository.FindOne(map[string]interface{}{ | ||
| 57 | + "context": ctx, | ||
| 58 | + "fileName": fileInfo.Name, | ||
| 59 | + "fileType": domain.SourceFile.ToString(), | ||
| 60 | + }); oldFile != nil && findOldFileErr == nil { | ||
| 61 | + oldFile.FileInfo = fileInfo | ||
| 62 | + oldFile.UpdatedAt = time.Now() | ||
| 63 | + newFile = oldFile | ||
| 87 | } | 64 | } |
| 88 | - defer func() { | ||
| 89 | - transactionContext.RollbackTransaction() | ||
| 90 | - }() | ||
| 91 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
| 92 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 93 | - } | ||
| 94 | - return nil, nil | ||
| 95 | -} | ||
| 96 | 65 | ||
| 97 | -// 生成主表 | ||
| 98 | -func (fileService *FileService) GenerateMainTable(generateMainTableCommand *command.GenerateMainTableCommand) (interface{}, error) { | ||
| 99 | - if err := generateMainTableCommand.ValidateCommand(); err != nil { | ||
| 100 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 101 | - } | ||
| 102 | - transactionContext, err := factory.CreateTransactionContext(nil) | 66 | + file, err := fileRepository.Save(newFile) |
| 103 | if err != nil { | 67 | if err != nil { |
| 104 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 68 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 105 | } | 69 | } |
| 106 | - if err := transactionContext.StartTransaction(); err != nil { | ||
| 107 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 70 | + if err = factory.FastLog(transactionContext, domain.CommonLog, file.FileId, &domainService.FileUploadSuccessLog{ |
| 71 | + LogEntry: domain.NewLogEntry(file.FileInfo.Name, domain.SourceFile.ToString(), domain.FileUpload, ctx), | ||
| 72 | + }); err != nil { | ||
| 73 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 108 | } | 74 | } |
| 109 | - defer func() { | ||
| 110 | - transactionContext.RollbackTransaction() | ||
| 111 | - }() | ||
| 112 | if err := transactionContext.CommitTransaction(); err != nil { | 75 | if err := transactionContext.CommitTransaction(); err != nil { |
| 113 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 76 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 114 | } | 77 | } |
| 115 | - return nil, nil | 78 | + return struct{}{}, nil |
| 116 | } | 79 | } |
| 117 | 80 | ||
| 118 | // 返回文件服务 | 81 | // 返回文件服务 |
| @@ -143,7 +106,7 @@ func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (inter | @@ -143,7 +106,7 @@ func (fileService *FileService) GetFile(getFileQuery *query.GetFileQuery) (inter | ||
| 143 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 106 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 144 | } | 107 | } |
| 145 | if file == nil { | 108 | if file == nil { |
| 146 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getFileQuery.FileId))) | 109 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", getFileQuery.FileId)) |
| 147 | } else { | 110 | } else { |
| 148 | if err := transactionContext.CommitTransaction(); err != nil { | 111 | if err := transactionContext.CommitTransaction(); err != nil { |
| 149 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 112 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| @@ -188,9 +151,9 @@ func (fileService *FileService) ListFile(listFileQuery *query.ListFileQuery) (in | @@ -188,9 +151,9 @@ func (fileService *FileService) ListFile(listFileQuery *query.ListFileQuery) (in | ||
| 188 | } | 151 | } |
| 189 | } | 152 | } |
| 190 | 153 | ||
| 191 | -// 加载表格数据 | ||
| 192 | -func (fileService *FileService) LoadDataTable(loadDataTableCommand *command.LoadDataTableCommand) (interface{}, error) { | ||
| 193 | - if err := loadDataTableCommand.ValidateCommand(); err != nil { | 154 | +// 返回文件服务列表 |
| 155 | +func (fileService *FileService) SearchFile(listFileQuery *query.SearchFileQuery) (interface{}, error) { | ||
| 156 | + if err := listFileQuery.ValidateQuery(); err != nil { | ||
| 194 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 157 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 195 | } | 158 | } |
| 196 | transactionContext, err := factory.CreateTransactionContext(nil) | 159 | transactionContext, err := factory.CreateTransactionContext(nil) |
| @@ -203,14 +166,35 @@ func (fileService *FileService) LoadDataTable(loadDataTableCommand *command.Load | @@ -203,14 +166,35 @@ func (fileService *FileService) LoadDataTable(loadDataTableCommand *command.Load | ||
| 203 | defer func() { | 166 | defer func() { |
| 204 | transactionContext.RollbackTransaction() | 167 | transactionContext.RollbackTransaction() |
| 205 | }() | 168 | }() |
| 169 | + var fileRepository domain.FileRepository | ||
| 170 | + if value, err := factory.CreateFileRepository(map[string]interface{}{ | ||
| 171 | + "transactionContext": transactionContext, | ||
| 172 | + }); err != nil { | ||
| 173 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 174 | + } else { | ||
| 175 | + fileRepository = value | ||
| 176 | + } | ||
| 177 | + count, files, err := fileRepository.Find(utils.ObjectToMap(listFileQuery)) | ||
| 178 | + if err != nil { | ||
| 179 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 180 | + } | ||
| 181 | + var fileDtos = make([]*dto.FileDto, 0) | ||
| 182 | + for _, file := range files { | ||
| 183 | + var item = &dto.FileDto{} | ||
| 184 | + item.Load(file) | ||
| 185 | + fileDtos = append(fileDtos, item) | ||
| 186 | + } | ||
| 206 | if err := transactionContext.CommitTransaction(); err != nil { | 187 | if err := transactionContext.CommitTransaction(); err != nil { |
| 207 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 188 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 208 | } | 189 | } |
| 209 | - return nil, nil | 190 | + return map[string]interface{}{ |
| 191 | + "count": count, | ||
| 192 | + "files": fileDtos, | ||
| 193 | + }, nil | ||
| 210 | } | 194 | } |
| 211 | 195 | ||
| 212 | // 移除文件服务 | 196 | // 移除文件服务 |
| 213 | -func (fileService *FileService) RemoveFile(removeFileCommand *command.RemoveFileCommand) (interface{}, error) { | 197 | +func (fileService *FileService) RemoveFile(ctx *domain.Context, removeFileCommand *command.RemoveFileCommand) (interface{}, error) { |
| 214 | if err := removeFileCommand.ValidateCommand(); err != nil { | 198 | if err := removeFileCommand.ValidateCommand(); err != nil { |
| 215 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 199 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
| 216 | } | 200 | } |
| @@ -237,16 +221,17 @@ func (fileService *FileService) RemoveFile(removeFileCommand *command.RemoveFile | @@ -237,16 +221,17 @@ func (fileService *FileService) RemoveFile(removeFileCommand *command.RemoveFile | ||
| 237 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 221 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 238 | } | 222 | } |
| 239 | if file == nil { | 223 | if file == nil { |
| 240 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeFileCommand.FileId))) | 224 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", removeFileCommand.FileId)) |
| 241 | } | 225 | } |
| 242 | - if file, err := fileRepository.Remove(file); err != nil { | 226 | + deleteFileService, _ := factory.CreateDeleteFileService(transactionContext) |
| 227 | + err = deleteFileService.DeleteFiles(ctx, file) | ||
| 228 | + if err != nil { | ||
| 243 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 229 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 244 | - } else { | 230 | + } |
| 245 | if err := transactionContext.CommitTransaction(); err != nil { | 231 | if err := transactionContext.CommitTransaction(); err != nil { |
| 246 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 232 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 247 | } | 233 | } |
| 248 | - return file, nil | ||
| 249 | - } | 234 | + return struct{}{}, nil |
| 250 | } | 235 | } |
| 251 | 236 | ||
| 252 | // 更新文件服务 | 237 | // 更新文件服务 |
| @@ -277,7 +262,7 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile | @@ -277,7 +262,7 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile | ||
| 277 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 262 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 278 | } | 263 | } |
| 279 | if file == nil { | 264 | if file == nil { |
| 280 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateFileCommand.FileId))) | 265 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%d", updateFileCommand.FileId)) |
| 281 | } | 266 | } |
| 282 | if err := file.Update(tool_funs.SimpleStructToMap(updateFileCommand)); err != nil { | 267 | if err := file.Update(tool_funs.SimpleStructToMap(updateFileCommand)); err != nil { |
| 283 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 268 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
| @@ -292,6 +277,82 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile | @@ -292,6 +277,82 @@ func (fileService *FileService) UpdateFile(updateFileCommand *command.UpdateFile | ||
| 292 | } | 277 | } |
| 293 | } | 278 | } |
| 294 | 279 | ||
| 280 | +// 取消校验中的文件 | ||
| 281 | +func (fileService *FileService) CancelVerifyingFile(ctx *domain.Context, cmd *command.CancelVerifyingFileCommand) (interface{}, error) { | ||
| 282 | + if err := cmd.ValidateCommand(); err != nil { | ||
| 283 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 284 | + } | ||
| 285 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 286 | + if err != nil { | ||
| 287 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 288 | + } | ||
| 289 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 290 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 291 | + } | ||
| 292 | + defer func() { | ||
| 293 | + transactionContext.RollbackTransaction() | ||
| 294 | + }() | ||
| 295 | + | ||
| 296 | + _, file, err := factory.FastPgFile(transactionContext, cmd.FileId) | ||
| 297 | + if err != nil { | ||
| 298 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 299 | + } | ||
| 300 | + if file.FileType != domain.TemporaryFile.ToString() { | ||
| 301 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "校验中的文件才允许取消") | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + deleteFileService, _ := factory.CreateDeleteFileService(transactionContext) | ||
| 305 | + err = deleteFileService.DeleteFiles(nil, file) | ||
| 306 | + if err != nil { | ||
| 307 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + byteCore, _ := factory.CreateByteCoreService(transactionContext) | ||
| 311 | + _, err = byteCore.CancelFile(domain.ReqCancelFile{}) | ||
| 312 | + if err != nil { | ||
| 313 | + return nil, factory.FastError(err) | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 317 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 318 | + } | ||
| 319 | + return struct{}{}, nil | ||
| 320 | +} | ||
| 321 | + | ||
| 322 | +// CheckFileVerifyStatus 检查文件校验状态 | ||
| 323 | +func (fileService *FileService) CheckFileVerifyStatus(ctx *domain.Context, cmd *command.CheckFileVerifyStatusCommand) (interface{}, error) { | ||
| 324 | + if err := cmd.ValidateCommand(); err != nil { | ||
| 325 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 326 | + } | ||
| 327 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 328 | + if err != nil { | ||
| 329 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 330 | + } | ||
| 331 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 332 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 333 | + } | ||
| 334 | + defer func() { | ||
| 335 | + transactionContext.RollbackTransaction() | ||
| 336 | + }() | ||
| 337 | + | ||
| 338 | + fileRepository, file, err := factory.FastPgFile(transactionContext, cmd.FileId) | ||
| 339 | + if err != nil { | ||
| 340 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 341 | + } | ||
| 342 | + var res = struct { | ||
| 343 | + ExistVerifyFile bool `json:"existVerifyFile"` | ||
| 344 | + }{} | ||
| 345 | + _, verifyFiles, findErr := fileRepository.Find(map[string]interface{}{"context": ctx, "fileType": domain.VerifiedFile.ToString(), "sourceFileId": file.SourceFileId}) | ||
| 346 | + if findErr == nil && len(verifyFiles) > 0 { | ||
| 347 | + res.ExistVerifyFile = true | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 351 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 352 | + } | ||
| 353 | + return res, nil | ||
| 354 | +} | ||
| 355 | + | ||
| 295 | func NewFileService(options map[string]interface{}) *FileService { | 356 | func NewFileService(options map[string]interface{}) *FileService { |
| 296 | newFileService := &FileService{} | 357 | newFileService := &FileService{} |
| 297 | return newFileService | 358 | return newFileService |
pkg/application/log/command/create_log.go
0 → 100644
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type CreateLogCommand struct { | ||
| 12 | + // 对象名称 数据表名 / 文件名 | ||
| 13 | + ObjectName string `cname:"对象名称 数据表名 / 文件名" json:"objectName" valid:"Required"` | ||
| 14 | + // 对象类型 1.主表 2.分表 3.副表 4.源文件 5.校验文件 | ||
| 15 | + ObjectType string `cname:"对象类型 1.主表 2.分表 3.副表 4.源文件 5.校验文件" json:"objectType" valid:"Required"` | ||
| 16 | + // 操作类型 1.主表生成 2.主表拆分 3.数据导入 4.分表生成 5.表复制 6.编辑记录 7.文件上传 8.文件校验 | ||
| 17 | + OperationType string `cname:"操作类型 1.主表生成 2.主表拆分 3.数据导入 4.分表生成 5.表复制 6.编辑记录 7.文件上传 8.文件校验" json:"operationType" valid:"Required"` | ||
| 18 | + // 日志内容 | ||
| 19 | + Content string `cname:"日志内容" json:"content" valid:"Required"` | ||
| 20 | + // 操作人名称 | ||
| 21 | + OperatorName string `cname:"操作人名称" json:"operatorName" valid:"Required"` | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (createLogCommand *CreateLogCommand) Valid(validation *validation.Validation) { | ||
| 25 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func (createLogCommand *CreateLogCommand) ValidateCommand() error { | ||
| 29 | + valid := validation.Validation{} | ||
| 30 | + b, err := valid.Valid(createLogCommand) | ||
| 31 | + if err != nil { | ||
| 32 | + return err | ||
| 33 | + } | ||
| 34 | + if !b { | ||
| 35 | + elem := reflect.TypeOf(createLogCommand).Elem() | ||
| 36 | + for _, validErr := range valid.Errors { | ||
| 37 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 38 | + if isExist { | ||
| 39 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 40 | + } else { | ||
| 41 | + return fmt.Errorf(validErr.Message) | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + return nil | ||
| 46 | +} |
pkg/application/log/command/remove_log.go
0 → 100644
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type RemoveLogCommand struct { | ||
| 12 | + // 日志ID | ||
| 13 | + LogId int `cname:"日志ID" json:"logId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (removeLogCommand *RemoveLogCommand) Valid(validation *validation.Validation) { | ||
| 17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (removeLogCommand *RemoveLogCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(removeLogCommand) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(removeLogCommand).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
pkg/application/log/command/search_log.go
0 → 100644
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + "time" | ||
| 8 | + | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 10 | + | ||
| 11 | + "github.com/beego/beego/v2/core/validation" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type SearchLogCommand struct { | ||
| 15 | + // 日志类型 VerifiedStepLog:校验步骤 CommonLog:常规日志 | ||
| 16 | + LogType string `json:"logType"` | ||
| 17 | + // 日志内容 | ||
| 18 | + MatchContent string `cname:"匹配日志内容" json:"matchContent,omitempty"` | ||
| 19 | + // 源数据ID | ||
| 20 | + SourceId int `cname:"源数据ID" json:"sourceId"` | ||
| 21 | + // 多个源数据ID | ||
| 22 | + InSourceId []int `cname:"多个源数据ID" json:"inSourceId"` | ||
| 23 | + // 页码 | ||
| 24 | + PageNumber int `cname:"页码" json:"pageNumber,omitempty"` | ||
| 25 | + // 页数 | ||
| 26 | + PageSize int `cname:"页数" json:"pageSize,omitempty"` | ||
| 27 | + // 对象名称 | ||
| 28 | + ObjectName string `cname:"页数" json:"objectName,omitempty"` | ||
| 29 | + | ||
| 30 | + Year int `cname:"年" json:"year,omitempty"` | ||
| 31 | + Month int `cname:"月" json:"month,omitempty"` | ||
| 32 | + Day int `cname:"日" json:"day,omitempty"` | ||
| 33 | + // 开始时间 | ||
| 34 | + BeginTime time.Time `cname:"开始时间" json:"beginTime"` | ||
| 35 | + // 结束时间 | ||
| 36 | + EndTime time.Time `cname:"结束时间" json:"endTime"` | ||
| 37 | + // 按log_id 排序 | ||
| 38 | + SortByLogId string `json:"sortByLogId"` | ||
| 39 | + Context *domain.Context | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +func (cmd *SearchLogCommand) Valid(validation *validation.Validation) { | ||
| 43 | + if cmd.Year > 0 && cmd.Month == 0 && cmd.Day == 0 { | ||
| 44 | + cmd.BeginTime = time.Date(cmd.Year, 1, 1, 0, 0, 0, 0, time.Local) | ||
| 45 | + cmd.EndTime = cmd.BeginTime.AddDate(1, 0, 0) | ||
| 46 | + } | ||
| 47 | + if cmd.Year > 0 && cmd.Month > 0 && cmd.Day == 0 { | ||
| 48 | + cmd.BeginTime = time.Date(cmd.Year, time.Month(cmd.Month), 1, 0, 0, 0, 0, time.Local) | ||
| 49 | + cmd.EndTime = cmd.BeginTime.AddDate(0, 1, 0) | ||
| 50 | + } | ||
| 51 | + if cmd.Year > 0 && cmd.Month > 0 && cmd.Day > 0 { | ||
| 52 | + cmd.BeginTime = time.Date(cmd.Year, time.Month(cmd.Month), cmd.Day, 0, 0, 0, 0, time.Local) | ||
| 53 | + cmd.EndTime = cmd.BeginTime.AddDate(0, 0, 1) | ||
| 54 | + } | ||
| 55 | + if cmd.PageNumber == 0 { | ||
| 56 | + cmd.PageNumber = 1 | ||
| 57 | + } | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +func (cmd *SearchLogCommand) ValidateCommand() error { | ||
| 61 | + valid := validation.Validation{} | ||
| 62 | + b, err := valid.Valid(cmd) | ||
| 63 | + if err != nil { | ||
| 64 | + return err | ||
| 65 | + } | ||
| 66 | + if !b { | ||
| 67 | + elem := reflect.TypeOf(cmd).Elem() | ||
| 68 | + for _, validErr := range valid.Errors { | ||
| 69 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 70 | + if isExist { | ||
| 71 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 72 | + } else { | ||
| 73 | + return fmt.Errorf(validErr.Message) | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + return nil | ||
| 78 | +} |
pkg/application/log/command/update_log.go
0 → 100644
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type UpdateLogCommand struct { | ||
| 12 | + // 日志ID | ||
| 13 | + LogId int `cname:"日志ID" json:"logId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (updateLogCommand *UpdateLogCommand) Valid(validation *validation.Validation) { | ||
| 17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (updateLogCommand *UpdateLogCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(updateLogCommand) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(updateLogCommand).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
pkg/application/log/dto/log_dto.go
0 → 100644
| 1 | +package dto | ||
| 2 | + | ||
| 3 | +import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 4 | + | ||
| 5 | +type LogDto struct { | ||
| 6 | + // 日志ID | ||
| 7 | + LogId int `json:"logId"` | ||
| 8 | + // 日志类型 1.校验步骤 2.常规日志 | ||
| 9 | + //LogType string `json:"logType"` | ||
| 10 | + // 源数据ID | ||
| 11 | + SourceId int `json:"sourceId"` | ||
| 12 | + // 对象名称 数据表名 / 文件名 | ||
| 13 | + ObjectName string `json:"objectName"` | ||
| 14 | + // 对象类型 1.主表 2.分表 3.副表 4.源文件 5.校验文件 | ||
| 15 | + ObjectType string `json:"objectType"` | ||
| 16 | + // 操作类型 1.主表生成 2.主表拆分 3.数据导入 4.分表生成 5.表复制 6.编辑记录 7.文件上传 8.文件校验 | ||
| 17 | + OperationType string `json:"operationType"` | ||
| 18 | + // 日志内容 | ||
| 19 | + Content string `json:"content"` | ||
| 20 | + // 操作人名称 | ||
| 21 | + OperatorName string `json:"operatorName"` | ||
| 22 | + // 创建时间 | ||
| 23 | + CreatedAt string `json:"createdAt"` | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (d *LogDto) Load(m *domain.Log) { | ||
| 27 | + d.LogId = m.LogId | ||
| 28 | + d.SourceId = m.SourceId | ||
| 29 | + d.ObjectName = m.ObjectName | ||
| 30 | + d.ObjectType = m.ObjectType | ||
| 31 | + d.OperationType = m.OperationType | ||
| 32 | + d.Content = m.Content | ||
| 33 | + d.OperatorName = m.OperatorName | ||
| 34 | + d.CreatedAt = m.CreatedAt.Local().Format("2006-01-02 15:04:05") | ||
| 35 | +} |
| 1 | +package dto | ||
| 2 | + | ||
| 3 | +import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
| 4 | + | ||
| 5 | +type VerifiedStepLogDto struct { | ||
| 6 | + // 日志ID | ||
| 7 | + LogId int `json:"logId"` | ||
| 8 | + // 日志类型 1.校验步骤 2.常规日志 | ||
| 9 | + //LogType string `json:"logType"` | ||
| 10 | + // 源数据ID | ||
| 11 | + //SourceId int `json:"sourceId"` | ||
| 12 | + // 对象名称 数据表名 / 文件名 | ||
| 13 | + //ObjectName string `json:"objectName"` | ||
| 14 | + // 对象类型 1.主表 2.分表 3.副表 4.源文件 5.校验文件 | ||
| 15 | + //ObjectType string `json:"objectType"` | ||
| 16 | + // 操作类型 1.主表生成 2.主表拆分 3.数据导入 4.分表生成 5.表复制 6.编辑记录 7.文件上传 8.文件校验 | ||
| 17 | + //OperationType string `json:"operationType"` | ||
| 18 | + // 日志内容 | ||
| 19 | + Content string `json:"content"` | ||
| 20 | + // 操作人名称 | ||
| 21 | + //OperatorName string `json:"operatorName"` | ||
| 22 | + // 创建时间 | ||
| 23 | + CreatedAt string `json:"createdAt"` | ||
| 24 | + // 错误级别 | ||
| 25 | + Level string `json:"level"` | ||
| 26 | + // 错误信息 | ||
| 27 | + Error string `json:"error"` | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (d *VerifiedStepLogDto) Load(m *domain.Log) { | ||
| 31 | + d.LogId = m.LogId | ||
| 32 | + //d.SourceId = m.SourceId | ||
| 33 | + //d.ObjectName = m.ObjectName | ||
| 34 | + //d.ObjectType = m.ObjectType | ||
| 35 | + //d.OperationType = m.OperationType | ||
| 36 | + d.Content = m.Content | ||
| 37 | + //d.OperatorName = m.OperatorName | ||
| 38 | + d.CreatedAt = m.CreatedAt.Local().Format("2006-01-02 15:04:05") | ||
| 39 | + d.Level = m.Entry.Level | ||
| 40 | + d.Error = m.Entry.Error | ||
| 41 | + if len(d.Level) == 0 { | ||
| 42 | + d.Level = domain.LevelInfo.ToString() | ||
| 43 | + } | ||
| 44 | +} |
pkg/application/log/query/get_log.go
0 → 100644
| 1 | +package query | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type GetLogQuery struct { | ||
| 12 | + // 日志ID | ||
| 13 | + LogId int `cname:"日志ID" json:"logId" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (getLogQuery *GetLogQuery) Valid(validation *validation.Validation) { | ||
| 17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (getLogQuery *GetLogQuery) ValidateQuery() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(getLogQuery) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(getLogQuery).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
pkg/application/log/query/list_log.go
0 → 100644
| 1 | +package query | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type ListLogQuery struct { | ||
| 12 | + // 查询偏离量 | ||
| 13 | + Offset int `cname:"查询偏离量" json:"offset" valid:"Required"` | ||
| 14 | + // 查询限制 | ||
| 15 | + Limit int `cname:"查询限制" json:"limit" valid:"Required"` | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (listLogQuery *ListLogQuery) Valid(validation *validation.Validation) { | ||
| 19 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func (listLogQuery *ListLogQuery) ValidateQuery() error { | ||
| 23 | + valid := validation.Validation{} | ||
| 24 | + b, err := valid.Valid(listLogQuery) | ||
| 25 | + if err != nil { | ||
| 26 | + return err | ||
| 27 | + } | ||
| 28 | + if !b { | ||
| 29 | + elem := reflect.TypeOf(listLogQuery).Elem() | ||
| 30 | + for _, validErr := range valid.Errors { | ||
| 31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 32 | + if isExist { | ||
| 33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 34 | + } else { | ||
| 35 | + return fmt.Errorf(validErr.Message) | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + return nil | ||
| 40 | +} |
-
请 注册 或 登录 后发表评论