|
@@ -11,6 +11,7 @@ import com.dragoninfo.dcuc.app.facade.IApplyInfoFacade;
|
|
|
import com.dragoninfo.dcuc.auth.auth.constance.CommonCons;
|
|
|
import com.dragoninfo.dcuc.auth.config.DcucAuthConfig;
|
|
|
import com.dragoninfo.dcuc.auth.config.SubSyncConfig;
|
|
|
+import com.dragoninfo.dcuc.auth.constance.AddSyncContance;
|
|
|
import com.dragoninfo.dcuc.auth.constance.UserApiConstance;
|
|
|
import com.dragoninfo.dcuc.auth.sub.business.ISubSyncBusiness;
|
|
|
import com.dragoninfo.dcuc.auth.sub.entity.*;
|
|
@@ -22,6 +23,7 @@ import com.dragoninfo.dcuc.common.http.HttpUtil;
|
|
|
import com.dragoninfo.dcuc.duceap.enums.UserTypeEnum;
|
|
|
import com.dragoninfo.duceap.core.enums.ResultEnum;
|
|
|
import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
+import com.dragonsoft.duceap.base.entity.security.SecurityUser;
|
|
|
import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
import com.dragonsoft.duceap.base.utils.UserContextUtils;
|
|
|
import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
|
|
@@ -31,15 +33,18 @@ import com.dragonsoft.duceap.core.search.enums.SearchOperator;
|
|
|
import com.google.common.base.Joiner;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.Header;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.context.request.RequestAttributes;
|
|
|
-import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.util.StopWatch;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -53,6 +58,16 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
|
|
|
public static Logger logger = LoggerFactory.getLogger(ISubSyncBusiness.class);
|
|
|
|
|
|
+ private final String syncAllFail = "000";
|
|
|
+
|
|
|
+ private final String syncSuccessStatus = "2";
|
|
|
+
|
|
|
+ private final String syncS_FStatus = "1";
|
|
|
+
|
|
|
+ private final String syncFailStatus = "0";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
private IAuthOrgInfoService authOrgInfoService;
|
|
|
|
|
@@ -83,32 +98,94 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
@Autowired
|
|
|
private IApplyInfoFacade applyInfoFacade;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAddSyncRecordService addSyncRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAuthUserAddOriginalService userAddOriginalService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAuthOrgAddOriginalService orgAddOriginalService;
|
|
|
+
|
|
|
@Override
|
|
|
public ResponseStatus userSync() {
|
|
|
- //因为子线程中需要调用总线需要用到请求头中的信息
|
|
|
- //需要将requestAttributes设置到子线程中的RequestContextHolder
|
|
|
- //SpringWeb暂时未提供RequestContextHolder父子线程共享ThreadLocal中的数据的配置,需要手动设置
|
|
|
- RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
|
|
- //开启父子线程
|
|
|
- //方法内部有从ThreadLocal获取信息
|
|
|
- //CompletableFuture默认使用ForkJoin线程池,不要使用1.8的新线程开启方法
|
|
|
- //如果使用线程池需要用包装类将线程包装后设置RequestContextHolder
|
|
|
- Runnable r = ()->{
|
|
|
- RequestContextHolder.setRequestAttributes(requestAttributes);
|
|
|
- try {
|
|
|
- //同步用户信息
|
|
|
- getUserInfoFromRemote(1, subSyncConfig.getPageSize());
|
|
|
- userInfoSync();
|
|
|
- } finally {
|
|
|
- RequestContextHolder.resetRequestAttributes();
|
|
|
- }
|
|
|
- };
|
|
|
+ //不使用线程池
|
|
|
+ //currentUser在线程环境中才能清除
|
|
|
+ SecurityUser currentUser = UserContextUtils.getCurrentUser();
|
|
|
+ String idcard = currentUser.getIdcard();
|
|
|
+ List<Header> headers = getHeads(idcard);
|
|
|
+ Runnable r = getUserSyncTask(currentUser, headers);
|
|
|
Thread t = new Thread(r);
|
|
|
t.start();
|
|
|
return ResponseStatus.success();
|
|
|
}
|
|
|
|
|
|
- private void saveUserOrgRel(List<AuthUserOriginalData> content, Map<String, AuthUserInfo> idcardMap, UserTypeEnum userType) {
|
|
|
+ private Runnable getUserSyncTask(SecurityUser currentUser, List<Header> headers) {
|
|
|
+ return ()->{
|
|
|
+ UserContextUtils.setCurrentUser(currentUser);
|
|
|
+ RLock lock = redissonClient.getLock(AddSyncContance.USER_SYNC_KEY);
|
|
|
+ try {
|
|
|
+ //加锁
|
|
|
+ boolean tryLock = lock.tryLock(0, 20, TimeUnit.MINUTES);
|
|
|
+ if (!tryLock) {
|
|
|
+ log.info("try lock fail");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ StopWatch watch = new StopWatch("userSync");
|
|
|
+
|
|
|
+ //获取用户信息
|
|
|
+ watch.start("getUserInfoFromRemote");
|
|
|
+ getUserInfoFromRemote(1, subSyncConfig.getPageSize(), headers);
|
|
|
+ watch.stop();
|
|
|
+
|
|
|
+ //同步用户信息
|
|
|
+ watch.start("userInfoSync");
|
|
|
+ userInfoSync();
|
|
|
+ watch.stop();
|
|
|
+
|
|
|
+ //更新同步记录
|
|
|
+ updateAddSyncRecord(AddSyncContance.ADD_SYNC_TYPE_USER, true, null, null);
|
|
|
+ } catch (Exception e){
|
|
|
+ log.error("userSync error.", e);
|
|
|
+ updateAddSyncRecord(AddSyncContance.ADD_SYNC_TYPE_USER, false, null, null);
|
|
|
+ }finally {
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateAddSyncRecord(String type, boolean success, Date updateTime, String result) {
|
|
|
+ if(null == updateTime) {
|
|
|
+ updateTime = new Date();
|
|
|
+ }
|
|
|
+ AddSyncRecord record = addSyncRecordService.getRecordByType(type);
|
|
|
+ if(null == record) {
|
|
|
+ record = new AddSyncRecord();
|
|
|
+ record.setType(type);
|
|
|
+ }
|
|
|
+ if(success) {
|
|
|
+ record.setSuccessTime(updateTime);
|
|
|
+ record.setSuccessResult(result);
|
|
|
+ }else {
|
|
|
+ record.setFailTime(updateTime);
|
|
|
+ record.setFailResult(result);
|
|
|
+ }
|
|
|
+ if(record.getId() != null) {
|
|
|
+ addSyncRecordService.update(record);
|
|
|
+ } else {
|
|
|
+ addSyncRecordService.save(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveUserOrgRel(List<? extends AuthUserOriginalBase> content, Map<String, AuthUserInfo> idcardMap, UserTypeEnum userType) {
|
|
|
+ if(CollectionUtils.isEmpty(content)) {
|
|
|
+ log.info("saveUserOrgRel content is empty");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
Boolean rel = subSyncConfig.getUserOrgRel();
|
|
|
if(null != rel && rel) {
|
|
|
saveUserOrgRelFromRemote(content, idcardMap, userType);
|
|
@@ -134,7 +211,7 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
rel.setRelStatus(JobTypeEnum.ZZ.getValue());
|
|
|
return rel;
|
|
|
}).collect(Collectors.toList());
|
|
|
- authUserOrgRelService.saveOneRelByOrgId(collect);
|
|
|
+ authUserOrgRelService.saveOneRelByOrgCode(collect);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -143,11 +220,8 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
* @param idcardMap
|
|
|
* @param userType
|
|
|
*/
|
|
|
- private void saveUserOrgRelFromRemote(List<AuthUserOriginalData> content, Map<String, AuthUserInfo> idcardMap, UserTypeEnum userType) {
|
|
|
+ private void saveUserOrgRelFromRemote(List<? extends AuthUserOriginalBase> content, Map<String, AuthUserInfo> idcardMap, UserTypeEnum userType) {
|
|
|
logger.info("-------------saveUserOrgRelFromRemote START-----------");
|
|
|
- if(CollectionUtils.isEmpty(content)) {
|
|
|
- return ;
|
|
|
- }
|
|
|
List<AuthUserOrgRel> relList = new ArrayList<>();
|
|
|
if(UserTypeEnum.POLICE.equals(userType)) {
|
|
|
List<AuthUserOrgRel> collect = getAuthUserOrgRelsFromPolice(idcardMap, content);
|
|
@@ -171,7 +245,7 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
logger.info("-------------saveUserOrgRelFromRemote END-----------");
|
|
|
}
|
|
|
|
|
|
- private List<AuthUserOrgRel> getAuthUserOrgRelsFromExternal(Map<String, AuthUserInfo> idcardMap, List<AuthUserOriginalData> externalGroup) {
|
|
|
+ private List<AuthUserOrgRel> getAuthUserOrgRelsFromExternal(Map<String, AuthUserInfo> idcardMap, List<? extends AuthUserOriginalBase> externalGroup) {
|
|
|
//收集所有的应用id,批量查询应用信息
|
|
|
//通过appCode查询应用所属机构code
|
|
|
//然后录入机构关联信息
|
|
@@ -187,6 +261,7 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
Map<String, String> appCodeKeyOrgCodeMap = applyInfoList
|
|
|
.stream()
|
|
|
.filter(e->StringUtils.isNotBlank(e.getOrgCode()))
|
|
|
+ .distinct()
|
|
|
.collect(Collectors.toMap(ApplyInfo::getApplyCode, ApplyInfo::getOrgCode));
|
|
|
List<String> orgCodes = new ArrayList<>(appCodeKeyOrgCodeMap.values());
|
|
|
List<AuthOrgInfo> orgInfoList = authOrgInfoService.getOrgByCodes(orgCodes);
|
|
@@ -207,24 +282,23 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
rel.setUserId(userInfo.getId());
|
|
|
rel.setIdcard(userInfo.getIdcard());
|
|
|
rel.setUserType(UserTypeEnum.EXTERNAL.getValue());
|
|
|
+ rel.setRelStatus(JobTypeEnum.ZZ.getValue());
|
|
|
String orgCode = appCodeKeyOrgCodeMap.get(appCode);
|
|
|
if (StringUtils.isBlank(orgCode)) {
|
|
|
return null;
|
|
|
}
|
|
|
+ rel.setOrgCode(orgCode);
|
|
|
AuthOrgInfo authOrgInfo = orgCodeKeyOrgMap.get(orgCode);
|
|
|
- if (null == authOrgInfo) {
|
|
|
- return null;
|
|
|
+ if (null != authOrgInfo) {
|
|
|
+ rel.setOrgId(authOrgInfo.getId());
|
|
|
}
|
|
|
- rel.setOrgCode(authOrgInfo.getCode());
|
|
|
- rel.setOrgId(authOrgInfo.getId());
|
|
|
- rel.setRelStatus(JobTypeEnum.ZZ.getValue());
|
|
|
return rel;
|
|
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
return rels;
|
|
|
}).filter(Objects::nonNull).flatMap(List::stream).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- private List<AuthUserOrgRel> getAuthUserOrgRelsFromAuxiliry(Map<String, AuthUserInfo> idcardMap, List<AuthUserOriginalData> auxiliryGroup) {
|
|
|
+ private List<AuthUserOrgRel> getAuthUserOrgRelsFromAuxiliry(Map<String, AuthUserInfo> idcardMap, List<? extends AuthUserOriginalBase> auxiliryGroup) {
|
|
|
return auxiliryGroup.stream().map(e -> {
|
|
|
AuthUserInfo userInfo = idcardMap.get(e.getIdcard());
|
|
|
if (null == userInfo) {
|
|
@@ -246,7 +320,7 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- private List<AuthUserOrgRel> getAuthUserOrgRelsFromPolice(Map<String, AuthUserInfo> idcardMap, List<AuthUserOriginalData> policeGroup) {
|
|
|
+ private List<AuthUserOrgRel> getAuthUserOrgRelsFromPolice(Map<String, AuthUserInfo> idcardMap, List<? extends AuthUserOriginalBase> policeGroup) {
|
|
|
List<AuthUserOrgRel> collect = policeGroup.stream().map(e -> convertPostInfoToRel(idcardMap, e))
|
|
|
.filter(Objects::nonNull)
|
|
|
.flatMap(List::stream).collect(Collectors.toList());
|
|
@@ -269,9 +343,9 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
return collect;
|
|
|
}
|
|
|
|
|
|
- private List<AuthUserOrgRel> convertPostInfoToRel(Map<String, AuthUserInfo> idcardMap, AuthUserOriginalData e) {
|
|
|
- String orgRelData = e.getOrgRelData();
|
|
|
- String idcard = e.getIdcard();
|
|
|
+ private <T extends AuthUserOriginalBase> List<AuthUserOrgRel> convertPostInfoToRel(Map<String, AuthUserInfo> idcardMap, T t) {
|
|
|
+ String orgRelData = t.getOrgRelData();
|
|
|
+ String idcard = t.getIdcard();
|
|
|
AuthUserInfo userInfo = idcardMap.get(idcard);
|
|
|
if (userInfo == null) {
|
|
|
return null;
|
|
@@ -282,13 +356,17 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
}
|
|
|
return jsonArray.stream().map(json -> {
|
|
|
JSONObject jsonObject = (JSONObject) json;
|
|
|
+ String orgCode = jsonObject.getString("orgCode");
|
|
|
+ if(StringUtils.isBlank(orgCode)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
AuthUserOrgRel rel = new AuthUserOrgRel();
|
|
|
rel.setUserId(userInfo.getId());
|
|
|
rel.setUserType(UserTypeEnum.POLICE.getValue());
|
|
|
rel.setIdcard(idcard);
|
|
|
rel.setRelName(jsonObject.getString("postType"));
|
|
|
rel.setRelStatus(jsonObject.getString("jobType"));
|
|
|
- rel.setOrgCode(jsonObject.getString("orgCode"));
|
|
|
+ rel.setOrgCode(orgCode);
|
|
|
return rel;
|
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
@@ -296,13 +374,14 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
|
|
|
/**
|
|
|
* 从用户中心获取用户信息并保存到用户原始数据表
|
|
|
- * @param pageSize
|
|
|
* @param currentPage
|
|
|
+ * @param pageSize
|
|
|
+ * @param headers
|
|
|
*/
|
|
|
- public void getUserInfoFromRemote(Integer currentPage,Integer pageSize) {
|
|
|
- getDiffTypeUserInfo(currentPage, pageSize, UserApiConstance.POLICE_SYNC_API, UserTypeEnum.POLICE);
|
|
|
- getDiffTypeUserInfo(currentPage, pageSize, UserApiConstance.AUXILIRY_SYNC_API, UserTypeEnum.HELPER);
|
|
|
- getDiffTypeUserInfo(currentPage, pageSize, UserApiConstance.EXTERNAL_SYNC_API, UserTypeEnum.EXTERNAL);
|
|
|
+ public void getUserInfoFromRemote(Integer currentPage, Integer pageSize, List<Header> headers) {
|
|
|
+ getDiffTypeUserInfo(currentPage, pageSize, UserApiConstance.POLICE_SYNC_API, UserTypeEnum.POLICE, headers);
|
|
|
+ getDiffTypeUserInfo(currentPage, pageSize, UserApiConstance.AUXILIRY_SYNC_API, UserTypeEnum.HELPER, headers);
|
|
|
+ getDiffTypeUserInfo(currentPage, pageSize, UserApiConstance.EXTERNAL_SYNC_API, UserTypeEnum.EXTERNAL, headers);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -311,15 +390,22 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
* @param pageSize
|
|
|
* @param userInfoApi
|
|
|
* @param userType
|
|
|
+ * @param headers
|
|
|
*/
|
|
|
- private void getDiffTypeUserInfo(Integer currentPage, Integer pageSize, String userInfoApi, UserTypeEnum userType) {
|
|
|
+ private void getDiffTypeUserInfo(Integer currentPage, Integer pageSize, String userInfoApi,
|
|
|
+ UserTypeEnum userType, List<Header> headers) {
|
|
|
Date now = new Date();
|
|
|
Integer totalPage = null;
|
|
|
- List<Header> headers = getHeads();
|
|
|
ApiSearchReq apiSearchReq = new ApiSearchReq();
|
|
|
ApiPageReq pageReq = new ApiPageReq();
|
|
|
pageReq.setSize(pageSize);
|
|
|
apiSearchReq.setPage(pageReq);
|
|
|
+ Map<String, SearchParam> filters = new HashMap<>();
|
|
|
+ SearchParam searchParam = new SearchParam();
|
|
|
+ searchParam.setValue(BooleanEnum.FALSE.value);
|
|
|
+ searchParam.setOperator(SearchOperator.eq.name());
|
|
|
+ filters.put("deleted", searchParam);
|
|
|
+ apiSearchReq.setFilters(filters);
|
|
|
String url = Joiner.on("").join(authConfig.getUserCenterUrl(), userInfoApi);
|
|
|
logger.info("-------------getUserInfoFromRemote START-----------");
|
|
|
do {
|
|
@@ -354,43 +440,25 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
return totalPage;
|
|
|
}
|
|
|
|
|
|
- private List<Header> getHeads() {
|
|
|
- String idcard = UserContextUtils.getCurrentUser().getIdcard();
|
|
|
+ private List<Header> getHeads(String idcard) {
|
|
|
+ if(StringUtils.isBlank(idcard)) {
|
|
|
+ idcard = authConfig.getSyncTaskIdcard();
|
|
|
+ }
|
|
|
return UserCenterBusiUtil.getHeads(idcard, authConfig.getAppCode());
|
|
|
}
|
|
|
|
|
|
private void saveUserOri(Date now, ApiResultPage<JSONObject> syncResult, UserTypeEnum userType) {
|
|
|
List<JSONObject> content = syncResult.getContent();
|
|
|
List<AuthUserOriginalData> originals = new ArrayList<>();
|
|
|
- for (JSONObject jsonObject : content) {
|
|
|
+ for (JSONObject json : content) {
|
|
|
AuthUserOriginalData userOri = new AuthUserOriginalData();
|
|
|
- userOri.setIdcard(jsonObject.getString("idcard"));
|
|
|
+ userOri.setIdcard(json.getString("idcard"));
|
|
|
userOri.setDeleted(BooleanEnum.FALSE.value);
|
|
|
userOri.setSync(BooleanEnum.FALSE.value);
|
|
|
userOri.setSyncDate(now);
|
|
|
userOri.setUserType(userType.getValue());
|
|
|
//保存联系方式json
|
|
|
- JSONObject userContact = jsonObject.getJSONObject("userContact");
|
|
|
- if(null != userContact && !userContact.isEmpty()) {
|
|
|
- userOri.setContactData(userContact.toJSONString());
|
|
|
- }
|
|
|
- jsonObject.remove("userContact");
|
|
|
- //保存人员和机构关系json
|
|
|
- if (userType.equals(UserTypeEnum.POLICE)) {
|
|
|
- JSONArray jsonArray = jsonObject.getJSONArray("postInfos");
|
|
|
- if (CollectionUtils.isNotEmpty(jsonArray)) {
|
|
|
- userOri.setOrgRelData(jsonArray.toJSONString());
|
|
|
- jsonObject.remove("postInfos");
|
|
|
- }
|
|
|
- } else if (userType.equals(UserTypeEnum.EXTERNAL)) {
|
|
|
- String projectCodes = jsonObject.getString("projectCode");
|
|
|
- if(StringUtils.isNotBlank(projectCodes)) {
|
|
|
- userOri.setOrgRelData(projectCodes);
|
|
|
- }
|
|
|
- jsonObject.remove("projectCode");
|
|
|
- }
|
|
|
- //保存人员数据json
|
|
|
- userOri.setJsonData(jsonObject.toJSONString());
|
|
|
+ setJSONData(userType, json, userOri);
|
|
|
originals.add(userOri);
|
|
|
}
|
|
|
//过程数据保存
|
|
@@ -433,7 +501,11 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
}while (true);
|
|
|
}
|
|
|
|
|
|
- private void saveContact(List<AuthUserOriginalData> content, Map<String, AuthUserInfo> idcardMap) {
|
|
|
+ private void saveContact(List<? extends AuthUserOriginalBase> content, Map<String, AuthUserInfo> idcardMap) {
|
|
|
+ if(CollectionUtils.isEmpty(content)) {
|
|
|
+ log.info("saveContact content is empty");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
logger.info("-------------saveUserContact START-----------");
|
|
|
List<AuthUserContact> collect = content.stream().map(e -> {
|
|
|
String contactData = e.getContactData();
|
|
@@ -454,6 +526,10 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
}
|
|
|
|
|
|
private List<AuthUserInfo> saveUserInfo(List<AuthUserOriginalData> content, UserTypeEnum userType) {
|
|
|
+ if(CollectionUtils.isEmpty(content)) {
|
|
|
+ log.info("saveUserInfo content is empty");
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
List<AuthUserInfo> userInfoList = content.stream().map(item -> {
|
|
|
String jsonData = item.getJsonData();
|
|
|
AuthUserInfo authUserInfo = JSON.parseObject(jsonData, AuthUserInfo.class);
|
|
@@ -464,12 +540,40 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
//设置人员的机构字段信息
|
|
|
- setUserOrgInfos(content, userType, userInfoList);
|
|
|
+ if(UserTypeEnum.POLICE.equals(userType)) {
|
|
|
+ setPoliceOrgCode(content, userType, userInfoList);
|
|
|
+ }
|
|
|
+ setUserOrgInfos(userType, userInfoList);
|
|
|
authUserInfoService.batchSaveByIdcard(userInfoList);
|
|
|
return userInfoList;
|
|
|
}
|
|
|
|
|
|
- private void setUserOrgInfos(List<AuthUserOriginalData> content, UserTypeEnum userType, List<AuthUserInfo> userInfoList) {
|
|
|
+ private void setPoliceOrgCode(List<? extends AuthUserOriginalBase> content, UserTypeEnum userType, List<AuthUserInfo> userInfoList) {
|
|
|
+ //警员根据职务排序,取职务序号小的为主机构
|
|
|
+ Map<String, AuthUserInfo> idcardMap = userInfoList
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(AuthUserInfo::getIdcard, e -> e));
|
|
|
+ content.forEach(e->{
|
|
|
+ String orgRelData = e.getOrgRelData();
|
|
|
+ JSONArray jsonArray = JSON.parseObject(orgRelData, JSONArray.class);
|
|
|
+ if(!jsonArray.isEmpty()) {
|
|
|
+ String orgCode = jsonArray.stream()
|
|
|
+ .map(json -> (JSONObject) json).min((x, y) -> {
|
|
|
+ String xJobType = x.getString("jobType");
|
|
|
+ String yJobType = y.getString("jobType");
|
|
|
+ return xJobType.compareTo(yJobType);
|
|
|
+ }).orElse(new JSONObject()).getString("orgCode");
|
|
|
+ if(StringUtils.isNotBlank(orgCode)) {
|
|
|
+ AuthUserInfo userInfo = idcardMap.get(e.getIdcard());
|
|
|
+ if(null != userInfo) {
|
|
|
+ userInfo.setOrgCode(orgCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setUserOrgInfos(UserTypeEnum userType, List<AuthUserInfo> userInfoList) {
|
|
|
if(UserTypeEnum.EXTERNAL.equals(userType)) {
|
|
|
//施工人员不关联主机构
|
|
|
userInfoList.forEach(e->{
|
|
@@ -477,7 +581,7 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
e.setOrgCode(null);
|
|
|
e.setOrgName(null);
|
|
|
});
|
|
|
- } else if (UserTypeEnum.HELPER.equals(userType)) {
|
|
|
+ } else {
|
|
|
//修改orgId
|
|
|
List<String> orgCodes = userInfoList.stream()
|
|
|
.map(AuthUserInfo::getOrgCode).distinct()
|
|
@@ -486,33 +590,6 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
List<AuthOrgInfo> authOrgInfos = authOrgInfoService.getOrgByCodes(orgCodes);
|
|
|
setUpOrgInfo(userInfoList, authOrgInfos);
|
|
|
}
|
|
|
- } else if(UserTypeEnum.POLICE.equals(userType)) {
|
|
|
- //警员根据职务排序,取职务序号小的为主机构
|
|
|
- Map<String, AuthUserInfo> idcardMap = userInfoList
|
|
|
- .stream()
|
|
|
- .collect(Collectors.toMap(AuthUserInfo::getIdcard, e -> e));
|
|
|
- Set<String> orgCodes = new HashSet<>();
|
|
|
- content.forEach(e->{
|
|
|
- String orgRelData = e.getOrgRelData();
|
|
|
- JSONArray jsonArray = JSON.parseObject(orgRelData, JSONArray.class);
|
|
|
- if(!jsonArray.isEmpty()) {
|
|
|
- String orgCode = jsonArray.stream()
|
|
|
- .map(json -> (JSONObject) json).min((x, y) -> {
|
|
|
- String xJobType = x.getString("jobType");
|
|
|
- String yJobType = y.getString("jobType");
|
|
|
- return xJobType.compareTo(yJobType);
|
|
|
- }).orElse(new JSONObject()).getString("orgCode");
|
|
|
- if(StringUtils.isNotBlank(orgCode)) {
|
|
|
- AuthUserInfo userInfo = idcardMap.get(e.getIdcard());
|
|
|
- userInfo.setOrgCode(orgCode);
|
|
|
- orgCodes.add(orgCode);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- if(!orgCodes.isEmpty()) {
|
|
|
- List<AuthOrgInfo> authOrgInfos = authOrgInfoService.getOrgByCodes(new ArrayList<>(orgCodes));
|
|
|
- setUpOrgInfo(userInfoList, authOrgInfos);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -525,7 +602,6 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
if(StringUtils.isBlank(orgCode) || null == (authOrgInfo = orgCodeMap.get(orgCode))) {
|
|
|
e.setOrgName(null);
|
|
|
e.setOrgId(null);
|
|
|
- e.setOrgCode(null);
|
|
|
return ;
|
|
|
}
|
|
|
e.setOrgId(authOrgInfo.getId());
|
|
@@ -536,30 +612,383 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
|
|
|
@Override
|
|
|
public ResponseStatus orgSync() {
|
|
|
- //因为子线程中需要调用总线需要用到请求头中的信息
|
|
|
- //需要将requestAttributes设置到子线程中的RequestContextHolder
|
|
|
- //SpringWeb暂时未提供RequestContextHolder父子线程共享ThreadLocal中的数据的配置,需要手动设置
|
|
|
- RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
|
|
- //开启父子线程
|
|
|
- //方法内部有从ThreadLocal获取信息
|
|
|
- //CompletableFuture默认使用ForkJoin线程池,不要使用1.8的新线程开启方法
|
|
|
- //如果使用线程池需要用包装类将线程包装后设置RequestContextHolder
|
|
|
- Runnable r = ()->{
|
|
|
- RequestContextHolder.setRequestAttributes(requestAttributes);
|
|
|
- try {
|
|
|
- getOrgInfoFromRemote(1, subSyncConfig.getPageSize());
|
|
|
- orgInfoSync();
|
|
|
- setPathAndUpId();
|
|
|
- orgTreeService.reInitTrees();
|
|
|
- } finally {
|
|
|
- RequestContextHolder.resetRequestAttributes();
|
|
|
- }
|
|
|
- };
|
|
|
+ //不使用线程池
|
|
|
+ //currentUser在线程环境中才能清除
|
|
|
+ SecurityUser currentUser = UserContextUtils.getCurrentUser();
|
|
|
+ List<Header> heads = getHeads(currentUser.getIdcard());
|
|
|
+ Runnable r = getOrgSyncTask(currentUser, heads);
|
|
|
+ Thread t = new Thread(r);
|
|
|
+ t.start();
|
|
|
+ return ResponseStatus.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Runnable getOrgSyncTask(SecurityUser currentUser, List<Header> heads) {
|
|
|
+ return ()->{
|
|
|
+ UserContextUtils.setCurrentUser(currentUser);
|
|
|
+ //分布式锁
|
|
|
+ RLock lock = redissonClient.getLock(AddSyncContance.ORG_SYNC_KEY);
|
|
|
+ try {
|
|
|
+ boolean tryLock = lock.tryLock(0, 20, TimeUnit.MINUTES);
|
|
|
+ if (!tryLock) {
|
|
|
+ log.info("try lock fail");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ StopWatch watch = new StopWatch("orgSync");
|
|
|
+
|
|
|
+ watch.start("getOrgInfoFromRemote");
|
|
|
+ getOrgInfoFromRemote(1, subSyncConfig.getPageSize(), heads);
|
|
|
+ watch.stop();
|
|
|
+
|
|
|
+ watch.start("orgInfoSync");
|
|
|
+ orgInfoSync();
|
|
|
+ watch.stop();
|
|
|
+
|
|
|
+ //修改人员信息中保留了机构code但是机构id为空的字段
|
|
|
+ watch.start("updateOrgInfoInUser");
|
|
|
+ updateOrgInfoInUser();
|
|
|
+ watch.stop();
|
|
|
+
|
|
|
+ watch.start("reInitTrees");
|
|
|
+ setPathAndUpId();
|
|
|
+ orgTreeService.reInitTrees();
|
|
|
+ watch.stop();
|
|
|
+
|
|
|
+ log.info("orgSync total time:{}", watch.prettyPrint());
|
|
|
+ updateAddSyncRecord(AddSyncContance.ADD_SYNC_TYPE_ORG, true, null, null);
|
|
|
+ } catch (Exception e){
|
|
|
+ log.error("orgSync error.", e);
|
|
|
+ updateAddSyncRecord(AddSyncContance.ADD_SYNC_TYPE_ORG, false, null, null);
|
|
|
+ }finally {
|
|
|
+ //解锁
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateOrgInfoInUser() {
|
|
|
+ authUserInfoService.updateOrgInfoInUser();
|
|
|
+ authUserOrgRelService.updateOrgInfoInUser();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseStatus userAddSync() {
|
|
|
+ SecurityUser currentUser = UserContextUtils.getCurrentUser();
|
|
|
+ String idcard = null;
|
|
|
+ if(null != currentUser) {
|
|
|
+ idcard = currentUser.getIdcard();
|
|
|
+ }
|
|
|
+ List<Header> headers = getHeads(idcard);
|
|
|
+ Runnable r = getUserAddSyncTask(currentUser, headers);
|
|
|
Thread t = new Thread(r);
|
|
|
t.start();
|
|
|
return ResponseStatus.success();
|
|
|
}
|
|
|
|
|
|
+ private Runnable getUserAddSyncTask(SecurityUser currentUser, List<Header> headers) {
|
|
|
+ return ()->{
|
|
|
+ RLock lock = redissonClient.getLock(AddSyncContance.USER_SYNC_KEY);
|
|
|
+ UserContextUtils.setCurrentUser(currentUser);
|
|
|
+ try {
|
|
|
+ boolean tryLock = lock.tryLock(0, 5, TimeUnit.MINUTES);
|
|
|
+ if (!tryLock) {
|
|
|
+ log.info("try lock fail");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ StopWatch watch = new StopWatch("userAddSync");
|
|
|
+
|
|
|
+ watch.start("onUserInfoAddStart");
|
|
|
+ //获取上次同步成功的时间
|
|
|
+ Date syncStartTime = getSyncStartTime(AddSyncContance.ADD_SYNC_TYPE_USER);
|
|
|
+ if(null == syncStartTime) {
|
|
|
+ log.info("userAddSync syncStartTime is null");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //删除增量同步的数据
|
|
|
+ deleteUserAddInfo();
|
|
|
+ watch.stop();
|
|
|
+
|
|
|
+ //在同步前记录时间
|
|
|
+ //避免同步时用户中心更新的数据未被同步过来
|
|
|
+ //被同步的会在下次同步时再更新一次
|
|
|
+ Date updateTime = new Date();
|
|
|
+
|
|
|
+ watch.start("getUserInfoAddFromRemote");
|
|
|
+ //增量同步用户信息
|
|
|
+ String addUserInfoStatus = getAddUserInfo(subSyncConfig.getPageSize(), syncStartTime, headers);
|
|
|
+ watch.stop();
|
|
|
+ if(syncAllFail.equals(addUserInfoStatus)) {
|
|
|
+ log.info("getUserInfoAddFromRemote all failed");
|
|
|
+ updateAddSyncRecord(AddSyncContance.ADD_SYNC_TYPE_USER, false, null, addUserInfoStatus);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果有任意人员同步失败记录同步时间
|
|
|
+ if(addUserInfoStatus.contains(syncFailStatus) || addUserInfoStatus.contains(syncS_FStatus)) {
|
|
|
+ log.info("getUserInfoAddFromRemote something failed");
|
|
|
+ updateAddSyncRecord(AddSyncContance.ADD_SYNC_TYPE_USER, false, null, addUserInfoStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ //同步用户信息
|
|
|
+ watch.start("userInfoAddSync");
|
|
|
+ addUserInfoSync();
|
|
|
+ watch.stop();
|
|
|
+
|
|
|
+ //记录同步成功时间
|
|
|
+ updateAddSyncRecord(AddSyncContance.ADD_SYNC_TYPE_USER, true, updateTime, addUserInfoStatus);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("userAddSync error.", e);
|
|
|
+ //记录同步失败时间
|
|
|
+ updateAddSyncRecord(AddSyncContance.ADD_SYNC_TYPE_USER, false, null, syncAllFail);
|
|
|
+ }finally {
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addUserInfoSync() {
|
|
|
+ diffTypeAddUserSync(UserTypeEnum.POLICE);
|
|
|
+ diffTypeAddUserSync(UserTypeEnum.HELPER);
|
|
|
+ diffTypeAddUserSync(UserTypeEnum.EXTERNAL);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void diffTypeAddUserSync(UserTypeEnum userType) {
|
|
|
+ int currentPage = 0;
|
|
|
+ Searchable searchable = Searchable.newSearchable();
|
|
|
+ searchable.addSort(Sort.Direction.ASC, "userUpdateTime");
|
|
|
+ do {
|
|
|
+ searchable.setPage(currentPage, 1000);
|
|
|
+ Page<AuthUserAddOriginal> page = userAddOriginalService.pageSearch(searchable);
|
|
|
+ if(page.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ List<AuthUserAddOriginal> content = page.getContent();
|
|
|
+
|
|
|
+ //保存人员信息
|
|
|
+ //返回最终需要新增的或修改的人员信息
|
|
|
+ List<AuthUserInfo> userInfoList = saveAddUserInfo(content, userType);
|
|
|
+ Map<String, AuthUserInfo> idcardMap = userInfoList
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(AuthUserInfo::getIdcard, e -> e, (old, last) -> last));
|
|
|
+
|
|
|
+ //过滤删除人员的身份证号
|
|
|
+ List<String> delIdcards = content.stream()
|
|
|
+ .filter(e -> BooleanEnum.TRUE.value.equals(e.getUserDeleted()))
|
|
|
+ .map(AuthUserAddOriginal::getIdcard)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ //保存人员联系方式
|
|
|
+ saveAddContact(content, idcardMap, delIdcards);
|
|
|
+ //保存人员和机构关系
|
|
|
+ saveAddUserOrgRel(content, idcardMap, userType, delIdcards);
|
|
|
+ ++currentPage;
|
|
|
+ }while (true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存人员与机构的关系
|
|
|
+ * @param content 人员与机构关系json数据
|
|
|
+ * @param idcardMap 最终同步后存在的人员map key:idcard value:userInfo
|
|
|
+ * @param userType 人员类型枚举
|
|
|
+ * @param delIdcards 需要删除的人员的id
|
|
|
+ */
|
|
|
+ private void saveAddUserOrgRel(List<AuthUserAddOriginal> content, Map<String, AuthUserInfo> idcardMap,
|
|
|
+ UserTypeEnum userType, List<String> delIdcards) {
|
|
|
+ if(CollectionUtils.isEmpty(content)) {
|
|
|
+ log.info("saveAddUserOrgRel content is empty");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //先删除人员与机构的关系
|
|
|
+ //人员删除后添加userId发生变化,人员与机构的关系也需要重新添加
|
|
|
+ authUserOrgRelService.delByIdcards(delIdcards);
|
|
|
+ List<AuthUserAddOriginal> collect = content.stream()
|
|
|
+ .filter(e -> BooleanEnum.FALSE.value.equals(e.getUserDeleted())
|
|
|
+ && idcardMap.keySet().contains(e.getIdcard())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Boolean rel = subSyncConfig.getUserOrgRel();
|
|
|
+ if(null != rel && rel) {
|
|
|
+ saveUserOrgRelFromRemote(collect, idcardMap, userType);
|
|
|
+ }else {
|
|
|
+ saveUserOrgRelFromUserInFo(new ArrayList<>(idcardMap.values()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存人员联系方式
|
|
|
+ * @param idcardMap 最终同步后存在的人员map key:idcard value:userInfo
|
|
|
+ * @param delIdcards 需要删除的人员的id
|
|
|
+ * @param content 联系方式json数据
|
|
|
+ */
|
|
|
+ private void saveAddContact(List<AuthUserAddOriginal> content, Map<String, AuthUserInfo> idcardMap, List<String> delIdcards) {
|
|
|
+ if(CollectionUtils.isEmpty(content)) {
|
|
|
+ log.info("saveAddContact content is empty");
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //先删除人员联系方式
|
|
|
+ //人员删除后添加userId发生变化,联系方式也需要重新添加
|
|
|
+ authUserContact.delByIdcards(delIdcards);
|
|
|
+ List<AuthUserAddOriginal> collect = content.stream()
|
|
|
+ .filter(e -> BooleanEnum.FALSE.value.equals(e.getUserDeleted())
|
|
|
+ && idcardMap.keySet().contains(e.getIdcard())).collect(Collectors.toList());
|
|
|
+ //保存或修改联系方式
|
|
|
+ saveContact(collect, idcardMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<AuthUserInfo> saveAddUserInfo(List<AuthUserAddOriginal> content, UserTypeEnum userType) {
|
|
|
+ if(CollectionUtils.isEmpty(content)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<AuthUserInfo> userInfoList = content.stream().map(e -> {
|
|
|
+ String userDeleted = e.getUserDeleted();
|
|
|
+ String jsonData = e.getJsonData();
|
|
|
+ AuthUserInfo authUserInfo;
|
|
|
+ if (BooleanEnum.FALSE.value.equals(userDeleted)) {
|
|
|
+ authUserInfo = JSON.parseObject(jsonData, AuthUserInfo.class);
|
|
|
+ authUserInfo.setSource(CommonCons.USER_SOURCE_SYNC);
|
|
|
+ authUserInfo.setUserType(userType.getValue());
|
|
|
+ authUserInfo.setDeleted(BooleanEnum.FALSE.value);
|
|
|
+ } else {
|
|
|
+ authUserInfo = new AuthUserInfo();
|
|
|
+ authUserInfo.setIdcard(e.getIdcard());
|
|
|
+ authUserInfo.setDeleted(BooleanEnum.TRUE.value);
|
|
|
+ }
|
|
|
+ return authUserInfo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ //设置人员的机构字段信息
|
|
|
+ //警员根据职务排序,取职务序号小的为主机构
|
|
|
+ if(UserTypeEnum.POLICE.equals(userType)) {
|
|
|
+ setPoliceOrgCode(content, userType, userInfoList);
|
|
|
+ }
|
|
|
+ setUserOrgInfos(userType, userInfoList);
|
|
|
+ return authUserInfoService.batchSaveByIdcard(userInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String getAddUserInfo(Integer pageSize, Date syncStartTime, List<Header> headers) {
|
|
|
+ String policeStatus = getAddDiffTypeUserInfo(pageSize, syncStartTime, UserApiConstance.POLICE_SYNC_API, UserTypeEnum.POLICE, headers);
|
|
|
+ String helpStatus = getAddDiffTypeUserInfo(pageSize, syncStartTime, UserApiConstance.AUXILIRY_SYNC_API, UserTypeEnum.HELPER, headers);
|
|
|
+ String externalStatus = getAddDiffTypeUserInfo(pageSize, syncStartTime, UserApiConstance.EXTERNAL_SYNC_API, UserTypeEnum.EXTERNAL, headers);
|
|
|
+ String status = policeStatus + helpStatus + externalStatus;
|
|
|
+ log.info("getAddUserInfo status :{}",status);
|
|
|
+ return status;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getAddDiffTypeUserInfo(Integer pageSize, Date syncStartTime, String userInfoApi, UserTypeEnum userTypeEnum, List<Header> headers) {
|
|
|
+ int currentPage = 1;
|
|
|
+ Integer totalPage = null;
|
|
|
+ ApiSearchReq apiSearchReq = new ApiSearchReq();
|
|
|
+ //设置分页参数
|
|
|
+ ApiPageReq pageReq = new ApiPageReq();
|
|
|
+ pageReq.setSize(pageSize);
|
|
|
+ //设置同步时间
|
|
|
+ SearchParam searchParam = new SearchParam();
|
|
|
+ Map<String, SearchParam> filters = new HashMap<>();
|
|
|
+ filters.put("updateTime", searchParam);
|
|
|
+ searchParam.setOperator(SearchOperator.gt.name());
|
|
|
+ searchParam.setValue(syncStartTime);
|
|
|
+ apiSearchReq.setFilters(filters);
|
|
|
+ apiSearchReq.setPage(pageReq);
|
|
|
+ String url = Joiner.on("").join(authConfig.getUserCenterUrl(), userInfoApi);
|
|
|
+ logger.info("-------------getAddUserInfoFromRemote START-----------");
|
|
|
+ do {
|
|
|
+ logger.info("getAddUserInfoFromRemote currentPage:{}", currentPage);
|
|
|
+ pageReq.setFrom(currentPage);
|
|
|
+ String result = HttpUtil.postJSON(url, JSON.toJSONString(apiSearchReq), headers,null);
|
|
|
+ if (StringUtils.isBlank(result)) {
|
|
|
+ logger.info("result is null");
|
|
|
+ if(currentPage == 1) {
|
|
|
+ return syncFailStatus;
|
|
|
+ }else {
|
|
|
+ return syncS_FStatus;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //从结果解析用户数据保存到原始数据表
|
|
|
+ ApiResult apiResult = JSON.parseObject(result, ApiResult.class);
|
|
|
+ if(!ResultEnum.SUCCESS.getKey().equals(apiResult.getStatusCode())) {
|
|
|
+ logger.info("getAddUserInfoFromRemote ERROR:{}, PAGE NO:{}",apiResult.getMessage(), currentPage);
|
|
|
+ if(currentPage == 1) {
|
|
|
+ return syncFailStatus;
|
|
|
+ }else {
|
|
|
+ return syncS_FStatus;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject obj = (JSONObject) apiResult.getResult();
|
|
|
+ ApiResultPage<JSONObject> page = JSON.parseObject(obj.toJSONString(), new TypeReference<ApiResultPage<JSONObject>>(){});
|
|
|
+ //从结果解析总页数
|
|
|
+ totalPage = getTotalPage(pageSize, totalPage, page.getTotal().intValue());
|
|
|
+ //解析请求结果
|
|
|
+ saveAddUserOri(page, userTypeEnum);
|
|
|
+ } while (++currentPage <= totalPage);
|
|
|
+ logger.info("-------------getUserInfoFromRemote END-----------");
|
|
|
+ return syncSuccessStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveAddUserOri(ApiResultPage<JSONObject> page, UserTypeEnum userType) {
|
|
|
+ List<JSONObject> content = page.getContent();
|
|
|
+ List<AuthUserAddOriginal> originals = new ArrayList<>();
|
|
|
+ for (JSONObject json : content) {
|
|
|
+ AuthUserAddOriginal userOri = new AuthUserAddOriginal();
|
|
|
+ String idcard = json.getString("idcard");
|
|
|
+ String userDeleted = json.getString("deleted");
|
|
|
+ Date updateTime = json.getDate("updateTime");
|
|
|
+ userOri.setIdcard(idcard);
|
|
|
+ userOri.setUserType(userType.getValue());
|
|
|
+ userOri.setUserDeleted(userDeleted);
|
|
|
+ userOri.setUserUpdateTime(updateTime);
|
|
|
+ if(BooleanEnum.TRUE.value.equals(userDeleted)) {
|
|
|
+ originals.add(userOri);
|
|
|
+ continue ;
|
|
|
+ }
|
|
|
+ setJSONData(userType, json, userOri);
|
|
|
+ originals.add(userOri);
|
|
|
+ }
|
|
|
+ //过程数据保存
|
|
|
+ userAddOriginalService.batchSave(originals);
|
|
|
+ }
|
|
|
+
|
|
|
+ private <T extends AuthUserOriginalBase> void setJSONData(UserTypeEnum userType, JSONObject json, T userOri) {
|
|
|
+ //保存联系方式json
|
|
|
+ JSONObject userContact = json.getJSONObject("userContact");
|
|
|
+ if(null != userContact && !userContact.isEmpty()) {
|
|
|
+ userOri.setContactData(userContact.toJSONString());
|
|
|
+ }
|
|
|
+ json.remove("userContact");
|
|
|
+ //保存人员和机构关系json
|
|
|
+ if (userType.equals(UserTypeEnum.POLICE)) {
|
|
|
+ JSONArray jsonArray = json.getJSONArray("postInfos");
|
|
|
+ if (CollectionUtils.isNotEmpty(jsonArray)) {
|
|
|
+ userOri.setOrgRelData(jsonArray.toJSONString());
|
|
|
+ json.remove("postInfos");
|
|
|
+ }
|
|
|
+ } else if (userType.equals(UserTypeEnum.EXTERNAL)) {
|
|
|
+ String projectCodes = json.getString("projectCode");
|
|
|
+ if(StringUtils.isNotBlank(projectCodes)) {
|
|
|
+ userOri.setOrgRelData(projectCodes);
|
|
|
+ }
|
|
|
+ json.remove("projectCode");
|
|
|
+ }
|
|
|
+ //保存人员数据json
|
|
|
+ userOri.setJsonData(json.toJSONString());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteUserAddInfo() {
|
|
|
+ userAddOriginalService.deleteAll();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date getSyncStartTime(String type) {
|
|
|
+ AddSyncRecord record = addSyncRecordService.getRecordByType(type);
|
|
|
+ Date syncStartTime = null;
|
|
|
+ if(null != record) {
|
|
|
+ syncStartTime = record.getSuccessTime();
|
|
|
+ }
|
|
|
+ return syncStartTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseStatus orgAddSync() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 同步完成后设置机构的path和upGovId
|
|
|
*/
|
|
@@ -595,16 +1024,16 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
* 从用户中心获取机构数据
|
|
|
* @param currentPage
|
|
|
* @param pageSize
|
|
|
+ * @param heads
|
|
|
*/
|
|
|
- public void getOrgInfoFromRemote(int currentPage, Integer pageSize) {
|
|
|
+ public void getOrgInfoFromRemote(int currentPage, Integer pageSize, List<Header> heads) {
|
|
|
Date now = new Date();
|
|
|
Integer totalPage = null;
|
|
|
- List<Header> headers = getHeads();
|
|
|
ApiSearchReq apiSearchReq = new ApiSearchReq();
|
|
|
- HashMap<String, SearchParam> filters = new HashMap<>();
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setOperator(SearchOperator.eq.name());
|
|
|
searchParam.setValue(BooleanEnum.FALSE.value);
|
|
|
+ Map<String, SearchParam> filters = new HashMap<>();
|
|
|
filters.put("deleted", searchParam);
|
|
|
apiSearchReq.setFilters(filters);
|
|
|
ApiPageReq pageReq = new ApiPageReq();
|
|
@@ -614,7 +1043,7 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
logger.info("-------------getOrgInfoFromRemote START-----------");
|
|
|
do {
|
|
|
pageReq.setFrom(currentPage);
|
|
|
- String result = HttpUtil.postJSON(url, JSON.toJSONString(apiSearchReq), headers,null);
|
|
|
+ String result = HttpUtil.postJSON(url, JSON.toJSONString(apiSearchReq), heads,null);
|
|
|
if(StringUtils.isBlank(result)) {
|
|
|
logger.info("result is null");
|
|
|
break;
|