fix: 修复组织机构及用户数据在同步时接口报错导致用户数据无法正常处理,直接将数据库中的数据全部删除的BUG
This commit is contained in:
+145
-137
@@ -47,89 +47,93 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
|||||||
try{
|
try{
|
||||||
SyncUserService syncUserService = new SyncUserService();
|
SyncUserService syncUserService = new SyncUserService();
|
||||||
List<String> res = syncUserService.syncFotonUser();
|
List<String> res = syncUserService.syncFotonUser();
|
||||||
//存放岗位信息
|
if(res!=null && !res.isEmpty()){
|
||||||
Map<String, String> positionMap = new HashMap<>();
|
//存放岗位信息
|
||||||
TsPosition position = new TsPosition();
|
Map<String, String> positionMap = new HashMap<>();
|
||||||
position.setCurrent(1);
|
TsPosition position = new TsPosition();
|
||||||
position.setPageSize(100000);
|
position.setCurrent(1);
|
||||||
IPage<TsPosition> iPage = tsPositionService.getPosition(position);
|
position.setPageSize(100000);
|
||||||
List<TsPosition> positions=iPage.getRecords();
|
IPage<TsPosition> iPage = tsPositionService.getPosition(position);
|
||||||
if (!positions.isEmpty()) {
|
List<TsPosition> positions=iPage.getRecords();
|
||||||
positions.forEach(tsPosition -> {
|
if (!positions.isEmpty()) {
|
||||||
positionMap.put(tsPosition.getName(), tsPosition.getId());
|
positions.forEach(tsPosition -> {
|
||||||
});
|
positionMap.put(tsPosition.getName(), tsPosition.getId());
|
||||||
}
|
|
||||||
List<TsUser> addUserList = new ArrayList<>();
|
|
||||||
List<TsUser> upUserList = new ArrayList<>();
|
|
||||||
for (String s : res) {
|
|
||||||
JSONObject userData = JSONObject.parseObject(s);
|
|
||||||
if(userData.containsKey("results")){
|
|
||||||
JSONArray jsonArray = userData.getJSONArray("results");
|
|
||||||
jsonArray.forEach(object -> {
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
|
||||||
String userid = jsonObject.getString("userid");
|
|
||||||
TsUser userEO = tsUserService.getById(userid);
|
|
||||||
String userState = "";
|
|
||||||
if(userEO != null){
|
|
||||||
userState = "UPDATE";
|
|
||||||
}else{
|
|
||||||
userState = "ADD";
|
|
||||||
userEO = new TsUser();
|
|
||||||
}
|
|
||||||
//先获取岗位以及岗位id
|
|
||||||
//设置岗位
|
|
||||||
if (null != jsonObject.getString("title")) {
|
|
||||||
//通过岗位名称查询系统表中是否有岗位,有则设定用户的岗位为系统中的岗位,否则新增
|
|
||||||
if (null == positionMap.get(jsonObject.getString("title"))) {
|
|
||||||
TsPosition tsPosition = new TsPosition();
|
|
||||||
tsPosition.setId(String.valueOf(UUID.randomUUID()));
|
|
||||||
tsPosition.setName(jsonObject.getString("title"));
|
|
||||||
tsPositionService.addPosition(tsPosition);
|
|
||||||
//放入岗位的map集合中
|
|
||||||
positionMap.put(tsPosition.getName(), tsPosition.getId());
|
|
||||||
//放入类中
|
|
||||||
userEO.setPositionName(tsPosition.getName());
|
|
||||||
userEO.setPositionId(tsPosition.getId());
|
|
||||||
} else {
|
|
||||||
userEO.setPositionName(jsonObject.getString("title").trim());
|
|
||||||
userEO.setPositionId(positionMap.get(jsonObject.getString("title").trim()));
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
userEO.setPositionId(null);
|
|
||||||
userEO.setPositionName(null);
|
|
||||||
}
|
|
||||||
//设置其他数据
|
|
||||||
Timestamp createTime = new Timestamp(new Date().getTime());
|
|
||||||
userEO.setState(jsonObject.getString("userStatus"));
|
|
||||||
userEO.setUname(null!=jsonObject.getString("name")?jsonObject.getString("name"):"");
|
|
||||||
userEO.setCreationTime(createTime);
|
|
||||||
userEO.setUserId(jsonObject.getString("userid"));
|
|
||||||
userEO.setAccount(jsonObject.getString("userid"));
|
|
||||||
userEO.setInstitutionId(null!=jsonObject.getString("orgNumber")?jsonObject.getString("orgNumber"):"" );
|
|
||||||
userEO.setInstitutionName(null!=jsonObject.getString("orgName")?jsonObject.getString("orgName"):"" );
|
|
||||||
//2022-05-23:用户同步增加状态标识,将停用的用户过滤掉
|
|
||||||
if("1".equals(jsonObject.getString("userStatus"))){
|
|
||||||
userEO.setValidFlag(ValidFlagEnum.VALID_TRUE.getValue()+"");
|
|
||||||
userEO.setDisableFlag(ValidFlagEnum.VALID_TRUE.getValue()+"");
|
|
||||||
}else{
|
|
||||||
userEO.setValidFlag(ValidFlagEnum.VALID_FALSE.getValue()+"");
|
|
||||||
userEO.setDisableFlag(ValidFlagEnum.VALID_FALSE.getValue()+"");
|
|
||||||
}
|
|
||||||
if("ADD".equals(userState)){
|
|
||||||
addUserList.add(userEO);
|
|
||||||
}else {
|
|
||||||
upUserList.add(userEO);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
List<TsUser> addUserList = new ArrayList<>();
|
||||||
if(!addUserList.isEmpty()){
|
List<TsUser> upUserList = new ArrayList<>();
|
||||||
logger.debug("本次新增的用户为:"+JSONObject.toJSONString(addUserList));
|
for (String s : res) {
|
||||||
tsUserService.saveBatch(addUserList);
|
JSONObject userData = JSONObject.parseObject(s);
|
||||||
}
|
if(userData.containsKey("results")){
|
||||||
if(!upUserList.isEmpty()){
|
JSONArray jsonArray = userData.getJSONArray("results");
|
||||||
logger.debug("本次更新的用户为:"+JSONObject.toJSONString(upUserList));
|
jsonArray.forEach(object -> {
|
||||||
tsUserService.updateBatchById(upUserList);
|
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
||||||
|
String userid = jsonObject.getString("userid");
|
||||||
|
TsUser userEO = tsUserService.getById(userid);
|
||||||
|
String userState = "";
|
||||||
|
if(userEO != null){
|
||||||
|
userState = "UPDATE";
|
||||||
|
}else{
|
||||||
|
userState = "ADD";
|
||||||
|
userEO = new TsUser();
|
||||||
|
}
|
||||||
|
//先获取岗位以及岗位id
|
||||||
|
//设置岗位
|
||||||
|
if (null != jsonObject.getString("title")) {
|
||||||
|
//通过岗位名称查询系统表中是否有岗位,有则设定用户的岗位为系统中的岗位,否则新增
|
||||||
|
if (null == positionMap.get(jsonObject.getString("title"))) {
|
||||||
|
TsPosition tsPosition = new TsPosition();
|
||||||
|
tsPosition.setId(String.valueOf(UUID.randomUUID()));
|
||||||
|
tsPosition.setName(jsonObject.getString("title"));
|
||||||
|
tsPositionService.addPosition(tsPosition);
|
||||||
|
//放入岗位的map集合中
|
||||||
|
positionMap.put(tsPosition.getName(), tsPosition.getId());
|
||||||
|
//放入类中
|
||||||
|
userEO.setPositionName(tsPosition.getName());
|
||||||
|
userEO.setPositionId(tsPosition.getId());
|
||||||
|
} else {
|
||||||
|
userEO.setPositionName(jsonObject.getString("title").trim());
|
||||||
|
userEO.setPositionId(positionMap.get(jsonObject.getString("title").trim()));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
userEO.setPositionId(null);
|
||||||
|
userEO.setPositionName(null);
|
||||||
|
}
|
||||||
|
//设置其他数据
|
||||||
|
Timestamp createTime = new Timestamp(new Date().getTime());
|
||||||
|
userEO.setState(jsonObject.getString("userStatus"));
|
||||||
|
userEO.setUname(null!=jsonObject.getString("name")?jsonObject.getString("name"):"");
|
||||||
|
userEO.setCreationTime(createTime);
|
||||||
|
userEO.setUserId(jsonObject.getString("userid"));
|
||||||
|
userEO.setAccount(jsonObject.getString("userid"));
|
||||||
|
userEO.setInstitutionId(null!=jsonObject.getString("orgNumber")?jsonObject.getString("orgNumber"):"" );
|
||||||
|
userEO.setInstitutionName(null!=jsonObject.getString("orgName")?jsonObject.getString("orgName"):"" );
|
||||||
|
//2022-05-23:用户同步增加状态标识,将停用的用户过滤掉
|
||||||
|
if("1".equals(jsonObject.getString("userStatus"))){
|
||||||
|
userEO.setValidFlag(ValidFlagEnum.VALID_TRUE.getValue()+"");
|
||||||
|
userEO.setDisableFlag(ValidFlagEnum.VALID_TRUE.getValue()+"");
|
||||||
|
}else{
|
||||||
|
userEO.setValidFlag(ValidFlagEnum.VALID_FALSE.getValue()+"");
|
||||||
|
userEO.setDisableFlag(ValidFlagEnum.VALID_FALSE.getValue()+"");
|
||||||
|
}
|
||||||
|
if("ADD".equals(userState)){
|
||||||
|
addUserList.add(userEO);
|
||||||
|
}else {
|
||||||
|
upUserList.add(userEO);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!addUserList.isEmpty()){
|
||||||
|
logger.debug("本次新增的用户为:"+JSONObject.toJSONString(addUserList));
|
||||||
|
tsUserService.saveBatch(addUserList);
|
||||||
|
}
|
||||||
|
if(!upUserList.isEmpty()){
|
||||||
|
logger.debug("本次更新的用户为:"+JSONObject.toJSONString(upUserList));
|
||||||
|
tsUserService.updateBatchById(upUserList);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
logger.info("本次获取用户的数据为空,原因有2种:1、没有同步数据 2、请求接口报错");
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error(e.getMessage(),e);
|
logger.error(e.getMessage(),e);
|
||||||
@@ -145,68 +149,72 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
|||||||
try{
|
try{
|
||||||
SyncUserService syncUserService = new SyncUserService();
|
SyncUserService syncUserService = new SyncUserService();
|
||||||
List<String> res = syncUserService.syncFotonOrg();
|
List<String> res = syncUserService.syncFotonOrg();
|
||||||
//获取到所有用户数据
|
if(res!=null && !res.isEmpty()){
|
||||||
List<String> strings=new ArrayList<>();
|
//获取到所有用户数据
|
||||||
//tsInstitutionService.clearData();
|
List<String> strings=new ArrayList<>();
|
||||||
for (String s : res) {
|
//tsInstitutionService.clearData();
|
||||||
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
for (String s : res) {
|
||||||
jsonArray.forEach(object -> {
|
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
||||||
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
|
||||||
strings.add(jsonObject.getString("parentOrgNumber"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
List<TsInstitution> allTsInstitutionList = tsInstitutionService.list();
|
|
||||||
List<TsInstitution> addTsInstitutionList = new ArrayList<>();
|
|
||||||
List<TsInstitution> updateTsInstitutionList = new ArrayList<>();
|
|
||||||
List<TsInstitution> delTsInstitutionList = new ArrayList<>();
|
|
||||||
Set<String> syncAllIdList = new HashSet<>();
|
|
||||||
for (String s : res) {
|
|
||||||
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
|
||||||
if(jsonArray!=null){
|
|
||||||
jsonArray.forEach(object -> {
|
jsonArray.forEach(object -> {
|
||||||
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
||||||
TsInstitution tsInstitution=new TsInstitution();
|
strings.add(jsonObject.getString("parentOrgNumber"));
|
||||||
tsInstitution.setId(jsonObject.getString("orgNumber"));
|
|
||||||
tsInstitution.setName(jsonObject.getString("orgName"));
|
|
||||||
tsInstitution.setHasChild(strings.contains(jsonObject.getString("orgNumber"))?"1":"0");
|
|
||||||
tsInstitution.setParentId(jsonObject.getString("parentOrgNumber"));
|
|
||||||
//部门为"null"的数据不保存
|
|
||||||
if (!"null".equals(jsonObject.getString("orgName"))){
|
|
||||||
TsInstitution institution = tsInstitutionService.getById(tsInstitution.getId());
|
|
||||||
if(institution!=null){
|
|
||||||
updateTsInstitutionList.add(tsInstitution);
|
|
||||||
}else{
|
|
||||||
addTsInstitutionList.add(tsInstitution);
|
|
||||||
}
|
|
||||||
syncAllIdList.add(tsInstitution.getId());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
List<TsInstitution> allTsInstitutionList = tsInstitutionService.list();
|
||||||
//遍历出来需要删除的数据
|
List<TsInstitution> addTsInstitutionList = new ArrayList<>();
|
||||||
for(TsInstitution data :allTsInstitutionList){
|
List<TsInstitution> updateTsInstitutionList = new ArrayList<>();
|
||||||
if(!syncAllIdList.contains(data.getId())){
|
List<TsInstitution> delTsInstitutionList = new ArrayList<>();
|
||||||
delTsInstitutionList.add(data);
|
Set<String> syncAllIdList = new HashSet<>();
|
||||||
|
for (String s : res) {
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
|
||||||
|
if(jsonArray!=null){
|
||||||
|
jsonArray.forEach(object -> {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(object.toString());
|
||||||
|
TsInstitution tsInstitution=new TsInstitution();
|
||||||
|
tsInstitution.setId(jsonObject.getString("orgNumber"));
|
||||||
|
tsInstitution.setName(jsonObject.getString("orgName"));
|
||||||
|
tsInstitution.setHasChild(strings.contains(jsonObject.getString("orgNumber"))?"1":"0");
|
||||||
|
tsInstitution.setParentId(jsonObject.getString("parentOrgNumber"));
|
||||||
|
//部门为"null"的数据不保存
|
||||||
|
if (!"null".equals(jsonObject.getString("orgName"))){
|
||||||
|
TsInstitution institution = tsInstitutionService.getById(tsInstitution.getId());
|
||||||
|
if(institution!=null){
|
||||||
|
updateTsInstitutionList.add(tsInstitution);
|
||||||
|
}else{
|
||||||
|
addTsInstitutionList.add(tsInstitution);
|
||||||
|
}
|
||||||
|
syncAllIdList.add(tsInstitution.getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
//遍历出来需要删除的数据
|
||||||
//需要新增的数据
|
for(TsInstitution data :allTsInstitutionList){
|
||||||
if(!addTsInstitutionList.isEmpty()){
|
if(!syncAllIdList.contains(data.getId())){
|
||||||
logger.debug("本次新增的组织机构为:"+JSONObject.toJSONString(addTsInstitutionList));
|
delTsInstitutionList.add(data);
|
||||||
tsInstitutionService.saveBatch(addTsInstitutionList);
|
}
|
||||||
}
|
|
||||||
//需要更新的数据
|
|
||||||
if(!updateTsInstitutionList.isEmpty()){
|
|
||||||
logger.debug("本次更新的组织机构为:"+JSONObject.toJSONString(updateTsInstitutionList));
|
|
||||||
tsInstitutionService.updateBatchById(updateTsInstitutionList);
|
|
||||||
}
|
|
||||||
//需要删除的数据
|
|
||||||
if(!delTsInstitutionList.isEmpty()){
|
|
||||||
logger.debug("本次删除的组织机构为:"+JSONObject.toJSONString(delTsInstitutionList));
|
|
||||||
List<String> delIdList = new ArrayList<>();
|
|
||||||
for(TsInstitution data : delTsInstitutionList){
|
|
||||||
delIdList.add(data.getId());
|
|
||||||
}
|
}
|
||||||
tsInstitutionService.removeByIds(delIdList);
|
//需要新增的数据
|
||||||
|
if(!addTsInstitutionList.isEmpty()){
|
||||||
|
logger.debug("本次新增的组织机构为:"+JSONObject.toJSONString(addTsInstitutionList));
|
||||||
|
tsInstitutionService.saveBatch(addTsInstitutionList);
|
||||||
|
}
|
||||||
|
//需要更新的数据
|
||||||
|
if(!updateTsInstitutionList.isEmpty()){
|
||||||
|
logger.debug("本次更新的组织机构为:"+JSONObject.toJSONString(updateTsInstitutionList));
|
||||||
|
tsInstitutionService.updateBatchById(updateTsInstitutionList);
|
||||||
|
}
|
||||||
|
//需要删除的数据
|
||||||
|
if(!delTsInstitutionList.isEmpty()){
|
||||||
|
logger.debug("本次删除的组织机构为:"+JSONObject.toJSONString(delTsInstitutionList));
|
||||||
|
List<String> delIdList = new ArrayList<>();
|
||||||
|
for(TsInstitution data : delTsInstitutionList){
|
||||||
|
delIdList.add(data.getId());
|
||||||
|
}
|
||||||
|
tsInstitutionService.removeByIds(delIdList);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
logger.info("本次获取组织机构的数据为空,原因有2种:1、没有同步数据 2、请求接口报错");
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error(e.getMessage(),e);
|
logger.error(e.getMessage(),e);
|
||||||
|
|||||||
Reference in New Issue
Block a user