SycnSpActiveService.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.SpModels;
  5. using Library;
  6. using LitJson;
  7. using System.Threading;
  8. namespace MySystem
  9. {
  10. public class SycnSpActiveService
  11. {
  12. public readonly static SycnSpActiveService Instance = new SycnSpActiveService();
  13. private SycnSpActiveService()
  14. { }
  15. public void Start()
  16. {
  17. Thread th = new Thread(StartDo);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. public void StartDo()
  22. {
  23. while (true)
  24. {
  25. try
  26. {
  27. WebCMSEntities spdb = new WebCMSEntities();
  28. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  29. MpMainModels2.WebCMSEntities mpdb = new MpMainModels2.WebCMSEntities();
  30. string Month = DateTime.Now.ToString("yyyyMM");
  31. string Date = DateTime.Now.ToString("yyyyMMdd");
  32. DateTime start = DateTime.Now.AddDays(-5);
  33. DateTime end = DateTime.Now.AddMinutes(-1);
  34. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/ActivateRecordId.txt")));
  35. IQueryable<ActivateRecord> acts = spdb.ActivateRecord.Where(m => m.Id >= StartId && m.CreateDate >= start && m.CreateDate < end && m.Status == 1).OrderByDescending(m => m.Id).Take(20);
  36. foreach (ActivateRecord act in acts.ToList())
  37. {
  38. PosPushDataNewHelper.Deposit(act);
  39. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  40. if (edit != null)
  41. {
  42. edit.Status = 2;
  43. }
  44. }
  45. spdb.SaveChanges();
  46. spdb.Dispose();
  47. db.SaveChanges();
  48. db.Dispose();
  49. mpdb.Dispose();
  50. }
  51. catch (Exception ex)
  52. {
  53. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  54. }
  55. Thread.Sleep(1000);
  56. }
  57. }
  58. }
  59. }