1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using Library;
- using MySystem.Models;
- using System;
- using System.Linq;
- namespace MySystem
- {
- public class PosMachinesHelper
- {
- public readonly static PosMachinesHelper Instance = new PosMachinesHelper();
- private PosMachinesHelper()
- { }
- public string Start()
- {
- bool op = true;
- WebCMSEntities db = new WebCMSEntities();
- string result = "success";
- int total = 0;
- while (op)
- {
- PosMachines PopData = new PosMachines();
- try
- {
- //获取apserver待同步的数据,执行入库
- PopData = RedisDbconn.Instance.RPop<PosMachines>("Pop:PosMachines");
- if (PopData != null)
- {
- PosMachines checkExist = db.PosMachines.FirstOrDefault(m => m.Id == PopData.Id);
- if (checkExist != null)
- {
- checkExist = PopData;
- }
- else
- {
- db.PosMachines.Add(PopData);
- }
- if (total >= 20)
- {
- total = 0;
- db.SaveChanges();
- }
- if (string.IsNullOrEmpty(result)) result = "success";
- }
- else
- {
- db.SaveChanges();
- op = false;
- }
- }
- catch (Exception ex)
- {
- ErrorMsg msg = new ErrorMsg();
- msg.Obj = PopData;
- msg.Time = DateTime.Now;
- msg.ErrorContent = ex.ToString();
- LogHelper.Instance.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(msg), "Pop:PosMachines:Error");
- result = "有异常,请查看Pop:PosMachines:Error队列";
- }
- }
- db.Dispose();
- return result;
- }
- }
- }
|