Exemple #1
0
        private void PushProc()
        {
            string rMsg = string.Empty;

            try
            {
                string    rSql = "select JLBH,CONTENT from s_pushfy_000020 where sendTime is null";
                DataTable dt   = new DataTable();
                SHOPDB_Center.DB2012Class_GetDataRefTable(rSql, ref rMsg, dt);

                if (rMsg != "")
                {
                    LogHelper.Logger.ErrorFormat("Name={0},查询推送数据出错:" + rMsg, _se.Name);
                    return;
                }

                if (dt.Rows.Count == 0)
                {
                    LogHelper.Logger.InfoFormat("Name={0},没有可推送的数据!", _se.Name);
                    return;
                }
                WebSKPFY.FService f = new WebSKPFY.FService();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string  result    = f.ReceiveFY_LGB(dt.Rows[i]["CONTENT"].ToString());
                    JObject tmpResult = (JObject)JsonConvert.DeserializeObject(result);
                    string  pFLAG     = (tmpResult.GetValue("FLAG") ?? "").ToString();
                    string  pMSG      = (tmpResult.GetValue("MSG") ?? "").ToString();

                    if (pFLAG == "0")
                    {
                        rSql = "update s_pushfy_000020 set sendTime = sysdate where JLBH = :pJLBH~pJLBH,NUMBER," + dt.Rows[i]["JLBH"].ToString();
                        SHOPDB_Center.DB2012Class_ExecOneCommand(rSql, ref rMsg);
                        if (rMsg != "")
                        {
                            LogHelper.Logger.ErrorFormat("Name={0},推送[" + dt.Rows[i]["JLBH"].ToString() + "]更新推送结果出错," + rMsg, _se.Name);
                        }
                        else
                        {
                            LogHelper.Logger.InfoFormat("Name={0},推送[" + dt.Rows[i]["JLBH"].ToString() + "]成功", _se.Name);
                        }
                    }
                    else
                    {
                        LogHelper.Logger.ErrorFormat("Name={0},推送[" + dt.Rows[i]["JLBH"].ToString() + "]出错," + result, _se.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Logger.ErrorFormat("Name={0},推送出错," + ex.Message, _se.Name); return;
            }
        }
Exemple #2
0
        private void PushProc()
        {
            string rMsg = string.Empty;

            try
            {
                //找推送报表的时间点,人员。
                string    selectAllTS = "select RID,CODE,SJD,SHOPCODE from BUCOWNER.BMCP_WeChat_Auth@BUCENTER ";
                DataTable dt          = new DataTable();
                DB_Center.DB2012Class_GetDataRefTable(selectAllTS, ref rMsg, dt);
                if (rMsg != "")
                {
                    LogHelper.Logger.ErrorFormat("查询推送报表和人员信息出错,", _se.Name);
                    return;
                }
                if (dt.Rows.Count == 0)
                {
                    LogHelper.Logger.InfoFormat("没有要推送的报表和人员!", _se.Name);
                    return;
                }
                int    hour   = DateTime.Now.Hour;
                int    Minute = DateTime.Now.Minute;
                string strT   = DateTime.Now.ToString("s").Substring(0, DateTime.Now.ToString("s").IndexOf('T'));//2003-09-23
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string rid      = dt.Rows[i]["RID"].ToString();      //报表id
                    string code     = dt.Rows[i]["CODE"].ToString();     //人员code
                    string sjd      = dt.Rows[i]["SJD"].ToString();      //时间点
                    string SHOPCODE = dt.Rows[i]["SHOPCODE"].ToString(); //SHOPCODE
                    if (SHOPCODE == null || SHOPCODE != "000004")
                    {
                        continue;
                    }
                    string[] sjdsz = sjd.Split(',');

                    if (sjd != null && sjd != "" && sjdsz.Length > 0)
                    {
                        for (int j = 0; j < sjdsz.Length; j++)
                        {
                            if (hour.ToString() == sjdsz[j].ToString())
                            {//当前时间点 == 数据库中的时间
                                if (Minute != 10)
                                {
                                    return;
                                }

                                //找数据库中有没有插入,当前时间点,当前人员,当前报表的信息。

                                string selectHasSql = "select JLBH ,to_char(CREATETIME, 'YYYY-MM-dd hh24') CREATETIME,OPENID,RID from bmcp_wechat_send "
                                                      + " where OPENID = (select OPENID from L_SHOP_USER where CODE = '" + code + "' ) "
                                                      + " and to_char(CREATETIME,'YYYY-MM-dd hh24') = '" + (strT + " " + hour) + "'"
                                                      + " and RID = " + rid;
                                DataTable dtHas = new DataTable();
                                DB_Center.DB2012Class_GetDataRefTable(selectHasSql, ref rMsg, dtHas);
                                if (rMsg != "")
                                {
                                    LogHelper.Logger.ErrorFormat("查询微信推送报表信息出错", _se.Name);
                                    return;
                                }
                                if (dtHas.Rows.Count != 0)
                                {
                                    //LogHelper.Logger.InfoFormat("已经添加过了不需要再次添加", _se.Name);
                                    continue;
                                }

                                string touser      = "";
                                string template_id = "";
                                string url         = "";
                                string shopCode2   = "";
                                string RBELONG     = "";

                                //找推送报表,的RID,RURL,
                                string sel = "select bw.RID,bw.RNAME,bw.RURL,bw.TSQL,bw.SHOPCODE,(select SHOPNAME from L_SHOP where SHOPCODE=bw.SHOPCODE) SHOPNAME,bw.RBELONG,bt.TEMPLATE_ID "
                                             + " from BUCOWNER.BMCP_WeChat_Rule @BUCENTER bw,BUCOWNER.BMCP_WeChat_TEMPLATE @BUCENTER bt where bw.TID = bt.TID and bw.RSTATUS = 1 and bw.RID = " + rid;
                                DataTable dtt = new DataTable();
                                DB_Center.DB2012Class_GetDataRefTable(sel, ref rMsg, dtt);
                                if (rMsg != "")
                                {
                                    LogHelper.Logger.ErrorFormat("查询报表详细信息出错,编号为" + rid, _se.Name);
                                    return;
                                }
                                if (dtt.Rows.Count == 0)
                                {
                                    LogHelper.Logger.InfoFormat("没有编号为" + rid + "的报表详细信息!", _se.Name);
                                    continue;
                                }
                                url         = dtt.Rows[0]["RURL"].ToString() + "?RQ=" + strT + "%26SJD=" + hour;//%26为url编码时&符号
                                shopCode2   = dtt.Rows[0]["SHOPCODE"].ToString();
                                template_id = dtt.Rows[0]["TEMPLATE_ID"].ToString();
                                string sql      = dtt.Rows[0]["TSQL"].ToString().Replace("\"", "'");
                                string shopName = dtt.Rows[0]["SHOPNAME"].ToString();
                                RBELONG = dtt.Rows[0]["RBELONG"].ToString();
                                string RNAME = dtt.Rows[0]["RNAME"].ToString();

                                if (!SHOPCODE.Equals(shopCode2))
                                {
                                    continue;
                                }

                                //根据人员CODE,找openid
                                string    sqlUser = "******" + code + "'";
                                DataTable dtUser  = new DataTable();
                                DB_Center.DB2012Class_GetDataRefTable(sqlUser, ref rMsg, dtUser);
                                if (rMsg != "")
                                {
                                    LogHelper.Logger.ErrorFormat("查询人员账号为" + code + "详细信息出错,", _se.Name);
                                    return;
                                }
                                if (dtUser.Rows.Count == 0)
                                {
                                    LogHelper.Logger.InfoFormat("没有人员账号为" + code + "的详细信息!", _se.Name);
                                    continue;
                                }

                                if (dtUser.Rows[0]["OPENID"] == null || dtUser.Rows[0]["OPENID"].ToString() == "")
                                {
                                    LogHelper.Logger.InfoFormat("账号为" + code + "人员没有绑定微信账号,无法推送!", _se.Name);
                                    continue;
                                }
                                touser = dtUser.Rows[0]["OPENID"].ToString(); //人员的openid
                                                                              //组装推送的内容
                                string    firstVl    = shopName + "\\n" + strT + RNAME;
                                string    keyword1Vl = "";
                                string    keyword2Vl = "";
                                DataTable dtyy       = new DataTable();


                                SHOPDB_Center.DB2012Class_GetDataRefTable(sql, ref rMsg, dtyy);
                                if (rMsg != "")
                                {
                                    LogHelper.Logger.ErrorFormat("查询出错,", _se.Name);
                                    return;
                                }
                                if (dtyy.Rows.Count == 0 || dtyy.Rows[0]["keyword1"] == null || dtyy.Rows[0]["keyword1"].ToString() == "")
                                {
                                    keyword1Vl = "0元";
                                    keyword2Vl = "0笔";
                                }
                                else
                                {
                                    keyword1Vl = dtyy.Rows[0]["keyword1"].ToString() + "元";
                                    keyword2Vl = dtyy.Rows[0]["keyword2"].ToString() + "笔";
                                }

                                string all = "{\"touser\":\"" + touser + "\",\"template_id\":\"" + template_id + "\",\"url\":\"" + url
                                             + "\",\"data\":{\"first\":{\"value\":\"" + firstVl + "\" } ,\"keyword1\":{\"value\":\"" + keyword1Vl + "\" },\"keyword2\":{\"value\":\"" + keyword2Vl + "\" },\"remark\":{\"value\":\"点击了解详情\" } } }";

                                //找推送表的id
                                string tsjlbh = DB_Center.DB2012Class_SelectDataFromOne("SELECT bmcp_wechat_send_tb_seq.NEXTVAL FROM DUAL", ref rMsg);
                                if (rMsg != "")
                                {
                                    LogHelper.Logger.ErrorFormat("生成记录推送编号出错,", _se.Name);
                                    return;
                                }
                                //插入信息
                                string insertSql = "insert into bmcp_wechat_send(JLBH,shopcode,bmcp_lx,createtime,openid,sendcontent,RID) "
                                                   + " values('" + tsjlbh + "','" + shopCode2 + "', '" + RBELONG + "', sysdate, '" + touser + "','" + all + "'," + rid + ") ";
                                DB_Center.DB2012Class_ExecOneCommand(insertSql, ref rMsg, true);
                                if (rMsg == "")
                                {
                                    LogHelper.Logger.InfoFormat("生成推送记录成功,编号为" + tsjlbh, _se.Name);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Logger.ErrorFormat("生成推送内容出错" + ex.Message, _se.Name); return;
            }
        }