bug: 修改人员同步定时任务,去掉时间戳
This commit is contained in:
@@ -49,7 +49,7 @@ public class ScheduledSync {
|
||||
if(isNotScheduled){
|
||||
log.info("======================================开始同步基础数据========================================");
|
||||
iDataSyncService.orgDataSync2(); //时间短
|
||||
iDataSyncService.dataSync2(System.currentTimeMillis() / 1000); //时间长
|
||||
iDataSyncService.dataSync3(); //时间长
|
||||
log.info("======================================结束同步基础数据========================================");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ public interface IDataSyncService {
|
||||
public String dataSync();
|
||||
|
||||
public String dataSync2(Long chuo);
|
||||
|
||||
public String dataSync3();
|
||||
// 定时增量同步
|
||||
public String orgDataSync();
|
||||
// 手动全量同步
|
||||
|
||||
+109
@@ -469,6 +469,115 @@ public class DataSyncServiceImpl implements IDataSyncService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同步人员数据,去掉时间戳 版本
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = {RuntimeException.class,Exception.class})
|
||||
public String dataSync3(){
|
||||
try{
|
||||
SyncUserService syncUserService = new SyncUserService();
|
||||
List<String> res = syncUserService.syncFotonUser3();
|
||||
if(res!=null && !res.isEmpty()){
|
||||
res.forEach(each -> logger.info("同步人员数据:"+each));
|
||||
//存放岗位信息
|
||||
Map<String, String> positionMap = new HashMap<>();
|
||||
TsPosition position = new TsPosition();
|
||||
position.setCurrent(1);
|
||||
position.setPageSize(100000);
|
||||
IPage<TsPosition> iPage = tsPositionService.getPosition(position);
|
||||
List<TsPosition> positions=iPage.getRecords();
|
||||
if (!positions.isEmpty()) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
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){
|
||||
logger.error(e.getMessage(),e);
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
}
|
||||
return "1";
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 增量同步部门数据
|
||||
@Transactional(rollbackFor = {RuntimeException.class,Exception.class})
|
||||
public String orgDataSync(){
|
||||
|
||||
@@ -114,6 +114,56 @@ public class SyncUserService {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉时间戳,其他与syncFotonUser2相同
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<String> syncFotonUser3()throws Exception{
|
||||
String appuser = "app_slrs";
|
||||
String appkey = "Fxi5LHbI5yGbQQDpVp86GcCdXeC5Bjfe";
|
||||
AuthUtils util = new AuthUtils(appuser, appkey, null);
|
||||
|
||||
List<String> json=new ArrayList<>();
|
||||
byte[] cookie = null;
|
||||
do {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("cookie", Base64.encodeBase64String(cookie));
|
||||
params.put("timestamp", "");
|
||||
|
||||
// 用户参数
|
||||
params.put("filter", "(userid=*)");
|
||||
params.put("basedn", "ou=People,o=foton.com.cn,o=isp");
|
||||
log.info("RequestBody:" + params.toString());
|
||||
// 用户测试
|
||||
String rs = util.getResponseFromServer("http://idmsync.foton.com.cn/rest/users/getUserList", params);
|
||||
log.info("远程调用同步的员工数据:"+rs);
|
||||
JSONObject responseStr = JSON.parseObject(rs);
|
||||
if(responseStr.containsKey("status") && responseStr.getBoolean("status")){
|
||||
json.add(rs);
|
||||
}
|
||||
if (responseStr.containsKey("cookie")) {
|
||||
try {
|
||||
JSONArray entries = responseStr.getJSONArray("cookie");
|
||||
if(entries==null){
|
||||
break;
|
||||
}
|
||||
cookie = new byte[entries.size()];
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
cookie[i] = (byte) entries.getByte(i);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
if (e.getMessage().contains("is not a JSONArray")) {
|
||||
cookie = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} while (cookie != null);
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<String> syncFotonOrg()throws Exception{
|
||||
|
||||
Reference in New Issue
Block a user