CheckDataHelper.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using SCC.Common;
  2. using SCC.Interface;
  3. using SCC.Models;
  4. using SCC.Services;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. namespace SCC.Crawler.Tools
  10. {
  11. public class CheckDataHelper
  12. {
  13. private static LogHelper log = null;
  14. private static IEmail email = null;
  15. private static CheckResultServices resultServices = null;
  16. static CheckDataHelper()
  17. {
  18. email = IOC.Resolve<IEmail>();
  19. log = new LogHelper();
  20. resultServices = new CheckResultServices();
  21. }
  22. /// <summary>
  23. /// 纠错参数
  24. /// </summary>
  25. /// <param name="dbData"></param>
  26. /// <param name="newData"></param>
  27. public void CheckData(Dictionary<string, string> dbData, Dictionary<string, string> newData, string Area, SCCLottery Lottery)
  28. {
  29. try
  30. {
  31. Dictionary<int, int> result = new Dictionary<int, int>();
  32. foreach (var item in dbData)
  33. {
  34. var data = newData.SingleOrDefault(w => w.Key == item.Key);
  35. if (data.Key != null)
  36. {
  37. var dbdata = Array.ConvertAll<string, int>(data.Value.Split(','), s => int.Parse(s)).ToList();
  38. var newdata = Array.ConvertAll<string, int>(item.Value.Split(','), s => int.Parse(s)).ToList();
  39. dbdata.Sort();
  40. newdata.Sort();
  41. var dbcode = string.Join(",", dbdata);
  42. var newcode = string.Join(",", newdata);
  43. if (dbcode != newcode)
  44. {
  45. result.Add(int.Parse(item.Key), 0);
  46. email.AddEmail(Area + Lottery.ToString(), data.Key, DateTime.Now, "数据验证失败" + string.Format("数据库:{0},爬取:{1}", item.Value, data.Value));
  47. }
  48. else
  49. {
  50. result.Add(int.Parse(item.Key), 1);
  51. }
  52. }
  53. }
  54. var tableName = EnumHelper.GetSCCLotteryTableName(Lottery);
  55. int rt = resultServices.ExecuteResult(tableName, result);
  56. if (rt < 0)
  57. {
  58. email.AddEmail(Area + Lottery.ToString(), "0", DateTime.Now, "执行验证结果结果失败");
  59. }
  60. }
  61. catch (Exception ex)
  62. {
  63. log.Error(this.GetType(), string.Format("【{0}】数据验证发生错误,错误信息【{1}】", Area + Lottery.ToString(), ex.Message));
  64. }
  65. }
  66. }
  67. }