-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdp2CommandService.cs
More file actions
1054 lines (916 loc) · 35.8 KB
/
dp2CommandService.cs
File metadata and controls
1054 lines (916 loc) · 35.8 KB
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 DigitalPlatform;
using DigitalPlatform.IO;
using DigitalPlatform.Text;
using DigitalPlatform.LibraryRestClient;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using DigitalPlatform.Xml;
namespace dp2Command.Service
{
public class dp2CommandService : dp2BaseCommandService
{
//=================
// 设为单一实例
static dp2CommandService _instance;
private dp2CommandService()
{
//Thread.Sleep(100); //假设多线程的时候因某种原因阻塞100毫秒
}
static object _lock = new object();
static public dp2CommandService Instance
{
get
{
lock (_lock)
{
if (null == _instance)
{
_instance = new dp2CommandService();
}
}
return _instance;
}
}
//===========
// dp2服务器地址与代理账号
public string dp2Url = "";//"http://dp2003.com/dp2library/rest/"; //"http://localhost:8001/dp2library/rest/";//
public string dp2UserName = "";//"weixin";
public string dp2Password = "";//"111111";
// dp2通道池
public LibraryChannelPool ChannelPool = null;
// 是否使用mongodb存储微信用户与读者关系
private bool IsUseMongoDb = false;
/// <summary>
///
/// </summary>
/// <param name="strDp2Url"></param>
/// <param name="strDp2UserName"></param>
/// <param name="strDp2Password"></param>
/// <param name="weiXinUrl"></param>
/// <param name="weiXinLogDir"></param>
/// <param name="isUseMongoDb"></param>
/// <param name="mongoDbConnStr"></param>
/// <param name="instancePrefix"></param>
public void Init(string strDp2Url,
string strDp2UserName,
string strDp2Password,
string weiXinUrl,
string weiXinDataDir,
bool isUseMongoDb,
string mongoDbConnStr,
string instancePrefix
)
{
this.dp2Url = strDp2Url;
this.dp2UserName = strDp2UserName;
this.dp2Password = strDp2Password;
this.weiXinUrl = weiXinUrl;
this.weiXinDataDir = weiXinDataDir;
// 通道池对象
ChannelPool = new LibraryChannelPool();
ChannelPool.BeforeLogin -= new BeforeLoginEventHandle(Channel_BeforeLogin);
ChannelPool.BeforeLogin += new BeforeLoginEventHandle(Channel_BeforeLogin);
// 使用mongodb存储微信用户与读者绑定关系
this.IsUseMongoDb = isUseMongoDb;
if (this.IsUseMongoDb == true)
{
WxUserDatabase.Current.Open(mongoDbConnStr, instancePrefix);
}
}
/// <summary>
/// 自动登录,提供密码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Channel_BeforeLogin(object sender, BeforeLoginEventArgs e)
{
if (e.FirstTry == false)
{
e.Cancel = true;
return;
}
// 我这里赋上通道自己的账号,而不是使用全局变量。
// 因为从池中征用通道后,都给通道设了密码。账号密码是通道的属性。
LibraryChannel channel = sender as LibraryChannel;
e.LibraryServerUrl = channel.Url;
e.UserName = channel.UserName;
e.Password = channel.Password;
e.Parameters = "client=ilovelibrary|1.0"; //todo 写到这里合适吗
}
#region 检索相关
/// <summary>
/// 检索书目
/// </summary>
/// <param name="strWord"></param>
/// <returns></returns>
public override long SearchBiblio(string remoteUserName,
string strWord,
SearchCommand searchCmd,
out string strFirstPage,
out string strError)
{
strFirstPage = "";
strError = "";
// 判断检索词
strWord = strWord.Trim();
if (String.IsNullOrEmpty(strWord))
{
strError = "检索词不能为空。";
return -1;
}
long lTotoalCount = 0;
// 从池中征用通道
LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
channel.Password = this.dp2Password;
try
{
/*
public long SearchBiblio(
string strBiblioDbNames,
string strQueryWord,
int nPerMax,
string strFromStyle,
string strMatchStyle,
string strResultSetName,
string strOutputStyle,
out string strError)
*/
// -1失败
// 0 未命令
string strQueryXml = "";
long lRet = channel.SearchBiblio("",//全部途径
strWord,
C_Search_MaxCount,
"",
"middle",
"", // "weixin-biblio";
"id,cols",
out strQueryXml,
out strError);
if (lRet == -1 || lRet == 0)
{
return lRet;
}
// 取出命中记录列表
lTotoalCount = lRet;
List<string> totalResultList = new List<string>();
long lStart = 0;
// 当前总共取的多少记录
long lCurTotalCount = 0;
REDO:
List<string> resultPathList = null;
long lCount = -1;
lRet = channel.GetBiblioSearchResult(lStart,
lCount,
out resultPathList,
out strError);
if (lRet == -1)
return -1;
// 加到结果集中
totalResultList.AddRange(resultPathList);
// 检查记录是否获取完成,没取完继续取
lCurTotalCount += lRet;
if (lCurTotalCount < lTotoalCount)
{
lStart = lCurTotalCount;
goto REDO;
}
// 检查一下,取出来的记录数,是否与返回的命中数量一致
if (lTotoalCount != totalResultList.Count)
{
strError = "内部错误,不可能结果集数量不一致";
return -1;
}
// 将检索结果信息保存到检索命令中
searchCmd.BiblioResultPathList = totalResultList;
searchCmd.ResultNextStart = 0;
searchCmd.IsCanNextPage = true;
// 获得第一页检索结果
bool bRet = searchCmd.GetNextPage(out strFirstPage, out strError);
if (bRet == false)
{
return -1;
}
}
finally
{
// 归还通道到池
this.ChannelPool.ReturnChannel(channel);
}
return lTotoalCount;
}
/// <summary>
/// 根据书目序号得到详细的参考信息
/// </summary>
/// <param name="nIndex">书目序号,从1排序</param>
/// <param name="strInfo"></param>
/// <param name="strError"></param>
/// <returns></returns>
public override int GetDetailBiblioInfo(string remoteUserName,
SearchCommand searchCmd,
int nIndex,
out string strBiblioInfo,
out string strError)
{
strBiblioInfo = "";
strError = "";
Debug.Assert(searchCmd != null);
//检查有无超过数组界面
if (nIndex <= 0 || searchCmd.BiblioResultPathList.Count < nIndex)
{
strError = "您输入的书目序号[" + nIndex.ToString() + "]越出范围。";
return -1;
}
// 获取路径,注意要截取
string strPath = searchCmd.BiblioResultPathList[nIndex - 1];
int index = strPath.IndexOf("*");
if (index > 0)
strPath = strPath.Substring(0, index);
LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
channel.Password = this.dp2Password;
try
{
long lRet1 = channel.GetBiblioDetail(strPath,
out strBiblioInfo,
out strError);
if (lRet1 == -1)
{
strError = "获取详细信息失败:" + strError;
return -1;
}
}
finally
{
this.ChannelPool.ReturnChannel(channel);
}
return 0;
}
/// <summary>
/// 根据操作时间检索
/// </summary>
/// <param name="strWord"></param>
/// <param name="searchCmd"></param>
/// <param name="strFirstPage"></param>
/// <param name="strError"></param>
/// <returns></returns>
public long SearchBiblioByPublishtime(string strWord,
SearchCommand searchCmd,
out string strFirstPage,
out string strError)
{
strFirstPage = "";
strError = "";
// 判断检索词
strWord = strWord.Trim();
if (String.IsNullOrEmpty(strWord))
{
strError = "检索词不能为空。";
return -1;
}
long lTotoalCount = 0;
// 从池中征用通道
LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
channel.Password = this.dp2Password;
try
{
/*
public long SearchBiblio(
string strBiblioDbNames,
string strQueryWord,
int nPerMax,
string strFromStyle,
string strMatchStyle,
string strResultSetName,
string strOutputStyle,
out string strError)
*/
// -1失败
// 0 未命令
string strQueryXml = "";
long lRet = channel.SearchBiblio("",//全部途径
strWord,
C_Search_MaxCount,
"publishtime,_time,_freetime",
"left",
"",
"id,cols",
out strQueryXml,
out strError);
if (lRet == -1 || lRet == 0)
{
return lRet;
}
// 取出命中记录列表
lTotoalCount = lRet;
List<string> totalResultList = new List<string>();
long lStart = 0;
// 当前总共取的多少记录
long lCurTotalCount = 0;
REDO:
List<string> resultPathList = null;
long lCount = -1;
lRet = channel.GetBiblioSearchResult(lStart,
lCount,
out resultPathList,
out strError);
if (lRet == -1)
return -1;
// 加到结果集中
totalResultList.AddRange(resultPathList);
// 检查记录是否获取完成,没取完继续取
lCurTotalCount += lRet;
if (lCurTotalCount < lTotoalCount)
{
lStart = lCurTotalCount;
goto REDO;
}
// 检查一下,取出来的记录数,是否与返回的命中数量一致
if (lTotoalCount != totalResultList.Count)
{
strError = "内部错误,不可能结果集数量不一致";
return -1;
}
// 将检索结果信息保存到检索命令中
searchCmd.BiblioResultPathList = totalResultList;
searchCmd.ResultNextStart = 0;
searchCmd.IsCanNextPage = true;
// 获得第一页检索结果
bool bRet = searchCmd.GetNextPage(out strFirstPage, out strError);
if (bRet == false)
{
return -1;
}
}
finally
{
// 归还通道到池
this.ChannelPool.ReturnChannel(channel);
}
return lTotoalCount;
}
#endregion
#region 绑定解绑
/// <summary>
///
/// </summary>
/// <param name="strBarcode"></param>
/// <param name="strPassword"></param>
/// <param name="weiXinId"></param>
/// <returns>
/// -1 出错
/// 0 读者证条码号或密码不正确
/// 1 成功
/// </returns>
public override int Bind(string remoteUserName,
string libCode,
string strFullWord,
string strPassword,
string strWeiXinId,
out WxUserItem userItem,
out string strReaderBarcode,
out string strError)
{
userItem = null;
strError = "";
strReaderBarcode = "";
LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
channel.Password = this.dp2Password;
try
{
// 检验用户名与密码
long lRet = channel.VerifyReaderPassword(strFullWord,
strPassword,
out strError);
if (lRet == -1)
{
strError = "读者证条码号或密码不正确。\n请重新输入'读者证条码号'(注:您也可以同时输入'读者证条码号'和'密码',中间以/分隔,例如:R0000001/123)";
return 0;
}
if (lRet == 0)
{
strError = "读者证条码号或密码不正确。\n请重新输入'读者证条码号'(注:您也可以同时输入'读者证条码号'和'密码',中间以/分隔,例如:R0000001/123)";
return 0;
}
if (lRet == 1)
{
// 进行绑定
// 先根据barcode检索出来,得到原记录与时间戳
GetReaderInfoResponse response = channel.GetReaderInfo(strFullWord,
"xml");
if (response.GetReaderInfoResult.Value != 1)
{
strError = "根据读者证条码号得到读者记录异常:" + response.GetReaderInfoResult.ErrorInfo;
return -1;
}
string strRecPath = response.strRecPath;
string strTimestamp = StringUtil.GetHexTimeStampString(response.baTimestamp);
string strXml = response.results[0];
// 改读者的email字段
XmlDocument readerDom = new XmlDocument();
readerDom.LoadXml(strXml);
XmlNode emailNode = readerDom.SelectSingleNode("//email");
if (emailNode == null)
{
emailNode = readerDom.CreateElement("email");
readerDom.DocumentElement.AppendChild(emailNode);
}
emailNode.InnerText = JoinEmail(emailNode.InnerText, strWeiXinId);
string strNewXml = ConvertXmlToString(readerDom);
// 更新到读者库
lRet = channel.SetReaderInfoForWeiXin(strRecPath,
strNewXml,
strTimestamp,
out strError);
if (lRet == -1)
{
strError = "绑定出错:" + strError;
return -1;
}
// 绑定成功,把读者证条码记下来,用于续借 2015/11/7,不要用strbarcode变量,因为可能做的大小写转换
strReaderBarcode = DomUtil.GetNodeText(readerDom.DocumentElement.SelectSingleNode("barcode"));
// 将关系存到mongodb库
if (this.IsUseMongoDb == true)
{
//name
string name = "";
XmlNode node = readerDom.DocumentElement.SelectSingleNode("name");
if (node != null)
name = DomUtil.GetNodeText(node);
userItem = WxUserDatabase.Current.GetActiveOrFirst(strWeiXinId,libCode);
if (userItem == null)
{
userItem = new WxUserItem();
userItem.weixinId = strWeiXinId;
userItem.libCode = "";
userItem.libUserName = "";
userItem.readerBarcode = strReaderBarcode;
userItem.readerName = name;
userItem.xml = strXml;
userItem.refID = strRecPath;
userItem.createTime = DateTimeUtil.DateTimeToString(DateTime.Now);
userItem.updateTime = userItem.createTime;
WxUserDatabase.Current.Add(userItem);
}
else
{
userItem.readerBarcode = strReaderBarcode;
userItem.readerName = name;
userItem.xml = strXml;
userItem.refID = strRecPath;
userItem.updateTime = DateTimeUtil.DateTimeToString(DateTime.Now);
lRet = WxUserDatabase.Current.Update(userItem);
}
}
return 1;
}
strError = "校验读者账号返回未知情况,返回值:" + lRet.ToString() + "-" + strError;
return -1;
}
finally
{
this.ChannelPool.ReturnChannel(channel);
}
}
/// <summary>
/// 根据微信id检索读者
/// </summary>
/// <param name="strWeiXinId"></param>
/// <param name="strRecPath"></param>
/// <param name="strXml"></param>
/// <param name="strError"></param>
/// <returns></returns>
public override long SearchOnePatronByWeiXinId(string remoteUserName,
string libCode,
string strWeiXinId,
out string strBarcode,
out string strError)
{
strError = "";
strBarcode = "";
long lRet = 0;
LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
channel.Password = this.dp2Password;
try
{
strWeiXinId = dp2CommandUtility.C_WeiXinIdPrefix + strWeiXinId;//weixinid:
// 先从mongodb查
if (this.IsUseMongoDb == true)
{
return 0;
}
lRet = channel.SearchReader("",
strWeiXinId,
-1,
"email",
"exact",
"zh",
"weixin",
"keyid",
out strError);
if (lRet == -1)
{
strError = "检索微信用户对应的读者出错:" + strError;
return -1;
}
else if (lRet > 1)
{
strError = "检索微信用户对应的读者异常,得到" + lRet.ToString() + "条读者记录";
return -1;
}
else if (lRet == 0)
{
strError = "根据微信id未找到对应读者。";
return 0;
}
else if (lRet == 1)
{
Record[] searchresults = null;
lRet = channel.GetSearchResult("weixin",
0,
-1,
"id,xml",
"zh",
out searchresults,
out strError);
if (searchresults.Length != 1)
{
throw new Exception("获得的记录数不是1");
}
if (lRet != 1)
{
strError = "获取结果集异常:" + strError;
return -1;
}
string strXml = searchresults[0].RecordBody.Xml;
XmlDocument dom = new XmlDocument();
dom.LoadXml(strXml);
strBarcode = DomUtil.GetNodeText(dom.DocumentElement.SelectSingleNode("barcode"));
// 将关系存到mongodb库
if (this.IsUseMongoDb == true)
{
//name
string name = "";
XmlNode node = dom.DocumentElement.SelectSingleNode("name");
if (node != null)
name = DomUtil.GetNodeText(node);
WxUserItem userItem = new WxUserItem();
userItem.weixinId = strWeiXinId;
userItem.readerBarcode = strBarcode;
userItem.readerName = name;
userItem.libCode = "";
userItem.libUserName = "";
userItem.xml = strXml;
userItem.refID = searchresults[0].Path ;
userItem.createTime = DateTimeUtil.DateTimeToString(DateTime.Now);
userItem.updateTime = userItem.createTime;
WxUserDatabase.Current.Add(userItem);
}
}
}
finally
{
this.ChannelPool.ReturnChannel(channel);
}
return 0;
}
/// <summary>
///
/// </summary>
/// <param name="weiXinId"></param>
/// <param name="strError"></param>
/// <returns>
/// -1 出错
/// 0 成功
/// </returns>
public override int Unbind(string remoteUserName,
string libCode,
string strBarcode,
string strWeiXinId,
out string strError)
{
strError = "";
LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
channel.Password = this.dp2Password;
try
{
// 得到原读者记录与时间戳
GetReaderInfoResponse response = channel.GetReaderInfo(strBarcode, "xml");
if (response.GetReaderInfoResult.Value != 1)
{
strError = "根据路径得到读者记录异常:" + response.GetReaderInfoResult.ErrorInfo;
return -1;
}
string strRecPath = response.strRecPath;
string strTimestamp = StringUtil.GetHexTimeStampString(response.baTimestamp);
string strXml = response.results[0];
// 修改xml中的email字段,去掉weixin:***
// 改为读者的email字段
XmlDocument readerDom = new XmlDocument();
readerDom.LoadXml(strXml);
XmlNode emailNode = readerDom.SelectSingleNode("//email");
string email = emailNode.InnerText.Trim();
string strEmailLeft = email;
string strEmailLRight = "";
int nIndex = email.IndexOf(dp2CommandUtility.C_WeiXinIdPrefix);//"weixinid:");
if (nIndex >= 0)
{
strEmailLeft = email.Substring(0, nIndex);
string strOldWeixinId = email.Substring(nIndex);
nIndex = strOldWeixinId.IndexOf(',');
if (nIndex > 0)
{
strEmailLRight = strOldWeixinId.Substring(nIndex);
strOldWeixinId = strOldWeixinId.Substring(0, nIndex);
}
strEmailLeft = TrimComma(strEmailLeft);
strEmailLRight = TrimComma(strEmailLRight);
}
email = strEmailLeft;
if (strEmailLRight != "")
{
if (email != "")
email += ",";
email += strEmailLRight;
}
emailNode.InnerText = email;
string strNewXml = ConvertXmlToString(readerDom);
// 更新到读者库
long lRet = channel.SetReaderInfoForWeiXin(strRecPath,
strNewXml,
strTimestamp,
out strError);
if (lRet == -1)
{
strError = "解除绑定出错:" + strError;
return -1;
}
// 从mongodb删除
if (this.IsUseMongoDb == true)
{
//todo
//long nCount = WxUserDatabase.Current.Delete(strWeiXinId, strBarcode,libCode);
}
return 0;
}
finally
{
this.ChannelPool.ReturnChannel(channel);
}
}
#endregion
#region 我的空间
/// <summary>
/// 续借
/// </summary>
/// <param name="strItemBarcode">册条码号</param>
/// <returns></returns>
public override int Renew(string remoteUserName,
string strReaderBarcode,
string strItemBarcode,
out BorrowInfo borrowInfo,
out string strError)
{
borrowInfo = null;
strError = "";
if (strItemBarcode == null)
strItemBarcode = "";
strItemBarcode = strItemBarcode.Trim();
if (strItemBarcode == "")
{
strError = "续借失败:您输入的续借图书编号或者册条码号为空。";
return -1;
}
if (String.IsNullOrEmpty(strReaderBarcode) == true)
{
strError = "续借失败:内部错误,读者证条码号为空。";
return -1;
}
/*
// 优先从序号字典中找下
if (this.CurrentMessageContext.BorrowDict.ContainsKey(strItemBarcode))
{
string temp = this.CurrentMessageContext.BorrowDict[strItemBarcode];
if (temp != null && temp != "")
strItemBarcode = temp;
}
*/
LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
channel.Password = this.dp2Password;
try
{
string strOutputReaderBarcode = "";
string strReaderXml = "";
long lRet = channel.Borrow(true,
strReaderBarcode,
strItemBarcode,
out strOutputReaderBarcode,
out strReaderXml,
out borrowInfo,
out strError);
if (lRet == -1)
return -1;
return 1;
}
finally
{
this.ChannelPool.ReturnChannel(channel);
}
}
/// <summary>
///
/// </summary>
/// <param name="openid"></param>
/// <param name="myinfo"></param>
/// <param name="strError"></param>
/// <returns>
/// -1 出错
/// 0 未找到读者记录
/// 1 成功
/// </returns>
public override int GetMyInfo(string remoteUserName,
string strReaderBarcode,
out string strMyInfo,
out string strError)
{
strError = "";
strMyInfo = "";
Debug.Assert(String.IsNullOrEmpty(strReaderBarcode) == false);
// 得到高级xml
string strXml = "";
long lRet = this.GetReaderAdvanceXml(strReaderBarcode, out strXml,
out strError);
if (lRet == -1)
return -1;
// 取出个人信息
XmlDocument dom = new XmlDocument();
dom.LoadXml(strXml);
//string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "barcode");
string strName = DomUtil.GetElementText(dom.DocumentElement, "name");
string strDepartment = DomUtil.GetElementText(dom.DocumentElement, "department");
string strState = DomUtil.GetElementText(dom.DocumentElement, "state");
string strCreateDate = DateTimeUtil.ToLocalTime(DomUtil.GetElementText(dom.DocumentElement,
"createDate"), "yyyy/MM/dd");
string strExpireDate = DateTimeUtil.ToLocalTime(DomUtil.GetElementText(dom.DocumentElement,
"expireDate"), "yyyy/MM/dd");
string strReaderType = DomUtil.GetElementText(dom.DocumentElement,
"readerType");
string strComment = DomUtil.GetElementText(dom.DocumentElement,
"comment");
strMyInfo = "个人信息" + "\n"
+ "姓名:" + strName + "\n"
+ "证条码号:" + strReaderBarcode + "\n"
+ "部门:" + strDepartment + "\n"
+ "联系方式:\n" + GetContactString(dom) + "\n"
+ "状态:" + strState + "\n"
+ "有效期:" + strCreateDate + "~" + strExpireDate + "\n"
+ "读者类别:" + strReaderType + "\n"
+ "注释:" + strComment;
return 1;
}
/// <summary>
///
/// </summary>
/// <param name="openid"></param>
/// <param name="strMyInfo"></param>
/// <param name="strError"></param>
/// <returns>
/// -1 出错
/// 0 未找到读者记录
/// 1 成功
/// </returns>
public override int GetBorrowInfo(string remoteUserName,
string strReaderBarcode, out string strBorrowInfo, out string strError)
{
strError = "";
strBorrowInfo = "";
// 得到高级xml
string strXml = "";
long lRet = this.GetReaderAdvanceXml(strReaderBarcode, out strXml,
out strError);
if (lRet == -1)
return -1;
// 提取借书信息
lRet = this.GetBorrowsInfoInternal(strXml, out strBorrowInfo);
if (lRet == -1)
return -1;
return 1;
}
/// <summary>
/// 获取读者Advance Xml
/// </summary>
/// <param name="strRecPath"></param>
/// <param name="strXml"></param>
/// <param name="strError"></param>
/// <returns></returns>
private int GetReaderAdvanceXml(string strReaderBarcode, out string strXml, out string strError)
{
strXml = "";
strError = "";
LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
channel.Password = this.dp2Password;
try
{
// 先根据barcode检索出来,得到原记录与时间戳
GetReaderInfoResponse response = channel.GetReaderInfo(strReaderBarcode,//"@path:" + strRecPath,
"advancexml,advancexml_borrow_bibliosummary,advancexml_overdue_bibliosummary");
if (response.GetReaderInfoResult.Value != 1)
{
strError = "根据读者证条码号得到读者记录异常:" + response.GetReaderInfoResult.ErrorInfo;
return -1;
}
string strTimestamp = StringUtil.GetHexTimeStampString(response.baTimestamp);
strXml = response.results[0];
return 1;
}
finally
{
this.ChannelPool.ReturnChannel(channel);
}
}
#endregion
#region 静态函数
/// <summary>
/// 拼email
/// </summary>
/// <param name="oldEmail"></param>
/// <param name="openid"></param>
/// <returns></returns>
public static string JoinEmail(string oldEmail, string openid)
{
string email = oldEmail.Trim();
string strEmailLeft = email;
string strEmailLRight = "";
int nIndex = email.IndexOf(dp2CommandUtility.C_WeiXinIdPrefix);//"weixinid:");
if (nIndex > 0)
{
strEmailLeft = email.Substring(0, nIndex);
string strOldWeixinId = email.Substring(nIndex);
nIndex = strOldWeixinId.IndexOf(',');
if (nIndex > 0)
{
strEmailLRight = strOldWeixinId.Substring(nIndex);
strOldWeixinId = strOldWeixinId.Substring(0, nIndex);
}
strEmailLeft = TrimComma(strEmailLeft);
strEmailLRight = TrimComma(strEmailLRight);
}
email = strEmailLeft;
if (strEmailLRight != "")
{
if (email != "")
email += ",";
email += strEmailLRight;
}
if (openid != null && openid != "")
{
if (email != "")
email += ",";
email += dp2CommandUtility.C_WeiXinIdPrefix + openid;// "weixinid:"
}