5
5
import com .example .springbootshiro .domain .Tree ;
6
6
import com .example .springbootshiro .service .BaseService ;
7
7
import com .example .springbootshiro .service .MenuService ;
8
+ import com .example .springbootshiro .service .RoleMenuService ;
8
9
import com .example .springbootshiro .util .StringUtils ;
10
+ import com .example .springbootshiro .util .TreeUtils ;
9
11
import org .springframework .beans .factory .annotation .Autowired ;
10
12
import org .springframework .stereotype .Service ;
11
13
import org .springframework .transaction .annotation .Propagation ;
12
14
import org .springframework .transaction .annotation .Transactional ;
13
15
import tk .mybatis .mapper .entity .Example ;
14
16
15
17
import java .util .ArrayList ;
18
+ import java .util .Arrays ;
19
+ import java .util .Date ;
16
20
import java .util .List ;
17
21
18
22
/**
@@ -25,6 +29,9 @@ public class MenuServiceImpl extends BaseService<MenuInfo> implements MenuServic
25
29
@ Autowired
26
30
private MenuMapper menuMapper ;
27
31
32
+ @ Autowired
33
+ private RoleMenuService roleMenuService ;
34
+
28
35
@ Override
29
36
public List <MenuInfo > findUserPermissions (String userName ) {
30
37
return this .menuMapper .findUserPermissions (userName );
@@ -62,42 +69,93 @@ public Tree<MenuInfo> getMenuButtonTree() {
62
69
tree .setText (menuInfo .getMenuName ());
63
70
trees .add (tree );
64
71
}
65
- Tree <MenuInfo > t = null ;
72
+ Tree <MenuInfo > t = TreeUtils . build ( trees ) ;
66
73
return t ;
67
74
}
68
75
69
76
@ Override
70
77
public Tree <MenuInfo > getMenuTree () {
71
- return null ;
78
+ List <Tree <MenuInfo >> trees = new ArrayList <>();
79
+ Example example = new Example (MenuInfo .class );
80
+ example .createCriteria ().andCondition ("type=" , 0 );
81
+ example .setOrderByClause ("create_time" );
82
+ List <MenuInfo > menus = this .menuMapper .selectByExample (example );
83
+ for (MenuInfo menuInfo : menus ){
84
+ Tree <MenuInfo > tree = new Tree <>();
85
+ tree .setId (menuInfo .getMenuId ().toString ());
86
+ tree .setParentId (menuInfo .getParentId ().toString ());
87
+ tree .setText (menuInfo .getMenuName ());
88
+
89
+ trees .add (tree );
90
+ }
91
+
92
+ Tree <MenuInfo > t = TreeUtils .build (trees );
93
+ return t ;
72
94
}
73
95
74
96
@ Override
75
97
public Tree <MenuInfo > getUserMenu (String userName ) {
76
- return null ;
98
+
99
+ List <Tree <MenuInfo >> trees = new ArrayList <>();
100
+ List <MenuInfo > menus = findUserMenus (userName );
101
+
102
+ for (MenuInfo menu : menus ) {
103
+ Tree <MenuInfo > tree = new Tree <MenuInfo >();
104
+ tree .setId (menu .getMenuId ().toString ());
105
+ tree .setParentId (menu .getParentId ().toString ());
106
+ tree .setText (menu .getMenuName ());
107
+ tree .setUrl (menu .getUrl ());
108
+ trees .add (tree );
109
+ }
110
+ Tree <MenuInfo > t = TreeUtils .build (trees );
111
+ return t ;
77
112
}
78
113
79
114
@ Override
80
115
public MenuInfo findById (Long menuId ) {
81
- return null ;
116
+ return selectByKey ( menuId ) ;
82
117
}
83
118
84
119
@ Override
85
120
public MenuInfo findByNameAndType (String menuName , String type ) {
86
- return null ;
121
+ Example example = new Example (MenuInfo .class );
122
+ example .createCriteria ().andCondition ("lower(menu_name)=" , menuName .toLowerCase ())
123
+ .andEqualTo ("type" , Long .valueOf (type ));
124
+ List <MenuInfo > list = menuMapper .selectByExample (example );
125
+ if (list .size () == 0 ) {
126
+ return null ;
127
+ }else {
128
+ return list .get (0 );
129
+ }
87
130
}
88
131
89
132
@ Override
133
+ @ Transactional (propagation = Propagation .REQUIRED , readOnly = false )
90
134
public void addMenu (MenuInfo menu ) {
91
-
135
+ menu .setCreateTime (new Date ());
136
+ if (menu .getParentId () == null ) {
137
+ menu .setParentId (0L );
138
+ }
139
+ this .save (menu );
92
140
}
93
141
94
142
@ Override
143
+ @ Transactional (propagation = Propagation .REQUIRED , readOnly = false )
95
144
public void updateMenu (MenuInfo menu ) {
145
+ menu .setModifyTime (new Date ());
146
+ if (menu .getParentId () == null ) {
147
+ menu .setParentId (0L );
148
+ }
149
+ this .updateNotNull (menu );
96
150
97
151
}
98
152
99
153
@ Override
154
+ @ Transactional (propagation = Propagation .REQUIRED , readOnly = false )
100
155
public void deleteMeuns (String menuIds ) {
101
-
156
+ List <String > list = Arrays .asList (menuIds .split ("," ));
157
+ batchDelete (list , "menuId" , MenuInfo .class );
158
+ roleMenuService .deleteRoleMenusByMenuId (menuIds );
159
+ menuMapper .changToTop (list );
102
160
}
103
161
}
0 commit comments