ZtArticleBll.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using CP.Dapper;
  2. using CP.Model;
  3. using MC.ORM;
  4. using MySql.Data.MySqlClient;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Configuration;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace CP.Business
  12. {
  13. public class ZtArticleBll : BaseBll
  14. {
  15. /// <summary>
  16. /// 上线前数据的导入
  17. /// </summary>
  18. /// <param name="datas"></param>
  19. public static void testadd(List<ZtArticle> datas)
  20. {
  21. using (Database db = new Database(mysql, MySqlClientFactory.Instance))
  22. {
  23. try
  24. {
  25. db.BeginTransaction();
  26. for (var i = 0; i < datas.Count; i++)
  27. {
  28. db.Insert("Zt_Article", "Id", false, datas[i]);
  29. Console.WriteLine($"{i}");
  30. }
  31. //var task1 = Task.Factory.StartNew(() =>
  32. //{
  33. // for (var i = 0; i < 200000; i++)
  34. // {
  35. // db.Insert(datas[i]);
  36. // Console.WriteLine($"{i}\n");
  37. // }
  38. //});
  39. //var count = datas.Count;
  40. //var task2 = Task.Factory.StartNew(() =>
  41. //{
  42. // for (var i = 200000; i < count; i++)
  43. // {
  44. // db.Insert(datas[i]);
  45. // Console.WriteLine($"{i}\n");
  46. // }
  47. //});
  48. db.CompleteTransaction();
  49. }
  50. catch (Exception ex)
  51. {
  52. db.AbortTransaction();
  53. throw ex;
  54. }
  55. }
  56. }
  57. public static Page<ZtArticle> GetPager(ZtArticle entity, int pageSize, int pageIndex)
  58. {
  59. var dc = new DataConnect();
  60. string where = "";
  61. if(entity.Cid>0)
  62. where = $" where cid={entity.Cid} ";
  63. if (entity.TagId > 0)
  64. {
  65. if (where.Contains("where"))
  66. {
  67. where += $" and TagId={entity.TagId} ";
  68. }
  69. else {
  70. where = $"where TagId={entity.TagId} ";
  71. }
  72. }
  73. string sql = $@"select Id,Title,Cid,TagId,ShortDetail,Addtime from ZT_Article
  74. {where} order by id desc";
  75. var datas = dc.db.Page<ZtArticle>(pageIndex, pageSize, new Sql(sql));
  76. return datas;
  77. ; }
  78. }
  79. /// <summary>
  80. /// 上线前数据的导出
  81. /// </summary>
  82. public class ZtArticleTest : DbHelper
  83. {
  84. public ZtArticleTest()
  85. {
  86. }
  87. public void TestAdd()
  88. {
  89. base.db = new MsSqlDatabase(ConfigurationManager.ConnectionStrings["ZhuanTiSqlService"].ToString());
  90. //var list = db.FindList<ZtArticle>("select * from Zt_Article where addtime>'2018-1-1 00:00:01'").ToList();
  91. //var list = db.FindList<ZtArticle>("select * from Zt_Article where addtime>'2017-1-1 00:00:01' and addtime<'2018-1-1 00:00:01'").ToList();
  92. //var list = db.FindList<ZtArticle>("select * from Zt_Article where addtime>'2016-1-1 00:00:01' and addtime<'2017-1-1 00:00:01'").ToList();
  93. var list = new List<ZtArticle>();
  94. if (list != null && list.Count > 0)
  95. {
  96. ZtArticleBll.testadd(list);
  97. }
  98. }
  99. }
  100. }