作者 yangfu

业务表同步

@@ -9,7 +9,7 @@ HTTP_PORT = 8081 @@ -9,7 +9,7 @@ HTTP_PORT = 8081
9 ENABLE_KAFKA_LOG11 = true 9 ENABLE_KAFKA_LOG11 = true
10 HTTPS_PORT = 8143 10 HTTPS_PORT = 8143
11 ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com 11 ALLIED_CREATION_USER_HOST = http://allied-creation-user-dev.fjmaimaimai.com
12 -# AUTH_SERVER_HOST = http://127.0.0.1:8081 12 +# AUTH_SERVER_HOST = http://127.0.0.1:8081 192.168.100.9:8303
13 BYTE_CORE_HOST = http://47.97.5.102:8303 13 BYTE_CORE_HOST = http://47.97.5.102:8303
14 METADATA_BASTION_HOST = http://106.75.231.90:9999 14 METADATA_BASTION_HOST = http://106.75.231.90:9999
15 15
  1 +package command
  2 +
  3 +type GenerateBusinessTableRequest struct {
  4 + TableName string `json:"mainTableName"`
  5 + TableFullName string `json:"tableFullName"`
  6 + Fields []FieldSchemas `json:"fields"`
  7 +}
  1 +package command
  2 +
  3 +type UpdateBusinessTableRequest struct {
  4 + TableName string `json:"tableRemarkName"`
  5 + TableFullName string `json:"tableFullName"`
  6 + Fields []FieldSchemas `json:"fields"`
  7 + ShowTableNameBy int `json:"showTableNameBy"` // 展示表名 0:原表名 1:表名备注
  8 + ShowTableFieldNameBy int `json:"showTableFieldNameBy"` // 字段名在字库的显示 0:字段原名 1:字段备注
  9 +}
  10 +
  11 +type FieldSchemas struct {
  12 + FieldEnName string `json:"fieldEnName"`
  13 + FieldType string `json:"fieldType"`
  14 + FieldZhName string `json:"fieldZhName"`
  15 +}
  1 +package query
  2 +
  3 +type ShowBusinessDatabasesRequest struct {
  4 + TableFullName string `json:"tableFullName"`
  5 + PageNumber int `json:"pageNumber"`
  6 + PageSize int `json:"pageSize"`
  7 +}
  1 +package query
  2 +
  3 +type ShowTableDataRequest struct {
  4 + TableFullName string `json:"tableFullName"`
  5 + PageNumber int `json:"pageNumber"`
  6 + PageSize int `json:"pageSize"`
  7 +}
  1 +package query
  2 +
  3 +type ShowTablesRequest struct {
  4 + DatabaseEnName string `json:"databaseEnName"`
  5 + DatabaseType string `json:"databaseType"`
  6 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
  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/bytelib"
  12 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
  13 +)
  14 +
  15 +func (tableService *TableService) ShowBusinessDatabases(ctx *domain.Context, cmd *query.ShowBusinessDatabasesRequest) (interface{}, error) {
  16 + byteCoreService := domainService.ByteCoreService{}
  17 + response, err := byteCoreService.ShowBusinessDatabases(bytelib.ReqShowBusinessDatabases{})
  18 + return response, err
  19 +}
  20 +
  21 +func (tableService *TableService) ShowBusinessTables(ctx *domain.Context, cmd *query.ShowTablesRequest) (interface{}, error) {
  22 + byteCoreService := domainService.ByteCoreService{}
  23 + response, err := byteCoreService.ShowBusinessTables(bytelib.ReqShowBusinessTables{
  24 + DatabaseEnName: cmd.DatabaseEnName,
  25 + DatabaseType: cmd.DatabaseType,
  26 + })
  27 + result := make([]map[string]interface{}, 0)
  28 + for _, t := range response.TableFullNames {
  29 + result = append(result, map[string]interface{}{
  30 + "name": t,
  31 + })
  32 + }
  33 + return map[string]interface{}{
  34 + "list": result,
  35 + }, err
  36 +}
  37 +
  38 +func (tableService *TableService) QueryBusinessTable(ctx *domain.Context, cmd *query.ShowTableDataRequest) (interface{}, error) {
  39 + byteCoreService := domainService.ByteCoreService{}
  40 + response, err := byteCoreService.QueryBusinessTable(bytelib.ReqQueryBusinessTable{
  41 + TableFullName: cmd.TableFullName,
  42 + PageNumber: cmd.PageNumber,
  43 + PageSize: cmd.PageSize,
  44 + })
  45 +
  46 + transactionContext, err := factory.CreateTransactionContext(nil)
  47 + if err != nil {
  48 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  49 + }
  50 + tableRepository, _, _ := factory.FastPgTable(transactionContext, 0)
  51 + table, _ := tableRepository.FindBusinessTable(constant.COMPANY_SU_TIAN_XIA, response.TableFullName)
  52 + if table != nil {
  53 + response.TableRemarkName = table.Name
  54 + response.ShowTableNameBy = table.TableInfo.BusinessTableShowTableNameBy
  55 + response.ShowTableFieldNameBy = table.TableInfo.BusinessTableShowTableFieldNameBy
  56 + for i, f := range response.FieldSchemas {
  57 + for j, jf := range table.DataFields {
  58 + if jf.SQLName == f.FieldEnName {
  59 + response.FieldSchemas[i].FieldZhName = table.DataFields[j].Name
  60 + }
  61 + }
  62 + }
  63 +
  64 + }
  65 + return response, err
  66 +}
  67 +
  68 +func (tableService *TableService) UpdateBusinessTable(ctx *domain.Context, cmd *command.UpdateBusinessTableRequest) (interface{}, error) {
  69 + transactionContext, err := factory.CreateTransactionContext(nil)
  70 + if err != nil {
  71 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  72 + }
  73 + if err := transactionContext.StartTransaction(); err != nil {
  74 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  75 + }
  76 + defer func() {
  77 + transactionContext.RollbackTransaction()
  78 + }()
  79 + var tableRepository domain.TableRepository
  80 + if value, err := factory.CreateTableRepository(map[string]interface{}{
  81 + "transactionContext": transactionContext,
  82 + }); err != nil {
  83 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  84 + } else {
  85 + tableRepository = value
  86 + }
  87 +
  88 + ctx.CompanyId = int(constant.COMPANY_SU_TIAN_XIA)
  89 +
  90 + var (
  91 + fields = make([]*domain.Field, 0)
  92 + mainTable *domain.Table
  93 + )
  94 + for i, f := range cmd.Fields {
  95 + fields = append(fields, &domain.Field{
  96 + Index: i + 1,
  97 + Name: f.FieldZhName,
  98 + SQLName: f.FieldEnName,
  99 + SQLType: f.FieldType, //TODO:类型转换
  100 + Flag: domain.MainTableField,
  101 + })
  102 + }
  103 + table, _ := tableRepository.FindBusinessTable(constant.COMPANY_SU_TIAN_XIA, cmd.TableFullName)
  104 + if table == nil {
  105 + mainTable = domainService.NewTable(domain.BusinessTable, cmd.TableName, fields, 0).
  106 + WithContext(ctx).
  107 + WithPrefix(domain.BusinessTable.ToString())
  108 + mainTable.SQLName = cmd.TableFullName
  109 + mainTable.DataFields = fields
  110 + mainTable.TableInfo.BusinessTableShowTableNameBy = cmd.ShowTableNameBy
  111 + mainTable.TableInfo.BusinessTableShowTableFieldNameBy = cmd.ShowTableFieldNameBy
  112 + mainTable.TableInfo.TableFrom = 1
  113 +
  114 + if mainTable, err = tableRepository.Save(mainTable); err != nil {
  115 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  116 + }
  117 + } else {
  118 + table.Name = cmd.TableName
  119 + table.DataFields = fields
  120 + table.TableInfo.BusinessTableShowTableNameBy = cmd.ShowTableNameBy
  121 + table.TableInfo.BusinessTableShowTableFieldNameBy = cmd.ShowTableFieldNameBy
  122 + if table, err = tableRepository.Save(table); err != nil {
  123 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  124 + }
  125 + }
  126 +
  127 + if err = transactionContext.CommitTransaction(); err != nil {
  128 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  129 + }
  130 + return mainTable, nil
  131 +}
  132 +
  133 +func (tableService *TableService) GenerateBusinessTable(ctx *domain.Context, cmd *command.GenerateBusinessTableRequest) (interface{}, error) {
  134 + transactionContext, err := factory.CreateTransactionContext(nil)
  135 + if err != nil {
  136 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  137 + }
  138 + if err := transactionContext.StartTransaction(); err != nil {
  139 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  140 + }
  141 + defer func() {
  142 + transactionContext.RollbackTransaction()
  143 + }()
  144 + var tableRepository domain.TableRepository
  145 + if value, err := factory.CreateTableRepository(map[string]interface{}{
  146 + "transactionContext": transactionContext,
  147 + }); err != nil {
  148 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  149 + } else {
  150 + tableRepository = value
  151 + }
  152 + ctx.CompanyId = int(constant.COMPANY_SU_TIAN_XIA)
  153 +
  154 + duplicateTable, err := tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableName": cmd.TableName,
  155 + "tableTypes": []string{string(domain.MainTable), string(domain.SubTable), string(domain.SideTable)}})
  156 + if err == nil && duplicateTable != nil {
  157 + return nil, fmt.Errorf("表名称重复")
  158 + }
  159 +
  160 + var (
  161 + fields = make([]*domain.Field, 0)
  162 + mainTable *domain.Table
  163 + )
  164 + for i, f := range cmd.Fields {
  165 + fields = append(fields, &domain.Field{
  166 + Index: i + 1,
  167 + Name: f.FieldZhName,
  168 + SQLName: f.FieldEnName,
  169 + SQLType: f.FieldType, //TODO:类型转换
  170 + Flag: domain.MainTableField,
  171 + })
  172 + }
  173 + mainTable = domainService.NewTable(domain.MainTable, cmd.TableName, fields, 0).
  174 + WithContext(ctx).
  175 + WithPrefix(domain.MainTable.ToString()).ApplyDefaultModule()
  176 + mainTable.SQLName = cmd.TableFullName
  177 + mainTable.TableInfo.TableFrom = 1
  178 + mainTable.DataFields = fields
  179 + if mainTable, err = tableRepository.Save(mainTable); err != nil {
  180 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  181 + }
  182 +
  183 + if err = transactionContext.CommitTransaction(); err != nil {
  184 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  185 + }
  186 + return nil, nil
  187 +}
@@ -31,6 +31,8 @@ var BLACK_LIST_USER int64 @@ -31,6 +31,8 @@ var BLACK_LIST_USER int64
31 var BLACK_LIST_COMPANY int64 31 var BLACK_LIST_COMPANY int64
32 var WHITE_LIST_USERS []int 32 var WHITE_LIST_USERS []int
33 33
  34 +var COMPANY_SU_TIAN_XIA int64 = 1689162984523304960
  35 +
34 func init() { 36 func init() {
35 LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL) 37 LOG_LEVEL = Configurator.DefaultString("LOG_LEVEL", LOG_LEVEL)
36 MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST) 38 MMM_BYTE_BANK_HOST = Configurator.DefaultString("MMM_BYTE_BANK_HOST", MMM_BYTE_BANK_HOST)
@@ -47,6 +49,8 @@ func init() { @@ -47,6 +49,8 @@ func init() {
47 BLACK_LIST_COMPANY = Configurator.DefaultInt64("BLACK_LIST_COMPANY", BLACK_LIST_COMPANY) 49 BLACK_LIST_COMPANY = Configurator.DefaultInt64("BLACK_LIST_COMPANY", BLACK_LIST_COMPANY)
48 DIGITAL_SERVER_HOST = Configurator.DefaultString("DIGITAL_SERVER_HOST", DIGITAL_SERVER_HOST) 50 DIGITAL_SERVER_HOST = Configurator.DefaultString("DIGITAL_SERVER_HOST", DIGITAL_SERVER_HOST)
49 51
  52 + COMPANY_SU_TIAN_XIA = Configurator.DefaultInt64("COMPANY_SU_TIAN_XIA", COMPANY_SU_TIAN_XIA)
  53 +
50 whiteListUsers := strings.Split(Configurator.DefaultString("WHITE_LIST_USERS", ""), ",") 54 whiteListUsers := strings.Split(Configurator.DefaultString("WHITE_LIST_USERS", ""), ",")
51 for _, userId := range whiteListUsers { 55 for _, userId := range whiteListUsers {
52 v, _ := strconv.Atoi(userId) 56 v, _ := strconv.Atoi(userId)
@@ -104,6 +104,7 @@ var ( @@ -104,6 +104,7 @@ var (
104 SubTable TableType = "SubTable" 104 SubTable TableType = "SubTable"
105 ExcelTable TableType = "ExcelTable" 105 ExcelTable TableType = "ExcelTable"
106 TemporaryTable TableType = "TemporaryTable" 106 TemporaryTable TableType = "TemporaryTable"
  107 + BusinessTable TableType = "BusinessTable" // 业务表
107 ) 108 )
108 109
109 var ( 110 var (
@@ -55,6 +55,7 @@ type TableRepository interface { @@ -55,6 +55,7 @@ type TableRepository interface {
55 Save(table *Table) (*Table, error) 55 Save(table *Table) (*Table, error)
56 Remove(table *Table) (*Table, error) 56 Remove(table *Table) (*Table, error)
57 FindOne(queryOptions map[string]interface{}) (*Table, error) 57 FindOne(queryOptions map[string]interface{}) (*Table, error)
  58 + FindBusinessTable(companyId int64, sqlName string) (*Table, error)
58 Find(queryOptions map[string]interface{}) (int64, []*Table, error) 59 Find(queryOptions map[string]interface{}) (int64, []*Table, error)
59 } 60 }
60 61
@@ -5,6 +5,10 @@ type TableInfo struct { @@ -5,6 +5,10 @@ type TableInfo struct {
5 ApplyOnModule int `json:"module"` 5 ApplyOnModule int `json:"module"`
6 // 依赖关联的表 6 // 依赖关联的表
7 DependencyTables []int `json:"dependencyTables"` 7 DependencyTables []int `json:"dependencyTables"`
  8 + // 表来源
  9 + TableFrom int `json:"tableFrom"` // 0:字库导入 1:字库实表同步
  10 + BusinessTableShowTableNameBy int `json:"showTableNameBy"` // 【业务表】展示表名 0:原表名 1:表名备注
  11 + BusinessTableShowTableFieldNameBy int `json:"showTableFieldNameBy"` // 【业务表】字段名在字库的显示 0:字段原名 1:字段备注
8 } 12 }
9 13
10 func (t *TableInfo) SetApplyOn(applyOn int) *TableInfo { 14 func (t *TableInfo) SetApplyOn(applyOn int) *TableInfo {
@@ -278,3 +278,36 @@ func (gateway ApiByteLib) FormulasClear(param domain.ReqFormulasClear) (*domain. @@ -278,3 +278,36 @@ func (gateway ApiByteLib) FormulasClear(param domain.ReqFormulasClear) (*domain.
278 var response = domain.DataFormulasClear{} 278 var response = domain.DataFormulasClear{}
279 return &response, nil 279 return &response, nil
280 } 280 }
  281 +
  282 +func (gateway ApiByteLib) ShowBusinessDatabases(request ReqShowBusinessDatabases) (*DataShowBusinessDatabases, error) {
  283 + url := gateway.Host() + "/databases/show-business-databases"
  284 + method := "post"
  285 + var data DataShowBusinessDatabases
  286 + err := gateway.FastDoRequest(url, method, request, &data)
  287 + if err != nil {
  288 + return nil, err
  289 + }
  290 + return &data, nil
  291 +}
  292 +
  293 +func (gateway ApiByteLib) ShowBusinessTables(request ReqShowBusinessTables) (*DataShowBusinessTables, error) {
  294 + url := gateway.Host() + "/databases/show-tables"
  295 + method := "post"
  296 + var data DataShowBusinessTables
  297 + err := gateway.FastDoRequest(url, method, request, &data)
  298 + if err != nil {
  299 + return nil, err
  300 + }
  301 + return &data, nil
  302 +}
  303 +
  304 +func (gateway ApiByteLib) QueryBusinessTable(request ReqQueryBusinessTable) (*DataQueryBusinessTable, error) {
  305 + url := gateway.Host() + "/databases/query-table"
  306 + method := "post"
  307 + var data DataQueryBusinessTable
  308 + err := gateway.FastDoRequest(url, method, request, &data)
  309 + if err != nil {
  310 + return nil, err
  311 + }
  312 + return &data, nil
  313 +}
@@ -332,3 +332,49 @@ type ( @@ -332,3 +332,49 @@ type (
332 FormulasClearResponse struct { 332 FormulasClearResponse struct {
333 } 333 }
334 ) 334 )
  335 +
  336 +type (
  337 + ReqShowBusinessDatabases struct {
  338 + }
  339 + DataShowBusinessDatabases struct {
  340 + BusinessDatabases []struct {
  341 + DatabaseDescription string `json:"databaseDescription"`
  342 + DatabaseEnName string `json:"databaseEnName"`
  343 + DatabaseType string `json:"databaseType"`
  344 + DatabaseZhName string `json:"databaseZhName"`
  345 + } `json:"businessDatabases"`
  346 + }
  347 +)
  348 +
  349 +type (
  350 + ReqShowBusinessTables struct {
  351 + DatabaseEnName string `json:"databaseEnName"`
  352 + DatabaseType string `json:"databaseType"`
  353 + }
  354 + DataShowBusinessTables struct {
  355 + TableFullNames []string `json:"tableFullNames"`
  356 + }
  357 +)
  358 +
  359 +type (
  360 + ReqQueryBusinessTable struct {
  361 + TableFullName string `json:"tableFullName"`
  362 + PageNumber int `json:"pageNumber"`
  363 + PageSize int `json:"pageSize"`
  364 + }
  365 + DataQueryBusinessTable struct {
  366 + DataCount int `json:"dataCount"`
  367 + FieldSchemas []struct {
  368 + FieldDescription string `json:"fieldDescription"`
  369 + FieldEnName string `json:"fieldEnName"`
  370 + FieldType string `json:"fieldType"`
  371 + FieldZhName string `json:"fieldZhName"`
  372 + IsAllowNull bool `json:"isAllowNull"`
  373 + } `json:"fieldSchemas"`
  374 + ShowData [][]string `json:"showData"`
  375 + TableFullName string `json:"tableFullName"`
  376 + TableRemarkName string `json:"tableRemarkName"`
  377 + ShowTableNameBy int `json:"showTableNameBy"` // 展示表名 0:原表名 1:表名备注
  378 + ShowTableFieldNameBy int `json:"showTableFieldNameBy"` // 字段名在字库的显示 0:字段原名 1:字段备注
  379 + }
  380 +)
@@ -170,6 +170,21 @@ func (ptr *ByteCoreService) FormulasClear(param domain.ReqFormulasClear) (*domai @@ -170,6 +170,21 @@ func (ptr *ByteCoreService) FormulasClear(param domain.ReqFormulasClear) (*domai
170 return apiByteLib.FormulasClear(param) 170 return apiByteLib.FormulasClear(param)
171 } 171 }
172 172
  173 +func (ptr *ByteCoreService) ShowBusinessDatabases(param bytelib.ReqShowBusinessDatabases) (*bytelib.DataShowBusinessDatabases, error) {
  174 + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
  175 + return apiByteLib.ShowBusinessDatabases(param)
  176 +}
  177 +
  178 +func (ptr *ByteCoreService) ShowBusinessTables(param bytelib.ReqShowBusinessTables) (*bytelib.DataShowBusinessTables, error) {
  179 + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
  180 + return apiByteLib.ShowBusinessTables(param)
  181 +}
  182 +
  183 +func (ptr *ByteCoreService) QueryBusinessTable(param bytelib.ReqQueryBusinessTable) (*bytelib.DataQueryBusinessTable, error) {
  184 + apiByteLib := bytelib.NewApiByteLib(constant.BYTE_CORE_HOST)
  185 + return apiByteLib.QueryBusinessTable(param)
  186 +}
  187 +
173 func (ptr *ByteCoreService) ExcelExprCalcPersistence(expr *domain.FieldFormulaExpr, param domain.ReqFormulasGenerate, persistence bool) error { 188 func (ptr *ByteCoreService) ExcelExprCalcPersistence(expr *domain.FieldFormulaExpr, param domain.ReqFormulasGenerate, persistence bool) error {
174 if len(param.QueryComponents) == 0 { 189 if len(param.QueryComponents) == 0 {
175 return nil 190 return nil
@@ -165,6 +165,28 @@ func (repository *TableRepository) FindOne(queryOptions map[string]interface{}) @@ -165,6 +165,28 @@ func (repository *TableRepository) FindOne(queryOptions map[string]interface{})
165 return transform.TransformToTableDomainModelFromPgModels(tableModel) 165 return transform.TransformToTableDomainModelFromPgModels(tableModel)
166 } 166 }
167 } 167 }
  168 +
  169 +func (repository *TableRepository) FindBusinessTable(companyId int64, sqlName string) (*domain.Table, error) {
  170 + tx := repository.transactionContext.DB()
  171 + tableModel := new(models.Table)
  172 + query := sqlbuilder.BuildQuery(tx.Model(tableModel), nil)
  173 + query.Where("context->'companyId'='?'", companyId)
  174 + query.Where("sql_name = ?", sqlName)
  175 + query.Where("table_type = ?", domain.BusinessTable.ToString())
  176 + if err := query.First(); err != nil {
  177 + if err.Error() == "pg: no rows in result set" {
  178 + return nil, domain.ErrorNotFound
  179 + } else {
  180 + return nil, err
  181 + }
  182 + }
  183 + if tableModel.TableId == 0 {
  184 + return nil, nil
  185 + } else {
  186 + return transform.TransformToTableDomainModelFromPgModels(tableModel)
  187 + }
  188 +}
  189 +
168 func (repository *TableRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Table, error) { 190 func (repository *TableRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Table, error) {
169 tx := repository.transactionContext.DB() 191 tx := repository.transactionContext.DB()
170 var tableModels []*models.Table 192 var tableModels []*models.Table
@@ -177,6 +199,9 @@ func (repository *TableRepository) Find(queryOptions map[string]interface{}) (in @@ -177,6 +199,9 @@ func (repository *TableRepository) Find(queryOptions map[string]interface{}) (in
177 if v, ok := queryOptions["tableIds"]; ok && len(v.([]int)) > 0 { 199 if v, ok := queryOptions["tableIds"]; ok && len(v.([]int)) > 0 {
178 query.Where(`table_id in (?)`, pg.In(v.([]int))) 200 query.Where(`table_id in (?)`, pg.In(v.([]int)))
179 } 201 }
  202 + if v, ok := queryOptions["sqlNames"]; ok && len(v.([]string)) > 0 {
  203 + query.Where(`sql_name in (?)`, pg.In(v.([]string)))
  204 + }
180 if v, ok := queryOptions["tableTypes"]; ok && len(v.([]string)) > 0 { 205 if v, ok := queryOptions["tableTypes"]; ok && len(v.([]string)) > 0 {
181 query.Where(`table_type in (?)`, pg.In(v.([]string))) 206 query.Where(`table_type in (?)`, pg.In(v.([]string)))
182 } 207 }
  1 +package controllers
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
  5 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/service"
  7 +)
  8 +
  9 +func (controller *TableController) ShowBusinessDatabases() {
  10 + tableService := service.NewTableService(nil)
  11 + cmd := &query.ShowBusinessDatabasesRequest{}
  12 + Must(controller.Unmarshal(cmd))
  13 + data, err := tableService.ShowBusinessDatabases(ParseContext(controller.BaseController), cmd)
  14 + controller.Response(data, err)
  15 +}
  16 +
  17 +func (controller *TableController) ShowBusinessTables() {
  18 + tableService := service.NewTableService(nil)
  19 + cmd := &query.ShowTablesRequest{}
  20 + Must(controller.Unmarshal(cmd))
  21 + data, err := tableService.ShowBusinessTables(ParseContext(controller.BaseController), cmd)
  22 + controller.Response(data, err)
  23 +}
  24 +
  25 +func (controller *TableController) QueryBusinessTable() {
  26 + tableService := service.NewTableService(nil)
  27 + cmd := &query.ShowTableDataRequest{}
  28 + Must(controller.Unmarshal(cmd))
  29 + data, err := tableService.QueryBusinessTable(ParseContext(controller.BaseController), cmd)
  30 + controller.Response(data, err)
  31 +}
  32 +
  33 +func (controller *TableController) UpdateBusinessTable() {
  34 + tableService := service.NewTableService(nil)
  35 + cmd := &command.UpdateBusinessTableRequest{}
  36 + Must(controller.Unmarshal(cmd))
  37 + data, err := tableService.UpdateBusinessTable(ParseContext(controller.BaseController), cmd)
  38 + controller.Response(data, err)
  39 +}
  40 +
  41 +func (controller *TableController) GenerateBusinessTable() {
  42 + tableService := service.NewTableService(nil)
  43 + cmd := &command.GenerateBusinessTableRequest{}
  44 + Must(controller.Unmarshal(cmd))
  45 + data, err := tableService.GenerateBusinessTable(ParseContext(controller.BaseController), cmd)
  46 + controller.Response(data, err)
  47 +}
@@ -13,4 +13,10 @@ func init() { @@ -13,4 +13,10 @@ func init() {
13 web.Router("/api/app-table-file/append-data", &controllers.FileController{}, "Post:AppendDataAppTableFile") 13 web.Router("/api/app-table-file/append-data", &controllers.FileController{}, "Post:AppendDataAppTableFile")
14 web.Router("/api/app-table-file/list", &controllers.FileController{}, "Post:ListAppTableFile") 14 web.Router("/api/app-table-file/list", &controllers.FileController{}, "Post:ListAppTableFile")
15 web.Router("/api/app-table-file/update", &controllers.FileController{}, "Post:UpdateAppTableFile") 15 web.Router("/api/app-table-file/update", &controllers.FileController{}, "Post:UpdateAppTableFile")
  16 +
  17 + web.Router("/api/business-table/show-business-databases", &controllers.TableController{}, "Post:ShowBusinessDatabases")
  18 + web.Router("/api/business-table/show-tables", &controllers.TableController{}, "Post:ShowBusinessTables")
  19 + web.Router("/api/business-table/query-table", &controllers.TableController{}, "Post:QueryBusinessTable")
  20 + web.Router("/api/business-table/update", &controllers.TableController{}, "Post:UpdateBusinessTable")
  21 + web.Router("/api/business-table/generate", &controllers.TableController{}, "Post:GenerateBusinessTable")
16 } 22 }