正在显示
24 个修改的文件
包含
235 行增加
和
42 行删除
deploy/db/db_query_script.sql
0 → 100644
| 1 | +/* | ||
| 2 | + 1. 查询依赖的查询集 | ||
| 3 | +*/ | ||
| 4 | +select * from metadata.query_sets where query_set_info->>'BindTableId' in ( | ||
| 5 | + select distinct table_id::text from ( /*element_id,table_info,table_type*/ | ||
| 6 | + select json_array_elements(to_json(table_info->'dependencyTables'))::text::int element_id,table_info,table_id,table_type | ||
| 7 | + from metadata.tables where table_info->'dependencyTables'::text <>'null' and table_type in ('SubProcess','CalculateTable') | ||
| 8 | + ) a where a.element_id in (select table_id from metadata.tables where table_type in ('MainTable','SubTable','SideTable')) | ||
| 9 | + order by table_id asc | ||
| 10 | +) and context->>'operatorId' = '22' |
| @@ -26,6 +26,7 @@ require ( | @@ -26,6 +26,7 @@ require ( | ||
| 26 | github.com/patrickmn/go-cache v2.1.0+incompatible | 26 | github.com/patrickmn/go-cache v2.1.0+incompatible |
| 27 | github.com/sergi/go-diff v1.2.0 // indirect | 27 | github.com/sergi/go-diff v1.2.0 // indirect |
| 28 | github.com/shopspring/decimal v1.3.1 | 28 | github.com/shopspring/decimal v1.3.1 |
| 29 | + github.com/silenceper/wechat/v2 v2.1.4 // indirect | ||
| 29 | github.com/smartystreets/goconvey v1.7.2 // indirect | 30 | github.com/smartystreets/goconvey v1.7.2 // indirect |
| 30 | github.com/stretchr/testify v1.7.1 | 31 | github.com/stretchr/testify v1.7.1 |
| 31 | github.com/valyala/fasthttp v1.38.0 // indirect | 32 | github.com/valyala/fasthttp v1.38.0 // indirect |
| @@ -46,6 +47,6 @@ require ( | @@ -46,6 +47,6 @@ require ( | ||
| 46 | replace ( | 47 | replace ( |
| 47 | github.com/extrame/xls v0.0.1 => github.com/tiptok/xls v1.0.1 | 48 | github.com/extrame/xls v0.0.1 => github.com/tiptok/xls v1.0.1 |
| 48 | //github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 | 49 | //github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1 |
| 49 | - github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v1.0.0 | 50 | + github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v1.0.2 |
| 50 | 51 | ||
| 51 | ) | 52 | ) |
| @@ -19,10 +19,16 @@ type CreateFileCommand struct { | @@ -19,10 +19,16 @@ type CreateFileCommand struct { | ||
| 19 | FileSize int `cname:"文件大小" json:"fileSize" valid:"Required"` | 19 | FileSize int `cname:"文件大小" json:"fileSize" valid:"Required"` |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | +var MaxFileSize = 50 * 1024 * 1024 | ||
| 23 | + | ||
| 22 | func (createFileCommand *CreateFileCommand) Valid(validation *validation.Validation) { | 24 | func (createFileCommand *CreateFileCommand) Valid(validation *validation.Validation) { |
| 23 | ext := filepath.Ext(createFileCommand.Name) | 25 | ext := filepath.Ext(createFileCommand.Name) |
| 24 | if !(ext == domain.XLS || ext == domain.XLSX) { | 26 | if !(ext == domain.XLS || ext == domain.XLSX) { |
| 25 | - validation.Error(fmt.Sprintf("仅支持文件格式 xls 、 xlsx")) | 27 | + validation.Error("仅支持文件格式 xls 、 xlsx") |
| 28 | + return | ||
| 29 | + } | ||
| 30 | + if createFileCommand.FileSize > 0 && createFileCommand.FileSize > MaxFileSize { | ||
| 31 | + validation.Error("文件大小超过50M") | ||
| 26 | return | 32 | return |
| 27 | } | 33 | } |
| 28 | } | 34 | } |
| @@ -101,6 +101,9 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable | @@ -101,6 +101,9 @@ func (fileService *FileService) EditDataTable(ctx *domain.Context, editDataTable | ||
| 101 | if len(editDataTableCommand.ProcessFields) == 0 { | 101 | if len(editDataTableCommand.ProcessFields) == 0 { |
| 102 | return nil, factory.FastError(fmt.Errorf("请至少选择一个数据列")) | 102 | return nil, factory.FastError(fmt.Errorf("请至少选择一个数据列")) |
| 103 | } | 103 | } |
| 104 | + if editDataTableCommand.Action == "remove-column" && len(temporaryFile.Fields) == len(editDataTableCommand.ProcessFields) { | ||
| 105 | + return nil, factory.FastError(fmt.Errorf("请至少保留一个数据列")) | ||
| 106 | + } | ||
| 104 | // allowAction := func(fields []*domain.Field, action string) error { | 107 | // allowAction := func(fields []*domain.Field, action string) error { |
| 105 | // for _, f := range fields { | 108 | // for _, f := range fields { |
| 106 | // if f.SQLType != string(domain.String) && | 109 | // if f.SQLType != string(domain.String) && |
| @@ -61,6 +61,12 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman | @@ -61,6 +61,12 @@ func (fileService *FileService) CreateFile(ctx *domain.Context, createFileComman | ||
| 61 | oldFile.FileInfo = fileInfo | 61 | oldFile.FileInfo = fileInfo |
| 62 | oldFile.UpdatedAt = time.Now() | 62 | oldFile.UpdatedAt = time.Now() |
| 63 | newFile = oldFile | 63 | newFile = oldFile |
| 64 | + | ||
| 65 | + if err = factory.FastLog(transactionContext, domain.CommonLog, oldFile.FileId, &domainService.FileReplaceLog{ | ||
| 66 | + LogEntry: domain.NewLogEntry(oldFile.FileInfo.Name, domain.SourceFile.ToString(), domain.FileUpload, ctx), | ||
| 67 | + }); err != nil { | ||
| 68 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 69 | + } | ||
| 64 | } | 70 | } |
| 65 | 71 | ||
| 66 | file, err := fileRepository.Save(newFile) | 72 | file, err := fileRepository.Save(newFile) |
| @@ -18,7 +18,10 @@ type AddTableStructCommand struct { | @@ -18,7 +18,10 @@ type AddTableStructCommand struct { | ||
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | func (updateTableCommand *AddTableStructCommand) Valid(validation *validation.Validation) { | 20 | func (updateTableCommand *AddTableStructCommand) Valid(validation *validation.Validation) { |
| 21 | - | 21 | + if len(updateTableCommand.Fields) == 0 { |
| 22 | + validation.Error("请选择字段") | ||
| 23 | + return | ||
| 24 | + } | ||
| 22 | } | 25 | } |
| 23 | 26 | ||
| 24 | func (updateTableCommand *AddTableStructCommand) ValidateCommand() error { | 27 | func (updateTableCommand *AddTableStructCommand) ValidateCommand() error { |
| @@ -20,9 +20,9 @@ type TablePreviewCommand struct { | @@ -20,9 +20,9 @@ type TablePreviewCommand struct { | ||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | func (cmd *TablePreviewCommand) Valid(validation *validation.Validation) { | 22 | func (cmd *TablePreviewCommand) Valid(validation *validation.Validation) { |
| 23 | - if cmd.UseCache && cmd.PageSize==0{ | 23 | + if cmd.UseCache && cmd.PageSize == 0 { |
| 24 | cmd.PageNumber = 1 | 24 | cmd.PageNumber = 1 |
| 25 | - cmd.PageSize = 10000 //默认缓存前10000条 | 25 | + cmd.PageSize = 30000 //默认缓存前30000条 |
| 26 | } | 26 | } |
| 27 | if cmd.PageSize > 0 { | 27 | if cmd.PageSize > 0 { |
| 28 | cmd.Where.PageNumber = cmd.PageNumber | 28 | cmd.Where.PageNumber = cmd.PageNumber |
| @@ -18,7 +18,10 @@ type UpdateTableStructCommand struct { | @@ -18,7 +18,10 @@ type UpdateTableStructCommand struct { | ||
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | func (updateTableCommand *UpdateTableStructCommand) Valid(validation *validation.Validation) { | 20 | func (updateTableCommand *UpdateTableStructCommand) Valid(validation *validation.Validation) { |
| 21 | - | 21 | + if len(updateTableCommand.Fields) == 0 { |
| 22 | + validation.Error("请选择字段") | ||
| 23 | + return | ||
| 24 | + } | ||
| 22 | } | 25 | } |
| 23 | 26 | ||
| 24 | func (updateTableCommand *UpdateTableStructCommand) ValidateCommand() error { | 27 | func (updateTableCommand *UpdateTableStructCommand) ValidateCommand() error { |
| @@ -24,6 +24,7 @@ var ( | @@ -24,6 +24,7 @@ var ( | ||
| 24 | DeleteTable OperationType = "DeleteTable" // 表删除 | 24 | DeleteTable OperationType = "DeleteTable" // 表删除 |
| 25 | FileUpload OperationType = "FileUpload" // 文件上传 | 25 | FileUpload OperationType = "FileUpload" // 文件上传 |
| 26 | FileVerify OperationType = "FileVerify" // 文件校验 | 26 | FileVerify OperationType = "FileVerify" // 文件校验 |
| 27 | + FileReplace OperationType = "FileReplace" // 文件替换 | ||
| 27 | 28 | ||
| 28 | ExcelTableEdit OperationType = "ExcelTableEdit" // 文档表格编辑 | 29 | ExcelTableEdit OperationType = "ExcelTableEdit" // 文档表格编辑 |
| 29 | 30 | ||
| @@ -58,6 +59,7 @@ var OperationTypeMap = map[string]string{ | @@ -58,6 +59,7 @@ var OperationTypeMap = map[string]string{ | ||
| 58 | DeleteTable.ToString(): "表删除", | 59 | DeleteTable.ToString(): "表删除", |
| 59 | FileUpload.ToString(): "文件上传", | 60 | FileUpload.ToString(): "文件上传", |
| 60 | FileVerify.ToString(): "文件校验", | 61 | FileVerify.ToString(): "文件校验", |
| 62 | + FileReplace.ToString(): "文件覆盖", | ||
| 61 | ExcelTableEdit.ToString(): "文档表格编辑", | 63 | ExcelTableEdit.ToString(): "文档表格编辑", |
| 62 | 64 | ||
| 63 | CreateSchema.ToString(): "新增方案", | 65 | CreateSchema.ToString(): "新增方案", |
pkg/domain/enums_error.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +const ( | ||
| 4 | + InvalidAccessToken = 901 | ||
| 5 | + InvalidRefreshToken = 902 | ||
| 6 | + InvalidSign = 903 | ||
| 7 | + InvalidClientId = 904 | ||
| 8 | + InvalidUUid = 905 | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +var CodeMsg = map[int]string{ | ||
| 12 | + InvalidAccessToken: "access token 过期或无效,需刷新令牌", | ||
| 13 | + InvalidRefreshToken: "过期或失效,需重新进行登录认证操作", //refresh token | ||
| 14 | + InvalidSign: "sign 签名无效,需重新登录手机 APP", | ||
| 15 | + InvalidClientId: "client id 或 client secret 无效,需强制更新手机 APP", | ||
| 16 | + InvalidUUid: "uuid 无效", | ||
| 17 | +} |
| @@ -273,9 +273,11 @@ func RoundFieldValue(f *Field, v string) string { | @@ -273,9 +273,11 @@ func RoundFieldValue(f *Field, v string) string { | ||
| 273 | return utils.AssertString(fv) //fmt.Sprintf("%v", fv) | 273 | return utils.AssertString(fv) //fmt.Sprintf("%v", fv) |
| 274 | } | 274 | } |
| 275 | // TODO:计算表 Count(日期)类型是日期类型,0 的话下面日期解析成当前时间,计算表类型需要修改 | 275 | // TODO:计算表 Count(日期)类型是日期类型,0 的话下面日期解析成当前时间,计算表类型需要修改 |
| 276 | + if f.SQLType == Datetime.ToString() || f.SQLType == Date.ToString() { | ||
| 276 | if fv, err := strconv.ParseFloat(v, 64); err == nil { | 277 | if fv, err := strconv.ParseFloat(v, 64); err == nil { |
| 277 | return utils.AssertString(fv) | 278 | return utils.AssertString(fv) |
| 278 | } | 279 | } |
| 280 | + } | ||
| 279 | if f.SQLType == Datetime.ToString() { | 281 | if f.SQLType == Datetime.ToString() { |
| 280 | fv, err := xtime.Parse(v) | 282 | fv, err := xtime.Parse(v) |
| 281 | if err != nil { | 283 | if err != nil { |
| @@ -47,3 +47,20 @@ func (gateway *ApiAuthLib) MeInfo(param RequestUserMeQuery) (*DataUserMe, error) | @@ -47,3 +47,20 @@ func (gateway *ApiAuthLib) MeInfo(param RequestUserMeQuery) (*DataUserMe, error) | ||
| 47 | } | 47 | } |
| 48 | return &data, nil | 48 | return &data, nil |
| 49 | } | 49 | } |
| 50 | + | ||
| 51 | +func (gateway *ApiAuthLib) LoginCheck(param RequestLoginCheck) (*DataLoginCheck, error) { | ||
| 52 | + url := gateway.Host() + "/v1/login/check?token=" + param.Token | ||
| 53 | + method := "get" | ||
| 54 | + var data DataLoginCheck | ||
| 55 | + err := gateway.FastDoRequest(url, method, param, &data, api.WithHeader(gateway.DefaultHeader())) | ||
| 56 | + if errCodeMsg, ok := err.(api.ErrCodeMsg); ok { | ||
| 57 | + return &DataLoginCheck{ | ||
| 58 | + Code: errCodeMsg.Code, | ||
| 59 | + Msg: errCodeMsg.Msg, | ||
| 60 | + }, nil | ||
| 61 | + } | ||
| 62 | + if err != nil { | ||
| 63 | + return nil, err | ||
| 64 | + } | ||
| 65 | + return &data, nil | ||
| 66 | +} |
| @@ -42,3 +42,11 @@ type DataUserMe struct { | @@ -42,3 +42,11 @@ type DataUserMe struct { | ||
| 42 | Types string `json:"types"` | 42 | Types string `json:"types"` |
| 43 | } `json:"menus"` | 43 | } `json:"menus"` |
| 44 | } | 44 | } |
| 45 | + | ||
| 46 | +type RequestLoginCheck struct { | ||
| 47 | + Token string | ||
| 48 | +} | ||
| 49 | +type DataLoginCheck struct { | ||
| 50 | + Code int `json:"code"` | ||
| 51 | + Msg string `json:"msg"` | ||
| 52 | +} |
| @@ -77,6 +77,7 @@ type ( | @@ -77,6 +77,7 @@ type ( | ||
| 77 | FieldSchema FieldSchema `json:"fieldSchema"` | 77 | FieldSchema FieldSchema `json:"fieldSchema"` |
| 78 | // 字段新的英文名称(3.汇总集4.计算项中对应的新字段名称) | 78 | // 字段新的英文名称(3.汇总集4.计算项中对应的新字段名称) |
| 79 | GroupFieldName string `json:"groupFieldName"` | 79 | GroupFieldName string `json:"groupFieldName"` |
| 80 | + CalculateExpression string `json:"calculateExpression"` | ||
| 80 | } | 81 | } |
| 81 | ) | 82 | ) |
| 82 | 83 | ||
| @@ -207,6 +208,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon | @@ -207,6 +208,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon | ||
| 207 | res.FormulaGroupFields = append(res.FormulaGroupFields, &FormulaGroupField{ | 208 | res.FormulaGroupFields = append(res.FormulaGroupFields, &FormulaGroupField{ |
| 208 | DatabaseTableName: queryComponent.MasterTable.SQLName, | 209 | DatabaseTableName: queryComponent.MasterTable.SQLName, |
| 209 | FieldSchema: NewFieldSchemaFromField(f.Field), | 210 | FieldSchema: NewFieldSchemaFromField(f.Field), |
| 211 | + CalculateExpression: f.Expr.ExprSql, | ||
| 210 | GroupFieldName: tableField.SQLName, | 212 | GroupFieldName: tableField.SQLName, |
| 211 | }) | 213 | }) |
| 212 | } | 214 | } |
| @@ -82,6 +82,15 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | @@ -82,6 +82,15 @@ func (ptr *FlushDataTableService) flushSourceFile(ctx *domain.Context, table *do | ||
| 82 | if err != nil { | 82 | if err != nil { |
| 83 | return err | 83 | return err |
| 84 | } | 84 | } |
| 85 | + if len(files) > 0 { | ||
| 86 | + for _, existFile := range files { | ||
| 87 | + if err = FastLog(ptr.transactionContext, domain.CommonLog, file.FileId, &FileReplaceLog{ | ||
| 88 | + LogEntry: domain.NewLogEntry(existFile.FileInfo.Name, domain.VerifiedFile.ToString(), domain.FileUpload, ctx), | ||
| 89 | + }); err != nil { | ||
| 90 | + return err | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + } | ||
| 85 | deleteFileService, _ := NewDeleteFileService(ptr.transactionContext) | 94 | deleteFileService, _ := NewDeleteFileService(ptr.transactionContext) |
| 86 | if err = deleteFileService.DeleteFiles(ctx, files...); err != nil { | 95 | if err = deleteFileService.DeleteFiles(ctx, files...); err != nil { |
| 87 | return err | 96 | return err |
| @@ -127,6 +127,15 @@ func (l *FileVerifyLog) Content() string { | @@ -127,6 +127,15 @@ func (l *FileVerifyLog) Content() string { | ||
| 127 | return msg | 127 | return msg |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | +// FileReplaceLog 1.1文件已被覆盖 | ||
| 131 | +type FileReplaceLog struct { | ||
| 132 | + domain.LogEntry | ||
| 133 | +} | ||
| 134 | + | ||
| 135 | +func (l *FileReplaceLog) Content() string { | ||
| 136 | + return fmt.Sprintf("该文件已被覆盖") | ||
| 137 | +} | ||
| 138 | + | ||
| 130 | // GenerateMainTableLog 3.主表生成日志 | 139 | // GenerateMainTableLog 3.主表生成日志 |
| 131 | type GenerateMainTableLog struct { | 140 | type GenerateMainTableLog struct { |
| 132 | domain.LogEntry | 141 | domain.LogEntry |
| @@ -686,6 +686,20 @@ func aggregationHasEdit(ctx *domain.Context, querySet *domain.QuerySet, queryCom | @@ -686,6 +686,20 @@ func aggregationHasEdit(ctx *domain.Context, querySet *domain.QuerySet, queryCom | ||
| 686 | } | 686 | } |
| 687 | 687 | ||
| 688 | func queryComponentsHasEdit(ctx *domain.Context, querySet *domain.QuerySet, queryComponents []*domain.QueryComponent) bool { | 688 | func queryComponentsHasEdit(ctx *domain.Context, querySet *domain.QuerySet, queryComponents []*domain.QueryComponent) bool { |
| 689 | + if len(querySet.QueryComponents) != len(queryComponents) { | ||
| 690 | + return true | ||
| 691 | + } | ||
| 692 | + for i := range querySet.QueryComponents { | ||
| 693 | + if querySet.QueryComponents[i].MasterTable == nil || queryComponents[i].MasterTable == nil { | ||
| 694 | + continue | ||
| 695 | + } | ||
| 696 | + if querySet.QueryComponents[i].MasterTable.TableId != queryComponents[i].MasterTable.TableId { | ||
| 697 | + return true | ||
| 698 | + } | ||
| 699 | + if len(querySet.QueryComponents[i].MasterTable.Fields) != len(queryComponents[i].MasterTable.Fields) { | ||
| 700 | + return true | ||
| 701 | + } | ||
| 702 | + } | ||
| 689 | logs := selectsEditLog(ctx, querySet, queryComponents) | 703 | logs := selectsEditLog(ctx, querySet, queryComponents) |
| 690 | if len(logs) > 0 { | 704 | if len(logs) > 0 { |
| 691 | return true | 705 | return true |
| @@ -445,7 +445,7 @@ func (d *DataLayoutDataTable) Expand(cell *domain.LayoutCell, length int) error | @@ -445,7 +445,7 @@ func (d *DataLayoutDataTable) Expand(cell *domain.LayoutCell, length int) error | ||
| 445 | if expandLength < length { | 445 | if expandLength < length { |
| 446 | expandLength = length | 446 | expandLength = length |
| 447 | } | 447 | } |
| 448 | - if d.MaxX+expandLength > MaxExpandNum { | 448 | + if d.MaxX+expandLength > MaxExpandNum+DefaultExpandNum { |
| 449 | return fmt.Errorf("布局元素超过限制 %d", MaxExpandNum) | 449 | return fmt.Errorf("布局元素超过限制 %d", MaxExpandNum) |
| 450 | } | 450 | } |
| 451 | copyData := make([][]string, d.MaxX+length) | 451 | copyData := make([][]string, d.MaxX+length) |
| @@ -171,7 +171,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{}) | @@ -171,7 +171,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{}) | ||
| 171 | query.Where("query_set_info->'BindTableId' in (?)", pg.In(utils.ToArrayString(v.([]int)))) | 171 | query.Where("query_set_info->'BindTableId' in (?)", pg.In(utils.ToArrayString(v.([]int)))) |
| 172 | } | 172 | } |
| 173 | if v, ok := queryOptions["sortByName"]; ok && len(v.(string)) > 0 { | 173 | if v, ok := queryOptions["sortByName"]; ok && len(v.(string)) > 0 { |
| 174 | - query.SetOrderDirect("pin_name", v.(string)) | 174 | + query.SetOrderDirect("name", v.(string))//pin_name |
| 175 | } else if v, ok := queryOptions["sortByTime"]; ok && len(v.(string)) > 0 { | 175 | } else if v, ok := queryOptions["sortByTime"]; ok && len(v.(string)) > 0 { |
| 176 | query.SetOrderDirect("created_at", v.(string)) | 176 | query.SetOrderDirect("created_at", v.(string)) |
| 177 | } else { | 177 | } else { |
| @@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
| 8 | "github.com/linmadan/egglib-go/web/beego/filters" | 8 | "github.com/linmadan/egglib-go/web/beego/filters" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" | 9 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant" |
| 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" | 10 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" |
| 11 | + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/authlib" | ||
| 11 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/controllers" | 12 | "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/controllers" |
| 12 | "net/http" | 13 | "net/http" |
| 13 | "os" | 14 | "os" |
| @@ -76,6 +77,9 @@ func CreateRequestLogFilter(console bool) func(ctx *context.Context) { | @@ -76,6 +77,9 @@ func CreateRequestLogFilter(console bool) func(ctx *context.Context) { | ||
| 76 | } | 77 | } |
| 77 | 78 | ||
| 78 | func JwtFilter() func(ctx *context.Context) { | 79 | func JwtFilter() func(ctx *context.Context) { |
| 80 | + authLib := authlib.NewApiAuthLib(constant.AUTH_SERVER_HOST) | ||
| 81 | + authLib.BaseServiceGateway.ConnectTimeout = 200 * time.Millisecond | ||
| 82 | + authLib.BaseServiceGateway.ReadWriteTimeout = 200 * time.Millisecond | ||
| 79 | return func(ctx *context.Context) { | 83 | return func(ctx *context.Context) { |
| 80 | //token := ctx.Request.Header.Get("Authorization") | 84 | //token := ctx.Request.Header.Get("Authorization") |
| 81 | token := ctx.Request.Header.Get("x-mmm-accesstoken") | 85 | token := ctx.Request.Header.Get("x-mmm-accesstoken") |
| @@ -85,17 +89,35 @@ func JwtFilter() func(ctx *context.Context) { | @@ -85,17 +89,35 @@ func JwtFilter() func(ctx *context.Context) { | ||
| 85 | err := userToken.ParseToken(token) | 89 | err := userToken.ParseToken(token) |
| 86 | if err != nil { | 90 | if err != nil { |
| 87 | ctx.Output.SetStatus(http.StatusOK) | 91 | ctx.Output.SetStatus(http.StatusOK) |
| 88 | - ctx.Output.JSON(map[string]interface{}{ | ||
| 89 | - "msg": "token 过期或无效,需刷新令牌", | ||
| 90 | - "code": 901, | ||
| 91 | - "data": struct{}{}, | ||
| 92 | - }, false, false) | 92 | + ctx.Output.JSON(WithCodeMsgResponse(domain.InvalidRefreshToken), false, false) |
| 93 | + return | ||
| 94 | + } | ||
| 95 | + if userToken.UserId > 0 && userToken.CompanyId > 0 { | ||
| 96 | + loginCheckResponse, _ := authLib.LoginCheck(authlib.RequestLoginCheck{Token: token}) | ||
| 97 | + if loginCheckResponse != nil && loginCheckResponse.Code == 901 { | ||
| 98 | + ctx.Output.SetStatus(http.StatusOK) | ||
| 99 | + ctx.Output.JSON(WithCodeMsgResponse(domain.InvalidRefreshToken), false, false) | ||
| 93 | return | 100 | return |
| 94 | } | 101 | } |
| 102 | + } | ||
| 95 | ctx.Input.SetData("UserToken", userToken) | 103 | ctx.Input.SetData("UserToken", userToken) |
| 104 | + ctx.Input.SetData("Accesstoken", token) | ||
| 96 | } | 105 | } |
| 97 | } | 106 | } |
| 98 | } | 107 | } |
| 108 | + | ||
| 109 | +func WithCodeMsgResponse(code int) map[string]interface{} { | ||
| 110 | + msg := "token 过期或无效,需刷新令牌" | ||
| 111 | + if codeMsg, ok := domain.CodeMsg[code]; ok { | ||
| 112 | + msg = codeMsg | ||
| 113 | + } | ||
| 114 | + return map[string]interface{}{ | ||
| 115 | + "msg": msg, | ||
| 116 | + "code": code, | ||
| 117 | + "data": struct{}{}, | ||
| 118 | + } | ||
| 119 | +} | ||
| 120 | + | ||
| 99 | func RequestCostBefore() func(ctx *context.Context) { | 121 | func RequestCostBefore() func(ctx *context.Context) { |
| 100 | return func(ctx *context.Context) { | 122 | return func(ctx *context.Context) { |
| 101 | ctx.Input.SetData("cost-begin", time.Now().UnixMilli()) | 123 | ctx.Input.SetData("cost-begin", time.Now().UnixMilli()) |
| @@ -57,7 +57,11 @@ func ParseContext(c beego.BaseController) *domain.Context { | @@ -57,7 +57,11 @@ func ParseContext(c beego.BaseController) *domain.Context { | ||
| 57 | v := cacheItem.(*authlib.DataUserMe) | 57 | v := cacheItem.(*authlib.DataUserMe) |
| 58 | userName = v.User.NickName | 58 | userName = v.User.NickName |
| 59 | } else { | 59 | } else { |
| 60 | - requestToken, _ := userToken.GenerateToken() | 60 | + //requestToken, _ := userToken.GenerateToken() |
| 61 | + requestToken, ok := c.Ctx.Input.GetData("Accesstoken").(string) | ||
| 62 | + if !ok { | ||
| 63 | + goto END | ||
| 64 | + } | ||
| 61 | authLib := authlib.NewApiAuthLib(constant.AUTH_SERVER_HOST).WithToken(requestToken) | 65 | authLib := authlib.NewApiAuthLib(constant.AUTH_SERVER_HOST).WithToken(requestToken) |
| 62 | userInfo, err := authLib.MeInfo(authlib.RequestUserMeQuery{ | 66 | userInfo, err := authLib.MeInfo(authlib.RequestUserMeQuery{ |
| 63 | UserId: int(userToken.UserId), | 67 | UserId: int(userToken.UserId), |
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + _ "embed" | ||
| 5 | + "github.com/linmadan/egglib-go/core/application" | ||
| 6 | + "github.com/linmadan/egglib-go/utils/json" | ||
| 7 | + "strings" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +//go:embed errors.txt | ||
| 11 | +var errorsData []byte | ||
| 12 | + | ||
| 13 | +type CommErrorResolver struct { | ||
| 14 | + // TODO:LRU latest error list | ||
| 15 | + ErrorMapping map[string]string `json:"errorMapping"` | ||
| 16 | + errMapping map[string]error `json:"errorMapping"` | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (r *CommErrorResolver) Resolve(err error) error { | ||
| 20 | + if err == nil { | ||
| 21 | + return nil | ||
| 22 | + } | ||
| 23 | + errMsg := err.Error() | ||
| 24 | + if r.errMapping == nil { | ||
| 25 | + return err | ||
| 26 | + } | ||
| 27 | + if v, ok := r.errMapping[errMsg]; ok { | ||
| 28 | + return v | ||
| 29 | + } | ||
| 30 | + for k, v := range r.errMapping { | ||
| 31 | + if strings.Contains(errMsg, k) { | ||
| 32 | + return v | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + return err | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +func NewCommErrorResolver() (*CommErrorResolver, error) { | ||
| 39 | + obj := &CommErrorResolver{errMapping: make(map[string]error)} | ||
| 40 | + err := json.Unmarshal(errorsData, obj) | ||
| 41 | + if err != nil { | ||
| 42 | + return nil, err | ||
| 43 | + } | ||
| 44 | + for k, v := range obj.ErrorMapping { | ||
| 45 | + obj.errMapping[k] = application.ThrowError(application.INTERNAL_SERVER_ERROR, v) | ||
| 46 | + } | ||
| 47 | + return obj, nil | ||
| 48 | +} |
pkg/port/beego/controllers/errors.txt
0 → 100644
| @@ -6,37 +6,39 @@ import ( | @@ -6,37 +6,39 @@ import ( | ||
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | func init() { | 8 | func init() { |
| 9 | - web.Router("/data/tables/", &controllers.TableController{}, "Post:CreateTable") | ||
| 10 | - //web.Router("/data/tables/:tableId", &controllers.TableController{}, "Put:UpdateTable") | ||
| 11 | - web.Router("/data/tables/:tableId", &controllers.TableController{}, "Get:GetTable") | ||
| 12 | - web.Router("/data/tables/prepare", &controllers.TableController{}, "Get:PrepareTable") | ||
| 13 | - web.Router("/data/tables/:tableId", &controllers.TableController{}, "Delete:RemoveTable") | ||
| 14 | - web.Router("/data/tables/", &controllers.TableController{}, "Get:ListTable") | ||
| 15 | - web.Router("/data/tables/search", &controllers.TableController{}, "Post:Search") | ||
| 16 | - web.Router("/data/tables/relation-graph", &controllers.TableController{}, "Post:RelationGraph") | ||
| 17 | - web.Router("/data/tables/apply-on", &controllers.TableController{}, "Post:ApplyOn") | ||
| 18 | - web.Router("/data/tables/valid-expr-sql", &controllers.TableController{}, "Post:ValidExprSql") | ||
| 19 | - web.Router("/data/tables/check", &controllers.TableController{}, "Post:CheckRowDuplicate") | ||
| 20 | - web.Router("/data/tables/check-row-value-duplicate", &controllers.TableController{}, "Post:CheckRowValueDuplicate") | ||
| 21 | - web.Router("/data/tables/search-appended-list", &controllers.TableController{}, "Post:SearchAppendedList") | ||
| 22 | - web.Router("/data/tables/search-sub-table-list", &controllers.TableController{}, "Post:SearchSubTableList") | ||
| 23 | - web.Router("/data/tables/search-query-set-tables", &controllers.TableController{}, "Post:SearchQuerySetTables") | ||
| 24 | - web.Router("/data/tables/dependency-graph", &controllers.TableController{}, "Post:DependencyGraph") | 9 | + tableController := &controllers.TableController{} |
| 10 | + tableController.BaseController.ErrorResolver, _ = controllers.NewCommErrorResolver() | ||
| 11 | + web.Router("/data/tables/", tableController, "Post:CreateTable") | ||
| 12 | + //web.Router("/data/tables/:tableId", tableController, "Put:UpdateTable") | ||
| 13 | + web.Router("/data/tables/:tableId", tableController, "Get:GetTable") | ||
| 14 | + web.Router("/data/tables/prepare", tableController, "Get:PrepareTable") | ||
| 15 | + web.Router("/data/tables/:tableId", tableController, "Delete:RemoveTable") | ||
| 16 | + web.Router("/data/tables/", tableController, "Get:ListTable") | ||
| 17 | + web.Router("/data/tables/search", tableController, "Post:Search") | ||
| 18 | + web.Router("/data/tables/relation-graph", tableController, "Post:RelationGraph") | ||
| 19 | + web.Router("/data/tables/apply-on", tableController, "Post:ApplyOn") | ||
| 20 | + web.Router("/data/tables/valid-expr-sql", tableController, "Post:ValidExprSql") | ||
| 21 | + web.Router("/data/tables/check", tableController, "Post:CheckRowDuplicate") | ||
| 22 | + web.Router("/data/tables/check-row-value-duplicate", tableController, "Post:CheckRowValueDuplicate") | ||
| 23 | + web.Router("/data/tables/search-appended-list", tableController, "Post:SearchAppendedList") | ||
| 24 | + web.Router("/data/tables/search-sub-table-list", tableController, "Post:SearchSubTableList") | ||
| 25 | + web.Router("/data/tables/search-query-set-tables", tableController, "Post:SearchQuerySetTables") | ||
| 26 | + web.Router("/data/tables/dependency-graph", tableController, "Post:DependencyGraph") | ||
| 25 | 27 | ||
| 26 | - //web.Router("/data/tables/split-data-table", &controllers.TableController{}, "Post:SplitDataTable") | ||
| 27 | - //web.Router("/data/tables/batch-edit-sub-table", &controllers.TableController{}, "Post:BatchEditSubTable") | ||
| 28 | - web.Router("/data/tables/copy-data-table", &controllers.TableController{}, "Post:CopyDataTable") | ||
| 29 | - web.Router("/data/tables/update-table-struct/:tableId", &controllers.TableController{}, "Put:UpdateTableStruct") | ||
| 30 | - web.Router("/data/tables/add-sub-table", &controllers.TableController{}, "Post:AddTableStruct") | ||
| 31 | - web.Router("/data/tables/export-table", &controllers.TableController{}, "Post:ExportDataTable") | 28 | + //web.Router("/data/tables/split-data-table", tableController, "Post:SplitDataTable") |
| 29 | + //web.Router("/data/tables/batch-edit-sub-table", tableController, "Post:BatchEditSubTable") | ||
| 30 | + web.Router("/data/tables/copy-data-table", tableController, "Post:CopyDataTable") | ||
| 31 | + web.Router("/data/tables/update-table-struct/:tableId", tableController, "Put:UpdateTableStruct") | ||
| 32 | + web.Router("/data/tables/add-sub-table", tableController, "Post:AddTableStruct") | ||
| 33 | + web.Router("/data/tables/export-table", tableController, "Post:ExportDataTable") | ||
| 32 | 34 | ||
| 33 | - web.Router("/data/tables/table-preview", &controllers.TableController{}, "Post:TablePreview") | ||
| 34 | - web.Router("/data/tables/row-edit", &controllers.TableController{}, "Post:RowEdit") | 35 | + web.Router("/data/tables/table-preview", tableController, "Post:TablePreview") |
| 36 | + web.Router("/data/tables/row-edit", tableController, "Post:RowEdit") | ||
| 35 | 37 | ||
| 36 | - web.Router("/data/field-optional-values", &controllers.TableController{}, "Post:FieldOptionalValues") | ||
| 37 | - web.Router("/data/table-object-search", &controllers.TableController{}, "Post:TableObjectSearch") | 38 | + web.Router("/data/field-optional-values", tableController, "Post:FieldOptionalValues") |
| 39 | + web.Router("/data/table-object-search", tableController, "Post:TableObjectSearch") | ||
| 38 | 40 | ||
| 39 | - web.Router("/business/db-table-preview", &controllers.TableController{}, "Post:DBTablePreview") | ||
| 40 | - web.Router("/data/table-preview", &controllers.TableController{}, "Post:Preview") | 41 | + web.Router("/business/db-table-preview", tableController, "Post:DBTablePreview") |
| 42 | + web.Router("/data/table-preview", tableController, "Post:Preview") | ||
| 41 | 43 | ||
| 42 | } | 44 | } |
-
请 注册 或 登录 后发表评论