提交者
yangfu
feat: interact with byte core
正在显示
53 个修改的文件
包含
1381 行增加
和
316 行删除
@@ -3,9 +3,8 @@ ENV APP_DIR $GOPATH/src/character-library-metadata-bastion | @@ -3,9 +3,8 @@ 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 |
@@ -135,15 +135,15 @@ | @@ -135,15 +135,15 @@ | ||
135 | - [x] 校验步骤日志 /log/verified-step-Log | 135 | - [x] 校验步骤日志 /log/verified-step-Log |
136 | 136 | ||
137 | ## 数据预览 | 137 | ## 数据预览 |
138 | -- [ ] 表数据预览(格式) /table/preview | ||
139 | -- [ ] 表数据自定义查询 /table/preview where conditions 升序、降序 包含、不包含 | ||
140 | -- [ ] 表数据字段可选值搜索 /table/field-optional 文本匹配 | ||
141 | -- [ ] 表数据更新、添加、删除 /table/row-data-mutation | ||
142 | -- [ ] 表数据导出 /table/export-table | 138 | +- [x] 表数据预览(格式) /table/preview |
139 | +- [x] 表数据自定义查询 /table/preview where conditions 升序、降序 包含、不包含 | ||
140 | +- [x] 表数据字段可选值搜索 /table/field-optional 文本匹配 | ||
141 | +- [x] 表数据更新、添加、删除 /table/row-data-mutation | ||
142 | +- [x] 表数据导出 /table/export-table | ||
143 | 143 | ||
144 | ## 数据验证 | 144 | ## 数据验证 |
145 | 145 | ||
146 | -- [] 文件验证 /data/edit-data-table | 146 | +- [x] 文件验证 /data/edit-data-table |
147 | 147 | ||
148 | ## 底层字库接口 | 148 | ## 底层字库接口 |
149 | 149 | ||
@@ -155,19 +155,19 @@ | @@ -155,19 +155,19 @@ | ||
155 | "params": ["产品名2"] | 155 | "params": ["产品名2"] |
156 | } | 156 | } |
157 | ``` | 157 | ``` |
158 | -- [ ] 数据预览 | ||
159 | -- [ ] 表格编辑 | ||
160 | -- [ ] 保存校验文件 (文件地址) | ||
161 | -- [ ] 生成主表 | ||
162 | -- [ ] 表复制 | ||
163 | -- [ ] 追加数据 | ||
164 | -- [ ] 表删除 (主表、副表、分表) | ||
165 | -- [ ] 表拆分 | ||
166 | -- [ ] 更新表结构(分表) | ||
167 | -- [ ] 编辑、添加、删除表数据(副表) | 158 | +- [ ] 数据预览 1 |
159 | +- [ ] 表格编辑 1 | ||
160 | +- [ ] 保存校验文件 (文件地址) 1 | ||
161 | +- [ ] 生成主表 1 | ||
162 | +- [ ] 表复制 (副表) | ||
163 | +- [ ] 追加数据 (主表、副表) | ||
164 | +- [ ] 表删除 (主表、副表)~~、分表~~ | ||
165 | +- [x] ~~表拆分~~ | ||
166 | +- [x] ~~更新表结构(分表)~~ | ||
167 | +- [ ] 编辑、添加、删除表数据(副表) 1 | ||
168 | - [ ] 取消校验 | 168 | - [ ] 取消校验 |
169 | 169 | ||
170 | ## 定时作业 | 170 | ## 定时作业 |
171 | 171 | ||
172 | -- 隔天清理校验中的文件 | ||
173 | -- 隔天清理public临时文件 | ||
172 | +- [x] 隔天清理校验中的文件 | ||
173 | +- [x] 隔天清理public临时文件 |
@@ -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://192.168.100.34:8303" | ||
108 | + - name: STARROCKS_HOST | ||
109 | + value: "118.178.239.45" | ||
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 |
@@ -5,14 +5,12 @@ go 1.16 | @@ -5,14 +5,12 @@ go 1.16 | ||
5 | require ( | 5 | require ( |
6 | github.com/Shopify/sarama v1.30.0 // indirect | 6 | github.com/Shopify/sarama v1.30.0 // indirect |
7 | github.com/ajg/form v1.5.1 // indirect | 7 | github.com/ajg/form v1.5.1 // indirect |
8 | - github.com/aswjh/excel v0.0.0-20190302031512-353c59e41f09 | ||
9 | github.com/beego/beego/v2 v2.0.1 | 8 | github.com/beego/beego/v2 v2.0.1 |
10 | github.com/bwmarrin/snowflake v0.3.0 | 9 | github.com/bwmarrin/snowflake v0.3.0 |
11 | github.com/extrame/xls v0.0.1 | 10 | github.com/extrame/xls v0.0.1 |
12 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect | 11 | github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect |
13 | github.com/fatih/structs v1.1.0 // indirect | 12 | github.com/fatih/structs v1.1.0 // indirect |
14 | github.com/gavv/httpexpect v2.0.0+incompatible | 13 | github.com/gavv/httpexpect v2.0.0+incompatible |
15 | - github.com/go-ole/go-ole v1.2.4 // indirect | ||
16 | github.com/go-pg/pg/v10 v10.10.6 | 14 | github.com/go-pg/pg/v10 v10.10.6 |
17 | github.com/go-redis/redis v6.15.9+incompatible | 15 | github.com/go-redis/redis v6.15.9+incompatible |
18 | github.com/google/go-cmp v0.5.7 // indirect | 16 | github.com/google/go-cmp v0.5.7 // indirect |
@@ -3,6 +3,7 @@ package main | @@ -3,6 +3,7 @@ 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/pg" | 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg" |
8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" | 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/redis" |
@@ -31,6 +32,9 @@ func main() { | @@ -31,6 +32,9 @@ func main() { | ||
31 | if err := starrocks.Init(); err != nil { | 32 | if err := starrocks.Init(); err != nil { |
32 | log.Logger.Error(err.Error()) | 33 | log.Logger.Error(err.Error()) |
33 | } | 34 | } |
35 | + cron := crontab.NewCrontabService(nil) | ||
36 | + cron.StartCrontabTask() | ||
37 | + defer cron.StopCrontabTask() | ||
34 | 38 | ||
35 | time.Sleep(time.Second) | 39 | time.Sleep(time.Second) |
36 | log.Logger.Info("Service:" + constant.SERVICE_NAME) | 40 | log.Logger.Info("Service:" + constant.SERVICE_NAME) |
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 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
11 | + "io/fs" | ||
12 | + "os" | ||
13 | + "path/filepath" | ||
14 | + "time" | ||
15 | +) | ||
16 | + | ||
17 | +type CrontabService struct { | ||
18 | +} | ||
19 | + | ||
20 | +func NewCrontabService(options map[string]interface{}) *CrontabService { | ||
21 | + newCrontabService := &CrontabService{} | ||
22 | + return newCrontabService | ||
23 | +} | ||
24 | + | ||
25 | +func (crontabService *CrontabService) initTask() { | ||
26 | + autoRemoveExpiredTemporaryFile := task.NewTask("定时清理过期临时文件记录", "0 10 */1 * * *", AutoRemoveExpiredTemporaryFile) | ||
27 | + task.AddTask("autoRemoveExpiredTemporaryFile", autoRemoveExpiredTemporaryFile) | ||
28 | + | ||
29 | + autoRemovePublicDownloadFile := task.NewTask("定时清理缓存文件", "0 20 */1 * * *", AutoRemovePublicDownloadFile) | ||
30 | + task.AddTask("autoRemovePublicDownloadFile", autoRemovePublicDownloadFile) | ||
31 | +} | ||
32 | + | ||
33 | +func (crontabService *CrontabService) StartCrontabTask() { | ||
34 | + crontabService.initTask() | ||
35 | + task.StartTask() | ||
36 | + log.Logger.Info("crontab start!") | ||
37 | +} | ||
38 | + | ||
39 | +func (crontabService *CrontabService) StopCrontabTask() { | ||
40 | + task.StopTask() | ||
41 | + log.Logger.Info("crontab stop!") | ||
42 | +} | ||
43 | + | ||
44 | +func AutoRemoveExpiredTemporaryFile(ctx context.Context) error { | ||
45 | + | ||
46 | + defer func() { | ||
47 | + if r := recover(); r != nil { | ||
48 | + log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时清理过期临时文件记录"}) | ||
49 | + } | ||
50 | + }() | ||
51 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
52 | + if err != nil { | ||
53 | + return err | ||
54 | + } | ||
55 | + if err := transactionContext.StartTransaction(); err != nil { | ||
56 | + return err | ||
57 | + } | ||
58 | + defer func() { | ||
59 | + if err != nil { | ||
60 | + log.Logger.Error("【定时清理过期临时文件记录】 失败:" + err.Error()) | ||
61 | + } | ||
62 | + transactionContext.RollbackTransaction() | ||
63 | + }() | ||
64 | + | ||
65 | + log.Logger.Debug("【定时清理过期临时文件记录】 启动") | ||
66 | + end := xtime.New(time.Now()).BeginningOfDay().Add(-time.Hour * 6) | ||
67 | + begin := end.AddDate(0, 0, -7) | ||
68 | + fileRepository, _, _ := factory.FastPgFile(transactionContext, 0) | ||
69 | + _, files, err := fileRepository.Find(map[string]interface{}{"limit": 100, "fileType": domain.TemporaryFile.ToString(), "updatedAtBegin": begin, "updatedAtEnd": end}) | ||
70 | + if err != nil { | ||
71 | + return err | ||
72 | + } | ||
73 | + deleteFileService, _ := factory.CreateDeleteFileService(transactionContext) | ||
74 | + if err = deleteFileService.DeleteFiles(&domain.Context{ | ||
75 | + OperatorName: "系统", | ||
76 | + }, files...); err != nil { | ||
77 | + return err | ||
78 | + } | ||
79 | + | ||
80 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
81 | + return err | ||
82 | + } | ||
83 | + return nil | ||
84 | +} | ||
85 | + | ||
86 | +func AutoRemovePublicDownloadFile(ctx context.Context) error { | ||
87 | + var err error | ||
88 | + defer func() { | ||
89 | + if r := recover(); r != nil { | ||
90 | + log.Logger.Error(fmt.Sprintf("%v", r), map[string]interface{}{"task": "定时清理缓存文件"}) | ||
91 | + } | ||
92 | + }() | ||
93 | + defer func() { | ||
94 | + if err != nil { | ||
95 | + log.Logger.Error("【定时清理缓存文件】 失败:" + err.Error()) | ||
96 | + } | ||
97 | + }() | ||
98 | + log.Logger.Debug("【定时清理缓存文件】 启动") | ||
99 | + root := "public" | ||
100 | + end := xtime.New(time.Now()).BeginningOfDay().AddDate(0, 0, -1) | ||
101 | + err = filepath.Walk(root, func(path string, info fs.FileInfo, err error) error { | ||
102 | + t := info.ModTime() | ||
103 | + if !info.IsDir() && xtime.Before(t, end) { | ||
104 | + err = os.Remove(path) | ||
105 | + if err != nil { | ||
106 | + return err | ||
107 | + } | ||
108 | + log.Logger.Info(fmt.Sprintf("[%v] 删除文件:%v 大小:%v 路径:%v 文件创建时间:%v", "系统", info.Name(), info.Size(), path, info.ModTime())) | ||
109 | + return nil | ||
110 | + } | ||
111 | + return nil | ||
112 | + }) | ||
113 | + if err != nil { | ||
114 | + return err | ||
115 | + } | ||
116 | + return nil | ||
117 | +} |
@@ -53,6 +53,10 @@ func CreateAppendDataToTableService(transactionContext application.TransactionCo | @@ -53,6 +53,10 @@ func CreateAppendDataToTableService(transactionContext application.TransactionCo | ||
53 | return domainService.NewAppendDataToTableService(transactionContext.(*pg.TransactionContext)) | 53 | return domainService.NewAppendDataToTableService(transactionContext.(*pg.TransactionContext)) |
54 | } | 54 | } |
55 | 55 | ||
56 | +func CreateTableEditDataService(transactionContext application.TransactionContext) (domain.TableEditDataService, error) { | ||
57 | + return domainService.NewTableEditDataService(transactionContext.(*pg.TransactionContext)) | ||
58 | +} | ||
59 | + | ||
56 | // 字库核心 | 60 | // 字库核心 |
57 | func CreateByteCoreService(transactionContext application.TransactionContext) (bytecore.ByteLibService, error) { | 61 | func CreateByteCoreService(transactionContext application.TransactionContext) (bytecore.ByteLibService, error) { |
58 | return domainService.ByteCore, nil | 62 | return domainService.ByteCore, nil |
@@ -10,14 +10,26 @@ import ( | @@ -10,14 +10,26 @@ import ( | ||
10 | ) | 10 | ) |
11 | 11 | ||
12 | type EditDataTableCommand struct { | 12 | type EditDataTableCommand struct { |
13 | - // 文件ID | ||
14 | - FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
15 | - | ||
16 | - Fields []*domain.Field | 13 | + //// 文件ID |
14 | + //FileId int `cname:"文件ID" json:"fileId" valid:"Required"` | ||
15 | + // | ||
16 | + //Fields []*domain.Field | ||
17 | + domain.EditTableRequest | ||
17 | } | 18 | } |
18 | 19 | ||
19 | func (editDataTableCommand *EditDataTableCommand) Valid(validation *validation.Validation) { | 20 | func (editDataTableCommand *EditDataTableCommand) Valid(validation *validation.Validation) { |
20 | - | 21 | + if len(editDataTableCommand.ProcessFields) == 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 | + } | ||
21 | } | 33 | } |
22 | 34 | ||
23 | func (editDataTableCommand *EditDataTableCommand) ValidateCommand() error { | 35 | func (editDataTableCommand *EditDataTableCommand) ValidateCommand() error { |
@@ -11,11 +11,8 @@ import ( | @@ -11,11 +11,8 @@ import ( | ||
11 | 11 | ||
12 | type LoadDataTableCommand struct { | 12 | type LoadDataTableCommand struct { |
13 | // 文件ID | 13 | // 文件ID |
14 | - FileId int `cname:"文件ID" json:"objectId" valid:"Required"` | ||
15 | - // 页号 | ||
16 | - //PageNumber int `cname:"页号" json:"pageNumber"` | ||
17 | - // 页号 | ||
18 | - //PageSize int `cname:"数量" json:"pageSize"` | 14 | + FileId int `cname:"文件ID" json:"objectId" valid:"Required"` |
15 | + Fields []*domain.Field `json:"fields"` | ||
19 | domain.Where | 16 | domain.Where |
20 | } | 17 | } |
21 | 18 |
@@ -24,7 +24,7 @@ func (fileService *FileService) FilePreview(ctx *domain.Context, loadDataTableCo | @@ -24,7 +24,7 @@ func (fileService *FileService) FilePreview(ctx *domain.Context, loadDataTableCo | ||
24 | }() | 24 | }() |
25 | 25 | ||
26 | loadDataTableService, _ := factory.CreateLoadDataTableService(transactionContext) | 26 | loadDataTableService, _ := factory.CreateLoadDataTableService(transactionContext) |
27 | - data, err := loadDataTableService.Preview(ctx, loadDataTableCommand.FileId, loadDataTableCommand.Where) | 27 | + data, err := loadDataTableService.Preview(ctx, loadDataTableCommand.FileId, loadDataTableCommand.Fields, loadDataTableCommand.Where) |
28 | if err != nil { | 28 | if err != nil { |
29 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 29 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
30 | } | 30 | } |
@@ -53,6 +53,11 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable | @@ -53,6 +53,11 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable | ||
53 | transactionContext.RollbackTransaction() | 53 | transactionContext.RollbackTransaction() |
54 | }() | 54 | }() |
55 | 55 | ||
56 | + editDataTableService, _ := factory.CreateEditDataTableService(transactionContext) | ||
57 | + _, err = editDataTableService.Edit(ctx, editDataTableCommand.EditTableRequest) | ||
58 | + if err != nil { | ||
59 | + return nil, factory.FastError(err) | ||
60 | + } | ||
56 | if err := transactionContext.CommitTransaction(); err != nil { | 61 | if err := transactionContext.CommitTransaction(); err != nil { |
57 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 62 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
58 | } | 63 | } |
@@ -12,21 +12,23 @@ type MappingRuleDto struct { | @@ -12,21 +12,23 @@ type MappingRuleDto struct { | ||
12 | // 文件ID | 12 | // 文件ID |
13 | FileId int `json:"fileId"` | 13 | FileId int `json:"fileId"` |
14 | // 主表列 | 14 | // 主表列 |
15 | - MainTableFields []*domain.Field `json:"mainTableFields"` | 15 | + MainTableFields []*domain.Field `json:"mainTableFields,omitempty"` |
16 | // 校验文件列 | 16 | // 校验文件列 |
17 | - VerifiedFileFields []*domain.Field `json:"verifiedFileFields"` | 17 | + VerifiedFileFields []*domain.Field `json:"verifiedFileFields,omitempty"` |
18 | // 校验文件列 | 18 | // 校验文件列 |
19 | - MappingFields []*domain.MappingField `json:"mappingFields"` | 19 | + MappingFields []*domain.MappingField `json:"mappingFields,omitempty"` |
20 | } | 20 | } |
21 | 21 | ||
22 | -func (d *MappingRuleDto) Load(m *domain.MappingRule) { | 22 | +func (d *MappingRuleDto) Load(m *domain.MappingRule, detail bool) { |
23 | d.MappingRuleId = m.MappingRuleId | 23 | d.MappingRuleId = m.MappingRuleId |
24 | d.Name = m.Name | 24 | d.Name = m.Name |
25 | d.TableId = m.TableId | 25 | d.TableId = m.TableId |
26 | d.FileId = m.FileId | 26 | d.FileId = m.FileId |
27 | - d.MainTableFields = m.MainTableFields | ||
28 | - d.VerifiedFileFields = m.VerifiedFileFields | ||
29 | - d.MappingFields = m.MappingFields | 27 | + if detail { |
28 | + d.MainTableFields = m.MainTableFields | ||
29 | + d.VerifiedFileFields = m.VerifiedFileFields | ||
30 | + d.MappingFields = m.MappingFields | ||
31 | + } | ||
30 | } | 32 | } |
31 | 33 | ||
32 | func (d *MappingRuleDto) LoadFromTableAndFile(m *domain.Table, f *domain.File, fm *domain.Table) { | 34 | func (d *MappingRuleDto) LoadFromTableAndFile(m *domain.Table, f *domain.File, fm *domain.Table) { |
@@ -14,7 +14,7 @@ type GetMappingRuleQuery struct { | @@ -14,7 +14,7 @@ type GetMappingRuleQuery struct { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | func (getMappingRuleQuery *GetMappingRuleQuery) Valid(validation *validation.Validation) { | 16 | func (getMappingRuleQuery *GetMappingRuleQuery) Valid(validation *validation.Validation) { |
17 | - validation.SetError("CustomValid", "未实现的自定义认证") | 17 | + //validation.SetError("CustomValid", "未实现的自定义认证") |
18 | } | 18 | } |
19 | 19 | ||
20 | func (getMappingRuleQuery *GetMappingRuleQuery) ValidateQuery() error { | 20 | func (getMappingRuleQuery *GetMappingRuleQuery) ValidateQuery() error { |
@@ -62,6 +62,12 @@ func (mappingRuleService *MappingRuleService) CreateMappingRule(ctx *domain.Cont | @@ -62,6 +62,12 @@ func (mappingRuleService *MappingRuleService) CreateMappingRule(ctx *domain.Cont | ||
62 | UpdatedAt: time.Now(), | 62 | UpdatedAt: time.Now(), |
63 | Context: ctx, | 63 | Context: ctx, |
64 | } | 64 | } |
65 | + | ||
66 | + // 使用默认匹配 | ||
67 | + if len(cmd.MappingFields) == 0 { | ||
68 | + newMappingRule.MappingFields = domain.NewMappingFields(mainTable.Fields(false), fileTable.Fields(false)) | ||
69 | + } | ||
70 | + | ||
65 | if newMappingRule, err = mappingRuleRepository.Save(newMappingRule); err != nil { | 71 | if newMappingRule, err = mappingRuleRepository.Save(newMappingRule); err != nil { |
66 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 72 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
67 | } | 73 | } |
@@ -69,7 +75,10 @@ func (mappingRuleService *MappingRuleService) CreateMappingRule(ctx *domain.Cont | @@ -69,7 +75,10 @@ func (mappingRuleService *MappingRuleService) CreateMappingRule(ctx *domain.Cont | ||
69 | if err := transactionContext.CommitTransaction(); err != nil { | 75 | if err := transactionContext.CommitTransaction(); err != nil { |
70 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 76 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
71 | } | 77 | } |
72 | - return struct{}{}, nil | 78 | + |
79 | + result := &dto.MappingRuleDto{} | ||
80 | + result.Load(newMappingRule, true) | ||
81 | + return result, nil | ||
73 | } | 82 | } |
74 | 83 | ||
75 | // 返回匹配规则服务 | 84 | // 返回匹配规则服务 |
@@ -91,11 +100,13 @@ func (mappingRuleService *MappingRuleService) GetMappingRule(getMappingRuleQuery | @@ -91,11 +100,13 @@ func (mappingRuleService *MappingRuleService) GetMappingRule(getMappingRuleQuery | ||
91 | if err != nil { | 100 | if err != nil { |
92 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 101 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
93 | } | 102 | } |
103 | + result := &dto.MappingRuleDto{} | ||
104 | + result.Load(mappingRule, true) | ||
94 | 105 | ||
95 | if err := transactionContext.CommitTransaction(); err != nil { | 106 | if err := transactionContext.CommitTransaction(); err != nil { |
96 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 107 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
97 | } | 108 | } |
98 | - return mappingRule, nil | 109 | + return result, nil |
99 | } | 110 | } |
100 | 111 | ||
101 | // 返回匹配规则服务列表 | 112 | // 返回匹配规则服务列表 |
@@ -235,7 +246,7 @@ func (mappingRuleService *MappingRuleService) Search(searchCommand *command.Sear | @@ -235,7 +246,7 @@ func (mappingRuleService *MappingRuleService) Search(searchCommand *command.Sear | ||
235 | var result = make([]*dto.MappingRuleDto, 0) | 246 | var result = make([]*dto.MappingRuleDto, 0) |
236 | for _, r := range rules { | 247 | for _, r := range rules { |
237 | var item = &dto.MappingRuleDto{} | 248 | var item = &dto.MappingRuleDto{} |
238 | - item.Load(r) | 249 | + item.Load(r, false) |
239 | result = append(result, item) | 250 | result = append(result, item) |
240 | } | 251 | } |
241 | 252 |
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 RowEditCommand struct { | ||
13 | + // 表Id | ||
14 | + TableId int `cname:"表Id" json:"tableId" valid:"Required"` | ||
15 | + // 数据列 | ||
16 | + UpdateList []*domain.FieldValues `json:"updateList"` | ||
17 | + RemoveList []*domain.FieldValues `json:"removeList"` | ||
18 | + AddList []*domain.FieldValues `json:"addList"` | ||
19 | + Where domain.Where `json:"where"` | ||
20 | +} | ||
21 | + | ||
22 | +func (cmd *RowEditCommand) Valid(validation *validation.Validation) { | ||
23 | + | ||
24 | +} | ||
25 | + | ||
26 | +func (cmd *RowEditCommand) ValidateCommand() error { | ||
27 | + valid := validation.Validation{} | ||
28 | + b, err := valid.Valid(cmd) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if !b { | ||
33 | + elem := reflect.TypeOf(cmd).Elem() | ||
34 | + for _, validErr := range valid.Errors { | ||
35 | + field, isExist := elem.FieldByName(validErr.Field) | ||
36 | + if isExist { | ||
37 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
38 | + } else { | ||
39 | + return fmt.Errorf(validErr.Message) | ||
40 | + } | ||
41 | + } | ||
42 | + } | ||
43 | + return nil | ||
44 | +} |
@@ -31,4 +31,7 @@ func (d *TableDetailDto) Load(m *domain.Table, mainTable *domain.Table) { | @@ -31,4 +31,7 @@ func (d *TableDetailDto) Load(m *domain.Table, mainTable *domain.Table) { | ||
31 | } | 31 | } |
32 | d.Fields = m.Fields(false) | 32 | d.Fields = m.Fields(false) |
33 | d.ManualFields = m.ManualFields | 33 | d.ManualFields = m.ManualFields |
34 | + if len(d.ManualFields) == 0 { | ||
35 | + d.ManualFields = make([]*domain.Field, 0) | ||
36 | + } | ||
34 | } | 37 | } |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
8 | +) | ||
9 | + | ||
10 | +func (tableService *TableService) RowEdit(ctx *domain.Context, cmd *command.RowEditCommand) (interface{}, error) { | ||
11 | + if err := cmd.ValidateCommand(); err != nil { | ||
12 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
13 | + } | ||
14 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
15 | + if err != nil { | ||
16 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
17 | + } | ||
18 | + if err := transactionContext.StartTransaction(); err != nil { | ||
19 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
20 | + } | ||
21 | + defer func() { | ||
22 | + transactionContext.RollbackTransaction() | ||
23 | + }() | ||
24 | + | ||
25 | + editDataService, _ := factory.CreateTableEditDataService(transactionContext) | ||
26 | + _, err = editDataService.RowEdit(ctx, domain.EditDataRequest{ | ||
27 | + TableId: cmd.TableId, | ||
28 | + Where: cmd.Where, | ||
29 | + UpdateList: cmd.UpdateList, | ||
30 | + AddList: cmd.AddList, | ||
31 | + RemoveList: cmd.RemoveList, | ||
32 | + }) | ||
33 | + if err != nil { | ||
34 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
35 | + } | ||
36 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
37 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
38 | + } | ||
39 | + return struct{}{}, nil | ||
40 | +} |
@@ -17,25 +17,25 @@ type TableService struct { | @@ -17,25 +17,25 @@ type TableService struct { | ||
17 | } | 17 | } |
18 | 18 | ||
19 | // 批量编辑分表 | 19 | // 批量编辑分表 |
20 | -func (tableService *TableService) BatchEditSubTable(batchEditSubTableCommand *command.BatchEditSubTableCommand) (interface{}, error) { | ||
21 | - if err := batchEditSubTableCommand.ValidateCommand(); err != nil { | ||
22 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
23 | - } | ||
24 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
25 | - if err != nil { | ||
26 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
27 | - } | ||
28 | - if err := transactionContext.StartTransaction(); err != nil { | ||
29 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
30 | - } | ||
31 | - defer func() { | ||
32 | - transactionContext.RollbackTransaction() | ||
33 | - }() | ||
34 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
35 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
36 | - } | ||
37 | - return nil, nil | ||
38 | -} | 20 | +//func (tableService *TableService) BatchEditSubTable(batchEditSubTableCommand *command.BatchEditSubTableCommand) (interface{}, error) { |
21 | +// if err := batchEditSubTableCommand.ValidateCommand(); err != nil { | ||
22 | +// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
23 | +// } | ||
24 | +// transactionContext, err := factory.CreateTransactionContext(nil) | ||
25 | +// if err != nil { | ||
26 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
27 | +// } | ||
28 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
29 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
30 | +// } | ||
31 | +// defer func() { | ||
32 | +// transactionContext.RollbackTransaction() | ||
33 | +// }() | ||
34 | +// if err := transactionContext.CommitTransaction(); err != nil { | ||
35 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
36 | +// } | ||
37 | +// return nil, nil | ||
38 | +//} | ||
39 | 39 | ||
40 | // 表复制 | 40 | // 表复制 |
41 | func (tableService *TableService) CopyDataTable(ctx *domain.Context, cmd *command.CopyDataTableCommand) (interface{}, error) { | 41 | func (tableService *TableService) CopyDataTable(ctx *domain.Context, cmd *command.CopyDataTableCommand) (interface{}, error) { |
@@ -132,6 +132,36 @@ func (tableService *TableService) GetTable(getTableQuery *query.GetTableQuery) ( | @@ -132,6 +132,36 @@ func (tableService *TableService) GetTable(getTableQuery *query.GetTableQuery) ( | ||
132 | return tableDetailDto, nil | 132 | return tableDetailDto, nil |
133 | } | 133 | } |
134 | 134 | ||
135 | +// 返回表服务 | ||
136 | +func (tableService *TableService) PrepareSubTable(getTableQuery *query.GetTableQuery) (interface{}, error) { | ||
137 | + if err := getTableQuery.ValidateQuery(); err != nil { | ||
138 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
139 | + } | ||
140 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
141 | + if err != nil { | ||
142 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
143 | + } | ||
144 | + if err := transactionContext.StartTransaction(); err != nil { | ||
145 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
146 | + } | ||
147 | + defer func() { | ||
148 | + transactionContext.RollbackTransaction() | ||
149 | + }() | ||
150 | + _, table, err := factory.FastPgTable(transactionContext, getTableQuery.TableId) | ||
151 | + if err != nil { | ||
152 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
153 | + } | ||
154 | + tableDetailDto := dto.TableDetailDto{} | ||
155 | + tableDetailDto.Load(table, table) | ||
156 | + tableDetailDto.TableType = domain.SubTable.ToString() | ||
157 | + tableDetailDto.TableId = 0 | ||
158 | + tableDetailDto.ParentId = table.TableId | ||
159 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
160 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
161 | + } | ||
162 | + return tableDetailDto, nil | ||
163 | +} | ||
164 | + | ||
135 | // 返回表服务列表 | 165 | // 返回表服务列表 |
136 | func (tableService *TableService) ListTable(listTableQuery *query.ListTableQuery) (interface{}, error) { | 166 | func (tableService *TableService) ListTable(listTableQuery *query.ListTableQuery) (interface{}, error) { |
137 | if err := listTableQuery.ValidateQuery(); err != nil { | 167 | if err := listTableQuery.ValidateQuery(); err != nil { |
@@ -233,25 +263,25 @@ func (tableService *TableService) Search(searchQuery *query.SearchTableQuery) (i | @@ -233,25 +263,25 @@ func (tableService *TableService) Search(searchQuery *query.SearchTableQuery) (i | ||
233 | } | 263 | } |
234 | 264 | ||
235 | // 表拆分 | 265 | // 表拆分 |
236 | -func (tableService *TableService) SplitDataTable(splitDataTableCommand *command.SplitDataTableCommand) (interface{}, error) { | ||
237 | - if err := splitDataTableCommand.ValidateCommand(); err != nil { | ||
238 | - return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
239 | - } | ||
240 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
241 | - if err != nil { | ||
242 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
243 | - } | ||
244 | - if err := transactionContext.StartTransaction(); err != nil { | ||
245 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
246 | - } | ||
247 | - defer func() { | ||
248 | - transactionContext.RollbackTransaction() | ||
249 | - }() | ||
250 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
251 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
252 | - } | ||
253 | - return nil, nil | ||
254 | -} | 266 | +//func (tableService *TableService) SplitDataTable(splitDataTableCommand *command.SplitDataTableCommand) (interface{}, error) { |
267 | +// if err := splitDataTableCommand.ValidateCommand(); err != nil { | ||
268 | +// return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
269 | +// } | ||
270 | +// transactionContext, err := factory.CreateTransactionContext(nil) | ||
271 | +// if err != nil { | ||
272 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
273 | +// } | ||
274 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
275 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
276 | +// } | ||
277 | +// defer func() { | ||
278 | +// transactionContext.RollbackTransaction() | ||
279 | +// }() | ||
280 | +// if err := transactionContext.CommitTransaction(); err != nil { | ||
281 | +// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
282 | +// } | ||
283 | +// return nil, nil | ||
284 | +//} | ||
255 | 285 | ||
256 | // 更新表服务 | 286 | // 更新表服务 |
257 | func (tableService *TableService) UpdateTable(updateTableCommand *command.UpdateTableCommand) (interface{}, error) { | 287 | func (tableService *TableService) UpdateTable(updateTableCommand *command.UpdateTableCommand) (interface{}, error) { |
@@ -339,13 +369,16 @@ func (tableService *TableService) AddTableStruct(ctx *domain.Context, cmd *comma | @@ -339,13 +369,16 @@ func (tableService *TableService) AddTableStruct(ctx *domain.Context, cmd *comma | ||
339 | }() | 369 | }() |
340 | 370 | ||
341 | AddTableStructService, _ := factory.CreateAddTableStructService(transactionContext) | 371 | AddTableStructService, _ := factory.CreateAddTableStructService(transactionContext) |
342 | - if _, err := AddTableStructService.AddTableStruct(ctx, cmd.TableId, cmd.Fields, cmd.Name); err != nil { | 372 | + table, err := AddTableStructService.AddTableStruct(ctx, cmd.TableId, cmd.Fields, cmd.Name) |
373 | + if err != nil { | ||
343 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 374 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
344 | } | 375 | } |
345 | if err := transactionContext.CommitTransaction(); err != nil { | 376 | if err := transactionContext.CommitTransaction(); err != nil { |
346 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 377 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
347 | } | 378 | } |
348 | - return struct{}{}, nil | 379 | + tableDetailDto := dto.TableDetailDto{} |
380 | + tableDetailDto.Load(table, nil) | ||
381 | + return tableDetailDto, nil | ||
349 | } | 382 | } |
350 | 383 | ||
351 | func NewTableService(options map[string]interface{}) *TableService { | 384 | func NewTableService(options map[string]interface{}) *TableService { |
@@ -18,14 +18,11 @@ var PPROF_ON = true | @@ -18,14 +18,11 @@ var PPROF_ON = true | ||
18 | //天联共创用户模块 | 18 | //天联共创用户模块 |
19 | var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com" | 19 | var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creation-user-dev.fjmaimaimai.com" |
20 | 20 | ||
21 | -//天联共创业务模块 | ||
22 | -//var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com" | ||
23 | - | ||
24 | var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" | 21 | var MMM_BYTE_BANK_HOST = "http://220.250.41.79:8301" |
25 | 22 | ||
26 | var METADATA_BASTION_HOST = "http://127.0.0.1:8080" | 23 | var METADATA_BASTION_HOST = "http://127.0.0.1:8080" |
27 | 24 | ||
28 | -var BYTE_CORE_HOST = "http://127.0.0.1:8080" | 25 | +var BYTE_CORE_HOST = "http://192.168.100.34:8303" |
29 | 26 | ||
30 | //var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} | 27 | //var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} |
31 | 28 | ||
@@ -41,7 +38,6 @@ func init() { | @@ -41,7 +38,6 @@ func init() { | ||
41 | LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL) | 38 | LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL) |
42 | //ALLIED_CREATION_BASIC_HOST = Configurator.DefaultString("ALLIED_CREATION_BASIC_HOST", ALLIED_CREATION_BASIC_HOST) | 39 | //ALLIED_CREATION_BASIC_HOST = Configurator.DefaultString("ALLIED_CREATION_BASIC_HOST", ALLIED_CREATION_BASIC_HOST) |
43 | ALLIED_CREATION_USER_HOST = Configurator.DefaultString("ALLIED_CREATION_USER_HOST", ALLIED_CREATION_USER_HOST) | 40 | ALLIED_CREATION_USER_HOST = Configurator.DefaultString("ALLIED_CREATION_USER_HOST", ALLIED_CREATION_USER_HOST) |
44 | - //ALLIED_CREATION_COOPERATION_HOST = Configurator.DefaultString("ALLIED_CREATION_COOPERATION_HOST", ALLIED_CREATION_COOPERATION_HOST) | ||
45 | MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) | 41 | MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) |
46 | BYTE_CORE_HOST = Configurator.DefaultString("BYTE_CORE_HOST", BYTE_CORE_HOST) | 42 | BYTE_CORE_HOST = Configurator.DefaultString("BYTE_CORE_HOST", BYTE_CORE_HOST) |
47 | SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV) | 43 | SERVICE_ENV = Configurator.DefaultString("SERVICE_ENV", SERVICE_ENV) |
@@ -6,7 +6,7 @@ type ByteLibService interface { | @@ -6,7 +6,7 @@ type ByteLibService interface { | ||
6 | LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error) | 6 | LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error) |
7 | EditTable(param ReqEditDataTable) (*DataEditDataTable, error) | 7 | EditTable(param ReqEditDataTable) (*DataEditDataTable, error) |
8 | SaveTable(param ReqSaveTable) (*DataSaveTable, error) | 8 | SaveTable(param ReqSaveTable) (*DataSaveTable, error) |
9 | - GenerateTable(param ReqGenerateTable) (*DataGenerateTable, error) | 9 | + GenerateTable(ctx *domain.Context, param ReqGenerateTable) (*DataGenerateTable, error) |
10 | CopyTable(param ReqCopyTable) (*DataCopyTable, error) | 10 | CopyTable(param ReqCopyTable) (*DataCopyTable, error) |
11 | AppendData(param ReqAppendData) (*DataAppendData, error) | 11 | AppendData(param ReqAppendData) (*DataAppendData, error) |
12 | DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error) | 12 | DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error) |
@@ -16,11 +16,19 @@ type ByteLibService interface { | @@ -16,11 +16,19 @@ type ByteLibService interface { | ||
16 | 16 | ||
17 | type ( | 17 | type ( |
18 | ReqLoadDataTable struct { | 18 | ReqLoadDataTable struct { |
19 | - FileId int | ||
20 | - FileName string | ||
21 | - Url string | ||
22 | - Ext string | 19 | + FileId int `json:"file_id"` |
20 | + FileName string `json:"file_name"` | ||
21 | + Url string `json:"url"` | ||
22 | + Ext string `json:"ext"` | ||
23 | domain.Where | 23 | domain.Where |
24 | + OriginalTableId string `json:"originalTableId"` | ||
25 | + IsFromOriginalTable bool `json:"isFromOriginalTable"` | ||
26 | + TableFileUrl string `json:"tableFileUrl"` | ||
27 | + ColumnSchemas []ColumnSchema `json:"columnSchemas"` | ||
28 | + //PageNumber int `json:"pageNumber"` | ||
29 | + //PageSize int `json:"pageSize"` | ||
30 | + QueryParameters map[string]interface{} `json:"queryParameters"` | ||
31 | + SortParameters map[string]interface{} `json:"sortParameters"` | ||
24 | } | 32 | } |
25 | 33 | ||
26 | DataLoadDataTable struct { | 34 | DataLoadDataTable struct { |
@@ -79,13 +87,13 @@ func (table DataLoadDataTable) Filter(where domain.Where) *DataLoadDataTable { | @@ -79,13 +87,13 @@ func (table DataLoadDataTable) Filter(where domain.Where) *DataLoadDataTable { | ||
79 | 87 | ||
80 | type ( | 88 | type ( |
81 | ReqEditDataTable struct { | 89 | ReqEditDataTable struct { |
82 | - FileId int | ||
83 | - FileName string | ||
84 | - Url string | ||
85 | - Ext string | ||
86 | - Fields []*Field | ||
87 | - Action string | ||
88 | - Params []interface{} | 90 | + FileId int `json:"fileId"` |
91 | + PageNumber int `json:"pageNumber"` | ||
92 | + PageSize int `json:"pageSize"` | ||
93 | + Fields []*Field `json:"fields"` | ||
94 | + ProcessFields []*Field `json:"processFields"` | ||
95 | + Action string `json:"action"` | ||
96 | + Params map[string]interface{} `json:"params"` | ||
89 | } | 97 | } |
90 | 98 | ||
91 | DataEditDataTable struct { | 99 | DataEditDataTable struct { |
@@ -95,6 +103,7 @@ type ( | @@ -95,6 +103,7 @@ type ( | ||
95 | 103 | ||
96 | type ( | 104 | type ( |
97 | ReqSaveTable struct { | 105 | ReqSaveTable struct { |
106 | + FileId int | ||
98 | } | 107 | } |
99 | 108 | ||
100 | DataSaveTable struct { | 109 | DataSaveTable struct { |
@@ -104,9 +113,13 @@ type ( | @@ -104,9 +113,13 @@ type ( | ||
104 | 113 | ||
105 | type ( | 114 | type ( |
106 | ReqGenerateTable struct { | 115 | ReqGenerateTable struct { |
116 | + FileId int | ||
117 | + FileUrl string | ||
118 | + Table *domain.Table | ||
107 | } | 119 | } |
108 | 120 | ||
109 | DataGenerateTable struct { | 121 | DataGenerateTable struct { |
122 | + TableName string | ||
110 | } | 123 | } |
111 | ) | 124 | ) |
112 | 125 | ||
@@ -149,3 +162,20 @@ type ( | @@ -149,3 +162,20 @@ type ( | ||
149 | DataEditTableData struct { | 162 | DataEditTableData struct { |
150 | } | 163 | } |
151 | ) | 164 | ) |
165 | + | ||
166 | +type ColumnSchema struct { | ||
167 | + ColumnName string `json:"columnName"` | ||
168 | + ColumnType string `json:"columnType"` | ||
169 | +} | ||
170 | + | ||
171 | +func ToFields(fields []*domain.Field) []*Field { | ||
172 | + result := make([]*Field, 0) | ||
173 | + for _, f := range fields { | ||
174 | + result = append(result, &Field{ | ||
175 | + Index: f.Index, | ||
176 | + Name: f.Name, | ||
177 | + Type: f.SQLType, | ||
178 | + }) | ||
179 | + } | ||
180 | + return result | ||
181 | +} |
@@ -12,6 +12,13 @@ type Where struct { | @@ -12,6 +12,13 @@ type Where struct { | ||
12 | Conditions []Condition `json:"conditions"` | 12 | Conditions []Condition `json:"conditions"` |
13 | } | 13 | } |
14 | 14 | ||
15 | +func (w Where) Offset() int { | ||
16 | + if w.PageNumber == 0 && w.PageSize == 0 { | ||
17 | + return 0 | ||
18 | + } | ||
19 | + return (w.PageNumber - 1) * w.PageSize | ||
20 | +} | ||
21 | + | ||
15 | type Condition struct { | 22 | type Condition struct { |
16 | Field *Field `json:"field"` | 23 | Field *Field `json:"field"` |
17 | Like string `json:"like"` | 24 | Like string `json:"like"` |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | type FileTableService interface { | 3 | type FileTableService interface { |
4 | - Preview(ctx *Context, fileId int, where Where) (interface{}, error) | 4 | + Preview(ctx *Context, fileId int, fields []*Field, where Where) (interface{}, error) |
5 | Edit() | 5 | Edit() |
6 | Flush(ctx *Context, fileId int, table *Table) (interface{}, error) | 6 | Flush(ctx *Context, fileId int, table *Table) (interface{}, error) |
7 | DeleteFiles(ctx *Context, files ...*File) error | 7 | DeleteFiles(ctx *Context, files ...*File) error |
@@ -18,11 +18,13 @@ type TableService interface { | @@ -18,11 +18,13 @@ type TableService interface { | ||
18 | } | 18 | } |
19 | 19 | ||
20 | type PreviewDataTableService interface { | 20 | type PreviewDataTableService interface { |
21 | - Preview(ctx *Context, fileId int, where Where) (interface{}, error) | 21 | + Preview(ctx *Context, fileId int, fields []*Field, where Where) (interface{}, error) |
22 | GetFileId() int | 22 | GetFileId() int |
23 | } | 23 | } |
24 | 24 | ||
25 | -type EditDataTableService interface{} | 25 | +type EditDataTableService interface { |
26 | + Edit(ctx *Context, param EditTableRequest) (interface{}, error) | ||
27 | +} | ||
26 | 28 | ||
27 | type FlushDataTableService interface { | 29 | type FlushDataTableService interface { |
28 | Flush(ctx *Context, fileId int, table *Table) (interface{}, error) | 30 | Flush(ctx *Context, fileId int, table *Table) (interface{}, error) |
@@ -56,5 +58,25 @@ type UpdateTableStructService interface { | @@ -56,5 +58,25 @@ type UpdateTableStructService interface { | ||
56 | } | 58 | } |
57 | 59 | ||
58 | type AddTableStructService interface { | 60 | type AddTableStructService interface { |
59 | - AddTableStruct(ctx *Context, parentTableId int, fields []*Field, name string) (interface{}, error) | 61 | + AddTableStruct(ctx *Context, parentTableId int, fields []*Field, name string) (*Table, error) |
62 | +} | ||
63 | + | ||
64 | +type EditTableRequest struct { | ||
65 | + FileId int `json:"objectId"` | ||
66 | + Fields []*Field `json:"fields"` | ||
67 | + ProcessFields []*Field `json:"processFields"` | ||
68 | + Where Where `json:"where"` | ||
69 | + Action string `json:"action"` | ||
70 | + Params map[string]interface{} `json:"params"` | ||
71 | +} | ||
72 | + | ||
73 | +type TableEditDataService interface { | ||
74 | + RowEdit(ctx *Context, request EditDataRequest) (interface{}, error) | ||
75 | +} | ||
76 | +type EditDataRequest struct { | ||
77 | + TableId int `json:"tableId"` | ||
78 | + UpdateList []*FieldValues `json:"updateList"` | ||
79 | + RemoveList []*FieldValues `json:"removeList"` | ||
80 | + AddList []*FieldValues `json:"addList"` | ||
81 | + Where Where `json:"where"` | ||
60 | } | 82 | } |
@@ -19,6 +19,8 @@ var ( | @@ -19,6 +19,8 @@ var ( | ||
19 | DeleteTable OperationType = "DeleteTable" // 表删除 | 19 | DeleteTable OperationType = "DeleteTable" // 表删除 |
20 | FileUpload OperationType = "FileUpload" // 文件上传 | 20 | FileUpload OperationType = "FileUpload" // 文件上传 |
21 | FileVerify OperationType = "FileVerify" // 文件校验 | 21 | FileVerify OperationType = "FileVerify" // 文件校验 |
22 | + | ||
23 | + ExcelTableEdit OperationType = "ExcelTableEdit" // 文档表格编辑 | ||
22 | ) | 24 | ) |
23 | 25 | ||
24 | var OperationTypeMap = map[string]string{ | 26 | var OperationTypeMap = map[string]string{ |
@@ -31,6 +33,7 @@ var OperationTypeMap = map[string]string{ | @@ -31,6 +33,7 @@ var OperationTypeMap = map[string]string{ | ||
31 | DeleteTable.ToString(): "表删除", | 33 | DeleteTable.ToString(): "表删除", |
32 | FileUpload.ToString(): "文件上传", | 34 | FileUpload.ToString(): "文件上传", |
33 | FileVerify.ToString(): "文件校验", | 35 | FileVerify.ToString(): "文件校验", |
36 | + ExcelTableEdit.ToString(): "文档表格编辑", | ||
34 | } | 37 | } |
35 | 38 | ||
36 | var ( | 39 | var ( |
@@ -72,11 +75,11 @@ var ( | @@ -72,11 +75,11 @@ var ( | ||
72 | ) | 75 | ) |
73 | 76 | ||
74 | var ( | 77 | var ( |
75 | - String SQLType = "string" | ||
76 | - Int SQLType = "int" | ||
77 | - Float SQLType = "float" | ||
78 | - Date SQLType = "date" | ||
79 | - Datetime SQLType = "datetime" | 78 | + String SQLType = "STRING" |
79 | + Int SQLType = "INT" | ||
80 | + Float SQLType = "FLOAT" | ||
81 | + Date SQLType = "DATE" | ||
82 | + Datetime SQLType = "DATETIME" | ||
80 | ) | 83 | ) |
81 | 84 | ||
82 | var SQLTypeMap = map[string]string{ | 85 | var SQLTypeMap = map[string]string{ |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | -import "fmt" | 3 | +import ( |
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/utils/xtime" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils" | ||
7 | + "strings" | ||
8 | +) | ||
4 | 9 | ||
5 | // Field 字段 | 10 | // Field 字段 |
6 | type Field struct { | 11 | type Field struct { |
@@ -21,7 +26,7 @@ type Field struct { | @@ -21,7 +26,7 @@ type Field struct { | ||
21 | } | 26 | } |
22 | 27 | ||
23 | func (f *Field) Valid() error { | 28 | func (f *Field) Valid() error { |
24 | - if _, ok := SQLTypeMap[f.SQLType]; !ok { | 29 | + if _, ok := SQLTypeMap[strings.ToUpper(f.SQLType)]; !ok { |
25 | return fmt.Errorf("unknown sql type:%v", f.SQLType) | 30 | return fmt.Errorf("unknown sql type:%v", f.SQLType) |
26 | } | 31 | } |
27 | if f.Index == 0 && f.Flag == ManualField { | 32 | if f.Index == 0 && f.Flag == ManualField { |
@@ -97,3 +102,66 @@ func FieldsChange(oldFields []*Field, newFields []*Field) (reserve []*Field, del | @@ -97,3 +102,66 @@ func FieldsChange(oldFields []*Field, newFields []*Field) (reserve []*Field, del | ||
97 | } | 102 | } |
98 | return | 103 | return |
99 | } | 104 | } |
105 | + | ||
106 | +type FieldValues struct { | ||
107 | + Number int `json:"number"` | ||
108 | + FieldValues []*FieldValue `json:"fieldValues"` | ||
109 | +} | ||
110 | + | ||
111 | +func (f *FieldValues) Valid() error { | ||
112 | + for _, item := range f.FieldValues { | ||
113 | + if err := item.Valid(); err != nil { | ||
114 | + return err | ||
115 | + } | ||
116 | + } | ||
117 | + return nil | ||
118 | +} | ||
119 | + | ||
120 | +type FieldValue struct { | ||
121 | + *Field | ||
122 | + // 字段值(当前) | ||
123 | + Value string `json:"value,omitempty"` | ||
124 | + // 字段值(旧的,更新时有效) | ||
125 | + OldValue string `json:"oldValue,omitempty"` | ||
126 | + | ||
127 | + typeValue interface{} | ||
128 | +} | ||
129 | + | ||
130 | +func (f *FieldValue) CheckValue() error { | ||
131 | + val, err := ValueToType(f.Value, f.SQLType) | ||
132 | + if err != nil { | ||
133 | + return err | ||
134 | + } | ||
135 | + f.typeValue = val | ||
136 | + return nil | ||
137 | +} | ||
138 | + | ||
139 | +func (f *FieldValue) TypeValue() interface{} { | ||
140 | + if f.typeValue == nil { | ||
141 | + f.typeValue, _ = ValueToType(f.Value, f.SQLType) | ||
142 | + } | ||
143 | + return f.typeValue | ||
144 | +} | ||
145 | + | ||
146 | +func ValueToType(value string, sqlType string) (interface{}, error) { | ||
147 | + var toTypeVal interface{} | ||
148 | + var err error | ||
149 | + numberString := utils.NewNumberString(value) | ||
150 | + switch sqlType { | ||
151 | + case String.ToString(): | ||
152 | + toTypeVal = value | ||
153 | + case Int.ToString(): | ||
154 | + toTypeVal, err = numberString.Int() | ||
155 | + case Float.ToString(): | ||
156 | + toTypeVal, err = numberString.Float64() | ||
157 | + case Date.ToString(): | ||
158 | + toTypeVal, err = xtime.Parse(value) | ||
159 | + return nil, nil | ||
160 | + case Datetime.ToString(): | ||
161 | + toTypeVal, err = xtime.Parse(value) | ||
162 | + return nil, nil | ||
163 | + default: | ||
164 | + return nil, fmt.Errorf("unknow sql type :%v", sqlType) | ||
165 | + } | ||
166 | + return toTypeVal, err | ||
167 | +} |
@@ -44,6 +44,16 @@ func (file *File) Identify() interface{} { | @@ -44,6 +44,16 @@ func (file *File) Identify() interface{} { | ||
44 | return file.FileId | 44 | return file.FileId |
45 | } | 45 | } |
46 | 46 | ||
47 | +func (file *File) UpdateFileUrl(url string) { | ||
48 | + if len(url) == 0 { | ||
49 | + return | ||
50 | + } | ||
51 | + if url == file.FileInfo.Url { | ||
52 | + return | ||
53 | + } | ||
54 | + file.FileInfo.Url = url | ||
55 | +} | ||
56 | + | ||
47 | func (file *File) Update(data map[string]interface{}) error { | 57 | func (file *File) Update(data map[string]interface{}) error { |
48 | return nil | 58 | return nil |
49 | } | 59 | } |
@@ -74,7 +74,7 @@ func (gateway BaseServiceGateway) FastDoRequest(url, method string, param interf | @@ -74,7 +74,7 @@ func (gateway BaseServiceGateway) FastDoRequest(url, method string, param interf | ||
74 | result = err.Error() | 74 | result = err.Error() |
75 | } | 75 | } |
76 | if gateway.Interceptor != nil { | 76 | if gateway.Interceptor != nil { |
77 | - gateway.Interceptor(fmt.Sprintf("%v | %v | %v : %v \n request:%v \n response:%v", time.Since(begin), url, strings.ToUpper(method), | 77 | + gateway.Interceptor(fmt.Sprintf("【网关】%v | %v | %v : %v \nRequest:%v \nResponse:%v", time.Since(begin), url, strings.ToUpper(method), |
78 | result, | 78 | result, |
79 | string(jsonParam), | 79 | string(jsonParam), |
80 | string(jsonData), | 80 | string(jsonData), |
1 | package bytelib | 1 | package bytelib |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + "github.com/beego/beego/v2/core/logs" | ||
4 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" | 6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" |
5 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api" |
6 | - "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
7 | "time" | 8 | "time" |
8 | ) | 9 | ) |
9 | 10 | ||
@@ -18,7 +19,8 @@ func NewApiByteLib(host string) *ApiByteLib { | @@ -18,7 +19,8 @@ func NewApiByteLib(host string) *ApiByteLib { | ||
18 | gt.ConnectTimeout = 10 * time.Second | 19 | gt.ConnectTimeout = 10 * time.Second |
19 | gt.ReadWriteTimeout = 10 * time.Second | 20 | gt.ReadWriteTimeout = 10 * time.Second |
20 | gt.Interceptor = func(msg string) { | 21 | gt.Interceptor = func(msg string) { |
21 | - log.Logger.Info(msg) | 22 | + //log.Logger.Info(msg) |
23 | + logs.Debug(msg) | ||
22 | } | 24 | } |
23 | return &ApiByteLib{ | 25 | return &ApiByteLib{ |
24 | BaseServiceGateway: gt, | 26 | BaseServiceGateway: gt, |
@@ -28,43 +30,68 @@ func NewApiByteLib(host string) *ApiByteLib { | @@ -28,43 +30,68 @@ func NewApiByteLib(host string) *ApiByteLib { | ||
28 | // 加载数据 | 30 | // 加载数据 |
29 | 31 | ||
30 | func (gateway ApiByteLib) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) { | 32 | func (gateway ApiByteLib) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) { |
31 | - return nil, nil | 33 | + url := gateway.Host() + "/checkout-tables/query" |
34 | + method := "post" | ||
35 | + var data DataCheckoutTables | ||
36 | + request := NewRequestCheckoutTablesQuery(param) | ||
37 | + err := gateway.FastDoRequest(url, method, request, &data) | ||
38 | + if err != nil { | ||
39 | + return nil, err | ||
40 | + } | ||
41 | + | ||
42 | + response := ToDataLoadDataTable(data) | ||
43 | + return response, nil | ||
32 | } | 44 | } |
33 | 45 | ||
34 | // EditTable 编辑表格 | 46 | // EditTable 编辑表格 |
35 | func (gateway ApiByteLib) EditTable(param bytecore.ReqEditDataTable) (*bytecore.DataEditDataTable, error) { | 47 | func (gateway ApiByteLib) EditTable(param bytecore.ReqEditDataTable) (*bytecore.DataEditDataTable, error) { |
36 | - url := gateway.Host() + "/table/edit" | 48 | + url := gateway.Host() + "/checkout-tables/pre-proccess" |
37 | method := "post" | 49 | method := "post" |
38 | - var data bytecore.DataEditDataTable | ||
39 | - err := gateway.FastDoRequest(url, method, param, &data) | 50 | + var data DataCheckoutTables |
51 | + request := NewRequestCheckoutTablesPreProccess(param) | ||
52 | + err := gateway.FastDoRequest(url, method, request, &data) | ||
40 | if err != nil { | 53 | if err != nil { |
41 | return nil, err | 54 | return nil, err |
42 | } | 55 | } |
43 | - return &data, nil | 56 | + |
57 | + response := ToDataLoadDataTable(data) | ||
58 | + return &bytecore.DataEditDataTable{ | ||
59 | + DataLoadDataTable: *response, | ||
60 | + }, nil | ||
44 | } | 61 | } |
45 | 62 | ||
46 | // SaveTable 保存校验文件 (文件地址) | 63 | // SaveTable 保存校验文件 (文件地址) |
47 | func (gateway ApiByteLib) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) { | 64 | func (gateway ApiByteLib) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) { |
48 | - url := gateway.Host() + "/table/save" | 65 | + url := gateway.Host() + "/checkout-tables/save" |
49 | method := "post" | 66 | method := "post" |
50 | - var data bytecore.DataSaveTable | ||
51 | - err := gateway.FastDoRequest(url, method, param, &data) | 67 | + var data ResponseCheckoutTablesSave |
68 | + var request = RequestCheckoutTablesSave{ | ||
69 | + OriginalTableId: fmt.Sprintf("%v", param.FileId), | ||
70 | + } | ||
71 | + err := gateway.FastDoRequest(url, method, request, &data) | ||
52 | if err != nil { | 72 | if err != nil { |
53 | return nil, err | 73 | return nil, err |
54 | } | 74 | } |
55 | - return &data, nil | 75 | + var response = &bytecore.DataSaveTable{ |
76 | + Url: data.CheckoutTableUrl, | ||
77 | + } | ||
78 | + return response, nil | ||
56 | } | 79 | } |
57 | 80 | ||
58 | // GenerateTable 生成主表 | 81 | // GenerateTable 生成主表 |
59 | func (gateway ApiByteLib) GenerateTable(param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) { | 82 | func (gateway ApiByteLib) GenerateTable(param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) { |
60 | - url := gateway.Host() + "/table/generate" | 83 | + url := gateway.Host() + "/checkout-tables/generate-master-table" |
61 | method := "post" | 84 | method := "post" |
62 | - var data bytecore.DataGenerateTable | ||
63 | - err := gateway.FastDoRequest(url, method, param, &data) | 85 | + var data DataCheckoutTablesGenerateMasterTable |
86 | + request := NewRequestCheckoutTablesGenerateMasterTable(param) | ||
87 | + err := gateway.FastDoRequest(url, method, request, &data) | ||
64 | if err != nil { | 88 | if err != nil { |
65 | return nil, err | 89 | return nil, err |
66 | } | 90 | } |
67 | - return &data, nil | 91 | + var response = bytecore.DataGenerateTable{ |
92 | + TableName: data.MasterTableName, | ||
93 | + } | ||
94 | + return &response, nil | ||
68 | } | 95 | } |
69 | 96 | ||
70 | // CopyTable 表复制 | 97 | // CopyTable 表复制 |
pkg/infrastructure/api/bytelib/types.go
0 → 100644
1 | +package bytelib | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" | ||
7 | +) | ||
8 | + | ||
9 | +type RequestCheckoutTablesQuery struct { | ||
10 | + OriginalTableId string `json:"originalTableId"` | ||
11 | + IsFromOriginalTable bool `json:"isFromOriginalTable"` | ||
12 | + TableFileUrl string `json:"tableFileUrl"` | ||
13 | + ColumnSchemas []bytecore.ColumnSchema `json:"columnSchemas"` | ||
14 | + PageNumber int `json:"pageNumber"` | ||
15 | + PageSize int `json:"pageSize"` | ||
16 | + QueryParameters map[string]interface{} `json:"queryParameters"` | ||
17 | + SortParameters map[string]interface{} `json:"sortParameters"` | ||
18 | +} | ||
19 | + | ||
20 | +type DataCheckoutTables struct { | ||
21 | + OriginalTableId string `json:"originalTableId"` | ||
22 | + ColumnSchemas []bytecore.ColumnSchema `json:"columnSchemas"` | ||
23 | + PageNumber int `json:"pageNumber"` | ||
24 | + PageSize int `json:"pageSize"` | ||
25 | + DataCount int `json:"dataCount"` | ||
26 | + ShowData [][]string `json:"showData"` | ||
27 | + AbnormalProccessIndexes [][]interface{} `json:"abnormalProccessIndexes"` | ||
28 | +} | ||
29 | + | ||
30 | +func NewRequestCheckoutTablesQuery(param bytecore.ReqLoadDataTable) RequestCheckoutTablesQuery { | ||
31 | + return RequestCheckoutTablesQuery{ | ||
32 | + OriginalTableId: param.OriginalTableId, | ||
33 | + IsFromOriginalTable: param.IsFromOriginalTable, | ||
34 | + TableFileUrl: param.TableFileUrl, | ||
35 | + ColumnSchemas: param.ColumnSchemas, | ||
36 | + PageNumber: param.PageNumber, | ||
37 | + PageSize: param.PageSize, | ||
38 | + QueryParameters: param.QueryParameters, | ||
39 | + SortParameters: param.SortParameters, | ||
40 | + } | ||
41 | +} | ||
42 | + | ||
43 | +type RequestCheckoutTablesPreProccess struct { | ||
44 | + OriginalTableId string `json:"originalTableId"` | ||
45 | + ColumnSchemas []bytecore.ColumnSchema `json:"columnSchemas"` | ||
46 | + PreProccessColumnNames []string `json:"preProccessColumnNames"` | ||
47 | + PreProccessActionName string `json:"preProccessActionName"` | ||
48 | + PreProccessActionParameterValues map[string]string `json:"preProccessActionParameterValues"` | ||
49 | + PageNumber int `json:"pageNumber"` | ||
50 | + PageSize int `json:"pageSize"` | ||
51 | + QueryParameters map[string]interface{} `json:"queryParameters"` | ||
52 | + SortParameters map[string]interface{} `json:"sortParameters"` | ||
53 | +} | ||
54 | + | ||
55 | +func NewRequestCheckoutTablesPreProccess(param bytecore.ReqEditDataTable) RequestCheckoutTablesPreProccess { | ||
56 | + req := RequestCheckoutTablesPreProccess{ | ||
57 | + OriginalTableId: fmt.Sprintf("%v", param.FileId), | ||
58 | + ColumnSchemas: FieldsToColumnSchemas(param.Fields), | ||
59 | + PreProccessActionName: param.Action, | ||
60 | + PreProccessActionParameterValues: make(map[string]string), | ||
61 | + PageNumber: param.PageNumber, | ||
62 | + PageSize: param.PageSize, | ||
63 | + QueryParameters: make(map[string]interface{}), | ||
64 | + SortParameters: make(map[string]interface{}), | ||
65 | + } | ||
66 | + | ||
67 | + for _, v := range param.ProcessFields { | ||
68 | + req.PreProccessColumnNames = append(req.PreProccessColumnNames, v.Name) | ||
69 | + } | ||
70 | + | ||
71 | + return req | ||
72 | +} | ||
73 | + | ||
74 | +type RequestCheckoutTablesSave struct { | ||
75 | + OriginalTableId string `json:"originalTableId"` | ||
76 | +} | ||
77 | + | ||
78 | +type ResponseCheckoutTablesSave struct { | ||
79 | + CheckoutTableUrl string `json:"checkoutTableUrl"` | ||
80 | +} | ||
81 | + | ||
82 | +func FieldsToColumnSchemas(fields []*bytecore.Field) []bytecore.ColumnSchema { | ||
83 | + result := make([]bytecore.ColumnSchema, 0) | ||
84 | + | ||
85 | + for _, f := range fields { | ||
86 | + result = append(result, bytecore.ColumnSchema{ | ||
87 | + ColumnName: f.Name, | ||
88 | + ColumnType: f.Type, | ||
89 | + }) | ||
90 | + } | ||
91 | + return result | ||
92 | +} | ||
93 | + | ||
94 | +func DomainFieldsToColumnSchemas(fields []*domain.Field) []bytecore.ColumnSchema { | ||
95 | + result := make([]bytecore.ColumnSchema, 0) | ||
96 | + | ||
97 | + for _, f := range fields { | ||
98 | + result = append(result, bytecore.ColumnSchema{ | ||
99 | + ColumnName: f.Name, | ||
100 | + ColumnType: f.SQLType, | ||
101 | + }) | ||
102 | + } | ||
103 | + return result | ||
104 | +} | ||
105 | + | ||
106 | +func ToDataLoadDataTable(data DataCheckoutTables) *bytecore.DataLoadDataTable { | ||
107 | + response := &bytecore.DataLoadDataTable{ | ||
108 | + PageNumber: data.PageNumber, | ||
109 | + Data: data.ShowData, | ||
110 | + Total: data.DataCount, | ||
111 | + } | ||
112 | + for i, f := range data.ColumnSchemas { | ||
113 | + response.Fields = append(response.Fields, &bytecore.Field{ | ||
114 | + Index: i + 1, | ||
115 | + Name: f.ColumnName, | ||
116 | + Type: f.ColumnType, | ||
117 | + }) | ||
118 | + } | ||
119 | + return response | ||
120 | +} | ||
121 | + | ||
122 | +type ( | ||
123 | + RequestCheckoutTablesGenerateMasterTable struct { | ||
124 | + OriginalTableId string `json:"originalTableId"` | ||
125 | + CheckoutTableFileUrl string `json:"checkoutTableFileUrl"` | ||
126 | + ColumnSchemas []bytecore.ColumnSchema `json:"columnSchemas"` | ||
127 | + MasterTableName string `json:"masterTableName"` | ||
128 | + FieldSchemas []FieldSchema `json:"fieldSchemas"` | ||
129 | + KeyFieldEnNames []string `json:"keyFieldEnNames"` | ||
130 | + } | ||
131 | + DataCheckoutTablesGenerateMasterTable struct { | ||
132 | + MasterTableName string `json:"masterTableName"` | ||
133 | + } | ||
134 | + FieldSchema struct { | ||
135 | + FieldZhName string `json:"fieldZhName"` | ||
136 | + FieldEnName string `json:"fieldEnName"` | ||
137 | + FieldType string `json:"fieldType"` | ||
138 | + FieldDescription string `json:"fieldDescription"` | ||
139 | + IsAllowNull bool `json:"isAllowNull"` | ||
140 | + } | ||
141 | +) | ||
142 | + | ||
143 | +func NewRequestCheckoutTablesGenerateMasterTable(param bytecore.ReqGenerateTable) RequestCheckoutTablesGenerateMasterTable { | ||
144 | + request := RequestCheckoutTablesGenerateMasterTable{ | ||
145 | + OriginalTableId: fmt.Sprintf("%v", param.FileId), | ||
146 | + CheckoutTableFileUrl: param.FileUrl, | ||
147 | + ColumnSchemas: DomainFieldsToColumnSchemas(param.Table.DataFields), | ||
148 | + MasterTableName: param.Table.SQLName, | ||
149 | + FieldSchemas: ToFieldSchemas(param.Table.DataFields), | ||
150 | + KeyFieldEnNames: []string{param.Table.PK.SQLName}, | ||
151 | + } | ||
152 | + return request | ||
153 | +} | ||
154 | + | ||
155 | +func ToFieldSchemas(fields []*domain.Field) []FieldSchema { | ||
156 | + result := make([]FieldSchema, 0) | ||
157 | + for _, f := range fields { | ||
158 | + result = append(result, FieldSchema{ | ||
159 | + FieldZhName: f.Name, | ||
160 | + FieldEnName: f.SQLName, | ||
161 | + FieldType: f.SQLType, | ||
162 | + FieldDescription: f.Description, | ||
163 | + IsAllowNull: false, | ||
164 | + }) | ||
165 | + } | ||
166 | + return result | ||
167 | +} | ||
168 | + | ||
169 | +func ToFieldSchemaEnNames(fields []*domain.Field) []string { | ||
170 | + result := make([]string, 0) | ||
171 | + for _, f := range fields { | ||
172 | + result = append(result, f.SQLName) | ||
173 | + } | ||
174 | + return result | ||
175 | +} |
1 | package api | 1 | package api |
2 | 2 | ||
3 | +import "fmt" | ||
4 | + | ||
3 | var ( | 5 | var ( |
4 | JsonUnMarshError int = 1000 | 6 | JsonUnMarshError int = 1000 |
5 | ) | 7 | ) |
@@ -10,7 +12,7 @@ type ErrCodeMsg struct { | @@ -10,7 +12,7 @@ type ErrCodeMsg struct { | ||
10 | } | 12 | } |
11 | 13 | ||
12 | func (e ErrCodeMsg) Error() string { | 14 | func (e ErrCodeMsg) Error() string { |
13 | - return e.Msg | 15 | + return fmt.Sprintf("错误码:%v 错误信息:%v", e.Code, e.Msg) |
14 | } | 16 | } |
15 | 17 | ||
16 | func NewErrCodeMsg(code int, msg string) ErrCodeMsg { | 18 | func NewErrCodeMsg(code int, msg string) ErrCodeMsg { |
@@ -3,8 +3,10 @@ package domainService | @@ -3,8 +3,10 @@ package domainService | ||
3 | import ( | 3 | import ( |
4 | "bytes" | 4 | "bytes" |
5 | "github.com/beego/beego/v2/client/httplib" | 5 | "github.com/beego/beego/v2/client/httplib" |
6 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" | 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/bytelib" | ||
8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel" | 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/excel" |
9 | ) | 11 | ) |
10 | 12 | ||
@@ -12,7 +14,7 @@ type ByteCoreService struct { | @@ -12,7 +14,7 @@ type ByteCoreService struct { | ||
12 | TempDataTable map[int]*bytecore.DataLoadDataTable | 14 | TempDataTable map[int]*bytecore.DataLoadDataTable |
13 | } | 15 | } |
14 | 16 | ||
15 | -var ByteCore = &ByteCoreService{} //bytecore.ByteLibService | 17 | +var ByteCore bytecore.ByteLibService = &WrapByteCoreService{} //&ByteCoreService{} |
16 | 18 | ||
17 | var _ bytecore.ByteLibService = (*ByteCoreService)(nil) | 19 | var _ bytecore.ByteLibService = (*ByteCoreService)(nil) |
18 | 20 | ||
@@ -51,7 +53,8 @@ func (ptr *ByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*byt | @@ -51,7 +53,8 @@ func (ptr *ByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*byt | ||
51 | } | 53 | } |
52 | 54 | ||
53 | func (ptr *ByteCoreService) EditTable(param bytecore.ReqEditDataTable) (*bytecore.DataEditDataTable, error) { | 55 | func (ptr *ByteCoreService) EditTable(param bytecore.ReqEditDataTable) (*bytecore.DataEditDataTable, error) { |
54 | - return nil, nil | 56 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) |
57 | + return apiByteLib.EditTable(param) | ||
55 | } | 58 | } |
56 | 59 | ||
57 | func (ptr *ByteCoreService) save(fileId int, dataTable *bytecore.DataLoadDataTable) { | 60 | func (ptr *ByteCoreService) save(fileId int, dataTable *bytecore.DataLoadDataTable) { |
@@ -80,37 +83,57 @@ func columnToField(cols []string) []*bytecore.Field { | @@ -80,37 +83,57 @@ func columnToField(cols []string) []*bytecore.Field { | ||
80 | } | 83 | } |
81 | 84 | ||
82 | func (ptr *ByteCoreService) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) { | 85 | func (ptr *ByteCoreService) SaveTable(param bytecore.ReqSaveTable) (*bytecore.DataSaveTable, error) { |
83 | - return nil, nil | 86 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) |
87 | + return apiByteLib.SaveTable(param) | ||
84 | } | 88 | } |
85 | 89 | ||
86 | -func (ptr *ByteCoreService) GenerateTable(param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) { | ||
87 | - return nil, nil | 90 | +func (ptr *ByteCoreService) GenerateTable(ctx *domain.Context, param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) { |
91 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) | ||
92 | + return apiByteLib.GenerateTable(param) | ||
88 | } | 93 | } |
89 | 94 | ||
90 | func (ptr *ByteCoreService) CopyTable(param bytecore.ReqCopyTable) (*bytecore.DataCopyTable, error) { | 95 | func (ptr *ByteCoreService) CopyTable(param bytecore.ReqCopyTable) (*bytecore.DataCopyTable, error) { |
91 | - return nil, nil | 96 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) |
97 | + return apiByteLib.CopyTable(param) | ||
92 | } | 98 | } |
93 | 99 | ||
94 | func (ptr *ByteCoreService) AppendData(param bytecore.ReqAppendData) (*bytecore.DataAppendData, error) { | 100 | func (ptr *ByteCoreService) AppendData(param bytecore.ReqAppendData) (*bytecore.DataAppendData, error) { |
95 | - return nil, nil | 101 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) |
102 | + return apiByteLib.AppendData(param) | ||
96 | } | 103 | } |
97 | 104 | ||
98 | func (ptr *ByteCoreService) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore.DataDeleteTable, error) { | 105 | func (ptr *ByteCoreService) DeleteTable(param bytecore.ReqDeleteTable) (*bytecore.DataDeleteTable, error) { |
99 | - return nil, nil | 106 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) |
107 | + return apiByteLib.DeleteTable(param) | ||
100 | } | 108 | } |
101 | 109 | ||
102 | func (ptr *ByteCoreService) CancelFile(param bytecore.ReqCancelFile) (*bytecore.DataCancelFile, error) { | 110 | func (ptr *ByteCoreService) CancelFile(param bytecore.ReqCancelFile) (*bytecore.DataCancelFile, error) { |
103 | - return nil, nil | 111 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) |
112 | + return apiByteLib.CancelFile(param) | ||
104 | } | 113 | } |
105 | 114 | ||
106 | func (ptr *ByteCoreService) EditTableData(param bytecore.ReqEditTableData) (*bytecore.DataEditTableData, error) { | 115 | func (ptr *ByteCoreService) EditTableData(param bytecore.ReqEditTableData) (*bytecore.DataEditTableData, error) { |
107 | - return nil, nil | 116 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) |
117 | + return apiByteLib.EditTableData(param) | ||
108 | } | 118 | } |
109 | 119 | ||
110 | ////////////// | 120 | ////////////// |
111 | // 字库核心 | 121 | // 字库核心 |
112 | ////////////// | 122 | ////////////// |
113 | 123 | ||
114 | -func CreateByteCoreService() (*ByteCoreService, error) { | 124 | +func CreateByteCoreService() (bytecore.ByteLibService, error) { |
115 | return ByteCore, nil | 125 | return ByteCore, nil |
116 | } | 126 | } |
127 | + | ||
128 | +type WrapByteCoreService struct { | ||
129 | + ByteCoreService | ||
130 | +} | ||
131 | + | ||
132 | +func (ptr *WrapByteCoreService) LoadDataTable(param bytecore.ReqLoadDataTable) (*bytecore.DataLoadDataTable, error) { | ||
133 | + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST) | ||
134 | + return apiByteLib.LoadDataTable(param) | ||
135 | +} | ||
136 | + | ||
137 | +func (ptr *WrapByteCoreService) GenerateTable(ctx *domain.Context, param bytecore.ReqGenerateTable) (*bytecore.DataGenerateTable, error) { | ||
138 | + return nil, nil | ||
139 | +} |
@@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
8 | ) | 9 | ) |
9 | 10 | ||
10 | type DeleteFileService struct { | 11 | type DeleteFileService struct { |
@@ -24,14 +25,14 @@ func NewDeleteFileService(transactionContext *pgTransaction.TransactionContext) | @@ -24,14 +25,14 @@ func NewDeleteFileService(transactionContext *pgTransaction.TransactionContext) | ||
24 | // DeleteFiles 文件删除 | 25 | // DeleteFiles 文件删除 |
25 | func (ptr *DeleteFileService) DeleteFiles(ctx *domain.Context, files ...*domain.File) error { | 26 | func (ptr *DeleteFileService) DeleteFiles(ctx *domain.Context, files ...*domain.File) error { |
26 | for _, file := range files { | 27 | for _, file := range files { |
27 | - if err := ptr.delete(file); err != nil { | 28 | + if err := ptr.delete(ctx, file); err != nil { |
28 | return err | 29 | return err |
29 | } | 30 | } |
30 | } | 31 | } |
31 | return nil | 32 | return nil |
32 | } | 33 | } |
33 | 34 | ||
34 | -func (ptr *DeleteFileService) delete(file *domain.File) error { | 35 | +func (ptr *DeleteFileService) delete(ctx *domain.Context, file *domain.File) error { |
35 | // delete file | 36 | // delete file |
36 | if err := dao.FileDelete(ptr.transactionContext, file.FileId, domain.FileType(file.FileType)); err != nil { | 37 | if err := dao.FileDelete(ptr.transactionContext, file.FileId, domain.FileType(file.FileType)); err != nil { |
37 | return err | 38 | return err |
@@ -46,5 +47,6 @@ func (ptr *DeleteFileService) delete(file *domain.File) error { | @@ -46,5 +47,6 @@ func (ptr *DeleteFileService) delete(file *domain.File) error { | ||
46 | if err := dao.LogDirectDelete(ptr.transactionContext, file.FileId, domain.VerifiedStepLog); err != nil { | 47 | if err := dao.LogDirectDelete(ptr.transactionContext, file.FileId, domain.VerifiedStepLog); err != nil { |
47 | return err | 48 | return err |
48 | } | 49 | } |
50 | + log.Logger.Info(fmt.Sprintf("[%v] 删除文件:%v 文件类型:%v", ctx.OperatorName, file.FileInfo.Name, file.FileType)) | ||
49 | return nil | 51 | return nil |
50 | } | 52 | } |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "fmt" | 4 | "fmt" |
5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" | ||
7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" | 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" |
8 | ) | 9 | ) |
9 | 10 | ||
@@ -12,49 +13,41 @@ type EditDataTableService struct { | @@ -12,49 +13,41 @@ type EditDataTableService struct { | ||
12 | } | 13 | } |
13 | 14 | ||
14 | // Edit 表结构编辑 【data-table】 | 15 | // Edit 表结构编辑 【data-table】 |
15 | -func (ptr *EditDataTableService) Edit(ctx *domain.Context, fileId int, tableId int, mappingFields []*domain.MappingField) (interface{}, error) { | 16 | +func (ptr *EditDataTableService) Edit(ctx *domain.Context, req domain.EditTableRequest) (interface{}, error) { |
16 | fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) | 17 | fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) |
17 | - file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) | 18 | + file, err := fileRepository.FindOne(map[string]interface{}{"fileId": req.FileId}) |
18 | if err != nil { | 19 | if err != nil { |
19 | return nil, fmt.Errorf("文件不存在") | 20 | return nil, fmt.Errorf("文件不存在") |
20 | } | 21 | } |
21 | - | ||
22 | - tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | ||
23 | - table, err := tableRepository.FindOne(map[string]interface{}{"tableId": tableId}) | ||
24 | - if err != nil { | ||
25 | - return nil, fmt.Errorf("表不存在") | ||
26 | - } | ||
27 | - | ||
28 | - excelTable, err := tableRepository.FindOne(map[string]interface{}{"tableId": file.FileInfo.TableId}) | ||
29 | - if err != nil { | 22 | + if file.FileType != domain.TemporaryFile.ToString() { |
30 | return nil, fmt.Errorf("文件未校验") | 23 | return nil, fmt.Errorf("文件未校验") |
31 | } | 24 | } |
32 | - | ||
33 | - if !(table.TableType == domain.MainTable.ToString() || table.TableType == domain.SideTable.ToString()) { | ||
34 | - return nil, fmt.Errorf("只能追加数据到主表或者副表") | ||
35 | - } | ||
36 | - var subTables []*domain.Table | ||
37 | - _, subTables, err = tableRepository.Find(map[string]interface{}{"parentId": tableId, "tableTypes": []string{domain.SubTable.ToString()}}) | ||
38 | - if err != nil { | ||
39 | - return nil, err | ||
40 | - } | ||
41 | - | 25 | + // TODO:操作名映射 |
26 | + var operateName string = req.Action | ||
42 | // 日志 | 27 | // 日志 |
43 | - if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &AppendDataToTableLog{ | ||
44 | - LogEntry: domain.NewLogEntry(table.Name, domain.MainTable.ToString(), domain.AppendData, ctx), | ||
45 | - File: file, | ||
46 | - Table: table, | ||
47 | - SubTables: subTables, | ||
48 | - RowCount: excelTable.RowCount, | 28 | + if err = FastLog(ptr.transactionContext, domain.VerifiedStepLog, file.FileId, &ExcelTableEditLog{ |
29 | + LogEntry: domain.NewLogEntry(file.FileInfo.Name, domain.VerifiedFile.ToString(), domain.FileVerify, ctx), | ||
30 | + ProcessFields: req.ProcessFields, | ||
31 | + OperateName: operateName, | ||
49 | }); err != nil { | 32 | }); err != nil { |
50 | return nil, err | 33 | return nil, err |
51 | } | 34 | } |
35 | + // 通知底层进行文件表编辑 | ||
36 | + | ||
37 | + response, err := ByteCore.EditTable(bytecore.ReqEditDataTable{ | ||
38 | + FileId: file.FileId, | ||
39 | + PageNumber: req.Where.PageNumber, | ||
40 | + PageSize: req.Where.PageSize, | ||
41 | + Fields: bytecore.ToFields(req.Fields), | ||
42 | + ProcessFields: bytecore.ToFields(req.ProcessFields), | ||
43 | + Action: req.Action, | ||
44 | + Params: req.Params, | ||
45 | + }) | ||
46 | + if err != nil { | ||
47 | + return nil, err | ||
48 | + } | ||
52 | 49 | ||
53 | - // 通知底层进行追加数据 | ||
54 | - | ||
55 | - return map[string]interface{}{ | ||
56 | - "result": fmt.Sprintf("源数据%v条,成功追加%v条;", excelTable.RowCount, excelTable.RowCount), | ||
57 | - }, nil | 50 | + return response, nil |
58 | } | 51 | } |
59 | 52 | ||
60 | func NewEditDataTableService(transactionContext *pgTransaction.TransactionContext) (*EditDataTableService, error) { | 53 | func NewEditDataTableService(transactionContext *pgTransaction.TransactionContext) (*EditDataTableService, error) { |
@@ -6,8 +6,10 @@ import ( | @@ -6,8 +6,10 @@ import ( | ||
6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
7 | "github.com/linmadan/egglib-go/utils/tool_funs" | 7 | "github.com/linmadan/egglib-go/utils/tool_funs" |
8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" | ||
9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao" | 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/dao" |
10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" | 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" |
12 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log" | ||
11 | "time" | 13 | "time" |
12 | ) | 14 | ) |
13 | 15 | ||
@@ -29,15 +31,25 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table * | @@ -29,15 +31,25 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table * | ||
29 | } | 31 | } |
30 | // New Table | 32 | // New Table |
31 | table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx) | 33 | table = NewTable(domain.ExcelTable, file.FileInfo.Name, table.DataFields, table.RowCount).WithContext(ctx) |
34 | + // 通知底层保存、进行回调 | ||
35 | + response, _ := ByteCore.SaveTable(bytecore.ReqSaveTable{FileId: fileId}) | ||
36 | + if err != nil { | ||
37 | + return nil, err | ||
38 | + } | ||
32 | // 来自源文件的 | 39 | // 来自源文件的 |
33 | // 临时文件 -》校验文件 | 40 | // 临时文件 -》校验文件 |
41 | + var newUrl string | ||
42 | + if response != nil { | ||
43 | + newUrl = response.Url | ||
44 | + } | ||
45 | + log.Logger.Info("更新文件地址", map[string]interface{}{"from_url": file.FileInfo.Url, "to_url": newUrl, "sourceFileId": file.SourceFileId}) | ||
34 | switch sourceFile.FileType { | 46 | switch sourceFile.FileType { |
35 | case domain.SourceFile.ToString(): | 47 | case domain.SourceFile.ToString(): |
36 | - if err = ptr.flushSourceFile(ctx, table, file, sourceFile, fileRepository); err != nil { | 48 | + if err = ptr.flushSourceFile(ctx, table, file, sourceFile, fileRepository, newUrl); err != nil { |
37 | return nil, err | 49 | return nil, err |
38 | } | 50 | } |
39 | case domain.VerifiedFile.ToString(): | 51 | case domain.VerifiedFile.ToString(): |
40 | - if err = ptr.flushVerifiedFile(ctx, table, file, sourceFile, fileRepository); err != nil { | 52 | + if err = ptr.flushVerifiedFile(ctx, table, file, sourceFile, fileRepository, newUrl); err != nil { |
41 | return nil, err | 53 | return nil, err |
42 | } | 54 | } |
43 | } | 55 | } |
@@ -48,12 +60,11 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table * | @@ -48,12 +60,11 @@ func (ptr *FlushDataTableService) Flush(ctx *domain.Context, fileId int, table * | ||
48 | }); err != nil { | 60 | }); err != nil { |
49 | return nil, err | 61 | return nil, err |
50 | } | 62 | } |
51 | - // 通知底层保存、进行回调 | ||
52 | 63 | ||
53 | return struct{}{}, nil | 64 | return struct{}{}, nil |
54 | } | 65 | } |
55 | 66 | ||
56 | -func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *domain.Table, file *domain.File, sourceFile *domain.File, fileRepository domain.FileRepository) error { | 67 | +func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *domain.Table, file *domain.File, sourceFile *domain.File, fileRepository domain.FileRepository, url string) error { |
57 | var err error | 68 | var err error |
58 | // 新增 | 69 | // 新增 |
59 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | 70 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) |
@@ -63,6 +74,7 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | @@ -63,6 +74,7 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | ||
63 | } | 74 | } |
64 | file.FileInfo.TableId = table.TableId | 75 | file.FileInfo.TableId = table.TableId |
65 | file.FileType = domain.VerifiedFile.ToString() | 76 | file.FileType = domain.VerifiedFile.ToString() |
77 | + file.UpdateFileUrl(url) | ||
66 | if file, err = fileRepository.Save(file); err != nil { | 78 | if file, err = fileRepository.Save(file); err != nil { |
67 | return err | 79 | return err |
68 | } | 80 | } |
@@ -77,7 +89,7 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | @@ -77,7 +89,7 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | ||
77 | return nil | 89 | return nil |
78 | } | 90 | } |
79 | 91 | ||
80 | -func (ptr *FlushDataTableService) flushVerifiedFile(ctx *domain.Context, table *domain.Table, file *domain.File, sourceFile *domain.File, fileRepository domain.FileRepository) error { | 92 | +func (ptr *FlushDataTableService) flushVerifiedFile(ctx *domain.Context, table *domain.Table, file *domain.File, sourceFile *domain.File, fileRepository domain.FileRepository, url string) error { |
81 | var err error | 93 | var err error |
82 | temporaryFileTableId := table.TableId | 94 | temporaryFileTableId := table.TableId |
83 | // 校验文件对应的表更新 | 95 | // 校验文件对应的表更新 |
@@ -86,6 +98,10 @@ func (ptr *FlushDataTableService) flushVerifiedFile(ctx *domain.Context, table * | @@ -86,6 +98,10 @@ func (ptr *FlushDataTableService) flushVerifiedFile(ctx *domain.Context, table * | ||
86 | if err = dao.ChangeStepLogOwner(ptr.transactionContext, file.FileId, sourceFile.FileId); err != nil { | 98 | if err = dao.ChangeStepLogOwner(ptr.transactionContext, file.FileId, sourceFile.FileId); err != nil { |
87 | return err | 99 | return err |
88 | } | 100 | } |
101 | + sourceFile.UpdateFileUrl(url) | ||
102 | + if sourceFile, err = fileRepository.Save(sourceFile); err != nil { | ||
103 | + return err | ||
104 | + } | ||
89 | // 删除中间文件 | 105 | // 删除中间文件 |
90 | if err = dao.FileDelete(ptr.transactionContext, file.FileId, domain.TemporaryFile); err != nil { | 106 | if err = dao.FileDelete(ptr.transactionContext, file.FileId, domain.TemporaryFile); err != nil { |
91 | return err | 107 | return err |
@@ -144,7 +160,7 @@ func PK() *domain.Field { | @@ -144,7 +160,7 @@ func PK() *domain.Field { | ||
144 | Index: 0, | 160 | Index: 0, |
145 | Name: "序号", | 161 | Name: "序号", |
146 | SQLName: "id", | 162 | SQLName: "id", |
147 | - SQLType: domain.Int.ToString(), | 163 | + SQLType: domain.String.ToString(), |
148 | Description: "主键", | 164 | Description: "主键", |
149 | Flag: domain.PKField, | 165 | Flag: domain.PKField, |
150 | } | 166 | } |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "fmt" | 4 | "fmt" |
5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
7 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" | ||
7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" | 8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" |
8 | ) | 9 | ) |
9 | 10 | ||
@@ -42,6 +43,10 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i | @@ -42,6 +43,10 @@ func (ptr *GenerateMainTableService) GenerateTable(ctx *domain.Context, fileId i | ||
42 | }); err != nil { | 43 | }); err != nil { |
43 | return nil, err | 44 | return nil, err |
44 | } | 45 | } |
46 | + | ||
47 | + if _, err = ByteCore.GenerateTable(ctx, bytecore.ReqGenerateTable{FileId: fileId, FileUrl: file.FileInfo.Url, Table: table}); err != nil { | ||
48 | + return nil, err | ||
49 | + } | ||
45 | return struct{}{}, nil | 50 | return struct{}{}, nil |
46 | } | 51 | } |
47 | 52 |
@@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" | 7 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/bytecore" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/bytelib" | ||
8 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" | 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository" |
9 | ) | 10 | ) |
10 | 11 | ||
@@ -14,19 +15,22 @@ type PreviewDataTableService struct { | @@ -14,19 +15,22 @@ type PreviewDataTableService struct { | ||
14 | } | 15 | } |
15 | 16 | ||
16 | // Preview 预览 【data-table】 | 17 | // Preview 预览 【data-table】 |
17 | -func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, where domain.Where) (interface{}, error) { | 18 | +func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, fields []*domain.Field, where domain.Where) (interface{}, error) { |
18 | fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) | 19 | fileRepository, _ := repository.NewFileRepository(ptr.transactionContext) |
19 | file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) | 20 | file, err := fileRepository.FindOne(map[string]interface{}{"fileId": fileId}) |
20 | if err != nil { | 21 | if err != nil { |
21 | return nil, fmt.Errorf("文件不存在") | 22 | return nil, fmt.Errorf("文件不存在") |
22 | } | 23 | } |
23 | - | 24 | + isSourceFile := false |
25 | + fileUrl := "" | ||
24 | // Copy to TemporaryFile | 26 | // Copy to TemporaryFile |
25 | if file.FileType != domain.TemporaryFile.ToString() { | 27 | if file.FileType != domain.TemporaryFile.ToString() { |
26 | file = file.CopyTo(domain.TemporaryFile, ctx) | 28 | file = file.CopyTo(domain.TemporaryFile, ctx) |
27 | if file, err = fileRepository.Save(file); err != nil { | 29 | if file, err = fileRepository.Save(file); err != nil { |
28 | return nil, err | 30 | return nil, err |
29 | } | 31 | } |
32 | + isSourceFile = true | ||
33 | + fileUrl = file.FileInfo.Url | ||
30 | } | 34 | } |
31 | //TEST | 35 | //TEST |
32 | ptr.FileId = file.FileId | 36 | ptr.FileId = file.FileId |
@@ -39,22 +43,23 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, whe | @@ -39,22 +43,23 @@ func (ptr *PreviewDataTableService) Preview(ctx *domain.Context, fileId int, whe | ||
39 | Url: file.FileInfo.Url, | 43 | Url: file.FileInfo.Url, |
40 | Ext: file.FileInfo.Ext, | 44 | Ext: file.FileInfo.Ext, |
41 | Where: where, | 45 | Where: where, |
46 | + | ||
47 | + OriginalTableId: fmt.Sprintf("%v", file.FileId), | ||
48 | + IsFromOriginalTable: isSourceFile, | ||
49 | + TableFileUrl: fileUrl, | ||
50 | + ColumnSchemas: bytelib.DomainFieldsToColumnSchemas(fields), | ||
51 | + QueryParameters: make(map[string]interface{}), | ||
52 | + SortParameters: make(map[string]interface{}), | ||
42 | }) | 53 | }) |
43 | if err != nil { | 54 | if err != nil { |
44 | return nil, err | 55 | return nil, err |
45 | } | 56 | } |
46 | response.ObjectType = domain.ObjectFile | 57 | response.ObjectType = domain.ObjectFile |
58 | + response.FileId = file.FileId | ||
47 | response.TableType = domain.ExcelTable.ToString() | 59 | response.TableType = domain.ExcelTable.ToString() |
48 | return response, nil | 60 | return response, nil |
49 | } | 61 | } |
50 | 62 | ||
51 | -//func convert(from *bytecore.DataLoadDataTable)(to *domain.DataTable){ | ||
52 | -// to = &domain.DataTable{ | ||
53 | -// | ||
54 | -// } | ||
55 | -// return | ||
56 | -//} | ||
57 | - | ||
58 | func (ptr *PreviewDataTableService) GetFileId() int { | 63 | func (ptr *PreviewDataTableService) GetFileId() int { |
59 | return ptr.FileId | 64 | return ptr.FileId |
60 | } | 65 | } |
@@ -187,6 +187,51 @@ func (l *CopyTableLog) Content() string { | @@ -187,6 +187,51 @@ func (l *CopyTableLog) Content() string { | ||
187 | return msg | 187 | return msg |
188 | } | 188 | } |
189 | 189 | ||
190 | +// 7.编辑记录 | ||
191 | +type RowAddLog struct { | ||
192 | + domain.LogEntry | ||
193 | +} | ||
194 | + | ||
195 | +func (l *RowAddLog) Content() string { | ||
196 | + msg := fmt.Sprintf("新增行数据") | ||
197 | + return msg | ||
198 | +} | ||
199 | + | ||
200 | +type RowUpdateLog struct { | ||
201 | + domain.LogEntry | ||
202 | + FieldValue []*domain.FieldValue | ||
203 | + Where domain.Where | ||
204 | + Number int | ||
205 | +} | ||
206 | + | ||
207 | +func (l *RowUpdateLog) Content() string { | ||
208 | + change := "" | ||
209 | + index := l.Number + l.Where.Offset() | ||
210 | + for _, f := range l.FieldValue { | ||
211 | + if f.OldValue != f.Value { | ||
212 | + change += fmt.Sprintf("%v字段%v行的值从%v更改为%v;", f.Field.Name, index, f.OldValue, f.Value) | ||
213 | + } | ||
214 | + } | ||
215 | + if len(change) == 0 { | ||
216 | + return "更新数据内容" | ||
217 | + } | ||
218 | + msg := fmt.Sprintf("更改数据内容:%v", change) | ||
219 | + return msg | ||
220 | +} | ||
221 | + | ||
222 | +type RowRemoveLog struct { | ||
223 | + domain.LogEntry | ||
224 | + FieldValue *domain.FieldValues | ||
225 | + Where domain.Where | ||
226 | +} | ||
227 | + | ||
228 | +func (l *RowRemoveLog) Content() string { | ||
229 | + index := l.FieldValue.Number + l.Where.Offset() | ||
230 | + //msg := fmt.Sprintf("删除%v行数据;筛选件:%v",index,"") | ||
231 | + msg := fmt.Sprintf("删除%v行数据;", index) | ||
232 | + return msg | ||
233 | +} | ||
234 | + | ||
190 | // 8.表删除日志 | 235 | // 8.表删除日志 |
191 | type DeleteTableLog struct { | 236 | type DeleteTableLog struct { |
192 | domain.LogEntry | 237 | domain.LogEntry |
@@ -228,3 +273,21 @@ func (l *AppendDataToTableLog) Content() string { | @@ -228,3 +273,21 @@ func (l *AppendDataToTableLog) Content() string { | ||
228 | } | 273 | } |
229 | return msg | 274 | return msg |
230 | } | 275 | } |
276 | + | ||
277 | +/*步骤日志*/ | ||
278 | +type ExcelTableEditLog struct { | ||
279 | + domain.LogEntry | ||
280 | + // 操作名称 | ||
281 | + OperateName string | ||
282 | + // 操作列 | ||
283 | + ProcessFields []*domain.Field | ||
284 | +} | ||
285 | + | ||
286 | +func (l *ExcelTableEditLog) Content() string { | ||
287 | + fieldsName := make([]string, 0) | ||
288 | + for _, f := range l.ProcessFields { | ||
289 | + fieldsName = append(fieldsName, fmt.Sprintf("【%v】", f.Name)) | ||
290 | + } | ||
291 | + msg := fmt.Sprintf("%v:%v", l.OperateName, strings.Join(fieldsName, "、")) | ||
292 | + return msg | ||
293 | +} |
@@ -21,7 +21,7 @@ func NewAddTableStructService(transactionContext *pgTransaction.TransactionConte | @@ -21,7 +21,7 @@ func NewAddTableStructService(transactionContext *pgTransaction.TransactionConte | ||
21 | } | 21 | } |
22 | } | 22 | } |
23 | 23 | ||
24 | -func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTableId int, fields []*domain.Field, name string) (interface{}, error) { | 24 | +func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTableId int, fields []*domain.Field, name string) (*domain.Table, error) { |
25 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | 25 | tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) |
26 | mainTable, err := tableRepository.FindOne(map[string]interface{}{"tableId": parentTableId}) | 26 | mainTable, err := tableRepository.FindOne(map[string]interface{}{"tableId": parentTableId}) |
27 | if err != nil { | 27 | if err != nil { |
@@ -38,19 +38,20 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl | @@ -38,19 +38,20 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl | ||
38 | } | 38 | } |
39 | 39 | ||
40 | fields = MappingFields(mainTable, fields) | 40 | fields = MappingFields(mainTable, fields) |
41 | - dataFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": 1}) | ||
42 | - manualFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": 2}) | 41 | + dataFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.MainTableField}) |
42 | + manualFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.ManualField}) | ||
43 | table := NewTable(domain.SubTable, name, fields, mainTable.RowCount).WithContext(ctx) | 43 | table := NewTable(domain.SubTable, name, fields, mainTable.RowCount).WithContext(ctx) |
44 | table.DataFieldIndex = mainTable.DataFieldIndex | 44 | table.DataFieldIndex = mainTable.DataFieldIndex |
45 | table.DataFields = dataFields | 45 | table.DataFields = dataFields |
46 | table.ManualFields = manualFields | 46 | table.ManualFields = manualFields |
47 | table.ParentId = parentTableId | 47 | table.ParentId = parentTableId |
48 | + table.SQLName = mainTable.SQLName // 主表名跟分表名相同 | ||
48 | reserves, deletes, adds := domain.FieldsChange(table.Fields(false), fields) | 49 | reserves, deletes, adds := domain.FieldsChange(table.Fields(false), fields) |
49 | 50 | ||
50 | if err = domain.ValidFields(fields); err != nil { | 51 | if err = domain.ValidFields(fields); err != nil { |
51 | return nil, err | 52 | return nil, err |
52 | } | 53 | } |
53 | - if _, err = tableRepository.Save(table); err != nil { | 54 | + if table, err = tableRepository.Save(table); err != nil { |
54 | return nil, err | 55 | return nil, err |
55 | } | 56 | } |
56 | if _, err = tableRepository.Save(mainTable); err != nil { | 57 | if _, err = tableRepository.Save(mainTable); err != nil { |
@@ -70,5 +71,5 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl | @@ -70,5 +71,5 @@ func (ptr *AddTableStructService) AddTableStruct(ctx *domain.Context, parentTabl | ||
70 | } | 71 | } |
71 | 72 | ||
72 | // 通知底层 | 73 | // 通知底层 |
73 | - return struct{}{}, nil | 74 | + return table, nil |
74 | } | 75 | } |
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
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/repository" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks" | ||
9 | +) | ||
10 | + | ||
11 | +type TableEditDataService struct { | ||
12 | + transactionContext *pgTransaction.TransactionContext | ||
13 | +} | ||
14 | + | ||
15 | +func NewTableEditDataService(transactionContext *pgTransaction.TransactionContext) (*TableEditDataService, error) { | ||
16 | + if transactionContext == nil { | ||
17 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
18 | + } else { | ||
19 | + return &TableEditDataService{ | ||
20 | + transactionContext: transactionContext, | ||
21 | + }, nil | ||
22 | + } | ||
23 | +} | ||
24 | + | ||
25 | +func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.EditDataRequest) (interface{}, error) { | ||
26 | + tableRepository, _ := repository.NewTableRepository(ptr.transactionContext) | ||
27 | + table, err := tableRepository.FindOne(map[string]interface{}{"tableId": request.TableId}) | ||
28 | + if err != nil { | ||
29 | + return nil, err | ||
30 | + } | ||
31 | + if table.TableType != domain.SideTable.ToString() { | ||
32 | + return nil, fmt.Errorf("副表才允许编辑数据") | ||
33 | + } | ||
34 | + //if table.TableType == domain.SubTable.ToString(){ | ||
35 | + // mainTable, err := tableRepository.FindOne(map[string]interface{}{"tableId": request.TableId}) | ||
36 | + // if err != nil { | ||
37 | + // return nil, err | ||
38 | + // } | ||
39 | + // table.SQLName = mainTable.SQLName | ||
40 | + //} | ||
41 | + | ||
42 | + for _, l := range request.AddList { | ||
43 | + ptr.add(ctx, table, l, request.Where) | ||
44 | + } | ||
45 | + for _, l := range request.RemoveList { | ||
46 | + ptr.remove(ctx, table, l, request.Where) | ||
47 | + } | ||
48 | + for _, l := range request.UpdateList { | ||
49 | + ptr.update(ctx, table, l, request.Where) | ||
50 | + } | ||
51 | + | ||
52 | + return nil, nil | ||
53 | +} | ||
54 | + | ||
55 | +func (ptr *TableEditDataService) add(ctx *domain.Context, table *domain.Table, list *domain.FieldValues, where domain.Where) error { | ||
56 | + var err error | ||
57 | + | ||
58 | + // 日志 | ||
59 | + if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &RowAddLog{ | ||
60 | + LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.RowEdit, ctx), | ||
61 | + }); err != nil { | ||
62 | + return err | ||
63 | + } | ||
64 | + | ||
65 | + // 添加记录 | ||
66 | + if err = starrocks.Insert(starrocks.DB, table.SQLName, list.FieldValues); err != nil { | ||
67 | + return err | ||
68 | + } | ||
69 | + return nil | ||
70 | +} | ||
71 | + | ||
72 | +func (ptr *TableEditDataService) remove(ctx *domain.Context, table *domain.Table, list *domain.FieldValues, where domain.Where) error { | ||
73 | + var err error | ||
74 | + | ||
75 | + // 日志 | ||
76 | + if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &RowRemoveLog{ | ||
77 | + LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.RowEdit, ctx), | ||
78 | + FieldValue: list, | ||
79 | + Where: where, | ||
80 | + }); err != nil { | ||
81 | + return err | ||
82 | + } | ||
83 | + | ||
84 | + // 删除记录 | ||
85 | + if err = starrocks.Delete(starrocks.DB, table.SQLName, list.FieldValues); err != nil { | ||
86 | + return err | ||
87 | + } | ||
88 | + return nil | ||
89 | +} | ||
90 | + | ||
91 | +func (ptr *TableEditDataService) update(ctx *domain.Context, table *domain.Table, list *domain.FieldValues, where domain.Where) error { | ||
92 | + var err error | ||
93 | + | ||
94 | + // 日志 | ||
95 | + if err = FastLog(ptr.transactionContext, domain.CommonLog, table.TableId, &RowUpdateLog{ | ||
96 | + LogEntry: domain.NewLogEntry(table.Name, table.TableType, domain.RowEdit, ctx), | ||
97 | + }); err != nil { | ||
98 | + return err | ||
99 | + } | ||
100 | + | ||
101 | + // 更新记录 | ||
102 | + if err = starrocks.Update(starrocks.DB, table.SQLName, list.FieldValues); err != nil { | ||
103 | + return err | ||
104 | + } | ||
105 | + return nil | ||
106 | +} |
@@ -38,8 +38,8 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl | @@ -38,8 +38,8 @@ func (ptr *UpdateTableStructService) UpdateTableStruct(ctx *domain.Context, tabl | ||
38 | 38 | ||
39 | fields = MappingFields(mainTable, fields) | 39 | fields = MappingFields(mainTable, fields) |
40 | reserves, deletes, adds := domain.FieldsChange(table.Fields(false), fields) | 40 | reserves, deletes, adds := domain.FieldsChange(table.Fields(false), fields) |
41 | - dataFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": 1}) | ||
42 | - manualFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": 2}) | 41 | + dataFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.MainTableField}) |
42 | + manualFields := (domain.Fields)(fields).Select(map[string]interface{}{"flag": domain.ManualField}) | ||
43 | table.DataFieldIndex = mainTable.DataFieldIndex | 43 | table.DataFieldIndex = mainTable.DataFieldIndex |
44 | table.DataFields = dataFields | 44 | table.DataFields = dataFields |
45 | table.ManualFields = manualFields | 45 | table.ManualFields = manualFields |
@@ -76,17 +76,18 @@ func MappingFields(table *domain.Table, fields []*domain.Field) []*domain.Field | @@ -76,17 +76,18 @@ func MappingFields(table *domain.Table, fields []*domain.Field) []*domain.Field | ||
76 | tableFieldsMap := (domain.Fields)(tableFields).ToMap() | 76 | tableFieldsMap := (domain.Fields)(tableFields).ToMap() |
77 | for i := range fields { | 77 | for i := range fields { |
78 | f := fields[i] | 78 | f := fields[i] |
79 | - if v, ok := tableFieldsMap[fields[i].Name]; ok { | 79 | + if v, ok := tableFieldsMap[f.Name]; ok { |
80 | fields[i].Name = v.Name | 80 | fields[i].Name = v.Name |
81 | fields[i].SQLName = v.SQLName | 81 | fields[i].SQLName = v.SQLName |
82 | fields[i].Index = v.Index | 82 | fields[i].Index = v.Index |
83 | fields[i].SQLType = v.SQLType | 83 | fields[i].SQLType = v.SQLType |
84 | - fields[i].Description = v.Description | 84 | + fields[i].Description = f.Description |
85 | fields[i].Flag = v.Flag | 85 | fields[i].Flag = v.Flag |
86 | } else { | 86 | } else { |
87 | if f.Flag == domain.ManualField && f.Index == 0 { | 87 | if f.Flag == domain.ManualField && f.Index == 0 { |
88 | table.DataFieldIndex += 1 | 88 | table.DataFieldIndex += 1 |
89 | fields[i] = DataField(f.Name, f.SQLType, domain.ManualField, table.DataFieldIndex) | 89 | fields[i] = DataField(f.Name, f.SQLType, domain.ManualField, table.DataFieldIndex) |
90 | + fields[i].Description = f.Description | ||
90 | } | 91 | } |
91 | } | 92 | } |
92 | } | 93 | } |
@@ -4,7 +4,6 @@ import ( | @@ -4,7 +4,6 @@ import ( | ||
4 | "bytes" | 4 | "bytes" |
5 | "encoding/csv" | 5 | "encoding/csv" |
6 | "fmt" | 6 | "fmt" |
7 | - "github.com/aswjh/excel" | ||
8 | "github.com/xuri/excelize/v2" | 7 | "github.com/xuri/excelize/v2" |
9 | "io" | 8 | "io" |
10 | "os" | 9 | "os" |
@@ -156,70 +155,70 @@ func NewCSVWriterTo(title []string, data [][]string) *CSVWriterTo { | @@ -156,70 +155,70 @@ func NewCSVWriterTo(title []string, data [][]string) *CSVWriterTo { | ||
156 | } | 155 | } |
157 | } | 156 | } |
158 | 157 | ||
159 | -type XlSWriterTo struct { | ||
160 | - data [][]string | ||
161 | - title []string | ||
162 | -} | ||
163 | - | ||
164 | -func (xw *XlSWriterTo) WriteTo(w io.Writer) (n int64, err error) { | ||
165 | - var file = bytes.NewBuffer(nil) | ||
166 | - err = xw.write(file) | ||
167 | - if err != nil { | ||
168 | - return 0, nil | ||
169 | - } | ||
170 | - return file.WriteTo(w) | ||
171 | -} | ||
172 | - | ||
173 | -func (xw *XlSWriterTo) Save(fileName string) error { | ||
174 | - if err := checkPath(fileName); err != nil { | ||
175 | - return err | ||
176 | - } | ||
177 | - option := excel.Option{"Visible": true, "DisplayAlerts": true, "ScreenUpdating": true} | ||
178 | - xl, err := excel.New(option) //xl, _ := excel.Open("test_excel.xls", option) | ||
179 | - if err != nil { | ||
180 | - return err | ||
181 | - } | ||
182 | - defer xl.Quit() | ||
183 | - | ||
184 | - sheet, _ := xl.Sheet(1) //xl.Sheet("sheet1") | ||
185 | - defer sheet.Release() | ||
186 | - | ||
187 | - index := 1 | ||
188 | - sheet.PutRange(excelRange(index, xw.title), toInterface(xw.title)...) | ||
189 | - for _, item := range xw.data { | ||
190 | - row := toInterface(item) | ||
191 | - index += 1 | ||
192 | - sheet.PutRange(excelRange(index, item), row) | ||
193 | - } | ||
194 | - errs := xl.SaveAs(fileName) | ||
195 | - if len(errs) > 0 { | ||
196 | - return errs[0] | ||
197 | - } | ||
198 | - return nil | ||
199 | -} | ||
200 | - | ||
201 | -func excelRange(index int, data []string) string { | ||
202 | - var begin byte = 'a' | ||
203 | - r := fmt.Sprintf("%c%d:%c%d", begin, index, begin+byte(len(data)), index) | ||
204 | - return r | ||
205 | -} | ||
206 | - | ||
207 | -func toInterface(data []string) []interface{} { | ||
208 | - row := make([]interface{}, len(data)) | ||
209 | - for i := range data { | ||
210 | - row[i] = data[i] | ||
211 | - } | ||
212 | - return row | ||
213 | -} | ||
214 | - | ||
215 | -func (xw *XlSWriterTo) write(w io.Writer) error { | ||
216 | - | ||
217 | - return nil | ||
218 | -} | ||
219 | - | ||
220 | -func NewXlSWriterTo(title []string, data [][]string) *XlSWriterTo { | ||
221 | - return &XlSWriterTo{ | ||
222 | - data: data, | ||
223 | - title: title, | ||
224 | - } | ||
225 | -} | 158 | +//type XlSWriterTo struct { |
159 | +// data [][]string | ||
160 | +// title []string | ||
161 | +//} | ||
162 | +// | ||
163 | +//func (xw *XlSWriterTo) WriteTo(w io.Writer) (n int64, err error) { | ||
164 | +// var file = bytes.NewBuffer(nil) | ||
165 | +// err = xw.write(file) | ||
166 | +// if err != nil { | ||
167 | +// return 0, nil | ||
168 | +// } | ||
169 | +// return file.WriteTo(w) | ||
170 | +//} | ||
171 | +// | ||
172 | +//func (xw *XlSWriterTo) Save(fileName string) error { | ||
173 | +// if err := checkPath(fileName); err != nil { | ||
174 | +// return err | ||
175 | +// } | ||
176 | +// option := excel.Option{"Visible": true, "DisplayAlerts": true, "ScreenUpdating": true} | ||
177 | +// xl, err := excel.New(option) //xl, _ := excel.Open("test_excel.xls", option) | ||
178 | +// if err != nil { | ||
179 | +// return err | ||
180 | +// } | ||
181 | +// defer xl.Quit() | ||
182 | +// | ||
183 | +// sheet, _ := xl.Sheet(1) //xl.Sheet("sheet1") | ||
184 | +// defer sheet.Release() | ||
185 | +// | ||
186 | +// index := 1 | ||
187 | +// sheet.PutRange(excelRange(index, xw.title), toInterface(xw.title)...) | ||
188 | +// for _, item := range xw.data { | ||
189 | +// row := toInterface(item) | ||
190 | +// index += 1 | ||
191 | +// sheet.PutRange(excelRange(index, item), row) | ||
192 | +// } | ||
193 | +// errs := xl.SaveAs(fileName) | ||
194 | +// if len(errs) > 0 { | ||
195 | +// return errs[0] | ||
196 | +// } | ||
197 | +// return nil | ||
198 | +//} | ||
199 | +// | ||
200 | +//func excelRange(index int, data []string) string { | ||
201 | +// var begin byte = 'a' | ||
202 | +// r := fmt.Sprintf("%c%d:%c%d", begin, index, begin+byte(len(data)), index) | ||
203 | +// return r | ||
204 | +//} | ||
205 | +// | ||
206 | +//func toInterface(data []string) []interface{} { | ||
207 | +// row := make([]interface{}, len(data)) | ||
208 | +// for i := range data { | ||
209 | +// row[i] = data[i] | ||
210 | +// } | ||
211 | +// return row | ||
212 | +//} | ||
213 | +// | ||
214 | +//func (xw *XlSWriterTo) write(w io.Writer) error { | ||
215 | +// | ||
216 | +// return nil | ||
217 | +//} | ||
218 | +// | ||
219 | +//func NewXlSWriterTo(title []string, data [][]string) *XlSWriterTo { | ||
220 | +// return &XlSWriterTo{ | ||
221 | +// data: data, | ||
222 | +// title: title, | ||
223 | +// } | ||
224 | +//} |
@@ -3,9 +3,13 @@ package transform | @@ -3,9 +3,13 @@ package transform | ||
3 | import ( | 3 | import ( |
4 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
5 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | 5 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" |
6 | + "strings" | ||
6 | ) | 7 | ) |
7 | 8 | ||
8 | func TransformToTableDomainModelFromPgModels(tableModel *models.Table) (*domain.Table, error) { | 9 | func TransformToTableDomainModelFromPgModels(tableModel *models.Table) (*domain.Table, error) { |
10 | + for _, f := range tableModel.DataFields { | ||
11 | + f.SQLType = strings.ToUpper(f.SQLType) | ||
12 | + } | ||
9 | return &domain.Table{ | 13 | return &domain.Table{ |
10 | TableId: tableModel.TableId, | 14 | TableId: tableModel.TableId, |
11 | TableType: tableModel.TableType, | 15 | TableType: tableModel.TableType, |
@@ -9,6 +9,7 @@ import ( | @@ -9,6 +9,7 @@ import ( | ||
9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" | 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/models" |
11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" | 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg/transform" |
12 | + "time" | ||
12 | ) | 13 | ) |
13 | 14 | ||
14 | type FileRepository struct { | 15 | type FileRepository struct { |
@@ -142,7 +143,12 @@ func (repository *FileRepository) Find(queryOptions map[string]interface{}) (int | @@ -142,7 +143,12 @@ func (repository *FileRepository) Find(queryOptions map[string]interface{}) (int | ||
142 | if v, ok := queryOptions["notInFileIds"]; ok && len(v.([]int)) > 0 { | 143 | if v, ok := queryOptions["notInFileIds"]; ok && len(v.([]int)) > 0 { |
143 | query.Where(`file_id not in (?)`, pg.In(v.([]int))) | 144 | query.Where(`file_id not in (?)`, pg.In(v.([]int))) |
144 | } | 145 | } |
145 | - | 146 | + if v, ok := queryOptions["updatedAtBegin"]; ok && !v.(time.Time).IsZero() { |
147 | + query.Where(`updated_at>?`, v.(time.Time)) | ||
148 | + } | ||
149 | + if v, ok := queryOptions["updatedAtEnd"]; ok && !v.(time.Time).IsZero() { | ||
150 | + query.Where(`updated_at<?`, v.(time.Time)) | ||
151 | + } | ||
146 | query.SetOffsetAndLimit(20) | 152 | query.SetOffsetAndLimit(20) |
147 | query.SetOrderDirect("file_id", "DESC") | 153 | query.SetOrderDirect("file_id", "DESC") |
148 | if count, err := query.SelectAndCount(); err != nil { | 154 | if count, err := query.SelectAndCount(); err != nil { |
@@ -165,7 +165,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6 | @@ -165,7 +165,7 @@ func (repository *LogRepository) Find(queryOptions map[string]interface{}) (int6 | ||
165 | } | 165 | } |
166 | 166 | ||
167 | query.SetOffsetAndLimit(20) | 167 | query.SetOffsetAndLimit(20) |
168 | - query.SetOrderDirect("log_id", "DESC") | 168 | + query.SetOrderDirect("log_id", "ASC") |
169 | if count, err := query.SelectAndCount(); err != nil { | 169 | if count, err := query.SelectAndCount(); err != nil { |
170 | return 0, logs, err | 170 | return 0, logs, err |
171 | } else { | 171 | } else { |
pkg/infrastructure/starrocks/exec.go
0 → 100644
1 | +package starrocks | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | ||
6 | + "gorm.io/gorm" | ||
7 | +) | ||
8 | + | ||
9 | +func Insert(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | ||
10 | + value := map[string]interface{}{} | ||
11 | + for _, f := range fields { | ||
12 | + if f.Field.Flag == domain.PKField && f.Value == "" { | ||
13 | + continue | ||
14 | + } | ||
15 | + value[f.Field.SQLName] = f.TypeValue() | ||
16 | + } | ||
17 | + //tx := db.Table(tableName).Create(value) | ||
18 | + //return tx.Error | ||
19 | + sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { | ||
20 | + return tx.Table(tableName).Create(value) | ||
21 | + }) | ||
22 | + tx := db.Exec(sql) | ||
23 | + return tx.Error | ||
24 | +} | ||
25 | + | ||
26 | +func Update(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | ||
27 | + value := map[string]interface{}{} | ||
28 | + var pk *domain.FieldValue | ||
29 | + for _, f := range fields { | ||
30 | + if f.Field.Flag == domain.PKField && f.Value != "" { | ||
31 | + pk = f | ||
32 | + } | ||
33 | + value[f.Field.SQLName] = f.TypeValue() | ||
34 | + } | ||
35 | + if pk == nil && pk.Value != "" && pk.TypeValue() != nil { | ||
36 | + return fmt.Errorf("主键不能为空") | ||
37 | + } | ||
38 | + //tx := db.Table(tableName).Where("? = ?", pk.Field.SQLName, pk.Value).Updates(value) | ||
39 | + //return tx.Error | ||
40 | + sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { | ||
41 | + return tx.Table(tableName).Create(value) | ||
42 | + }) | ||
43 | + tx := db.Exec(sql) | ||
44 | + return tx.Error | ||
45 | +} | ||
46 | + | ||
47 | +func Delete(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { | ||
48 | + var pk *domain.FieldValue | ||
49 | + for _, f := range fields { | ||
50 | + if f.Field.Flag == domain.PKField && f.Value != "" { | ||
51 | + pk = f | ||
52 | + } | ||
53 | + } | ||
54 | + if pk == nil { | ||
55 | + return fmt.Errorf("主键不能为空") | ||
56 | + } | ||
57 | + //tx := db.Table(tableName).Delete("? = ?", pk.Field.SQLName, pk.Value) | ||
58 | + //return tx.Error | ||
59 | + sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB { | ||
60 | + return tx.Table(tableName).Delete("? = ?", pk.Field.SQLName, pk.Value) | ||
61 | + }) | ||
62 | + tx := db.Exec(sql) | ||
63 | + return tx.Error | ||
64 | +} |
@@ -8,8 +8,8 @@ import ( | @@ -8,8 +8,8 @@ import ( | ||
8 | "gorm.io/driver/mysql" | 8 | "gorm.io/driver/mysql" |
9 | "gorm.io/gorm" | 9 | "gorm.io/gorm" |
10 | "gorm.io/gorm/logger" | 10 | "gorm.io/gorm/logger" |
11 | - rawlog "log" | ||
12 | - "os" | 11 | + //rawlog "log" |
12 | + //"os" | ||
13 | "reflect" | 13 | "reflect" |
14 | "time" | 14 | "time" |
15 | ) | 15 | ) |
@@ -19,7 +19,7 @@ var DB *gorm.DB | @@ -19,7 +19,7 @@ var DB *gorm.DB | ||
19 | func Init() error { | 19 | func Init() error { |
20 | var err error | 20 | var err error |
21 | newLogger := logger.New( | 21 | newLogger := logger.New( |
22 | - rawlog.New(os.Stdout, "\r\n", rawlog.LstdFlags), // io writer | 22 | + log.GormLogWriter{Module: "【StarRocks】"}, //rawlog.New(os.Stdout, "\r\n", rawlog.LstdFlags), // io writer |
23 | logger.Config{ | 23 | logger.Config{ |
24 | SlowThreshold: time.Second, // Slow SQL threshold | 24 | SlowThreshold: time.Second, // Slow SQL threshold |
25 | LogLevel: logger.Info, // Log level | 25 | LogLevel: logger.Info, // Log level |
pkg/infrastructure/utils/convert.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import "strconv" | ||
4 | + | ||
5 | +type NumberString string | ||
6 | + | ||
7 | +func (s NumberString) String() string { | ||
8 | + return string(s) | ||
9 | +} | ||
10 | + | ||
11 | +func (s NumberString) Int() (int, error) { | ||
12 | + v, err := strconv.Atoi(s.String()) | ||
13 | + return v, err | ||
14 | +} | ||
15 | + | ||
16 | +func (s NumberString) MustInt() int { | ||
17 | + v, _ := s.Int() | ||
18 | + return v | ||
19 | +} | ||
20 | + | ||
21 | +func (s NumberString) UInt32() (uint32, error) { | ||
22 | + v, err := strconv.Atoi(s.String()) | ||
23 | + return uint32(v), err | ||
24 | +} | ||
25 | + | ||
26 | +func (s NumberString) MustUInt32() uint32 { | ||
27 | + v, _ := s.UInt32() | ||
28 | + return v | ||
29 | +} | ||
30 | + | ||
31 | +func (s NumberString) Int64() (int64, error) { | ||
32 | + v, err := strconv.ParseInt(s.String(), 10, 64) | ||
33 | + return v, err | ||
34 | +} | ||
35 | + | ||
36 | +func (s NumberString) MustInt64() int64 { | ||
37 | + v, _ := s.Int64() | ||
38 | + return v | ||
39 | +} | ||
40 | + | ||
41 | +func (s NumberString) Float64() (float64, error) { | ||
42 | + return strconv.ParseFloat(s.String(), 64) | ||
43 | +} | ||
44 | + | ||
45 | +func (s NumberString) MustFloat64() float64 { | ||
46 | + v, _ := strconv.ParseFloat(s.String(), 64) | ||
47 | + return v | ||
48 | +} | ||
49 | + | ||
50 | +func NewNumberString(str string) NumberString { | ||
51 | + return NumberString(str) | ||
52 | +} |
pkg/log/gorm_logger.go
0 → 100644
1 | package beego | 1 | package beego |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
5 | + "github.com/beego/beego/v2/core/logs" | ||
4 | "github.com/beego/beego/v2/server/web" | 6 | "github.com/beego/beego/v2/server/web" |
7 | + "github.com/beego/beego/v2/server/web/context" | ||
5 | "github.com/linmadan/egglib-go/web/beego/filters" | 8 | "github.com/linmadan/egglib-go/web/beego/filters" |
6 | "os" | 9 | "os" |
7 | "strconv" | 10 | "strconv" |
@@ -26,7 +29,32 @@ func init() { | @@ -26,7 +29,32 @@ func init() { | ||
26 | web.BConfig.Listen.HTTPPort = port | 29 | web.BConfig.Listen.HTTPPort = port |
27 | } | 30 | } |
28 | } | 31 | } |
32 | + | ||
33 | + //https支持 | ||
34 | + web.BConfig.Listen.EnableHTTPS = true | ||
35 | + web.BConfig.Listen.HTTPSPort = 443 | ||
36 | + | ||
37 | + //进程内监控 | ||
38 | + //web.BConfig.Listen.EnableAdmin = true | ||
39 | + //web.BConfig.Listen.AdminPort = 8088 | ||
40 | + if os.Getenv("HTTPS_PORT") != "" { | ||
41 | + portStr := os.Getenv("HTTPS_PORT") | ||
42 | + if port, err := strconv.Atoi(portStr); err == nil { | ||
43 | + web.BConfig.Listen.HTTPSPort = port | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
29 | web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors()) | 47 | web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors()) |
30 | - web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger)) | 48 | + web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger)) // CreateRequestLogFilter(true) |
31 | web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) | 49 | web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) |
32 | } | 50 | } |
51 | + | ||
52 | +func CreateRequestLogFilter(console bool) func(ctx *context.Context) { | ||
53 | + return func(ctx *context.Context) { | ||
54 | + msg := fmt.Sprintf("beego | %v | %v \n %v", ctx.Input.Method(), ctx.Input.URL(), string(ctx.Input.RequestBody)) | ||
55 | + logs.Debug(msg) | ||
56 | + if console { | ||
57 | + fmt.Println(msg) | ||
58 | + } | ||
59 | + } | ||
60 | +} |
@@ -101,7 +101,7 @@ func (controller *FileController) FilePreview() { | @@ -101,7 +101,7 @@ func (controller *FileController) FilePreview() { | ||
101 | func (controller *FileController) EditDataTable() { | 101 | func (controller *FileController) EditDataTable() { |
102 | fileService := service.NewFileService(nil) | 102 | fileService := service.NewFileService(nil) |
103 | editDataTableCommand := &command.EditDataTableCommand{} | 103 | editDataTableCommand := &command.EditDataTableCommand{} |
104 | - controller.Unmarshal(editDataTableCommand) | 104 | + Must(controller.Unmarshal(editDataTableCommand)) |
105 | data, err := fileService.EditDataTable(ParseContext(controller.BaseController), editDataTableCommand) | 105 | data, err := fileService.EditDataTable(ParseContext(controller.BaseController), editDataTableCommand) |
106 | controller.Response(data, err) | 106 | controller.Response(data, err) |
107 | } | 107 | } |
@@ -42,6 +42,15 @@ func (controller *TableController) GetTable() { | @@ -42,6 +42,15 @@ func (controller *TableController) GetTable() { | ||
42 | controller.Response(data, err) | 42 | controller.Response(data, err) |
43 | } | 43 | } |
44 | 44 | ||
45 | +func (controller *TableController) PrepareTable() { | ||
46 | + tableService := service.NewTableService(nil) | ||
47 | + getTableQuery := &query.GetTableQuery{} | ||
48 | + tableId, _ := controller.GetInt("tableId") | ||
49 | + getTableQuery.TableId = tableId | ||
50 | + data, err := tableService.PrepareSubTable(getTableQuery) | ||
51 | + controller.Response(data, err) | ||
52 | +} | ||
53 | + | ||
45 | func (controller *TableController) RemoveTable() { | 54 | func (controller *TableController) RemoveTable() { |
46 | tableService := service.NewTableService(nil) | 55 | tableService := service.NewTableService(nil) |
47 | removeTableCommand := &command.RemoveTableCommand{} | 56 | removeTableCommand := &command.RemoveTableCommand{} |
@@ -63,21 +72,21 @@ func (controller *TableController) ListTable() { | @@ -63,21 +72,21 @@ func (controller *TableController) ListTable() { | ||
63 | controller.Response(data, err) | 72 | controller.Response(data, err) |
64 | } | 73 | } |
65 | 74 | ||
66 | -func (controller *TableController) SplitDataTable() { | ||
67 | - tableService := service.NewTableService(nil) | ||
68 | - splitDataTableCommand := &command.SplitDataTableCommand{} | ||
69 | - controller.Unmarshal(splitDataTableCommand) | ||
70 | - data, err := tableService.SplitDataTable(splitDataTableCommand) | ||
71 | - controller.Response(data, err) | ||
72 | -} | ||
73 | - | ||
74 | -func (controller *TableController) BatchEditSubTable() { | ||
75 | - tableService := service.NewTableService(nil) | ||
76 | - batchEditSubTableCommand := &command.BatchEditSubTableCommand{} | ||
77 | - controller.Unmarshal(batchEditSubTableCommand) | ||
78 | - data, err := tableService.BatchEditSubTable(batchEditSubTableCommand) | ||
79 | - controller.Response(data, err) | ||
80 | -} | 75 | +//func (controller *TableController) SplitDataTable() { |
76 | +// tableService := service.NewTableService(nil) | ||
77 | +// splitDataTableCommand := &command.SplitDataTableCommand{} | ||
78 | +// controller.Unmarshal(splitDataTableCommand) | ||
79 | +// data, err := tableService.SplitDataTable(splitDataTableCommand) | ||
80 | +// controller.Response(data, err) | ||
81 | +//} | ||
82 | +// | ||
83 | +//func (controller *TableController) BatchEditSubTable() { | ||
84 | +// tableService := service.NewTableService(nil) | ||
85 | +// batchEditSubTableCommand := &command.BatchEditSubTableCommand{} | ||
86 | +// controller.Unmarshal(batchEditSubTableCommand) | ||
87 | +// data, err := tableService.BatchEditSubTable(batchEditSubTableCommand) | ||
88 | +// controller.Response(data, err) | ||
89 | +//} | ||
81 | 90 | ||
82 | func (controller *TableController) CopyDataTable() { | 91 | func (controller *TableController) CopyDataTable() { |
83 | tableService := service.NewTableService(nil) | 92 | tableService := service.NewTableService(nil) |
@@ -128,17 +137,19 @@ func (controller *TableController) SearchSubTableList() { | @@ -128,17 +137,19 @@ func (controller *TableController) SearchSubTableList() { | ||
128 | 137 | ||
129 | func (controller *TableController) UpdateTableStruct() { | 138 | func (controller *TableController) UpdateTableStruct() { |
130 | tableService := service.NewTableService(nil) | 139 | tableService := service.NewTableService(nil) |
131 | - batchEditSubTableCommand := &command.UpdateTableStructCommand{} | ||
132 | - controller.Unmarshal(batchEditSubTableCommand) | ||
133 | - data, err := tableService.UpdateTableStruct(ParseContext(controller.BaseController), batchEditSubTableCommand) | 140 | + cmd := &command.UpdateTableStructCommand{} |
141 | + controller.Unmarshal(cmd) | ||
142 | + tableId, _ := controller.GetInt(":tableId") | ||
143 | + cmd.TableId = tableId | ||
144 | + data, err := tableService.UpdateTableStruct(ParseContext(controller.BaseController), cmd) | ||
134 | controller.Response(data, err) | 145 | controller.Response(data, err) |
135 | } | 146 | } |
136 | 147 | ||
137 | func (controller *TableController) AddTableStruct() { | 148 | func (controller *TableController) AddTableStruct() { |
138 | tableService := service.NewTableService(nil) | 149 | tableService := service.NewTableService(nil) |
139 | - batchEditSubTableCommand := &command.AddTableStructCommand{} | ||
140 | - controller.Unmarshal(batchEditSubTableCommand) | ||
141 | - data, err := tableService.AddTableStruct(ParseContext(controller.BaseController), batchEditSubTableCommand) | 150 | + cmd := &command.AddTableStructCommand{} |
151 | + controller.Unmarshal(cmd) | ||
152 | + data, err := tableService.AddTableStruct(ParseContext(controller.BaseController), cmd) | ||
142 | controller.Response(data, err) | 153 | controller.Response(data, err) |
143 | } | 154 | } |
144 | 155 | ||
@@ -201,3 +212,11 @@ func (controller *TableController) Preview() { | @@ -201,3 +212,11 @@ func (controller *TableController) Preview() { | ||
201 | } | 212 | } |
202 | controller.Response(data, err) | 213 | controller.Response(data, err) |
203 | } | 214 | } |
215 | + | ||
216 | +func (controller *TableController) RowEdit() { | ||
217 | + tableService := service.NewTableService(nil) | ||
218 | + cmd := &command.RowEditCommand{} | ||
219 | + Must(controller.Unmarshal(cmd)) | ||
220 | + data, err := tableService.RowEdit(ParseContext(controller.BaseController), cmd) | ||
221 | + controller.Response(data, err) | ||
222 | +} |
@@ -7,8 +7,9 @@ import ( | @@ -7,8 +7,9 @@ import ( | ||
7 | 7 | ||
8 | func init() { | 8 | func init() { |
9 | web.Router("/data/tables/", &controllers.TableController{}, "Post:CreateTable") | 9 | web.Router("/data/tables/", &controllers.TableController{}, "Post:CreateTable") |
10 | - web.Router("/data/tables/:tableId", &controllers.TableController{}, "Put:UpdateTable") | 10 | + //web.Router("/data/tables/:tableId", &controllers.TableController{}, "Put:UpdateTable") |
11 | web.Router("/data/tables/:tableId", &controllers.TableController{}, "Get:GetTable") | 11 | web.Router("/data/tables/:tableId", &controllers.TableController{}, "Get:GetTable") |
12 | + web.Router("/data/tables/prepare", &controllers.TableController{}, "Get:PrepareTable") | ||
12 | web.Router("/data/tables/:tableId", &controllers.TableController{}, "Delete:RemoveTable") | 13 | web.Router("/data/tables/:tableId", &controllers.TableController{}, "Delete:RemoveTable") |
13 | web.Router("/data/tables/", &controllers.TableController{}, "Get:ListTable") | 14 | web.Router("/data/tables/", &controllers.TableController{}, "Get:ListTable") |
14 | web.Router("/data/tables/search", &controllers.TableController{}, "Post:Search") | 15 | web.Router("/data/tables/search", &controllers.TableController{}, "Post:Search") |
@@ -16,14 +17,16 @@ func init() { | @@ -16,14 +17,16 @@ func init() { | ||
16 | web.Router("/data/tables/search-appended-list", &controllers.TableController{}, "Post:SearchAppendedList") | 17 | web.Router("/data/tables/search-appended-list", &controllers.TableController{}, "Post:SearchAppendedList") |
17 | web.Router("/data/tables/search-sub-table-list", &controllers.TableController{}, "Post:SearchSubTableList") | 18 | web.Router("/data/tables/search-sub-table-list", &controllers.TableController{}, "Post:SearchSubTableList") |
18 | 19 | ||
19 | - web.Router("/data/tables/split-data-table", &controllers.TableController{}, "Post:SplitDataTable") | ||
20 | - web.Router("/data/tables/batch-edit-sub-table", &controllers.TableController{}, "Post:BatchEditSubTable") | 20 | + //web.Router("/data/tables/split-data-table", &controllers.TableController{}, "Post:SplitDataTable") |
21 | + //web.Router("/data/tables/batch-edit-sub-table", &controllers.TableController{}, "Post:BatchEditSubTable") | ||
21 | web.Router("/data/tables/copy-data-table", &controllers.TableController{}, "Post:CopyDataTable") | 22 | web.Router("/data/tables/copy-data-table", &controllers.TableController{}, "Post:CopyDataTable") |
22 | - web.Router("/data/tables/update-table-struct", &controllers.TableController{}, "Post:UpdateTableStruct") | 23 | + web.Router("/data/tables/update-table-struct/:tableId", &controllers.TableController{}, "Put:UpdateTableStruct") |
23 | web.Router("/data/tables/add-sub-table", &controllers.TableController{}, "Post:AddTableStruct") | 24 | web.Router("/data/tables/add-sub-table", &controllers.TableController{}, "Post:AddTableStruct") |
24 | web.Router("/data/tables/export-table", &controllers.TableController{}, "Post:ExportDataTable") | 25 | web.Router("/data/tables/export-table", &controllers.TableController{}, "Post:ExportDataTable") |
25 | 26 | ||
26 | web.Router("/data/tables/table-preview", &controllers.TableController{}, "Post:TablePreview") | 27 | web.Router("/data/tables/table-preview", &controllers.TableController{}, "Post:TablePreview") |
28 | + web.Router("/data/tables/row-edit", &controllers.TableController{}, "Post:RowEdit") | ||
29 | + | ||
27 | web.Router("/data/field-optional-values", &controllers.TableController{}, "Post:FieldOptionalValues") | 30 | web.Router("/data/field-optional-values", &controllers.TableController{}, "Post:FieldOptionalValues") |
28 | 31 | ||
29 | web.Router("/business/db-table-preview", &controllers.TableController{}, "Post:DBTablePreview") | 32 | web.Router("/business/db-table-preview", &controllers.TableController{}, "Post:DBTablePreview") |
-
请 注册 或 登录 后发表评论