1. 思路
- 取出数据集合
- 计算总页数等
- 遍历取出处理
2. 这里只贴一下代码段,方便自己以后参考
Dictionary<int, string> dicList = SensetimeApi.GetVisitorListByType(2);
List<dynamic> resList = new List<dynamic>();
int recordCount = dicList.Count;
int pageSize = 50;
int totalPage = 0;
if (recordCount % pageSize == 0)
{
totalPage = recordCount / pageSize;
}
else
{
totalPage = (recordCount / pageSize) + 1;
}
for (int pageNum = 1; pageNum <= totalPage; pageNum++)
{
List<VisitorModel> updateList = new List<VisitorModel>();
Dictionary<string, string> strList = new Dictionary<string, string>();
List<string> tempList = dicList.Skip(pageSize * (pageNum - 1)).Take(pageSize).Select(x => x.Value).ToList();
strList = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(SensetimeApi.GetSensetDesrypt(tempList)));
foreach (var item in strList)
{
try
{
int dicKey = dicList.Where(x => x.Value.Equals(item.Key)).FirstOrDefault().Key;
if (dicKey > 0)
{
VisitorModel visitor = BizBase.Get<BizVisitor>().GetModelByPhone(item.Value);
if (visitor != null)
{
// Log4Helper.Warn(this.GetType(), $"用户名:{visitor.SName} sID:{Convert.ToString(dicKey)}");
visitor.SID = Convert.ToString(dicKey);
updateList.Add(visitor);
}
}
}
catch (Exception ex)
{
continue;
}
}
if (updateList != null && updateList.Count > 0)
{
BizBase.Get<BizVisitor>().UpdateModelList(updateList);
}
}
2
//字典
var dt = new Dictionary<string, object>();
dt.Add("id", 1);
dt.Add("name", null);
dt.Add("createTime", DateTime.Now);
var t66 = db.Updateable(dt).AS("student").WhereColumns("id").ExecuteCommand();
Dictionary<int, string> dicList = SensetimeApi.GetVisitorListByType(2);
List<dynamic> resList = new List<dynamic>();
int recordCount = dicList.Count;
int pageSize = 50;
int totalPage = 0;
if (recordCount % pageSize == 0)
{
totalPage = recordCount / pageSize;
}
else
{
totalPage = (recordCount / pageSize) + 1;
}
for (int pageNum = 1; pageNum <= totalPage; pageNum++)
{
//List<VisitorModel> updateList = new List<VisitorModel>();
Dictionary<string, string> strList = new Dictionary<string, string>();
List<Dictionary<string, object>> dicResList = new List<Dictionary<string, object>>();
List<string> tempList = dicList.Skip(pageSize * (pageNum - 1)).Take(pageSize).Select(x => x.Value).ToList();
strList = JsonConvert.DeserializeObject<Dictionary<string, string>>(JsonConvert.SerializeObject(SensetimeApi.GetSensetDesrypt(tempList)));
foreach (var item in strList)
{
try
{
int dicKey = dicList.Where(x => x.Value.Equals(item.Key)).FirstOrDefault().Key;
if (dicKey > 0)
{
VisitorModel visitor = BizBase.Get<BizVisitor>().GetModelByPhone(item.Value);
if (visitor != null)
{
Dictionary<string, object> dicTemp = new Dictionary<string, object>();
dicTemp.Add("pkCode", visitor.Code);
dicTemp.Add("sID", Convert.ToString(dicKey));
dicResList.Add(dicTemp);
}
}
}
catch (Exception ex)
{
continue;
}
}
if (dicResList != null && dicResList.Count > 0)
{
BizBase.Get<BizVisitor>().UpdateDictionaryList(dicResList);
}
}