1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data;
  6. using System.Xml;
  7. using System.Collections;
  8. using MySql.Data.MySqlClient;
  9.  
  10. /// <summary>
  11. /// Summary description for MySqlHelper
  12. /// </summary>
  13. public sealed class MySqlHelper
  14. {
  15. private static readonly string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionStringMySql"].ConnectionString;
  16. public static readonly string connectionString1 = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionStringMySql1"].ConnectionString;
  17. public static readonly string connectionString2 = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionStringMySql2"].ConnectionString;
  18. public static readonly string connectionString3 = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionStringMySql3"].ConnectionString;
  19. public static readonly string connectionString4 = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionStringMySql4"].ConnectionString;
  20. public MySqlHelper()
  21. {
  22. }
  23.  
  24. public static DataSet ExecuteDataset(CommandType commandType, string commandText, params MySqlParameter[] commandParameters)
  25. {
  26. using (MySqlConnection cn = new MySqlConnection(connectionString))
  27. {
  28. cn.Open();
  29. return ExecuteDataset(cn, commandType, commandText, commandParameters);
  30. }
  31. }
  32.  
  33. public static DataSet ExecuteDatasetNew(CommandType commandType, string commandText, string newconntentString,params MySqlParameter[] commandParameters)
  34. {
  35. using (MySqlConnection cn = new MySqlConnection(newconntentString))
  36. {
  37. cn.Open();
  38. return ExecuteDataset(cn, commandType, commandText, commandParameters);
  39. }
  40. }
  41.  
  42. public static DataSet ExecuteDataset(MySqlConnection connection, CommandType commandType, string commandText, params MySqlParameter[] commandParameters)
  43. {
  44. MySqlCommand cmd = new MySqlCommand();
  45. cmd.CommandTimeout = ;
  46. PrepareCommand(cmd, connection, (MySqlTransaction)null, commandType, commandText, commandParameters);
  47. MySqlDataAdapter da = new MySqlDataAdapter(cmd);
  48. DataSet ds = new DataSet();
  49. da.Fill(ds);
  50. return ds;
  51. }
  52.  
  53. private static void PrepareCommand(MySqlCommand command, MySqlConnection connection, MySqlTransaction transaction, CommandType commandType, string commandText, MySqlParameter[] commandParameters)
  54. {
  55. if (connection.State != ConnectionState.Open)
  56. {
  57. Console.WriteLine("open");
  58. connection.Open();
  59. }
  60. command.Connection = connection;
  61. command.CommandText = commandText;
  62. if (transaction != null)
  63. {
  64. transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
  65. }
  66. command.CommandType = commandType;
  67. if (commandParameters != null)
  68. {
  69. AttachParameters(command, commandParameters);
  70. }
  71. return;
  72. }
  73.  
  74. private static void AttachParameters(MySqlCommand command, MySqlParameter[] commandParameters)
  75. {
  76. foreach (MySqlParameter p in commandParameters)
  77. {
  78. //check for derived output value with no value assigned
  79. if ((p.Direction == ParameterDirection.InputOutput) && (p.Value == null))
  80. {
  81. p.Value = DBNull.Value;
  82. }
  83.  
  84. command.Parameters.Add(p);
  85. }
  86. }
  87. }

以上是help类。

接着是GetAdspaceReportForMD_HourlyNew,GetMediaBuyReportFromHourlyNew,GetAdFormatReportHourlyNew,GetAdFormatReportHourlyALLNew调用:

  1. public static List<AdSpaceHourlyNew> GetAdspaceReportForMD_HourlyNew(DateTime start, DateTime end, String aid)
  2. {
  3. List<AdSpaceHourlyNew> result = new List<AdSpaceHourlyNew>();
  4. List<AdSpaceHourlyNew> result1 = new List<AdSpaceHourlyNew>();
  5. List<AdSpaceHourlyNew> result2 = new List<AdSpaceHourlyNew>();
  6. AdSpaceIdForHourly adspaceinfo = new AdSpaceIdForHourly();
  7.  
  8. string[] constr = new[] { MySqlHelper.connectionString1, MySqlHelper.connectionString3, MySqlHelper.connectionString4 };
  9.  
  10. string sqladspace = @"SELECT AD.ID,AD.NAME,AD.ROAD_BLOCK_GROUP_ID FROM AD_SPACE AD WHERE id=:AID";
  11. OracleParameter para2 = new OracleParameter(":AID", OracleType.Int32);
  12. para2.Value = aid;
  13. OracleParameter[] paras = { para2 };
  14. DataTable dtadspace = OracleHelper.ExecuteDataset(CONNECTION_STRING, CommandType.Text, sqladspace, paras).Tables[];
  15.  
  16. if (dtadspace.Rows.Count > )
  17. {
  18. adspaceinfo = new AdSpaceIdForHourly()
  19. {
  20. RoadBlockGroupId = Convert.ToInt32(dtadspace.Rows[]["ROAD_BLOCK_GROUP_ID"]),
  21. AdSpaceId = Convert.ToInt32(dtadspace.Rows[]["ID"]),
  22. AdSpaceName = dtadspace.Rows[]["NAME"].ToString()
  23. };
  24. }
  25.  
  26. String sqlhourly = @"SELECT date_format(SETTLED_TIME,'%Y-%m-%d %H') SETTLED_TIME, SUM(COUNT) AS PV
  27. FROM REPORT_DATA_HOURLY_CASUAL_NCT R
  28. WHERE
  29. (ACTION_TYPE,PROCESS_STATUS) IN ((2,3),(7,1),(2,5),(2,0),(2,4),(8,1),(2,2),(7,2),(8,4))
  30. AND R.AD_SPACE_ID=@AID
  31. AND SETTLED_TIME>=@ST AND SETTLED_TIME<@ET
  32. GROUP BY date_format(SETTLED_TIME,'%Y-%m-%d %H')";
  33. MySqlParameter[] orp = new MySqlParameter[] {
  34. new MySqlParameter("@AID", aid),
  35. new MySqlParameter("@ST", start),
  36. new MySqlParameter("@ET", end)
  37. };
  38. #region
  39. for (int i = ; i < ; i++)
  40. {
  41. DataTable dt1 = MySqlHelper.ExecuteDatasetNew(CommandType.Text, sqlhourly, constr[i], orp).Tables[];
  42. if (dt1.Rows.Count > )
  43. {
  44. for (int x = ; x < dt1.Rows.Count; x++)
  45. {
  46. var r = result1.Find(os => os.SettledTime == dt1.Rows[x]["SETTLED_TIME"].ToString());
  47. if (r == null)
  48. {
  49. result1.Add(new AdSpaceHourlyNew()
  50. {
  51. SettledTime = dt1.Rows[x]["SETTLED_TIME"].ToString(),
  52. AdSpaceId = adspaceinfo.AdSpaceId,
  53. AdSpaceName = adspaceinfo.AdSpaceName,
  54. Pv = Convert.ToInt64(dt1.Rows[x]["PV"])
  55. });
  56. }
  57. else
  58. {
  59. r.Pv += Convert.ToInt64(dt1.Rows[x]["PV"]);
  60. }
  61. }
  62. }
  63. }
  64. #endregion
  65.  
  66. string sqlhourlypv = string.Empty;
  67. if (IfRB(aid))
  68. {
  69. sqlhourlypv = @"SELECT date_format(SETTLED_TIME,'%Y-%m-%d %H') SETTLED_TIME,SUM(ADV_IMP_PAID) AS ADV,SUM(PUB_IMP_PAID) AS PUB,
  70. SUM(CLICKS)AS CLICKS FROM REPORT_DATA_HOURLY_NOCITY R WHERE R.ROADBLOCK_ID=@ROAD_BLOCK_GROUP_ID AND ADV_FLAG=1 AND SETTLED_TIME>=@ST AND SETTLED_TIME<@ET
  71. GROUP BY date_format(SETTLED_TIME,'%Y-%m-%d %H')";
  72. MySqlParameter[] orp1 = new MySqlParameter[] {
  73. new MySqlParameter("@ROAD_BLOCK_GROUP_ID", adspaceinfo.RoadBlockGroupId),
  74. new MySqlParameter("@ST", start),
  75. new MySqlParameter("@ET", end)
  76. };
  77. for (int i = ; i < ; i++)
  78. {
  79. DataTable dt1 = MySqlHelper.ExecuteDatasetNew(CommandType.Text, sqlhourlypv, constr[i], orp1).Tables[];
  80. if (dt1.Rows.Count > )
  81. {
  82. for (int y = ; y < dt1.Rows.Count; y++)
  83. {
  84. var r = result1.Find(os => os.SettledTime == dt1.Rows[y]["SETTLED_TIME"].ToString());
  85. if (r == null)
  86. {
  87. result2.Add(new AdSpaceHourlyNew()
  88. {
  89. SettledTime = dt1.Rows[y]["SETTLED_TIME"].ToString(),
  90. AdSpaceId = adspaceinfo.AdSpaceId,
  91. AdSpaceName = adspaceinfo.AdSpaceName,
  92. Adv = Convert.ToInt64(dt1.Rows[y]["ADV"]),
  93. Pub = Convert.ToInt64(dt1.Rows[y]["PUB"]),
  94. Clicks = Convert.ToInt64(dt1.Rows[y]["CLICKS"])
  95. });
  96. }
  97. else
  98. {
  99. r.Adv += Convert.ToInt64(dt1.Rows[y]["ADV"]);
  100. r.Pub += Convert.ToInt64(dt1.Rows[y]["PUB"]);
  101. r.Clicks += Convert.ToInt64(dt1.Rows[y]["CLICKS"]);
  102. }
  103. }
  104. }
  105. }
  106. }
  107. else
  108. {
  109. sqlhourlypv = @"SELECT date_format(SETTLED_TIME,'%Y-%m-%d %H') SETTLED_TIME,SUM(ADV_IMP_PAID) AS ADV,SUM(PUB_IMP_PAID) AS PUB,
  110. SUM(CLICKS)AS CLICKS FROM REPORT_DATA_HOURLY_NOCITY R WHERE R.AD_SPACE_ID=@ROAD_BLOCK_GROUP_ID AND ADV_FLAG=1 AND SETTLED_TIME>=@ST AND SETTLED_TIME<@ET
  111. GROUP BY date_format(SETTLED_TIME,'%Y-%m-%d %H')";
  112. MySqlParameter[] orp1 = new MySqlParameter[] {
  113. new MySqlParameter("@ROAD_BLOCK_GROUP_ID", adspaceinfo.AdSpaceId),
  114. new MySqlParameter("@ST", start),
  115. new MySqlParameter("@ET", end)
  116. };
  117. for (int i = ; i < ; i++)
  118. {
  119. DataTable dt1 = MySqlHelper.ExecuteDatasetNew(CommandType.Text, sqlhourlypv, constr[i], orp1).Tables[];
  120. if (dt1.Rows.Count > )
  121. {
  122. for (int y = ; y < dt1.Rows.Count; y++)
  123. {
  124. var r = result2.Find(os => os.SettledTime == dt1.Rows[y]["SETTLED_TIME"].ToString());
  125. if (r == null)
  126. {
  127. result2.Add(new AdSpaceHourlyNew()
  128. {
  129. SettledTime = dt1.Rows[y]["SETTLED_TIME"].ToString(),
  130. AdSpaceId = adspaceinfo.AdSpaceId,
  131. AdSpaceName = adspaceinfo.AdSpaceName,
  132. Adv = Convert.ToInt64(dt1.Rows[y]["ADV"]),
  133. Pub = Convert.ToInt64(dt1.Rows[y]["PUB"]),
  134. Clicks = Convert.ToInt64(dt1.Rows[y]["CLICKS"])
  135. });
  136. }
  137. else
  138. {
  139. r.Adv += Convert.ToInt64(dt1.Rows[y]["ADV"]);
  140. r.Pub += Convert.ToInt64(dt1.Rows[y]["PUB"]);
  141. r.Clicks += Convert.ToInt64(dt1.Rows[y]["CLICKS"]);
  142. }
  143. }
  144. }
  145. }
  146. }
  147.  
  148. foreach (var minfo in result1)
  149. {
  150. AdSpaceHourlyNew r = new AdSpaceHourlyNew();
  151. var pubr1 = result1.Find(os => os.SettledTime == minfo.SettledTime);
  152. var pubr2 = result2.Find(os => os.SettledTime == minfo.SettledTime);
  153. if (pubr2!=null)
  154. {
  155. r.AdSpaceId = minfo.AdSpaceId;
  156. r.AdSpaceName = minfo.AdSpaceName;
  157. r.Pv = minfo.Pv;
  158. r.Pub = pubr2 != null ? pubr2.Pub : ;
  159. r.Clicks = pubr2 != null ? pubr2.Clicks : ;
  160. r.Adv = pubr2 != null ? pubr2.Adv : ;
  161. r.Ctr = r.Adv > ? (double)r.Clicks / r.Adv : ;
  162. r.SettledTime = minfo.SettledTime;
  163. result.Add(r);
  164. }
  165. else
  166. {
  167. r.AdSpaceId = minfo.AdSpaceId;
  168. r.AdSpaceName = minfo.AdSpaceName;
  169. r.Pv = minfo.Pv;
  170. r.Pub = pubr1 != null ? pubr1.Pub : ;
  171. r.Clicks = pubr1 != null ? pubr1.Clicks : ;
  172. r.Adv = pubr1 != null ? pubr1.Adv : ;
  173. r.Ctr = r.Adv > ? (double)r.Clicks / r.Adv : ;
  174. r.SettledTime = minfo.SettledTime;
  175. result.Add(r);
  176. }
  177. }
  178. return result;
  179. }
  1. public static List<MediaBuyReportFromHourly> GetMediaBuyReportFromHourlyNew(int campaignID, DateTime start, DateTime end)
  2. {
  3. List<MediaBuyReportFromHourly> List = new List<MediaBuyReportFromHourly>();
  4. List<MediaBuyReportFromHourly> List1 = new List<MediaBuyReportFromHourly>();
  5. List<MediaBuyReportFromHourly> List2 = new List<MediaBuyReportFromHourly>();
  6. MediaBuyReportFromHourly MediaBuyReportFromHourly = new MediaBuyReportFromHourly();
  7. string[] constr = new[] { MySqlHelper.connectionString1, MySqlHelper.connectionString3, MySqlHelper.connectionString4 };
  8.  
  9. string sqlo = @"select campaign_id,id as media_buy_id,start_time,end_time,NAME,--rate.rate,
  10. BUDGET,PACING_DISABLED,decode(PACING_DISABLED,1,0,NVL(minute_budget,0)) minute_budget,balance FROM media_buy WHERE campaign_id = :CAMPAIGN_ID AND status > 0";
  11. OracleParameter pCampaignID = new OracleParameter(":CAMPAIGN_ID", OracleType.Int32);
  12. pCampaignID.Value = campaignID;
  13.  
  14. DataSet ords = OracleHelper.ExecuteDataset(CONNECTION_STRING, CommandType.Text, sqlo, pCampaignID);
  15. string mediabuyid = "";
  16. foreach (DataRow row in ords.Tables[].Rows)
  17. {
  18. mediabuyid += row[] + " ,";
  19. }
  20. mediabuyid = mediabuyid.TrimEnd(',');
  21. if (ords.Tables[].Rows.Count > )
  22. {
  23. for (int i = ; i < ords.Tables[].Rows.Count; i++)
  24. {
  25. List1.Add(new MediaBuyReportFromHourly()
  26. {
  27. Campaign_ID = Convert.ToInt32(ords.Tables[].Rows[i]["Campaign_ID"].ToString()),
  28. Media_Buy_ID = Convert.ToInt32(ords.Tables[].Rows[i]["Media_Buy_ID"].ToString()),
  29. Start_Time = Convert.ToDateTime(ords.Tables[].Rows[i]["Start_Time"].ToString()),
  30. End_Time = Convert.ToDateTime(ords.Tables[].Rows[i]["End_Time"].ToString()),
  31. Name = ords.Tables[].Rows[i]["Name"].ToString(),
  32. Budget = Convert.ToInt32(ords.Tables[].Rows[i]["Budget"]),
  33. Pacing_Disabled = Convert.ToInt32(ords.Tables[].Rows[i]["Pacing_Disabled"]),
  34. Minute_Budget = Convert.ToDouble(ords.Tables[].Rows[i]["Minute_Budget"]),
  35. Balance = Convert.ToDouble(ords.Tables[].Rows[i]["Balance"])
  36. });
  37. }
  38.  
  39. }
  40. string sqlm = @"select media_buy_id, coalesce(sum(adv_imp_paid),0) as adv_imp_paid,coalesce(sum(pub_imp_paid),0) as pub_imp_paid,coalesce(sum(clicks),0) as clicks
  41. from report_data_hourly_nocity a
  42. where media_buy_id in ({0})
  43. and settled_time >= @starttime and settled_time <@endtime and adv_flag=1
  44. group by media_buy_id";
  45. sqlm = string.Format(sqlm, mediabuyid);
  46. MySqlParameter[] myp = new MySqlParameter[] {
  47. new MySqlParameter("@starttime", start),
  48. new MySqlParameter("@endtime", end)
  49. };
  50.  
  51. for (int i = ; i < ; i++)
  52. {
  53. DataTable dt1 = MySqlHelper.ExecuteDatasetNew(CommandType.Text, sqlm, constr[i], myp).Tables[];
  54. if (dt1.Rows.Count > )
  55. {
  56. for (int j = ; j < dt1.Rows.Count; j++)
  57. {
  58. var r = List2.Find(mbi => mbi.Media_Buy_ID == Convert.ToInt32(dt1.Rows[j]["Media_Buy_ID"].ToString()));
  59. if (r == null)
  60. {
  61. List2.Add(new MediaBuyReportFromHourly()
  62. {
  63. Media_Buy_ID = Convert.ToInt32(dt1.Rows[j]["Media_Buy_ID"] != DBNull.Value ? dt1.Rows[j]["Media_Buy_ID"] : ),
  64. Adv_Imp_Paid = Convert.ToInt64(dt1.Rows[j]["Adv_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Adv_Imp_Paid"] : ),
  65. Pub_Imp_Paid = Convert.ToInt64(dt1.Rows[j]["Pub_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Pub_Imp_Paid"] : ),
  66. Clicks = Convert.ToInt64(dt1.Rows[j]["Clicks"] != DBNull.Value ? dt1.Rows[j]["Clicks"] : )
  67.  
  68. });
  69. }
  70. else
  71. {
  72. r.Adv_Imp_Paid += Convert.ToInt64(dt1.Rows[j]["Adv_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Adv_Imp_Paid"] : );
  73. r.Pub_Imp_Paid += Convert.ToInt64(dt1.Rows[j]["Pub_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Pub_Imp_Paid"] : );
  74. r.Clicks += Convert.ToInt64(dt1.Rows[j]["Clicks"] != DBNull.Value ? dt1.Rows[j]["Clicks"] : );
  75. }
  76. }
  77.  
  78. }
  79. }
  80. foreach (var mymbi in List2)
  81. {
  82. MediaBuyReportFromHourly r = new MediaBuyReportFromHourly();
  83. var minfo = List1.Find(mbi => mbi.Media_Buy_ID == mymbi.Media_Buy_ID);
  84. if (minfo != null)
  85. {
  86. r.Campaign_ID = minfo.Campaign_ID;
  87. r.Media_Buy_ID = minfo.Media_Buy_ID;
  88. r.Start_Time = minfo.Start_Time;
  89. r.End_Time = minfo.End_Time;
  90. r.Name = minfo.Name;
  91. r.Budget = minfo.Budget;
  92. r.Pacing_Disabled = minfo.Pacing_Disabled;
  93. r.Minute_Budget = minfo.Minute_Budget;
  94. r.Balance = minfo.Balance;
  95. }
  96.  
  97. r.Adv_Imp_Paid = mymbi.Adv_Imp_Paid;
  98. r.Pub_Imp_Paid = mymbi.Pub_Imp_Paid;
  99. r.Clicks = mymbi.Clicks;
  100. r.Ctr = r.Adv_Imp_Paid > ? (double)r.Clicks / r.Adv_Imp_Paid : ;
  101. List.Add(r);
  102. }
  103.  
  104. //foreach (var minfo in List1)
  105. //{
  106. // MediaBuyReportFromHourly r = new MediaBuyReportFromHourly();
  107. // var mymbi = List2.Find(mbi => mbi.Media_Buy_ID == minfo.Media_Buy_ID);
  108. // r.Campaign_ID = minfo.Campaign_ID;
  109. // r.Media_Buy_ID = minfo.Media_Buy_ID;
  110. // r.Start_Time = minfo.Start_Time;
  111. // r.End_Time = minfo.End_Time;
  112. // r.Name = minfo.Name;
  113. // r.Budget = minfo.Budget;
  114. // r.Pacing_Disabled = minfo.Pacing_Disabled;
  115. // r.Minute_Budget = minfo.Minute_Budget;
  116. // r.Balance = minfo.Balance;
  117. // r.Adv_Imp_Paid = mymbi != null ? mymbi.Adv_Imp_Paid : 0;
  118. // r.Pub_Imp_Paid = mymbi != null ? mymbi.Pub_Imp_Paid : 0;
  119. // r.Clicks = mymbi != null ? mymbi.Clicks : 0;
  120. // r.Ctr = r.Adv_Imp_Paid > 0 ? (double)r.Clicks / r.Adv_Imp_Paid : 0;
  121. // List.Add(r);
  122. //}
  123.  
  124. return List.OrderBy(os => os.Media_Buy_ID).ToList();
  125. }
  1. public static List<AdFormatReportResultHourly> GetAdFormatReportHourlyNew(int campaignID, DateTime start, DateTime end)
  2. {
  3. List<AdFormatReportResultHourly> List = new List<AdFormatReportResultHourly>();
  4. List<AdFormatReportHourly> ListA = new List<AdFormatReportHourly>();
  5. List<AdFormatReportHourly> ListB = new List<AdFormatReportHourly>();
  6. List<AdFormatReportHourly> List1 = new List<AdFormatReportHourly>();
  7. List<AdFormatReportHourly> List2 = new List<AdFormatReportHourly>();
  8. List<AdFormatReportHourly> List3 = new List<AdFormatReportHourly>();
  9. List<AdFormatReportHourly> List4 = new List<AdFormatReportHourly>();
  10. AdFormatReportHourly AdFormatReportHourly = new AdFormatReportHourly();
  11. string[] constr = new[] { MySqlHelper.connectionString1, MySqlHelper.connectionString3, MySqlHelper.connectionString4 };
  12.  
  13. string sqlo = @"select campaign_id,id FROM media_buy WHERE campaign_id = :CAMPAIGN_ID AND status > 0";
  14. OracleParameter pCampaignID = new OracleParameter(":CAMPAIGN_ID", OracleType.Int32);
  15. pCampaignID.Value = campaignID;
  16.  
  17. DataSet ords = OracleHelper.ExecuteDataset(CONNECTION_STRING, CommandType.Text, sqlo, pCampaignID);
  18. string mediabuyid = "";
  19. foreach (DataRow row in ords.Tables[].Rows)
  20. {
  21. mediabuyid += row[] + " ,";
  22. }
  23. mediabuyid = mediabuyid.TrimEnd(',');
  24. if (mediabuyid.Length == )
  25. return List;
  26. string creativids = "";
  27. string sqlm = @"select creative_id,roadblock_id, coalesce(sum(adv_imp_paid),0) as adv_imp_paid,coalesce(sum(pub_imp_paid),0) as pub_imp_paid,coalesce(sum(clicks),0) as clicks
  28. from report_data_hourly_nocity a where media_buy_id in ({0}) and settled_time >= @starttime and settled_time <@endtime and adv_flag=1 group by creative_id,roadblock_id";
  29. sqlm = string.Format(sqlm, mediabuyid);
  30. MySqlParameter[] myp = new MySqlParameter[] {
  31. new MySqlParameter("@starttime", start),
  32. new MySqlParameter("@endtime", end)
  33. };
  34. for (int i = ; i < ; i++)
  35. {
  36. DataTable dt1 = MySqlHelper.ExecuteDatasetNew(CommandType.Text, sqlm, constr[i], myp).Tables[];
  37. if (dt1.Rows.Count > )
  38. {
  39. for (int j = ; j < dt1.Rows.Count; j++)
  40. {
  41. int creativeid = Convert.ToInt32(dt1.Rows[j]["Creative_ID"].ToString());
  42. creativids += creativeid + ",";
  43. int roadblockid = Convert.ToInt32(dt1.Rows[j]["roadblock_id"].ToString());
  44. var r = List1.Find(cid => cid.Creative_ID == creativeid && cid.RoadblockId == roadblockid);
  45. if (r == null)
  46. {
  47. List1.Add(new AdFormatReportHourly()
  48. {
  49. Campaign_ID = campaignID,
  50. Creative_ID = creativeid,
  51. RoadblockId = roadblockid,
  52. Adv_Imp_Paid = Convert.ToInt64(dt1.Rows[j]["Adv_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Adv_Imp_Paid"] : ),
  53. Pub_Imp_Paid = Convert.ToInt64(dt1.Rows[j]["Pub_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Pub_Imp_Paid"] : ),
  54. Clicks = Convert.ToInt64(dt1.Rows[j]["Clicks"] != DBNull.Value ? dt1.Rows[j]["Clicks"] : )
  55. });
  56. }
  57. else
  58. {
  59. r.Adv_Imp_Paid += Convert.ToInt64(dt1.Rows[j]["Adv_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Adv_Imp_Paid"] : );
  60. r.Pub_Imp_Paid += Convert.ToInt64(dt1.Rows[j]["Pub_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Pub_Imp_Paid"] : );
  61. r.Clicks += Convert.ToInt64(dt1.Rows[j]["Clicks"] != DBNull.Value ? dt1.Rows[j]["Clicks"] : );
  62. }
  63. }
  64. }
  65. }
  66.  
  67. #region
  68. if (creativids.Length > )
  69. {
  70. string sqlNC = @"select id,ad_format,format_name from (select id,ad_format,ad_size_format_desc as format_name from creative c left join AD_SIZE_FORMAT f on c.ad_format=f.format) c
  71. where c.id in ({0}) ";
  72. sqlNC = string.Format(sqlNC, creativids.TrimEnd(','));
  73.  
  74. DataSet ordsN2 = OracleHelper.ExecuteDataset(CONNECTION_STRING, CommandType.Text, sqlNC);
  75. if (ordsN2.Tables[].Rows.Count > )
  76. {
  77. for (int k = ; k < ordsN2.Tables[].Rows.Count; k++)
  78. {
  79. List2.Add(new AdFormatReportHourly()
  80. {
  81. Creative_ID = Convert.ToInt32(ordsN2.Tables[].Rows[k]["ID"].ToString()),
  82. Format_Name = ordsN2.Tables[].Rows[k]["Format_Name"].ToString(),
  83. AdFormat = Convert.ToInt32(ordsN2.Tables[].Rows[k]["ad_format"].ToString())
  84. });
  85. }
  86. }
  87. }
  88. #endregion
  89.  
  90. foreach (var minfo in List1)
  91. {
  92. AdFormatReportHourly r = new AdFormatReportHourly();
  93. var mymbi = List2.Find(cid => cid.Creative_ID == minfo.Creative_ID);
  94. r.Campaign_ID = campaignID;
  95. r.RoadblockId = minfo.RoadblockId;
  96. r.Format_Name = mymbi != null ? mymbi.Format_Name : "";
  97. r.AdFormat = mymbi != null ? mymbi.AdFormat : -;
  98. r.Adv_Imp_Paid = minfo.Adv_Imp_Paid;
  99. r.Pub_Imp_Paid = minfo.Pub_Imp_Paid;
  100. r.Clicks = minfo.Clicks;
  101. ListA.Add(r);
  102. ListB.Add(r);
  103. }
  104.  
  105. ListA = ListA.FindAll(os => (os.RoadblockId != || os.AdFormat != ));

var ListA = ListA.GroupBy(a1 => new { a1.Campaign_ID, a1.Format_Name })
.Select(a2 => new AdFormatReportHourly
{
Clicks=a2.Sum(a3=>a3.Clicks),
Adv_Imp_Paid=a2.Sum(a3=>a3.Adv_Imp_Paid),
Pub_Imp_Paid=a2.Sum(a3=>a3.Pub_Imp_Paid),
Campaign_ID=a2.Key.Campaign_ID,
Format_Name=a2.Key.Format_Name
});

  1. ListB = ListB.FindAll(os => os.RoadblockId == && os.AdFormat == ).ToList();

var listB = ListB.GroupBy(t1 => new { t1.Campaign_ID, t1.Format_Name })
.Select(t2 => new AdFormatReportHourly
{
Clicks=t2.Sum(t3=>t3.Clicks),
Adv_Imp_Paid=t2.Sum(t3=>t3.Adv_Imp_Paid),
Pub_Imp_Paid=t2.Sum(t3=>t3.Pub_Imp_Paid),
Campaign_ID=t2.Key.Campaign_ID,
Format_Name=t2.Key.Format_Name
});

  1. foreach (var lb in listB)
  2. {
  3. var temp = ListA.FindAll(os => os.Format_Name == lb.Format_Name);
  4. if (temp == null || temp.Count == )
  5. {
  6. ListA.Add(lb);
  7. }
  8. }
  9. ListA.ForEach(os =>
  10. {
  11. List.Add(new AdFormatReportResultHourly()
  12. {
  13. Adv_Imp_Paid = os.Adv_Imp_Paid,
  14. Campaign_ID = os.Campaign_ID,
  15. Format_Name = os.Format_Name,
  16. Clicks = os.Clicks,
  17. Pub_Imp_Paid = os.Pub_Imp_Paid,
  18. Ctr = os.Adv_Imp_Paid > ? os.Clicks / os.Adv_Imp_Paid :
  19. });
  20. });
  21. return List;
  22. }
  1. public static List<AdFormatReportResultNewHourly> GetAdFormatReportHourlyALLNew(string campaignID, DateTime start, DateTime end)
  2. {
  3. List<AdFormatReportResultNewHourly> List = new List<AdFormatReportResultNewHourly>();
  4. List<AdFormatReportHourly> ListA = new List<AdFormatReportHourly>();
  5. List<AdFormatReportHourly> ListB = new List<AdFormatReportHourly>();
  6. List<AdFormatReportHourly> List1 = new List<AdFormatReportHourly>();
  7. List<AdFormatReportHourly> List2 = new List<AdFormatReportHourly>();
  8. List<AdFormatReportHourly> List3 = new List<AdFormatReportHourly>();
  9. List<AdFormatReportHourly> List4 = new List<AdFormatReportHourly>();
  10. AdFormatReportHourly AdFormatReportHourly = new AdFormatReportHourly();
  11. string[] constr = new[] { MySqlHelper.connectionString1, MySqlHelper.connectionString3, MySqlHelper.connectionString4 };
  12.  
  13. string sqlo = @"select campaign_id,id FROM media_buy WHERE campaign_id in (" + campaignID + @") AND status > :status";
  14. OracleParameter pCampaignID = new OracleParameter(":status", OracleType.Int32);
  15. pCampaignID.Value = ;
  16.  
  17. DataSet ords = OracleHelper.ExecuteDataset(CONNECTION_STRING, CommandType.Text, sqlo, pCampaignID);
  18. string mediabuyid = "";
  19. foreach (DataRow row in ords.Tables[].Rows)
  20. {
  21. mediabuyid += row[] + " ,";
  22.  
  23. }
  24. mediabuyid = mediabuyid.TrimEnd(',');
  25. if (mediabuyid.Length == )
  26. return List;
  27. string creativids = "";
  28. string sqlm = @"select creative_id,roadblock_id, coalesce(sum(adv_imp_paid),0) as adv_imp_paid,coalesce(sum(pub_imp_paid),0) as pub_imp_paid,coalesce(sum(clicks),0) as clicks
  29. from report_data_hourly_nocity a where media_buy_id in ({0}) and settled_time >= @starttime and settled_time <@endtime and adv_flag=1 group by creative_id,roadblock_id";
  30. sqlm = string.Format(sqlm, mediabuyid);
  31. MySqlParameter[] myp = new MySqlParameter[] {
  32. new MySqlParameter("@starttime", start),
  33. new MySqlParameter("@endtime", end)
  34. };
  35. for (int i = ; i < ; i++)
  36. {
  37. DataTable dt1 = MySqlHelper.ExecuteDatasetNew(CommandType.Text, sqlm, constr[i], myp).Tables[];
  38. if (dt1.Rows.Count > )
  39. {
  40. for (int j = ; j < dt1.Rows.Count; j++)
  41. {
  42. int creativeid = Convert.ToInt32(dt1.Rows[j]["Creative_ID"].ToString());
  43.  
  44. creativids += creativeid + ",";
  45. int roadblockid = Convert.ToInt32(dt1.Rows[j]["roadblock_id"].ToString());
  46. var r = List1.Find(cid => cid.Creative_ID == creativeid && cid.RoadblockId == roadblockid);
  47. if (r == null)
  48. {
  49. List1.Add(new AdFormatReportHourly()
  50. {
  51. Campaign_ID =,
  52. Creative_ID = creativeid,
  53. RoadblockId = roadblockid,
  54. Adv_Imp_Paid = Convert.ToInt64(dt1.Rows[j]["Adv_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Adv_Imp_Paid"] : ),
  55. Pub_Imp_Paid = Convert.ToInt64(dt1.Rows[j]["Pub_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Pub_Imp_Paid"] : ),
  56. Clicks = Convert.ToInt64(dt1.Rows[j]["Clicks"] != DBNull.Value ? dt1.Rows[j]["Clicks"] : )
  57. });
  58. }
  59. else
  60. {
  61. r.Adv_Imp_Paid += Convert.ToInt64(dt1.Rows[j]["Adv_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Adv_Imp_Paid"] : );
  62. r.Pub_Imp_Paid += Convert.ToInt64(dt1.Rows[j]["Pub_Imp_Paid"] != DBNull.Value ? dt1.Rows[j]["Pub_Imp_Paid"] : );
  63. r.Clicks += Convert.ToInt64(dt1.Rows[j]["Clicks"] != DBNull.Value ? dt1.Rows[j]["Clicks"] : );
  64. }
  65. }
  66. }
  67. }
  68.  
  69. #region
  70. if (creativids.Length > )
  71. {
  72. string sqlNC = @"select id,ad_format,format_name from (select id,ad_format,ad_size_format_desc as format_name from creative c left join AD_SIZE_FORMAT f on c.ad_format=f.format) c
  73. where c.id in ({0}) ";
  74. sqlNC = string.Format(sqlNC, creativids.TrimEnd(','));
  75.  
  76. DataSet ordsN2 = OracleHelper.ExecuteDataset(CONNECTION_STRING, CommandType.Text, sqlNC);
  77. if (ordsN2.Tables[].Rows.Count > )
  78. {
  79. for (int k = ; k < ordsN2.Tables[].Rows.Count; k++)
  80. {
  81. List2.Add(new AdFormatReportHourly()
  82. {
  83. Creative_ID = Convert.ToInt32(ordsN2.Tables[].Rows[k]["ID"].ToString()),
  84. Format_Name = ordsN2.Tables[].Rows[k]["Format_Name"].ToString(),
  85. AdFormat = Convert.ToInt32(ordsN2.Tables[].Rows[k]["ad_format"].ToString())
  86. });
  87. }
  88. }
  89. }
  90. #endregion
  91.  
  92. foreach (var minfo in List1)
  93. {
  94. AdFormatReportHourly r = new AdFormatReportHourly();
  95. var mymbi = List2.Find(cid => cid.Creative_ID == minfo.Creative_ID);
  96. r.Campaign_ID =;
  97. r.RoadblockId = minfo.RoadblockId;
  98. r.Format_Name = mymbi != null ? mymbi.Format_Name : "";
  99. r.AdFormat = mymbi != null ? mymbi.AdFormat : -;
  100. r.Adv_Imp_Paid = minfo.Adv_Imp_Paid;
  101. r.Pub_Imp_Paid = minfo.Pub_Imp_Paid;
  102. r.Clicks = minfo.Clicks;
  103. ListA.Add(r);
  104. ListB.Add(r);
  105. }
  106.  
  107. ListA = ListA.FindAll(os => (os.RoadblockId != || os.AdFormat != ));

var ListA = ListA.GroupBy(a1 => new { a1.Campaign_ID, a1.Format_Name })
.Select(a2 => new AdFormatReportHourly
{
Clicks=a2.Sum(a3=>a3.Clicks),
Adv_Imp_Paid=a2.Sum(a3=>a3.Adv_Imp_Paid),
Pub_Imp_Paid=a2.Sum(a3=>a3.Pub_Imp_Paid),
Campaign_ID=a2.Key.Campaign_ID,
Format_Name=a2.Key.Format_Name
});

  1. ListB = ListB.FindAll(os => os.RoadblockId == && os.AdFormat == ).ToList();

var listB = ListB.GroupBy(t1 => new { t1.Campaign_ID, t1.Format_Name })
.Select(t2 => new AdFormatReportHourly
{
Clicks=t2.Sum(t3=>t3.Clicks),
Adv_Imp_Paid=t2.Sum(t3=>t3.Adv_Imp_Paid),
Pub_Imp_Paid=t2.Sum(t3=>t3.Pub_Imp_Paid),
Campaign_ID=t2.Key.Campaign_ID,
Format_Name=t2.Key.Format_Name
});

  1. foreach (var lb in listB)
  2. {
  3. var temp = ListA.FindAll(os => os.Format_Name == lb.Format_Name);
  4. if (temp == null || temp.Count == )
  5. {
  6. ListA.Add(lb);
  7. }
  8. }
  9. ListA.ForEach(os =>
  10. {
  11. List.Add(new AdFormatReportResultNewHourly()
  12. {
  13. Adv_Imp_Paid = os.Adv_Imp_Paid,
  14. Campaign_ID = "AllCampaign",
  15. Format_Name = os.Format_Name,
  16. Clicks = os.Clicks,
  17. Pub_Imp_Paid = os.Pub_Imp_Paid,
  18. Ctr = os.Adv_Imp_Paid > ? os.Clicks / os.Adv_Imp_Paid :
  19. });
  20. });
  21. return List;
  22. }

CASUAL_NCT的更多相关文章

随机推荐

  1. scp: command not found

    scp 不能用? [root@doc]# scp jdk-8u144-linux-x64.tar.gz root@10.10.10.17:/root/ root@10.10.10.17's passw ...

  2. Ubuntu 14.03 安装jdk

    安装python-software-properties $sudo apt-get install python-software-properties $sudo apt-get install ...

  3. JS HTML倒计时 进入页面

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. django 的model是如何把字段加入到meta中的

    def contribute_to_class(self, cls, name): self.set_attributes_from_name(name) self.model = cls cls._ ...

  5. python tp_ready函数分析

    int PyType_Ready(PyTypeObject *type) { PyObject *dict, *bases; PyTypeObject *base; Py_ssize_t i, n; ...

  6. 多进程模块 multiprocessing

    由于GIL的存在,python中的多线程其实并不是真正的多线程,如果想要充分地使用多核CPU的资源,在python中大部分情况需要使用多进程. multiprocessing包是Python中的多进程 ...

  7. Unity for VsCode

    安装以下两个插件 以下设置VsCode在换行保存时不删除tab空格

  8. 【原】The Linux Command Line - Processes

    ps - report a snapshot of current processes top - display tasks job - list active jobs bg - place a ...

  9. texmaker报错:could not start command 解决

    我当时文件命名加了邮箱,引入特殊字符@,然后就报错了

  10. MFC笔记10

    1. CDC MemDC1; MemDC1.SetBkMode(OPAQUE); 背景模式,VC6下面有三种:/* Background Modes */#define TRANSPARENT 1// ...