houyaf 3 anni fa
parent
commit
14e11f88dd

+ 12 - 3
datamodels/biz_object_mapping.go

@@ -1,12 +1,21 @@
 package datamodels
 
+import "time"
+
 type BizObjectMapping struct {
-    BizId           int64     `json:"bizId"           xorm:"'biz_id'            bigint  pk comment('Biz ID')     "`
-    ObjectId        int64     `json:"objectId"        xorm:"'object_id'         bigint  pk comment('Object ID')  "`
-    MappingId       int64     `json:"mappingId"       xorm:"'mapping_id'        bigint     comment('Mapping ID') "`
+    MappingId       int64     `json:"mappingId"       xorm:"'mapping_id'        bigint  pk comment('Mapping ID')       "`
+    BizId           int64     `json:"bizId"           xorm:"'biz_id'            bigint     comment('Biz ID')           "`
+    ObjectId        int64     `json:"objectId"        xorm:"'object_id'         bigint     comment('Object ID')        "`
     MappingModelId  int64     `json:"mappingModelId"  xorm:"'mapping_model_id'  bigint     comment('Mapping Model ID') "`
     MappingObjectId int64     `json:"mappingObjectId" xorm:"'mapping_object_id' bigint     comment('Mapping Object ID')"`
     SortNo          int64     `json:"sortNo"          xorm:"'sort_no'           bigint     comment('Sort No')          "`
+    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 *BizObjectMapping) TableName() string {

+ 7 - 6
repositories/biz_object_attr_repo.go

@@ -104,13 +104,14 @@ func (d *BizObjectAttrRepo) GetListById(bizId, objectId int64) ([]viewmodels.Biz
 }
 
 func (d *BizObjectAttrRepo) GetById(bizId, objectId, attrId int64) (*viewmodels.BizObjectAttrInfo, error) {
+    sqlSelect  := ` SELECT A.*                 `
+    sqlFrom    := ` FROM  biz_object_attr AS A  `
+    sqlWhere   := ` WHERE A.deleted_flag = 0   `
+    sqlWhere   += fmt.Sprintf(" AND A.biz_id  = %d", bizId)
+    sqlWhere   += fmt.Sprintf(" AND A.object_id = %d", objectId)
     data    := &viewmodels.BizObjectAttrInfo{}
-    ok, err := d.engine.
-        Where("biz_id = ?", bizId).
-        Where("object_id = ?", objectId).
-        Where("attr_id = ?", attrId).
-        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

+ 41 - 18
repositories/biz_object_mapping_repo.go

@@ -21,8 +21,12 @@ func (d *BizObjectMappingRepo) GetPage(m map[string]interface{}) (*viewmodels.Pa
     limit     := m["limit"].(int)
     page      := m["page"].(int)
     
-    sqlSelect := ` SELECT A.*                     `
-    sqlFrom   := ` FROM   biz_object_mapping AS A `
+    sqlSelect := ` SELECT A.*,
+                          B.model_title  as mapping_model_title,
+                          C.object_title as mapping_object_title`
+    sqlFrom   := ` FROM      biz_object_mapping AS A
+                   LEFT JOIN ds_model           AS B ON (A.mapping_model_id  = B.model_id)
+                   LEFT JOIN ds_object          AS C ON (A.mapping_object_id = C.object_id)   `
     sqlWhere  := ` WHERE A.deleted_flag = 0       `
     if keywords, ok := m["keywords"]; ok {
         sqlWhere += ` AND A.object_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
@@ -53,9 +57,13 @@ func (d *BizObjectMappingRepo) GetPage(m map[string]interface{}) (*viewmodels.Pa
 }
 
 func (d *BizObjectMappingRepo) GetList(m map[string]interface{}) ([]viewmodels.BizObjectMappingInfo, error) {
-    sqlSelect  := ` SELECT A.*                 `
-    sqlFrom    := ` FROM   biz_object_mapping AS A  `
-    sqlWhere   := ` WHERE  A.deleted_flag = 0   `
+    sqlSelect := ` SELECT A.*,
+                          B.model_title  as mapping_model_title,
+                          C.object_title as mapping_object_title`
+    sqlFrom   := ` FROM      biz_object_mapping AS A
+                   LEFT JOIN ds_model           AS B ON (A.mapping_model_id  = B.model_id)
+                   LEFT JOIN ds_object          AS C ON (A.mapping_object_id = C.object_id)   `
+    sqlWhere  := ` WHERE A.deleted_flag = 0       `
     if keywords, ok := m["keywords"]; ok {
         sqlWhere += ` AND A.object_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
     }
@@ -71,9 +79,13 @@ func (d *BizObjectMappingRepo) GetList(m map[string]interface{}) ([]viewmodels.B
 }
 
 func (d *BizObjectMappingRepo) GetAll() ([]viewmodels.BizObjectMappingInfo, error) {
-    sqlSelect  := ` SELECT A.*                  `
-    sqlFrom    := ` FROM   biz_object_mapping AS A  `
-    sqlWhere   := ` WHERE  A.deleted_flag = 0   `
+    sqlSelect  := ` SELECT A.*,
+                           B.model_title  as mapping_model_title,
+                           C.object_title as mapping_object_title`
+    sqlFrom    := ` FROM      biz_object_mapping AS A
+                    LEFT JOIN ds_model           AS B ON (A.mapping_model_id  = B.model_id)
+                    LEFT JOIN ds_object          AS C ON (A.mapping_object_id = C.object_id)   `
+    sqlWhere   := ` WHERE A.deleted_flag = 0       `
     sqlOrderBy := ` ORDER BY A.sort_no          `
     
     datalist   := make([]viewmodels.BizObjectMappingInfo, 0)
@@ -86,9 +98,13 @@ func (d *BizObjectMappingRepo) GetAll() ([]viewmodels.BizObjectMappingInfo, erro
 }
 
 func (d *BizObjectMappingRepo) GetListById(bizId, objectId int64) ([]viewmodels.BizObjectMappingInfo, error) {
-    sqlSelect  := ` SELECT A.*                 `
-    sqlFrom    := ` FROM  biz_object_mapping AS A  `
-    sqlWhere   := ` WHERE A.deleted_flag = 0   `
+    sqlSelect  := ` SELECT A.*,
+                           B.model_title  as mapping_model_title,
+                           C.object_title as mapping_object_title`
+    sqlFrom    := ` FROM      biz_object_mapping AS A
+                    LEFT JOIN ds_model           AS B ON (A.mapping_model_id  = B.model_id)
+                    LEFT JOIN ds_object          AS C ON (A.mapping_object_id = C.object_id)   `
+    sqlWhere   := ` WHERE A.deleted_flag = 0       `
     sqlWhere   += fmt.Sprintf(" AND A.biz_id  = %d", bizId)
     sqlWhere   += fmt.Sprintf(" AND A.object_id = %d", objectId)
     sqlOrderBy := " ORDER BY A.sort_no "
@@ -103,13 +119,20 @@ func (d *BizObjectMappingRepo) GetListById(bizId, objectId int64) ([]viewmodels.
 }
 
 func (d *BizObjectMappingRepo) GetById(bizId, objectId, mappingId int64) (*viewmodels.BizObjectMappingInfo, error) {
-    data    := &viewmodels.BizObjectMappingInfo{}
-    ok, err := d.engine.
-        Where("biz_id = ?", bizId).
-        Where("object_id = ?", objectId).
-        Where("mapping_id = ?", mappingId).
-        Get(data)
-    if !ok && err == nil {
+    sqlSelect := ` SELECT A.*,
+                          B.model_title  as mapping_model_title,
+                          C.object_title as mapping_object_title`
+    sqlFrom   := ` FROM      biz_object_mapping AS A
+                   LEFT JOIN ds_model           AS B ON (A.mapping_model_id  = B.model_id)
+                   LEFT JOIN ds_object          AS C ON (A.mapping_object_id = C.object_id)   `
+    sqlWhere  := ` WHERE A.deleted_flag = 0       `
+    sqlWhere  += fmt.Sprintf(" AND A.biz_id  = %d", bizId)
+    sqlWhere  += fmt.Sprintf(" AND A.object_id = %d", objectId)
+    sqlWhere  += fmt.Sprintf(" AND A.mapping_id = %d", mappingId)
+    
+    data      := &viewmodels.BizObjectMappingInfo{}
+    has, err  := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
+    if !has || err != nil {
         return nil, err
     } else {
         return data, nil

+ 8 - 6
viewmodels/biz_object_mapping_info.go

@@ -1,12 +1,14 @@
 package viewmodels
 
 type BizObjectMappingInfo struct {
-    BizId           int64     `json:"bizId"           xorm:"'biz_id'            bigint  pk comment('Biz ID')     "`
-    ObjectId        int64     `json:"objectId"        xorm:"'object_id'         bigint  pk comment('Object ID')  "`
-    MappingId       int64     `json:"mappingId"       xorm:"'mapping_id'        bigint     comment('Mapping ID') "`
-    MappingModelId  int64     `json:"mappingModelId"  xorm:"'mapping_model_id'  bigint     comment('Mapping Model ID') "`
-    MappingObjectId int64     `json:"mappingObjectId" xorm:"'mapping_object_id' bigint     comment('Mapping Object ID')"`
-    SortNo          int64     `json:"sortNo"          xorm:"'sort_no'           bigint     comment('Sort No')          "`
+    MappingId          int64     `json:"mappingId"          xorm:"'mapping_id'           bigint  pk comment('Mapping ID')           "`
+    BizId              int64     `json:"bizId"              xorm:"'biz_id'               bigint     comment('Biz ID')               "`
+    ObjectId           int64     `json:"objectId"           xorm:"'object_id'            bigint     comment('Object ID')            "`
+    MappingModelId     int64     `json:"mappingModelId"     xorm:"'mapping_model_id'     bigint     comment('Mapping Model ID')     "`
+    MappingModelTitle  string    `json:"mappingModelTitle"  xorm:"'mapping_model_title'  bigint     comment('Mapping Model Title')  "`
+    MappingObjectId    int64     `json:"mappingObjectId"    xorm:"'mapping_object_id'    bigint     comment('Mapping Object ID')    "`
+    MappingObjectTitle string    `json:"mappingObjectTitle" xorm:"'mapping_object_title' bigint     comment('Mapping Object Title') "`
+    SortNo             int64     `json:"sortNo"             xorm:"'sort_no'              bigint     comment('Sort No')          "`
 }
 
 func (t *BizObjectMappingInfo) TableName() string {

+ 92 - 0
web/controllers/biz_object_mapping_controller.go

@@ -0,0 +1,92 @@
+package controllers
+
+import (
+    "github.com/kataras/iris/v12/mvc"
+    "xps/datamodels"
+    "xps/service"
+)
+
+type BizObjectMappingController struct {
+    Base
+    Service service.BizObjectMappingService
+}
+
+func (c *BizObjectMappingController) BeforeActivation(b mvc.BeforeActivation) {
+    b.Handle("GET",         "/",                                 "GetList"   )
+    b.Handle("GET",         "/page",                             "GetPage"   )
+    b.Handle("GET",         "/{bizId:int64}/{objectId:int64}",   "GetById"   )
+    b.Handle("POST",        "/add",                              "Create"    )
+    b.Handle("PUT",         "/update",                           "Update"    )
+    b.Handle("DELETE",      "/{bizId:int64}/{objectId:int64}",   "DeleteByID")
+}
+
+func (c *BizObjectMappingController) GetList() *JsonResult {
+    params  := c.buildParams()
+    bizId := c.Ctx.URLParamInt64Default("bizId", 0)
+    if bizId <= 0 {
+        return ResultErr("参数不完整", nil)
+    }
+    params["bizId"] = bizId
+    data, err := c.Service.GetList(params)
+    if err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("获取成功", data)
+    }
+}
+
+func (c *BizObjectMappingController) GetPage() *JsonResult {
+    params  := c.buildParams()
+    bizId   := c.Ctx.URLParamInt64Default("bizId", 0)
+    if bizId <= 0 {
+        return ResultErr("参数不完整", nil)
+    }
+    
+    params["bizId"] = bizId
+    data, err := c.Service.GetPage(params)
+    if err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("获取成功", data)
+    }
+}
+
+func (c *BizObjectMappingController) GetById(bizId, objectId, mappingId int64) *JsonResult {
+    data, err := c.Service.GetById(bizId, objectId, mappingId)
+    if err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("获取成功", data)
+    }
+}
+
+func (c *BizObjectMappingController) Create() *JsonResult {
+    userId     := c.GetCurUserId()
+    
+    objectData := datamodels.BizObjectMapping{}
+    if err := c.Ctx.ReadJSON(&objectData); err != nil {
+        return ResultErr("读取数据失败", nil)
+    }
+    
+    objectData.CreatedBy = userId
+    if err := c.Service.Create(&objectData); err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("新增成功", nil)
+    }
+}
+
+func (c *BizObjectMappingController) DeleteByID(bizId, objectId, mappingId int64) *JsonResult {
+    userId := c.GetCurUserId()
+    
+    m := make(map[string]interface{})
+    m["bizId"]     = bizId
+    m["objectId"]  = objectId
+    m["mappingId"] = mappingId
+    m["deletedBy"] = userId
+    if err := c.Service.Delete(m); err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("删除成功", nil)
+    }
+}