bug: 修改人员同步接口,去除已离职人员
This commit is contained in:
+21
@@ -23,7 +23,9 @@ import com.adc.da.sys.constant.ValidFlagEnum;
|
|||||||
import com.adc.da.sys.entity.UserOrgEO;
|
import com.adc.da.sys.entity.UserOrgEO;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import lombok.extern.log4j.Log4j;
|
import lombok.extern.log4j.Log4j;
|
||||||
@@ -496,6 +498,7 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
|||||||
}
|
}
|
||||||
List<TsUser> addUserList = new ArrayList<>();
|
List<TsUser> addUserList = new ArrayList<>();
|
||||||
List<TsUser> upUserList = new ArrayList<>();
|
List<TsUser> upUserList = new ArrayList<>();
|
||||||
|
Set<String> syncUserIdSet = new HashSet<>();
|
||||||
for (String s : res) {
|
for (String s : res) {
|
||||||
JSONObject userData = JSONObject.parseObject(s);
|
JSONObject userData = JSONObject.parseObject(s);
|
||||||
if(userData.containsKey("results")){
|
if(userData.containsKey("results")){
|
||||||
@@ -503,6 +506,7 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
|||||||
jsonArray.forEach(object -> {
|
jsonArray.forEach(object -> {
|
||||||
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
||||||
String userid = jsonObject.getString("userid");
|
String userid = jsonObject.getString("userid");
|
||||||
|
syncUserIdSet.add(userid);
|
||||||
TsUser userEO = tsUserService.getById(userid);
|
TsUser userEO = tsUserService.getById(userid);
|
||||||
String userState = "";
|
String userState = "";
|
||||||
if(userEO != null){
|
if(userEO != null){
|
||||||
@@ -566,6 +570,23 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
|||||||
logger.debug("本次更新的用户为:"+JSONObject.toJSONString(upUserList));
|
logger.debug("本次更新的用户为:"+JSONObject.toJSONString(upUserList));
|
||||||
tsUserService.updateBatchById(upUserList);
|
tsUserService.updateBatchById(upUserList);
|
||||||
}
|
}
|
||||||
|
LambdaQueryWrapper<TsUser> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(TsUser::getState,"1");
|
||||||
|
wrapper.eq(TsUser::getValidFlag,"0");
|
||||||
|
wrapper.eq(TsUser::getDisableFlag,"0");
|
||||||
|
wrapper.select(TsUser::getUserId);
|
||||||
|
Set<String> userIdDbList = tsUserService.list(wrapper).stream().map(TsUser::getUserId).collect(Collectors.toSet());
|
||||||
|
userIdDbList.removeAll(syncUserIdSet);
|
||||||
|
logger.info("本次同步删除掉的用户有:"+userIdDbList);
|
||||||
|
if(!userIdDbList.isEmpty()){
|
||||||
|
//删除数据库中不存在的用户
|
||||||
|
LambdaUpdateWrapper<TsUser> wrapper1 = new LambdaUpdateWrapper<>();
|
||||||
|
wrapper1.in(TsUser::getUserId,userIdDbList);
|
||||||
|
wrapper1.set(TsUser::getState,"0");
|
||||||
|
wrapper1.set(TsUser::getValidFlag,"1");
|
||||||
|
wrapper1.set(TsUser::getDisableFlag,"1");
|
||||||
|
tsUserService.update(wrapper1);
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
logger.info("本次获取用户的数据为空,原因有2种:1、没有同步数据 2、请求接口报错");
|
logger.info("本次获取用户的数据为空,原因有2种:1、没有同步数据 2、请求接口报错");
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -47,6 +47,7 @@
|
|||||||
<select id="selectPreviousInstitution" resultMap="TsUser">
|
<select id="selectPreviousInstitution" resultMap="TsUser">
|
||||||
select * from ts_user
|
select * from ts_user
|
||||||
<where>
|
<where>
|
||||||
|
STATE = '1' and VALID_FLAG = '0' and DISABLE_FLAG = '0'
|
||||||
<if test="userName != null and userName != '' ">
|
<if test="userName != null and userName != '' ">
|
||||||
( ts_user.ACCOUNT like concat(concat('%',#{userName}),'%') or ts_user.UNAME like concat(concat('%',#{userName}),'%') )
|
( ts_user.ACCOUNT like concat(concat('%',#{userName}),'%') or ts_user.UNAME like concat(concat('%',#{userName}),'%') )
|
||||||
</if>
|
</if>
|
||||||
@@ -96,7 +97,8 @@
|
|||||||
from ts_user
|
from ts_user
|
||||||
left join ts_institution ON ts_institution.id = (SELECT parent_id from ts_institution WHERE id = ts_user.INSTITUTION_ID)
|
left join ts_institution ON ts_institution.id = (SELECT parent_id from ts_institution WHERE id = ts_user.INSTITUTION_ID)
|
||||||
left join ts_institution t2 on t2.id=ts_user.INSTITUTION_ID
|
left join ts_institution t2 on t2.id=ts_user.INSTITUTION_ID
|
||||||
WHERE institution_id=#{institutionId}
|
WHERE ts_user.STATE = '1' and ts_user.VALID_FLAG = '0' and ts_user.DISABLE_FLAG = '0'
|
||||||
|
and institution_id=#{institutionId}
|
||||||
<if test="userName != null and userName != '' ">
|
<if test="userName != null and userName != '' ">
|
||||||
and ( ts_user.ACCOUNT like concat(concat('%',#{userName}),'%') or ts_user.UNAME like concat(concat('%',#{userName}),'%') )
|
and ( ts_user.ACCOUNT like concat(concat('%',#{userName}),'%') or ts_user.UNAME like concat(concat('%',#{userName}),'%') )
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
Reference in New Issue
Block a user