houyaf vor 3 Jahren
Ursprung
Commit
3aef974ec0

+ 5 - 4
datamodels/api.go

@@ -3,12 +3,13 @@ package datamodels
 import "time"
 
 type Api struct {
-    ModId       int64     `json:"modId"             xorm:"'mod_id'       bigint     pk comment('主键ID')   "`
-    ApiId       int64     `json:"apiId"             xorm:"'api_id'       bigint     pk comment('主键ID')   "`
+    ModId       int64     `json:"modId"             xorm:"'mod_id'       bigint     pk comment('Module ID' "`
+    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')  "`
+    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('描述')      "`
     CreatedBy   int64     `json:"createdBy"         xorm:"'created_by'"`
     CreatedAt   time.Time `json:"createdAt"         xorm:"'created_at'"`

+ 12 - 15
datamodels/api_trans_unit.go

@@ -3,21 +3,18 @@ package datamodels
 import "time"
 
 type ApiTransUnit struct {
-    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:"modelIdId"     xorm:"'model_id'     bigint      pk comment('ModelId')   "`
-    ObjectId    int64       `json:"objectId"      xorm:"'object_id'    bigint      pk comment('ObjectId')  "`
-    OamId       int64       `json:"oamId"         xorm:"'oam_id'       bigint      pk comment('OamId')     "`
-    AtuTitle    string      `json:"atuTitle"      xorm:"'atu_title'    varchar(127)   comment('AtuTitle')  "`
-    AtuType     string      `json:"atuType"       xorm:"'atu_type'     bigint         comment('AtuType')   "`
-    AtuDesc     string      `json:"atuDesc"       xorm:"'atu_desc'     varchar(2047)  comment('AtuDesc')   "`
-    CreatedBy   int64     `json:"createdBy"         xorm:"'created_by'"`
-    CreatedAt   time.Time `json:"createdAt"         xorm:"'created_at'"`
-    UpdatedBy   int64     `json:"updatedBy"         xorm:"'updated_by'"`
-    UpdatedAt   time.Time `json:"updatedAt"         xorm:"'updated_at'"`
-    DeletedFlag int64     `json:"deletedFlag"       xorm:"'deleted_flag'"`
-    DeletedBy   int64     `json:"deletedBy"         xorm:"'deleted_by'"`
-    DeletedAt   time.Time `json:"deletedAt"         xorm:"'deleted_at'"`
+    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')     "`
+    ObjectId        int64       `json:"objectId"        xorm:"'object_id'           bigint comment('ObjectId')    "`
+    ObjectOamType   int64       `json:"objectOamType"   xorm:"'object_oam_type'     bigint comment('ObjectOamType')"`
+    CreatedBy       int64       `json:"createdBy"       xorm:"'created_by'"`
+    CreatedAt       time.Time   `json:"createdAt"       xorm:"'created_at'"`
+    UpdatedBy       int64       `json:"updatedBy"       xorm:"'updated_by'"`
+    UpdatedAt       time.Time   `json:"updatedAt"       xorm:"'updated_at'"`
+    DeletedFlag     int64       `json:"deletedFlag"     xorm:"'deleted_flag'"`
+    DeletedBy       int64       `json:"deletedBy"       xorm:"'deleted_by'"`
+    DeletedAt       time.Time   `json:"deletedAt"       xorm:"'deleted_at'"`
 }
 
 func (t *ApiTransUnit) TableName() string {

+ 17 - 9
repositories/api_repo.go

@@ -22,8 +22,10 @@ func (d *ApiRepo) GetPage(m map[string]interface{}) (*viewmodels.PageResult, err
     limit := m["limit"].(int)
     page  := m["page"].(int)
     
-    sqlSelect := ` SELECT A.*                 `
-    sqlFrom   := ` FROM   ps_api   AS A       `
+    sqlSelect := ` SELECT    A.*,
+                             B.mod_title  `
+    sqlFrom   := ` FROM      ps_api    AS A
+                   LEFT JOIN ps_module AS B ON (A.mod_id = B.mod_id) `
     sqlWhere  := ` WHERE  A.deleted_flag = 0  `
     if keywords, ok := m["keywords"]; ok {
         sqlWhere += ` AND A.api_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
@@ -56,8 +58,10 @@ func (d *ApiRepo) GetPage(m map[string]interface{}) (*viewmodels.PageResult, err
 func (d *ApiRepo) GetList(m map[string]interface{}) ([]viewmodels.ApiInfo, error) {
     modId     := m["modId"].(int64)
     
-    sqlSelect := ` SELECT A.*            `
-    sqlFrom   := ` FROM   ps_api AS A    `
+    sqlSelect := ` SELECT    A.*,
+                             B.mod_title  `
+    sqlFrom   := ` FROM      ps_api    AS A
+                   LEFT JOIN ps_module AS B ON (A.mod_id = B.mod_id) `
     sqlWhere  := ` WHERE  A.deleted_flag = 0 AND A.mod_id =` + fmt.Sprintf("%d", modId)
     if keywords, ok := m["keywords"]; ok {
         sqlWhere += ` AND A.api_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
@@ -74,12 +78,16 @@ func (d *ApiRepo) GetList(m map[string]interface{}) ([]viewmodels.ApiInfo, error
 }
 
 func (d *ApiRepo) GetById(modId, apiId int64) (*viewmodels.ApiInfo, error) {
+    sqlSelect := ` SELECT    A.*,
+                             B.mod_title  `
+    sqlFrom   := ` FROM      ps_api    AS A
+                   LEFT JOIN ps_module AS B ON (A.mod_id = B.mod_id) `
+    sqlWhere  := ` WHERE  A.deleted_flag = 0 AND A.mod_id =` + fmt.Sprintf("%d", modId)
+    sqlWhere  += fmt.Sprintf(" AND A.api_id = %d", apiId)
+    
     data := &viewmodels.ApiInfo{}
-    ok, err := d.engine.
-        Where("mod_id = ?", modId).
-        Where("api_id = ?", apiId).
-        Get(data)
-    if !ok && err == nil {
+    has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
+    if !has || err != nil {
         return nil, err
     } else {
         return data, nil

+ 17 - 16
repositories/api_trans_unit_repo.go

@@ -23,9 +23,11 @@ func (d *ApiTransUnitRepo) GetPage(m map[string]interface{}) (*viewmodels.PageRe
     page  := m["page"].(int)
     
     sqlSelect := ` SELECT     A.*,
-                              B.api_title `
+                              B.model_title,
+                              C.object_title `
     sqlFrom   := ` FROM       ps_api_trans_unit AS A
-                   LEFT  JOIN ps_api            AS B ON (A.api_id = B.api_id)`
+                   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 {
@@ -33,7 +35,7 @@ func (d *ApiTransUnitRepo) GetPage(m map[string]interface{}) (*viewmodels.PageRe
     }
     
     if keywords, ok := m["keywords"]; ok {
-        sqlWhere += ` AND A.atu_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
+        sqlWhere += ` AND C.object_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
     }
     
     sqlCount := ` SELECT COUNT(*) `
@@ -62,18 +64,19 @@ func (d *ApiTransUnitRepo) GetPage(m map[string]interface{}) (*viewmodels.PageRe
 
 func (d *ApiTransUnitRepo) GetList(m map[string]interface{}) ([]viewmodels.ApiTransUnitInfo, error) {
     sqlSelect := ` SELECT     A.*,
-                              B.api_title `
+                              B.model_title,
+                              C.object_title `
     sqlFrom   := ` FROM       ps_api_trans_unit AS A
-                   LEFT  JOIN ps_api            AS B ON (A.api_id = B.api_id)`
+                   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 A.atu_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
+        sqlWhere += ` AND C.object_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
     }
     sqlOrderBy := " ORDER BY A.atu_id ASC "
     
@@ -88,11 +91,13 @@ func (d *ApiTransUnitRepo) GetList(m map[string]interface{}) ([]viewmodels.ApiTr
 
 func (d *ApiTransUnitRepo) GetListById(apiId int64) ([]viewmodels.ApiTransUnitInfo, error) {
     sqlSelect := ` SELECT     A.*,
-                              B.api_title `
+                              B.model_title,
+                              C.object_title `
     sqlFrom   := ` FROM       ps_api_trans_unit AS A
-                   LEFT  JOIN ps_api            AS B ON (A.api_id = B.api_id)`
+                   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 `
-    sqlWhere += ` AND A.api_id = `+ fmt.Sprintf("%d", apiId)
+    sqlWhere  += ` AND A.api_id = `+ fmt.Sprintf("%d", apiId)
     sqlOrderBy := " ORDER BY A.atu_id ASC "
     
     datalist := make([]viewmodels.ApiTransUnitInfo, 0)
@@ -137,15 +142,11 @@ func (d *ApiTransUnitRepo) Update(data *datamodels.ApiTransUnit) error {
 func (d *ApiTransUnitRepo) Delete(m map[string]interface{}) error {
     apiId     := m["apiId"].(int64)
     atuId     := m["atuId"].(int64)
-    deletedBy := m["deletedBy"].(int64)
     
-    data := &datamodels.AppCat{}
-    data.DeletedFlag = 1
-    data.DeletedBy = deletedBy
-    data.DeletedAt = time.Now()
+    data := &datamodels.ApiTransUnit{}
     _, err := d.engine.
         Where("api_id = ?", apiId).
         Where("atu_id = ?", atuId).
-        Update(data)
+        Delete(data)
     return err
 }

+ 13 - 10
repositories/object_attr_repo.go

@@ -35,7 +35,7 @@ func (d *ObjectAttrRepo) GetPage(m map[string]interface{}) (*viewmodels.PageResu
 		return nil, err1
 	}
 
-	sqlOrderBy := " ORDER BY object_id DESC "
+	sqlOrderBy := " ORDER BY A.object_id DESC "
 	pageStart  := (page - 1) * limit
 	sqlLimit   := fmt.Sprintf(" LIMIT %d OFFSET %d ", limit, pageStart)
 
@@ -60,7 +60,7 @@ func (d *ObjectAttrRepo) GetList(m map[string]interface{}) ([]viewmodels.ObjectA
 	if keywords, ok := m["keywords"]; ok {
 		sqlWhere += ` AND A.attr_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
 	}
-	sqlOrderBy := " ORDER BY model_id DESC "
+	sqlOrderBy := " ORDER BY A.model_id DESC "
 	
 	datalist   := make([]viewmodels.ObjectAttrInfo, 0)
 	err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
@@ -72,19 +72,22 @@ func (d *ObjectAttrRepo) GetList(m map[string]interface{}) ([]viewmodels.ObjectA
 }
 
 func (d *ObjectAttrRepo) GetListById(modelId, objectId int64) ([]viewmodels.ObjectAttrInfo, error) {
-	data    := make([]viewmodels.ObjectAttrInfo, 0)
-	ok, err := d.engine.
-		Where("model_id = ?", modelId).
-		Where("object_id = ?", objectId).
-		Get(data)
-	if !ok && err == nil {
+	sqlSelect  := ` SELECT A.*                 `
+	sqlFrom    := ` FROM  ds_object_attr AS A  `
+	sqlWhere   := ` WHERE A.deleted_flag = 0   `
+	sqlWhere   += fmt.Sprintf(" AND A.model_id  = %d", modelId)
+	sqlWhere   += fmt.Sprintf(" AND A.object_id = %d", objectId)
+	sqlOrderBy := " ORDER BY A.model_id DESC "
+	
+	datalist   := make([]viewmodels.ObjectAttrInfo, 0)
+	err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
+	if err != nil {
 		return nil, err
 	} else {
-		return data, nil
+		return datalist, nil
 	}
 }
 
-
 func (d *ObjectAttrRepo) GetById(modelId, objectId, attrId int64) (*viewmodels.ObjectAttrInfo, error) {
 	data    := &viewmodels.ObjectAttrInfo{}
 	ok, err := d.engine.

+ 0 - 1
service/api_trans_unit_service.go

@@ -43,7 +43,6 @@ func (s *apiTransUnitService) Create(atu *datamodels.ApiTransUnit) error {
     return s.repo.Create(atu)
 }
 
-
 func (s *apiTransUnitService) Update(atu *datamodels.ApiTransUnit) error {
     return s.repo.Update(atu)
 }

+ 2 - 6
service/object_service.go

@@ -68,12 +68,8 @@ func (s *objectService) GetObjectDataById(modelId, objectId int64) (*viewmodels.
 	if err != nil {
 		return nil, err
 	}
-
-	m := make(map[string]interface{}, 0)
-	m["modelId"] = modelId
-	m["objectId"] = objectId
-	m["keywords"] = ""
-	attrs, err := s.objectAttrRepo.GetList(m)
+	
+	attrs, err := s.objectAttrRepo.GetListById(modelId, objectId)
 	if err != nil {
 		return nil, err
 	}

+ 4 - 2
viewmodels/api_info.go

@@ -1,8 +1,10 @@
 package viewmodels
 
 type ApiInfo struct {
-    ModId       int64     `json:"modId"        xorm:"'mod_id'       bigint     pk comment('主键ID')    "`
-    ApiId       int64     `json:"apiId"        xorm:"'api_id'       bigint     pk comment('主键ID')    "`
+    ModId       int64     `json:"modId"        xorm:"'mod_id'       bigint     pk comment('Module ID')"`
+    ModTitle    string    `json:"modTitle"     xorm:"'mod_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')    "`

+ 7 - 8
viewmodels/api_trans_unit_info.go

@@ -2,14 +2,13 @@ package viewmodels
 
 
 type ApiTransUnitInfo struct {
-    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:"modelIdId"     xorm:"'model_id'     bigint      pk comment('ModelId')   "`
-    ObjectId    int64       `json:"objectId"      xorm:"'object_id'    bigint      pk comment('ObjectId')  "`
-    OamId       int64       `json:"oamId"         xorm:"'oam_id'       bigint      pk comment('OamId')     "`
-    AtuTitle    string      `json:"atuTitle"      xorm:"'atu_title'    varchar(127)   comment('AtuTitle')  "`
-    AtuType     string      `json:"atuType"       xorm:"'atu_type'     bigint         comment('AtuType')   "`
-    AtuDesc     string      `json:"atuDesc"       xorm:"'atu_desc'     varchar(2047)  comment('AtuDesc')   "`
+    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') "`
+    ObjectOamType   int64       `json:"objectOamType"   xorm:"'object_oam_type'     bigint        comment('ObjectOamType')"`
 }
 
 func (t *ApiTransUnitInfo) TableName() string {

+ 8 - 4
web/controllers/api_trans_unit_controller.go

@@ -12,10 +12,12 @@ type ApiTransUnitController struct {
 }
 
 func (c *ApiTransUnitController) BeforeActivation(b mvc.BeforeActivation) {
-    b.Handle("GET",         "/",                              "GetList"       )
-    b.Handle("GET",         "/page",                          "GetPage"       )
-    b.Handle("GET",         "/{apiId:int64}/{atuId:int64}",   "GetById"       )
-    b.Handle("POST",        "/add",                           "Create"        )
+    b.Handle("GET",         "/",                                "GetList"       )
+    b.Handle("GET",         "/page",                            "GetPage"       )
+    b.Handle("GET",         "/{apiId:int64}/{atuId:int64}",     "GetById"       )
+    b.Handle("POST",        "/add",                             "Create"        )
+    b.Handle("PUT",         "/update",                          "Update"        )
+    b.Handle("DELETE",      "/{apiId:int64}/{atuId:int64}",     "DeleteByID"    )
 }
 
 func (c *ApiTransUnitController) GetList() *JsonResult {
@@ -93,3 +95,5 @@ func (c *ApiTransUnitController) DeleteByID(apiId, atuId int64) *JsonResult {
         return ResultOk("删除成功", nil)
     }
 }
+
+