Kaynağa Gözat

微信数据调整

吴志根 4 yıl önce
ebeveyn
işleme
e461efa31f

+ 13 - 5
src/dsb/com/cnd3b/restcontroller/enterprise/data/data.java

@@ -109,7 +109,7 @@ public class data extends Controller {
     public String getRoles() {
     public String getRoles() {
 
 
 
 
-        return getSucReturnObject().setData(GetWechatData.positionAgent).toString();
+        return getSucReturnObject().setData(getPosition(1)).toString();
     }
     }
 
 
     /**
     /**
@@ -120,24 +120,26 @@ public class data extends Controller {
     public String getAllRoles() {
     public String getAllRoles() {
         int type = content.getIntValue("type");
         int type = content.getIntValue("type");
         JSONArray array = new JSONArray();
         JSONArray array = new JSONArray();
+
+
         //¾­ÏúÉÌ
         //¾­ÏúÉÌ
         if (type == 1) {
         if (type == 1) {
-            for (String str : GetWechatData.positionAgent) {
+            for (String str : getPosition(1)) {
                 array.add(str);
                 array.add(str);
             }
             }
         }
         }
         //ÒµÎñÔ±
         //ÒµÎñÔ±
         if (type == 2) {
         if (type == 2) {
-            for (String str : GetWechatData.positionSeller) {
+            for (String str : getPosition(2)) {
                 array.add(str);
                 array.add(str);
             }
             }
         }
         }
         //ËùÓÐ
         //ËùÓÐ
         if (type == 3) {
         if (type == 3) {
-            for (String str : GetWechatData.positionAgent) {
+            for (String str : getPosition(1)) {
                 array.add(str);
                 array.add(str);
             }
             }
-            for (String str : GetWechatData.positionSeller) {
+            for (String str : getPosition(2)) {
                 array.add(str);
                 array.add(str);
             }
             }
         }
         }
@@ -146,5 +148,11 @@ public class data extends Controller {
         return getSucReturnObject().setData(array).toString();
         return getSucReturnObject().setData(array).toString();
     }
     }
 
 
+    public String[] getPosition(int ftype) {
+        String sql = "SELECT fname from tposition WHERE ftype ='" + ftype + "'";
+        Rows rows = dbConnect.runSqlQuery(sql);
+        return rows.toArray("fname");
+    }
+
 
 
 }
 }

+ 48 - 48
src/dsb/com/cnd3b/service/DataStatusChange.java

@@ -1,48 +1,48 @@
-package com.cnd3b.service;
-
-import com.cnd3b.common.BaseClass;
-import com.cnd3b.common.data.db.DBConnect;
-import com.cnd3b.common.data.db.SQLiteJDBC;
-
-import java.util.ArrayList;
-
-public class DataStatusChange extends BaseClass implements Runnable {
-
-    @Override
-    public void run() {
-        try {
-            if (new SQLiteJDBC().checkServicesUsed("DataStatusChange", true)) {
-                supplyanddemandstatus();
-                activitystatus();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    /**
-     * 供需到期
-     */
-    public void supplyanddemandstatus() {
-        try {
-            DBConnect dbConnect = new DBConnect();
-            dbConnect.runSqlUpdate("update tsupplyanddemand set fstatus='已过期' where convert(varchar(10),fenddate,120)<=getdate() and fstatus ='待对接'");
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-
-    public void activitystatus() {
-        try {
-            DBConnect dbConnect = new DBConnect();
-            ArrayList<String> list = new ArrayList<>();
-            list.add("update tactivity set fstatus='已结束' where convert(varchar(10),fenddate,120)<convert(varchar(10),getdate(),120)");
-            list.add("update tactivity set fstatus='未开始' where convert(varchar(10),fbegdate,120)>convert(varchar(10),getdate(),120)");
-            list.add("update tactivity set fstatus='活动中' where convert(varchar(10),fenddate,120)>=convert(varchar(10),getdate(),120) and convert(varchar(10),fbegdate,120)<=convert(varchar(10),getdate(),120)");
-            dbConnect.runSqlUpdate(list);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-}
+//package com.cnd3b.service;
+//
+//import com.cnd3b.common.BaseClass;
+//import com.cnd3b.common.data.db.DBConnect;
+//import com.cnd3b.common.data.db.SQLiteJDBC;
+//
+//import java.util.ArrayList;
+//
+//public class DataStatusChange extends BaseClass implements Runnable {
+//
+//    @Override
+//    public void run() {
+//        try {
+//            if (new SQLiteJDBC().checkServicesUsed("DataStatusChange", true)) {
+//                supplyanddemandstatus();
+//                activitystatus();
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//    }
+//
+//    /**
+//     * 供需到期
+//     */
+//    public void supplyanddemandstatus() {
+//        try {
+//            DBConnect dbConnect = new DBConnect();
+//            dbConnect.runSqlUpdate("update tsupplyanddemand set fstatus='已过期' where convert(varchar(10),fenddate,120)<=getdate() and fstatus ='待对接'");
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//    }
+//
+//
+//    public void activitystatus() {
+//        try {
+//            DBConnect dbConnect = new DBConnect();
+//            ArrayList<String> list = new ArrayList<>();
+//            list.add("update tactivity set fstatus='已结束' where convert(varchar(10),fenddate,120)<convert(varchar(10),getdate(),120)");
+//            list.add("update tactivity set fstatus='未开始' where convert(varchar(10),fbegdate,120)>convert(varchar(10),getdate(),120)");
+//            list.add("update tactivity set fstatus='活动中' where convert(varchar(10),fenddate,120)>=convert(varchar(10),getdate(),120) and convert(varchar(10),fbegdate,120)<=convert(varchar(10),getdate(),120)");
+//            dbConnect.runSqlUpdate(list);
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//    }
+//}

+ 235 - 260
src/dsb/com/cnd3b/service/GetWechatData.java

@@ -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);
+    }
+
 }
 }

+ 75 - 75
src/dsb/com/cnd3b/service/ObsAutoDelete.java

@@ -1,75 +1,75 @@
-package com.cnd3b.service;
-
-import com.cnd3b.common.BaseClass;
-import com.cnd3b.common.data.Row;
-import com.cnd3b.common.data.Rows;
-import com.cnd3b.common.data.SQLFactory;
-import com.cnd3b.common.data.db.DBConnect;
-import com.cnd3b.common.data.db.SQLiteJDBC;
-import com.cnd3b.utility.obs.BucketFile;
-import p2.util.P2Exception;
-
-import java.util.Calendar;
-
-/**
- * 存储容量定时清理
- */
-public class ObsAutoDelete extends BaseClass implements Runnable {
-
-    @Override
-    public void run() {
-        if (new SQLiteJDBC().checkServicesUsed("ObsAutoDelete", true)) {
-            try {
-                clean();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-        if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) == 3) {
-            System.gc();
-        }
-    }
-
-    public void clean() throws P2Exception {
-        DBConnect dbConnect = new DBConnect();
-        /**
-         * 第一步,搜索出所有存在附件的表格
-         */
-        Rows objectrows = dbConnect.runSqlQuery("select distinct ownertable,t2.uniquecolumnname from tattachment t1 inner join PS_SYSTABLES t2 on t1.ownertable=t2.tablename");
-        for (Row objectrow : objectrows) {
-
-            String objectname = objectrow.getString("ownertable");
-            String uniquecolumnname = objectrow.getString("uniquecolumnname");
-
-            Rows tattachmentrows = null;
-            try {
-                tattachmentrows = dbConnect.runSqlQuery("select t1.siteid,t1.tattachmentid,t1.serialnumber,t1.fdocument,t1.fparentid,t1.ftype from tattachment t1 left join " + objectname + " t2 on  t1.ownerid=t2." + uniquecolumnname + " inner join tobsmag t3 on t1.siteid=t3.siteid and t3.fisautoclean=1  where t1.ownertable='" + objectname + "' and t2." + uniquecolumnname + " is null");
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            if (tattachmentrows != null) {
-                for (Row tattachmentrow : tattachmentrows) {
-                    String siteid = tattachmentrow.getString("siteid");
-                    String ftype = tattachmentrow.getString("ftype");
-                    String tattachmentid = tattachmentrow.getString("tattachmentid");
-                    String serialnumber = tattachmentrow.getString("serialnumber");
-                    String fdocument = tattachmentrow.getString("fdocument");
-                    BucketFile bucketFile = new BucketFile(siteid);
-                    if ("hls".equalsIgnoreCase(ftype)) {
-                        bucketFile.deleteFolder(serialnumber);
-                    } else {
-                        bucketFile.deleteFile(serialnumber);
-                    }
-                    if (!bucketFile.doesObjectExist(serialnumber)) {
-                        printInfoOut("云存储文件清理", siteid + "-表名:" + objectname + ";附件ID:" + tattachmentid + ";云存储文件名:" + serialnumber + ";文件名:" + fdocument);
-                        SQLFactory sqlFactory = new SQLFactory(this, "附件信息删除");
-                        sqlFactory.addParameter("siteid", siteid);
-                        sqlFactory.addParameter("tattachmentid", tattachmentid);
-                        dbConnect.runSqlUpdate(sqlFactory.getSQL());
-                    }
-                    bucketFile.close();
-                }
-            }
-        }
-    }
-}
+//package com.cnd3b.service;
+//
+//import com.cnd3b.common.BaseClass;
+//import com.cnd3b.common.data.Row;
+//import com.cnd3b.common.data.Rows;
+//import com.cnd3b.common.data.SQLFactory;
+//import com.cnd3b.common.data.db.DBConnect;
+//import com.cnd3b.common.data.db.SQLiteJDBC;
+//import com.cnd3b.utility.obs.BucketFile;
+//import p2.util.P2Exception;
+//
+//import java.util.Calendar;
+//
+///**
+// * 存储容量定时清理
+// */
+//public class ObsAutoDelete extends BaseClass implements Runnable {
+//
+//    @Override
+//    public void run() {
+//        if (new SQLiteJDBC().checkServicesUsed("ObsAutoDelete", true)) {
+//            try {
+//                clean();
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//            }
+//        }
+//        if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) == 3) {
+//            System.gc();
+//        }
+//    }
+//
+//    public void clean() throws P2Exception {
+//        DBConnect dbConnect = new DBConnect();
+//        /**
+//         * 第一步,搜索出所有存在附件的表格
+//         */
+//        Rows objectrows = dbConnect.runSqlQuery("select distinct ownertable,t2.uniquecolumnname from tattachment t1 inner join PS_SYSTABLES t2 on t1.ownertable=t2.tablename");
+//        for (Row objectrow : objectrows) {
+//
+//            String objectname = objectrow.getString("ownertable");
+//            String uniquecolumnname = objectrow.getString("uniquecolumnname");
+//
+//            Rows tattachmentrows = null;
+//            try {
+//                tattachmentrows = dbConnect.runSqlQuery("select t1.siteid,t1.tattachmentid,t1.serialnumber,t1.fdocument,t1.fparentid,t1.ftype from tattachment t1 left join " + objectname + " t2 on  t1.ownerid=t2." + uniquecolumnname + " inner join tobsmag t3 on t1.siteid=t3.siteid and t3.fisautoclean=1  where t1.ownertable='" + objectname + "' and t2." + uniquecolumnname + " is null");
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//            }
+//            if (tattachmentrows != null) {
+//                for (Row tattachmentrow : tattachmentrows) {
+//                    String siteid = tattachmentrow.getString("siteid");
+//                    String ftype = tattachmentrow.getString("ftype");
+//                    String tattachmentid = tattachmentrow.getString("tattachmentid");
+//                    String serialnumber = tattachmentrow.getString("serialnumber");
+//                    String fdocument = tattachmentrow.getString("fdocument");
+//                    BucketFile bucketFile = new BucketFile(siteid);
+//                    if ("hls".equalsIgnoreCase(ftype)) {
+//                        bucketFile.deleteFolder(serialnumber);
+//                    } else {
+//                        bucketFile.deleteFile(serialnumber);
+//                    }
+//                    if (!bucketFile.doesObjectExist(serialnumber)) {
+//                        printInfoOut("云存储文件清理", siteid + "-表名:" + objectname + ";附件ID:" + tattachmentid + ";云存储文件名:" + serialnumber + ";文件名:" + fdocument);
+//                        SQLFactory sqlFactory = new SQLFactory(this, "附件信息删除");
+//                        sqlFactory.addParameter("siteid", siteid);
+//                        sqlFactory.addParameter("tattachmentid", tattachmentid);
+//                        dbConnect.runSqlUpdate(sqlFactory.getSQL());
+//                    }
+//                    bucketFile.close();
+//                }
+//            }
+//        }
+//    }
+//}

+ 100 - 100
src/dsb/com/cnd3b/service/ObsMpcTaskQuery.java

@@ -1,100 +1,100 @@
-package com.cnd3b.service;
-
-import com.alibaba.fastjson.JSONObject;
-import com.cnd3b.common.BaseClass;
-import com.cnd3b.common.Controller;
-import com.cnd3b.common.data.Row;
-import com.cnd3b.common.data.Rows;
-import com.cnd3b.common.data.SQLFactory;
-import com.cnd3b.common.data.db.DBConnect;
-import com.cnd3b.common.data.db.SQLiteJDBC;
-import com.cnd3b.utility.obs.BucketFile;
-import com.cnd3b.utility.obs.mpc.MpcFactory;
-import com.cnd3b.utility.obs.mpc.MpcFile;
-
-import java.util.ArrayList;
-
-/**
- * 华为云存储转码任务查询
- */
-public class ObsMpcTaskQuery extends BaseClass implements Runnable {
-
-    @Override
-    public void run() {
-        try {
-            if (new SQLiteJDBC().checkServicesUsed("ObsMpcTaskQuery", true)) {
-                mpcTask();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    public void mpcTask() {
-        DBConnect dbConnect = new DBConnect();
-        SQLFactory taskquerySQl = new SQLFactory(this, "转码任务查询");
-        Rows rows = dbConnect.runSqlQuery(taskquerySQl.getSQL());
-
-        ArrayList<String> list = new ArrayList<>();
-        if (!rows.isEmpty()) {
-            System.err.println("转码任务查询:共" + rows.size() + "条");
-        }
-        MpcFactory mpcFactory = new MpcFactory();
-        int rownum = 1;
-        for (Row row : rows) {
-            String siteid = row.getString("siteid");
-            String tattachmentid = row.getString("tattachmentid");
-            String mpctaskid = row.getString("mpctaskid");
-            String ownertable = row.getString("ownertable");
-            String ownerid = row.getString("ownerid");
-            String postfix = row.getString("postfix");
-            String fdocument = row.getString("fdocument");
-
-            System.err.println("转码任务查询:开始执行第" + (rownum++) + "条,siteid:" + siteid + "tattachmentid:" + tattachmentid + "mpctaskid:" + mpctaskid);
-            MpcFile file = mpcFactory.queryMpcTask(mpctaskid);
-            if (file != null) {
-                //转码成功的视频文件名称
-                String objectname = file.getObject();
-                System.err.println("转码任务查询:转码后名称" + objectname);
-                String obsfilename = objectname + "/" + file.getOutput_file_name();
-
-                BucketFile bucketFile = new BucketFile(siteid);
-                if (!bucketFile.doesObjectExist(obsfilename)) {
-                    System.err.println("转码任务查询:没有找到实体文件" + obsfilename);
-                    continue;
-                }
-                String fileurl = bucketFile.getFileUrl(obsfilename);
-                System.err.println("转码任务查询:获取转码文件访问地址" + fileurl);
-
-                //生成缩略图附件信息
-                SQLFactory sqlFactory = new SQLFactory(this, "子附件信息插入");
-                sqlFactory.addParameter("fparentid", tattachmentid);
-                sqlFactory.addParameter("tattachmentid", new Controller(new JSONObject()).createTableID("tattachment", "tattachmentid"));
-                sqlFactory.addParameter("siteid", siteid);
-                sqlFactory.addParameter("ownertable", ownertable);
-                sqlFactory.addParameter("ownerid", ownerid);
-                sqlFactory.addParameter("createby", "system");
-                sqlFactory.addParameter("ftype", "hls");
-                sqlFactory.addParameter("postfix", postfix);
-                sqlFactory.addParameter("serialnumber", objectname);
-                sqlFactory.addParameter("fdocument", fdocument);
-                sqlFactory.addParameter("fobsurl", fileurl);
-                sqlFactory.addParameter("contentlength", bucketFile.getObjectMetadata(obsfilename).getContentLength());
-
-                list.add(sqlFactory.getSQL());
-                list.add("update tattachment set mpctaskstatus=1 where tattachmentid='" + tattachmentid + "'");
-                bucketFile.close();
-            } else {
-                System.err.println("转码任务查询:转码未完成");
-            }
-        }
-        if (!list.isEmpty()) {
-            System.err.println("更新附件表转码后访问路径");
-            String status = dbConnect.runSqlUpdate(list);
-            if (!status.equals("true")) {
-                System.err.println("转码任务查询:" + status);
-            }
-        }
-    }
-
-}
+//package com.cnd3b.service;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.cnd3b.common.BaseClass;
+//import com.cnd3b.common.Controller;
+//import com.cnd3b.common.data.Row;
+//import com.cnd3b.common.data.Rows;
+//import com.cnd3b.common.data.SQLFactory;
+//import com.cnd3b.common.data.db.DBConnect;
+//import com.cnd3b.common.data.db.SQLiteJDBC;
+//import com.cnd3b.utility.obs.BucketFile;
+//import com.cnd3b.utility.obs.mpc.MpcFactory;
+//import com.cnd3b.utility.obs.mpc.MpcFile;
+//
+//import java.util.ArrayList;
+//
+///**
+// * 华为云存储转码任务查询
+// */
+//public class ObsMpcTaskQuery extends BaseClass implements Runnable {
+//
+//    @Override
+//    public void run() {
+//        try {
+//            if (new SQLiteJDBC().checkServicesUsed("ObsMpcTaskQuery", true)) {
+//                mpcTask();
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//    }
+//
+//    public void mpcTask() {
+//        DBConnect dbConnect = new DBConnect();
+//        SQLFactory taskquerySQl = new SQLFactory(this, "转码任务查询");
+//        Rows rows = dbConnect.runSqlQuery(taskquerySQl.getSQL());
+//
+//        ArrayList<String> list = new ArrayList<>();
+//        if (!rows.isEmpty()) {
+//            System.err.println("转码任务查询:共" + rows.size() + "条");
+//        }
+//        MpcFactory mpcFactory = new MpcFactory();
+//        int rownum = 1;
+//        for (Row row : rows) {
+//            String siteid = row.getString("siteid");
+//            String tattachmentid = row.getString("tattachmentid");
+//            String mpctaskid = row.getString("mpctaskid");
+//            String ownertable = row.getString("ownertable");
+//            String ownerid = row.getString("ownerid");
+//            String postfix = row.getString("postfix");
+//            String fdocument = row.getString("fdocument");
+//
+//            System.err.println("转码任务查询:开始执行第" + (rownum++) + "条,siteid:" + siteid + "tattachmentid:" + tattachmentid + "mpctaskid:" + mpctaskid);
+//            MpcFile file = mpcFactory.queryMpcTask(mpctaskid);
+//            if (file != null) {
+//                //转码成功的视频文件名称
+//                String objectname = file.getObject();
+//                System.err.println("转码任务查询:转码后名称" + objectname);
+//                String obsfilename = objectname + "/" + file.getOutput_file_name();
+//
+//                BucketFile bucketFile = new BucketFile(siteid);
+//                if (!bucketFile.doesObjectExist(obsfilename)) {
+//                    System.err.println("转码任务查询:没有找到实体文件" + obsfilename);
+//                    continue;
+//                }
+//                String fileurl = bucketFile.getFileUrl(obsfilename);
+//                System.err.println("转码任务查询:获取转码文件访问地址" + fileurl);
+//
+//                //生成缩略图附件信息
+//                SQLFactory sqlFactory = new SQLFactory(this, "子附件信息插入");
+//                sqlFactory.addParameter("fparentid", tattachmentid);
+//                sqlFactory.addParameter("tattachmentid", new Controller(new JSONObject()).createTableID("tattachment", "tattachmentid"));
+//                sqlFactory.addParameter("siteid", siteid);
+//                sqlFactory.addParameter("ownertable", ownertable);
+//                sqlFactory.addParameter("ownerid", ownerid);
+//                sqlFactory.addParameter("createby", "system");
+//                sqlFactory.addParameter("ftype", "hls");
+//                sqlFactory.addParameter("postfix", postfix);
+//                sqlFactory.addParameter("serialnumber", objectname);
+//                sqlFactory.addParameter("fdocument", fdocument);
+//                sqlFactory.addParameter("fobsurl", fileurl);
+//                sqlFactory.addParameter("contentlength", bucketFile.getObjectMetadata(obsfilename).getContentLength());
+//
+//                list.add(sqlFactory.getSQL());
+//                list.add("update tattachment set mpctaskstatus=1 where tattachmentid='" + tattachmentid + "'");
+//                bucketFile.close();
+//            } else {
+//                System.err.println("转码任务查询:转码未完成");
+//            }
+//        }
+//        if (!list.isEmpty()) {
+//            System.err.println("更新附件表转码后访问路径");
+//            String status = dbConnect.runSqlUpdate(list);
+//            if (!status.equals("true")) {
+//                System.err.println("转码任务查询:" + status);
+//            }
+//        }
+//    }
+//
+//}

+ 4 - 0
src/dsb/com/cnd3b/service/SQL/保存日志.sql

@@ -0,0 +1,4 @@
+INSERT INTO tdatalog
+    (tdatalogid, siteid, changeby, changedate, rmkenable, flog)
+VALUES ($tdatalogid$, 'JIUSHENG', 'P2ADMIN', GETDATE(), 0, $flog$)
+

+ 1 - 1
src/dsb/com/cnd3b/service/SQL/删除经销商.sql

@@ -1,3 +1,3 @@
 DELETE
 DELETE
 FROM tagents
 FROM tagents
-WHERE wechat_depid NOT IN $ids$
+WHERE wechat_depid IN $ids$

+ 3 - 0
src/dsb/com/cnd3b/service/SQL/删除经销商2.sql

@@ -0,0 +1,3 @@
+DELETE
+FROM tagents
+WHERE wechat_depid NOT IN $ids$

+ 5 - 1
src/dsb/com/cnd3b/service/SQL/插入微信成员.sql

@@ -5,5 +5,9 @@ VALUES
 	( $tuserid$,$wechat_depid$, $wechat_userid$, $wechat_name$,$wechat_open_userid$,$wechat_mobile$,$wechat_position$,$fusertype$,'JIUSHENG',0,'P2ADMIN','P2ADMIN',GETDATE() ,GETDATE());
 	( $tuserid$,$wechat_depid$, $wechat_userid$, $wechat_name$,$wechat_open_userid$,$wechat_mobile$,$wechat_position$,$fusertype$,'JIUSHENG',0,'P2ADMIN','P2ADMIN',GETDATE() ,GETDATE());
 ELSE
 ELSE
 UPDATE tuser
 UPDATE tuser
-SET changedate=GETDATE()
+SET changedate=GETDATE(),
+    wechat_name = $wechat_name$,
+    wechat_mobile = $wechat_mobile$,
+    wechat_depid = $wechat_depid$,
+    wechat_open_userid = $wechat_open_userid$
 WHERE wechat_userid = $wechat_userid$
 WHERE wechat_userid = $wechat_userid$

+ 3 - 1
src/dsb/com/cnd3b/service/SQL/插入微信部门.sql

@@ -6,5 +6,7 @@ VALUES
 ELSE
 ELSE
 UPDATE tdepartment
 UPDATE tdepartment
 SET changedate=GETDATE(),
 SET changedate=GETDATE(),
-    wechat_depname = $wechat_depname$
+    wechat_depname = $wechat_depname$,
+    wechat_depid = $wechat_depid$,
+    wechat_parendeptid = $wechat_parendeptid$
 WHERE wechat_depid = $wechat_depid$
 WHERE wechat_depid = $wechat_depid$

+ 6 - 1
src/dsb/com/cnd3b/service/SQL/插入经销商档案.sql

@@ -5,5 +5,10 @@ VALUES
 	( $tagentsid$,  (SELECT wechat_depname FROM tdepartment WHERE wechat_depid =  $wechat_depid$), $faddress$, $fcontact$,$fphonenumber$,$wechat_depid$,0,'P2ADMIN','P2ADMIN',GETDATE() ,GETDATE());
 	( $tagentsid$,  (SELECT wechat_depname FROM tdepartment WHERE wechat_depid =  $wechat_depid$), $faddress$, $fcontact$,$fphonenumber$,$wechat_depid$,0,'P2ADMIN','P2ADMIN',GETDATE() ,GETDATE());
 ELSE
 ELSE
 UPDATE tagents
 UPDATE tagents
-SET changedate=GETDATE()
+SET changedate=GETDATE(),
+    fagentname = (SELECT wechat_depname FROM tdepartment WHERE wechat_depid = $wechat_depid$),
+    faddress = $faddress$,
+    fcontact = $fcontact$,
+    fphonenumber = $fphonenumber$,
+    wechat_depid = $wechat_depid$
 WHERE wechat_depid = $wechat_depid$
 WHERE wechat_depid = $wechat_depid$