添加批量更新网格员方法
This commit is contained in:
@@ -44,4 +44,6 @@ public class JobCron {
|
|||||||
public void updateCronCompanyContactEncrypt(){SpringUtils.getBean(CompanyContactService.class).updateCronCompanyContactEncrypt();}
|
public void updateCronCompanyContactEncrypt(){SpringUtils.getBean(CompanyContactService.class).updateCronCompanyContactEncrypt();}
|
||||||
//批量更新岗位联系人
|
//批量更新岗位联系人
|
||||||
public void updateCronJobContactEncrypt(){SpringUtils.getBean(JobContactService.class).updateCronJobContactEncrypt();}
|
public void updateCronJobContactEncrypt(){SpringUtils.getBean(JobContactService.class).updateCronJobContactEncrypt();}
|
||||||
|
//批量处理网格员
|
||||||
|
public void updateAppUserWgyEncrypt(){SpringUtils.getBean(IAppUserService.class).updateAppUserWgyEncrypt();}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,4 +44,14 @@ public interface AppUserMapper extends BaseMapper<AppUser>
|
|||||||
List<SysUser> getSysUserListEncrypt();
|
List<SysUser> getSysUserListEncrypt();
|
||||||
|
|
||||||
void batchUpdateSysUserEncrypt(List<SysUser> list);
|
void batchUpdateSysUserEncrypt(List<SysUser> list);
|
||||||
|
|
||||||
|
List<AppUser> selectAddUserSjdz();
|
||||||
|
|
||||||
|
List<AppUser> selectDifferUserSjdz();
|
||||||
|
|
||||||
|
void retract();
|
||||||
|
|
||||||
|
void batchUpdateDifferUser(List<AppUser> list);
|
||||||
|
|
||||||
|
void batchAddUser(List<AppUser> list);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,4 +95,6 @@ public interface IAppUserService
|
|||||||
public void updateSysUserEncrypt();
|
public void updateSysUserEncrypt();
|
||||||
|
|
||||||
public AppUser selectAppuserByIdcard(String idCard,String userType);
|
public AppUser selectAppuserByIdcard(String idCard,String userType);
|
||||||
|
|
||||||
|
public void updateAppUserWgyEncrypt();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.*;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@@ -1008,6 +1009,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> imple
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量处理app用户身份证和手机号加密问题
|
||||||
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateAppUserEncrypt(){
|
public void updateAppUserEncrypt(){
|
||||||
List<AppUser> userList=appUserMapper.selectAppUserList(new AppUser());
|
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)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateSysUserEncrypt(){
|
public void updateSysUserEncrypt(){
|
||||||
List<SysUser> sysUserList=appUserMapper.getSysUserListEncrypt();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,4 +236,85 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
on a.user_id = b.user_id and (phonenumber is not null or id_card is not null)
|
on a.user_id = b.user_id and (phonenumber is not null or id_card is not null)
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectAddUserSjdz" resultMap="AppUserResult">
|
||||||
|
SELECT name,sex ,phone,create_by,id_card,dw_userid,status,del_flag,is_recommend,is_company_user
|
||||||
|
FROM dwd_system_user WHERE id_card IS NOT NULL and phone!='vy4NnIAD3WKqsXM7zDDskg=='
|
||||||
|
AND NOT EXISTS ( SELECT 1 FROM ks_db4.app_user a WHERE trim(a.dw_userid) = trim(dwd_system_user.dw_userid))
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectDifferUserSjdz" resultMap="AppUserResult">
|
||||||
|
SELECT a.name,a.sex ,a.phone,a.create_by,a.id_card,a.dw_userid,a.status,a.del_flag,a.is_recommend,a.is_company_user,b.user_id
|
||||||
|
FROM dwd_system_user a inner join app_user b on a.dw_userid=b.dw_userid
|
||||||
|
WHERE b.del_flag='0' and a.phone!=b.phone_encrypt
|
||||||
|
and a.dw_userid!='1000000001' and b.dw_userid!='1000000001'
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="retract">
|
||||||
|
UPDATE app_user a SET is_company_user = '1',dw_userid = NULL,update_by = 'jbd_user',update_time = CURRENT_TIMESTAMP
|
||||||
|
WHERE a.del_flag = '0' AND a.dw_userid IS NOT NULL AND a.dw_userid != ''
|
||||||
|
AND a.dw_userid != '1000000001'
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM dwd_system_user b
|
||||||
|
WHERE a.dw_userid = b.dw_userid
|
||||||
|
);
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="batchUpdateDifferUser">
|
||||||
|
<if test="list != null and !list.isEmpty()">
|
||||||
|
UPDATE app_user
|
||||||
|
SET id_card = CASE
|
||||||
|
<foreach collection="list" item="item" separator="">
|
||||||
|
WHEN user_id = #{item.userId} THEN #{item.idCard}
|
||||||
|
</foreach>
|
||||||
|
END,
|
||||||
|
id_card_cipher = CASE
|
||||||
|
<foreach collection="list" item="item" separator="">
|
||||||
|
WHEN user_id = #{item.userId} THEN #{item.idCardCipher}
|
||||||
|
</foreach>
|
||||||
|
END,
|
||||||
|
id_card_encrypt = CASE
|
||||||
|
<foreach collection="list" item="item" separator="">
|
||||||
|
WHEN user_id = #{item.userId} THEN #{item.idCardEncrypt}
|
||||||
|
</foreach>
|
||||||
|
END,
|
||||||
|
phone = CASE
|
||||||
|
<foreach collection="list" item="item" separator="">
|
||||||
|
WHEN user_id = #{item.userId} THEN #{item.phone}
|
||||||
|
</foreach>
|
||||||
|
END,
|
||||||
|
phone_cipher = CASE
|
||||||
|
<foreach collection="list" item="item" separator="">
|
||||||
|
WHEN user_id = #{item.userId} THEN #{item.phoneCipher}
|
||||||
|
</foreach>
|
||||||
|
END,
|
||||||
|
phone_encrypt = CASE
|
||||||
|
<foreach collection="list" item="item" separator="">
|
||||||
|
WHEN user_id = #{item.userId} THEN #{item.phoneEncrypt}
|
||||||
|
</foreach>
|
||||||
|
END,
|
||||||
|
update_by = 'jbd_user',
|
||||||
|
update_time = CURRENT_TIMESTAMP
|
||||||
|
WHERE user_id IN
|
||||||
|
<foreach collection="list" item="item" open="(" separator="," close=")">
|
||||||
|
#{item.userId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<insert id="batchAddUser">
|
||||||
|
<if test="list != null and !list.isEmpty()">
|
||||||
|
INSERT INTO app_user (
|
||||||
|
name, sex, phone,phone_encrypt,phone_cipher,create_by,create_time,id_card,id_card_encrypt,id_card_cipher, dw_userid, status,del_flag,is_recommend,is_company_user
|
||||||
|
) VALUES
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(
|
||||||
|
#{item.name}, #{item.sex}, #{item.phone},#{item.phoneEncrypt},#{item.phoneCipher},
|
||||||
|
#{item.createBy}, SYSDATE, #{item.idCard},#{item.idCardEncrypt},#{item.idCardCipher},
|
||||||
|
#{item.dwUserid},#{item.status},#{item.delFlag},#{item.isRecommend},#{item.isCompanyUser}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
</insert>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user