houyaf před 3 roky
rodič
revize
98179ea225

+ 6 - 0
constant/constant.go

@@ -65,6 +65,12 @@ const (
 	BIZ_RULE_CUR_USER_GROUP_NAME = 9
 )
 
+const (
+	REPO_DATABASE     = 1
+	REPO_FILE_SERVER  = 2
+	REPO_CACHE        = 3
+)
+
 // RetCode Result Code
 type RetCode int
 

+ 2 - 1
datamodels/repo.go

@@ -5,7 +5,7 @@ import "time"
 type Repo struct {
     RepoId          int64     `json:"repoId"         xorm:"'repo_id'            bigint      pk comment('Repo ID')         "`
     RepoTypeId      int64     `json:"repoTypeId"     xorm:"'repo_type_id'       bigint      pk comment('Repo Type ID')    "`
-    RepoCatId       int64     `json:"repoCatId"      xorm:"'repo_cat_id'        bigint      pk comment('Repo Cat ID')     "`
+    RepoCatId       int64     `json:"repoCatId"      xorm:"'repo_cat_id'        bigint         comment('Repo Cat ID')     "`
     RepoTitle       string    `json:"repoTitle"      xorm:"'repo_title'         varchar(127)   comment('Repo Title')      "`
     RepoHost        string    `json:"repoHost"       xorm:"'repo_host'          varchar(127)   comment('Repo Host')       "`
     RepoPort        int64     `json:"repoPort"       xorm:"'repo_port'          bigint         comment('Repo Port')       "`
@@ -13,6 +13,7 @@ type Repo struct {
     RepoPassword    string    `json:"repoPassword"   xorm:"'repo_password'      varchar(127)   comment('Repo Password')   "`
     RepoAccessKey   string    `json:"repoAccessKey"  xorm:"'repo_access_key'    varchar(127)   comment('Repo Access Key') "`
     RepoSecretKey   string    `json:"repoSecretKey"  xorm:"'repo_secret_key'    varchar(127)   comment('Repo Secret Key') "`
+    RepoTarget      string    `json:"repoTarget"     xorm:"'repo_target'        varchar(255)   comment('Repo Target')     "`
     RepoDesc        string    `json:"repoDesc"       xorm:"'repo_desc'          varchar(255)   comment('Repo Desc')       "`
     Status          int64     `json:"status"         xorm:"'status'             bigint         comment('Status')          "`
     

+ 45 - 10
repositories/repo.go

@@ -22,8 +22,12 @@ func (d *Repo) GetPage(m map[string]interface{}) (*viewmodels.PageResult, error)
     limit     := m["limit"].(int)
     page      := m["page"].(int)
     
-    sqlSelect := ` SELECT A.*                `
-    sqlFrom   := ` FROM   repo   AS A        `
+    sqlSelect := ` SELECT    A.*,
+                             B.repo_type_title,
+                             C.repo_cat_title             `
+    sqlFrom   := ` FROM      repo      AS A
+                   LEFT JOIN repo_type AS B ON (A.repo_type_id = B.repo_type_id)
+                   LEFT JOIN repo_cat  AS C ON (A.repo_type_id = C.repo_type_id AND A.repo_cat_id = C.repo_cat_id) `
     sqlWhere  := ` WHERE  A.deleted_flag = 0 `
     if keywords, ok := m["keywords"]; ok {
         sqlWhere += ` AND A.repo_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
@@ -54,8 +58,12 @@ func (d *Repo) GetPage(m map[string]interface{}) (*viewmodels.PageResult, error)
 }
 
 func (d *Repo) GetList(m map[string]interface{}) ([]viewmodels.RepoInfo, error) {
-    sqlSelect := ` SELECT A.*               `
-    sqlFrom   := ` FROM  repo AS A          `
+    sqlSelect := ` SELECT    A.*,
+                             B.repo_type_title,
+                             C.repo_cat_title             `
+    sqlFrom   := ` FROM      repo      AS A
+                   LEFT JOIN repo_type AS B ON (A.repo_type_id = B.repo_type_id)
+                   LEFT JOIN repo_cat  AS C ON (A.repo_type_id = C.repo_type_id AND A.repo_cat_id = C.repo_cat_id) `
     sqlWhere  := ` WHERE A.deleted_flag = 0 `
     if keywords, ok := m["keywords"]; ok {
         sqlWhere += ` AND A.repo_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
@@ -70,9 +78,31 @@ func (d *Repo) GetList(m map[string]interface{}) ([]viewmodels.RepoInfo, error)
     return datalist, nil
 }
 
+func (d *Repo) GetListById(repoTypeId int64) ([]viewmodels.RepoInfo, error) {
+    sqlSelect := ` SELECT    A.*,
+                             B.repo_type_title,
+                             C.repo_cat_title             `
+    sqlFrom   := ` FROM      repo      AS A
+                   LEFT JOIN repo_type AS B ON (A.repo_type_id = B.repo_type_id)
+                   LEFT JOIN repo_cat  AS C ON (A.repo_type_id = C.repo_type_id AND A.repo_cat_id = C.repo_cat_id) `
+    sqlWhere  := ` WHERE A.deleted_flag = 0 `
+    sqlWhere  += fmt.Sprintf(" AND A.repo_type_id = %d ", repoTypeId)
+    sqlOrderBy := ` ORDER BY A.repo_id ASC `
+    datalist   := make([]viewmodels.RepoInfo, 0)
+    err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
+    if err != nil {
+        return nil, err
+    }
+    return datalist, nil
+}
+
 func (d *Repo) GetAll() ([]viewmodels.RepoInfo, error) {
-    sqlSelect  := ` SELECT A.*               `
-    sqlFrom    := ` FROM  repo AS A          `
+    sqlSelect  := ` SELECT    A.*,
+                              B.repo_type_title,
+                              C.repo_cat_title             `
+    sqlFrom    := ` FROM      repo      AS A
+                    LEFT JOIN repo_type AS B ON (A.repo_type_id = B.repo_type_id)
+                    LEFT JOIN repo_cat  AS C ON (A.repo_type_id = C.repo_type_id AND A.repo_cat_id = C.repo_cat_id) `
     sqlWhere   := ` WHERE A.deleted_flag = 0 `
     sqlOrderBy := ` ORDER BY A.repo_id ASC   `
     datalist   := make([]viewmodels.RepoInfo, 0)
@@ -83,11 +113,16 @@ func (d *Repo) GetAll() ([]viewmodels.RepoInfo, error) {
     return datalist, nil
 }
 
-func (d *Repo) GetById(repoId int64) (*viewmodels.RepoInfo, error) {
-    sqlSelect  := ` SELECT A.*                `
-    sqlFrom    := ` FROM   repo   AS A        `
+func (d *Repo) GetById(repoTypeId, repoId int64) (*viewmodels.RepoInfo, error) {
+    sqlSelect  := ` SELECT    A.*,
+                              B.repo_type_title,
+                              C.repo_cat_title             `
+    sqlFrom    := ` FROM      repo      AS A
+                    LEFT JOIN repo_type AS B ON (A.repo_type_id = B.repo_type_id)
+                    LEFT JOIN repo_cat  AS C ON (A.repo_type_id = C.repo_type_id AND A.repo_cat_id = C.repo_cat_id) `
     sqlWhere   := ` WHERE  A.deleted_flag = 0 `
-    sqlWhere   += fmt.Sprintf(" A.repo_id = %d ", repoId)
+    sqlWhere   += fmt.Sprintf(" AND A.repo_type_id = %d ", repoTypeId)
+    sqlWhere   += fmt.Sprintf(" AND A.repo_id      = %d ", repoId)
     
     data := &viewmodels.RepoInfo{}
     has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)

+ 7 - 4
repositories/task_cat_repo.go

@@ -63,7 +63,7 @@ func (d *TaskCatRepo) GetList(m map[string]interface{}) ([]viewmodels.TaskCatInf
 	sqlSelect := ` SELECT A.* `
 	sqlFrom   := ` FROM  task_cat   AS A    `
 	sqlWhere  := ` WHERE A.deleted_flag = 0 `
-	sqlWhere  +=  fmt.Sprintf(" AND A.oc_id =%d ", ocId)
+	sqlWhere  +=  fmt.Sprintf(" AND A.oc_id = %d ", ocId)
 	
 	if keywords, ok := m["keywords"]; ok {
 		sqlWhere += ` AND A.task_cat_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
@@ -81,8 +81,8 @@ func (d *TaskCatRepo) GetList(m map[string]interface{}) ([]viewmodels.TaskCatInf
 
 func (d *TaskCatRepo) GetById(ocId int64, taskCatId int64) (*viewmodels.TaskCatInfo, error) {
 	sqlSelect := ` SELECT A.*               `
-	sqlFrom   := ` FROM  task_cat   AS A    `
-	sqlWhere  := ` WHERE A.deleted_flag = 0  AND A.oc_id =` + fmt.Sprintf("%d", ocId)
+	sqlFrom   := ` FROM  task_cat AS A      `
+	sqlWhere  := ` WHERE A.deleted_flag = 0 AND A.oc_id =` + fmt.Sprintf("%d", ocId)
 	data := &viewmodels.TaskCatInfo{}
 	has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
 	if !has || err != nil {
@@ -103,7 +103,10 @@ func (d *TaskCatRepo) Update(data *datamodels.TaskCat) error {
 	taskCatId := data.TaskCatId
 
 	data.UpdatedAt = time.Now()
-	_, err := d.engine.Where("oc_id = ?", ocId).Where("task_cat_id = ?", taskCatId).Update(data)
+	_, err := d.engine.
+		Where("oc_id = ?", ocId).
+		Where("task_cat_id = ?", taskCatId).
+		Update(data)
 	return err
 }
 

+ 5 - 0
service/repo_cat_service.go

@@ -10,6 +10,7 @@ import (
 type RepoCatService interface {
     GetList(m map[string]interface{}) ([]viewmodels.RepoCatInfo, error)
     GetPage(m map[string]interface{}) (*viewmodels.PageResult, error)
+    GetListById(repoTypeId int64) ([]viewmodels.RepoCatInfo, error)
     GetById(repoTypeId, repoCatId int64) (*viewmodels.RepoCatInfo, error)
     Create(d *datamodels.RepoCat) error
     Update(d *datamodels.RepoCat) error
@@ -34,6 +35,10 @@ func (s *repoCatService) GetPage(m map[string]interface{}) (*viewmodels.PageResu
     return s.repo.GetPage(m)
 }
 
+func (s *repoCatService) GetListById(repoTypeId int64) ([]viewmodels.RepoCatInfo, error) {
+    return s.repo.GetListById(repoTypeId)
+}
+
 func (s *repoCatService) GetById(repoTypeId, repoCatId int64) (*viewmodels.RepoCatInfo, error) {
     return s.repo.GetById(repoTypeId, repoCatId)
 }

+ 8 - 3
service/repo_service.go

@@ -10,7 +10,8 @@ import (
 type RepoService interface {
     GetList(m map[string]interface{}) ([]viewmodels.RepoInfo, error)
     GetPage(m map[string]interface{}) (*viewmodels.PageResult, error)
-    GetById(repoId int64) (*viewmodels.RepoInfo, error)
+    GetListById(repoTypeId int64) ([]viewmodels.RepoInfo, error)
+    GetById(repoTypeId, repoId int64) (*viewmodels.RepoInfo, error)
     Create(d *datamodels.Repo) error
     Update(d *datamodels.Repo) error
     Delete(m map[string]interface{}) error
@@ -30,12 +31,16 @@ func (s *repoService) GetList(m map[string]interface{}) ([]viewmodels.RepoInfo,
     return s.repo.GetList(m)
 }
 
+func (s *repoService) GetListById(repoTypeId int64) ([]viewmodels.RepoInfo, error) {
+    return s.repo.GetListById(repoTypeId)
+}
+
 func (s *repoService) GetPage(m map[string]interface{}) (*viewmodels.PageResult, error) {
     return s.repo.GetPage(m)
 }
 
-func (s *repoService) GetById(repoId int64) (*viewmodels.RepoInfo, error) {
-    return s.repo.GetById(repoId)
+func (s *repoService) GetById(repoTypeId, repoId int64) (*viewmodels.RepoInfo, error) {
+    return s.repo.GetById(repoTypeId, repoId)
 }
 
 func (s *repoService) Create(m *datamodels.Repo) error {

+ 7 - 1
viewmodels/repo_info.go

@@ -2,14 +2,20 @@ package viewmodels
 
 type RepoInfo struct {
     RepoId          int64     `json:"repoId"         xorm:"'repo_id'            bigint      pk comment('Repo ID')         "`
-    RepoTypeId      int64     `json:"repoTypeId"     xorm:"'repo_type_id'       bigint      pk comment('Repo Type ID')    "`
     RepoTitle       string    `json:"repoTitle"      xorm:"'repo_title'         varchar(127)   comment('Repo Title')      "`
+    
+    RepoTypeId      int64     `json:"repoTypeId"     xorm:"'repo_type_id'       bigint         comment('Repo Type ID')    "`
+    RepoTypeTitle   string    `json:"repoTypeTitle"  xorm:"'repo_type_title'    varchar(127)   comment('Repo Title')      "`
+    RepoCatId       int64     `json:"repoCatId"      xorm:"'repo_cat_id'        bigint         comment('Repo Cat ID')     "`
+    RepoCatTitle    string    `json:"repoCatTitle"   xorm:"'repo_cat_title'     varchar(127)   comment('Repo Cat Title')  "`
+    
     RepoHost        string    `json:"repoHost"       xorm:"'repo_host'          varchar(127)   comment('Repo Host')       "`
     RepoPort        int64     `json:"repoPort"       xorm:"'repo_port'          bigint         comment('Repo Port')       "`
     RepoAccount     string    `json:"repoAccount"    xorm:"'repo_account'       varchar(127)   comment('Repo Account')    "`
     RepoPassword    string    `json:"repoPassword"   xorm:"'repo_password'      varchar(127)   comment('Repo Password')   "`
     RepoAccessKey   string    `json:"repoAccessKey"  xorm:"'repo_access_key'    varchar(127)   comment('Repo Access Key') "`
     RepoSecretKey   string    `json:"repoSecretKey"  xorm:"'repo_secret_key'    varchar(127)   comment('Repo Secret Key') "`
+    RepoTarget      string    `json:"repoTarget"     xorm:"'repo_target'        varchar(255)   comment('Repo Target')     "`
     RepoDesc        string    `json:"repoDesc"       xorm:"'repo_desc'          varchar(255)   comment('Repo Desc')       "`
     Status          int64     `json:"status"         xorm:"'status'             bigint         comment('Status')          "`
 }

+ 0 - 1
web/controllers/api_controller.go

@@ -105,7 +105,6 @@ func (c *ApiController) UpdateStatus(apiId, status int64)*JsonResult{
 
 func (c *ApiController) DeleteByID(apiId int64) *JsonResult {
     userId := c.GetCurUserId()
-    
     m := make(map[string]interface{})
     m["apiId"]     = apiId
     m["deletedBy"] = userId

+ 17 - 6
web/controllers/repo_cat_controller.go

@@ -12,12 +12,13 @@ type RepoCatController struct {
 }
 
 func (c *RepoCatController) BeforeActivation(b mvc.BeforeActivation) {
-    b.Handle("GET",         "/",                                        "GetList"   )
-    b.Handle("GET",         "/page",                                    "GetPage"   )
-    b.Handle("GET",         "/{repoTypeId:int64}/{repoCatId:int64}",    "GetById"   )
-    b.Handle("POST",        "/add",                                     "Create"    )
-    b.Handle("PUT",         "/update",                                  "Update"    )
-    b.Handle("DELETE",      "/{repoTypeId:int64}/{repoCatId:int64}",    "DeleteByID")
+    b.Handle("GET",         "/",                                        "GetList"       )
+    b.Handle("GET",         "/page",                                    "GetPage"       )
+    b.Handle("GET",         "/{repoTypeId:int64}",                      "GetListById"   )
+    b.Handle("GET",         "/{repoTypeId:int64}/{repoCatId:int64}",    "GetById"       )
+    b.Handle("POST",        "/add",                                     "Create"        )
+    b.Handle("PUT",         "/update",                                  "Update"        )
+    b.Handle("DELETE",      "/{repoTypeId:int64}/{repoCatId:int64}",    "DeleteByID"    )
 }
 
 func (c *RepoCatController) GetList() *JsonResult {
@@ -40,6 +41,16 @@ func (c *RepoCatController) GetPage() *JsonResult {
     }
 }
 
+func (c *RepoCatController) GetListById(repoTypeId int64) *JsonResult {
+    data, err := c.Service.GetListById(repoTypeId)
+    if err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("获取成功", data)
+    }
+}
+
+
 func (c *RepoCatController) GetById(repoTypeId, repoCatId int64) *JsonResult {
     data, err := c.Service.GetById(repoTypeId, repoCatId)
     if err != nil {

+ 19 - 8
web/controllers/repo_controller.go

@@ -12,12 +12,13 @@ type RepoController struct {
 }
 
 func (c *RepoController) BeforeActivation(b mvc.BeforeActivation) {
-    b.Handle("GET",         "/",                        "GetList"   )
-    b.Handle("GET",         "/page",                    "GetPage"   )
-    b.Handle("GET",         "/{repoId:int64}",          "GetById"   )
-    b.Handle("POST",        "/add",                     "Create"    )
-    b.Handle("PUT",         "/update",                  "Update"    )
-    b.Handle("DELETE",      "/{repoId:int64}",          "DeleteByID")
+    b.Handle("GET",         "/",                                            "GetList"       )
+    b.Handle("GET",         "/page",                                        "GetPage"       )
+    b.Handle("GET",         "/{repoTypeId:int64}/{repoId:int64}",           "GetById"       )
+    b.Handle("GET",         "/{repoTypeId:int64}",                          "GetListById"   )
+    b.Handle("POST",        "/add",                                         "Create"        )
+    b.Handle("PUT",         "/update",                                      "Update"        )
+    b.Handle("DELETE",      "/{repoId:int64}",                              "DeleteByID"    )
 }
 
 func (c *RepoController) GetList() *JsonResult {
@@ -40,9 +41,19 @@ func (c *RepoController) GetPage() *JsonResult {
     }
 }
 
-func (c *RepoController) GetById(repoId int64) *JsonResult {
+func (c *RepoController) GetListById(repoTypeId int64) *JsonResult {
     
-    data, err := c.Service.GetById(repoId)
+    data, err := c.Service.GetListById(repoTypeId)
+    if err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("获取成功", data)
+    }
+}
+
+func (c *RepoController) GetById(repoTypeId, repoId int64) *JsonResult {
+    
+    data, err := c.Service.GetById(repoTypeId, repoId)
     if err != nil {
         return ResultErr(err.Error(), nil)
     } else {

+ 6 - 6
web/controllers/repo_db_controller.go

@@ -12,13 +12,13 @@ type RepoDBController struct {
 }
 
 func (c *RepoDBController) BeforeActivation(b mvc.BeforeActivation) {
-    b.Handle("GET",         "/table/{objectCode:string}",         "GetList"      )
-    b.Handle("GET",         "/table/{objectCode:string}/page",    "GetPage"      )
-    b.Handle("GET",         "/table/{objectCode:string}/fields",  "GetFields"    )
+    b.Handle("GET",         "/table/{objectCode:string}",         "GetDataOfList"      )
+    b.Handle("GET",         "/table/{objectCode:string}/page",    "GetDataOfPage"      )
+    b.Handle("GET",         "/table/{objectCode:string}/fields",  "GetTableFields"     )
     
 }
 
-func (c *RepoDBController) GetList(objectCode string) *JsonResult {
+func (c *RepoDBController) GetDataOfList(objectCode string) *JsonResult {
     data, err := c.Service.GetDataOfList(objectCode)
     if err != nil {
         return ResultErr(err.Error(), nil)
@@ -27,7 +27,7 @@ func (c *RepoDBController) GetList(objectCode string) *JsonResult {
     }
 }
 
-func (c *RepoDBController) GetPage(objectCode string) *JsonResult {
+func (c *RepoDBController) GetDataOfPage(objectCode string) *JsonResult {
     data, err := c.Service.GetDataOfPage(objectCode)
     if err != nil {
         return ResultErr(err.Error(), nil)
@@ -36,7 +36,7 @@ func (c *RepoDBController) GetPage(objectCode string) *JsonResult {
     }
 }
 
-func (c *RepoDBController) GetFields(objectCode string) *JsonResult {
+func (c *RepoDBController) GetTableFields(objectCode string) *JsonResult {
     attrs, err :=  cache.GetModelObjectAttrs(objectCode)
     if err != nil {
         return ResultErr(err.Error(), nil)

+ 0 - 1
web/main.go

@@ -57,6 +57,5 @@ func makeAccessLog() *accesslog.AccessLog {
 
 func main() {
 	app := newApp()
-
 	app.Listen(":8001", iris.WithPostMaxMemory(maxSize))
 }