| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using MySystem.SpModels;
- using Library;
- using LitJson;
- namespace MySystem
- {
- public class SycnSpBindService
- {
- public readonly static SycnSpBindService Instance = new SycnSpBindService();
- private SycnSpBindService()
- { }
- public void Start()
- {
- function.WriteLog("1", "SycnSpServer监控");
- WebCMSEntities spdb = new WebCMSEntities();
- PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
- DateTime start = DateTime.Now.AddDays(-2);
- function.WriteLog("2", "SycnSpServer监控");
- var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerSnNo }).Where(m => m.CreateTime >= start && m.Status == 1).OrderByDescending(m => m.Id).ToList();
- function.WriteLog("3:count:" + Binds.Count, "SycnSpServer监控");
- foreach (var Bind in Binds)
- {
- PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- pos.BindingState = 1;
- pos.BindingTime = DateTime.Now;
- BothdisDbconn.Instance.SendMq("Pop:PosMachinesTwo", pos);
- }
- BindRecord edit = spdb.BindRecord.FirstOrDefault(m => m.Id == Bind.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- string IdBrand = pos.UserId + "_" + pos.BrandId;
- PxcModels.UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
- if (MachineData == null)
- {
- MachineData = db.UserMachineData.Add(new PxcModels.UserMachineData()
- {
- IdBrand = IdBrand,
- }).Entity;
- db.SaveChanges();
- }
- MachineData.BindCount += 1;
- MachineData.UnBindCount -= 1;
- db.SaveChanges();
- BothdisDbconn.Instance.SendMq("Pop:UserMachineData", MachineData);
- function.WriteLog("BindId:" + Bind.Id, "SycnSpServer监控");
- }
- spdb.SaveChanges();
- spdb.Dispose();
- db.SaveChanges();
- db.Dispose();
- function.WriteLog(":ok:", "SycnSpServer监控");
- }
- }
- }
|