1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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.MerNo, 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;
- PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
- if (merFor == null)
- {
- merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
- {
- MerNo = Bind.MerNo,
- SnId = pos.Id,
- }).Entity;
- }
- db.SaveChanges();
- RedisDbconn.Instance.Set("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监控");
- }
- }
- }
|