commit
This commit is contained in:
@@ -42,7 +42,32 @@ public class SysDataUserPullController {
|
|||||||
@ApiOperation("分页数据")
|
@ApiOperation("分页数据")
|
||||||
@Ok("json:{locked:'password|idCard'}")
|
@Ok("json:{locked:'password|idCard'}")
|
||||||
public Result pageData(@Valid SysDataUserPullPageForm pageForm) {
|
public Result pageData(@Valid SysDataUserPullPageForm pageForm) {
|
||||||
Sql sql = Sqls.create("select us.*,su.`name` AS unit_name from sys_user_source us left join sys_unit su ON su.id = us.unitId $condition");
|
Sql sql = Sqls.create("""
|
||||||
|
SELECT
|
||||||
|
us.id,
|
||||||
|
us.loginname,
|
||||||
|
us.username,
|
||||||
|
us.sex,
|
||||||
|
us.mobile,
|
||||||
|
us.birthday,
|
||||||
|
us.userState,
|
||||||
|
us.arrivalAtSchoolDate,
|
||||||
|
us.preparedBy,
|
||||||
|
us.personType,
|
||||||
|
us.technicalTitle,
|
||||||
|
us.position,
|
||||||
|
us.education,
|
||||||
|
us.academicDegree,
|
||||||
|
COALESCE(su.`name`, us.unitName) AS unitName,
|
||||||
|
us.unitId,
|
||||||
|
us.political,
|
||||||
|
us.nation,
|
||||||
|
us.pullTime
|
||||||
|
FROM
|
||||||
|
sys_user_source us
|
||||||
|
LEFT JOIN sys_unit su ON su.id = us.unitId
|
||||||
|
$condition
|
||||||
|
""");
|
||||||
Cnd cnd = Cnd.NEW();
|
Cnd cnd = Cnd.NEW();
|
||||||
cnd.andEX(Sys_user_source::getPullTime, "=", pageForm.getPullTime());
|
cnd.andEX(Sys_user_source::getPullTime, "=", pageForm.getPullTime());
|
||||||
cnd.and(Cnd.likeEX(Sys_user_source::getUsername, pageForm.getUserName()));
|
cnd.and(Cnd.likeEX(Sys_user_source::getUsername, pageForm.getUserName()));
|
||||||
|
|||||||
+66
-21
@@ -5,6 +5,7 @@ import cn.hutool.core.collection.ListUtil;
|
|||||||
import cn.hutool.core.date.DateField;
|
import cn.hutool.core.date.DateField;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.http.HtmlUtil;
|
import cn.hutool.http.HtmlUtil;
|
||||||
import com.budwk.app.base.constant.RoleConstant;
|
import com.budwk.app.base.constant.RoleConstant;
|
||||||
import com.budwk.app.base.event.role.RoleEventMsg;
|
import com.budwk.app.base.event.role.RoleEventMsg;
|
||||||
@@ -65,6 +66,11 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
|||||||
|
|
||||||
private static Map<String, String> unitIdNameMap;
|
private static Map<String, String> unitIdNameMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人员数据时仅按在职状态增加会员,不因状态不匹配取消已有会员。
|
||||||
|
*/
|
||||||
|
private static final Set<String> MEMBER_USER_STATES = Set.of("在岗", "切线", "免职", "驻村", "援疆(藏)");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段映射类,用于缓存反射结果
|
* 字段映射类,用于缓存反射结果
|
||||||
*/
|
*/
|
||||||
@@ -139,6 +145,49 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
|||||||
return memberPreparedByTypes.contains(preparedBy);
|
return memberPreparedByTypes.contains(preparedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断本次人员状态是否需要增加会员身份。
|
||||||
|
*/
|
||||||
|
private boolean shouldAddMember(String userState) {
|
||||||
|
return StrUtil.isNotBlank(userState) && MEMBER_USER_STATES.contains(userState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量补充会员角色,已存在会员角色的用户不重复插入。
|
||||||
|
*/
|
||||||
|
private void addMemberRolesIfAbsent(List<String> userIds, Sys_role memberRole) {
|
||||||
|
if (Lang.isEmpty(userIds) || memberRole == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> distinctUserIds = userIds.stream().filter(Objects::nonNull).distinct().toList();
|
||||||
|
if (distinctUserIds.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Sys_user_role> existingRoles = dao.query(Sys_user_role.class,
|
||||||
|
Cnd.where("roleId", "=", memberRole.getId()).and("userId", "in", distinctUserIds));
|
||||||
|
Set<String> existingUserIds = existingRoles.stream().map(Sys_user_role::getUserId).collect(Collectors.toSet());
|
||||||
|
List<Sys_user_role> roleList = distinctUserIds.stream()
|
||||||
|
.filter(id -> !existingUserIds.contains(id))
|
||||||
|
.map(id -> {
|
||||||
|
Sys_user_role userRole = new Sys_user_role();
|
||||||
|
userRole.setRoleId(memberRole.getId());
|
||||||
|
userRole.setUserId(id);
|
||||||
|
return userRole;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (roleList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<List<Sys_user_role>> batches = ListUtil.split(roleList, 500);
|
||||||
|
batches.forEach(batch -> {
|
||||||
|
try {
|
||||||
|
dao.fastInsert(batch);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("批量添加会员角色异常", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全量更新用户数据
|
* 全量更新用户数据
|
||||||
*
|
*
|
||||||
@@ -189,19 +238,31 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
|||||||
// 创建用户对象
|
// 创建用户对象
|
||||||
Sys_user u = new Sys_user();
|
Sys_user u = new Sys_user();
|
||||||
BeanUtils.copyProperties(source, u);
|
BeanUtils.copyProperties(source, u);
|
||||||
|
boolean addMember = shouldAddMember(source.getUserState());
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
// 新增用户,初始化数据
|
// 新增用户,初始化数据
|
||||||
|
if (u.getId() == null) {
|
||||||
|
u.setId(R.UU32());
|
||||||
|
}
|
||||||
String salt = R.UU32();
|
String salt = R.UU32();
|
||||||
u.setSalt(salt);
|
u.setSalt(salt);
|
||||||
u.setPassword(PwdUtil.getPassword(PwdUtil.generate(12), salt));
|
u.setPassword(PwdUtil.getPassword(PwdUtil.generate(12), salt));
|
||||||
u.setMember(false);
|
// 更新人员数据只增加会员,不因状态不匹配取消已有会员。
|
||||||
|
if (addMember) {
|
||||||
|
u.setMember(true);
|
||||||
|
addMemberUserIds.add(u.getId());
|
||||||
|
}
|
||||||
needInitUserList.add(u);
|
needInitUserList.add(u);
|
||||||
} else {
|
} else {
|
||||||
// 修改现有用户 - 根据工号判断是原有的人
|
// 修改现有用户 - 根据工号判断是原有的人
|
||||||
u.setId(user.getId());
|
u.setId(user.getId());
|
||||||
// 保持原有会员身份不变
|
// 保持原有会员身份不变
|
||||||
u.setMember(user.getMember());
|
// 更新人员数据只增加会员,不因状态不匹配取消已有会员。
|
||||||
|
if (addMember) {
|
||||||
|
u.setMember(true);
|
||||||
|
addMemberUserIds.add(user.getId());
|
||||||
|
}
|
||||||
|
|
||||||
needDoUpdateList.add(u);
|
needDoUpdateList.add(u);
|
||||||
}
|
}
|
||||||
@@ -313,35 +374,19 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* // 4. 异步添加会员角色 - 不等待完成
|
// 4. 异步添加会员角色 - 不等待完成
|
||||||
if (Lang.isNotEmpty(addMemberUserIds)) {
|
if (Lang.isNotEmpty(addMemberUserIds)) {
|
||||||
executorService.execute(() -> {
|
executorService.execute(() -> {
|
||||||
try {
|
try {
|
||||||
log.info("添加会员角色: {} 个", addMemberUserIds.size());
|
log.info("添加会员角色: {} 个", addMemberUserIds.size());
|
||||||
List<Sys_user_role> roleList = addMemberUserIds.stream().map(id -> {
|
addMemberRolesIfAbsent(addMemberUserIds, memberRole);
|
||||||
Sys_user_role userRole = new Sys_user_role();
|
|
||||||
userRole.setRoleId(memberRole.getId());
|
|
||||||
userRole.setUserId(id);
|
|
||||||
return userRole;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (!roleList.isEmpty()) {
|
|
||||||
// 分批处理角色分配
|
|
||||||
List<List<Sys_user_role>> batches = ListUtil.split(roleList, 500);
|
|
||||||
batches.forEach(batch -> {
|
|
||||||
try {
|
|
||||||
dao.fastInsert(batch);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("批量添加会员角色异常", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("添加会员角色异常", e);
|
log.error("添加会员角色异常", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// 5. 异步移除会员角色 - 不等待完成
|
// 5. 异步移除会员角色 - 不等待完成
|
||||||
if (Lang.isNotEmpty(removeMemberUserIds)) {
|
if (Lang.isNotEmpty(removeMemberUserIds)) {
|
||||||
executorService.execute(() -> {
|
executorService.execute(() -> {
|
||||||
|
|||||||
+60
-1
@@ -27,7 +27,10 @@ import java.util.List;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增量更新系统用户数据
|
* 增量更新系统用户数据
|
||||||
@@ -40,6 +43,47 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
|||||||
@Inject
|
@Inject
|
||||||
private SysRoleService sysRoleService;
|
private SysRoleService sysRoleService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人员数据时仅按在职状态增加会员,不因状态不匹配取消已有会员。
|
||||||
|
*/
|
||||||
|
private static final Set<String> MEMBER_USER_STATES = Set.of("在岗", "切线", "免职", "驻村", "援疆(藏)");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断本次人员状态是否需要增加会员身份。
|
||||||
|
*/
|
||||||
|
private boolean shouldAddMember(String userState) {
|
||||||
|
return StrUtil.isNotBlank(userState) && MEMBER_USER_STATES.contains(userState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量补充会员角色,已存在会员角色的用户不重复插入。
|
||||||
|
*/
|
||||||
|
private void addMemberRolesIfAbsent(List<String> userIds, Sys_role memberRole) {
|
||||||
|
if (userIds == null || userIds.isEmpty() || memberRole == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> distinctUserIds = userIds.stream().filter(Objects::nonNull).distinct().toList();
|
||||||
|
if (distinctUserIds.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Sys_user_role> existingRoles = dao.query(Sys_user_role.class,
|
||||||
|
Cnd.where("roleId", "=", memberRole.getId()).and("userId", "in", distinctUserIds));
|
||||||
|
Set<String> existingUserIds = existingRoles.stream().map(Sys_user_role::getUserId).collect(Collectors.toSet());
|
||||||
|
List<Sys_user_role> roleList = distinctUserIds.stream()
|
||||||
|
.filter(id -> !existingUserIds.contains(id))
|
||||||
|
.map(id -> {
|
||||||
|
Sys_user_role userRole = new Sys_user_role();
|
||||||
|
userRole.setRoleId(memberRole.getId());
|
||||||
|
userRole.setUserId(id);
|
||||||
|
return userRole;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (!roleList.isEmpty()) {
|
||||||
|
List<List<Sys_user_role>> batches = ListUtil.split(roleList, 500);
|
||||||
|
batches.forEach(dao::fastInsert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String update(SysDataUserUpdateParam updateParam) {
|
public String update(SysDataUserUpdateParam updateParam) {
|
||||||
// 基本SQL查询
|
// 基本SQL查询
|
||||||
@@ -58,6 +102,7 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
|||||||
|
|
||||||
//加入到系统用户表
|
//加入到系统用户表
|
||||||
List<Sys_user> sysUsers = BeanUtil.copyToList(userSources, Sys_user.class);
|
List<Sys_user> sysUsers = BeanUtil.copyToList(userSources, Sys_user.class);
|
||||||
|
List<String> addMemberUserIds = new java.util.ArrayList<>();
|
||||||
for (Sys_user sysUser : sysUsers) {
|
for (Sys_user sysUser : sysUsers) {
|
||||||
//重新设置
|
//重新设置
|
||||||
sysUser.setId(R.UU32());
|
sysUser.setId(R.UU32());
|
||||||
@@ -68,6 +113,13 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
|||||||
sysUser.setPassword(PwdUtil.getPassword(pwd, salt));
|
sysUser.setPassword(PwdUtil.getPassword(pwd, salt));
|
||||||
sysUser.setLoginCount(0);
|
sysUser.setLoginCount(0);
|
||||||
|
|
||||||
|
// 更新人员数据不处理会员字段,避免覆盖会员业务维护的状态。
|
||||||
|
// 只增加会员:符合指定在职状态时设置为会员,不符合时不设置为非会员。
|
||||||
|
if (shouldAddMember(sysUser.getUserState())) {
|
||||||
|
sysUser.setMember(true);
|
||||||
|
addMemberUserIds.add(sysUser.getId());
|
||||||
|
}
|
||||||
|
/*
|
||||||
// 检查是否符合会员条件
|
// 检查是否符合会员条件
|
||||||
// 1. 用户状态为"在岗"
|
// 1. 用户状态为"在岗"
|
||||||
if ("在岗".equals(sysUser.getUserState())) {
|
if ("在岗".equals(sysUser.getUserState())) {
|
||||||
@@ -95,6 +147,7 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
|||||||
} else {
|
} else {
|
||||||
sysUser.setMember(false);
|
sysUser.setMember(false);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
List<List<Sys_user>> splitSysUsers = ListUtil.split(sysUsers, 500);
|
List<List<Sys_user>> splitSysUsers = ListUtil.split(sysUsers, 500);
|
||||||
@@ -116,6 +169,11 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
|||||||
});
|
});
|
||||||
sysRoleService.clearCache();
|
sysRoleService.clearCache();
|
||||||
|
|
||||||
|
Sys_role memberRole = sysRoleService.getByCode(RoleConstant.MEMBER);
|
||||||
|
addMemberRolesIfAbsent(addMemberUserIds, memberRole);
|
||||||
|
|
||||||
|
// 更新人员数据不处理单位数据,单位更新请使用独立的更新单位接口。
|
||||||
|
/*
|
||||||
//比较单位数据
|
//比较单位数据
|
||||||
List<Sys_unit> sysUnits = dao.query(Sys_unit.class, Cnd.where(Sys_unit::getUnitLevel, "=", 2));
|
List<Sys_unit> sysUnits = dao.query(Sys_unit.class, Cnd.where(Sys_unit::getUnitLevel, "=", 2));
|
||||||
List<String> sysUnitIds = sysUnits.stream().map(Sys_unit::getId).toList();
|
List<String> sysUnitIds = sysUnits.stream().map(Sys_unit::getId).toList();
|
||||||
@@ -145,6 +203,7 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
|||||||
|
|
||||||
// 计算设置为会员的人数
|
// 计算设置为会员的人数
|
||||||
long memberCount = sysUsers.stream().filter(Sys_user::getMember).count();
|
long memberCount = sysUsers.stream().filter(Sys_user::getMember).count();
|
||||||
|
*/
|
||||||
|
|
||||||
// 6.1 更新提案的校领导角色,发送订阅
|
// 6.1 更新提案的校领导角色,发送订阅
|
||||||
ProposalConfig config = dao.fetch(ProposalConfig.class, Cnd.where("delFlag", "=", false).desc("updatedAt"));
|
ProposalConfig config = dao.fetch(ProposalConfig.class, Cnd.where("delFlag", "=", false).desc("updatedAt"));
|
||||||
@@ -152,6 +211,6 @@ public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateServic
|
|||||||
RoleEventPublisher.broadcast(new RoleEventMsg(unitId, RoleConstant.PROPOSAL_BRANCH_SCHOOL_LEADER.name(), RoleEventMsg.RENEW_ROLE));
|
RoleEventPublisher.broadcast(new RoleEventMsg(unitId, RoleConstant.PROPOSAL_BRANCH_SCHOOL_LEADER.name(), RoleEventMsg.RENEW_ROLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return StrUtil.format("增量更新成功,本次更新新入职老师{}人,新增单位{}个,设置为会员{}人。", sysUsers.size(), insertUnits.size(), memberCount);
|
return StrUtil.format("增量更新成功,本次更新新入职老师{}人。", sysUsers.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,18 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
|||||||
*/
|
*/
|
||||||
private static List<FieldMapping> fieldMappings;
|
private static List<FieldMapping> fieldMappings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 信息中心人员接口部分 dept_id 返回的是 32 位主键,这里转换为系统单位编码后再写入 unitId。
|
||||||
|
*/
|
||||||
|
private static final Map<String, String> DEPT_ID_UNIT_ID_MAP = Map.of(
|
||||||
|
"2c94270993a0da080193de729af43b43", "87",
|
||||||
|
"2c94270993a0da080193de7374763b5f", "88",
|
||||||
|
"2c94270993a0da080193de74c59c3b72", "26",
|
||||||
|
"2c94270993a0da080193de7528763b77", "89",
|
||||||
|
"2c9a816c7d0973aa017d30ef01210015", "46",
|
||||||
|
"2c9a816c7d0973aa017d30ef67670016", "302"
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取字段映射,使用懒加载模式
|
* 获取字段映射,使用懒加载模式
|
||||||
*/
|
*/
|
||||||
@@ -104,6 +116,16 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
|||||||
return fieldMappings;
|
return fieldMappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉取人员数据时,统一处理信息中心 dept_id 与系统 unitId 不一致的固定映射。
|
||||||
|
*/
|
||||||
|
private String convertDeptIdToUnitId(String deptId) {
|
||||||
|
if (StrUtil.isBlank(deptId)) {
|
||||||
|
return deptId;
|
||||||
|
}
|
||||||
|
return DEPT_ID_UNIT_ID_MAP.getOrDefault(deptId, deptId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Aop(TransAop.READ_COMMITTED)
|
@Aop(TransAop.READ_COMMITTED)
|
||||||
public Date pull() {
|
public Date pull() {
|
||||||
@@ -149,6 +171,9 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
|||||||
// 根据字段类型设置值
|
// 根据字段类型设置值
|
||||||
if (mapping.field.getType() == String.class) {
|
if (mapping.field.getType() == String.class) {
|
||||||
String value = raw.getStr(mapping.key);
|
String value = raw.getStr(mapping.key);
|
||||||
|
if ("unitId".equals(mapping.field.getName())) {
|
||||||
|
value = convertDeptIdToUnitId(value);
|
||||||
|
}
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(mapping.dict)) {
|
if (StrUtil.isNotBlank(mapping.dict)) {
|
||||||
List<Sys_data_dict> dictList = dataDictMap.get(mapping.dict);
|
List<Sys_data_dict> dictList = dataDictMap.get(mapping.dict);
|
||||||
|
|||||||
Reference in New Issue
Block a user