17
17
18
18
import cn .hutool .jwt .JWTPayload ;
19
19
import cn .hutool .jwt .JWTUtil ;
20
+ import com .robin .basis .dto .LoginUserDTO ;
20
21
import com .robin .basis .dto .SysMenuDTO ;
22
+ import com .robin .basis .model .system .SysResource ;
21
23
import com .robin .basis .sercurity .SysLoginUser ;
22
24
import com .robin .basis .service .system .SysResourceService ;
23
25
import com .robin .basis .utils .SecurityUtils ;
26
28
import com .robin .core .base .spring .SpringContextHolder ;
27
29
import com .robin .core .base .util .Const ;
28
30
import com .robin .core .convert .util .ConvertUtil ;
31
+ import com .robin .core .query .util .PageQuery ;
29
32
import com .robin .core .web .controller .AbstractController ;
30
33
import com .robin .core .web .service .ILoginService ;
31
34
import com .robin .core .web .util .CookieUtils ;
36
39
import org .springframework .security .authentication .AuthenticationManager ;
37
40
import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
38
41
import org .springframework .security .core .Authentication ;
42
+ import org .springframework .util .CollectionUtils ;
39
43
import org .springframework .util .ObjectUtils ;
40
44
import org .springframework .web .bind .annotation .GetMapping ;
41
45
import org .springframework .web .bind .annotation .PostMapping ;
48
52
import javax .servlet .http .HttpServletResponse ;
49
53
import java .time .LocalDateTime ;
50
54
import java .time .ZoneId ;
51
- import java .util .Arrays ;
52
- import java .util .HashMap ;
53
- import java .util .List ;
54
- import java .util .Map ;
55
+ import java .util .*;
56
+ import java .util .function .Function ;
57
+ import java .util .stream .Collectors ;
55
58
56
59
@ RestController
57
60
public class LoginController extends AbstractController {
@@ -154,21 +157,74 @@ public boolean validateCaptcha(String code, String uuid) {
154
157
public Map <String , Object > getUserInfo (HttpServletRequest request ) {
155
158
SysLoginUser loginUser = SecurityUtils .getLoginUser ();
156
159
Map <String , Object > retMap = new HashMap <>();
157
- retMap .put ("user " , loginUser );
160
+ retMap .put ("info " , LoginUserDTO . fromLoginUsers ( loginUser ) );
158
161
retMap .put ("roles" , loginUser .getRoles ());
159
- return retMap ;
162
+ retMap .put ("permission" ,loginUser .getPermissions ());
163
+ return wrapObject (retMap );
160
164
}
161
165
162
166
@ GetMapping ("/getRouters" )
163
167
public Map <String , Object > getRouter (HttpServletRequest request ) {
164
168
Map <String , Object > retMap = new HashMap <>();
165
169
SysLoginUser loginUser =SecurityUtils .getLoginUser ();
166
170
if (loginUser != null ) {
167
- List <SysMenuDTO > routers = resourceService . getMenuList (loginUser .getId ());
171
+ List <SysMenuDTO > routers = getMenuList (loginUser .getId ());
168
172
retMap = wrapObject (routers );
169
173
} else {
170
174
wrapError (retMap , "not login" );
171
175
}
172
176
return retMap ;
173
177
}
178
+ public List <SysMenuDTO > getMenuList (Long userId ) {
179
+ List <SysResource > allList = resourceService .getAllValidate ();
180
+ List <SysMenuDTO > dtoList = allList .stream ().map (SysMenuDTO ::fromVO ).collect (Collectors .toList ());
181
+ Map <Long , SysMenuDTO > dtoMap = dtoList .stream ().collect (Collectors .toMap (SysMenuDTO ::getId , Function .identity ()));
182
+ SysMenuDTO root = new SysMenuDTO ();
183
+ dtoMap .put (0L , root );
184
+ Map <Long , Integer > readMap = new HashMap <>();
185
+
186
+ PageQuery <Map <String , Object >> query1 = new PageQuery ();
187
+ query1 .setPageSize (0 );
188
+ query1 .setSelectParamId ("GET_RESOURCEINFO" );
189
+ query1 .addNamedParameter ("userId" , userId );
190
+ jdbcDao .queryBySelectId (query1 );
191
+ try {
192
+ if (!query1 .getRecordSet ().isEmpty ()) {
193
+ Map <Long , List <SysMenuDTO >> aMap = query1 .getRecordSet ().stream ().map (SysMenuDTO ::fromMap ).collect (Collectors .groupingBy (SysMenuDTO ::getPid , Collectors .toList ()));
194
+
195
+ List <SysMenuDTO > tops = aMap .get (0L );
196
+ tops .sort (Comparator .comparing (SysMenuDTO ::getSeqNo ));
197
+ for (SysMenuDTO dto : tops ) {
198
+ if (!readMap .containsKey (dto .getId ()) && !dto .getAssignType ().equals (Const .RESOURCE_ASSIGN_DENIED )) {
199
+ if (dtoMap .get (dto .getPid ()).getChildren ()==null ){
200
+ dtoMap .get (dto .getPid ()).setChildren (new ArrayList <>());
201
+ }
202
+ dtoMap .get (dto .getPid ()).getChildren ().add (dtoMap .get (dto .getId ()));
203
+ doScanChildren (dtoMap , aMap , dto , readMap );
204
+ }
205
+ readMap .put (dto .getId (), 0 );
206
+ }
207
+
208
+ }
209
+ } catch (Exception ex ) {
210
+ ex .printStackTrace ();
211
+ }
212
+ return dtoMap .get (0L ).getChildren ();
213
+ }
214
+
215
+ private void doScanChildren (Map <Long , SysMenuDTO > cmap , Map <Long , List <SysMenuDTO >> pMap , SysMenuDTO dto , Map <Long , Integer > readMap ) {
216
+ if (!CollectionUtils .isEmpty (pMap .get (dto .getId ()))) {
217
+ pMap .get (dto .getId ()).sort (Comparator .comparing (SysMenuDTO ::getSeqNo ));
218
+ for (SysMenuDTO childs : pMap .get (dto .getId ())) {
219
+ if (!readMap .containsKey (childs .getId ()) && !childs .getAssignType ().equals (Const .RESOURCE_ASSIGN_DENIED )) {
220
+ if (cmap .get (childs .getPid ()).getChildren ()==null ){
221
+ cmap .get (childs .getPid ()).setChildren (new ArrayList <>());
222
+ }
223
+ cmap .get (childs .getPid ()).getChildren ().add (cmap .get (childs .getId ()));
224
+ doScanChildren (cmap , pMap , childs , readMap );
225
+ }
226
+ readMap .put (childs .getId (), 0 );
227
+ }
228
+ }
229
+ }
174
230
}
0 commit comments