bug: 修改人员同步定时任务,去掉时间戳,改为全量同步

This commit is contained in:
wxyclub
2023-11-10 11:26:10 +08:00
parent 44fa867f1f
commit 6f1b59748f
6 changed files with 156 additions and 6 deletions
@@ -48,7 +48,7 @@ public class ScheduledSync {
public void syncSchedulingTasks() {
if(isNotScheduled){
log.info("======================================开始同步基础数据========================================");
iDataSyncService.orgDataSync2(); //时间短
iDataSyncService.orgDataSync3(); //时间短
iDataSyncService.dataSync3(); //时间长
log.info("======================================结束同步基础数据========================================");
}
@@ -47,6 +47,12 @@ public class DataSyncController {
return iDataSyncService.dataSync2(chuo);
}
@ApiOperation("同步用户数据3,不带时间戳,全量同步")
@PostMapping("/importUserData3")
public String importUserData3() throws Exception {
return iDataSyncService.dataSync3();
}
@ApiOperation("同步组织机构")
@PostMapping("/importOrgData")
public String importOrgData() throws Exception {
@@ -12,8 +12,10 @@ public interface IDataSyncService {
public String dataSync3();
// 定时增量同步
public String orgDataSync();
// 手动全量同步
public String orgDataSync2();
// 全量同步
public String orgDataSync3();
public String updateByOrgs();
}
@@ -764,6 +764,101 @@ public class DataSyncServiceImpl implements IDataSyncService {
return "1";
}
// 手动全量同步部门信息
@Override
@Transactional(rollbackFor = {RuntimeException.class,Exception.class})
public String orgDataSync3(){
try{
SyncUserService syncUserService = new SyncUserService();
List<String> res = syncUserService.syncFotonOrg3();
if(res!=null && !res.isEmpty()){
res.forEach(each -> logger.info("同步部门数据:"+each));
//获取到所有用户数据
List<String> strings=new ArrayList<>();
//tsInstitutionService.clearData();
for (String s : res) {
JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(s.toString()).getString("results"));
jsonArray.forEach(object -> {
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 -> {
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(!syncAllIdList.contains(data.getId())){
delTsInstitutionList.add(data);
}
}
//需要新增的数据
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);
}
//全部部门
List<TsInstitution> allTsInstitutionListForPids = new ArrayList<>(addTsInstitutionList);
allTsInstitutionListForPids.addAll(updateTsInstitutionList);
for (TsInstitution tsInstitution : allTsInstitutionListForPids){
List<String> parentIds = new ArrayList<>();
getParentTaxCompanyIds(allTsInstitutionListForPids, tsInstitution.getId(), parentIds);
tsInstitution.setParentIds(String.join(",",parentIds));
}
if (! allTsInstitutionListForPids.isEmpty()) {
tsInstitutionService.updateBatchById(allTsInstitutionListForPids);
}
}else{
logger.info("本次获取组织机构的数据为空,原因有2种:1、没有同步数据 2、请求接口报错");
}
}catch(Exception e){
logger.error(e.getMessage(),e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
return "1";
}
public String updateByOrgs(){
QueryWrapper<TsInstitution> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("id","");