添加批量更新网格员方法

This commit is contained in:
sh
2026-03-30 16:10:42 +08:00
parent 933fe9288e
commit a8a082ef9d
5 changed files with 160 additions and 0 deletions

View File

@@ -44,4 +44,6 @@ public class JobCron {
public void updateCronCompanyContactEncrypt(){SpringUtils.getBean(CompanyContactService.class).updateCronCompanyContactEncrypt();}
//批量更新岗位联系人
public void updateCronJobContactEncrypt(){SpringUtils.getBean(JobContactService.class).updateCronJobContactEncrypt();}
//批量处理网格员
public void updateAppUserWgyEncrypt(){SpringUtils.getBean(IAppUserService.class).updateAppUserWgyEncrypt();}
}

View File

@@ -44,4 +44,14 @@ public interface AppUserMapper extends BaseMapper<AppUser>
List<SysUser> getSysUserListEncrypt();
void batchUpdateSysUserEncrypt(List<SysUser> list);
List<AppUser> selectAddUserSjdz();
List<AppUser> selectDifferUserSjdz();
void retract();
void batchUpdateDifferUser(List<AppUser> list);
void batchAddUser(List<AppUser> list);
}

View File

@@ -95,4 +95,6 @@ public interface IAppUserService
public void updateSysUserEncrypt();
public AppUser selectAppuserByIdcard(String idCard,String userType);
public void updateAppUserWgyEncrypt();
}

View File

@@ -4,6 +4,7 @@ import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@@ -1008,6 +1009,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> imple
}
}
/**
* 批量处理app用户身份证和手机号加密问题
*/
@Transactional(rollbackFor = Exception.class)
public void updateAppUserEncrypt(){
List<AppUser> userList=appUserMapper.selectAppUserList(new AppUser());
@@ -1023,6 +1027,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> imple
}
}
/**
* 批量处理sys_user用户身份证和手机号加密问题
*/
@Transactional(rollbackFor = Exception.class)
public void updateSysUserEncrypt(){
List<SysUser> sysUserList=appUserMapper.getSysUserListEncrypt();
@@ -1034,4 +1041,62 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> imple
}
}
}
/**
* 批量处理数据底座同步网格员用户
*/
@Transactional(rollbackFor = Exception.class)
public void updateAppUserWgyEncrypt(){
//1.处理用户手机号不一样的用户
List<AppUser> differUser=appUserMapper.selectDifferUserSjdz();
if(CollUtil.isNotEmpty(differUser)){
decryptAndRemoveFailed(differUser);
//分批次处理
List<List<AppUser>> differBatches = StringUtil.splitList(differUser, StringUtil.BATCH_SIZE);
for (List<AppUser> batch : differBatches) {
appUserMapper.batchUpdateDifferUser(batch);
}
}
//2.处理新增用户
List<AppUser> addUser=appUserMapper.selectAddUserSjdz();
if(CollUtil.isNotEmpty(addUser)){
decryptAndRemoveFailed(addUser);
List<List<AppUser>> addBatches = StringUtil.splitList(addUser, StringUtil.BATCH_SIZE);
for (List<AppUser> batch : addBatches) {
appUserMapper.batchAddUser(batch);
}
}
//3.处理不存在的用户,收回权限
appUserMapper.retract();
}
/**
* 移除手机号为空或者解密失败的数据
* @param userList
*/
private void decryptAndRemoveFailed(List<AppUser> userList) {
Iterator<AppUser> iterator = userList.iterator();
while (iterator.hasNext()) {
AppUser user = iterator.next();
try {
String encryptedPhone = user.getPhone();
String realPhone = null;
if (encryptedPhone != null) {
realPhone = QuickValidUtils.getSm4Decrypt(encryptedPhone);
}
String finalPhone = (realPhone == null) ? "" : realPhone.trim();
if (finalPhone.isEmpty() || finalPhone.length() > 11) {
log.warn("用户ID=" + user.getUserId() + "dw_userid=" + user.getDwUserid() + " 手机号解密后为空或超长,跳过");
iterator.remove();
continue;
}
user.setPhone(finalPhone);
//手机号身份证都加密
QuickValidUtils.savePhoneIdCardSm4(user);
} catch (Exception e) {
log.error("用户ID=" + user.getUserId() + " 手机号解密失败,已从更新列表移除", e);
iterator.remove();
}
}
}
}