Просмотр исходного кода

拉取微信部门,微信部门成员,建立经销商档案

吴志根 4 лет назад
Родитель
Сommit
9ad49d7b3b

+ 1 - 1
src/dsb/com/cnd3b/common/parameter/parameter.java

@@ -24,7 +24,7 @@ public class parameter {
     //userid:usermsg
     public static HashMap<Long, Row> userIdList = new HashMap<>(16);
 
-    public static String defaultsiteid = "BWJ";
+    public static String defaultsiteid = "JIUSHENG";
 
     /**
      * µÇ¼-ÊÖ»úºÅ¡¢ÑéÖ¤Âë

+ 16 - 0
src/dsb/com/cnd3b/restcontroller/enterprise/tagents/SQL/经销商档案列表.sql

@@ -0,0 +1,16 @@
+SELECT t1.fagentname,
+       t1.faddress,
+       t1.tagentsid,
+       t1.createdate,
+       t1.wechat_agentid,
+       t1.fcounty,
+       t1.tsalerid,
+       t1.fagentnum,
+       t1.wechat_corpid,
+       t1.fcontact,
+       t1.fphonenumber,
+       t1.fcity,
+       t1.wechat_corp_name,
+       t1.fprovince
+FROM tagents t1
+ORDER BY t1.createdate desc

+ 79 - 9
src/dsb/com/cnd3b/restcontroller/enterprise/tagents/tagents.java

@@ -2,6 +2,9 @@ package com.cnd3b.restcontroller.enterprise.tagents;
 
 import com.alibaba.fastjson.JSONObject;
 import com.cnd3b.common.Controller;
+import com.cnd3b.common.data.Rows;
+import com.cnd3b.common.data.SQLFactory;
+import com.cnd3b.utility.wechatdock.WechatDock_Enterprise;
 import p2.pao.PaoRemote;
 import p2.pao.PaoSetRemote;
 import p2.util.P2Exception;
@@ -41,6 +44,12 @@ public class tagents extends Controller {
         String faddress = content.getString("faddress");
         //所属业务员ID
         String tsalerid = content.getString("tsalerid");
+        //下游企业corpid
+        String wechat_corpid = content.getString("wechat_corpid");
+        //下游企业名称
+        String wechat_corp_name = content.getString("wechat_corp_name");
+        //下游企业应用id
+        String wechat_agentid = content.getString("wechat_agentid");
 
         PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tagents");
         PaoRemote paoRemote = paoSetRemote.addAtEnd();
@@ -55,12 +64,12 @@ public class tagents extends Controller {
         paoRemote.setValue("tsalerid", tsalerid, 11L);
         paoRemote.setValue("siteid", "JIUSHENG");
         paoRemote.setValue("createby", username, 11L);
+        paoRemote.setValue("wechat_corpid", wechat_corpid, 11L);
+        paoRemote.setValue("wechat_corp_name", wechat_corp_name, 11L);
+        paoRemote.setValue("wechat_agentid", wechat_agentid, 11L);
         paoSetRemote.save();
 
-        JSONObject object = new JSONObject();
-        object.put("tagentsid", paoRemote.getUniqueIDValue());
-
-        return getSucReturnObject().setData(object).toString();
+        return getSucReturnObject().toString();
     }
 
     /**
@@ -68,8 +77,53 @@ public class tagents extends Controller {
      *
      * @return
      */
-    public String updateTagents() {
-        return "";
+    public String updateTagents() throws P2Exception {
+        String tagentsid = content.getString("tagentsid");
+        //经销商编号
+        String fagentnum = content.getString("fagentnum");
+        //经销商名称
+        String fagentname = content.getString("fagentname");
+        //联系人
+        String fcontact = content.getString("fcontact");
+        //联系方式
+        String fphonenumber = content.getString("fphonenumber");
+        //省
+        String fprovince = content.getString("fprovince");
+        //市
+        String fcity = content.getString("fcity");
+        //县
+        String fcounty = content.getString("fcounty");
+        //地址
+        String faddress = content.getString("faddress");
+        //所属业务员ID
+        String tsalerid = content.getString("tsalerid");
+        //下游企业corpid
+        String wechat_corpid = content.getString("wechat_corpid");
+        //下游企业名称
+        String wechat_corp_name = content.getString("wechat_corp_name");
+        //下游企业应用id
+        String wechat_agentid = content.getString("wechat_agentid");
+
+        PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tagents", "tagentsid = '" + tagentsid + "'");
+        if (!paoSetRemote.isEmpty()) {
+            PaoRemote paoRemote = paoSetRemote.getPao(0);
+            paoRemote.setValue("fagentnum", fagentnum, 11L);
+            paoRemote.setValue("fagentname", fagentname, 11L);
+            paoRemote.setValue("fcontact", fcontact, 11L);
+            paoRemote.setValue("fphonenumber", fphonenumber, 11L);
+            paoRemote.setValue("fprovince", fprovince, 11L);
+            paoRemote.setValue("fcity", fcity, 11L);
+            paoRemote.setValue("fcounty", fcounty, 11L);
+            paoRemote.setValue("faddress", faddress, 11L);
+            paoRemote.setValue("tsalerid", tsalerid, 11L);
+            paoRemote.setValue("siteid", "JIUSHENG");
+            paoRemote.setValue("createby", username, 11L);
+            paoRemote.setValue("wechat_corpid", wechat_corpid, 11L);
+            paoRemote.setValue("wechat_corp_name", wechat_corp_name, 11L);
+            paoRemote.setValue("wechat_agentid", wechat_agentid, 11L);
+            paoSetRemote.save();
+        }
+        return getSucReturnObject().toString();
     }
 
     /**
@@ -77,8 +131,18 @@ public class tagents extends Controller {
      *
      * @return
      */
-    public String deleteTagents() {
-        return "";
+    public String deleteTagents() throws P2Exception {
+        String tagentsid = content.getString("tagentsid");
+        if (tagentsid == null || tagentsid.equals("")) {
+            return getErrReturnObject().setErrMsg("经销商id为空").toString();
+        }
+        PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tagents", "tagentsid = '" + tagentsid + "'");
+        if (!paoSetRemote.isEmpty()) {
+            PaoRemote paoRemote = paoSetRemote.getPao(0);
+            paoRemote.delete();
+            paoSetRemote.save();
+        }
+        return getSucReturnObject().toString();
     }
 
     /**
@@ -87,7 +151,13 @@ public class tagents extends Controller {
      * @return
      */
     public String selectTagentsList() {
-        return "";
+
+        SQLFactory sqlFactory = new SQLFactory(this, "经销商档案列表");
+        sqlFactory.addParameter("siteid", siteid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+
+        return getSucReturnObject().setData(rows).toString();
     }
 
+
 }

+ 15 - 1
src/dsb/com/cnd3b/restcontroller/enterprise/tdepartment/tdepartment.java

@@ -2,6 +2,7 @@ package com.cnd3b.restcontroller.enterprise.tdepartment;
 
 import com.alibaba.fastjson.JSONObject;
 import com.cnd3b.common.Controller;
+import com.cnd3b.utility.wechatdock.WechatDock_Enterprise;
 import p2.pao.PaoRemote;
 import p2.pao.PaoSetRemote;
 import p2.util.P2Exception;
@@ -25,7 +26,8 @@ public class tdepartment extends Controller {
         //下游企业ID、经销商ID
         String tagentsid = content.getString("tagentsid");
         //企业微信部门ID
-        String wechat_departmentid =  content.getString("wechat_departmentid");;
+        String wechat_departmentid = content.getString("wechat_departmentid");
+        ;
         //父部门id。根部门为1。
         String wechat_departmentparentid = "1";
         //在父部门中的次序值。order值大的排序靠前。值范围是[0, 2^32)。
@@ -77,4 +79,16 @@ public class tdepartment extends Controller {
     public String selectTdepartmentList() {
         return "";
     }
+
+    /**
+     * 获取微信下游企业信息
+     *
+     * @return
+     */
+    public String getWeChatDepartmentList() {
+//        int agentid = content.getIntValue("agentid");
+//        String corpid = content.getString("corpid");
+//        return getSucReturnObject().setData(WechatDock_Enterprise.getDepartmentList(agentid, corpid)).toString();
+        return "";
+    }
 }

+ 0 - 336
src/dsb/com/cnd3b/service/GetPolyvAnalysisBigData.java

@@ -1,336 +0,0 @@
-package com.cnd3b.service;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.cnd3b.common.BaseClass;
-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.polyv.Polyv;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-
-/**
- * 保利威统计数据查询,频率5分钟一次
- */
-public class GetPolyvAnalysisBigData extends BaseClass implements Runnable {
-    @Override
-    public void run() {
-
-        if (new SQLiteJDBC().checkServicesUsed("GetPolyvAnalysisBigData", false)) {
-            try {
-                getLiveData();//频道统计信息,占用资源少
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            try {
-                System.err.println("start:getLiveviewLog");
-                getLiveviewLog();//观众信息,占用资源大
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            try {
-                System.err.println("start:getLiveMessageList");
-                getLiveMessageList();//观众留言、占用资源较大
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            try {
-                System.err.println("start:getSessionStats");
-                getSessionStats();//场次统计信息,占用资源少
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-
-    }
-
-    /**
-     * 获取频道直播概览统计数据表,频道统计信息比较延迟,拉取昨天至今天的直播信息
-     */
-    public void getLiveData() {
-        DBConnect dbConnect = new DBConnect();
-        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where DATEADD(Day,1, lastlivedate)>=convert(varchar(10),getDate(),120) ").toArray("channelid");
-        Polyv polyv = new Polyv();
-        ArrayList<String> sqllist = new ArrayList<>();
-        String[] dates = new String[]{getDate_Str(-1), getDate_Str()};
-        for (String date : dates) {
-            JSONArray dataArray = polyv.getChannelSummary(channelids, date);
-            if (dataArray == null) {
-                continue;
-            }
-            for (Object o : dataArray) {
-                JSONObject contentsObject = (JSONObject) o;
-                String userId = contentsObject.getString("userId");
-                String channelId = contentsObject.getString("channelId");
-                String name = contentsObject.getString("name");
-                int pcPlayDuration = contentsObject.getInteger("pcPlayDuration");
-                long pcFlowSize = contentsObject.getLong("pcFlowSize");
-                int pcVideoView = contentsObject.getInteger("pcVideoView");
-                int pcUniqueViewer = contentsObject.getInteger("pcUniqueViewer");
-                int mobilePlayDuration = contentsObject.getInteger("mobilePlayDuration");
-                long mobileFlowSize = contentsObject.getLong("mobileFlowSize");
-                int mobileVideoView = contentsObject.getInteger("mobileVideoView");
-                int mobileUniqueViewer = contentsObject.getInteger("mobileUniqueViewer");
-                int livePcPlayDuration = contentsObject.getInteger("livePcPlayDuration");
-                int playbackPcPlayDuration = contentsObject.getInteger("playbackPcPlayDuration");
-                int liveMobilePlayDuration = contentsObject.getInteger("liveMobilePlayDuration");
-                int playbackMobilePlayDuration = contentsObject.getInteger("playbackMobilePlayDuration");
-                int unknownPcPlayDuration = contentsObject.getInteger("unknownPcPlayDuration");
-                int unknownMobilePlayDuration = contentsObject.getInteger("unknownMobilePlayDuration");
-                String creatorName = contentsObject.getString("creatorName");//
-
-                if (mobilePlayDuration > 0 || pcPlayDuration > 0) {
-                    SQLFactory sqlFactory = new SQLFactory(this, "频道直播概览统计数据插入");
-                    sqlFactory.addParameter("date", date);
-                    sqlFactory.addParameter("userid", userId);
-                    sqlFactory.addParameter("channelid", channelId);
-                    sqlFactory.addParameter("name", name);
-                    sqlFactory.addParameter("pcplayduration", pcPlayDuration);
-                    sqlFactory.addParameter("pcflowsize", pcFlowSize);
-                    sqlFactory.addParameter("pcvideoview", pcVideoView);
-                    sqlFactory.addParameter("pcuniqueviewer", pcUniqueViewer);
-                    sqlFactory.addParameter("mobileplayduration", mobilePlayDuration);
-                    sqlFactory.addParameter("mobileflowsize", mobileFlowSize);
-                    sqlFactory.addParameter("mobilevideoview", mobileVideoView);
-                    sqlFactory.addParameter("mobileuniqueviewer", mobileUniqueViewer);
-                    sqlFactory.addParameter("livepcplayduration", livePcPlayDuration);
-                    sqlFactory.addParameter("playbackpcplayduration", playbackPcPlayDuration);
-                    sqlFactory.addParameter("livemobileplayduration", liveMobilePlayDuration);
-                    sqlFactory.addParameter("playbackmobileplayduratio", playbackMobilePlayDuration);
-                    sqlFactory.addParameter("unknownpcplayduration", unknownPcPlayDuration);
-                    sqlFactory.addParameter("unknownmobileplayduration", unknownMobilePlayDuration);
-                    sqlFactory.addParameter("creatorname", creatorName);
-                    sqllist.add(sqlFactory.getSQL());
-                }
-            }
-            dbConnect.runSqlUpdate(sqllist);
-        }
-    }
-
-
-    public static void main(String[] args) {
-        GetPolyvAnalysisBigData getPolyvAnalysisBigData = new GetPolyvAnalysisBigData();
-        Polyv polyv = new Polyv();
-        //JSONObject object = polyv.getPageViewlog("2771246", getPolyvAnalysisBigData.getDate_Str(), "200", "1");
-        JSONArray object = polyv.getChannelSummary(new String[]{"2772308"}, "2022-01-08");
-        System.err.println(object);
-    }
-
-    /**
-     * 获取频道直播观看详情数据,频道统计信息比较延迟,拉取昨天至今天的直播信息
-     */
-    public void getLiveviewLog() {
-        DBConnect dbConnect = new DBConnect();
-        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where DATEADD(Day,1, lastlivedate)>=convert(varchar(10),getDate(),120)").toArray("channelid");
-        Polyv polyv = new Polyv();
-        String[] dates = new String[]{getDate_Str(-1), getDate_Str()};
-        for (String date : dates) {
-            for (String channelid : channelids) {
-                boolean islastpage = false;
-                int pageNumber = 1;
-                do {
-                    ArrayList<String> sqllist = new ArrayList<>();
-                    JSONObject object = polyv.getPageViewlog(channelid, date, "200", String.valueOf(pageNumber++));
-                    if (object == null) {
-                        break;
-                    }
-                    islastpage = object.getBoolean("lastPage");
-                    JSONArray contentsarray = object.getJSONArray("contents");
-                    if (contentsarray.isEmpty()) {
-                        break;
-                    }
-                    for (Object o : contentsarray) {
-                        JSONObject contentsObject = (JSONObject) o;
-                        String playId = contentsObject.getString("playId");
-                        String userId = contentsObject.getString("userId");
-                        String channelId = contentsObject.getString("channelId");
-                        int playDuration = contentsObject.getInteger("playDuration");
-                        int stayDuration = contentsObject.getInteger("stayDuration");
-                        long flowSize = contentsObject.getLong("flowSize");
-                        String sessionId = contentsObject.getString("sessionId");
-                        String param1 = contentsObject.getString("param1");
-                        String param2 = contentsObject.getString("param2");
-                        String param3 = contentsObject.getString("param3");
-                        String param4 = contentsObject.getString("param4");
-                        String param5 = contentsObject.getString("param5");
-                        String ipAddress = contentsObject.getString("ipAddress");
-                        String country = contentsObject.getString("country");
-                        String province = contentsObject.getString("province");
-                        String city = contentsObject.getString("city");
-                        String isp = contentsObject.getString("isp");
-                        String referer = contentsObject.getString("referer");
-                        String userAgent = contentsObject.getString("userAgent");
-                        String operatingSystem = contentsObject.getString("operatingSystem");
-                        String browser = contentsObject.getString("browser");
-                        String isMobile = contentsObject.getString("isMobile");
-                        String currentDay = contentsObject.getString("currentDay");
-                        long createdTime = contentsObject.getLong("createdTime");
-                        long lastModified = contentsObject.getLong("lastModified");
-                        int ptype = contentsObject.getInteger("ptype");
-
-                        SQLFactory sqlFactory = new SQLFactory(this, "频道直播观看详情数据插入");
-                        sqlFactory.addParameter("ptype", ptype);
-                        sqlFactory.addParameter("playid", playId);
-                        sqlFactory.addParameter("userid", userId);
-                        sqlFactory.addParameter("channelid", channelId);
-                        sqlFactory.addParameter("playduration", playDuration);
-                        sqlFactory.addParameter("stayduration", stayDuration);
-                        sqlFactory.addParameter("flowsize", flowSize);
-                        sqlFactory.addParameter("sessionid", sessionId);
-                        sqlFactory.addParameter("param1", param1);
-                        sqlFactory.addParameter("param2", param2);
-                        sqlFactory.addParameter("param3", param3);
-                        sqlFactory.addParameter("param4", param4);
-                        sqlFactory.addParameter("param5", param5);
-                        sqlFactory.addParameter("ipaddress", ipAddress);
-                        sqlFactory.addParameter("country", country);
-                        sqlFactory.addParameter("province", province);
-                        sqlFactory.addParameter("city", city);
-                        sqlFactory.addParameter("isp", isp);
-                        sqlFactory.addParameter("referer", referer);
-                        sqlFactory.addParameter("useragent", userAgent);
-                        sqlFactory.addParameter("operatingsystem", operatingSystem);
-                        sqlFactory.addParameter("browser", browser);
-                        sqlFactory.addParameter("ismobile", isMobile);
-                        sqlFactory.addParameter("currentday", currentDay);
-                        sqlFactory.addParameter("createdtime", createdTime);
-                        sqlFactory.addParameter("lastmodified", lastModified);
-                        sqllist.add(sqlFactory.getSQL());
-                    }
-                    dbConnect.runSqlUpdate(sqllist);
-                } while (!islastpage);
-            }
-        }
-    }
-
-
-    /**
-     * 获取频道直播观众聊天记录,信息获取延迟时间短,拉取当日该场次最新聊天记录时间之后的聊天信息
-     */
-    public void getLiveMessageList() {
-        DBConnect dbConnect = new DBConnect();
-        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus in('live','waiting') and convert(varchar(10),lastlivedate,120)=convert(varchar(10),getDate(),120) ").toArray("channelid");
-        Polyv polyv = new Polyv();
-        for (String channelid : channelids) {
-            String startdate = getDate_Str();
-            Rows maxtimerows = dbConnect.runSqlQuery("select isnull(max(time),0) as ftime from tlive_usermessages where channelid='" + channelid + "' having isnull(max(time),0)>0");
-            if (!maxtimerows.isEmpty()) {
-                Calendar calendar = Calendar.getInstance();
-                calendar.setTimeInMillis(Long.parseLong(maxtimerows.get(0).getString("ftime")) + 1000);
-                startdate = getDateTime_Str(calendar.getTime());
-            }
-            ArrayList<String> sqllist = new ArrayList<>();
-            boolean islastpage;
-            int pageNumber = 1;
-            do {
-                JSONObject object = polyv.getPageMessageList(channelid, startdate, getDate_Str(), "200", String.valueOf(pageNumber++));
-                if (object == null) {
-                    break;
-                }
-                JSONArray contentsarray = object.getJSONArray("contents");
-                if (contentsarray.isEmpty()) {
-                    break;
-                }
-                islastpage = contentsarray.size() == 0;
-                for (Object o : contentsarray) {
-                    JSONObject contentsObject = (JSONObject) o;
-                    String id = contentsObject.getString("id");
-                    String accountId = contentsObject.getString("accountId");
-                    String clientIP = contentsObject.getString("clientIP");
-                    String content = contentsObject.getString("content");
-                    String event = contentsObject.getString("event");
-                    String image = contentsObject.getString("image");
-                    String msgType = contentsObject.getString("msgType");
-                    String quote = contentsObject.getString("quote");
-                    String sessionId = contentsObject.getString("sessionId");
-                    String roomId = contentsObject.getString("roomId");
-                    String channelId = contentsObject.getString("channelId");
-                    String time = contentsObject.getString("time");
-                    String userType = contentsObject.getString("userType");
-                    String status = contentsObject.getString("status");
-                    String sourceType = contentsObject.getString("sourceType");
-
-                    JSONObject userObject = contentsObject.getJSONObject("user");
-
-                    String actor = userObject.getString("actor");
-                    boolean banned = userObject.getBoolean("banned");
-                    String nickname = userObject.getString("nickname");
-                    String pic = userObject.getString("pic");
-                    String uid = userObject.getString("uid");
-                    String userId = userObject.getString("userId");
-                    String userSource = userObject.getString("userSource");
-
-                    SQLFactory sqlFactory = new SQLFactory(this, "频道直播观众聊天记录数据插入");
-                    sqlFactory.addParameter("id", id);
-                    sqlFactory.addParameter("accountid", accountId);
-                    sqlFactory.addParameter("clientip", clientIP);
-                    sqlFactory.addParameter("content", content);
-                    sqlFactory.addParameter("event", event);
-                    sqlFactory.addParameter("imageurl", image);
-                    sqlFactory.addParameter("msgtype", msgType);
-                    sqlFactory.addParameter("quote", quote);
-                    sqlFactory.addParameter("sessionid", sessionId);
-                    sqlFactory.addParameter("roomid", roomId);
-                    sqlFactory.addParameter("channelid", channelId);
-                    sqlFactory.addParameter("time", time);
-                    sqlFactory.addParameter("usertype", userType);
-                    sqlFactory.addParameter("status", status);
-                    sqlFactory.addParameter("sourcetype", sourceType);
-                    sqlFactory.addParameter("actor", actor);
-                    sqlFactory.addParameter("banned", banned ? 1 : 0);
-                    sqlFactory.addParameter("nickname", nickname);
-                    sqlFactory.addParameter("pic", pic);
-                    sqlFactory.addParameter("uid", uid);
-                    sqlFactory.addParameter("userid", userId);
-                    sqlFactory.addParameter("usersource", userSource);
-                    sqllist.add(sqlFactory.getSQL());
-                }
-            } while (!islastpage);
-            dbConnect.runSqlUpdate(sqllist);
-        }
-    }
-
-    /**
-     * 查询频道多场次概览统计数据,场次统计信息比较延迟,拉取昨天至今天的直播场次信息
-     */
-    public void getSessionStats() {
-        DBConnect dbConnect = new DBConnect();
-        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where DATEADD(Day,1, lastlivedate)>=convert(varchar(10),getDate(),120)").toArray("channelid");
-        for (String channelid : channelids) {
-            Polyv polyv = new Polyv();
-            ArrayList<String> sqllist = new ArrayList<>();
-            JSONArray dataArray = polyv.getSessionStats(channelid);
-            if (dataArray == null) {
-                continue;
-            }
-            for (Object o : dataArray) {
-                JSONObject contentsObject = (JSONObject) o;
-                String channelId = contentsObject.getString("channelId");
-                String sessionId = contentsObject.getString("sessionId");
-                String name = contentsObject.getString("name");
-                String startTime = contentsObject.getString("startTime");
-                long duration = contentsObject.getLong("duration");
-                long liveUV = contentsObject.getLong("liveUV");
-                long livePV = contentsObject.getLong("livePV");
-                long playbackPV = contentsObject.getLong("playbackPV");
-                long playbackUV = contentsObject.getLong("playbackUV");
-                SQLFactory sqlFactory = new SQLFactory(this, "场次直播概览统计数据插入");
-
-                sqlFactory.addParameter("channelid", channelId);
-                sqlFactory.addParameter("sessionid", sessionId);
-                sqlFactory.addParameter("name", name);
-                sqlFactory.addParameter("starttime", startTime);
-                sqlFactory.addParameter("duration", duration);
-                sqlFactory.addParameter("liveuv", liveUV);
-                sqlFactory.addParameter("livepv", livePV);
-                sqlFactory.addParameter("playbackpv", playbackPV);
-                sqlFactory.addParameter("playbackuv", playbackUV);
-                sqllist.add(sqlFactory.getSQL());
-            }
-            dbConnect.runSqlUpdate(sqllist);
-        }
-    }
-}

+ 0 - 146
src/dsb/com/cnd3b/service/GetPolyvAnalysisData.java

@@ -1,146 +0,0 @@
-package com.cnd3b.service;
-
-import com.alibaba.fastjson.JSONObject;
-import com.cnd3b.common.BaseClass;
-import com.cnd3b.common.data.Rows;
-import com.cnd3b.common.data.RowsMap;
-import com.cnd3b.common.data.SQLFactory;
-import com.cnd3b.common.data.db.DBConnect;
-import com.cnd3b.common.data.db.SQLiteJDBC;
-import com.cnd3b.common.parameter.parameter;
-import com.cnd3b.common.websocket.WebClientSocket;
-import com.cnd3b.utility.polyv.Polyv;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-
-/**
- * 保利威统计数据查询,频率30秒一次
- */
-public class GetPolyvAnalysisData extends BaseClass implements Runnable {
-    @Override
-    public void run() {
-        if (new SQLiteJDBC().checkServicesUsed("GetPolyvAnalysisData", false)) {
-            try {
-                getLiveStatusAndCoverImageUrl();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            try {
-                getLiveUserCount();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    /**
-     * 同步频道直播状态,及获取直播封面图
-     */
-    public void getLiveStatusAndCoverImageUrl() {
-        DBConnect dbConnect = new DBConnect();
-        Rows channelRows = dbConnect.runSqlQuery("select channelid,livestatus,tagentsid,siteid from tlive");
-        String[] channelids = channelRows.toArray("channelid");
-        RowsMap map = channelRows.toRowsMap("channelid");
-        Polyv polyv = new Polyv();
-        HashMap<String, String> livestatusMap = new HashMap<>();
-        //最多同时查询20个频道
-        if (channelids.length > 20) {
-            int size = channelids.length / 20;
-            for (int i = 0; i < size; i++) {
-                livestatusMap.putAll(polyv.getLiveStatuses(Arrays.copyOfRange(channelids, i * 20, (i + 1) * 20)));
-            }
-            livestatusMap.putAll(polyv.getLiveStatuses(Arrays.copyOfRange(channelids, size * 20, channelids.length)));
-        } else {
-            livestatusMap = polyv.getLiveStatuses(channelids);
-        }
-
-        ArrayList<String> sqllist = new ArrayList<>();
-        for (String channelid : livestatusMap.keySet()) {
-            String livestatus = livestatusMap.get(channelid);
-            if (map.containsKey(channelid)) {
-                if (livestatus.equalsIgnoreCase("live")) {
-                    sqllist.add("update tlive set livestatus='" + livestatus + "',lastlivedate='" + getDate_Str() + "' ,channelcoverimageurl='" + polyv.getChannelImage(channelid, livestatus) + "' where channelid='" + channelid + "'");
-                    if (!livestatus.equals(map.get(channelid).get(0).getString("livestatus"))) {
-                        long tagentsid = map.get(channelid).get(0).getLong("tagentsid");
-                        String siteid = map.get(channelid).get(0).getString("siteid");
-                        createLiveMessage(siteid, tagentsid);
-                    }
-                } else if (livestatus.equalsIgnoreCase("waiting")) {
-                    sqllist.add("update tlive set livestatus='" + livestatus + "',channelcoverimageurl='" + polyv.getChannelImage(channelid, livestatus) + "' where channelid='" + channelid + "'");
-                } else {
-                    sqllist.add("update tlive set livestatus='" + livestatus + "' where channelid='" + channelid + "'");
-                }
-            }
-        }
-        dbConnect.runSqlUpdate(sqllist);
-    }
-
-    /**
-     * 创建开播提醒消息
-     */
-    private void createLiveMessage(String siteid, long tagentsid) {
-        try {
-            //如果从未直播状态变为直播状态,则创建系统消息提醒其合作商
-            DBConnect dbConnect = new DBConnect();
-            Rows agentRows = dbConnect.runSqlQuery("select * from tagents where siteid='" + siteid + "' and tagentsid='" + tagentsid + "'");
-            if (!agentRows.isEmpty()) {
-                String fbrand = agentRows.get(0).getString("fbrand");
-                Rows useridRows = dbConnect.runSqlQuery("select distinct t2.tenterprise_userid from tagents_cooperation t1 inner join tenterprise_users t2 on t1.siteid=t2.siteid and t1.tagentsid=t2.tagentsid where t1.tagentsid='" + tagentsid + "'");//获取其所有合作商的账号列表
-                ArrayList<String> userids = useridRows.toArrayList("tenterprise_userid");
-                SQLFactory factory = new SQLFactory(this, "系统消息插入");
-                factory.addParameter("siteid", siteid);
-                factory.addParameter("ftype", "商户");
-                factory.addParameter("ftitle", "开播提醒");
-                factory.addParameter("fmessage", "合作商户" + fbrand + "正在直播!");
-                factory.addParameter_in("tenterprise_userid", userids);
-                factory.addParameter("objectid", "null");
-                factory.addParameter("objectname", "null");
-                dbConnect.runSqlUpdate(factory.getSQL());
-                for (String id : userids) {
-                    long userid = Long.parseLong(id);
-                    if (parameter.websocketClients.containsKey(userid)) {
-                        JSONObject methodobject = new JSONObject();
-                        methodobject.put("type", "remind");//提醒
-                        methodobject.put("text", "合作商户" + fbrand + "正在直播!");
-                        for (WebClientSocket webClientSocket : parameter.websocketClients.get(userid).values()) {
-                            webClientSocket.sendSystemMessage(methodobject);
-                        }
-                    }
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-
-    /**
-     * 获取频道实时在线人数
-     */
-    public void getLiveUserCount() {
-        DBConnect dbConnect = new DBConnect();
-        ArrayList<String> sqllist = new ArrayList<>();
-        String[] channelids = dbConnect.runSqlQuery("select channelid from tlive where livestatus='live'").toArray("channelid");
-        Polyv polyv = new Polyv();
-        for (String channelid : channelids) {
-            JSONObject object = polyv.getRealtimeViewers(channelid);
-            String channelId = object.getString("channelId");
-            String time = object.getString("time");
-            String count = object.getString("count");
-
-            SQLFactory sqlFactory = new SQLFactory(this, "直播频道在线用户数插入");
-            sqlFactory.addParameter("channelid", channelId);
-            sqlFactory.addParameter("time", getDate_Str() + " " + time);
-            sqlFactory.addParameter("count", count);
-            sqllist.add(sqlFactory.getSQL());
-        }
-        dbConnect.runSqlUpdate(sqllist);
-
-        SQLFactory sqlFactory = new SQLFactory(this, "直播频道在线用户调整数更新");
-        sqlFactory.addParameter_in("channelid", channelids);
-        dbConnect.runSqlUpdate(sqlFactory);
-    }
-
-}

+ 227 - 0
src/dsb/com/cnd3b/service/GetWechatData.java

@@ -0,0 +1,227 @@
+package com.cnd3b.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.cnd3b.common.BaseClass;
+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.common.parameter.parameter;
+import com.cnd3b.utility.WebRequest;
+import com.cnd3b.utility.wechatdock.WechatDock_Enterprise;
+import p2.common.parse.A;
+import p2.pao.PaoRemote;
+import p2.pao.PaoSetRemote;
+import p2.util.P2Exception;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class GetWechatData extends BaseClass implements Runnable {
+
+    private String depname = "嘉兴多三边科技有限公司";
+
+    @Override
+    public void run() {
+        if (new SQLiteJDBC().checkServicesUsed("GetWechatData", false)) {
+            try {
+                System.err.println("GetWechatData Service start...");
+                getDepartmentList();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+        }
+    }
+
+    /**
+     * 获取企业微信部门列表
+     *
+     * @return
+     */
+    public JSONArray getDepartmentList() throws P2Exception {
+        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");
+        updateDepartment(array);
+        JSONArray userArray = new JSONArray();
+        JSONArray tagentsArray = new JSONArray();
+        int id = 0;
+        for (Object obj : array) {
+            JSONObject jsonObject = (JSONObject) obj;
+            String name = jsonObject.getString("name");
+            //查询部门名称为经销商的部门id
+            if (name.equals(depname)) {
+                id = jsonObject.getIntValue("id");
+            }
+            userArray.addAll(getDepartmentUsers(jsonObject.getIntValue("id"), 0));
+
+        }
+        //更新成员表
+        updateUser(userArray);
+        //更新经销商表
+
+        updateTagents(id);
+        return object.getJSONArray("department");
+    }
+
+    /**
+     * 获取企业微信部门成员列表
+     *
+     * @return
+     */
+    public JSONArray getDepartmentUsers(int id, int 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);
+        return object.getJSONArray("userlist");
+    }
+
+    public void updateDepartment(JSONArray array) throws P2Exception {
+        ArrayList<String> ids = new ArrayList<>();
+        for (Object obj : array) {
+            JSONObject jsonObject = (JSONObject) obj;
+            int id = jsonObject.getIntValue("id");
+            ids.add(id + "");
+
+            PaoSetRemote paoSetRemote = getP2ServerSystemPaoSet("tdepartment", "wechat_depid = '" + id + "'");
+            if (paoSetRemote.isEmpty()) {
+                PaoRemote paoRemote = paoSetRemote.addAtEnd();
+                paoRemote.setValue("wechat_depid", id, 11L);
+                paoRemote.setValue("wechat_parendeptid", jsonObject.getIntValue("parentid"), 11L);
+                paoRemote.setValue("wechat_depname", jsonObject.getString("name"), 11L);
+                paoSetRemote.save();
+            } else {
+                PaoRemote paoRemote = paoSetRemote.getPao(0);
+                paoRemote.setValue("wechat_depid", id, 11L);
+                paoRemote.setValue("wechat_parendeptid", jsonObject.getIntValue("parentid"), 11L);
+                paoRemote.setValue("wechat_depname", jsonObject.getString("name"), 11L);
+                paoSetRemote.save();
+            }
+        }
+        SQLFactory sqlFactory = new SQLFactory(this, "删除微信部门");
+        sqlFactory.addParameter_in("ids", ids);
+        new DBConnect().runSqlUpdate(sqlFactory.getSQL());
+    }
+
+    public void updateUser(JSONArray userArray) throws P2Exception {
+        ArrayList<String> ids = new ArrayList<>();
+        DBConnect dbConnect = new DBConnect();
+        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(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();
+            } else {
+                PaoRemote paoRemote = paoSetRemote.getPao(0);
+                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();
+            }
+
+
+        }
+        SQLFactory sqlFactory = new SQLFactory(this, "删除微信部门成员");
+        sqlFactory.addParameter_in("ids", ids);
+        dbConnect.runSqlUpdate(sqlFactory.getSQL());
+    }
+
+
+    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());
+    }
+
+}

+ 3 - 0
src/dsb/com/cnd3b/service/SQL/删除微信部门.sql

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

+ 3 - 0
src/dsb/com/cnd3b/service/SQL/删除微信部门成员.sql

@@ -0,0 +1,3 @@
+DELETE
+FROM tuser
+WHERE wechat_userid NOT IN $ids$

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

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

+ 42 - 0
src/dsb/com/cnd3b/utility/wechatdock/WechatDock_Enterprise.java

@@ -0,0 +1,42 @@
+package com.cnd3b.utility.wechatdock;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.cnd3b.common.BaseClass;
+import com.cnd3b.common.data.db.DBConnect;
+import com.cnd3b.utility.WebRequest;
+import p2.pao.PaoRemote;
+import p2.pao.PaoSetRemote;
+import p2.util.P2Exception;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+
+public class WechatDock_Enterprise extends BaseClass {
+    //企业ID
+    public static String corpid = "ww1679499b0ccbb304";
+    //应用的凭证密钥
+    public static String corpsecret = "VmoM0sWqot77xka1xxRb1cGZApLxW5sKvsmYQjSHH1o";
+    //企业应用agentid
+    public static long agentid = 1000003;
+    //有效期2小时,需定时刷新,重复获取将导致上次获取的失效
+    private static String access_token = "";
+    private static long access_token_timelimit = 0L;
+
+    public static String getAccessToken() {
+        long nowtime = Calendar.getInstance().getTimeInMillis();
+        if (access_token_timelimit < nowtime) {
+            String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + corpid + "&corpsecret=" + corpsecret;
+            String res = new WebRequest().doGet(url);
+            JSONObject resobject = JSONObject.parseObject(res);
+            System.err.println(resobject);
+            if (resobject.containsKey("access_token")) {
+                access_token = resobject.getString("access_token");
+                access_token_timelimit = nowtime + 1000 * resobject.getIntValue("expires_in");
+            }
+        }
+        return access_token;
+    }
+
+
+}