Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
attendance-performance-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
赵啸非
attendance-performance-platform
Commits
8de65dc3
Commit
8de65dc3
authored
Apr 28, 2024
by
廖旭伟
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
79f2e625
5a5d8d40
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
492 additions
and
4 deletions
+492
-4
attendance-performance-manager/src/main/java/com/mortals/xhx/base/system/resource/service/ResourceService.java
...als/xhx/base/system/resource/service/ResourceService.java
+6
-0
attendance-performance-manager/src/main/java/com/mortals/xhx/base/system/resource/service/impl/ResourceServiceImpl.java
...ase/system/resource/service/impl/ResourceServiceImpl.java
+126
-4
attendance-performance-manager/src/main/java/com/mortals/xhx/base/system/resource/web/ResourceController.java
...tals/xhx/base/system/resource/web/ResourceController.java
+22
-0
attendance-performance-manager/src/main/java/com/mortals/xhx/common/utils/ControllerScanUtil.java
...java/com/mortals/xhx/common/utils/ControllerScanUtil.java
+338
-0
No files found.
attendance-performance-manager/src/main/java/com/mortals/xhx/base/system/resource/service/ResourceService.java
View file @
8de65dc3
...
...
@@ -9,7 +9,9 @@
package
com.mortals.xhx.base.system.resource.service
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.service.ICRUDService
;
import
com.mortals.xhx.base.system.resource.model.ResourceEntity
;
...
...
@@ -63,4 +65,8 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
* @param userType
*/
List
<
ResourceEntity
>
findAll
(
int
userType
);
Rest
<
String
>
refreshResourceUrl
(
String
packageName
,
Context
context
);
}
\ No newline at end of file
attendance-performance-manager/src/main/java/com/mortals/xhx/base/system/resource/service/impl/ResourceServiceImpl.java
View file @
8de65dc3
...
...
@@ -8,18 +8,30 @@
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.model.Context
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.framework.util.DataUtil
;
import
com.mortals.framework.util.StringUtils
;
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.ResourceQuery
;
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.RoleAuthQuery
;
import
com.mortals.xhx.base.system.role.service.RoleAuthService
;
import
com.mortals.xhx.common.key.RedisKey
;
import
com.mortals.xhx.common.utils.ControllerScanUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
static
com
.
mortals
.
xhx
.
common
.
utils
.
MenuEncodeUtil
.
generateMenuUrlCode
;
/**
* <p>Title: 资源信息</p>
...
...
@@ -32,6 +44,13 @@ import java.util.Set;
@Service
(
"resourceService"
)
public
class
ResourceServiceImpl
extends
AbstractCRUDServiceImpl
<
ResourceDao
,
ResourceEntity
,
Long
>
implements
ResourceService
{
@Autowired
private
ICacheService
cacheService
;
@Autowired
private
RoleAuthService
roleAuthService
;
@Override
public
List
<
ResourceEntity
>
findAllEnable
()
throws
AppException
{
ResourceQuery
params
=
new
ResourceQuery
();
...
...
@@ -68,5 +87,108 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,Res
public
List
<
ResourceEntity
>
findAll
(
int
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
);
});
tempResource
.
setUrl
(
setUrl
.
stream
().
collect
(
Collectors
.
joining
(
","
)));
this
.
update
(
tempResource
,
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
);
});
tempResource
.
setUrl
(
setUrl
.
stream
().
collect
(
Collectors
.
joining
(
","
)));
this
.
update
(
tempResource
,
context
);
}
}
}
}
@Override
protected
void
updateAfter
(
ResourceEntity
entity
,
Context
context
)
throws
AppException
{
updateUserMenuUrlCache
();
}
@Override
protected
void
saveAfter
(
ResourceEntity
entity
,
Context
context
)
throws
AppException
{
updateUserMenuUrlCache
();
}
@Override
protected
void
removeAfter
(
Long
[]
ids
,
Context
context
,
int
result
)
throws
AppException
{
//删除关联表中数据
if
(!
ObjectUtils
.
isEmpty
(
ids
))
{
RoleAuthQuery
query
=
new
RoleAuthQuery
();
query
.
setResourceIdList
(
Arrays
.
asList
(
ids
));
List
<
RoleAuthEntity
>
roleAuthEntities
=
roleAuthService
.
find
(
query
);
if
(!
ObjectUtils
.
isEmpty
(
roleAuthEntities
))
{
roleAuthService
.
remove
(
roleAuthEntities
.
stream
().
map
(
m
->
m
.
getId
()).
toArray
(
Long
[]::
new
),
context
);
updateUserMenuUrlCache
();
}
}
}
private
void
updateUserMenuUrlCache
()
{
//更新用户菜单
Set
<
String
>
hkeys
=
cacheService
.
hkeys
(
RedisKey
.
KEY_USER_MENU_CACHE
);
for
(
String
userId
:
hkeys
)
{
Set
<
String
>
urls
=
this
.
findUrlSetByUserId
(
DataUtil
.
converStr2Long
(
userId
,
0L
));
String
menuUrlCode
=
generateMenuUrlCode
(
urls
);
cacheService
.
hset
(
RedisKey
.
KEY_USER_MENU_CACHE
,
userId
,
menuUrlCode
);
}
}
}
\ No newline at end of file
attendance-performance-manager/src/main/java/com/mortals/xhx/base/system/resource/web/ResourceController.java
View file @
8de65dc3
...
...
@@ -2,7 +2,9 @@ package com.mortals.xhx.base.system.resource.web;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.annotation.UnAuth
;
import
com.mortals.framework.common.IBaseEnum
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.common.code.UserType
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
...
...
@@ -13,6 +15,7 @@ import com.mortals.xhx.common.code.SourceType;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
...
...
@@ -59,5 +62,24 @@ public class ResourceController extends BaseCRUDJsonBodyMappingController<Resour
ret
.
put
(
KEY_RESULT_DATA
,
service
.
findAll
(
userType
));
return
ret
.
toJSONString
();
}
/**
* 资源路径刷新
*/
@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
attendance-performance-manager/src/main/java/com/mortals/xhx/common/utils/ControllerScanUtil.java
0 → 100644
View file @
8de65dc3
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