houyaf há 3 anos atrás
pai
commit
20ed114d64

+ 3 - 3
cache/redis.go

@@ -119,14 +119,14 @@ func GetBizObjectData(objectCode string)(*viewmodels.BizObjectDataInfo, error){
 	return bizObjectData, nil
 }
 
-func SetApiData(apiCode string, data *viewmodels.ApiDataInfo) error {
+func SetApiData(apiCode string, data *viewmodels.ApiInfo) error {
 	keyStr := fmt.Sprintf("api_%s", apiCode)
 	return SetCache(keyStr, data, 0)
 }
 
-func GetApiData(apiCode string)(*viewmodels.ApiDataInfo, error){
+func GetApiData(apiCode string)(*viewmodels.ApiInfo, error){
 	keyStr := fmt.Sprintf("api_%s", apiCode)
-	apiData := &viewmodels.ApiDataInfo{}
+	apiData := &viewmodels.ApiInfo{}
 	err := Instance().Get(context.Background(), keyStr).Scan(apiData)
 	if err != nil {
 		return nil, err

+ 2 - 3
datamodels/api.go

@@ -11,10 +11,9 @@ type Api struct {
     ApiParams       string    `json:"apiParams"       xorm:"'api_params'    varchar(127)  comment('Param')     "`
     Status          int64     `json:"status"          xorm:"'status'        bigint        comment('Status')    "`
     ApiDesc         string    `json:"apiDesc"         xorm:"'api_desc'      varchar(50)   comment('描述')       "`
-    ObjectType      int64     `json:"objectType"      xorm:"'objectType'    bigint        comment('Object Type')"`
-    ObjectGroupId   int64     `json:"objectGroupId"   xorm:"'objectGroupId' bigint        comment('Object GroupId')"`
+    BizId           int64     `json:"bizId"           xorm:"'bizId'         bigint        comment('Biz Id')     "`
     ObjectId        int64     `json:"objectId"        xorm:"'objectId'      bigint        comment('Object Id')  "`
-    OamId           int64     `json:"oamId"           xorm:"'oamId'         bigint        comment('Oam Id')  "`
+    OamId           int64     `json:"oamId"           xorm:"'oamId'         bigint        comment('Oam Id')     "`
     CreatedBy       int64     `json:"createdBy"       xorm:"'created_by'"`
     CreatedAt       time.Time `json:"createdAt"       xorm:"'created_at'"`
     UpdatedBy       int64     `json:"updatedBy"       xorm:"'updated_by'"`

+ 5 - 4
datamodels/biz_object_oam.go

@@ -11,10 +11,11 @@ type BizObjectOAM struct {
     OamType      int64     `json:"oamType"         xorm:"'oam_type'        bigint         comment('Oam Type')       "`
     SqlType      int64     `json:"sqlType"         xorm:"'sql_type'        bigint         comment('Sql Type')       "`
     SqlStatement string    `json:"sqlStatement"    xorm:"'sql_statement'   varchar(1023)  comment('Statement')      "`
-    SqlSelect    string    `json:"sqlSelect"       xorm:"'sql_select'      varchar(1023)  comment('Statement')      "`
-    SqlFrom      string    `json:"sqlFrom"         xorm:"'sql_from'        varchar(1023)  comment('Statement')      "`
-    SqlWhere     string    `json:"sqlWhere"        xorm:"'sql_where'       varchar(1023)  comment('Statement')      "`
-    SqlOrder     string    `json:"sqlOrder"        xorm:"'sql_order'       varchar(1023)  comment('Statement')      "`
+    SqlSelect    string    `json:"sqlSelect"       xorm:"'sql_select'      varchar(1023)  comment('Sql Select')     "`
+    SqlFrom      string    `json:"sqlFrom"         xorm:"'sql_from'        varchar(1023)  comment('Sql From')       "`
+    SqlWhere     string    `json:"sqlWhere"        xorm:"'sql_where'       varchar(1023)  comment('Sql Where')      "`
+    SqlOrder     string    `json:"sqlOrder"        xorm:"'sql_order'       varchar(1023)  comment('Sql Order')      "`
+    SqlCount     string    `json:"sqlCount"        xorm:"'sql_count'       varchar(1023)  comment('Sql Count')      "`
     OamDesc      string    `json:"oamDesc"         xorm:"'oam_desc'        varchar(1023)  comment('描述')            "`
     CreatedBy    int64     `json:"createdBy"       xorm:"'created_by'"`
     CreatedAt    time.Time `json:"createdAt"       xorm:"'created_at'"`

+ 75 - 20
repositories/api_repo.go

@@ -23,16 +23,30 @@ func (d *ApiRepo) GetPage(m map[string]interface{}) (*viewmodels.PageResult, err
     page  := m["page"].(int)
     
     sqlSelect := ` SELECT    A.*,
-                             B.module_title  `
-    sqlFrom   := ` FROM      api        AS A
-                   LEFT JOIN api_module AS B ON (A.module_id = B.module_id) `
+                             B.module_title,
+                             C.biz_title,
+                             D.object_title,
+                             D.object_code,
+                             D.object_type,
+                             E.oam_title,
+                             E.oam_type,
+                             E.oam_code,
+                             E.sql_type,
+                             E.sql_statement,
+                             E.sql_count,
+                             E.oam_desc `
+    sqlFrom   := ` FROM      api            AS A
+                   LEFT JOIN api_module     AS B ON (A.module_id = B.module_id)
+                   LEFT JOIN biz            AS C ON (A.biz_id = C.biz_id)
+                   LEFT JOIN biz_object     AS D ON (A.biz_id = D.biz_id AND A.object_id = D.object_id)
+                   LEFT JOIN biz_object_oam AS E ON (A.biz_id = E.biz_id AND A.object_id = E.object_id AND A.oam_id = E.oam_id)`
     sqlWhere  := ` WHERE  A.deleted_flag = 0  `
     if keywords, ok := m["keywords"]; ok {
         sqlWhere += ` AND A.api_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
     }
     
     sqlCount := ` SELECT COUNT(*) `
-    total, err1 := d.engine.SQL(sqlCount + sqlFrom + sqlWhere).Count(new(datamodels.Api))
+    total, err1 := d.engine.SQL(sqlCount + sqlFrom + sqlWhere).Count(new(viewmodels.ApiInfo))
     if err1 != nil {
         return nil, err1
     }
@@ -41,7 +55,7 @@ func (d *ApiRepo) GetPage(m map[string]interface{}) (*viewmodels.PageResult, err
     pageStart  := (page - 1) * limit
     sqlLimit   := fmt.Sprintf(" LIMIT %d OFFSET %d ", limit, pageStart)
     
-    datalist := make([]datamodels.Api, 0)
+    datalist := make([]viewmodels.ApiInfo, 0)
     err2 := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy + sqlLimit).Find(&datalist)
     if err2 != nil {
         return nil, err2
@@ -59,10 +73,24 @@ func (d *ApiRepo) GetList(m map[string]interface{}) ([]viewmodels.ApiInfo, error
     moduleId  := m["moduleId"].(int64)
     
     sqlSelect := ` SELECT    A.*,
-                             B.module_title  `
-    sqlFrom   := ` FROM      api        AS A
-                   LEFT JOIN api_module AS B ON (A.module_id = B.module_id) `
-    sqlWhere  := ` WHERE  A.deleted_flag = 0 `
+                             B.module_title,
+                             C.biz_title,
+                             D.object_title,
+                             D.object_code,
+                             D.object_type,
+                             E.oam_title,
+                             E.oam_type,
+                             E.oam_code,
+                             E.sql_type,
+                             E.sql_statement,
+                             E.sql_count,
+                             E.oam_desc `
+    sqlFrom   := ` FROM      api            AS A
+                   LEFT JOIN api_module     AS B ON (A.module_id = B.module_id)
+                   LEFT JOIN biz            AS C ON (A.biz_id = C.biz_id)
+                   LEFT JOIN biz_object     AS D ON (A.biz_id = D.biz_id AND A.object_id = D.object_id)
+                   LEFT JOIN biz_object_oam AS E ON (A.biz_id = E.biz_id AND A.object_id = E.object_id AND A.oam_id = E.oam_id)`
+    sqlWhere  := ` WHERE  A.deleted_flag = 0  `
     sqlWhere  += fmt.Sprintf(" AND A.module_id = %d", moduleId)
     
     if keywords, ok := m["keywords"]; ok {
@@ -80,12 +108,25 @@ func (d *ApiRepo) GetList(m map[string]interface{}) ([]viewmodels.ApiInfo, error
 }
 
 func (d *ApiRepo) GetAll() ([]viewmodels.ApiInfo, error) {
-    
-    sqlSelect  := ` SELECT    A.*,
-                              B.module_title  `
-    sqlFrom    := ` FROM      api        AS A
-                    LEFT JOIN api_module AS B ON (A.module_id = B.module_id) `
-    sqlWhere   := ` WHERE  A.deleted_flag = 0 `
+    sqlSelect := `    SELECT  A.*,
+                              B.module_title,
+                              C.biz_title,
+                              D.object_title,
+                              D.object_code,
+                              D.object_type,
+                              E.oam_title,
+                              E.oam_type,
+                              E.oam_code,
+                              E.sql_type,
+                              E.sql_statement,
+                              E.sql_count,
+                              E.oam_desc `
+    sqlFrom    := ` FROM      api            AS A
+                    LEFT JOIN api_module     AS B ON (A.module_id = B.module_id)
+                    LEFT JOIN biz            AS C ON (A.biz_id = C.biz_id)
+                    LEFT JOIN biz_object     AS D ON (A.biz_id = D.biz_id AND A.object_id = D.object_id)
+                    LEFT JOIN biz_object_oam AS E ON (A.biz_id = E.biz_id AND A.object_id = E.object_id AND A.oam_id = E.oam_id)`
+    sqlWhere   := ` WHERE  A.deleted_flag = 0  `
     sqlOrderBy := " ORDER BY A.module_id, A.api_id ASC "
     datalist := make([]viewmodels.ApiInfo, 0)
     err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
@@ -97,11 +138,25 @@ func (d *ApiRepo) GetAll() ([]viewmodels.ApiInfo, error) {
 }
 
 func (d *ApiRepo) GetById(moduleId, apiId int64) (*viewmodels.ApiInfo, error) {
-    sqlSelect := ` SELECT    A.*,
-                             B.module_title  `
-    sqlFrom   := ` FROM      api        AS A
-                   LEFT JOIN api_module AS B ON (A.module_id = B.module_id) `
-    sqlWhere  := ` WHERE  A.deleted_flag = 0 `
+    sqlSelect := `    SELECT  A.*,
+                              B.module_title,
+                              C.biz_title,
+                              D.object_title,
+                              D.object_code,
+                              D.object_type,
+                              E.oam_title,
+                              E.oam_type,
+                              E.oam_code,
+                              E.sql_type,
+                              E.sql_statement,
+                              E.sql_count,
+                              E.oam_desc `
+    sqlFrom    := ` FROM      api            AS A
+                    LEFT JOIN api_module     AS B ON (A.module_id = B.module_id)
+                    LEFT JOIN biz            AS C ON (A.biz_id = C.biz_id)
+                    LEFT JOIN biz_object     AS D ON (A.biz_id = D.biz_id AND A.object_id = D.object_id)
+                    LEFT JOIN biz_object_oam AS E ON (A.biz_id = E.biz_id AND A.object_id = E.object_id AND A.oam_id = E.oam_id)`
+    sqlWhere   := ` WHERE  A.deleted_flag = 0  `
     sqlWhere  += fmt.Sprintf(" AND A.module_id = %d", moduleId)
     sqlWhere  += fmt.Sprintf(" AND A.api_id = %d", apiId)
     

+ 0 - 220
repositories/api_trans_unit_repo.go

@@ -1,220 +0,0 @@
-package repositories
-
-import (
-    "fmt"
-    "time"
-    "xorm.io/xorm"
-    "xps/datamodels"
-    "xps/viewmodels"
-)
-
-type ApiTransUnitRepo struct {
-    engine *xorm.Engine
-}
-
-func NewApiTransUnitRepo(engine *xorm.Engine) *ApiTransUnitRepo {
-    return &ApiTransUnitRepo{
-        engine: engine,
-    }
-}
-
-func (d *ApiTransUnitRepo) GetPage(m map[string]interface{}) (*viewmodels.PageResult, error) {
-    limit := m["limit"].(int)
-    page  := m["page"].(int)
-    
-    sqlSelect := ` SELECT     A.*,
-                              B.model_title,
-                              C.object_title,
-                              C.object_code  `
-    sqlFrom   := ` FROM       ps_api_trans_unit AS A
-                   LEFT  JOIN ds_model          AS B ON (A.model_id = B.model_id)
-                   LEFT  JOIN ds_object         AS C ON (A.model_id = C.model_id AND A.object_id = C.object_id)`
-    sqlWhere  := ` WHERE 1 = 1  AND A.deleted_flag = 0 `
-    
-    if apiId, ok := m["apiId"]; ok {
-        sqlWhere += ` AND A.api_id = `+ fmt.Sprintf("%d", apiId)
-    }
-    
-    if keywords, ok := m["keywords"]; ok {
-        sqlWhere += ` AND C.object_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
-    }
-    
-    sqlCount := ` SELECT COUNT(*) `
-    total, err1 := d.engine.SQL(sqlCount + sqlFrom + sqlWhere).Count(new(datamodels.ApiTransUnit))
-    if err1 != nil {
-        return nil, err1
-    }
-    sqlOrderBy := " ORDER BY A.atu_id ASC "
-    
-    pageStart  := (page - 1) * limit
-    sqlLimit   := fmt.Sprintf(" LIMIT %d OFFSET %d ", limit, pageStart)
-    
-    datalist := make([]datamodels.ApiTransUnit, 0)
-    err2 := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy + sqlLimit).Find(&datalist)
-    if err2 != nil {
-        return nil, err2
-    }
-    
-    pageResult := &viewmodels.PageResult{}
-    pageResult.Data     = datalist
-    pageResult.Total    = total
-    pageResult.PageSize = limit
-    pageResult.Page     = page
-    return pageResult, nil
-}
-
-func (d *ApiTransUnitRepo) GetList(m map[string]interface{}) ([]viewmodels.ApiTransUnitInfo, error) {
-    sqlSelect := ` SELECT     A.*,
-                              B.model_title,
-                              C.object_title,
-                              C.object_code,
-                              D.oam_title,
-                              D.oam_code,
-                              D.oam_type,
-                              D.sql_type,
-                              D.sql_statement,
-                              D.sql_select,
-                              D.sql_from,
-                              D.sql_where,
-                              D.sql_order,
-                              D.oam_desc `
-    sqlFrom   := ` FROM       ps_api_trans_unit AS A
-                   LEFT  JOIN ds_model          AS B ON (A.model_id = B.model_id)
-                   LEFT  JOIN ds_object         AS C ON (A.model_id = C.model_id AND A.object_id = C.object_id)
-                   LEFT  JOIN ds_object_oam     AS D ON (A.model_id = D.model_id AND A.object_id = D.object_id AND A.oam_id = D.oam_id)`
-    sqlWhere  := ` WHERE A.deleted_flag = 0 `
-    sqlOrderBy := " ORDER BY A.api_id, A.sort_no ASC "
-    if apiId, ok := m["apiId"]; ok {
-        sqlWhere += ` AND A.api_id = `+ fmt.Sprintf("%d", apiId)
-    }
-    
-    if keywords, ok := m["keywords"]; ok {
-        sqlWhere += ` AND C.object_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
-    }
-    
-    datalist := make([]viewmodels.ApiTransUnitInfo, 0)
-    err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
-    if err != nil {
-        return nil, err
-    } else {
-        return datalist, nil
-    }
-}
-
-func (d *ApiTransUnitRepo) GetAll() ([]viewmodels.ApiTransUnitInfo, error) {
-    sqlSelect := ` SELECT     A.*,
-                              B.model_title,
-                              C.object_title,
-                              C.object_code,
-                              D.oam_title,
-                              D.oam_code,
-                              D.oam_type,
-                              D.sql_type,
-                              D.sql_statement,
-                              D.sql_select,
-                              D.sql_from,
-                              D.sql_where,
-                              D.sql_order,
-                              D.oam_desc `
-    sqlFrom   := ` FROM       ps_api_trans_unit AS A
-                   LEFT  JOIN ds_model          AS B ON (A.model_id = B.model_id)
-                   LEFT  JOIN ds_object         AS C ON (A.model_id = C.model_id AND A.object_id = C.object_id)
-                   LEFT  JOIN ds_object_oam     AS D ON (A.model_id = D.model_id AND A.object_id = D.object_id AND A.oam_id = D.oam_id)`
-    sqlWhere  := ` WHERE A.deleted_flag = 0 `
-    sqlOrderBy := " ORDER BY A.api_id, A.sort_no ASC "
-    datalist := make([]viewmodels.ApiTransUnitInfo, 0)
-    err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
-    if err != nil {
-        return nil, err
-    } else {
-        return datalist, nil
-    }
-}
-
-func (d *ApiTransUnitRepo) GetListById(moduleId, apiId int64) ([]viewmodels.ApiTransUnitInfo, error) {
-    sqlSelect := ` SELECT     A.*,
-                              B.model_title,
-                              C.object_title,
-                              C.object_code,
-                              D.oam_title,
-                              D.oam_code,
-                              D.oam_type,
-                              D.sql_type,
-                              D.sql_statement,
-                              D.sql_select,
-                              D.sql_from,
-                              D.sql_where,
-                              D.sql_order,
-                              D.oam_desc `
-    sqlFrom   := ` FROM       ps_api_trans_unit AS A
-                   LEFT  JOIN ds_model          AS B ON (A.model_id = B.model_id)
-                   LEFT  JOIN ds_object         AS C ON (A.model_id = C.model_id AND A.object_id = C.object_id)
-                   LEFT  JOIN ds_object_oam     AS D ON (A.model_id = D.model_id AND A.object_id = D.object_id AND A.oam_id = D.oam_id)`
-    sqlWhere  := ` WHERE A.deleted_flag = 0 `
-    sqlWhere  += ` AND A.module_id = `+ fmt.Sprintf("%d", moduleId)
-    sqlWhere  += ` AND A.api_id    = `+ fmt.Sprintf("%d", apiId)
-    sqlOrderBy := " ORDER BY A.atu_id ASC "
-    
-    datalist := make([]viewmodels.ApiTransUnitInfo, 0)
-    err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
-    if err != nil {
-        return nil, err
-    } else {
-        return datalist, nil
-    }
-}
-
-func (d *ApiTransUnitRepo) GetById(moduleId, apiId, atuId int64) (*viewmodels.ApiTransUnitInfo, error) {
-    sqlSelect := ` SELECT     A.*,
-                              B.model_title,
-                              C.object_title,
-                              C.object_code  `
-    sqlFrom   := ` FROM       ps_api_trans_unit AS A
-                   LEFT  JOIN ds_model          AS B ON (A.model_id = B.model_id)
-                   LEFT  JOIN ds_object         AS C ON (A.model_id = C.model_id AND A.object_id = C.object_id)`
-    sqlWhere  := ` WHERE A.deleted_flag = 0 `
-    sqlWhere  += ` AND A.module_id = `+ fmt.Sprintf("%d", moduleId)
-    sqlWhere  += ` AND A.api_id    = `+ fmt.Sprintf("%d", apiId)
-    sqlWhere  += ` AND A.atu_id    = `+ fmt.Sprintf("%d", atuId)
-    
-    data := &viewmodels.ApiTransUnitInfo{}
-    has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
-    if !has || err != nil {
-        return nil, err
-    } else {
-        return data, nil
-    }
-}
-
-func (d *ApiTransUnitRepo) Create(data *datamodels.ApiTransUnit) error {
-    _, err := d.engine.Insert(data)
-    return err
-}
-
-func (d *ApiTransUnitRepo) Update(data *datamodels.ApiTransUnit) error {
-    moduleId := data.ModuleId
-    apiId    := data.ApiId
-    atuId    := data.AtuId
-    
-    data.UpdatedAt = time.Now()
-    _, err := d.engine.
-        Where("module_id = ?", moduleId).
-        Where("api_id = ?", apiId).
-        Where("atu_id = ?", atuId).
-        Update(data)
-    return err
-}
-
-func (d *ApiTransUnitRepo) Delete(m map[string]interface{}) error {
-    moduleId  := m["moduleId"].(int64)
-    apiId     := m["apiId"].(int64)
-    atuId     := m["atuId"].(int64)
-    
-    data := &datamodels.ApiTransUnit{}
-    _, err := d.engine.
-        Where("module_id = ?", moduleId).
-        Where("api_id = ?", apiId).
-        Where("atu_id = ?", atuId).
-        Delete(data)
-    return err
-}

+ 44 - 25
repositories/data_bus_rebo.go

@@ -5,6 +5,7 @@ import (
     "fmt"
     "time"
     "xorm.io/xorm"
+    "xps/cache"
     "xps/datamodels"
     "xps/viewmodels"
 )
@@ -19,12 +20,11 @@ func NewDataBusRepo(engine *xorm.Engine) *DataBusRepo {
     }
 }
 
-func (d *DataBusRepo) GetPage(sqlSelect, sqlFrom, sqlWhere, sqlOrderBy string, m map[string]interface{}) (*viewmodels.PageResult, error) {
-    limit     := m["limit"].(int)
-    page      := m["page"].(int)
+func (d *DataBusRepo) GetPage(sqlStatement, sqlCount string, m map[string]interface{}) (*viewmodels.PageResult, error) {
+    limit := m["limit"].(int)
+    page  := m["page"].(int)
     
-    sqlCount    := ` SELECT COUNT(*) `
-    _, err1 := d.engine.Exec(sqlCount + sqlFrom + sqlWhere)
+    _, err1 := d.engine.Exec(sqlCount)
     if err1 != nil {
         return nil, err1
     }
@@ -33,7 +33,7 @@ func (d *DataBusRepo) GetPage(sqlSelect, sqlFrom, sqlWhere, sqlOrderBy string, m
     sqlLimit   := fmt.Sprintf(" LIMIT %d OFFSET %d ", limit, pageStart)
     
     datalist := make([]datamodels.App, 0)
-    err2 := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy + sqlLimit).Find(&datalist)
+    err2 := d.engine.SQL(sqlStatement + sqlLimit).Find(&datalist)
     if err2 != nil {
         return nil, err2
     }
@@ -46,22 +46,21 @@ func (d *DataBusRepo) GetPage(sqlSelect, sqlFrom, sqlWhere, sqlOrderBy string, m
     return pageResult, nil
 }
 
-func (d *DataBusRepo) GetList(sqlSelect, sqlFrom, sqlWhere, sqlOrderBy string, m map[string]interface{}) ([]map[string]interface{}, error) {
-    results, err := d.engine.QueryInterface(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy)
+func (d *DataBusRepo) GetList(sqlStatement string, m map[string]interface{}) ([]map[string]interface{}, error) {
+    results, err := d.engine.QueryInterface(sqlStatement)
     if err != nil {
         return nil, err
     }
     return results, nil
 }
 
-func (d *DataBusRepo) GetById(statement string, fields map[string]interface{})([]map[string]interface{}, error){
-    
-    sql := statement
+func (d *DataBusRepo) GetById(sqlStatement string, fields map[string]interface{})(map[string]interface{}, error){
+    sql := sqlStatement
     sql += " WHERE 1 = 1"
     
-    // for fieldName, fieldValue := range fields {
-    //    sql += fmt.Sprintf(" AND %v = %v", fieldName, fieldValue)
-    // }
+    for fieldName, fieldValue := range fields {
+        sql += fmt.Sprintf(" AND %v = %v", fieldName, fieldValue)
+    }
     results, err   := d.engine.QueryInterface(sql)
     
     if err != nil {
@@ -71,10 +70,15 @@ func (d *DataBusRepo) GetById(statement string, fields map[string]interface{})([
         return nil, errors.New(" 主键不唯一")
     }
     
-    return results, nil
+    return results[0], nil
 }
 
-func (d *DataBusRepo) Create(object *viewmodels.ModelObjectDataInfo, values map[string]interface{}) error {
+func (d *DataBusRepo) Create(objectCode string, values map[string]interface{}) error {
+    object, err1 := cache.GetModelObjectData(objectCode)
+    if err1 == nil {
+        return err1
+    }
+    
     tableName := object.ObjectCode
     fields    := object.Attrs
     
@@ -99,18 +103,23 @@ func (d *DataBusRepo) Create(object *viewmodels.ModelObjectDataInfo, values map[
     sqlFields += ") "
     sqlValues += ") "
     
-    _, err := d.engine.Exec(sql + sqlFields + sqlValues)
-    return err
+    _, err2 := d.engine.Exec(sql + sqlFields + sqlValues)
+    return err2
 }
 
-func (d *DataBusRepo) Update(object *viewmodels.ModelObjectDataInfo, values map[string]interface{}) error {
+func (d *DataBusRepo) Update(objectCode string, values map[string]interface{}) error {
+    object, err1 := cache.GetModelObjectData(objectCode)
+    if err1 == nil {
+        return err1
+    }
+    
     tableName := object.ObjectCode
     fields    := object.Attrs
     
     sql := fmt.Sprintf("UPDATE table %s ", tableName)
     
-    sqlFieldSets   := "SET "
-    sqlWhere := "WHERE 1 = 1"
+    sqlFieldSets := " SET "
+    sqlWhere     := " WHERE 1 = 1 "
     for idx, field := range fields {
         fieldName := field.AttrCode
         fieldValue, ok := values[fieldName]
@@ -133,14 +142,19 @@ func (d *DataBusRepo) Update(object *viewmodels.ModelObjectDataInfo, values map[
     return err
 }
 
-func (d *DataBusRepo) Patch(object *viewmodels.ModelObjectDataInfo, values map[string]interface{}) error {
+func (d *DataBusRepo) Patch(objectCode string, values map[string]interface{}) error {
+    object, err1 := cache.GetModelObjectData(objectCode)
+    if err1 == nil {
+        return err1
+    }
+    
     tableName := object.ObjectCode
     fields    := object.Attrs
     
     sql := fmt.Sprintf("UPDATE table %s ", tableName)
     
-    sqlFieldSets   := "SET "
-    sqlWhere := "WHERE 1 = 1"
+    sqlFieldSets := "SET "
+    sqlWhere     := "WHERE 1 = 1"
     for idx, field := range fields {
         fieldName := field.AttrCode
         fieldValue, ok := values[fieldName]
@@ -164,7 +178,12 @@ func (d *DataBusRepo) Patch(object *viewmodels.ModelObjectDataInfo, values map[s
 }
 
 
-func (d *DataBusRepo) Delete(object *viewmodels.ModelObjectDataInfo, values map[string]interface{}) error {
+func (d *DataBusRepo) Delete(objectCode string, values map[string]interface{}) error {
+    object, err1 := cache.GetModelObjectData(objectCode)
+    if err1 == nil {
+        return err1
+    }
+    
     tableName := object.ObjectCode
     fields    := object.Attrs
     

+ 112 - 72
service/api_gateway_service.go

@@ -1,14 +1,17 @@
 package service
 
 import (
-    "errors"
     "xps/cache"
     "xps/datasource"
     "xps/repositories"
+    "xps/viewmodels"
 )
 
 type ApiGatewayService interface {
-    Get(apiCode string, m map[string]interface{})([]map[string]interface{}, error)
+    Get(apiCode string, m map[string]interface{})(map[string]interface{}, error)
+    GetPage(apiCode string, m map[string]interface{})(*viewmodels.PageResult, error)
+    GetList(apiCode string, m map[string]interface{})([]map[string]interface{}, error)
+    
     Create(apiCode string, m map[string]interface{})error
     Update(apiCode string, m map[string]interface{})error
     Patch(apiCode string, m map[string]interface{})error
@@ -25,92 +28,129 @@ func NewApiGatewayService() ApiGatewayService {
     }
 }
 
-func (a *apiGatewayService) Get(apiCode string, m map[string]interface{}) ([]map[string]interface{}, error) {
-    apiInfo, err1 := cache.GetApiData(apiCode)
+func (a *apiGatewayService) Get(apiCode string, m map[string]interface{}) (map[string]interface{}, error) {
+    apiDef, err1 := cache.GetApiData(apiCode)
     if err1 != nil{
         return nil, err1
     }
     
-    transUnits := apiInfo.TransUnits
-    if len(transUnits) > 0 {
-        trans := transUnits[0]
-        oamType      := trans.OamType
-        sqlStatement := trans.SqlStatement
-        sqlSelect    := trans.SqlSelect
-        sqlFrom      := trans.SqlFrom
-        sqlWhere     := trans.SqlWhere
-        sqlOrder     := trans.SqlOrder
-        
-        if oamType == 1 {
-           return a.dataBus.GetById(sqlStatement, m)
-        }
-        
-        if oamType == 2 {
-            return a.dataBus.GetList(sqlSelect, sqlFrom, sqlWhere, sqlOrder, m)
-        }
-        
-        return a.dataBus.GetList(sqlSelect, sqlFrom, sqlWhere, sqlOrder, m)
-    }
-    
-    return nil, errors.New("API交易数据不完整")
+    objectCode := apiDef.ObjectCode
+    _, err2 := cache.GetBizObjectData(objectCode)
+    if err2 != nil {
+        return nil, err2
+    }
+    sqlStatement := apiDef.SqlStatement
+    
+    return a.dataBus.GetById(sqlStatement, m)
+}
+
+func (a *apiGatewayService) GetList(apiCode string, m map[string]interface{}) ([]map[string]interface{}, error) {
+    apiDef, err1 := cache.GetApiData(apiCode)
+    if err1 != nil{
+        return nil, err1
+    }
+    
+    objectCode := apiDef.ObjectCode
+    _, err2 := cache.GetBizObjectData(objectCode)
+    if err2 != nil {
+        return nil, err2
+    }
+    sqlStatement := apiDef.SqlStatement
+    
+    return a.dataBus.GetList(sqlStatement, m)
 }
 
-func (a *apiGatewayService) Handle(apiCode string, action int, m map[string]interface{}) error{
-   apiInfo, err1 := cache.GetApiData(apiCode)
-   if err1 == nil{
-       return err1
-   }
-   
-   transUnits := apiInfo.TransUnits
-   for _, transUnit := range transUnits {
-       objectCode := transUnit.ObjectCode
-       
-       objectInfo, err2 := cache.GetModelObjectData(objectCode)
-       if err2 == nil {
-           return err2
-       }
-       
-       if action == 1 {
-           err5 := a.dataBus.Create(objectInfo, m)
-           if err5 == nil {
-               return err5
-           }
-       }
-       if action == 2 {
-           err5 := a.dataBus.Update(objectInfo, m)
-           if err5 == nil {
-               return err5
-           }
-       }
-       if action == 3 {
-           err5 := a.dataBus.Patch(objectInfo, m)
-           if err5 == nil {
-               return err5
-           }
-       }
-       if action == 4 {
-           err5 := a.dataBus.Delete(objectInfo, m)
-           if err5 == nil {
-               return err5
-           }
-       }
-   }
-   
-   return nil
+func (a *apiGatewayService) GetPage(apiCode string, m map[string]interface{}) (*viewmodels.PageResult, error) {
+    apiDef, err1 := cache.GetApiData(apiCode)
+    if err1 != nil{
+        return nil, err1
+    }
+    
+    objectCode := apiDef.ObjectCode
+    _, err2 := cache.GetBizObjectData(objectCode)
+    if err2 != nil {
+        return nil, err2
+    }
+    
+    sqlStatement := apiDef.SqlStatement
+    sqlCount     := apiDef.SqlCount
+    return a.dataBus.GetPage(sqlStatement, sqlCount, m)
 }
 
 func (a *apiGatewayService) Create(apiCode string, m map[string]interface{}) error {
-    return a.Handle(apiCode, 1, m)
+    apiDef, err1 := cache.GetApiData(apiCode)
+    if err1 != nil{
+        return err1
+    }
+    
+    objectCode := apiDef.ObjectCode
+    _, err2 := cache.GetBizObjectData(objectCode)
+    if err2 != nil {
+        return err2
+    }
+    
+    err3 := a.dataBus.Create(objectCode, m)
+    if err3 != nil {
+        return err3
+    }
+    
+    return nil
 }
 
 func (a *apiGatewayService) Update(apiCode string, m map[string]interface{}) error {
-    return a.Handle(apiCode, 2, m)
+    apiDef, err1 := cache.GetApiData(apiCode)
+    if err1 != nil{
+        return err1
+    }
+    
+    objectCode := apiDef.ObjectCode
+    _, err2 := cache.GetBizObjectData(objectCode)
+    if err2 != nil {
+        return err2
+    }
+    
+    err3 := a.dataBus.Update(objectCode, m)
+    if err3 != nil {
+        return err3
+    }
+    
+    return nil
 }
 
 func (a *apiGatewayService) Patch(apiCode string, m map[string]interface{}) error {
-    return a.Handle(apiCode, 3, m)
+    apiDef, err1 := cache.GetApiData(apiCode)
+    if err1 != nil{
+        return err1
+    }
+    
+    objectCode := apiDef.ObjectCode
+    _, err2 := cache.GetBizObjectData(objectCode)
+    if err2 != nil {
+        return err2
+    }
+    
+    err3 := a.dataBus.Patch(objectCode, m)
+    if err3 != nil {
+        return err3
+    }
+    return nil
 }
 
 func (a *apiGatewayService) Delete(apiCode string, m map[string]interface{}) error {
-    return a.Handle(apiCode, 4, m)
+    apiDef, err1 := cache.GetApiData(apiCode)
+    if err1 != nil{
+        return err1
+    }
+    
+    objectCode := apiDef.ObjectCode
+    _, err2 := cache.GetBizObjectData(objectCode)
+    if err2 != nil {
+        return err2
+    }
+    
+    err3 := a.dataBus.Delete(objectCode, m)
+    if err3 != nil {
+        return err3
+    }
+    return nil
 }

+ 1 - 21
service/api_service.go

@@ -22,13 +22,11 @@ type ApiService interface {
 
 type apiService struct {
     apiRepo *repositories.ApiRepo
-    transRepo *repositories.ApiTransUnitRepo
 }
 
 func NewApiService() ApiService {
     return &apiService{
         apiRepo: repositories.NewApiRepo(datasource.InstanceMaster()),
-        transRepo: repositories.NewApiTransUnitRepo(datasource.InstanceMaster()),
     }
 }
 
@@ -91,26 +89,8 @@ func (s *apiService) CacheApiData(moduleId, apiId int64) error {
         return nil
     }
     
-    trans, err := s.transRepo.GetListById(moduleId, apiId)
-    if err != nil {
-        return nil
-    }
-    
-    cacheData := &viewmodels.ApiDataInfo{
-        ModuleId:    api.ModuleId,
-        ModuleTitle: api.ModuleTitle,
-        ApiId:       api.ApiId,
-        ApiCode:     api.ApiCode,
-        ApiTitle:    api.ApiTitle,
-        ApiType:     api.ApiType,
-        ApiParams:   api.ApiParams,
-        ApiDesc:     api.ApiDesc,
-        Status:      api.Status,
-        TransUnits: trans,
-    }
-    
     // 缓存数据
-    err = cache.SetApiData(api.ApiCode, cacheData)
+    err = cache.SetApiData(api.ApiCode, api)
     if err != nil {
         return errors.New("Redis缓存Model数据失败")
     }

+ 0 - 148
service/api_trans_unit_service.go

@@ -1,148 +0,0 @@
-package service
-
-import (
-    "errors"
-    "xps/cache"
-    "xps/datamodels"
-    "xps/datasource"
-    "xps/repositories"
-    "xps/viewmodels"
-)
-
-type ApiTransUnitService interface {
-    GetList(m map[string]interface{}) ([]viewmodels.ApiTransUnitInfo, error)
-    GetPage(m map[string]interface{}) (*viewmodels.PageResult, error)
-    GetById(moduleId, apiId, atuId int64) (*viewmodels.ApiTransUnitInfo, error)
-    Create(d *datamodels.ApiTransUnit) error
-    Update(d *datamodels.ApiTransUnit) error
-    Delete(m map[string]interface{}) error
-    GenerateParams(apiCode string)(map[string]interface{}, error)
-}
-
-type apiTransUnitService struct {
-    apiRepo *repositories.ApiRepo
-    transRepo *repositories.ApiTransUnitRepo
-}
-
-
-func NewApiTransUnitService() ApiTransUnitService {
-    return &apiTransUnitService{
-        apiRepo: repositories.NewApiRepo(datasource.InstanceMaster()),
-        transRepo: repositories.NewApiTransUnitRepo(datasource.InstanceMaster()),
-    }
-}
-
-func (s *apiTransUnitService) GetList(m map[string]interface{}) ([]viewmodels.ApiTransUnitInfo, error) {
-    return s.transRepo.GetList(m)
-}
-
-func (s *apiTransUnitService) GetPage(m map[string]interface{}) (*viewmodels.PageResult, error) {
-    return s.transRepo.GetPage(m)
-}
-
-func (s *apiTransUnitService) GetById(moduleId, apiId, atuId int64) (*viewmodels.ApiTransUnitInfo, error) {
-    return s.transRepo.GetById(moduleId, apiId, atuId)
-}
-
-func (s *apiTransUnitService) Create(atu *datamodels.ApiTransUnit) error {
-    atu.AtuId = NewID()
-    err := s.transRepo.Create(atu)
-    if err != nil {
-        return err
-    }
-    
-    moduleId := atu.ModuleId
-    apiId    := atu.ApiId
-    return s.CacheApiData(moduleId, apiId)
-}
-
-func (s *apiTransUnitService) Update(atu *datamodels.ApiTransUnit) error {
-    err := s.transRepo.Update(atu)
-    if err != nil {
-        return err
-    }
-    
-    moduleId := atu.ModuleId
-    apiId    := atu.ApiId
-    return s.CacheApiData(moduleId, apiId)
-}
-
-func (s *apiTransUnitService) Delete(m map[string]interface{}) error {
-    return s.transRepo.Delete(m)
-}
-
-func (s *apiTransUnitService) CacheApiData(moduleId, apiId int64) error {
-    api, err := s.apiRepo.GetById(moduleId, apiId)
-    if err != nil {
-        return nil
-    }
-    
-    trans, err := s.transRepo.GetListById(moduleId, apiId)
-    if err != nil {
-        return nil
-    }
-    
-    cacheData := &viewmodels.ApiDataInfo{
-        ModuleId:    api.ModuleId,
-        ModuleTitle: api.ModuleTitle,
-        ApiId:       api.ApiId,
-        ApiCode:     api.ApiCode,
-        ApiTitle:    api.ApiTitle,
-        ApiType:     api.ApiType,
-        ApiParams:   api.ApiParams,
-        ApiDesc:     api.ApiDesc,
-        Status:      api.Status,
-        TransUnits: trans,
-    }
-    
-    // 缓存数据
-    err = cache.SetApiData(api.ApiCode, cacheData)
-    if err != nil {
-        return errors.New("Redis缓存Api数据失败")
-    }
-    
-    return nil
-}
-
-
-func (s *apiTransUnitService) GenerateParams(apiCode string)(map[string]interface{}, error){
-    apiInfo, err1 := cache.GetApiData(apiCode)
-    if err1 != nil {
-        return nil, err1
-    }
-    
-    params := make(map[string]interface{})
-    transUnits := apiInfo.TransUnits
-    for _, transUnit := range transUnits {
-        objectCode := transUnit.ObjectCode
-        objectInfo, err2 := cache.GetModelObjectData(objectCode)
-        if err2 != nil {
-            return nil, err2
-        }
-        
-        attrs := objectInfo.Attrs
-        for _, attr := range attrs {
-            attrCode := attr.AttrCode
-            if _, ok := params[attrCode]; !ok{
-                switch attr.AttrType {
-                case 1: // int
-                   params[attrCode] = 0
-                case 2: // string
-                    params[attrCode] = "test"
-                case 3: // decimal
-                    params[attrCode] = 0.01
-                case 4: // datetime
-                    params[attrCode] = "2020-01-01 10:10:10"
-                case 5: // date
-                    params[attrCode] = "2020-01-01"
-                case 6: // time
-                    params[attrCode] = "10:10:10"
-                default:
-                    params[attrCode] = "NaN"
-                }
-            }
-        }
-    }
-    
-    return params, nil
-}

+ 2 - 30
service/init_service.go

@@ -18,7 +18,6 @@ type initService struct {
     modelObjectRepo         *repositories.ModelObjectRepo
     modelObjectAttrRepo     *repositories.ModelObjectAttrRepo
     apiRepo                 *repositories.ApiRepo
-    apiTransUnitRepo        *repositories.ApiTransUnitRepo
 }
 
 func NewInitService() InitService {
@@ -26,7 +25,6 @@ func NewInitService() InitService {
         modelObjectRepo:        repositories.NewModelObjectRepo(datasource.InstanceMaster()),
         modelObjectAttrRepo:    repositories.NewModelObjectAttrRepo(datasource.InstanceMaster()),
         apiRepo:                repositories.NewApiRepo(datasource.InstanceMaster()),
-        apiTransUnitRepo:       repositories.NewApiTransUnitRepo(datasource.InstanceMaster()),
     }
 }
 
@@ -79,36 +77,10 @@ func (s *initService) CacheApiData() error {
         return nil
     }
     
-    transList, err2 := s.apiTransUnitRepo.GetAll()
-    if err2 != nil {
-        return nil
-    }
-    
     for _, api := range apiList {
-        moduleId := api.ModuleId
-        apiId    := api.ApiId
-        trans := make([]viewmodels.ApiTransUnitInfo, 0)
-        for _, tran := range transList{
-            if tran.ModuleId == moduleId && tran.ApiId == apiId {
-               trans = append(trans, tran)
-            }
-        }
-    
-        cacheData := &viewmodels.ApiDataInfo{
-            ModuleId:    api.ModuleId,
-            ModuleTitle: api.ModuleTitle,
-            ApiId:       api.ApiId,
-            ApiCode:     api.ApiCode,
-            ApiTitle:    api.ApiTitle,
-            ApiType:     api.ApiType,
-            ApiParams:   api.ApiParams,
-            ApiDesc:     api.ApiDesc,
-            Status:      api.Status,
-            TransUnits:  trans,
-        }
-    
+        
         // 缓存数据
-        err3 := cache.SetApiData(api.ApiCode, cacheData)
+        err3 := cache.SetApiData(api.ApiCode, &api)
         if err3 != nil {
             return errors.New("Redis缓存Api数据失败")
         }

+ 0 - 28
viewmodels/api_data_info.go

@@ -1,28 +0,0 @@
-package viewmodels
-
-import "encoding/json"
-
-type ApiDataInfo struct {
-    ModuleId    int64     `json:"moduleId"     xorm:"'module_id'    bigint pk     comment('Module ID')    "`
-    ModuleTitle string    `json:"moduleTitle"  xorm:"'module_title' varchar(127)  comment('Module Title') "`
-    ApiId       int64     `json:"apiId"        xorm:"'api_id'       bigint     pk comment('Api ID')   "`
-    ApiType     int64     `json:"apiType"      xorm:"'api_type'     bigint     pk comment('Api Type') "`
-    ApiTitle    string    `json:"apiTitle"     xorm:"'api_title'    varchar(127)  comment('名称')      "`
-    ApiCode     string    `json:"apiCode"      xorm:"'api_code'     varchar(127)  comment('编码')      "`
-    ApiParams   string    `json:"apiParams"    xorm:"'api_params'   varchar(127)  comment('Param')    "`
-    Status      int64     `json:"status"       xorm:"'status'       bigint        comment('Status')   "`
-    ApiDesc     string    `json:"apiDesc"      xorm:"'api_desc'     varchar(50)   comment('描述')      "`
-    TransUnits  []ApiTransUnitInfo `json:"transUnits"`
-}
-
-func (t *ApiDataInfo) TableName() string {
-    return "ps_api"
-}
-
-func (g *ApiDataInfo) MarshalBinary() (data []byte, err error){
-    return json.Marshal(g)
-}
-
-func (g *ApiDataInfo) UnmarshalBinary(data []byte) (err error){
-    return json.Unmarshal(data, g)
-}

+ 36 - 10
viewmodels/api_info.go

@@ -1,17 +1,43 @@
 package viewmodels
 
+import "encoding/json"
+
 type ApiInfo struct {
-    ModuleId    int64     `json:"moduleId"     xorm:"'module_id'    bigint pk     comment('Module ID')    "`
-    ModuleTitle string    `json:"moduleTitle"  xorm:"'module_title' varchar(127)  comment('Module Title') "`
-    ApiId       int64     `json:"apiId"        xorm:"'api_id'       bigint     pk comment('Api ID')       "`
-    ApiType     int64     `json:"apiType"      xorm:"'api_type'     bigint     pk comment('Api Type')     "`
-    ApiTitle    string    `json:"apiTitle"     xorm:"'api_title'    varchar(127)  comment('名称')          "`
-    ApiCode     string    `json:"apiCode"      xorm:"'api_code'     varchar(127)  comment('编码')          "`
-    ApiParams   string    `json:"apiParams"    xorm:"'api_params'   varchar(127)  comment('Param')         "`
-    Status      int64     `json:"status"       xorm:"'status'       bigint        comment('Status')        "`
-    ApiDesc     string    `json:"apiDesc"      xorm:"'api_desc'     varchar(50)   comment('描述')           "`
+    ModuleId        int64     `json:"moduleId"      xorm:"'module_id'       bigint pk      comment('Module ID')    "`
+    ModuleTitle     string    `json:"moduleTitle"   xorm:"'module_title'    varchar(127)   comment('Module Title') "`
+    ApiId           int64     `json:"apiId"         xorm:"'api_id'          bigint     pk  comment('Api ID')       "`
+    ApiType         int64     `json:"apiType"       xorm:"'api_type'        bigint     pk  comment('Api Type')     "`
+    ApiTitle        string    `json:"apiTitle"      xorm:"'api_title'       varchar(127)   comment('名称')          "`
+    ApiCode         string    `json:"apiCode"       xorm:"'api_code'        varchar(127)   comment('编码')          "`
+    ApiParams       string    `json:"apiParams"     xorm:"'api_params'      varchar(127)   comment('Param')        "`
+    Status          int64     `json:"status"        xorm:"'status'          bigint         comment('Status')       "`
+    ApiDesc         string    `json:"apiDesc"       xorm:"'api_desc'        varchar(50)    comment('描述')          "`
+    ObjectType      int64     `json:"objectType"    xorm:"'object_type'     bigint         comment('Object Type')  "`
+    ObjectGroupId   int64     `json:"objectGroupId" xorm:"'object_group_id' bigint         comment('Object GroupId')"`
+    ObjectId        int64     `json:"objectId"      xorm:"'object_id'       bigint         comment('Object Id')    "`
+    ObjectCode      string    `json:"objectCode"    xorm:"'object_code'     varchar(127)   comment('Object Code')  "`
+    OamId           int64     `json:"oamId"         xorm:"'oam_id'          bigint         comment('Oam Id')       "`
+    OamTitle        string    `json:"oamTitle"      xorm:"'oam_title'       varchar(127)   comment('OAMTitle')       "`
+    OamCode         string    `json:"oamCode"       xorm:"'oam_code'        varchar(127)   comment('OAMCode')        "`
+    OamType         int64     `json:"oamType"       xorm:"'oam_type'        bigint         comment('Oam Type')       "`
+    SqlType         int64     `json:"sqlType"       xorm:"'sql_type'        bigint         comment('Sql Type')       "`
+    SqlStatement    string    `json:"sqlStatement"  xorm:"'sql_statement'   varchar(1023)  comment('Statement')      "`
+    SqlSelect       string    `json:"sqlSelect"     xorm:"'sql_select'      varchar(1023)  comment('Sql Select')     "`
+    SqlFrom         string    `json:"sqlFrom"       xorm:"'sql_from'        varchar(1023)  comment('Sql From')       "`
+    SqlWhere        string    `json:"sqlWhere"      xorm:"'sql_where'       varchar(1023)  comment('Sql Where')      "`
+    SqlOrder        string    `json:"sqlOrder"      xorm:"'sql_order'       varchar(1023)  comment('Sql Order')      "`
+    SqlCount        string    `json:"sqlCount"      xorm:"'sql_count'       varchar(1023)  comment('Sql Count')      "`
+    OamDesc         string    `json:"oamDesc"       xorm:"'oam_desc'        varchar(1023)  comment('描述')            "`
 }
 
 func (t *ApiInfo) TableName() string {
-    return "ps_api"
+    return "api"
+}
+
+func (g *ApiInfo) MarshalBinary() (data []byte, err error){
+    return json.Marshal(g)
+}
+
+func (g *ApiInfo) UnmarshalBinary(data []byte) (err error){
+    return json.Unmarshal(data, g)
 }

+ 1 - 1
viewmodels/api_module_info.go

@@ -9,5 +9,5 @@ type ApiModuleInfo struct {
 }
 
 func (t *ApiModuleInfo) TableName() string {
-    return "ps_module"
+    return "api_module"
 }

+ 0 - 28
viewmodels/api_trans_unit_info.go

@@ -1,28 +0,0 @@
-package viewmodels
-
-
-type ApiTransUnitInfo struct {
-    ModuleId        int64       `json:"moduleId"        xorm:"'module_id'           bigint pk     comment('主键ID')       "`
-    ApiId           int64       `json:"apiId"           xorm:"'api_id'              bigint pk     comment('ApiId')        "`
-    AtuId           int64       `json:"atuId"           xorm:"'atu_id'              bigint pk     comment('AtuId')        "`
-    ModelId         int64       `json:"modelId"         xorm:"'model_id'            bigint        comment('ModelId')      "`
-    ModelTitle      string      `json:"modelTitle"      xorm:"'model_title'         varchar(127)  comment('Model Title')  "`
-    ObjectId        int64       `json:"objectId"        xorm:"'object_id'           bigint        comment('ObjectId')     "`
-    ObjectTitle     string      `json:"objectTitle"     xorm:"'object_title'        varchar(127)  comment('Object Title') "`
-    ObjectCode      string      `json:"objectCode"      xorm:"'object_code'         varchar(127)  comment('Object Code')  "`
-    OamId           int64       `json:"oamId"           xorm:"'oam_id'              bigint        comment('oamId')        "`
-    OamTitle        string      `json:"oamTitle"        xorm:"'oam_title'           varchar(127)  comment('OAMTitle')     "`
-    OamCode         string      `json:"oamCode"         xorm:"'oam_code'            varchar(127)  comment('OAMCode')      "`
-    OamType         int64       `json:"oamType"         xorm:"'oam_type'            bigint        comment('Oam Type')     "`
-    SqlType         int64       `json:"sqlType"         xorm:"'sql_type'            bigint        comment('Sql Type')     "`
-    SqlStatement    string      `json:"sqlStatement"    xorm:"'sql_statement'       varchar(1023) comment('Statement')    "`
-    SqlSelect       string      `json:"sqlSelect"       xorm:"'sql_select'          varchar(1023) comment('Statement')    "`
-    SqlFrom         string      `json:"sqlFrom"         xorm:"'sql_from'            varchar(1023) comment('Statement')    "`
-    SqlWhere        string      `json:"sqlWhere"        xorm:"'sql_where'           varchar(1023) comment('Statement')    "`
-    SqlOrder        string      `json:"sqlOrder"        xorm:"'sql_order'           varchar(1023) comment('Statement')    "`
-    OamDesc         string      `json:"oamDesc"         xorm:"'oam_desc'            varchar(1023) comment('描述')          "`
-}
-
-func (t *ApiTransUnitInfo) TableName() string {
-    return "ps_api_trans_unit"
-}

+ 35 - 5
web/controllers/api_gateway_controller.go

@@ -12,11 +12,13 @@ type ApiGatewayController struct {
 }
 
 func (c *ApiGatewayController) BeforeActivation(b mvc.BeforeActivation) {
-    //b.Handle("GET",         "/{apiCode:string}",              "Get"     )
-    //b.Handle("POST",        "/{apiCode:string}",              "Create"  )
-    //b.Handle("PUT",         "/{apiCode:string}",              "Update"  )
-    //b.Handle("PATCH",       "/{apiCode:string}",              "Patch"   )
-    //b.Handle("DELETE",      "/{apiCode:string}",              "Delete"  )
+    b.Handle("GET",         "/{apiCode:string}",              "Get"     )
+    b.Handle("GET",         "/{apiCode:string}/page",         "GetPage" )
+    b.Handle("GET",         "/{apiCode:string}/list",         "GetList" )
+    b.Handle("POST",        "/{apiCode:string}",              "Create"  )
+    b.Handle("PUT",         "/{apiCode:string}",              "Update"  )
+    b.Handle("PATCH",       "/{apiCode:string}",              "Patch"   )
+    b.Handle("DELETE",      "/{apiCode:string}",              "Delete"  )
 }
 
 func (c *ApiGatewayController) Get(apiCode string)*JsonResult {
@@ -33,6 +35,34 @@ func (c *ApiGatewayController) Get(apiCode string)*JsonResult {
     }
 }
 
+func (c *ApiGatewayController) GetPage(apiCode string)*JsonResult {
+    m := c.buildParams()
+    data, err := c.Service.GetPage(apiCode, m)
+    
+    m2, _ := c.GetJsonData()
+    fmt.Sprintf("%v", m2)
+    
+    if err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("获取成功", data)
+    }
+}
+
+func (c *ApiGatewayController) GetList(apiCode string)*JsonResult {
+    m := c.buildParams()
+    data, err := c.Service.GetList(apiCode, m)
+    
+    m2, _ := c.GetJsonData()
+    fmt.Sprintf("%v", m2)
+    
+    if err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("获取成功", data)
+    }
+}
+
 func (c *ApiGatewayController) Create(apiCode string)*JsonResult {
     m, err := c.GetJsonData()
     if err != nil {

+ 0 - 109
web/controllers/api_trans_unit_controller.go

@@ -1,109 +0,0 @@
-package controllers
-
-import (
-    "github.com/kataras/iris/v12/mvc"
-    "xps/datamodels"
-    "xps/service"
-)
-
-type ApiTransUnitController struct {
-    Base
-    Service service.ApiTransUnitService
-}
-
-func (c *ApiTransUnitController) BeforeActivation(b mvc.BeforeActivation) {
-    b.Handle("GET",         "/",                                                "GetList"       )
-    b.Handle("GET",         "/generate/params/{apiCode:string}",                "GenerateParams")
-    b.Handle("GET",         "/page",                                            "GetPage"       )
-    b.Handle("GET",         "/{moduleId:int64}/{apiId:int64}/{atuId:int64}",    "GetById"       )
-    b.Handle("POST",        "/add",                                             "Create"        )
-    b.Handle("PUT",         "/update",                                          "Update"        )
-    b.Handle("DELETE",      "/{moduleId:int64}/{apiId:int64}/{atuId:int64}",    "DeleteByID"    )
-}
-
-func (c *ApiTransUnitController) GetList() *JsonResult {
-    params  := c.buildParams()
-    data, err := c.Service.GetList(params)
-    if err != nil {
-        return ResultErr(err.Error(), nil)
-    } else {
-        return ResultOk("获取成功", data)
-    }
-}
-
-func (c *ApiTransUnitController) GetPage() *JsonResult {
-    params  := c.buildParams()
-    data, err := c.Service.GetPage(params)
-    if err != nil {
-        return ResultErr(err.Error(), nil)
-    } else {
-        return ResultOk("获取成功", data)
-    }
-}
-
-func (c *ApiTransUnitController) GetById(moduleId, apiId, atuId int64) *JsonResult {
-    data, err := c.Service.GetById(moduleId, apiId, atuId)
-    if err != nil {
-        return ResultErr(err.Error(), nil)
-    } else {
-        return ResultOk("获取成功", data)
-    }
-}
-
-func (c *ApiTransUnitController) Create() *JsonResult {
-    userId := c.GetCurUserId()
-    
-    atu    := datamodels.ApiTransUnit{}
-    if err := c.Ctx.ReadJSON(&atu); err != nil {
-        return ResultErr("读取数据失败", nil)
-    }
-    
-    atu.CreatedBy = userId
-    if err := c.Service.Create(&atu); err != nil {
-        return ResultErr(err.Error(), nil)
-    } else {
-        return ResultOk("新增成功", nil)
-    }
-}
-
-
-func (c *ApiTransUnitController) Update() *JsonResult {
-    userId := c.GetCurUserId()
-    
-    atu := datamodels.ApiTransUnit{}
-    if err := c.Ctx.ReadJSON(&atu); err != nil {
-        return ResultErr("读取数据失败", nil)
-    }
-    
-    atu.UpdatedBy = userId
-    if err := c.Service.Update(&atu); err != nil {
-        return ResultErr(err.Error(), nil)
-    } else {
-        return ResultOk("更新成功", nil)
-    }
-}
-
-func (c *ApiTransUnitController) DeleteByID(moduleId, apiId, atuId int64) *JsonResult {
-    userId := c.GetCurUserId()
-    
-    m := make(map[string]interface{})
-    m["moduleId"]  = moduleId
-    m["apiId"]     = apiId
-    m["atuId"]     = atuId
-    m["deletedBy"] = userId
-    if err := c.Service.Delete(m); err != nil {
-        return ResultErr(err.Error(), nil)
-    } else {
-        return ResultOk("删除成功", nil)
-    }
-}
-
-func (c *ApiTransUnitController) GenerateParams(apiCode string) *JsonResult {
-    data, err := c.Service.GenerateParams(apiCode);
-    if err != nil {
-        return ResultErr(err.Error(), nil)
-    } else {
-        return ResultOk("生成成功", data)
-    }
-}
-

+ 0 - 4
web/router/routes.go

@@ -233,10 +233,6 @@ func Configure(b *bootstrap.Bootstrapper) {
 		apiLogApp.Register(apiLogService)
 		apiLogApp.Handle(new(controllers.ApiLogController))
 		
-		atuService := service.NewApiTransUnitService()
-		apiAtuApp := mvc.New(apiParty.Party("/atu"))
-		apiAtuApp.Register(atuService)
-		apiAtuApp.Handle(new(controllers.ApiTransUnitController))
 	}
 	
 	// x