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
7644cf03
Commit
7644cf03
authored
Nov 17, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加资源自动刷新获取
parent
63a43d97
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
478 additions
and
38 deletions
+478
-38
portal-manager/src/main/java/com/mortals/xhx/base/system/resource/service/ResourceService.java
...als/xhx/base/system/resource/service/ResourceService.java
+6
-0
portal-manager/src/main/java/com/mortals/xhx/base/system/resource/service/impl/ResourceServiceImpl.java
...ase/system/resource/service/impl/ResourceServiceImpl.java
+72
-5
portal-manager/src/main/java/com/mortals/xhx/base/system/resource/web/ResourceController.java
...tals/xhx/base/system/resource/web/ResourceController.java
+63
-33
portal-manager/src/main/java/com/mortals/xhx/common/utils/ControllerScanUtil.java
...java/com/mortals/xhx/common/utils/ControllerScanUtil.java
+337
-0
No files found.
portal-manager/src/main/java/com/mortals/xhx/base/system/resource/service/ResourceService.java
View file @
7644cf03
...
@@ -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
;
...
@@ -63,4 +65,8 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
...
@@ -63,4 +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
portal-manager/src/main/java/com/mortals/xhx/base/system/resource/service/impl/ResourceServiceImpl.java
View file @
7644cf03
...
@@ -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
;
...
@@ -19,6 +20,7 @@ import com.mortals.xhx.base.system.resource.model.ResourceEntity;
...
@@ -19,6 +20,7 @@ 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.common.key.RedisKey
;
import
com.mortals.xhx.common.key.RedisKey
;
import
com.mortals.xhx.common.utils.ControllerScanUtil
;
import
com.mortals.xhx.module.role.model.RoleAuthEntity
;
import
com.mortals.xhx.module.role.model.RoleAuthEntity
;
import
com.mortals.xhx.module.role.model.RoleAuthQuery
;
import
com.mortals.xhx.module.role.model.RoleAuthQuery
;
import
com.mortals.xhx.module.role.service.RoleAuthService
;
import
com.mortals.xhx.module.role.service.RoleAuthService
;
...
@@ -26,10 +28,8 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -26,10 +28,8 @@ 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
;
...
@@ -51,7 +51,6 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
...
@@ -51,7 +51,6 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
@Autowired
@Autowired
private
RoleAuthService
roleAuthService
;
private
RoleAuthService
roleAuthService
;
@Override
@Override
public
List
<
ResourceEntity
>
findAllEnable
()
throws
AppException
{
public
List
<
ResourceEntity
>
findAllEnable
()
throws
AppException
{
ResourceQuery
params
=
new
ResourceQuery
();
ResourceQuery
params
=
new
ResourceQuery
();
...
@@ -89,6 +88,74 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
...
@@ -89,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
{
...
...
portal-manager/src/main/java/com/mortals/xhx/base/system/resource/web/ResourceController.java
View file @
7644cf03
...
@@ -2,8 +2,11 @@ package com.mortals.xhx.base.system.resource.web;
...
@@ -2,8 +2,11 @@ package com.mortals.xhx.base.system.resource.web;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.annotation.UnAuth
;
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.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.model.ResourceEntity
;
...
@@ -13,6 +16,7 @@ import com.mortals.xhx.common.code.SourceType;
...
@@ -13,6 +16,7 @@ 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
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -27,37 +31,63 @@ import java.util.Map;
...
@@ -27,37 +31,63 @@ import java.util.Map;
@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
(){
public
ResourceController
()
{
super
.
setModuleDesc
(
"资源信息"
);
super
.
setModuleDesc
(
"资源信息"
);
}
}
@Override
@Override
protected
void
init
(
Map
<
String
,
Object
>
model
,
Context
context
)
{
protected
void
init
(
Map
<
String
,
Object
>
model
,
Context
context
)
{
Map
<
String
,
Object
>
statsus
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
statsus
=
new
HashMap
<
String
,
Object
>();
statsus
.
put
(
"authType"
,
AuthType
.
getEnumMap
());
statsus
.
put
(
"authType"
,
AuthType
.
getEnumMap
());
statsus
.
put
(
"sourceType"
,
SourceType
.
getEnumMap
());
statsus
.
put
(
"sourceType"
,
SourceType
.
getEnumMap
());
if
(
getCurUser
().
isAdmin
())
{
if
(
getCurUser
().
isAdmin
())
{
statsus
.
put
(
"userType"
,
IBaseEnum
.
getEnumMap
(
UserType
.
class
));
statsus
.
put
(
"userType"
,
IBaseEnum
.
getEnumMap
(
UserType
.
class
));
}
else
{
}
else
{
statsus
.
put
(
"userType"
,
UserType
.
findByValue
(
getCurUser
().
getUserType
()));
statsus
.
put
(
"userType"
,
UserType
.
findByValue
(
getCurUser
().
getUserType
()));
}
}
model
.
put
(
KEY_RESULT_DICT
,
statsus
);
model
.
put
(
KEY_RESULT_DICT
,
statsus
);
}
}
/**
/**
* 获取所有资源
* 获取所有资源
*
*
* @return
* @return
*/
*/
@PostMapping
(
"allResources"
)
@PostMapping
(
"allResources"
)
public
String
allResources
(
int
userType
)
{
public
String
allResources
(
int
userType
)
{
JSONObject
ret
=
new
JSONObject
();
JSONObject
ret
=
new
JSONObject
();
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
ret
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
ret
.
put
(
KEY_RESULT_MSG
,
"所有的customer以及user"
);
ret
.
put
(
KEY_RESULT_MSG
,
"所有的customer以及user"
);
ret
.
put
(
KEY_RESULT_DATA
,
service
.
findAll
(
userType
));
ret
.
put
(
KEY_RESULT_DATA
,
service
.
findAll
(
userType
));
return
ret
.
toJSONString
();
return
ret
.
toJSONString
();
}
}
@Override
protected
void
doListBefore
(
ResourceEntity
query
,
Map
<
String
,
Object
>
model
,
Context
context
)
throws
AppException
{
super
.
doListBefore
(
query
,
model
,
context
);
}
/**
* 资源路径刷新
*/
@PostMapping
(
value
=
"refreshUrl"
)
@UnAuth
public
Rest
<
String
>
refreshUrl
(
@RequestParam
(
name
=
"packageName"
,
defaultValue
=
"com.mortals.xhx"
)
String
packageName
)
{
log
.
info
(
"刷新资源路径,packageName"
,
packageName
);
String
busiDesc
=
this
.
getModuleDesc
()
+
"资源路径刷新"
;
Rest
<
String
>
rest
=
Rest
.
ok
(
busiDesc
+
" 【成功】"
);
try
{
this
.
service
.
refreshResourceUrl
(
packageName
,
getContext
());
recordSysLog
(
request
,
busiDesc
+
" 【成功】"
);
}
catch
(
Exception
e
)
{
log
.
error
(
busiDesc
,
e
);
rest
=
Rest
.
fail
(
super
.
convertException
(
e
));
}
return
rest
;
}
}
}
\ No newline at end of file
portal-manager/src/main/java/com/mortals/xhx/common/utils/ControllerScanUtil.java
0 → 100644
View file @
7644cf03
This diff is collapsed.
Click to expand it.
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