You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
4.7 KiB
109 lines
4.7 KiB
3 years ago
|
package com.fr.plugin.utils;
|
||
|
|
||
|
import com.fr.general.ComparatorUtils;
|
||
|
import com.fr.json.JSONArray;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.plugin.beans.MyDepBean;
|
||
|
import com.fr.plugin.beans.MyUserBean;
|
||
|
import com.fr.plugin.config.YituanPri;
|
||
|
import com.fr.plugin.yt.MyCorpManager;
|
||
|
import com.fr.plugin.yt.MyUserSyncManager;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
import com.fr.third.org.apache.commons.lang3.time.DateFormatUtils;
|
||
|
|
||
|
import java.util.Date;
|
||
|
|
||
|
public class SyncThread implements Runnable {
|
||
|
private String operation;
|
||
|
|
||
|
public SyncThread(String operation) {
|
||
|
this.operation = operation;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void run() {
|
||
|
MyUserSyncManager corpManager = MyUserSyncManager.getInstance();
|
||
|
if (ComparatorUtils.equalsIgnoreCase("user", operation)) {
|
||
|
FineLoggerFactory.getLogger().info("增量同步用户开始");
|
||
|
String lastSyncUserTime = YituanPri.getInstance().getLastSyncUserTime();//格式:“2014-08-02 01:40:38”
|
||
|
String format = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
|
||
|
if(StringUtils.isBlank(lastSyncUserTime)){
|
||
|
lastSyncUserTime=format;
|
||
|
}
|
||
|
YituanPri.getInstance().setLastSyncUserTime(format);
|
||
|
JSONArray userLastSyn = WebUtils.getUserLastSyn(0,lastSyncUserTime);
|
||
|
int count = 0;
|
||
|
while (userLastSyn != null && !userLastSyn.isEmpty()) {
|
||
|
if (userLastSyn.isEmpty()) {
|
||
|
break;
|
||
|
}
|
||
|
int size = userLastSyn.size();
|
||
|
for (int i = 0; i < size; i++) {
|
||
|
JSONObject userJson = userLastSyn.getJSONObject(i);
|
||
|
int status = userJson.getInt("status");
|
||
|
String id = userJson.getString("openId");
|
||
|
String photoUrl = userJson.getString("photoUrl");
|
||
|
String name = userJson.getString("name");
|
||
|
String jobNo = userJson.getString("jobNo");
|
||
|
String phone = userJson.getString("phone");
|
||
|
String depName = userJson.getString("department");
|
||
|
MyUserBean entity = new MyUserBean();
|
||
|
entity.setPhone(phone);
|
||
|
entity.setPhotoUrl(photoUrl);
|
||
|
entity.setStatus(status);
|
||
|
entity.setOpenId(id);
|
||
|
entity.setName(name);
|
||
|
entity.setDepartment(depName);
|
||
|
entity.setJobNo(jobNo);
|
||
|
try {
|
||
|
corpManager.saveOrUpdateUser(entity);
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
count++;
|
||
|
}
|
||
|
FineLoggerFactory.getLogger().info("增量同步用户count:{},当前页面:{} 条", count,size);
|
||
|
userLastSyn = WebUtils.getUserLastSyn(count,lastSyncUserTime);
|
||
|
}
|
||
|
FineLoggerFactory.getLogger().info("增量同步用户完成 修改了:{}个用户信息", count);
|
||
|
} else {
|
||
|
FineLoggerFactory.getLogger().info("增量同步部门开始");
|
||
|
JSONArray depLastSyn = WebUtils.getDepLastSyn();
|
||
|
MyCorpManager myCorpManager = MyCorpManager.getInstance();
|
||
|
int count = 0;
|
||
|
if (depLastSyn != null && !depLastSyn.isEmpty()) {
|
||
|
int size = depLastSyn.size();
|
||
|
for (int i = 0; i < size; i++) {
|
||
|
JSONObject depJson = depLastSyn.getJSONObject(i);
|
||
|
String id = depJson.getString("id");
|
||
|
String pid = depJson.getString("parentId");
|
||
|
String name = depJson.getString("name");
|
||
|
String depName = depJson.getString("department");
|
||
|
int order = depJson.getInt("weights");
|
||
|
String opera = depJson.getString("");
|
||
|
MyDepBean depBean = new MyDepBean();
|
||
|
depBean.setDepName(depName);
|
||
|
depBean.setId(id);
|
||
|
depBean.setOrder(order);
|
||
|
depBean.setParentId(pid);
|
||
|
depBean.setName(name);
|
||
|
try {
|
||
|
if(ComparatorUtils.equalsIgnoreCase(opera,"3")){
|
||
|
myCorpManager.removeDep(depBean);
|
||
|
}else{
|
||
|
myCorpManager.saveOrUpdateDep(depBean);
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
count++;
|
||
|
}
|
||
|
}
|
||
|
FineLoggerFactory.getLogger().info("增量同步部门完成 修改了:{}个部门信息", count);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|