123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using CP.Dapper;
- using CP.Model;
- using MC.ORM;
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CP.Business
- {
- public class ZtArticleBll : BaseBll
- {
- /// <summary>
- /// 上线前数据的导入
- /// </summary>
- /// <param name="datas"></param>
- public static void testadd(List<ZtArticle> datas)
- {
- using (Database db = new Database(mysql, MySqlClientFactory.Instance))
- {
- try
- {
- db.BeginTransaction();
- for (var i = 0; i < datas.Count; i++)
- {
- db.Insert("Zt_Article", "Id", false, datas[i]);
- Console.WriteLine($"{i}");
- }
- //var task1 = Task.Factory.StartNew(() =>
- //{
- // for (var i = 0; i < 200000; i++)
- // {
- // db.Insert(datas[i]);
- // Console.WriteLine($"{i}\n");
- // }
- //});
- //var count = datas.Count;
- //var task2 = Task.Factory.StartNew(() =>
- //{
- // for (var i = 200000; i < count; i++)
- // {
- // db.Insert(datas[i]);
- // Console.WriteLine($"{i}\n");
- // }
- //});
- db.CompleteTransaction();
- }
- catch (Exception ex)
- {
- db.AbortTransaction();
- throw ex;
- }
- }
- }
- public static Page<ZtArticle> GetPager(ZtArticle entity, int pageSize, int pageIndex)
- {
- var dc = new DataConnect();
- string where = "";
- if(entity.Cid>0)
- where = $" where cid={entity.Cid} ";
- if (entity.TagId > 0)
- {
- if (where.Contains("where"))
- {
- where += $" and TagId={entity.TagId} ";
- }
- else {
- where = $"where TagId={entity.TagId} ";
- }
- }
- string sql = $@"select Id,Title,Cid,TagId,ShortDetail,Addtime from ZT_Article
- {where} order by id desc";
- var datas = dc.db.Page<ZtArticle>(pageIndex, pageSize, new Sql(sql));
- return datas;
- ; }
- }
- /// <summary>
- /// 上线前数据的导出
- /// </summary>
- public class ZtArticleTest : DbHelper
- {
- public ZtArticleTest()
- {
- }
- public void TestAdd()
- {
- base.db = new MsSqlDatabase(ConfigurationManager.ConnectionStrings["ZhuanTiSqlService"].ToString());
- //var list = db.FindList<ZtArticle>("select * from Zt_Article where addtime>'2018-1-1 00:00:01'").ToList();
- //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();
- //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();
- var list = new List<ZtArticle>();
- if (list != null && list.Count > 0)
- {
- ZtArticleBll.testadd(list);
- }
- }
- }
- }
|