作者 yangfu

add menu

@@ -10,11 +10,11 @@ metadata: @@ -10,11 +10,11 @@ metadata:
10 required: false 10 required: false
11 type: 11 type:
12 primitive: string 12 primitive: string
13 - - name: menuParentId 13 + - name: parentId
14 description: 菜单父级id 0:查询所有 n:父级id为n的菜单列表 14 description: 菜单父级id 0:查询所有 n:父级id为n的菜单列表
15 required: false 15 required: false
16 type: 16 type:
17 - primitive: string 17 + primitive: int64
18 - name: menuName 18 - name: menuName
19 description: 菜单名称过滤 19 description: 菜单名称过滤
20 required: false 20 required: false
@@ -9,6 +9,8 @@ import ( @@ -9,6 +9,8 @@ import (
9 type UpdateMenuCommand struct { 9 type UpdateMenuCommand struct {
10 // 菜单编号 10 // 菜单编号
11 MenuId int64 `json:"menuId" valid:"Required"` 11 MenuId int64 `json:"menuId" valid:"Required"`
  12 + // 父级id
  13 + ParentId int64 `json:"parentId,omitempty"`
12 // 菜单名称 14 // 菜单名称
13 MenuName string `json:"menuName" valid:"Required"` 15 MenuName string `json:"menuName" valid:"Required"`
14 // 菜单编码 SYSTEM_USER_EDIT / 100101 (字符编码) 16 // 菜单编码 SYSTEM_USER_EDIT / 100101 (字符编码)
@@ -10,11 +10,11 @@ type ListMenuQuery struct { @@ -10,11 +10,11 @@ type ListMenuQuery struct {
10 // 菜单类别 web app 10 // 菜单类别 web app
11 MenuCategory string `json:"menuCategory,omitempty"` 11 MenuCategory string `json:"menuCategory,omitempty"`
12 // 菜单父级id 0:查询所有 n:父级id为n的菜单列表 12 // 菜单父级id 0:查询所有 n:父级id为n的菜单列表
13 - MenuParentId string `json:"menuParentId,omitempty"` 13 + MenuParentId int64 `json:"parentId,omitempty"`
14 // 菜单名称过滤 14 // 菜单名称过滤
15 MenuName string `json:"menuName,omitempty"` 15 MenuName string `json:"menuName,omitempty"`
16 // 查询偏离量 16 // 查询偏离量
17 - Offset int `json:"offset" valid:"Required"` 17 + Offset int `json:"offset"`
18 // 查询限制 18 // 查询限制
19 Limit int `json:"limit" valid:"Required"` 19 Limit int `json:"limit" valid:"Required"`
20 } 20 }
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/application/menu/command" 8 "gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/application/menu/command"
9 "gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/application/menu/query" 9 "gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/application/menu/query"
10 "gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/domain" 10 "gitlab.fjmaimaimai.com/mmm-go-pp/terms/pkg/domain"
  11 + "strconv"
11 ) 12 )
12 13
13 // 菜单服务 14 // 菜单服务
@@ -48,6 +49,14 @@ func (menuService *MenuService) CreateMenu(createMenuCommand *command.CreateMenu @@ -48,6 +49,14 @@ func (menuService *MenuService) CreateMenu(createMenuCommand *command.CreateMenu
48 } else { 49 } else {
49 menuRepository = value 50 menuRepository = value
50 } 51 }
  52 + if newMenu.ParentId > 0 {
  53 + if pMenu, err := menuRepository.FindOne(map[string]interface{}{"menuId": newMenu.ParentId}); err != nil {
  54 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  55 + } else {
  56 + newMenu.ParentPath = pMenu.GetParentPath()
  57 + newMenu.Category = pMenu.GetCategory()
  58 + }
  59 + }
51 if menu, err := menuRepository.Save(newMenu); err != nil { 60 if menu, err := menuRepository.Save(newMenu); err != nil {
52 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 61 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
53 } else { 62 } else {
@@ -118,7 +127,14 @@ func (menuService *MenuService) ListMenu(listMenuQuery *query.ListMenuQuery) (in @@ -118,7 +127,14 @@ func (menuService *MenuService) ListMenu(listMenuQuery *query.ListMenuQuery) (in
118 } else { 127 } else {
119 menuRepository = value 128 menuRepository = value
120 } 129 }
121 - if count, menus, err := menuRepository.Find(tool_funs.SimpleStructToMap(listMenuQuery)); err != nil { 130 + queryOptions := tool_funs.SimpleStructToMap(listMenuQuery)
  131 + if len(listMenuQuery.MenuCategory) > 0 {
  132 + queryOptions["code"] = ""
  133 + if m, e := menuRepository.FindOne(map[string]interface{}{"code": listMenuQuery.MenuCategory}); e == nil && m != nil {
  134 + queryOptions["category"] = strconv.Itoa(int(m.MenuId))
  135 + }
  136 + }
  137 + if count, menus, err := menuRepository.Find(queryOptions); err != nil {
122 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 138 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
123 } else { 139 } else {
124 if err := transactionContext.CommitTransaction(); err != nil { 140 if err := transactionContext.CommitTransaction(); err != nil {
@@ -201,6 +217,33 @@ func (menuService *MenuService) UpdateMenu(updateMenuCommand *command.UpdateMenu @@ -201,6 +217,33 @@ func (menuService *MenuService) UpdateMenu(updateMenuCommand *command.UpdateMenu
201 if menu == nil { 217 if menu == nil {
202 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateMenuCommand.MenuId))) 218 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateMenuCommand.MenuId)))
203 } 219 }
  220 + // 父级节点有发生更新
  221 + if updateMenuCommand.ParentId != menu.ParentId && (updateMenuCommand.ParentId != 0 && menu.ParentId != 0) {
  222 + var oldParentFullPath, newParentFullPath = menu.GetFullPath(), menu.GetFullPath()
  223 + var oldParentPath = menu.ParentPath
  224 + if pMenu, err := menuRepository.FindOne(map[string]interface{}{"menuId": updateMenuCommand.ParentId}); err != nil {
  225 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  226 + } else {
  227 + newParentFullPath = pMenu.GetParentPath()
  228 + menu.ParentPath = newParentFullPath
  229 + }
  230 + // 父级目录不一致时,联动更新其他的子节点的父级目录
  231 + if oldParentFullPath != newParentFullPath {
  232 + if _, menus, err := menuRepository.Find(map[string]interface{}{"parentPath": oldParentFullPath}); err != nil {
  233 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  234 + } else {
  235 + for i := range menus {
  236 + if menus[i].ParentPath == oldParentPath {
  237 + continue
  238 + }
  239 + menus[i].UpdateParentPath(oldParentPath, newParentFullPath)
  240 + if _, err := menuRepository.Save(menus[i]); err != nil {
  241 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  242 + }
  243 + }
  244 + }
  245 + }
  246 + }
204 if err := menu.Update(tool_funs.SimpleStructToMap(updateMenuCommand)); err != nil { 247 if err := menu.Update(tool_funs.SimpleStructToMap(updateMenuCommand)); err != nil {
205 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 248 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
206 } 249 }
1 package domain 1 package domain
2 2
  3 +import (
  4 + "fmt"
  5 + "strconv"
  6 + "strings"
  7 +)
  8 +
  9 +var PathSegment = ","
  10 +
3 // 系统菜单 11 // 系统菜单
4 type Menu struct { 12 type Menu struct {
5 // 菜单编号 13 // 菜单编号
@@ -22,7 +30,7 @@ type Menu struct { @@ -22,7 +30,7 @@ type Menu struct {
22 Remark string `json:"remark"` 30 Remark string `json:"remark"`
23 // 菜单类别 (web:1、app:2) 31 // 菜单类别 (web:1、app:2)
24 Category string `json:"category"` 32 Category string `json:"category"`
25 - // 父级节点路径("0,11,12,") 33 + // 路径节点路径("0,11,12,")
26 ParentPath string `json:"parentPath"` 34 ParentPath string `json:"parentPath"`
27 // 菜单是否公开状态,[0:隐藏],[1:显示],默认显示 35 // 菜单是否公开状态,[0:隐藏],[1:显示],默认显示
28 IsPublish int `json:"isPublish"` 36 IsPublish int `json:"isPublish"`
@@ -45,9 +53,6 @@ func (menu *Menu) Identify() interface{} { @@ -45,9 +53,6 @@ func (menu *Menu) Identify() interface{} {
45 } 53 }
46 54
47 func (menu *Menu) Update(data map[string]interface{}) error { 55 func (menu *Menu) Update(data map[string]interface{}) error {
48 - if menuId, ok := data["menuId"]; ok {  
49 - menu.MenuId = menuId.(int64)  
50 - }  
51 if parentId, ok := data["parentId"]; ok { 56 if parentId, ok := data["parentId"]; ok {
52 menu.ParentId = parentId.(int64) 57 menu.ParentId = parentId.(int64)
53 } 58 }
@@ -72,12 +77,12 @@ func (menu *Menu) Update(data map[string]interface{}) error { @@ -72,12 +77,12 @@ func (menu *Menu) Update(data map[string]interface{}) error {
72 if desc, ok := data["desc"]; ok { 77 if desc, ok := data["desc"]; ok {
73 menu.Remark = desc.(string) 78 menu.Remark = desc.(string)
74 } 79 }
75 - if category, ok := data["category"]; ok {  
76 - menu.Category = category.(string)  
77 - }  
78 - if parentPath, ok := data["parentPath"]; ok {  
79 - menu.ParentPath = parentPath.(string)  
80 - } 80 + //if category, ok := data["category"]; ok {
  81 + // menu.Category = category.(string)
  82 + //}
  83 + //if fullPath, ok := data["fullPath"]; ok {
  84 + // menu.ParentPath = parentPath.(string)
  85 + //}
81 if isPublish, ok := data["isPublish"]; ok { 86 if isPublish, ok := data["isPublish"]; ok {
82 menu.IsPublish = isPublish.(int) 87 menu.IsPublish = isPublish.(int)
83 } 88 }
@@ -86,3 +91,40 @@ func (menu *Menu) Update(data map[string]interface{}) error { @@ -86,3 +91,40 @@ func (menu *Menu) Update(data map[string]interface{}) error {
86 } 91 }
87 return nil 92 return nil
88 } 93 }
  94 +
  95 +// GetParentPath 获取菜单路径
  96 +func (menu *Menu) GetParentPath() string {
  97 + if menu.ParentId == 0 {
  98 + return ""
  99 + }
  100 + if len(menu.ParentPath) > 0 {
  101 + return fmt.Sprintf("%v%v%v", menu.ParentPath, PathSegment, menu.MenuId)
  102 + }
  103 + return fmt.Sprintf("%v", menu.MenuId)
  104 +}
  105 +
  106 +// GetFullPath 获取菜单全路径
  107 +func (menu *Menu) GetFullPath() string {
  108 + if menu.ParentId == 0 {
  109 + return ""
  110 + }
  111 + if len(menu.ParentPath) > 0 {
  112 + return fmt.Sprintf("%v%v%v", menu.ParentPath, PathSegment, menu.MenuId)
  113 + }
  114 + return fmt.Sprintf("%v", menu.MenuId)
  115 +}
  116 +
  117 +// GetCategory 获取菜单类别 1.web 2.app
  118 +func (menu *Menu) GetCategory() string {
  119 + if menu.Category == "" {
  120 + return strconv.Itoa(int(menu.MenuId))
  121 + }
  122 + return menu.Category
  123 +}
  124 +
  125 +func (menu *Menu) UpdateParentPath(old, new string) {
  126 + if !strings.Contains(menu.ParentPath, old) {
  127 + return
  128 + }
  129 + menu.ParentPath = strings.Replace(menu.ParentPath, old, new, 1)
  130 +}
@@ -103,7 +103,6 @@ func (repository *MenuRepository) Save(menu *domain.Menu) (*domain.Menu, error) @@ -103,7 +103,6 @@ func (repository *MenuRepository) Save(menu *domain.Menu) (*domain.Menu, error)
103 &menu.IsSystem, 103 &menu.IsSystem,
104 ), 104 ),
105 fmt.Sprintf("UPDATE base.menu SET %s WHERE menu_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 105 fmt.Sprintf("UPDATE base.menu SET %s WHERE menu_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
106 - menu.MenuId,  
107 menu.ParentId, 106 menu.ParentId,
108 menu.MenuName, 107 menu.MenuName,
109 menu.Code, 108 menu.Code,
@@ -136,7 +135,9 @@ func (repository *MenuRepository) FindOne(queryOptions map[string]interface{}) ( @@ -136,7 +135,9 @@ func (repository *MenuRepository) FindOne(queryOptions map[string]interface{}) (
136 tx := repository.transactionContext.PgTx 135 tx := repository.transactionContext.PgTx
137 menuModel := new(models.Menu) 136 menuModel := new(models.Menu)
138 query := sqlbuilder.BuildQuery(tx.Model(menuModel), queryOptions) 137 query := sqlbuilder.BuildQuery(tx.Model(menuModel), queryOptions)
139 - query.SetWhereByQueryOption("menu.menu_id = ?", "menuId") 138 + query.SetWhereByQueryOption("menu_id = ?", "menuId")
  139 + query.SetWhereByQueryOption("parent_id = ?", "parentId")
  140 + query.SetWhereByQueryOption("code = ?", "code")
140 if err := query.First(); err != nil { 141 if err := query.First(); err != nil {
141 if err.Error() == "pg: no rows in result set" { 142 if err.Error() == "pg: no rows in result set" {
142 return nil, fmt.Errorf("没有此资源") 143 return nil, fmt.Errorf("没有此资源")
@@ -155,8 +156,15 @@ func (repository *MenuRepository) Find(queryOptions map[string]interface{}) (int @@ -155,8 +156,15 @@ func (repository *MenuRepository) Find(queryOptions map[string]interface{}) (int
155 var menuModels []*models.Menu 156 var menuModels []*models.Menu
156 menus := make([]*domain.Menu, 0) 157 menus := make([]*domain.Menu, 0)
157 query := sqlbuilder.BuildQuery(tx.Model(&menuModels), queryOptions) 158 query := sqlbuilder.BuildQuery(tx.Model(&menuModels), queryOptions)
  159 + query.SetWhereByQueryOption("category = ?", "category")
  160 + if v, ok := queryOptions["parentPath"]; ok {
  161 + query.Where(fmt.Sprintf("parent_path like '%v%%'", v))
  162 + }
  163 + if v, ok := queryOptions["menuName"]; ok {
  164 + query.Where(fmt.Sprintf("menu_name like '%%%v%%'", v))
  165 + }
158 query.SetOffsetAndLimit(20) 166 query.SetOffsetAndLimit(20)
159 - query.SetOrderDirect("menu_id", "DESC") 167 + query.SetOrderDirect("menu_id", "asc")
160 if count, err := query.SelectAndCount(); err != nil { 168 if count, err := query.SelectAndCount(); err != nil {
161 return 0, menus, err 169 return 0, menus, err
162 } else { 170 } else {
@@ -55,6 +55,9 @@ func (controller *MenuController) ListMenu() { @@ -55,6 +55,9 @@ func (controller *MenuController) ListMenu() {
55 listMenuQuery.Offset = offset 55 listMenuQuery.Offset = offset
56 limit, _ := controller.GetInt("limit") 56 limit, _ := controller.GetInt("limit")
57 listMenuQuery.Limit = limit 57 listMenuQuery.Limit = limit
  58 + listMenuQuery.MenuCategory = controller.GetString("menuCategory")
  59 + listMenuQuery.MenuParentId, _ = controller.GetInt64("parentId", 0)
  60 + listMenuQuery.MenuName = controller.GetString("menuName")
58 data, err := menuService.ListMenu(listMenuQuery) 61 data, err := menuService.ListMenu(listMenuQuery)
59 controller.Response(data, err) 62 controller.Response(data, err)
60 } 63 }
@@ -11,13 +11,12 @@ import ( @@ -11,13 +11,12 @@ import (
11 ) 11 )
12 12
13 var _ = Describe("返回菜单服务", func() { 13 var _ = Describe("返回菜单服务", func() {
14 - return  
15 var menuId int64 14 var menuId int64
16 BeforeEach(func() { 15 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 16 _, err := pG.DB.QueryOne(
18 pg.Scan(&menuId), 17 pg.Scan(&menuId),
19 - "INSERT INTO base.menu (menu_id, parent_id, menu_name, code, access_code, menu_type, icon, sort, desc, category, parent_path, is_publish, is_system) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING menu_id",  
20 - "testMenuId", "testParentId", "testMenuName", "testCode", "testAccessCode", "testMenuType", "testIcon", "testSort", "testDesc", "testCategory", "testParentPath", "testIsPublish", "testIsSystem") 18 + "INSERT INTO base.menu (menu_id, parent_id, menu_name, code, access_code, menu_type, icon, sort, remark, category, parent_path, is_publish, is_system) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING menu_id",
  19 + 1, 0, "testMenuName", "testCode", "testAccessCode", "testMenuType", "testIcon", 1, "testDesc", "testCategory", "testParentPath", 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 20 Expect(err).NotTo(HaveOccurred())
22 }) 21 })
23 Describe("根据menuId参数返回系统菜单", func() { 22 Describe("根据menuId参数返回系统菜单", func() {
@@ -25,7 +24,7 @@ var _ = Describe("返回菜单服务", func() { @@ -25,7 +24,7 @@ var _ = Describe("返回菜单服务", func() {
25 It("返回系统菜单数据", func() { 24 It("返回系统菜单数据", func() {
26 return 25 return
27 httpExpect := httpexpect.New(GinkgoT(), server.URL) 26 httpExpect := httpexpect.New(GinkgoT(), server.URL)
28 - httpExpect.GET("/menus/{Id}"). 27 + httpExpect.GET("/menus/1").
29 Expect(). 28 Expect().
30 Status(http.StatusOK). 29 Status(http.StatusOK).
31 JSON(). 30 JSON().
@@ -11,13 +11,12 @@ import ( @@ -11,13 +11,12 @@ import (
11 ) 11 )
12 12
13 var _ = Describe("返回菜单服务列表", func() { 13 var _ = Describe("返回菜单服务列表", func() {
14 - return  
15 var menuId int64 14 var menuId int64
16 BeforeEach(func() { 15 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 16 _, err := pG.DB.QueryOne(
18 pg.Scan(&menuId), 17 pg.Scan(&menuId),
19 - "INSERT INTO base.menu (menu_id, parent_id, menu_name, code, access_code, menu_type, icon, sort, desc, category, parent_path, is_publish, is_system) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING menu_id",  
20 - "testMenuId", "testParentId", "testMenuName", "testCode", "testAccessCode", "testMenuType", "testIcon", "testSort", "testDesc", "testCategory", "testParentPath", "testIsPublish", "testIsSystem") 18 + "INSERT INTO base.menu (menu_id, parent_id, menu_name, code, access_code, menu_type, icon, sort, remark, category, parent_path, is_publish, is_system) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING menu_id",
  19 + 1, 0, "testMenuName", "testCode", "testAccessCode", "testMenuType", "testIcon", 1, "testDesc", "testCategory", "testfullPath", 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 20 Expect(err).NotTo(HaveOccurred())
22 }) 21 })
23 Describe("根据参数返回系统菜单列表", func() { 22 Describe("根据参数返回系统菜单列表", func() {
@@ -26,8 +25,8 @@ var _ = Describe("返回菜单服务列表", func() { @@ -26,8 +25,8 @@ var _ = Describe("返回菜单服务列表", func() {
26 return 25 return
27 httpExpect := httpexpect.New(GinkgoT(), server.URL) 26 httpExpect := httpexpect.New(GinkgoT(), server.URL)
28 httpExpect.GET("/menus/"). 27 httpExpect.GET("/menus/").
29 - WithQuery("offset", "int").  
30 - WithQuery("limit", "int"). 28 + WithQuery("offset", 0).
  29 + WithQuery("limit", 20).
31 Expect(). 30 Expect().
32 Status(http.StatusOK). 31 Status(http.StatusOK).
33 JSON(). 32 JSON().
@@ -11,13 +11,12 @@ import ( @@ -11,13 +11,12 @@ import (
11 ) 11 )
12 12
13 var _ = Describe("移除菜单服务", func() { 13 var _ = Describe("移除菜单服务", func() {
14 - return  
15 var menuId int64 14 var menuId int64
16 BeforeEach(func() { 15 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 16 _, err := pG.DB.QueryOne(
18 pg.Scan(&menuId), 17 pg.Scan(&menuId),
19 - "INSERT INTO base.menu (menu_id, parent_id, menu_name, code, access_code, menu_type, icon, sort, desc, category, parent_path, is_publish, is_system) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING menu_id",  
20 - "testMenuId", "testParentId", "testMenuName", "testCode", "testAccessCode", "testMenuType", "testIcon", "testSort", "testDesc", "testCategory", "testParentPath", "testIsPublish", "testIsSystem") 18 + "INSERT INTO base.menu (menu_id, parent_id, menu_name, code, access_code, menu_type, icon, sort, remark, category, parent_path, is_publish, is_system) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING menu_id",
  19 + 1, 0, "testMenuName", "testCode", "testAccessCode", "testMenuType", "testIcon", 1, "testDesc", "testCategory", "testfullPath", 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 20 Expect(err).NotTo(HaveOccurred())
22 }) 21 })
23 Describe("根据参数移除菜单服务", func() { 22 Describe("根据参数移除菜单服务", func() {
@@ -25,7 +24,7 @@ var _ = Describe("移除菜单服务", func() { @@ -25,7 +24,7 @@ var _ = Describe("移除菜单服务", func() {
25 It("返回被移除系统菜单的数据", func() { 24 It("返回被移除系统菜单的数据", func() {
26 25
27 httpExpect := httpexpect.New(GinkgoT(), server.URL) 26 httpExpect := httpexpect.New(GinkgoT(), server.URL)
28 - httpExpect.DELETE("/menus/{Id}"). 27 + httpExpect.DELETE("/menus/1").
29 Expect(). 28 Expect().
30 Status(http.StatusOK). 29 Status(http.StatusOK).
31 JSON(). 30 JSON().
@@ -12,12 +12,11 @@ import ( @@ -12,12 +12,11 @@ import (
12 12
13 var _ = Describe("更新菜单服务", func() { 13 var _ = Describe("更新菜单服务", func() {
14 var menuId int64 14 var menuId int64
15 - return  
16 BeforeEach(func() { 15 BeforeEach(func() {
17 _, err := pG.DB.QueryOne( 16 _, err := pG.DB.QueryOne(
18 pg.Scan(&menuId), 17 pg.Scan(&menuId),
19 - "INSERT INTO base.menu (menu_id, parent_id, menu_name, code, access_code, menu_type, icon, sort, desc, category, parent_path, is_publish, is_system) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING menu_id",  
20 - "testMenuId", "testParentId", "testMenuName", "testCode", "testAccessCode", "testMenuType", "testIcon", "testSort", "testDesc", "testCategory", "testParentPath", "testIsPublish", "testIsSystem") 18 + "INSERT INTO base.menu (menu_id, parent_id, menu_name, code, access_code, menu_type, icon, sort, remark, category, parent_path, is_publish, is_system) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING menu_id",
  19 + 1, 0, "testMenuName", "testCode", "testAccessCode", "testMenuType", "testIcon", 1, "testDesc", "testCategory", "testfullPath", 1, 1)
21 Expect(err).NotTo(HaveOccurred()) 20 Expect(err).NotTo(HaveOccurred())
22 }) 21 })
23 Describe("提交数据更新菜单服务", func() { 22 Describe("提交数据更新菜单服务", func() {
@@ -26,17 +25,16 @@ var _ = Describe("更新菜单服务", func() { @@ -26,17 +25,16 @@ var _ = Describe("更新菜单服务", func() {
26 25
27 httpExpect := httpexpect.New(GinkgoT(), server.URL) 26 httpExpect := httpexpect.New(GinkgoT(), server.URL)
28 body := map[string]interface{}{ 27 body := map[string]interface{}{
29 - "menuId": "int64",  
30 - "menuName": "string",  
31 - "code": "string", 28 + "menuName": "string11",
  29 + "code": "string22",
32 "accessCode": "string", 30 "accessCode": "string",
33 - "menuType": "string", 31 + "menuType": "cate",
34 "icon": "string", 32 "icon": "string",
35 - "sort": "int", 33 + "sort": 1,
36 "desc": "string", 34 "desc": "string",
37 - "isPublish": "int", 35 + "isPublish": 0,
38 } 36 }
39 - httpExpect.PUT("/menus/{Id}"). 37 + httpExpect.PUT("/menus/1").
40 WithJSON(body). 38 WithJSON(body).
41 Expect(). 39 Expect().
42 Status(http.StatusOK). 40 Status(http.StatusOK).