-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathAppReservation.cs
2919 lines (2591 loc) · 121 KB
/
AppReservation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Diagnostics;
using System.Messaging;
using DigitalPlatform.Text;
using DigitalPlatform.Xml;
using DigitalPlatform.rms.Client;
using DigitalPlatform.IO;
namespace DigitalPlatform.LibraryServer
{
/// <summary>
/// 本部分是和流通预约(保留)功能相关的代码
/// </summary>
public partial class LibraryApplication
{
// 预约
// 权限:需要有reservation权限
public LibraryServerResult Reservation(
SessionInfo sessioninfo,
string strFunction,
string strReaderBarcode,
string strItemBarcodeList)
{
LibraryServerResult result = new LibraryServerResult();
// 权限字符串
if (StringUtil.IsInList("reservation", sessioninfo.RightsOrigin) == false)
{
result.Value = -1;
// text-level: 用户提示
result.ErrorInfo = this.GetString("预约操作被拒绝。不具备 reservation 权限。");
result.ErrorCode = ErrorCode.AccessDenied;
return result;
}
int nRet = 0;
string strError = "";
// 2010/12/31
if (String.IsNullOrEmpty(this.ArrivedDbName) == true)
{
strError = "预约到书库尚未定义, 预约操作失败";
goto ERROR1;
}
if (String.Compare(strFunction, "new", true) != 0
&& String.Compare(strFunction, "delete", true) != 0
&& String.Compare(strFunction, "merge", true) != 0
&& String.Compare(strFunction, "split", true) != 0
)
{
result.Value = -1;
// text-level: 内部错误
result.ErrorInfo = string.Format(this.GetString("未知的strFunction参数值s"), // "未知的strFunction参数值 '{0}'"
strFunction);
// "未知的strFunction参数值 '" + strFunction + "'";
result.ErrorCode = ErrorCode.InvalidParameter;
return result;
}
RmsChannel channel = sessioninfo.Channels.GetChannel(this.WsUrl);
if (channel == null)
{
strError = "get channel error";
goto ERROR1;
}
// 在架册集合
List<string> OnShelfItemBarcodes = new List<string>();
// 被删除的已到书状态册集合
List<string> ArriveItemBarcodes = new List<string>();
// 加读者记录锁
#if DEBUG_LOCK_READER
this.WriteErrorLog("Reservation 开始为读者加写锁 '" + strReaderBarcode + "'");
#endif
this.ReaderLocks.LockForWrite(strReaderBarcode);
try
{
// 读入读者记录
string strReaderXml = "";
string strOutputReaderRecPath = "";
byte[] reader_timestamp = null;
nRet = this.GetReaderRecXml(
// sessioninfo.Channels,
channel,
strReaderBarcode,
out strReaderXml,
out strOutputReaderRecPath,
out reader_timestamp,
out strError);
if (nRet == 0)
{
result.Value = -1;
// text-level: 用户提示
result.ErrorInfo = string.Format(this.GetString("读者证条码号s不存在"), // 读者证条码号 {0} 不存在
strReaderBarcode);
// "读者证条码号 '" + strReaderBarcode + "' 不存在";
result.ErrorCode = ErrorCode.ReaderBarcodeNotFound;
return result;
}
if (nRet == -1)
{
// text-level: 内部错误
strError = string.Format(this.GetString("读入读者记录时发生错误s"), // "读入读者记录时发生错误: {0}"
strError);
// "读入读者记录时发生错误: " + strError;
goto ERROR1;
}
string strPatronLibraryCode = "";
// 看看读者记录所从属的数据库,是否在参与流通的读者库之列
// 2012/9/8
if (String.IsNullOrEmpty(strOutputReaderRecPath) == false)
{
string strReaderDbName = ResPath.GetDbName(strOutputReaderRecPath);
bool bReaderDbInCirculation = true;
if (this.IsReaderDbName(strReaderDbName,
out bReaderDbInCirculation,
out strPatronLibraryCode) == false)
{
// text-level: 内部错误
strError = "读者记录路径 '" + strOutputReaderRecPath + "' 中的数据库名 '" + strReaderDbName + "' 居然不在定义的读者库之列。";
goto ERROR1;
}
if (bReaderDbInCirculation == false)
{
// text-level: 用户提示
strError = string.Format(this.GetString("预约操作被拒绝。读者证条码号s所在的读者记录s因其数据库s属于未参与流通的读者库"), // "预约操作被拒绝。读者证条码号 '{0}' 所在的读者记录 '{1}' 因其数据库 '{2}' 属于未参与流通的读者库"
strReaderBarcode,
strOutputReaderRecPath,
strReaderDbName);
goto ERROR1;
}
// 检查当前操作者是否管辖这个读者库
// 观察一个读者记录路径,看看是不是在当前用户管辖的读者库范围内?
if (this.IsCurrentChangeableReaderPath(strOutputReaderRecPath,
sessioninfo.LibraryCodeList) == false)
{
strError = $"读者记录路径 '{strOutputReaderRecPath}' 的读者库不在{GetCurrentUserName(sessioninfo)}管辖范围内";
goto ERROR1;
}
}
nRet = LibraryApplication.LoadToDom(strReaderXml,
out XmlDocument readerdom,
out strError);
if (nRet == -1)
{
// text-level: 内部错误
strError = string.Format(this.GetString("装载读者记录进入XMLDOM时发生错误s"), // "装载读者记录进入XML DOM时发生错误: {0}"
strError);
// "装载读者记录进入XML DOM时发生错误: " + strError;
goto ERROR1;
}
CachedRecordCollection records = new CachedRecordCollection();
records.Add(strOutputReaderRecPath, readerdom, reader_timestamp);
if (strFunction == "delete"
&& sessioninfo.UserType != "reader")
{
// 当工作人员代为操作时, 对于delete操作网开一面,不做基本检查(读者证状态和检查和未取次数的检查)
}
else
{
// return:
// -1 检测过程发生了错误。应当作不能借阅来处理
// 0 可以借阅
// 1 证已经过了失效期,不能借阅
// 2 证有不让借阅的状态
nRet = CheckReaderExpireAndState(readerdom,
out strError);
if (nRet != 0)
{
// text-level: 用户提示
strError = string.Format(this.GetString("预约操作被拒绝,原因s"), // "预约操作被拒绝,原因: {0}"
strError);
// "预约操作被拒绝,原因: " + strError;
goto ERROR1;
}
// 检查到书未取次数是否超标
XmlNode nodeOutof = readerdom.DocumentElement.SelectSingleNode("outofReservations");
if (nodeOutof != null)
{
string strCount = DomUtil.GetAttr(nodeOutof, "count");
int nCount = 0;
try
{
nCount = Convert.ToInt32(strCount);
}
catch
{
}
if (nCount >= this.OutofReservationThreshold)
{
strError = string.Format(this.GetString("预约操作被拒绝,因为次数超过"), // "预约操作被拒绝,因为当前读者以前预约到书后未取的次数超过了 {0} 次,被取消预约能力。如果要恢复预约能力,请读者到图书馆柜台办理解除手续。"
this.OutofReservationThreshold.ToString());
// "预约操作被拒绝,因为当前读者以前预约到书后未取的次数超过了 " + this.OutofReservationThreshold.ToString() + " 次,被取消预约能力。如果要恢复预约能力,请读者到图书馆柜台办理解除手续。";
goto ERROR1;
}
}
}
// 准备日志DOM
XmlDocument domOperLog = new XmlDocument();
domOperLog.LoadXml("<root />");
DomUtil.SetElementText(domOperLog.DocumentElement,
"libraryCode",
strPatronLibraryCode); // 读者所在的馆代码
DomUtil.SetElementText(domOperLog.DocumentElement, "operation", "reservation");
if (String.Compare(strFunction, "new", true) == 0)
{
// 对即将预约的册条码号进行查重
// 要求本读者先前未曾用这些条码号预约过
// return:
// -1 出错
// 0 没有重
// 1 有重 提示信息在strError中
nRet = this.ReservationCheckDup(
strItemBarcodeList,
strPatronLibraryCode,
ref readerdom,
out strError);
if (nRet == -1)
goto ERROR1;
if (nRet == 1)
{
result.Value = -1;
// text-level: 用户提示
result.ErrorInfo = string.Format(this.GetString("预约操作被拒绝,原因s"),
strError);
// result.ErrorInfo = "预约请求被拒绝: " + strError;
result.ErrorCode = ErrorCode.DupItemBarcode;
return result;
}
} // end of "new"
// 为写回读者、册记录做准备
// byte[] timestamp = null;
byte[] output_timestamp = null;
string strOutputPath = "";
#if NO
RmsChannel channel = sessioninfo.Channels.GetChannel(this.WsUrl);
if (channel == null)
{
strError = "get channel error";
goto ERROR1;
}
#endif
long lRet = 0;
// 切割出单个的册条码号
string[] itembarcodes = strItemBarcodeList.Split(new char[] { ',' });
for (int i = 0; i < itembarcodes.Length; i++)
{
string strItemBarcode = itembarcodes[i].Trim();
if (String.IsNullOrEmpty(strItemBarcode) == true)
continue;
string strItemXml = "";
string strOutputItemRecPath = "";
// 册记录加锁
this.EntityLocks.LockForWrite(strItemBarcode);
try
{
int nRedoCount = 0;
REDO_LOAD:
byte[] item_timestamp = null;
// 获得册记录
// return:
// -1 error
// 0 not found
// 1 命中1条
// >1 命中多于1条
nRet = this.GetItemRecXml(
channel,
strItemBarcode,
out strItemXml,
out strOutputItemRecPath,
out item_timestamp,
out strError);
if (nRet == 0)
{
result.Value = -1;
// text-level: 用户提示
result.ErrorInfo = string.Format(this.GetString("册条码号s不存在"), // "册条码号 {0} 不存在"
strItemBarcode);
// "册条码号 '" + strItemBarcode + "' 不存在";
result.ErrorCode = ErrorCode.ItemBarcodeNotFound;
return result;
}
if (nRet == -1)
{
// text-level: 内部错误
strError = string.Format(this.GetString("读入册记录时发生错误s"), // "读入册记录时发生错误: {0}"
strError);
// "读入册记录时发生错误: " + strError;
goto ERROR1;
}
if (nRet > 1)
{
// text-level: 内部错误
strError = string.Format(this.GetString("册条码号s有重复"), // "册条码号 '{0}' 有重复({1}条),无法进行预约操作。"
strItemBarcode,
nRet.ToString());
// "册条码号 '" + strItemBarcode + "' 有重复(" + nRet.ToString() + "条),无法进行预约操作。";
}
nRet = LibraryApplication.LoadToDom(strItemXml,
out XmlDocument itemdom,
out strError);
if (nRet == -1)
{
// text-level: 内部错误
strError = string.Format(this.GetString("装载册记录进入XMLDOM时发生错误s"), // "装载册记录进入XML DOM时发生错误: {0}"
strError);
// "装载册记录进入XML DOM时发生错误: " + strError;
goto ERROR1;
}
string strItemLibraryCode = GetItemLibraryCode(itemdom);
records.Add(strOutputItemRecPath, itemdom, item_timestamp);
// TODO: 若册属于个人藏书,则不仅要求预约者是同一分馆的读者,另外还要求预约者是主人的好友。即,主人的读者记录中 firends 列表中有预约者
if (strFunction != "delete")
{
// 2012/9/13
// 检查一个册记录的馆藏地点是否符合馆代码列表要求
// return:
// -1 检查过程出错
// 0 符合要求
// 1 不符合要求
nRet = CheckItemLibraryCode(itemdom,
strPatronLibraryCode,
out strError);
if (nRet == -1)
goto ERROR1;
if (nRet == 1)
{
if (AllowCrossBorrow(sessioninfo, strItemLibraryCode) == false)
{
strError = "册记录 '" + strItemBarcode + "' 因馆藏地而不能进行预约: " + strError;
goto ERROR1;
}
}
}
// 检查册是否允许借出?
if (strFunction == "new")
{
// 2011/12/7
// 检查册记录状态
string strState = DomUtil.GetElementText(itemdom.DocumentElement,
"state");
if (string.IsNullOrEmpty(strState) == false)
{
// text-level: 用户提示
strError = string.Format(this.GetString("册状态为s无法预约"), // "册 {0} 状态为 '{1}' ,无法进行预约操作。"
strItemBarcode,
strState,
nRet.ToString());
goto ERROR1;
}
StringBuilder debugInfo = null;
// 检查册是否允许被借出
// return:
// -1 出错
// 0 借阅操作应该被拒绝
// 1 借阅操作应该被允许
nRet = CheckCanBorrow(
strPatronLibraryCode,
false,
sessioninfo.Account,
strOutputReaderRecPath,
readerdom,
strOutputItemRecPath,
itemdom,
ref debugInfo,
out strError);
if (nRet == -1)
goto ERROR1;
if (nRet == 0)
{
strError = string.Format("因册 {0} 不允许借出,所以也不允许预约: {1}", strItemBarcode, strError);
goto ERROR1;
// TODO: 这里是否可以跳过不允许借书的一册,继续向后处理?
}
}
// 在册记录中添加或者删除预约信息
nRet = this.DoReservationItemXml(
records,
channel,
strFunction,
strReaderBarcode,
sessioninfo.UserID,
ref itemdom,
out bool bOnShelf,
out bool bArrived,
out strError);
if (nRet == -1)
goto ERROR1;
if (strFunction == "delete")
{
nRet = NotifyCancelArrive(
channel,
strItemBarcode,
"", // strRefID 暂时不使用此参数
itemdom,
strPatronLibraryCode,
strReaderBarcode,
strReaderXml,
out strError);
if (nRet == -1)
{
this.WriteErrorLog("发出放弃取书通知(册条码号=" + strItemBarcode + ")时出错: " + strError);
}
}
if (bOnShelf == true)
OnShelfItemBarcodes.Add(strItemBarcode);
if (bArrived == true)
ArriveItemBarcodes.Add(strItemBarcode);
// 写回册记录
lRet = channel.DoSaveTextRes(strOutputItemRecPath,
itemdom.OuterXml,
false,
"content", // ,ignorechecktimestamp
item_timestamp,
out output_timestamp,
out strOutputPath,
out strError);
if (lRet == -1)
{
if (channel.ErrorCode == ChannelErrorCode.TimestampMismatch)
{
if (nRedoCount > 10)
{
// text-level: 内部错误
strError = "写回册记录 '" + strOutputItemRecPath + "' 时反复遇到时间戳冲突, 超过10次重试仍然失败";
goto ERROR1;
}
nRedoCount++;
goto REDO_LOAD;
}
// 当写操作发生错误时,将来用更科学的措施来undo,
// 即把刚才增加的<request>元素找到后删除
goto ERROR1;
}
records.Remove(strOutputItemRecPath);
}
finally
{
this.EntityLocks.UnlockForWrite(strItemBarcode);
}
} // end of for
// 在读者记录中加入或删除预约信息
// parameters:
// strFunction "new"新增预约信息;"delete"删除预约信息; "merge"合并; "split"拆散
// return:
// -1 error
// 0 unchanged
// 1 changed
nRet = this.DoReservationReaderXml(
strFunction,
strItemBarcodeList,
sessioninfo.UserID,
ref readerdom,
out strError);
if (nRet == -1)
goto ERROR1;
CachedRecord reader_record = records.Find(strOutputReaderRecPath);
if (nRet == 1 || (reader_record != null && reader_record.Changed))
{
// 野蛮写入
lRet = channel.DoSaveTextRes(strOutputReaderRecPath,
readerdom.OuterXml,
false,
"content,ignorechecktimestamp",
reader_timestamp,
out output_timestamp,
out strOutputPath,
out strError);
if (lRet == -1)
goto ERROR1;
records.Remove(strOutputReaderRecPath);
DomUtil.SetElementText(domOperLog.DocumentElement,
"action", strFunction);
DomUtil.SetElementText(domOperLog.DocumentElement,
"readerBarcode", strReaderBarcode);
DomUtil.SetElementText(domOperLog.DocumentElement,
"itemBarcodeList", strItemBarcodeList);
string strOperTime = this.Clock.GetClock();
DomUtil.SetElementText(domOperLog.DocumentElement, "operator",
sessioninfo.UserID); // 操作者
DomUtil.SetElementText(domOperLog.DocumentElement, "operTime",
strOperTime); // 操作时间
nRet = this.OperLog.WriteOperLog(domOperLog,
sessioninfo.ClientAddress,
out strError);
if (nRet == -1)
{
// text-level: 内部错误
strError = "Reservation() API 写入日志时发生错误: " + strError;
goto ERROR1;
}
// 写入统计指标
if (this.Statis != null)
this.Statis.IncreaseEntryValue(
strPatronLibraryCode,
"出纳",
"预约次",
1);
}
// 对当前在普通架的图书,立即发出到书通知
if (this.CanReserveOnshelf == true
&& OnShelfItemBarcodes.Count > 0)
{
// 只通知第一个在架的册
string strItemBarcode = OnShelfItemBarcodes[0];
if (string.IsNullOrEmpty(strItemBarcode) == true)
{
strError = "内部错误:OnShelfItemBarcodes 的第一个元素为空。数组情况 '" + StringUtil.MakePathList(OnShelfItemBarcodes) + "'";
goto ERROR1;
}
// 通知预约到书的操作
// 出于对读者库加锁方面的便利考虑, 单独做了此函数
// return:
// -1 error
// 0 没有找到<request>元素
nRet = DoReservationNotify(
null,
channel,
strReaderBarcode,
false, // 不需要函数内加读者锁,因为这里已经加了
strItemBarcode,
true, // 在普通架
true, // 需要修改当前册记录的<request>元素state属性
"",
out List<string> DeletedNotifyRecPaths, // 被删除的通知记录。不用。
out strError);
if (nRet == -1)
{
// text-level: 用户提示
strError = string.Format(this.GetString("预约操作已经成功, 但是在架立即通知功能失败, 原因s"), // "预约操作已经成功, 但是在架立即通知功能失败, 原因: {0}"
strError);
// "预约操作已经成功, 但是在架立即通知功能失败, 原因: " + strError;
goto ERROR1;
}
/*
if (this.Statis != null)
this.Statis.IncreaseEntryValue(
strLibraryCode,
"出纳",
"预约到书册",
1);
* */
// 给与成功提示
// text-level: 用户提示
string strMessage = string.Format(this.GetString("请注意,您刚提交的预约请求立即就得到了兑现"), // "请注意,您刚提交的预约请求立即就得到了兑现(预约到书通知消息也向您发出了,请注意查收)。所预约的册 {0} 为在架状态,已为您保留,您从现在起就可来图书馆办理借阅手续。"
strItemBarcode);
// "请注意,您刚提交的预约请求立即就得到了兑现(预约到书通知消息也向您发出了,请注意查收)。所预约的册 " + strItemBarcode + " 为在架状态,已为您保留,您从现在起就可来图书馆办理借阅手续。";
if (OnShelfItemBarcodes.Count > 1)
{
OnShelfItemBarcodes.Remove(strItemBarcode);
string[] barcodelist = new string[OnShelfItemBarcodes.Count];
OnShelfItemBarcodes.CopyTo(barcodelist);
// text-level: 用户提示
strMessage += string.Format(this.GetString("您在同一预约请求中也同时提交了其他在架状态的册"), // "您在同一预约请求中也同时提交了其他在架状态的册: {0}。因同一集合中的前述册 {1} 的生效,这些册同时被忽略。(如确要预约多个在架的册让它们都独立生效,请每次勾选一个后单独提交,而不要把多个册一次性提交。)"
String.Join(",", barcodelist),
strItemBarcode);
// "您在同一预约请求中也同时提交了其他在架状态的册: " + String.Join(",", barcodelist) + "。因同一集合中的前述册 " + strItemBarcode + " 的生效,这些册同时被忽略。(如确要预约多个在架的册让它们都独立生效,请每次勾选一个后单独提交,而不要把多个册一次性提交。)";
}
result.ErrorInfo = strMessage;
}
if (ArriveItemBarcodes.Count > 0)
{
string[] barcodelist = new string[ArriveItemBarcodes.Count];
ArriveItemBarcodes.CopyTo(barcodelist);
// text-level: 用户提示
result.ErrorInfo += string.Format(this.GetString("册s在删除前已经处在到书状态"), // "册 {0} 在删除前已经处在“到书”状态。您刚刚删除了这(些)请求,这意味着您已经放弃取书。图书馆将顺次满足后面排队等待的预约者的请求,或允许其他读者借阅此书。(若您意图要去图书馆正常取书,请一定不要去删除这样的状态为“已到书”的请求,软件会在您取书后自动删除)"
String.Join(",", barcodelist));
// "册 " + String.Join(",", barcodelist) + " 在删除前已经处在“到书”状态。您刚刚删除了这(些)请求,这意味着您已经放弃取书。图书馆将顺次满足后面排队等待的预约者的请求,或允许其他读者借阅此书。(若您意图要去图书馆正常取书,请一定不要去删除这样的状态为“已到书”的请求,软件会在您取书后自动删除)";
}
}
finally
{
this.ReaderLocks.UnlockForWrite(strReaderBarcode);
#if DEBUG_LOCK_READER
this.WriteErrorLog("Reservation 结束为读者加写锁 '" + strReaderBarcode + "'");
#endif
}
return result;
ERROR1:
result.Value = -1;
result.ErrorInfo = strError;
result.ErrorCode = ErrorCode.SystemError;
return result;
}
// 对即将预约的册条码号进行查重
// 要求本读者先前未曾用这些条码号预约过
// parameters:
// strLibraryCode 读者记录所在读者库的馆代码
// return:
// -1 出错
// 0 没有重
// 1 有重 提示信息在strError中
public int ReservationCheckDup(
string strItemBarcodeList,
string strLibraryCode,
ref XmlDocument readerdom,
out string strError)
{
strError = "";
if (String.IsNullOrEmpty(strItemBarcodeList) == true)
{
strError = this.GetString("册条码号列表不能为空"); // 册条码号列表不能为空
return -1;
}
string strReaderType = DomUtil.GetElementText(readerdom.DocumentElement,
"readerType");
// 得到该读者类型针对所有类型图书的"可预约册数"
// return:
// reader和book类型均匹配 算4分
// 只有reader类型匹配,算3分
// 只有book类型匹配,算2分
// reader和book类型都不匹配,算1分
int nRet = this.GetLoanParam(
//null,
strLibraryCode,
strReaderType,
"",
"可预约册数",
out string strParamValue,
out MatchResult matchresult,
out strError);
if (nRet == -1 || nRet < 3)
{
// text-level: 用户提示
strError = string.Format(this.GetString("读者类型s尚未定义可预约册数参数"), // "读者类型 '{0}' 尚未定义 可预约册数 参数, 预约操作被拒绝"
strReaderType);
// "读者类型 '" + strReaderType + "' 尚未定义 可预约册数 参数, 预约操作被拒绝";
return -1;
}
int nMaxReserveItems = 0;
try
{
nMaxReserveItems = Convert.ToInt32(strParamValue);
}
catch
{
// text-level: 内部错误
strError = "馆代码 '" + strLibraryCode + "' 中 读者类型 '" + strReaderType + "' 定义的 可预约册数 参数值 '" + strParamValue + "' 不合法,应当为纯数字";
return -1;
}
string[] newbarcodes = strItemBarcodeList.Split(new char[] { ',' });
XmlNodeList nodes = readerdom.DocumentElement.SelectNodes("reservations/request");
// 检查是否超过每个读者的配额
if (nodes.Count >= nMaxReserveItems)
{
// text-level: 用户提示
strError = string.Format(this.GetString("预约册数超过最大值"), // "本次预约前已经预约的事项数已经达到 {0},已经超过 读者类型 '{1}' 允许的可预约册数 {2},预约操作被拒绝"
nodes.Count,
strReaderType,
nMaxReserveItems.ToString());
// "本次预约前已经预约的事项数已经达到 " + nodes.Count + ",已经超过 读者类型 '" + strReaderType + "' 允许的可预约册数 " + nMaxReserveItems.ToString() + ",预约操作被拒绝";
return -1;
}
// 检查是否曾经预约过
foreach (XmlElement node in nodes)
{
// XmlNode node = nodes[i];
string strItems = DomUtil.GetAttr(node, "items");
string[] barcodes = strItems.Split(new char[] { ',' });
foreach (string barcode in barcodes)
{
string strBarcode = barcode.Trim();
if (String.IsNullOrEmpty(strBarcode) == true)
continue;
foreach (string newbarcode in newbarcodes)
{
string strNewBarcode = newbarcode.Trim();
if (String.IsNullOrEmpty(strNewBarcode) == true)
continue;
if (strNewBarcode == strBarcode)
{
// text-level: 用户提示
strError = string.Format(this.GetString("册条码号s已经被预约过"), // "册条码号 '{0}' 已经被预约过..."
strNewBarcode);
// "册条码号 '" + strNewBarcode + "' 已经被预约过...";
return 1;
}
} // end of newbarcodes
} // end for barcode
} // end for nodes
// 检查是否正被当前读者借阅
nodes = readerdom.DocumentElement.SelectNodes("borrows/borrow");
foreach (XmlElement node in nodes)
{
// XmlNode node = nodes[i];
string strItemBarcode = DomUtil.GetAttr(node, "barcode");
if (String.IsNullOrEmpty(strItemBarcode) == true)
continue;
foreach (string newbarcode in newbarcodes)
{
string strNewBarcode = newbarcode.Trim();
if (String.IsNullOrEmpty(strNewBarcode) == true)
continue;
if (strNewBarcode == strItemBarcode)
{
// text-level: 用户提示
strError = string.Format(this.GetString("册s已经被当前读者借阅"), // "册 '{0}' 已被当前读者借阅,因此不能被预约..."
strNewBarcode);
// "册 '" + strNewBarcode + "' 已被当前读者借阅,因此不能被预约...";
return 1;
}
} // end of newbarcodes
} // end for nodes
#if NO
// 检查册是否允许借出?
foreach (string newbarcode in newbarcodes)
{
string strNewBarcode = newbarcode.Trim();
if (String.IsNullOrEmpty(strNewBarcode) == true)
continue;
}
#endif
return 0;
}
// 在册记录中加入预约信息
// TODO: 要关注本函数到底保存了 itemdom 代表的册记录没有?因为这样会引起时间戳发生变化
// parameters:
// strFunction "new"新增预约信息;"delete"删除预约信息
// bOnShelf strFunction为"new"的情况下,如果册本来就没有人借阅,并且当前读者为预约该册的第一人,则bOnShelf返回true
// bArrived strFunciont为"delete"的情况下,删除了状态为"arrived"的预约请求
public int DoReservationItemXml(
CachedRecordCollection records,
RmsChannel channel,
string strFunction,
string strReaderBarcode,
string strOperator,
ref XmlDocument itemdom,
out bool bOnShelf,
out bool bArrived,
out string strError)
{
strError = "";
bOnShelf = false;
bArrived = false;
if (String.IsNullOrEmpty(strReaderBarcode) == true)
{
// text-level: 用户提示
strError = this.GetString("读者证条码号不能为空"); // 读者证条码号不能为空
return -1;
}
XmlNode root = null;
root = itemdom.DocumentElement.SelectSingleNode("reservations");
if (root == null)
{
root = itemdom.CreateElement("reservations");
root = itemdom.DocumentElement.AppendChild(root);
}
// 看看是否已经存在元素
XmlNode nodeRequest = root.SelectSingleNode("request[@reader='" + strReaderBarcode + "']");
if (String.Compare(strFunction, "new", true) == 0)
{
// 检查是否没有被人借阅
string strBorrower = DomUtil.GetElementText(itemdom.DocumentElement,
"borrower");
string strState = DomUtil.GetElementText(itemdom.DocumentElement,
"state");
string strItemBarcode = DomUtil.GetElementText(itemdom.DocumentElement,
"barcode");
XmlNodeList nodesRequest = itemdom.DocumentElement.SelectNodes("reservations/request");
if (String.IsNullOrEmpty(strBorrower) == true
&& nodesRequest.Count == 0)
{
// 2009/10/19
// 状态为“加工中”
if (IncludeStateProcessing(strState) == true
&& this.CanReserveOnshelf == false)
{
// text-level: 用户提示
strError = string.Format(this.GetString("不能预约加工中的册s"), // "不能预约状态为加工中的册 {0}"
strItemBarcode);
return -1;
}
if (this.CanReserveOnshelf == false)
{
// text-level: 用户提示
strError = string.Format(this.GetString("不能预约在架的册s"), // "不能预约在架(未被借出的)册 {0}"
strItemBarcode);
// "不能预约在架(未被借出的)册 " + strItemBarcode;
return -1;
}
if (IncludeStateProcessing(strState) == false) // 只有不包含“加工中”的,才马上通知。否则只能等以后状态改变时通知
{
// 如果本来就没有人借阅,而且当前读者是第一个预约该册的
bOnShelf = true;
}
}
if (nodeRequest == null)
{
nodeRequest = itemdom.CreateElement("request");
nodeRequest = root.AppendChild(nodeRequest);
DomUtil.SetAttr(nodeRequest, "reader", strReaderBarcode);
}
// 请求时间
DomUtil.SetAttr(nodeRequest, "requestDate", this.Clock.GetClock());
// 操作者
DomUtil.SetAttr(nodeRequest, "operator", strOperator);
}
if (String.Compare(strFunction, "delete", true) == 0)
{
// 2023/11/8
if (nodeRequest == null)
{
var itemBarcode = DomUtil.GetElementText(itemdom.DocumentElement,
"barcode");
if (string.IsNullOrEmpty(itemBarcode))
itemBarcode = "@refID:" + DomUtil.GetElementText(itemdom.DocumentElement,
"refID");
strError = $"册 '{itemBarcode}' 中并不存在读者 '{strReaderBarcode}' 请求过的预约事项";
return -1;
}
else
{
// 删除前要检查状态,是不是arrived
string strState = DomUtil.GetAttr(nodeRequest, "state");
if (strState == "arrived")
{
// TODO: 是否需要短信通知当前读者,这样意味着已经到的书放弃取。
string strItemBarcode = DomUtil.GetElementText(itemdom.DocumentElement,
"barcode");
string strQueueRecXml = "";
byte[] baQueueRecTimestamp = null;
string strQueueRecPath = "";
// 获得预约到书队列记录
// parameters:
// strItemBarcodeParam 册条码号。可以使用 @itemRefID: 前缀
// return:
// -1 error
// 0 not found
// 1 命中1条
// >1 命中多于1条
int nRet = GetArrivedQueueRecXml(
// channels,
channel,
strItemBarcode.Replace("@refID:", "@itemRefID:"),
out strQueueRecXml,
out baQueueRecTimestamp,
out strQueueRecPath,
out strError);
if (nRet == -1)
return -1;
if (nRet >= 1)
{
XmlDocument queue_rec_dom = new XmlDocument();
try
{
queue_rec_dom.LoadXml(strQueueRecXml);
}
catch (Exception ex)
{
// text-level: 内部错误
strError = "预约队列记录XML装入DOM时失败: " + ex.Message;
return -1;
}
nRet = DoNotifyNext(
records,
channel,
strQueueRecPath,
queue_rec_dom,
baQueueRecTimestamp,
out strError);
if (nRet == -1)
return -1;
if (nRet == 1)
{
// 需要归架
// 册记录中<location>需要去掉#reservation,相关<request>元素也需要删除
string strLocation = DomUtil.GetElementText(itemdom.DocumentElement,
"location");
// StringUtil.RemoveFromInList("#reservation", true, ref strLocation);
strLocation = StringUtil.GetPureLocationString(strLocation);
DomUtil.SetElementText(itemdom.DocumentElement,
"location", strLocation);
}
}
// 给出返回状态
bArrived = true;
} // end of -- if (strState == "arrived")
// 经过 DoNotifyNext() 以后 itemdom 内容可能会发生变化
nodeRequest = root.SelectSingleNode("request[@reader='" + strReaderBarcode + "']");
if (nodeRequest != null && nodeRequest.ParentNode != null)
nodeRequest.ParentNode.RemoveChild(nodeRequest);
} // end of -- if (nodeRequest != null)
}
return 0;
}
// 在读者记录中加入或删除预约信息
// parameters:
// strFunction "new"新增预约信息;"delete"删除预约信息; "merge"合并; "split"拆散
// strItemBarcodeList 册条码号的列表。每个部分可以使用 @refID: 前缀
// return:
// -1 error
// 0 unchanged