SycnSpActiveService.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. JavaProductModels.WebCMSEntities javaprodb = new JavaProductModels.WebCMSEntities();
  31. string Month = DateTime.Now.ToString("yyyyMM");
  32. string Date = DateTime.Now.ToString("yyyyMMdd");
  33. DateTime start = DateTime.Now.AddDays(-30);
  34. DateTime end = DateTime.Now.AddMinutes(-1);
  35. int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/ActivateRecordId.txt")));
  36. 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);
  37. foreach (ActivateRecord act in acts.ToList())
  38. {
  39. PosPushDataNewHelper.Deposit(act);
  40. if(act.ProductType == "36" && decimal.Parse(function.CheckNum(act.Field3)) > 0)
  41. {
  42. JavaProductModels.KxsMachine pos = javaprodb.KxsMachine.FirstOrDefault(m => m.PosSn == act.SnNo && m.UserId > 0);
  43. if(pos != null)
  44. {
  45. RedisDbconn.Instance.AddList("HaoDaPrizeDataQueue", "{\"brand_id\":36,\"ext_field\":\"" + act.Field3 + "\",\"pos_sn\":\"" + act.SnNo + "\",\"user_id\":" + pos.UserId + "}");
  46. }
  47. }
  48. ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
  49. if (edit != null)
  50. {
  51. edit.Status = 2;
  52. }
  53. }
  54. spdb.SaveChanges();
  55. spdb.Dispose();
  56. db.SaveChanges();
  57. db.Dispose();
  58. mpdb.Dispose();
  59. javaprodb.Dispose();
  60. }
  61. catch (Exception ex)
  62. {
  63. Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
  64. }
  65. Thread.Sleep(1000);
  66. }
  67. }
  68. }
  69. }