add:添加全量部门同步
This commit is contained in:
@@ -50,7 +50,7 @@ public class DataSyncController {
|
||||
@ApiOperation("同步组织机构")
|
||||
@PostMapping("/importOrgData")
|
||||
public String importOrgData() throws Exception {
|
||||
return iDataSyncService.orgDataSync();
|
||||
return iDataSyncService.orgDataSync2();
|
||||
}
|
||||
|
||||
@ApiOperation("同步组织机构,添加参数")
|
||||
|
||||
@@ -8,8 +8,10 @@ public interface IDataSyncService {
|
||||
public String dataSync();
|
||||
|
||||
public String dataSync2(Long chuo);
|
||||
|
||||
// 定时增量同步
|
||||
public String orgDataSync();
|
||||
// 手动全量同步
|
||||
public String orgDataSync2();
|
||||
|
||||
public String updateByOrgs();
|
||||
}
|
||||
|
||||
+95
-2
@@ -469,7 +469,7 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 增量同步部门数据
|
||||
@Transactional(rollbackFor = {RuntimeException.class,Exception.class})
|
||||
public String orgDataSync(){
|
||||
try{
|
||||
@@ -532,7 +532,7 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
||||
tsInstitutionService.updateBatchById(updateTsInstitutionList);
|
||||
}
|
||||
//需要删除的数据
|
||||
// 先行注释,会删除所有部门
|
||||
// 增量同步,不作删除
|
||||
// if(!delTsInstitutionList.isEmpty()){
|
||||
// logger.debug("本次删除的组织机构为:"+JSONObject.toJSONString(delTsInstitutionList));
|
||||
// List<String> delIdList = new ArrayList<>();
|
||||
@@ -562,6 +562,99 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
||||
return "1";
|
||||
}
|
||||
|
||||
// 手动全量同步部门信息
|
||||
@Transactional(rollbackFor = {RuntimeException.class,Exception.class})
|
||||
public String orgDataSync2(){
|
||||
try{
|
||||
SyncUserService syncUserService = new SyncUserService();
|
||||
List<String> res = syncUserService.syncFotonOrg2();
|
||||
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","");
|
||||
|
||||
Reference in New Issue
Block a user