|
@@ -3,7 +3,6 @@ package com.cnd3b.service;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.oss.OSS;
|
|
import com.aliyun.oss.OSS;
|
|
|
-import com.aliyun.oss.OSSClient;
|
|
|
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
|
import com.aliyun.oss.model.*;
|
|
import com.aliyun.oss.model.*;
|
|
|
import com.cnd3b.common.BaseClass;
|
|
import com.cnd3b.common.BaseClass;
|
|
@@ -13,9 +12,10 @@ import com.cnd3b.common.data.SQLFactory;
|
|
|
import com.cnd3b.common.data.db.DBConnect;
|
|
import com.cnd3b.common.data.db.DBConnect;
|
|
|
import com.cnd3b.utility.WebRequest;
|
|
import com.cnd3b.utility.WebRequest;
|
|
|
import com.cnd3b.utility.wechatdock.WechatDock_Enterprise;
|
|
import com.cnd3b.utility.wechatdock.WechatDock_Enterprise;
|
|
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
-import java.util.zip.ZipEntry;
|
|
|
|
|
|
|
|
|
|
import static com.cnd3b.utility.aliyun.oss.AliyunOSSUtil.*;
|
|
import static com.cnd3b.utility.aliyun.oss.AliyunOSSUtil.*;
|
|
|
|
|
|
|
@@ -23,20 +23,37 @@ import static com.cnd3b.utility.aliyun.oss.AliyunOSSUtil.*;
|
|
|
public class GetWechatData extends BaseClass implements Runnable {
|
|
public class GetWechatData extends BaseClass implements Runnable {
|
|
|
|
|
|
|
|
public DBConnect dbConnect = null;
|
|
public DBConnect dbConnect = null;
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 内部职位 type=2
|
|
|
|
|
+ */
|
|
|
|
|
+ public String[] positionSeller;
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 经销商职位 type=1
|
|
|
|
|
+ */
|
|
|
|
|
+ public String[] positionAgent;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
this.dbConnect = new DBConnect();
|
|
this.dbConnect = new DBConnect();
|
|
|
-// if (new SQLiteJDBC().checkServicesUsed("GetWechatData", false)) {
|
|
|
|
|
try {
|
|
try {
|
|
|
- System.err.println("GetWechatData Service start...");
|
|
|
|
|
|
|
+ positionSeller = getPosition(2);
|
|
|
|
|
+ positionAgent = getPosition(1);
|
|
|
|
|
+ System.err.println(positionSeller.length);
|
|
|
|
|
+ System.err.println(positionAgent.length);
|
|
|
|
|
+ System.err.println("开始拉取微信数据......");
|
|
|
getDepartmentList();
|
|
getDepartmentList();
|
|
|
clearCache();
|
|
clearCache();
|
|
|
|
|
+ System.err.println("结束拉取微信数据......");
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String[] getPosition(int ftype) {
|
|
|
|
|
+ String sql = "SELECT fname from tposition WHERE ftype ='" + ftype + "'";
|
|
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sql);
|
|
|
|
|
+ return rows.toArray("fname");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -59,11 +76,8 @@ public class GetWechatData extends BaseClass implements Runnable {
|
|
|
if (!isLatestWeek(objectSummary.getLastModified(), new Date())) {
|
|
if (!isLatestWeek(objectSummary.getLastModified(), new Date())) {
|
|
|
keysList.add(key);
|
|
keysList.add(key);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- System.err.println("清除数量:" + keysList.size());
|
|
|
|
|
if (keysList.size() > 0) {
|
|
if (keysList.size() > 0) {
|
|
|
DeleteObjectsRequest request = new DeleteObjectsRequest(BUCKE_NAME_1);
|
|
DeleteObjectsRequest request = new DeleteObjectsRequest(BUCKE_NAME_1);
|
|
|
request.setKeys(keysList);
|
|
request.setKeys(keysList);
|
|
@@ -73,6 +87,9 @@ public class GetWechatData extends BaseClass implements Runnable {
|
|
|
|
|
|
|
|
client.shutdown();
|
|
client.shutdown();
|
|
|
keysList.clear();
|
|
keysList.clear();
|
|
|
|
|
+ String sql = " delete from TDATALOG where datediff(day,changedate,getdate()) > 3";
|
|
|
|
|
+ dbConnect.runSqlUpdate(sql);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -85,10 +102,14 @@ public class GetWechatData extends BaseClass implements Runnable {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public boolean isLatestWeek(Date addtime, Date now) {
|
|
public boolean isLatestWeek(Date addtime, Date now) {
|
|
|
- Calendar calendar = Calendar.getInstance(); //得到日历
|
|
|
|
|
- calendar.setTime(now);//把当前时间赋给日历
|
|
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, -7); //设置为7天前
|
|
|
|
|
- Date before7days = calendar.getTime(); //得到7天前的时间
|
|
|
|
|
|
|
+ //得到日历
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ //把当前时间赋给日历
|
|
|
|
|
+ calendar.setTime(now);
|
|
|
|
|
+ //设置为7天前
|
|
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -7);
|
|
|
|
|
+ //得到7天前的时间
|
|
|
|
|
+ Date before7days = calendar.getTime();
|
|
|
if (before7days.getTime() < addtime.getTime()) {
|
|
if (before7days.getTime() < addtime.getTime()) {
|
|
|
return true;
|
|
return true;
|
|
|
} else {
|
|
} else {
|
|
@@ -98,119 +119,7 @@ public class GetWechatData extends BaseClass implements Runnable {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-// public void updateUser(JSONArray userArray) throws P2Exception {
|
|
|
|
|
-// ArrayList<String> ids = new ArrayList<>();
|
|
|
|
|
-// for (Object obj : userArray) {
|
|
|
|
|
-// JSONObject jsonObject = (JSONObject) obj;
|
|
|
|
|
-// String wechat_userid = jsonObject.getString("userid");
|
|
|
|
|
-//
|
|
|
|
|
-// ids.add(wechat_userid);
|
|
|
|
|
-//
|
|
|
|
|
-// String WECHAT_NAME = jsonObject.getString("name");
|
|
|
|
|
-// String wechat_open_userid = jsonObject.getString("open_userid");
|
|
|
|
|
-// String wechat_mobile = jsonObject.getString("mobile");
|
|
|
|
|
-// String wechat_position = jsonObject.getString("position");
|
|
|
|
|
-// int wechat_depid = jsonObject.getIntValue("main_department");
|
|
|
|
|
-//
|
|
|
|
|
-// String sql = "SELECT wechat_depname FROM tdepartment WHERE wechat_depid='" + wechat_depid + "'";
|
|
|
|
|
-// Rows rows = dbConnect.runSqlQuery(sql);
|
|
|
|
|
-// String fusertype = "";
|
|
|
|
|
-// String wechat_depname = "";
|
|
|
|
|
-// if (!rows.isEmpty()) {
|
|
|
|
|
-// wechat_depname = rows.get(0).getString("wechat_depname");
|
|
|
|
|
-// }
|
|
|
|
|
-// if (wechat_depname.equals(parameter.depname)) {
|
|
|
|
|
-// fusertype = "经销商";
|
|
|
|
|
-//
|
|
|
|
|
-// } else {
|
|
|
|
|
-// fusertype = "业务员";
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-// PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tuser", "wechat_userid = '" + wechat_userid + "'");
|
|
|
|
|
-// if (paoSetRemote.isEmpty()) {
|
|
|
|
|
-// PaoRemote paoRemote = paoSetRemote.addAtEnd();
|
|
|
|
|
-// paoRemote.setValue("siteid", parameter.defaultsiteid, 11L);
|
|
|
|
|
-// paoRemote.setValue("wechat_userid", wechat_userid, 11L);
|
|
|
|
|
-// paoRemote.setValue("WECHAT_NAME", WECHAT_NAME, 11L);
|
|
|
|
|
-// paoRemote.setValue("wechat_open_userid", wechat_open_userid, 11L);
|
|
|
|
|
-// paoRemote.setValue("wechat_mobile", wechat_mobile, 11L);
|
|
|
|
|
-// paoRemote.setValue("wechat_position", wechat_position, 11L);
|
|
|
|
|
-// paoRemote.setValue("wechat_depid", wechat_depid, 11L);
|
|
|
|
|
-// paoRemote.setValue("fusertype", fusertype, 11L);
|
|
|
|
|
-// paoSetRemote.save();
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-// public void updateTagents(int id) throws P2Exception {
|
|
|
|
|
-// String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + WechatDock_Enterprise.getAccessToken() + "&id=" + id;
|
|
|
|
|
-// String response = new WebRequest().doGet(url);
|
|
|
|
|
-// JSONObject object = JSONObject.parseObject(response);
|
|
|
|
|
-// JSONArray array = object.getJSONArray("department");
|
|
|
|
|
-// DBConnect dbConnect = new DBConnect();
|
|
|
|
|
-// ArrayList<String> ids = new ArrayList<>();
|
|
|
|
|
-// for (Object obj : array) {
|
|
|
|
|
-// JSONObject jsonObject = (JSONObject) obj;
|
|
|
|
|
-//
|
|
|
|
|
-// int wechat_depid = jsonObject.getIntValue("id");
|
|
|
|
|
-// if (wechat_depid != id) {
|
|
|
|
|
-// ids.add(wechat_depid + "");
|
|
|
|
|
-// //获取管理员信息
|
|
|
|
|
-// JSONArray department_leader = jsonObject.getJSONArray("department_leader");
|
|
|
|
|
-// String fcontact = "";
|
|
|
|
|
-// String fphonenumber = "";
|
|
|
|
|
-// String faddress = "";
|
|
|
|
|
-// if (department_leader.size() > 0) {
|
|
|
|
|
-// String url2 = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=" + WechatDock_Enterprise.getAccessToken() + "&userid=" + department_leader.get(0);
|
|
|
|
|
-// String responseUser = new WebRequest().doGet(url2);
|
|
|
|
|
-// JSONObject objectUser = JSONObject.parseObject(responseUser);
|
|
|
|
|
-// fcontact = objectUser.getString("name");
|
|
|
|
|
-// fphonenumber = objectUser.getString("mobile");
|
|
|
|
|
-// faddress = objectUser.getString("address");
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// //保存经销商档案
|
|
|
|
|
-// PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tagents", "wechat_depid = '" + wechat_depid + "'");
|
|
|
|
|
-// if (paoSetRemote.isEmpty()) {
|
|
|
|
|
-// PaoRemote paoRemote = paoSetRemote.addAtEnd();
|
|
|
|
|
-// paoRemote.setValue("wechat_depid", wechat_depid, 11L);
|
|
|
|
|
-// paoRemote.setValue("fagentname", jsonObject.getString("name"), 11L);
|
|
|
|
|
-// paoRemote.setValue("fcontact", fcontact, 11L);
|
|
|
|
|
-// paoRemote.setValue("fphonenumber", fphonenumber, 11L);
|
|
|
|
|
-// paoRemote.setValue("faddress", faddress, 11L);
|
|
|
|
|
-// paoSetRemote.save();
|
|
|
|
|
-// }
|
|
|
|
|
-// else {
|
|
|
|
|
-// PaoRemote paoRemote = paoSetRemote.getPao(0);
|
|
|
|
|
-// paoRemote.setValue("wechat_depid", wechat_depid, 11L);
|
|
|
|
|
-// paoRemote.setValue("fagentname", jsonObject.getString("name"), 11L);
|
|
|
|
|
-// paoRemote.setValue("fcontact", fcontact, 11L);
|
|
|
|
|
-// paoRemote.setValue("fphonenumber", fphonenumber, 11L);
|
|
|
|
|
-// paoRemote.setValue("faddress", faddress, 11L);
|
|
|
|
|
-// paoSetRemote.save();
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// SQLFactory sqlFactory = new SQLFactory(this, "删除经销商");
|
|
|
|
|
-// sqlFactory.addParameter_in("ids", ids);
|
|
|
|
|
-// dbConnect.runSqlUpdate(sqlFactory.getSQL());
|
|
|
|
|
-// }
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 内部职位
|
|
|
|
|
- */
|
|
|
|
|
- public static String[] positionSeller = {"董事局主席", "董事长兼总裁", "董事长助理", "总裁助理", "营销总经理", "营销副总经理", "总监", "副总监", "总监助理", "部长", "主任", "大区总经理", "大区副总经理", "大区总助理", "片区经理", "储备人才"};
|
|
|
|
|
- /**
|
|
|
|
|
- * 经销商职位
|
|
|
|
|
- */
|
|
|
|
|
- public static String[] positionAgent = {"经销商管理员", "销售主管", "店长", "销售经理", "家居顾问", "售后经理", "安装技师"};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<String> list_wechat_userid = new ArrayList<>();
|
|
private ArrayList<String> list_wechat_userid = new ArrayList<>();
|
|
@@ -221,68 +130,32 @@ public class GetWechatData extends BaseClass implements Runnable {
|
|
|
*
|
|
*
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public JSONArray getDepartmentList() {
|
|
|
|
|
|
|
+ public void getDepartmentList() {
|
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + WechatDock_Enterprise.getAccessToken();
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + WechatDock_Enterprise.getAccessToken();
|
|
|
- System.err.println(url);
|
|
|
|
|
- String response = new WebRequest().doGet(url);
|
|
|
|
|
- JSONObject object = JSONObject.parseObject(response);
|
|
|
|
|
- JSONArray array = object.getJSONArray("department");
|
|
|
|
|
- System.err.println("部门数量:" + array.size());
|
|
|
|
|
|
|
+ JSONArray array = getResponse(url, "department");
|
|
|
|
|
+// System.err.println("微信部门数量:" + array.size());
|
|
|
if (array.size() > 0) {
|
|
if (array.size() > 0) {
|
|
|
- updateDepartment(array);
|
|
|
|
|
|
|
+ ArrayList<String> idsList = new ArrayList<>();
|
|
|
|
|
+ for (Object obj : array) {
|
|
|
|
|
+ JSONObject jsonObject = (JSONObject) obj;
|
|
|
|
|
+ int wechat_depid = jsonObject.getIntValue("id");
|
|
|
|
|
+ idsList.add(String.valueOf(wechat_depid));
|
|
|
|
|
+ //新增或更新微信部门
|
|
|
|
|
+ addDepartment(jsonObject);
|
|
|
|
|
+ }
|
|
|
|
|
+ //删除不存在的微信部门
|
|
|
|
|
+ deleteDepartments(idsList);
|
|
|
|
|
+ getDepartmentUsers(3, 1, positionSeller, "业务员");
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
WechatDock_Enterprise.getAccessToken2();
|
|
WechatDock_Enterprise.getAccessToken2();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- return object.getJSONArray("department");
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 更新数据到部门表
|
|
|
|
|
- *
|
|
|
|
|
- * @param array
|
|
|
|
|
- */
|
|
|
|
|
- public void updateDepartment(JSONArray array) {
|
|
|
|
|
-// ArrayList<String> listSql = new ArrayList<>();
|
|
|
|
|
- for (Object obj : array) {
|
|
|
|
|
- JSONObject jsonObject = (JSONObject) obj;
|
|
|
|
|
- int wechat_depid = jsonObject.getIntValue("id");
|
|
|
|
|
- int wechat_parendeptid = jsonObject.getIntValue("parentid");
|
|
|
|
|
- String wechat_depname = jsonObject.getString("name");
|
|
|
|
|
- SQLFactory sqlFactory = new SQLFactory(this, "插入微信部门");
|
|
|
|
|
- sqlFactory.addParameter("tdepartmentid", createTableID("tdepartment", "tdepartmentid"));
|
|
|
|
|
- sqlFactory.addParameter("wechat_depid", wechat_depid);
|
|
|
|
|
- sqlFactory.addParameter("wechat_parendeptid", wechat_parendeptid);
|
|
|
|
|
- sqlFactory.addParameter("wechat_depname", wechat_depname);
|
|
|
|
|
-// System.err.println("插入微信部门");
|
|
|
|
|
- dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
-// listSql.add(sqlFactory.getSQL());
|
|
|
|
|
-// if (listSql.size() > 100) {
|
|
|
|
|
-
|
|
|
|
|
-// dbConnect.runSqlUpdate(listSql);
|
|
|
|
|
-// listSql.clear();
|
|
|
|
|
-// try {
|
|
|
|
|
-// Thread.sleep(1000);
|
|
|
|
|
-// } catch (InterruptedException e) {
|
|
|
|
|
-// e.printStackTrace();
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-// dbConnect.runSqlUpdate(listSql);
|
|
|
|
|
-
|
|
|
|
|
-// try {
|
|
|
|
|
-// Thread.sleep(1000);
|
|
|
|
|
-// } catch (InterruptedException e) {
|
|
|
|
|
-// e.printStackTrace();
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
- getDepartmentUsers(3, 1, positionSeller, "业务员");
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //存放用户
|
|
|
|
|
+ ArrayList<String> idsList_user = new ArrayList<>();
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取企业微信部门成员列表
|
|
* 获取企业微信部门成员列表
|
|
@@ -291,113 +164,106 @@ public class GetWechatData extends BaseClass implements Runnable {
|
|
|
*/
|
|
*/
|
|
|
public JSONArray getDepartmentUsers(int id, int fetch_child, String[] strArray, String fusertype) {
|
|
public JSONArray getDepartmentUsers(int id, int fetch_child, String[] strArray, String fusertype) {
|
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=" + WechatDock_Enterprise.getAccessToken() + "&department_id=" + id + "&fetch_child=" + fetch_child;
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=" + WechatDock_Enterprise.getAccessToken() + "&department_id=" + id + "&fetch_child=" + fetch_child;
|
|
|
- String response = new WebRequest().doGet(url);
|
|
|
|
|
- JSONObject object = JSONObject.parseObject(response);
|
|
|
|
|
- JSONArray array = object.getJSONArray("userlist");
|
|
|
|
|
-// ArrayList<String> listSql = new ArrayList<>();
|
|
|
|
|
|
|
+ JSONArray array = getResponse(url, "userlist");
|
|
|
|
|
+ List<String> list = Arrays.asList(strArray);
|
|
|
for (Object obj : array) {
|
|
for (Object obj : array) {
|
|
|
JSONObject jsonObject = (JSONObject) obj;
|
|
JSONObject jsonObject = (JSONObject) obj;
|
|
|
String position = jsonObject.getString("position");
|
|
String position = jsonObject.getString("position");
|
|
|
- String name = jsonObject.getString("name");
|
|
|
|
|
String userid = jsonObject.getString("userid");
|
|
String userid = jsonObject.getString("userid");
|
|
|
int main_department = jsonObject.getIntValue("main_department");
|
|
int main_department = jsonObject.getIntValue("main_department");
|
|
|
- String mobile = jsonObject.getString("mobile");
|
|
|
|
|
- String open_userid = jsonObject.getString("open_userid");
|
|
|
|
|
- List<String> list = Arrays.asList(strArray);
|
|
|
|
|
if (list.contains(position)) {
|
|
if (list.contains(position)) {
|
|
|
list_wechat_userid.add(userid);
|
|
list_wechat_userid.add(userid);
|
|
|
- SQLFactory sqlFactory = new SQLFactory(this, "插入微信成员");
|
|
|
|
|
- sqlFactory.addParameter("tuserid", createTableID("tuser", "tuserid"));
|
|
|
|
|
- sqlFactory.addParameter("wechat_depid", main_department);
|
|
|
|
|
- sqlFactory.addParameter("wechat_userid", userid);
|
|
|
|
|
- sqlFactory.addParameter("wechat_name", name);
|
|
|
|
|
- sqlFactory.addParameter("wechat_open_userid", open_userid);
|
|
|
|
|
- sqlFactory.addParameter("wechat_mobile", mobile);
|
|
|
|
|
- sqlFactory.addParameter("wechat_position", position);
|
|
|
|
|
- sqlFactory.addParameter("fusertype", fusertype);
|
|
|
|
|
-// listSql.add(sqlFactory.getSQL());
|
|
|
|
|
- dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
-// System.err.println("业务员...");
|
|
|
|
|
-// if (listSql.size() > 100) {
|
|
|
|
|
-//
|
|
|
|
|
-// dbConnect.runSqlUpdate(listSql);
|
|
|
|
|
-// listSql.clear();
|
|
|
|
|
-// try {
|
|
|
|
|
-// Thread.sleep(1000);
|
|
|
|
|
-// } catch (InterruptedException e) {
|
|
|
|
|
-// e.printStackTrace();
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ addUser(jsonObject, main_department, fusertype);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// dbConnect.runSqlUpdate(listSql);
|
|
|
|
|
-
|
|
|
|
|
getDepartmentUsers2(144, 1, positionAgent, "经销商");
|
|
getDepartmentUsers2(144, 1, positionAgent, "经销商");
|
|
|
|
|
|
|
|
return array;
|
|
return array;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 获取企业微信部门成员列表
|
|
|
|
|
|
|
+ * 获取企业微信部门成员列表(经销商)
|
|
|
*
|
|
*
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public JSONArray getDepartmentUsers2(int id, int fetch_child, String[] strArray, String fusertype) {
|
|
public JSONArray getDepartmentUsers2(int id, int fetch_child, String[] strArray, String fusertype) {
|
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=" + WechatDock_Enterprise.getAccessToken() + "&department_id=" + id + "&fetch_child=" + fetch_child;
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=" + WechatDock_Enterprise.getAccessToken() + "&department_id=" + id + "&fetch_child=" + fetch_child;
|
|
|
- String response = new WebRequest().doGet(url);
|
|
|
|
|
- JSONObject object = JSONObject.parseObject(response);
|
|
|
|
|
- JSONArray array = object.getJSONArray("userlist");
|
|
|
|
|
-// ArrayList<String> listSql = new ArrayList<>();
|
|
|
|
|
|
|
+ JSONArray array = getResponse(url, "userlist");
|
|
|
|
|
+ //存放要更新的经销商档案
|
|
|
|
|
+ JSONArray tempArray = new JSONArray();
|
|
|
|
|
+ List<String> list = Arrays.asList(strArray);
|
|
|
|
|
+ //存放部门id
|
|
|
|
|
+ List<String> listDepids = new ArrayList<>();
|
|
|
|
|
+ for (Object obj : array) {
|
|
|
|
|
+ JSONObject jsonObject = (JSONObject) obj;
|
|
|
|
|
+ int main_department = jsonObject.getIntValue("main_department");
|
|
|
|
|
+ listDepids.add(String.valueOf(main_department));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for (Object obj : array) {
|
|
for (Object obj : array) {
|
|
|
JSONObject jsonObject = (JSONObject) obj;
|
|
JSONObject jsonObject = (JSONObject) obj;
|
|
|
String position = jsonObject.getString("position");
|
|
String position = jsonObject.getString("position");
|
|
|
- String name = jsonObject.getString("name");
|
|
|
|
|
String userid = jsonObject.getString("userid");
|
|
String userid = jsonObject.getString("userid");
|
|
|
int main_department = jsonObject.getIntValue("main_department");
|
|
int main_department = jsonObject.getIntValue("main_department");
|
|
|
- String mobile = jsonObject.getString("mobile");
|
|
|
|
|
- String open_userid = jsonObject.getString("open_userid");
|
|
|
|
|
- List<String> list = Arrays.asList(strArray);
|
|
|
|
|
if (list.contains(position)) {
|
|
if (list.contains(position)) {
|
|
|
list_wechat_userid.add(userid);
|
|
list_wechat_userid.add(userid);
|
|
|
- SQLFactory sqlFactory = new SQLFactory(this, "插入微信成员");
|
|
|
|
|
- sqlFactory.addParameter("tuserid", createTableID("tuser", "tuserid"));
|
|
|
|
|
- sqlFactory.addParameter("wechat_depid", main_department);
|
|
|
|
|
- sqlFactory.addParameter("wechat_userid", userid);
|
|
|
|
|
- sqlFactory.addParameter("wechat_name", name);
|
|
|
|
|
- sqlFactory.addParameter("wechat_open_userid", open_userid);
|
|
|
|
|
- sqlFactory.addParameter("wechat_mobile", mobile);
|
|
|
|
|
- sqlFactory.addParameter("wechat_position", position);
|
|
|
|
|
- sqlFactory.addParameter("fusertype", fusertype);
|
|
|
|
|
- dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
-// System.err.println("经销商...");
|
|
|
|
|
-// listSql.add(sqlFactory.getSQL());
|
|
|
|
|
-// if (listSql.size() > 100) {
|
|
|
|
|
-// System.err.println("经销商...");
|
|
|
|
|
-// dbConnect.runSqlUpdate(listSql);
|
|
|
|
|
-// listSql.clear();
|
|
|
|
|
-// try {
|
|
|
|
|
-// Thread.sleep(1000);
|
|
|
|
|
-// } catch (InterruptedException e) {
|
|
|
|
|
-// e.printStackTrace();
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ Rows deptids = dbConnect.runSqlQuery("SELECT wechat_depid from tdepartment WHERE wechat_parendeptid ='" + main_department + "'");
|
|
|
|
|
+ List<String> deptidsList = deptids.toArrayList("wechat_depid");
|
|
|
|
|
+ if (!deptids.isEmpty()) {
|
|
|
|
|
+// System.err.println("父:" + main_department);
|
|
|
|
|
+ //删除经销商
|
|
|
|
|
+ SQLFactory deleteTageents = new SQLFactory(this, "删除经销商");
|
|
|
|
|
+ deleteTageents.addParameter_in("ids", deptids.toArrayList("wechat_depid"));
|
|
|
|
|
+ dbConnect.runSqlUpdate(deleteTageents);
|
|
|
|
|
+
|
|
|
|
|
+ for (Object obj2 : array) {
|
|
|
|
|
+ JSONObject jsonObject2 = (JSONObject) obj2;
|
|
|
|
|
+ int subID = jsonObject2.getIntValue("main_department");
|
|
|
|
|
+
|
|
|
|
|
+ if (deptidsList.contains(String.valueOf(subID))) {
|
|
|
|
|
+// System.err.println(subID);
|
|
|
|
|
+ addUser(jsonObject2, main_department, fusertype);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ tempArray.add(obj);
|
|
|
|
|
+ } else {
|
|
|
|
|
+// tempArray.add(obj);
|
|
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT wechat_parendeptid from tdepartment WHERE wechat_depid ='" + main_department + "'");
|
|
|
|
|
+ if (!rows.isEmpty()) {
|
|
|
|
|
+ int wechat_parendeptid = rows.get(0).getInteger("wechat_parendeptid");
|
|
|
|
|
+// System.err.println("wechat_parendeptid:" + wechat_parendeptid);
|
|
|
|
|
+ //包含部门的说明是子部门,不包含说明是单独一个部门
|
|
|
|
|
+ if (listDepids.contains(String.valueOf(wechat_parendeptid))) {
|
|
|
|
|
+ addUser(jsonObject, wechat_parendeptid, fusertype);
|
|
|
|
|
+ //删除以前的子经销商部门
|
|
|
|
|
+ dbConnect.runSqlUpdate("DELETE FROM tagents WHERE wechat_depid = '" + main_department + "'");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ addUser(jsonObject, main_department, fusertype);
|
|
|
|
|
+ tempArray.add(obj);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// dbConnect.runSqlUpdate(listSql);
|
|
|
|
|
|
|
+ deleteUsers2(idsList_user);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
if (fusertype.equals("经销商")) {
|
|
if (fusertype.equals("经销商")) {
|
|
|
- updateAgents(array);
|
|
|
|
|
|
|
+// System.err.println("经销商个数:" + tempArray.size());
|
|
|
|
|
+ updateAgents(tempArray);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
return array;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 更新经销商信息
|
|
* 更新经销商信息
|
|
|
*
|
|
*
|
|
@@ -405,35 +271,32 @@ public class GetWechatData extends BaseClass implements Runnable {
|
|
|
*/
|
|
*/
|
|
|
public void updateAgents(JSONArray userArray) {
|
|
public void updateAgents(JSONArray userArray) {
|
|
|
// ArrayList<String> listSql = new ArrayList<>();
|
|
// ArrayList<String> listSql = new ArrayList<>();
|
|
|
|
|
+ ArrayList<String> idsList = new ArrayList<>();
|
|
|
for (Object obj : userArray) {
|
|
for (Object obj : userArray) {
|
|
|
JSONObject jsonObject = (JSONObject) obj;
|
|
JSONObject jsonObject = (JSONObject) obj;
|
|
|
int main_department = jsonObject.getIntValue("main_department");
|
|
int main_department = jsonObject.getIntValue("main_department");
|
|
|
|
|
+ idsList.add(String.valueOf(main_department));
|
|
|
String mobile = jsonObject.getString("mobile");
|
|
String mobile = jsonObject.getString("mobile");
|
|
|
String faddress = jsonObject.getString("address");
|
|
String faddress = jsonObject.getString("address");
|
|
|
String name = jsonObject.getString("name");
|
|
String name = jsonObject.getString("name");
|
|
|
-
|
|
|
|
|
SQLFactory sqlFactory = new SQLFactory(this, "插入经销商档案");
|
|
SQLFactory sqlFactory = new SQLFactory(this, "插入经销商档案");
|
|
|
sqlFactory.addParameter("tagentsid", createTableID("tagents", "tagentsid"));
|
|
sqlFactory.addParameter("tagentsid", createTableID("tagents", "tagentsid"));
|
|
|
-// sqlFactory.addParameter("fagentname", "");
|
|
|
|
|
sqlFactory.addParameter("faddress", faddress);
|
|
sqlFactory.addParameter("faddress", faddress);
|
|
|
sqlFactory.addParameter("fcontact", name);
|
|
sqlFactory.addParameter("fcontact", name);
|
|
|
sqlFactory.addParameter("fphonenumber", mobile);
|
|
sqlFactory.addParameter("fphonenumber", mobile);
|
|
|
sqlFactory.addParameter("wechat_depid", main_department);
|
|
sqlFactory.addParameter("wechat_depid", main_department);
|
|
|
// System.err.println("经销商档案...");
|
|
// System.err.println("经销商档案...");
|
|
|
- dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
-// listSql.add(sqlFactory.getSQL());
|
|
|
|
|
-// if (listSql.size() > 100) {
|
|
|
|
|
-//
|
|
|
|
|
-// dbConnect.runSqlUpdate(listSql);
|
|
|
|
|
-// listSql.clear();
|
|
|
|
|
-// try {
|
|
|
|
|
-// Thread.sleep(1000);
|
|
|
|
|
-// } catch (InterruptedException e) {
|
|
|
|
|
-// e.printStackTrace();
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ String res = dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
+
|
|
|
|
|
+ if (res.equals("true")) {
|
|
|
|
|
+ saveTDataLog("经销商档案-成功:部门id" + main_department);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ saveTDataLog("经销商档案-失败:部门id" + main_department);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ deleteTagents(idsList);
|
|
|
deleteUser();
|
|
deleteUser();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -442,24 +305,132 @@ public class GetWechatData extends BaseClass implements Runnable {
|
|
|
* 自动清除用户
|
|
* 自动清除用户
|
|
|
*/
|
|
*/
|
|
|
public void deleteUser() {
|
|
public void deleteUser() {
|
|
|
- System.err.println("用户数量:" + list_wechat_userid.size());
|
|
|
|
|
SQLFactory sqlFactory = new SQLFactory(this, "查询删除用户");
|
|
SQLFactory sqlFactory = new SQLFactory(this, "查询删除用户");
|
|
|
sqlFactory.addParameter_in("wechat_userid", list_wechat_userid);
|
|
sqlFactory.addParameter_in("wechat_userid", list_wechat_userid);
|
|
|
String sql = sqlFactory.getSQL();
|
|
String sql = sqlFactory.getSQL();
|
|
|
Rows rows = dbConnect.runSqlQuery(sql);
|
|
Rows rows = dbConnect.runSqlQuery(sql);
|
|
|
|
|
+ saveTDataLog("查询删除用户");
|
|
|
ArrayList<String> deleteList = rows.toArrayList("tuserid");
|
|
ArrayList<String> deleteList = rows.toArrayList("tuserid");
|
|
|
- System.err.println("删除用户数量:" + deleteList.size());
|
|
|
|
|
if (!rows.isEmpty()) {
|
|
if (!rows.isEmpty()) {
|
|
|
SQLFactory deleteFac = new SQLFactory(this, "删除用户");
|
|
SQLFactory deleteFac = new SQLFactory(this, "删除用户");
|
|
|
deleteFac.addParameter_in("tuserid", deleteList);
|
|
deleteFac.addParameter_in("tuserid", deleteList);
|
|
|
- System.err.println(deleteFac.getSQL());
|
|
|
|
|
- dbConnect.runSqlUpdate(deleteFac.getSQL());
|
|
|
|
|
|
|
+ String res = dbConnect.runSqlUpdate(deleteFac.getSQL());
|
|
|
|
|
+
|
|
|
|
|
+ if (res.equals("true")) {
|
|
|
|
|
+ saveTDataLog("删除用户-成功");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ saveTDataLog("删除用户-失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
list_wechat_userid.clear();
|
|
list_wechat_userid.clear();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增或更新微信部门
|
|
|
|
|
+ */
|
|
|
|
|
+ public void addDepartment(JSONObject departmentObj) {
|
|
|
|
|
+ int wechat_depid = departmentObj.getIntValue("id");
|
|
|
|
|
+ int wechat_parendeptid = departmentObj.getIntValue("parentid");
|
|
|
|
|
+ String wechat_depname = departmentObj.getString("name");
|
|
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "插入微信部门");
|
|
|
|
|
+ sqlFactory.addParameter("tdepartmentid", createTableID("tdepartment", "tdepartmentid"));
|
|
|
|
|
+ sqlFactory.addParameter("wechat_depid", wechat_depid);
|
|
|
|
|
+ sqlFactory.addParameter("wechat_parendeptid", wechat_parendeptid);
|
|
|
|
|
+ sqlFactory.addParameter("wechat_depname", wechat_depname);
|
|
|
|
|
+ String res = dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
+ if (res.equals("true")) {
|
|
|
|
|
+ saveTDataLog("部门成功:" + wechat_depname);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ saveTDataLog("部门失败:" + wechat_depname);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除微信部门
|
|
|
|
|
+ */
|
|
|
|
|
+ public void deleteDepartments(ArrayList list) {
|
|
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "删除微信部门");
|
|
|
|
|
+ sqlFactory.addParameter_in("ids", list);
|
|
|
|
|
+ String res = dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
+ if (res.equals("true")) {
|
|
|
|
|
+ saveTDataLog("删除部门成功");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ saveTDataLog("删除部门失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增或者更新用户(业务员、经销商)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param userObj
|
|
|
|
|
+ * @param main_department
|
|
|
|
|
+ * @param fusertype
|
|
|
|
|
+ */
|
|
|
|
|
+ public void addUser(JSONObject userObj, int main_department, String fusertype) {
|
|
|
|
|
+ String position = userObj.getString("position");
|
|
|
|
|
+ String name = userObj.getString("name");
|
|
|
|
|
+ String userid = userObj.getString("userid");
|
|
|
|
|
+ String mobile = userObj.getString("mobile");
|
|
|
|
|
+ String open_userid = userObj.getString("open_userid");
|
|
|
|
|
+
|
|
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "插入微信成员");
|
|
|
|
|
+ sqlFactory.addParameter("tuserid", createTableID("tuser", "tuserid"));
|
|
|
|
|
+ sqlFactory.addParameter("wechat_depid", main_department);
|
|
|
|
|
+ sqlFactory.addParameter("wechat_userid", userid);
|
|
|
|
|
+ sqlFactory.addParameter("wechat_name", name);
|
|
|
|
|
+ sqlFactory.addParameter("wechat_open_userid", open_userid);
|
|
|
|
|
+ sqlFactory.addParameter("wechat_mobile", mobile);
|
|
|
|
|
+ sqlFactory.addParameter("wechat_position", position);
|
|
|
|
|
+ sqlFactory.addParameter("fusertype", fusertype);
|
|
|
|
|
+ String res = dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
+ if (res.equals("true")) {
|
|
|
|
|
+ saveTDataLog(fusertype + "成功:" + name);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ saveTDataLog(fusertype + "失败:" + name);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ idsList_user.add(userid);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void deleteUsers2(ArrayList list) {
|
|
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "删除微信部门成员");
|
|
|
|
|
+ sqlFactory.addParameter_in("ids", list);
|
|
|
|
|
+ String res = dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
+ if (res.equals("true")) {
|
|
|
|
|
+ saveTDataLog("删除微信部门成员成功");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ saveTDataLog("删除微信部门成员失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void deleteTagents(ArrayList list) {
|
|
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "删除经销商2");
|
|
|
|
|
+ sqlFactory.addParameter_in("ids", list);
|
|
|
|
|
+ String res = dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
+ if (res.equals("true")) {
|
|
|
|
|
+ saveTDataLog("删除经销商成功");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ saveTDataLog("删除经销商失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存日志
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param flog
|
|
|
|
|
+ */
|
|
|
|
|
+ public void saveTDataLog(String flog) {
|
|
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "保存日志");
|
|
|
|
|
+ sqlFactory.addParameter("tdatalogid", createTableID("tdatalog", "tdatalogid"));
|
|
|
|
|
+ sqlFactory.addParameter("flog", flog);
|
|
|
|
|
+ dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取一个新的表数据ID
|
|
* 获取一个新的表数据ID
|
|
|
*/
|
|
*/
|
|
@@ -481,4 +452,8 @@ public class GetWechatData extends BaseClass implements Runnable {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public JSONArray getResponse(String url, String key) {
|
|
|
|
|
+ return JSONObject.parseObject(new WebRequest().doGet(url)).getJSONArray(key);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|