예제 #1
0
        static List <RequestItem> FromActions(List <ActionInfo> actions)
        {
            List <RequestItem> requests = new List <RequestItem>();

            foreach (var action in actions)
            {
                RequestItem request = new RequestItem();

                // 2020/4/27
                request.OperatorID = action.Operator?.PatronBarcode;

                // 注: 2020/9/8 把 request.PII 修改为带点的字符串形态
                request.PII = action.Entity.GetOiPii(true); // action.Entity?.PII;
                // TODO: 若 PII 为空,写入 UID?
                request.OperatorString = action.Operator == null ? null : JsonConvert.SerializeObject(action.Operator);
                request.EntityString   = JsonConvert.SerializeObject(action.Entity);

                /*
                 * request.Operator = action.Operator.Clone();
                 * request.Entity = action.Entity.Clone();
                 */
                request.Action            = action.Action;
                request.TransferDirection = action.TransferDirection;
                request.Location          = action.Location;
                request.CurrentShelfNo    = action.CurrentShelfNo;
                request.BatchNo           = action.BatchNo;
                request.SyncCount         = action.SyncCount;
                request.State             = action.State;
                request.SyncErrorInfo     = action.SyncErrorInfo;
                request.SyncErrorCode     = action.SyncErrorCode;
                if (action.OperTime == DateTime.MinValue)
                {
                    request.OperTime = DateTime.Now;
                }
                else
                {
                    request.OperTime = action.OperTime;
                }

                request.SyncOperTime = action.SyncOperTime;
                request.ActionString = action.ActionString;
                requests.Add(request);
            }

            return(requests);
        }
예제 #2
0
        // 2020/8/26
        // 把本地动作库中符合指定 borrowID 的状态修改为 “dontsync”
        internal static async Task ChangeDatabaseBorrowStateAsync(string borrowID)
        {
            using (var releaser = await _databaseLimit.EnterAsync())
            {
                using (var context = new RequestContext())
                {
                    var         items   = context.Requests.Where(o => o.Action == "borrow" && o.LinkID == null && string.IsNullOrEmpty(o.ActionString) == false).ToList();
                    RequestItem request = null;
                    foreach (var item in items)
                    {
                        try
                        {
                            var borrow_info = JsonConvert.DeserializeObject <BorrowInfo>(item.ActionString);
                            if (borrow_info.BorrowID == borrowID)
                            {
                                request = item;
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            WpfClientInfo.WriteErrorLog($"解析 borrow_info 字符串 '{item.ActionString}' 时出现异常: {ExceptionUtil.GetDebugText(ex)}");
                        }
                    }

                    if (request != null)
                    {
                        // request.State = "dontsync";

                        // 表示这个借书动作已经发生了还书
                        request.LinkID = $"borrowID={borrowID}";
                        context.SaveChanges();
                    }
                }
            }
        }