作者 yangfu

feat: error resolver

/*
1. 查询依赖的查询集
*/
select * from metadata.query_sets where query_set_info->>'BindTableId' in (
select distinct table_id::text from ( /*element_id,table_info,table_type*/
select json_array_elements(to_json(table_info->'dependencyTables'))::text::int element_id,table_info,table_id,table_type
from metadata.tables where table_info->'dependencyTables'::text <>'null' and table_type in ('SubProcess','CalculateTable')
) a where a.element_id in (select table_id from metadata.tables where table_type in ('MainTable','SubTable','SideTable'))
order by table_id asc
) and context->>'operatorId' = '22'
... ...
... ... @@ -46,6 +46,6 @@ require (
replace (
github.com/extrame/xls v0.0.1 => github.com/tiptok/xls v1.0.1
//github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v0.0.0-20220421085958-9682d0ac42c1
github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v1.0.0
github.com/linmadan/egglib-go v0.0.0-20210313060205-8b5e456b11f7 => github.com/tiptok/egglib-go v1.0.2
)
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
... ... @@ -11,6 +12,7 @@ import (
)
func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command.TablePreviewCommand) (interface{}, error) {
return nil, factory.FastError(fmt.Errorf("Backend not found. Check if any backend is down or not"))
if cmd.TableId == 0 {
return &dto.TablePreviewDto{}, nil
}
... ...
... ... @@ -273,8 +273,10 @@ func RoundFieldValue(f *Field, v string) string {
return utils.AssertString(fv) //fmt.Sprintf("%v", fv)
}
// TODO:计算表 Count(日期)类型是日期类型,0 的话下面日期解析成当前时间,计算表类型需要修改
if fv, err := strconv.ParseFloat(v, 64); err == nil {
return utils.AssertString(fv)
if f.SQLType == Datetime.ToString() || f.SQLType == Date.ToString() {
if fv, err := strconv.ParseFloat(v, 64); err == nil {
return utils.AssertString(fv)
}
}
if f.SQLType == Datetime.ToString() {
fv, err := xtime.Parse(v)
... ...
... ... @@ -445,7 +445,7 @@ func (d *DataLayoutDataTable) Expand(cell *domain.LayoutCell, length int) error
if expandLength < length {
expandLength = length
}
if d.MaxX+expandLength > MaxExpandNum {
if d.MaxX+expandLength > MaxExpandNum+DefaultExpandNum {
return fmt.Errorf("布局元素超过限制 %d", MaxExpandNum)
}
copyData := make([][]string, d.MaxX+length)
... ...
... ... @@ -171,7 +171,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{})
query.Where("query_set_info->'BindTableId' in (?)", pg.In(utils.ToArrayString(v.([]int))))
}
if v, ok := queryOptions["sortByName"]; ok && len(v.(string)) > 0 {
query.SetOrderDirect("pin_name", v.(string))
query.SetOrderDirect("name", v.(string))//pin_name
} else if v, ok := queryOptions["sortByTime"]; ok && len(v.(string)) > 0 {
query.SetOrderDirect("created_at", v.(string))
} else {
... ...
package controllers
import (
_ "embed"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/json"
"strings"
)
//go:embed errors.txt
var errorsData []byte
type CommErrorResolver struct {
// TODO:LRU latest error list
ErrorMapping map[string]string `json:"errorMapping"`
errMapping map[string]error `json:"errorMapping"`
}
func (r *CommErrorResolver) Resolve(err error) error {
if err == nil {
return nil
}
errMsg := err.Error()
if r.errMapping == nil {
return err
}
if v, ok := r.errMapping[errMsg]; ok {
return v
}
for k, v := range r.errMapping {
if strings.Contains(errMsg, k) {
return v
}
}
return err
}
func NewCommErrorResolver() (*CommErrorResolver, error) {
obj := &CommErrorResolver{errMapping: make(map[string]error)}
err := json.Unmarshal(errorsData, obj)
if err != nil {
return nil, err
}
for k, v := range obj.ErrorMapping {
obj.errMapping[k] = application.ThrowError(application.INTERNAL_SERVER_ERROR, v)
}
return obj, nil
}
... ...
{
"errorMapping":{
"Backend not found. Check if any backend is down or not":"数据库服务繁忙"
}
}
\ No newline at end of file
... ...
... ... @@ -6,37 +6,39 @@ import (
)
func init() {
web.Router("/data/tables/", &controllers.TableController{}, "Post:CreateTable")
//web.Router("/data/tables/:tableId", &controllers.TableController{}, "Put:UpdateTable")
web.Router("/data/tables/:tableId", &controllers.TableController{}, "Get:GetTable")
web.Router("/data/tables/prepare", &controllers.TableController{}, "Get:PrepareTable")
web.Router("/data/tables/:tableId", &controllers.TableController{}, "Delete:RemoveTable")
web.Router("/data/tables/", &controllers.TableController{}, "Get:ListTable")
web.Router("/data/tables/search", &controllers.TableController{}, "Post:Search")
web.Router("/data/tables/relation-graph", &controllers.TableController{}, "Post:RelationGraph")
web.Router("/data/tables/apply-on", &controllers.TableController{}, "Post:ApplyOn")
web.Router("/data/tables/valid-expr-sql", &controllers.TableController{}, "Post:ValidExprSql")
web.Router("/data/tables/check", &controllers.TableController{}, "Post:CheckRowDuplicate")
web.Router("/data/tables/check-row-value-duplicate", &controllers.TableController{}, "Post:CheckRowValueDuplicate")
web.Router("/data/tables/search-appended-list", &controllers.TableController{}, "Post:SearchAppendedList")
web.Router("/data/tables/search-sub-table-list", &controllers.TableController{}, "Post:SearchSubTableList")
web.Router("/data/tables/search-query-set-tables", &controllers.TableController{}, "Post:SearchQuerySetTables")
web.Router("/data/tables/dependency-graph", &controllers.TableController{}, "Post:DependencyGraph")
tableController := &controllers.TableController{}
//tableController.BaseController.ErrorResolver, _ = controllers.NewCommErrorResolver()
web.Router("/data/tables/", tableController, "Post:CreateTable")
//web.Router("/data/tables/:tableId", tableController, "Put:UpdateTable")
web.Router("/data/tables/:tableId", tableController, "Get:GetTable")
web.Router("/data/tables/prepare", tableController, "Get:PrepareTable")
web.Router("/data/tables/:tableId", tableController, "Delete:RemoveTable")
web.Router("/data/tables/", tableController, "Get:ListTable")
web.Router("/data/tables/search", tableController, "Post:Search")
web.Router("/data/tables/relation-graph", tableController, "Post:RelationGraph")
web.Router("/data/tables/apply-on", tableController, "Post:ApplyOn")
web.Router("/data/tables/valid-expr-sql", tableController, "Post:ValidExprSql")
web.Router("/data/tables/check", tableController, "Post:CheckRowDuplicate")
web.Router("/data/tables/check-row-value-duplicate", tableController, "Post:CheckRowValueDuplicate")
web.Router("/data/tables/search-appended-list", tableController, "Post:SearchAppendedList")
web.Router("/data/tables/search-sub-table-list", tableController, "Post:SearchSubTableList")
web.Router("/data/tables/search-query-set-tables", tableController, "Post:SearchQuerySetTables")
web.Router("/data/tables/dependency-graph", tableController, "Post:DependencyGraph")
//web.Router("/data/tables/split-data-table", &controllers.TableController{}, "Post:SplitDataTable")
//web.Router("/data/tables/batch-edit-sub-table", &controllers.TableController{}, "Post:BatchEditSubTable")
web.Router("/data/tables/copy-data-table", &controllers.TableController{}, "Post:CopyDataTable")
web.Router("/data/tables/update-table-struct/:tableId", &controllers.TableController{}, "Put:UpdateTableStruct")
web.Router("/data/tables/add-sub-table", &controllers.TableController{}, "Post:AddTableStruct")
web.Router("/data/tables/export-table", &controllers.TableController{}, "Post:ExportDataTable")
//web.Router("/data/tables/split-data-table", tableController, "Post:SplitDataTable")
//web.Router("/data/tables/batch-edit-sub-table", tableController, "Post:BatchEditSubTable")
web.Router("/data/tables/copy-data-table", tableController, "Post:CopyDataTable")
web.Router("/data/tables/update-table-struct/:tableId", tableController, "Put:UpdateTableStruct")
web.Router("/data/tables/add-sub-table", tableController, "Post:AddTableStruct")
web.Router("/data/tables/export-table", tableController, "Post:ExportDataTable")
web.Router("/data/tables/table-preview", &controllers.TableController{}, "Post:TablePreview")
web.Router("/data/tables/row-edit", &controllers.TableController{}, "Post:RowEdit")
web.Router("/data/tables/table-preview", tableController, "Post:TablePreview")
web.Router("/data/tables/row-edit", tableController, "Post:RowEdit")
web.Router("/data/field-optional-values", &controllers.TableController{}, "Post:FieldOptionalValues")
web.Router("/data/table-object-search", &controllers.TableController{}, "Post:TableObjectSearch")
web.Router("/data/field-optional-values", tableController, "Post:FieldOptionalValues")
web.Router("/data/table-object-search", tableController, "Post:TableObjectSearch")
web.Router("/business/db-table-preview", &controllers.TableController{}, "Post:DBTablePreview")
web.Router("/data/table-preview", &controllers.TableController{}, "Post:Preview")
web.Router("/business/db-table-preview", tableController, "Post:DBTablePreview")
web.Router("/data/table-preview", tableController, "Post:Preview")
}
... ...