Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
smart_gov_platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
smart_gov_platform
Commits
63a43d97
Commit
63a43d97
authored
Nov 17, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加资源自动刷新获取
parent
6da6770a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
488 additions
and
55 deletions
+488
-55
base-manager/src/main/java/com/mortals/xhx/base/system/resource/service/ResourceService.java
...als/xhx/base/system/resource/service/ResourceService.java
+10
-5
base-manager/src/main/java/com/mortals/xhx/base/system/resource/service/impl/ResourceServiceImpl.java
...ase/system/resource/service/impl/ResourceServiceImpl.java
+73
-5
base-manager/src/main/java/com/mortals/xhx/base/system/resource/web/ResourceController.java
...tals/xhx/base/system/resource/web/ResourceController.java
+68
-43
base-manager/src/main/java/com/mortals/xhx/common/utils/ControllerScanUtil.java
...java/com/mortals/xhx/common/utils/ControllerScanUtil.java
+337
-0
portal-manager/src/main/java/com/mortals/xhx/module/area/web/AreaController.java
.../java/com/mortals/xhx/module/area/web/AreaController.java
+0
-2
No files found.
base-manager/src/main/java/com/mortals/xhx/base/system/resource/service/ResourceService.java
View file @
63a43d97
...
@@ -9,7 +9,9 @@
...
@@ -9,7 +9,9 @@
package
com.mortals.xhx.base.system.resource.service
;
package
com.mortals.xhx.base.system.resource.service
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.service.ICRUDService
;
import
com.mortals.framework.service.ICRUDService
;
import
com.mortals.xhx.base.system.resource.model.ResourceEntity
;
import
com.mortals.xhx.base.system.resource.model.ResourceEntity
;
...
@@ -31,7 +33,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
...
@@ -31,7 +33,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
* @return
* @return
* @throws AppException
* @throws AppException
*/
*/
public
List
<
ResourceEntity
>
findAllEnable
()
throws
AppException
;
List
<
ResourceEntity
>
findAllEnable
()
throws
AppException
;
/**
/**
* 根据用户查询可用资源
* 根据用户查询可用资源
...
@@ -39,7 +41,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
...
@@ -39,7 +41,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
* @return
* @return
* @throws AppException
* @throws AppException
*/
*/
public
List
<
ResourceEntity
>
findListByUserId
(
Long
userId
)
throws
AppException
;
List
<
ResourceEntity
>
findListByUserId
(
Long
userId
)
throws
AppException
;
/**
/**
* 查询用户可用资源
* 查询用户可用资源
...
@@ -47,7 +49,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
...
@@ -47,7 +49,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
* @return 字符串,多个以逗号分隔
* @return 字符串,多个以逗号分隔
* @throws AppException
* @throws AppException
*/
*/
public
String
findUrlByUserId
(
Long
userId
)
throws
AppException
;
String
findUrlByUserId
(
Long
userId
)
throws
AppException
;
/**
/**
* 查询用户用资源集合
* 查询用户用资源集合
...
@@ -55,7 +57,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
...
@@ -55,7 +57,7 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
* @return
* @return
* @throws AppException
* @throws AppException
*/
*/
public
Set
<
String
>
findUrlSetByUserId
(
Long
userId
)
throws
AppException
;
Set
<
String
>
findUrlSetByUserId
(
Long
userId
)
throws
AppException
;
/**
/**
* 获取所有资源,不分页
* 获取所有资源,不分页
...
@@ -63,5 +65,8 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
...
@@ -63,5 +65,8 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
* @param userType
* @param userType
*/
*/
List
<
ResourceEntity
>
findAll
(
int
userType
);
List
<
ResourceEntity
>
findAll
(
int
userType
);
Rest
<
String
>
refreshResourceUrl
(
String
packageName
,
Context
context
);
}
}
\ No newline at end of file
base-manager/src/main/java/com/mortals/xhx/base/system/resource/service/impl/ResourceServiceImpl.java
View file @
63a43d97
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
package
com.mortals.xhx.base.system.resource.service.impl
;
package
com.mortals.xhx.base.system.resource.service.impl
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.service.ICacheService
;
...
@@ -18,19 +19,17 @@ import com.mortals.xhx.base.system.resource.dao.ResourceDao;
...
@@ -18,19 +19,17 @@ import com.mortals.xhx.base.system.resource.dao.ResourceDao;
import
com.mortals.xhx.base.system.resource.model.ResourceEntity
;
import
com.mortals.xhx.base.system.resource.model.ResourceEntity
;
import
com.mortals.xhx.base.system.resource.model.ResourceQuery
;
import
com.mortals.xhx.base.system.resource.model.ResourceQuery
;
import
com.mortals.xhx.base.system.resource.service.ResourceService
;
import
com.mortals.xhx.base.system.resource.service.ResourceService
;
import
com.mortals.xhx.base.system.role.model.RoleAuthEntity
;
import
com.mortals.xhx.base.system.role.model.RoleAuthEntity
;
import
com.mortals.xhx.base.system.role.model.RoleAuthQuery
;
import
com.mortals.xhx.base.system.role.model.RoleAuthQuery
;
import
com.mortals.xhx.base.system.role.service.RoleAuthService
;
import
com.mortals.xhx.base.system.role.service.RoleAuthService
;
import
com.mortals.xhx.common.key.RedisKey
;
import
com.mortals.xhx.common.key.RedisKey
;
import
com.mortals.xhx.common.utils.ControllerScanUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
java.util.Arrays
;
import
java.util.*
;
import
java.util.HashSet
;
import
java.util.stream.Collectors
;
import
java.util.List
;
import
java.util.Set
;
import
static
com
.
mortals
.
xhx
.
common
.
utils
.
MenuEncodeUtil
.
generateMenuUrlCode
;
import
static
com
.
mortals
.
xhx
.
common
.
utils
.
MenuEncodeUtil
.
generateMenuUrlCode
;
...
@@ -39,6 +38,7 @@ import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
...
@@ -39,6 +38,7 @@ import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
* <p>Description: ResourceServiceImpl service接口 </p>
* <p>Description: ResourceServiceImpl service接口 </p>
* <p>Copyright: Copyright ® </p>
* <p>Copyright: Copyright ® </p>
* <p>Company: </p>
* <p>Company: </p>
*
* @author
* @author
* @version 1.0.0
* @version 1.0.0
*/
*/
...
@@ -88,6 +88,74 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
...
@@ -88,6 +88,74 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
return
dao
.
getAll
(
userType
);
return
dao
.
getAll
(
userType
);
}
}
@Override
public
Rest
<
String
>
refreshResourceUrl
(
String
packageName
,
Context
context
)
{
List
<
Class
<?>>
classList
=
ControllerScanUtil
.
getAllClassByPackageName
(
packageName
);
//System.out.println(classList); //获取到了所有的类
List
<
ResourceEntity
>
newResourcelist
=
ControllerScanUtil
.
getAnnotationInfo
(
classList
).
stream
().
filter
(
f
->!
ObjectUtils
.
isEmpty
(
f
.
getUrl
())).
collect
(
Collectors
.
toList
());
Map
<
String
,
List
<
ResourceEntity
>>
localResourceMap
=
this
.
find
(
new
ResourceQuery
()).
stream
().
collect
(
Collectors
.
groupingBy
(
x
->
x
.
getName
()));
Map
<
String
,
List
<
ResourceEntity
>>
newResourceMap
=
newResourcelist
.
stream
().
collect
(
Collectors
.
groupingBy
(
x
->
x
.
getName
()));
//更新 与新增 新加的;
newResourceMap
.
entrySet
().
forEach
(
item
->
{
List
<
ResourceEntity
>
resourceEntities
=
item
.
getValue
();
if
(
ObjectUtils
.
isEmpty
(
resourceEntities
))
return
;
if
(
resourceEntities
.
size
()
==
1
)
{
ResourceEntity
resourceEntity
=
resourceEntities
.
get
(
0
);
saveUpdateResourceEntity
(
context
,
localResourceMap
,
resourceEntity
);
}
else
if
(
resourceEntities
.
size
()
>
1
)
{
//原始扫描 有多个资源列表针对一个名称的
for
(
ResourceEntity
resourceEntity
:
resourceEntities
)
{
saveUpdateResourceEntity
(
context
,
localResourceMap
,
resourceEntity
);
}
}
});
return
Rest
.
ok
();
}
private
void
saveUpdateResourceEntity
(
Context
context
,
Map
<
String
,
List
<
ResourceEntity
>>
localResourceMap
,
ResourceEntity
resourceEntity
)
{
//查找 本地是否已经存在了
List
<
ResourceEntity
>
tempResourceList
=
localResourceMap
.
getOrDefault
(
resourceEntity
.
getName
(),
new
ArrayList
<>());
if
(
tempResourceList
.
size
()
==
0
)
{
//新增 resource;
resourceEntity
.
setCreateUserId
(
this
.
getContextUserId
(
context
));
resourceEntity
.
setCreateTime
(
new
Date
());
this
.
save
(
resourceEntity
,
context
);
}
else
if
(
tempResourceList
.
size
()
==
1
)
{
//更新
ResourceEntity
tempResource
=
tempResourceList
.
get
(
0
);
Set
<
String
>
setUrl
=
Arrays
.
stream
(
resourceEntity
.
getUrl
().
split
(
","
)).
collect
(
Collectors
.
toSet
());
Arrays
.
stream
(
tempResource
.
getUrl
().
split
(
","
)).
forEach
(
i
->
{
setUrl
.
add
(
i
);
});
resourceEntity
.
setUrl
(
setUrl
.
stream
().
collect
(
Collectors
.
joining
(
","
)));
this
.
update
(
resourceEntity
,
context
);
}
else
if
(
tempResourceList
.
size
()
>
1
)
{
//找到多个同名的 资源配置
for
(
ResourceEntity
tempResource
:
tempResourceList
)
{
//模糊匹配到路径有一个存在的
Set
<
String
>
setUrl
=
Arrays
.
stream
(
resourceEntity
.
getUrl
().
split
(
","
)).
collect
(
Collectors
.
toSet
());
String
[]
splitUrl
=
tempResource
.
getUrl
().
split
(
","
);
Boolean
bool
=
false
;
for
(
int
i
=
0
;
i
<
splitUrl
.
length
;
i
++)
{
if
(
setUrl
.
contains
(
splitUrl
[
i
]))
{
bool
=
true
;
break
;
}
}
if
(
bool
)
{
//匹配到了,更新当前这个资源
Arrays
.
stream
(
tempResource
.
getUrl
().
split
(
","
)).
forEach
(
i
->
{
setUrl
.
add
(
i
);
});
resourceEntity
.
setUrl
(
setUrl
.
stream
().
collect
(
Collectors
.
joining
(
","
)));
this
.
update
(
resourceEntity
,
context
);
}
}
}
}
@Override
@Override
protected
void
updateAfter
(
ResourceEntity
entity
,
Context
context
)
throws
AppException
{
protected
void
updateAfter
(
ResourceEntity
entity
,
Context
context
)
throws
AppException
{
...
...
base-manager/src/main/java/com/mortals/xhx/base/system/resource/web/ResourceController.java
View file @
63a43d97
package
com.mortals.xhx.base.system.resource.web
;
package
com.mortals.xhx.base.system.resource.web
;
import
java.util.HashMap
;
import
com.alibaba.fastjson.JSONObject
;
import
java.util.Map
;
import
com.mortals.framework.annotation.UnAuth
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.mortals.framework.common.IBaseEnum
;
import
com.mortals.framework.common.IBaseEnum
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.common.code.UserType
;
import
com.mortals.framework.common.code.UserType
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
import
com.mortals.xhx.base.system.resource.model.ResourceEntity
;
import
com.mortals.xhx.base.system.resource.service.ResourceService
;
import
com.mortals.xhx.common.code.AuthType
;
import
com.mortals.xhx.common.code.SourceType
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.alibaba.fastjson.JSONObject
;
import
java.util.HashMap
;
import
com.mortals.framework.model.Context
;
import
java.util.Map
;
import
com.mortals.framework.web.BaseCRUDJsonMappingController
;
import
com.mortals.xhx.base.system.resource.model.ResourceEntity
;
import
com.mortals.xhx.base.system.resource.service.ResourceService
;
import
com.mortals.xhx.common.code.AuthType
;
import
com.mortals.xhx.common.code.SourceType
;
/**
/**
* 资源信息
* 资源信息
...
@@ -32,37 +31,63 @@ import com.mortals.xhx.common.code.SourceType;
...
@@ -32,37 +31,63 @@ import com.mortals.xhx.common.code.SourceType;
@Slf4j
@Slf4j
@RestController
@RestController
@RequestMapping
(
"resource"
)
@RequestMapping
(
"resource"
)
public
class
ResourceController
extends
BaseCRUDJsonBodyMappingController
<
ResourceService
,
ResourceEntity
,
Long
>
{
public
class
ResourceController
extends
BaseCRUDJsonBodyMappingController
<
ResourceService
,
ResourceEntity
,
Long
>
{
public
ResourceController
()
{
super
.
setModuleDesc
(
"资源信息"
);
}
@Override
protected
void
init
(
Map
<
String
,
Object
>
model
,
Context
context
)
{
Map
<
String
,
Object
>
statsus
=
new
HashMap
<
String
,
Object
>();
statsus
.
put
(
"authType"
,
AuthType
.
getEnumMap
());
statsus
.
put
(
"sourceType"
,
SourceType
.
getEnumMap
());
if
(
getCurUser
().
isAdmin
())
{
statsus
.
put
(
"userType"
,
IBaseEnum
.
getEnumMap
(
UserType
.
class
));
}
else
{
statsus
.
put
(
"userType"
,
UserType
.
findByValue
(
getCurUser
().
getUserType
()));
}
model
.
put
(
KEY_RESULT_DICT
,
statsus
);
}
/**
* 获取所有资源
*
* @return
*/
@PostMapping
(
"allResources"
)
public
String
allResources
(
int
userType
)
{
JSONObject
ret
=
new
JSONObject
();
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
ret
.
put
(
KEY_RESULT_MSG
,
"所有的customer以及user"
);
ret
.
put
(
KEY_RESULT_DATA
,
service
.
findAll
(
userType
));
return
ret
.
toJSONString
();
}
@Override
protected
void
doListBefore
(
ResourceEntity
query
,
Map
<
String
,
Object
>
model
,
Context
context
)
throws
AppException
{
public
ResourceController
(){
super
.
doListBefore
(
query
,
model
,
context
);
super
.
setModuleDesc
(
"资源信息"
);
}
}
@Override
/**
protected
void
init
(
Map
<
String
,
Object
>
model
,
Context
context
)
{
* 资源路径刷新
Map
<
String
,
Object
>
statsus
=
new
HashMap
<
String
,
Object
>();
*/
statsus
.
put
(
"authType"
,
AuthType
.
getEnumMap
());
@PostMapping
(
value
=
"refreshUrl"
)
statsus
.
put
(
"sourceType"
,
SourceType
.
getEnumMap
());
@UnAuth
if
(
getCurUser
().
isAdmin
())
{
public
Rest
<
String
>
refreshUrl
(
@RequestParam
(
name
=
"packageName"
,
defaultValue
=
"com.mortals.xhx"
)
String
packageName
)
{
statsus
.
put
(
"userType"
,
IBaseEnum
.
getEnumMap
(
UserType
.
class
));
log
.
info
(
"刷新资源路径,packageName"
,
packageName
);
}
else
{
String
busiDesc
=
this
.
getModuleDesc
()
+
"资源路径刷新"
;
statsus
.
put
(
"userType"
,
UserType
.
findByValue
(
getCurUser
().
getUserType
()));
Rest
<
String
>
rest
=
Rest
.
ok
(
busiDesc
+
" 【成功】"
);
}
try
{
model
.
put
(
KEY_RESULT_DICT
,
statsus
);
this
.
service
.
refreshResourceUrl
(
packageName
,
getContext
());
}
recordSysLog
(
request
,
busiDesc
+
" 【成功】"
);
}
catch
(
Exception
e
)
{
log
.
error
(
busiDesc
,
e
);
rest
=
Rest
.
fail
(
super
.
convertException
(
e
));
}
return
rest
;
}
/**
* 获取所有资源
*
* @return
*/
@PostMapping
(
"allResources"
)
public
String
allResources
(
int
userType
)
{
JSONObject
ret
=
new
JSONObject
();
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
ret
.
put
(
KEY_RESULT_MSG
,
"所有的customer以及user"
);
ret
.
put
(
KEY_RESULT_DATA
,
service
.
findAll
(
userType
));
return
ret
.
toJSONString
();
}
}
}
\ No newline at end of file
base-manager/src/main/java/com/mortals/xhx/common/utils/ControllerScanUtil.java
0 → 100644
View file @
63a43d97
package
com.mortals.xhx.common.utils
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.annotation.UnAuth
;
import
com.mortals.xhx.base.system.resource.model.ResourceEntity
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.IOException
;
import
java.lang.reflect.Method
;
import
java.net.JarURLConnection
;
import
java.net.URL
;
import
java.net.URLDecoder
;
import
java.util.*
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
import
java.util.stream.Collectors
;
public
class
ControllerScanUtil
{
/**
* 查看类路径
*/
public
static
final
String
[]
ULR_VIEW
=
{
"view"
,
"info"
,
"list"
,
"get"
,
"find"
,
"export"
,
"download"
,
"index"
,
"bill"
};
public
static
final
String
[]
WHITE_URL
=
{
"login"
,
"test"
,
"file"
,
"securitycode"
};
public
static
void
main
(
String
[]
args
)
{
List
<
Class
<?>>
classList
=
getAllClassByPackageName
(
"com.mortals.xhx"
);
//System.out.println(classList); //获取到了所有的类
getAnnotationInfo
(
classList
);
}
public
static
List
<
ResourceEntity
>
getAnnotationInfo
(
List
<
Class
<?>>
clsList
)
{
List
<
ResourceEntity
>
resourceArrayList
=
new
ArrayList
<>();
if
(
clsList
!=
null
&&
clsList
.
size
()
>
0
)
{
for
(
Class
<?>
cls
:
clsList
)
{
boolean
exits
=
cls
.
isAnnotationPresent
(
RestController
.
class
);
if
(!
exits
)
{
continue
;
}
//白名单地址的 也不需要
ResourceEntity
resourceViewEntity
=
new
ResourceEntity
();
resourceViewEntity
.
initAttrValue
();
ResourceEntity
resourceEditEntity
=
new
ResourceEntity
();
resourceEditEntity
.
initAttrValue
();
Method
substringMethod
=
null
;
String
result
=
""
;
try
{
String
packName
=
cls
.
getPackage
().
getName
();
if
(
StrUtil
.
contains
(
packName
,
"system"
))
{
//系统管理-xx管理-
substringMethod
=
cls
.
getMethod
(
"getModuleDesc"
);
result
=
(
String
)
substringMethod
.
invoke
(
cls
.
newInstance
());
resourceViewEntity
.
setName
(
"系统管理-"
+
result
+
"管理-查看"
);
resourceEditEntity
.
setName
(
"系统管理-"
+
result
+
"管理-维护"
);
}
else
{
substringMethod
=
cls
.
getMethod
(
"getModuleDesc"
);
result
=
(
String
)
substringMethod
.
invoke
(
cls
.
newInstance
());
resourceViewEntity
.
setName
(
result
+
"-查看"
);
resourceEditEntity
.
setName
(
result
+
"-维护"
);
}
}
catch
(
Exception
e
)
{
}
RequestMapping
requestMappingCls
=
cls
.
getAnnotation
(
RequestMapping
.
class
);
String
prefix
=
""
;
if
(
requestMappingCls
!=
null
)
{
prefix
=
"/"
+
requestMappingCls
.
value
()[
0
];
boolean
b
=
false
;
for
(
String
s
:
WHITE_URL
)
{
if
(
StrUtil
.
contains
(
requestMappingCls
.
value
()[
0
].
toLowerCase
(),
s
))
{
b
=
true
;
break
;
}
}
if
(
b
)
{
continue
;
}
}
if
(
ObjectUtils
.
isEmpty
(
result
))
{
if
(
requestMappingCls
!=
null
)
{
result
=
StrUtil
.
removeSuffix
(
StrUtil
.
removePrefix
(
requestMappingCls
.
value
()[
0
].
toUpperCase
(),
"/"
),
"/"
)
+
"接口模块"
;
}
resourceViewEntity
.
setName
(
result
+
"-查看"
);
resourceEditEntity
.
setName
(
result
+
"-维护"
);
}
Set
<
String
>
urlSet
=
new
HashSet
<>();
//获取类中的所有的方法
Method
[]
methods
=
cls
.
getDeclaredMethods
();
if
(
methods
!=
null
&&
methods
.
length
>
0
)
{
for
(
Method
method
:
methods
)
{
boolean
unAuth
=
method
.
isAnnotationPresent
(
UnAuth
.
class
);
if
(
unAuth
)
{
continue
;
}
boolean
mExits
=
method
.
isAnnotationPresent
(
RequestMapping
.
class
);
if
(
mExits
)
{
RequestMapping
requestMapping
=
method
.
getAnnotation
(
RequestMapping
.
class
);
String
url
=
prefix
+
"/"
+
requestMapping
.
value
()[
0
];
url
=
url
.
replaceAll
(
"/+"
,
"/"
);
urlSet
.
add
(
url
);
}
boolean
mExits1
=
method
.
isAnnotationPresent
(
GetMapping
.
class
);
if
(
mExits1
)
{
GetMapping
getMapping
=
method
.
getAnnotation
(
GetMapping
.
class
);
String
url
=
prefix
+
"/"
+
getMapping
.
value
()[
0
];
url
=
url
.
replaceAll
(
"/+"
,
"/"
);
urlSet
.
add
(
url
);
}
boolean
mExits2
=
method
.
isAnnotationPresent
(
PostMapping
.
class
);
if
(
mExits2
)
{
PostMapping
postMapping
=
method
.
getAnnotation
(
PostMapping
.
class
);
String
url
=
prefix
+
"/"
+
postMapping
.
value
()[
0
];
url
=
url
.
replaceAll
(
"/+"
,
"/"
);
urlSet
.
add
(
url
);
}
}
}
//获取超类中的方法
Method
[]
superMethods
=
cls
.
getSuperclass
().
getDeclaredMethods
();
if
(
superMethods
!=
null
&&
superMethods
.
length
>
0
)
{
for
(
Method
method
:
superMethods
)
{
boolean
unAuth
=
method
.
isAnnotationPresent
(
UnAuth
.
class
);
if
(
unAuth
)
{
continue
;
}
boolean
mExits
=
method
.
isAnnotationPresent
(
RequestMapping
.
class
);
if
(
mExits
)
{
RequestMapping
requestMapping
=
method
.
getAnnotation
(
RequestMapping
.
class
);
String
url
=
prefix
+
"/"
+
requestMapping
.
value
()[
0
];
url
=
url
.
replaceAll
(
"/+"
,
"/"
);
urlSet
.
add
(
url
);
}
boolean
mExits1
=
method
.
isAnnotationPresent
(
GetMapping
.
class
);
if
(
mExits1
)
{
GetMapping
getMapping
=
method
.
getAnnotation
(
GetMapping
.
class
);
String
url
=
prefix
+
"/"
+
getMapping
.
value
()[
0
];
url
=
url
.
replaceAll
(
"/+"
,
"/"
);
urlSet
.
add
(
url
);
}
boolean
mExits2
=
method
.
isAnnotationPresent
(
PostMapping
.
class
);
if
(
mExits2
)
{
PostMapping
postMapping
=
method
.
getAnnotation
(
PostMapping
.
class
);
String
url
=
prefix
+
"/"
+
postMapping
.
value
()[
0
];
url
=
url
.
replaceAll
(
"/+"
,
"/"
);
urlSet
.
add
(
url
);
}
}
}
if
(!
ObjectUtils
.
isEmpty
(
urlSet
))
{
Set
<
String
>
UrlViewSet
=
new
HashSet
<>();
Set
<
String
>
UrlEditSet
=
new
HashSet
<>();
for
(
String
url
:
urlSet
)
{
String
str
=
StrUtil
.
subAfter
(
url
,
"/"
,
true
);
boolean
bool
=
false
;
for
(
String
checkStr
:
ULR_VIEW
)
{
boolean
contains
=
StrUtil
.
contains
(
str
.
toLowerCase
(),
checkStr
);
if
(
contains
)
{
UrlViewSet
.
add
(
url
);
bool
=
true
;
break
;
}
}
if
(!
bool
)
{
UrlEditSet
.
add
(
url
);
}
}
resourceViewEntity
.
setUrl
(
UrlViewSet
.
stream
().
collect
(
Collectors
.
joining
(
","
)));
System
.
out
.
println
(
JSONObject
.
toJSONString
(
resourceViewEntity
));
resourceArrayList
.
add
(
resourceViewEntity
);
resourceEditEntity
.
setUrl
(
UrlEditSet
.
stream
().
collect
(
Collectors
.
joining
(
","
)));
System
.
out
.
println
(
JSONObject
.
toJSONString
(
resourceEditEntity
));
resourceArrayList
.
add
(
resourceEditEntity
);
}
}
}
return
resourceArrayList
;
}
public
static
List
<
Class
<?>>
getAllClassByPackageName
(
String
packageName
)
{
// 获取当前包下以及子包下所以的类
List
<
Class
<?>>
returnClassList
=
getClasses
(
packageName
);
return
returnClassList
;
}
/**
* 从包package中获取所有的Class
*
* @param packageName
* @return
*/
private
static
List
<
Class
<?>>
getClasses
(
String
packageName
)
{
// 第一个class类的集合
List
<
Class
<?>>
classes
=
new
ArrayList
<
Class
<?>>();
// 是否循环迭代
boolean
recursive
=
true
;
// 获取包的名字 并进行替换
String
packageDirName
=
packageName
.
replace
(
'.'
,
'/'
);
// 定义一个枚举的集合 并进行循环来处理这个目录下的things
Enumeration
<
URL
>
dirs
;
try
{
dirs
=
Thread
.
currentThread
().
getContextClassLoader
().
getResources
(
packageDirName
);
// 循环迭代下去
while
(
dirs
.
hasMoreElements
())
{
// 获取下一个元素
URL
url
=
dirs
.
nextElement
();
// 得到协议的名称
String
protocol
=
url
.
getProtocol
();
//System.out.println(url.getFile());
// 如果是以文件的形式保存在服务器上
if
(
"file"
.
equals
(
protocol
))
{
// 获取包的物理路径
String
filePath
=
URLDecoder
.
decode
(
url
.
getFile
(),
"UTF-8"
);
// 以文件的方式扫描整个包下的文件 并添加到集合中
findAndAddClassesInPackageByFile
(
packageName
,
filePath
,
recursive
,
classes
);
}
else
if
(
"jar"
.
equals
(
protocol
))
{
// 如果是jar包文件
// 定义一个JarFile
JarFile
jar
;
try
{
// 获取jar
jar
=
((
JarURLConnection
)
url
.
openConnection
()).
getJarFile
();
// 从此jar包 得到一个枚举类
Enumeration
<
JarEntry
>
entries
=
jar
.
entries
();
// 同样的进行循环迭代
while
(
entries
.
hasMoreElements
())
{
// 获取jar里的一个实体 可以是目录 和一些jar包里的其他文件 如META-INF等文件
JarEntry
entry
=
entries
.
nextElement
();
String
name
=
entry
.
getName
();
// 如果是以/开头的
if
(
name
.
charAt
(
0
)
==
'/'
)
{
// 获取后面的字符串
name
=
name
.
substring
(
1
);
}
// 如果前半部分和定义的包名相同
if
(
name
.
startsWith
(
packageDirName
))
{
int
idx
=
name
.
lastIndexOf
(
'/'
);
// 如果以"/"结尾 是一个包
if
(
idx
!=
-
1
)
{
// 获取包名 把"/"替换成"."
packageName
=
name
.
substring
(
0
,
idx
).
replace
(
'/'
,
'.'
);
}
// 如果可以迭代下去 并且是一个包
if
((
idx
!=
-
1
)
||
recursive
)
{
// 如果是一个.class文件 而且不是目录
if
(
name
.
endsWith
(
".class"
)
&&
!
entry
.
isDirectory
())
{
// 去掉后面的".class" 获取真正的类名
String
className
=
name
.
substring
(
packageName
.
length
()
+
1
,
name
.
length
()
-
6
);
try
{
// 添加到classes
classes
.
add
(
Class
.
forName
(
packageName
+
'.'
+
className
));
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
classes
;
}
/**
* 以文件的形式来获取包下的所有Class
*
* @param packageName
* @param packagePath
* @param recursive
* @param classes
*/
private
static
void
findAndAddClassesInPackageByFile
(
String
packageName
,
String
packagePath
,
final
boolean
recursive
,
List
<
Class
<?>>
classes
)
{
// 获取此包的目录 建立一个File
File
dir
=
new
File
(
packagePath
);
// 如果不存在或者 也不是目录就直接返回
if
(!
dir
.
exists
()
||
!
dir
.
isDirectory
())
{
return
;
}
// 如果存在 就获取包下的所有文件 包括目录
File
[]
dirFiles
=
dir
.
listFiles
(
new
FileFilter
()
{
// 自定义过滤规则 如果可以循环(包含子目录) 或则是以.class结尾的文件(编译好的java类文件)
public
boolean
accept
(
File
file
)
{
return
(
recursive
&&
file
.
isDirectory
())
||
(
file
.
getName
().
endsWith
(
".class"
));
}
});
assert
dirFiles
!=
null
;
// 循环所有文件
for
(
File
file
:
dirFiles
)
{
// 如果是目录 则继续扫描
if
(
file
.
isDirectory
())
{
findAndAddClassesInPackageByFile
(
packageName
+
"."
+
file
.
getName
(),
file
.
getAbsolutePath
(),
recursive
,
classes
);
}
else
{
// 如果是java类文件 去掉后面的.class 只留下类名
String
className
=
file
.
getName
().
substring
(
0
,
file
.
getName
().
length
()
-
6
);
try
{
// 添加到集合中去
classes
.
add
(
Class
.
forName
(
packageName
+
'.'
+
className
));
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
portal-manager/src/main/java/com/mortals/xhx/module/area/web/AreaController.java
View file @
63a43d97
...
@@ -29,8 +29,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
...
@@ -29,8 +29,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
@Autowired
@Autowired
private
ParamService
paramService
;
private
ParamService
paramService
;
@Autowired
private
IAuthTokenService
authTokenService
;
public
AreaController
()
{
public
AreaController
()
{
super
.
setModuleDesc
(
"区域"
);
super
.
setModuleDesc
(
"区域"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment