private void InsertData(List<special_alarm_detour> list)
        {
            try
            {
                using (var db = new DapperHelper(BasicInformation.connection))
                {
                    try
                    {
                        List<List<special_alarm_detour>> listGroup = new List<List<special_alarm_detour>>();
                        int j = 1000;
                        for (int i = 0; i < list.Count; i += 1000)//以1000为一组分组
                        {
                            List<special_alarm_detour> cList = new List<special_alarm_detour>();
                            cList = list.Take(j).Skip(i).ToList();
                            j += 1000;
                            listGroup.Add(cList);
                        }
                        for (int i = 0; i < listGroup.Count; i++)
                        {
                            List<special_alarm_detour> fzlist = new List<special_alarm_detour>();
                            fzlist = listGroup[i];
                            using (var ctx = db.TranStart())
                            {
                                try
                                {
                                    Stopwatch stopwatch = new Stopwatch();
                                    stopwatch.Restart();
                                    db.Insert<special_alarm_detour>(fzlist);
                                    ctx.Commit();
                                    stopwatch.Stop();
                                    Log.Blue($"【车辆绕行】插入数据:{fzlist.Count}条,耗时:{stopwatch.ElapsedMilliseconds}毫秒");
                                }
                                catch (Exception ex)
                                {
                                    ctx.Rollback();
                                    Log.Error($"【车辆绕行】插入数据报错:{ex.Message.ToString()}");
                                }
                            }

                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"【车辆绕行】插入数据报错:{ex.Message.ToString()}");
                    }

                }
            }
            catch (Exception ex)
            {
                Log.Error($"【车辆绕行】插入数据报错:{ex.Message.ToString()}");
            }
        }

 

posted on 2020-08-28 08:32  红磨坊后的白桦树  阅读(307)  评论(0编辑  收藏  举报