Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jyzb_platformV2
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
赵剑炜
jyzb_platformV2
Commits
3c57d097
Commit
3c57d097
authored
Feb 23, 2024
by
赵剑炜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
批量新增账号
parent
950837f9
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
115 行增加
和
13 行删除
+115
-13
PoliceController.java
jyzb-biz/src/main/java/com/junmp/jyzb/controller/PoliceController.java
+6
-1
PolicemanService.java
jyzb-biz/src/main/java/com/junmp/jyzb/service/PolicemanService.java
+1
-0
PolicemanServiceImpl.java
jyzb-biz/src/main/java/com/junmp/jyzb/service/impl/PolicemanServiceImpl.java
+106
-9
PolicemanMapper.xml
jyzb-biz/src/main/resources/mapper/PolicemanMapper.xml
+2
-3
没有找到文件。
jyzb-biz/src/main/java/com/junmp/jyzb/controller/PoliceController.java
View file @
3c57d097
...
@@ -318,9 +318,14 @@ public class PoliceController {
...
@@ -318,9 +318,14 @@ public class PoliceController {
// return ApiRes.success(policemanService.oneClickAccountCreation(pubOrg));
// return ApiRes.success(policemanService.oneClickAccountCreation(pubOrg));
// }
// }
@PostMapping
(
path
=
"/oneClickAccountCreation"
,
name
=
"一键生成账号(运维,管理,审核)#logType=30"
)
@PostMapping
(
path
=
"/oneClickAccountCreation"
,
name
=
"一键生成账号(运维,管理,审核)#logType=30"
)
@ApiOperation
(
"一键生成账号"
)
public
ApiRes
<
Boolean
>
oneClickAccountCreation
(
@RequestBody
PubOrg
pubOrg
)
throws
IOException
{
public
ApiRes
<
Boolean
>
oneClickAccountCreation
(
@RequestBody
PubOrg
pubOrg
)
throws
IOException
{
return
ApiRes
.
success
(
policemanService
.
oneClickAccountCreation1
(
pubOrg
));
return
ApiRes
.
success
(
policemanService
.
oneClickAccountCreation1
(
pubOrg
));
}
}
@PostMapping
(
path
=
"/CreateAccount"
,
name
=
"一键生成全部账号(运维,管理,审核)#logType=30"
)
@ApiOperation
(
"一键生成全部账号"
)
public
ApiRes
<
Boolean
>
CreateAccount
(
)
throws
InterruptedException
,
IOException
{
return
ApiRes
.
success
(
policemanService
.
CreateSystemAccount
());
}
}
}
jyzb-biz/src/main/java/com/junmp/jyzb/service/PolicemanService.java
View file @
3c57d097
...
@@ -127,6 +127,7 @@ public interface PolicemanService extends IService<Policeman> {
...
@@ -127,6 +127,7 @@ public interface PolicemanService extends IService<Policeman> {
// boolean oneClickAccountCreation(PubOrg pubOrg) throws IOException;
// boolean oneClickAccountCreation(PubOrg pubOrg) throws IOException;
boolean
oneClickAccountCreation1
(
PubOrg
pubOrg
)
throws
IOException
;
boolean
oneClickAccountCreation1
(
PubOrg
pubOrg
)
throws
IOException
;
boolean
CreateSystemAccount
()
throws
InterruptedException
,
IOException
;
//获取组织机构下所有的审核员的userId,用字符串拼接
//获取组织机构下所有的审核员的userId,用字符串拼接
String
searchUserByRoleId
(
Long
orgId
);
String
searchUserByRoleId
(
Long
orgId
);
}
}
jyzb-biz/src/main/java/com/junmp/jyzb/service/impl/PolicemanServiceImpl.java
View file @
3c57d097
...
@@ -71,6 +71,7 @@ import org.elasticsearch.index.query.QueryBuilders;
...
@@ -71,6 +71,7 @@ import org.elasticsearch.index.query.QueryBuilders;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
...
@@ -83,6 +84,9 @@ import java.text.SimpleDateFormat;
...
@@ -83,6 +84,9 @@ import java.text.SimpleDateFormat;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.*
;
import
java.util.concurrent.*
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -2318,6 +2322,7 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
...
@@ -2318,6 +2322,7 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
}
}
sysUser
.
setAccount
(
i
+
pubOrg
.
getOrgCode
());
sysUser
.
setAccount
(
i
+
pubOrg
.
getOrgCode
());
sysUser
.
setPassword
(
"123456"
);
SysUserCreateFactory
.
fillAddSysUser
(
sysUser
);
SysUserCreateFactory
.
fillAddSysUser
(
sysUser
);
sysUser
.
setAvatar
(
FileConstant
.
DEFAULT_AVATAR_FILE_ID
);
sysUser
.
setAvatar
(
FileConstant
.
DEFAULT_AVATAR_FILE_ID
);
sysUser
.
setDelFlag
(
LogicDelEnum
.
N
.
getCode
());
sysUser
.
setDelFlag
(
LogicDelEnum
.
N
.
getCode
());
...
@@ -2326,7 +2331,29 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
...
@@ -2326,7 +2331,29 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
sysUserService
.
save
(
sysUser
);
sysUserService
.
save
(
sysUser
);
return
sysUser
.
getUserId
();
return
sysUser
.
getUserId
();
}
}
private
SysUser
addUserAndReturn
(
SysUser
sysUser
,
String
i
,
PubOrg
pubOrg
){
if
(
i
.
equals
(
"yw"
))
{
sysUser
.
setNickName
(
pubOrg
.
getDName
()+
"运维人员"
);
sysUser
.
setRealName
(
pubOrg
.
getDName
()+
"运维人员"
);
}
if
(
i
.
equals
(
"sh"
))
{
sysUser
.
setNickName
(
pubOrg
.
getDName
()+
"审核员"
);
sysUser
.
setRealName
(
pubOrg
.
getDName
()+
"审核员"
);
}
if
(
i
.
equals
(
"gl"
))
{
sysUser
.
setNickName
(
pubOrg
.
getDName
()+
"仓管员"
);
sysUser
.
setRealName
(
pubOrg
.
getDName
()+
"仓管员"
);
}
sysUser
.
setAccount
(
i
+
pubOrg
.
getOrgCode
());
SysUserCreateFactory
.
fillAddSysUser
(
sysUser
);
sysUser
.
setAvatar
(
FileConstant
.
DEFAULT_AVATAR_FILE_ID
);
sysUser
.
setDelFlag
(
LogicDelEnum
.
N
.
getCode
());
sysUser
.
setCreateTime
(
DateTime
.
now
());
sysUser
.
setUpdateTime
(
DateTime
.
now
());
return
sysUser
;
}
public
List
<
PubOrg
>
searchAll
(
Integer
pageNum
,
Integer
pageSize
)
throws
IOException
{
public
List
<
PubOrg
>
searchAll
(
Integer
pageNum
,
Integer
pageSize
)
throws
IOException
{
...
@@ -2364,12 +2391,48 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
...
@@ -2364,12 +2391,48 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
return
pubOrg
;
return
pubOrg
;
}
}
public
boolean
CreateSystemAccount
(
)
throws
InterruptedException
,
IOException
{
// List<PubOrg> orgList = searchAll(0, 3000);
LambdaQueryWrapper
<
PubOrg
>
wp
=
new
LambdaQueryWrapper
<>();
wp
.
eq
(
PubOrg:
:
getDelFlag
,
1
);
List
<
PubOrg
>
listOrg
=
pubOrgService
.
list
(
wp
);
// 创建线程池
int
numThreads
=
Runtime
.
getRuntime
().
availableProcessors
();
// 获取可用处理器数量
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
numThreads
);
// 提交任务给线程池执行
for
(
PubOrg
one
:
listOrg
)
{
executor
.
submit
(()
->
{
try
{
oneClickAccountCreation1
(
one
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
});
}
// 关闭线程池
executor
.
shutdown
();
// 等待所有任务完成
while
(!
executor
.
isTerminated
())
{
// Thread.sleep(1000); // 可以根据需要调整等待时间
}
return
true
;
}
private
final
Lock
lock
=
new
ReentrantLock
();
// @Async
// @Override
// @Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
boolean
oneClickAccountCreation1
(
PubOrg
pubOrg
)
throws
IOException
{
public
boolean
oneClickAccountCreation1
(
PubOrg
pubOrg
)
throws
IOException
{
//一次性创建一个组织机构下的三种系统账号(运维,仓管员,审核员)
//一次性创建一个组织机构下的三种系统账号(运维,仓管员,审核员)
//先判断一下前端是否传递组织机构编号(如果传递,指定创建该组织机构下的三种账号)
//先判断一下前端是否传递组织机构编号(如果传递,指定创建该组织机构下的三种账号)
lock
.
lock
();
// 获取锁
try
{
List
<
String
>
userAccountList
=
new
ArrayList
<>();
List
<
String
>
userAccountList
=
new
ArrayList
<>();
userAccountList
.
add
(
"yw"
);
userAccountList
.
add
(
"yw"
);
userAccountList
.
add
(
"sh"
);
userAccountList
.
add
(
"sh"
);
...
@@ -2403,14 +2466,14 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
...
@@ -2403,14 +2466,14 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
}
else
{
}
else
{
//如果有组织机构编号,则判断该组织机构下面是否已经存在账号,如果存在,则不进行创建,否则进行创建
//如果有组织机构编号,则判断该组织机构下面是否已经存在账号,如果存在,则不进行创建,否则进行创建
PubOrg
one
=
pubOrgService
.
getOne
(
new
LambdaQueryWrapper
<
PubOrg
>()
PubOrg
one
=
pubOrgService
.
list
(
new
LambdaQueryWrapper
<
PubOrg
>()
.
eq
(
PubOrg:
:
getOrgCode
,
pubOrg
.
getOrgCode
()));
.
eq
(
PubOrg:
:
getOrgCode
,
pubOrg
.
getOrgCode
()))
.
get
(
0
)
;
if
(
ObjectUtil
.
isNull
(
one
)){
if
(
ObjectUtil
.
isNull
(
one
)){
throw
new
ServiceException
(
OrgExceptionEnum
.
ORG_NOT_EXIST
);
throw
new
ServiceException
(
OrgExceptionEnum
.
ORG_NOT_EXIST
);
}
}
List
<
UserDto
>
userDtos
=
policemanMapper
.
oneClickAccountCreation
(
one
.
getOrgId
(),
null
,
null
);
List
<
UserDto
>
userDtos
=
policemanMapper
.
oneClickAccountCreation
(
one
.
getOrgId
(),
null
,
null
);
if
(
CollectionUtil
.
isEmpty
(
userDtos
)
){
if
(
userDtos
.
size
()==
0
){
for
(
int
i
=
0
;
i
<
userAccountList
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
userAccountList
.
size
();
i
++)
{
sysUser
.
setUserId
(
null
);
sysUser
.
setUserId
(
null
);
//创建用户信息
//创建用户信息
...
@@ -2426,15 +2489,44 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
...
@@ -2426,15 +2489,44 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
sysUserRole
.
setUserId
(
userId
);
sysUserRole
.
setUserId
(
userId
);
sysUserRole
.
setCreateTime
(
DateTimeUtil
.
getCurrentDateTime
());
sysUserRole
.
setCreateTime
(
DateTimeUtil
.
getCurrentDateTime
());
sysUserRoleList
.
add
(
sysUserRole
);
sysUserRoleList
.
add
(
sysUserRole
);
// sysUser.setUserId(null);
// //创建用户信息
// SysUser Adduser = addUserAndReturn(sysUser, userAccountList.get(i), one);
// sysUserService.save(Adduser);
// //创建角色表数据
// SysUserRole sysUserRole = new SysUserRole();
// sysUserRole.setRoleId(userRoleList.get(i));
// sysUserRole.setUserId(Adduser.getUserId());
// sysUserRole.setCreateTime(DateTimeUtil.getCurrentDateTime());
// sysUserRoleService.save(sysUserRole);
// //创建关联表数据
// SysUserOrg sysUserOrg = new SysUserOrg();
// sysUserOrg.setOrgId(one.getOrgId());
// sysUserOrg.setUserId(Adduser.getUserId());
// sysUserOrg.setCreateTime(DateTimeUtil.getCurrentDateTime());
// sysUserOrgService.save(sysUserOrg);
}
}
}
else
{
}
else
{
Map
<
String
,
List
<?>>
map
=
addRoleAndOrg
(
userDtos
,
one
,
ywExists
,
shExists
,
glExists
,
sysUser
,
List
<
String
>
expectedPrefixes
=
Arrays
.
asList
(
"sh"
,
"gl"
,
"yw"
);
sysUserOrgList
,
userRoleList
,
userAccountList
,
sysUserRoleList
);
List
<
String
>
foundPrefixes
=
userDtos
.
stream
()
List
<
SysUserOrg
>
userlist
=(
List
<
SysUserOrg
>)
map
.
get
(
"sysUserOrgList"
);
.
map
(
UserDto:
:
getAccount
)
sysUserOrgList
.
addAll
(
userlist
);
.
map
(
account
->
account
.
substring
(
0
,
2
))
// 获取账户名的前两个字符
List
<
SysUserRole
>
roleList
=(
List
<
SysUserRole
>)
map
.
get
(
"sysUserRoleList"
);
.
filter
(
expectedPrefixes:
:
contains
)
// 过滤出符合期望前缀的账户名
sysUserRoleList
.
addAll
(
roleList
);
.
distinct
()
// 去重
.
collect
(
Collectors
.
toList
());
// 找出缺少的前缀
List
<
String
>
missingPrefixes
=
new
ArrayList
<>(
expectedPrefixes
);
missingPrefixes
.
removeAll
(
foundPrefixes
);
// 输出缺少的前缀
if
(!
missingPrefixes
.
isEmpty
())
{
System
.
out
.
println
(
"缺少以下前缀的用户: "
+
missingPrefixes
);
}
}
}
...
@@ -2444,6 +2536,11 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
...
@@ -2444,6 +2536,11 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
}
}
}
finally
{
lock
.
unlock
();
// 释放锁
}
return
true
;
return
true
;
}
}
...
...
jyzb-biz/src/main/resources/mapper/PolicemanMapper.xml
View file @
3c57d097
...
@@ -380,9 +380,8 @@ WHERE o.org_id IN
...
@@ -380,9 +380,8 @@ WHERE o.org_id IN
</if>
</if>
) as t
) as t
join sys_user_org uo on t.user_id=uo.user_id
join sys_user_org uo on t.user_id=uo.user_id
<if
test=
"orgId != null and orgId != ''"
>
and uo.org_id=#{orgId}
and uo.org_id=#{orgId}
</if>
join sys_user_role ur on t.user_id=ur.user_id
join sys_user_role ur on t.user_id=ur.user_id
join sys_role r on ur.role_id=r.role_id
join sys_role r on ur.role_id=r.role_id
<if
test=
"roleId==null"
>
<if
test=
"roleId==null"
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论