|
@@ -1,9 +1,11 @@
|
|
|
using System;
|
|
|
using System.Linq;
|
|
|
+using System.Data;
|
|
|
using System.Threading;
|
|
|
using Library;
|
|
|
using LitJson;
|
|
|
using MySystem.Models.Push;
|
|
|
+using System.Collections.Generic;
|
|
|
|
|
|
namespace MySystem
|
|
|
{
|
|
@@ -34,25 +36,109 @@ namespace MySystem
|
|
|
public void DoSomeThing()
|
|
|
{
|
|
|
WebCMSEntities db = new WebCMSEntities();
|
|
|
-
|
|
|
- db.Dispose();
|
|
|
- }
|
|
|
-
|
|
|
- //创建表
|
|
|
- public void CreateTable(string Title, string tableName, string fieldList)
|
|
|
- {
|
|
|
- string sql = "CREATE TABLE `" + tableName + "` (\n";
|
|
|
- sql += "`id` int(11) NOT NULL AUTO_INCREMENT,\n";
|
|
|
- sql += "`status` int(11) NOT NULL,\n";
|
|
|
- JsonData fieldJson = JsonMapper.ToObject(fieldList);
|
|
|
- for (int i = 0; i < fieldJson.Count; i++)
|
|
|
+ //查找开通推送的商户
|
|
|
+ var merchants = db.Merchant.Where(m => m.Status == 1).ToList();
|
|
|
+ foreach(var merchant in merchants)
|
|
|
{
|
|
|
- JsonData item = fieldJson[i];
|
|
|
- sql += "`" + item["name"].ToString() + "` varchar(" + item["len"].ToString() + ") DEFAULT NULL COMMENT '" + item["title"].ToString() + "',\n";
|
|
|
+ string RsaPubKey = merchant.RsaPubKey;
|
|
|
+ string RsaPriKey = merchant.RsaPriKey;
|
|
|
+ string AesSecret = merchant.AesSecret;
|
|
|
+ string MerchantNo = merchant.MerchantNo;
|
|
|
+ string MerchantName = merchant.MerchantName;
|
|
|
+
|
|
|
+ //查找商户开通的推送项目
|
|
|
+ var pushObj = db.PushObj.Where(m => m.Status == 1 && m.MerchantId == merchant.Id).ToList();
|
|
|
+ foreach(var pushItem in pushObj)
|
|
|
+ {
|
|
|
+ string FieldList = pushItem.FieldList;
|
|
|
+ string TableName = pushItem.TableName;
|
|
|
+ int EncryptMode = pushItem.EncryptMode;
|
|
|
+ string NoticeUrl = pushItem.NoticeUrl;
|
|
|
+ string Title = pushItem.Title;
|
|
|
+ int MerchantId = pushItem.MerchantId;
|
|
|
+
|
|
|
+ //构造抓取数据sql
|
|
|
+ string sql = "select " + FieldList.TrimEnd(',') + " from u_" + TableName + " where 1=1";
|
|
|
+ var condiList = db.PushObjCondition.Where(m => m.PushObjId == pushItem.Id).ToList();
|
|
|
+ foreach(var condi in condiList)
|
|
|
+ {
|
|
|
+ int QueryCondition = condi.QueryCondition;
|
|
|
+ if(QueryCondition == 1)
|
|
|
+ {
|
|
|
+ sql += " and " + condi.QueryField + "='" + condi.QueryVal + "'";
|
|
|
+ }
|
|
|
+ else if(QueryCondition == 2)
|
|
|
+ {
|
|
|
+ sql += " and " + condi.QueryField + " like '%" + condi.QueryVal + "%'";
|
|
|
+ }
|
|
|
+ else if(QueryCondition == 3)
|
|
|
+ {
|
|
|
+ string[] QueryValList = condi.QueryVal.Split('|');
|
|
|
+ sql += " and " + condi.QueryField + ">=" + QueryValList[0] + " and " + condi.QueryField + "<=" + QueryValList[1] + "";
|
|
|
+ }
|
|
|
+ else if(QueryCondition == 4)
|
|
|
+ {
|
|
|
+ string[] QueryValList = condi.QueryVal.Split('|');
|
|
|
+ sql += " and " + condi.QueryField + ">='" + QueryValList[0] + "' and " + condi.QueryField + "<='" + QueryValList[1] + "'";
|
|
|
+ }
|
|
|
+ else if(QueryCondition == 5)
|
|
|
+ {
|
|
|
+ sql += " and " + condi.QueryField + " in (" + condi.QueryVal + ")";
|
|
|
+ }
|
|
|
+ else if(QueryCondition == 6)
|
|
|
+ {
|
|
|
+ sql += " and " + condi.QueryField + " in ('" + condi.QueryVal.Replace(",", "','") + "')";
|
|
|
+ }
|
|
|
+ else if(QueryCondition == 7)
|
|
|
+ {
|
|
|
+ string[] QueryValList = condi.QueryVal.Split(',');
|
|
|
+ sql += " and (";
|
|
|
+ int index = 0;
|
|
|
+ foreach(string QueryVal in QueryValList)
|
|
|
+ {
|
|
|
+ index += 1;
|
|
|
+ sql += condi.QueryField + "=" + QueryVal;
|
|
|
+ if(index < QueryValList.Length)
|
|
|
+ {
|
|
|
+ sql += " or ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sql += ")";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sql += " and " + condi.QueryField + "=" + condi.QueryVal;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //抓取数据开始post数据
|
|
|
+ DataTable dt = CustomerSqlConn.dtable(sql, AppConfig.Base.SqlConnStr);
|
|
|
+ foreach(DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ SortedList<string, string> obj = new SortedList<string, string>();
|
|
|
+ foreach(DataColumn dc in dt.Columns)
|
|
|
+ {
|
|
|
+ obj.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
|
|
|
+ }
|
|
|
+ if(EncryptMode == 1)
|
|
|
+ {
|
|
|
+ string content = EncryptHelper.Encrypt1(obj, AesSecret);
|
|
|
+ obj = new SortedList<string, string>();
|
|
|
+ obj.Add("type", Title);
|
|
|
+ obj.Add("notice_id", Guid.NewGuid().ToString());
|
|
|
+ obj.Add("timestamp", DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8));
|
|
|
+ obj.Add("content", content);
|
|
|
+ string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
|
|
|
+ string result = function.PostWebRequest(NoticeUrl, requestJson, "application/json");
|
|
|
+ if(result.Contains("\"code\":\"200\""))
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- sql += "PRIMARY KEY (`id`)\n";
|
|
|
- sql += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='" + Title + "';";
|
|
|
- CustomerSqlConn.op(sql, AppConfig.Base.SqlConnStr);
|
|
|
+ db.Dispose();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|