Skip to content

Commit b2ab323

Browse files
持续重构
1 parent bc9e22e commit b2ab323

File tree

13 files changed

+1821
-990
lines changed

13 files changed

+1821
-990
lines changed

DigitalPlatform.LibraryService/LibraryService.cs

+266-3
Original file line numberDiff line numberDiff line change
@@ -3214,7 +3214,7 @@ public LibraryServerResult GetSearchResult(
32143214
string filePath = app.GetMemorySetFilePath(
32153215
sessioninfo,
32163216
strResultSetName,
3217-
strBrowseInfoStyle);
3217+
strBrowseInfoStyle);
32183218

32193219
BeginSearch(); // 如果创建本地结果集的时间太长,前端可以用 Stop() API 中断
32203220
channel.Idle += new IdleEventHandler(channel_IdleEvent);
@@ -3276,6 +3276,14 @@ public LibraryServerResult GetSearchResult(
32763276
return result;
32773277
}
32783278

3279+
// 2022/11/29
3280+
if (searchresults != null
3281+
&& StringUtil.IsInList("keycount", strBrowseInfoStyle) == false)
3282+
{
3283+
FilterResultSet(searchresults,
3284+
strBrowseInfoStyle);
3285+
}
3286+
#if OLD
32793287
// 2021/7/15
32803288
// 过滤结果
32813289
// 对 XML 记录进行过滤或者修改
@@ -3476,6 +3484,8 @@ public LibraryServerResult GetSearchResult(
34763484
}
34773485
}
34783486
}
3487+
#endif
3488+
34793489

34803490
result.Value = lRet;
34813491
result.ErrorInfo = strError;
@@ -3493,6 +3503,206 @@ public LibraryServerResult GetSearchResult(
34933503
}
34943504
}
34953505

3506+
// 2022/11/29 从 GetSearchResult() 处理中转移到此处。可能和 GetBrowseRecords() 中的旧代码有差异
3507+
// 对 XML 记录进行过滤或者修改
3508+
void FilterResultSet(Record[] searchresults,
3509+
string strBrowseInfoStyle)
3510+
{
3511+
// 2012/9/15
3512+
// 当前用户是否能管辖一个读者库。key 为数据库名,value 为 true 或 false
3513+
Hashtable table = new Hashtable(); // 加快运算速度
3514+
3515+
// return:
3516+
// null 没有找到 getreaderinfo 前缀
3517+
// "" 找到了前缀,并且 level 部分为空
3518+
// 其他 返回 level 部分
3519+
string read_level = LibraryApplication.GetReaderInfoLevel("getreaderinfo", sessioninfo.RightsOrigin);
3520+
bool bHasGetReaderInfoRight = read_level != null;
3521+
// bool bHasGetReaderInfoRight = StringUtil.IsInList("getreaderinfo", sessioninfo.RightsOrigin);
3522+
3523+
bool bHasGetBiblioInfoRight = StringUtil.IsInList("getbiblioinfo", sessioninfo.RightsOrigin);
3524+
3525+
foreach (Record record in searchresults)
3526+
{
3527+
string strDbName = ResPath.GetDbName(record.Path);
3528+
3529+
bool bIsReader = sessioninfo.UserType == "reader";
3530+
3531+
if (app.IsReaderDbName(strDbName))
3532+
{
3533+
// 2021/7/20
3534+
// 先检测当前用户是否能管辖读者库 strDbName
3535+
bool bChangeable = true;
3536+
3537+
if (bIsReader)
3538+
{
3539+
// 不是读者自己的读者记录或者下级记录(比如对象记录)
3540+
if (sessioninfo.Account == null
3541+
|| StringUtil.IsEqualOrSubPath(sessioninfo.Account.ReaderDomPath, record.Path) == false)
3542+
bChangeable = false;
3543+
}
3544+
else
3545+
{
3546+
object o = table[strDbName];
3547+
if (o == null)
3548+
{
3549+
if (app.IsReaderDbName(strDbName,
3550+
out bool bReaderDbInCirculation,
3551+
out string strLibraryCode) == true)
3552+
{
3553+
// 检查当前操作者是否管辖这个读者库
3554+
// 观察一个读者记录路径,看看是不是在当前用户管辖的读者库范围内?
3555+
bChangeable = app.IsCurrentChangeableReaderPath(strDbName + "/?",
3556+
sessioninfo.ExpandLibraryCodeList/*sessioninfo.LibraryCodeList*/);
3557+
}
3558+
table[strDbName] = bChangeable; // 记忆
3559+
}
3560+
else
3561+
bChangeable = (bool)o;
3562+
}
3563+
3564+
if (bChangeable == false)
3565+
{
3566+
// 当前用户不管辖此读者库
3567+
ClearRecord(record, $"当前用户不管辖读者库 '{strDbName}'");
3568+
record.Path = "";
3569+
/*
3570+
record.Cols = null;
3571+
record.RecordBody = null;
3572+
*/
3573+
}
3574+
else
3575+
{
3576+
// 过滤
3577+
FilterPatronRecord(record,
3578+
strDbName,
3579+
read_level,
3580+
strBrowseInfoStyle);
3581+
}
3582+
}
3583+
else if (app.IsBiblioDbName(strDbName))
3584+
{
3585+
/*
3586+
if (bHasGetBiblioInfoRight == false)
3587+
{
3588+
ClearCols(record, "[滤除]");
3589+
}
3590+
*/
3591+
FilterBiblioRecord(record,
3592+
strDbName,
3593+
bHasGetBiblioInfoRight,
3594+
sessioninfo.Access,
3595+
strBrowseInfoStyle);
3596+
}
3597+
else if (app.IsItemDbName(strDbName))
3598+
{
3599+
if (StringUtil.IsInList("getiteminfo,getentities,order", sessioninfo.RightsOrigin) == false)
3600+
{
3601+
ClearXml(record);
3602+
ClearCols(record, LibraryApplication.FILTERED);
3603+
}
3604+
else
3605+
AddItemOI(app, sessioninfo, record, "filter_borrower");
3606+
}
3607+
else if (app.IsIssueDbName(strDbName))
3608+
{
3609+
if (StringUtil.IsInList("getissues,getissueinfo,order", sessioninfo.RightsOrigin) == false)
3610+
{
3611+
ClearXml(record);
3612+
ClearCols(record, LibraryApplication.FILTERED);
3613+
}
3614+
}
3615+
else if (app.IsOrderDbName(strDbName))
3616+
{
3617+
if (StringUtil.IsInList("getorders,getorderinfo,order", sessioninfo.RightsOrigin) == false)
3618+
{
3619+
ClearXml(record);
3620+
ClearCols(record, LibraryApplication.FILTERED);
3621+
}
3622+
}
3623+
else if (app.IsCommentDbName(strDbName))
3624+
{
3625+
if (StringUtil.IsInList("getcommentinfo,order", sessioninfo.RightsOrigin) == false)
3626+
{
3627+
ClearXml(record);
3628+
ClearCols(record, LibraryApplication.FILTERED);
3629+
}
3630+
}
3631+
else if (app.ArrivedDbName == strDbName)
3632+
{
3633+
if (StringUtil.IsInList("borrow,return", sessioninfo.RightsOrigin) == true
3634+
|| read_level == "")
3635+
{
3636+
3637+
}
3638+
else
3639+
{
3640+
ClearXml(record);
3641+
ClearCols(record, LibraryApplication.FILTERED);
3642+
}
3643+
}
3644+
else if (app.AmerceDbName == strDbName)
3645+
{
3646+
if (StringUtil.IsInList("getrecord", sessioninfo.RightsOrigin) == false
3647+
|| sessioninfo.UserType == "reader")
3648+
{
3649+
ClearXml(record);
3650+
ClearCols(record, LibraryApplication.FILTERED);
3651+
}
3652+
else
3653+
FilterAmerceRecord(record);
3654+
// 注: GetRecord() API 可以获取违约金记录
3655+
// settlement undosettlement deletesettlement
3656+
}
3657+
else if (app.MessageDbName == strDbName)
3658+
{
3659+
if (StringUtil.IsInList("managedatabase", sessioninfo.RightsOrigin) == false)
3660+
{
3661+
ClearXml(record);
3662+
ClearCols(record, LibraryApplication.FILTERED);
3663+
}
3664+
}
3665+
else if (app.PinyinDbName == strDbName
3666+
|| app.GcatDbName == strDbName
3667+
|| app.WordDbName == strDbName)
3668+
{
3669+
if (StringUtil.IsInList("managedatabase", sessioninfo.RightsOrigin) == false)
3670+
{
3671+
ClearXml(record);
3672+
ClearCols(record, LibraryApplication.FILTERED);
3673+
}
3674+
}
3675+
else
3676+
{
3677+
// 实用库包括 publisher / zhongcihao / dictionary / inventory 类型
3678+
string util_type = ServerDatabaseUtility.GetUtilDbType(app.LibraryCfgDom,
3679+
strDbName);
3680+
if (util_type != null)
3681+
{
3682+
if (util_type == "inventory")
3683+
{
3684+
// TODO: 盘点操作的用户具有什么权限?
3685+
if (StringUtil.IsInList("inventory", sessioninfo.RightsOrigin) == false)
3686+
{
3687+
ClearXml(record);
3688+
ClearCols(record, LibraryApplication.FILTERED);
3689+
}
3690+
}
3691+
else if (util_type == "publisher")
3692+
{
3693+
// 公开
3694+
}
3695+
}
3696+
else
3697+
{
3698+
// TODO: 根据具体情况再扩展 if
3699+
ClearXml(record);
3700+
ClearCols(record, LibraryApplication.FILTERED);
3701+
}
3702+
}
3703+
}
3704+
}
3705+
34963706
/*
34973707
* record.Cols 和 record.RecordBody.Xml 需要进行过滤处理
34983708
* 1) (style 中包含 xml)如果 .Xml 被 access 处理(减少字段或者禁止)
@@ -4204,6 +4414,13 @@ public LibraryServerResult GetBrowseRecords(
42044414

42054415
#endif
42064416

4417+
// 2022/11/29
4418+
if (searchresults != null)
4419+
{
4420+
FilterResultSet(searchresults,
4421+
strBrowseInfoStyle);
4422+
}
4423+
#if OLD
42074424
// 对 XML 记录进行过滤或者修改
42084425
if (searchresults != null)
42094426
{
@@ -4291,6 +4508,50 @@ public LibraryServerResult GetBrowseRecords(
42914508
ClearCols(record, LibraryApplication.FILTERED);
42924509
}
42934510
}
4511+
else if (app.ArrivedDbName == strDbName)
4512+
{
4513+
if (StringUtil.IsInList("borrow,return", sessioninfo.RightsOrigin) == true
4514+
|| read_level == "")
4515+
{
4516+
4517+
}
4518+
else
4519+
{
4520+
ClearXml(record);
4521+
ClearCols(record, LibraryApplication.FILTERED);
4522+
}
4523+
}
4524+
else if (app.AmerceDbName == strDbName)
4525+
{
4526+
if (StringUtil.IsInList("getrecord", sessioninfo.RightsOrigin) == false
4527+
|| sessioninfo.UserType == "reader")
4528+
{
4529+
ClearXml(record);
4530+
ClearCols(record, LibraryApplication.FILTERED);
4531+
}
4532+
else
4533+
FilterAmerceRecord(record);
4534+
// 注: GetRecord() API 可以获取违约金记录
4535+
// settlement undosettlement deletesettlement
4536+
}
4537+
else if (app.MessageDbName == strDbName)
4538+
{
4539+
if (StringUtil.IsInList("managedatabase", sessioninfo.RightsOrigin) == false)
4540+
{
4541+
ClearXml(record);
4542+
ClearCols(record, LibraryApplication.FILTERED);
4543+
}
4544+
}
4545+
else if (app.PinyinDbName == strDbName
4546+
|| app.GcatDbName == strDbName
4547+
|| app.WordDbName == strDbName)
4548+
{
4549+
if (StringUtil.IsInList("managedatabase", sessioninfo.RightsOrigin) == false)
4550+
{
4551+
ClearXml(record);
4552+
ClearCols(record, LibraryApplication.FILTERED);
4553+
}
4554+
}
42944555
else
42954556
{
42964557
// TODO: 根据实际需要增补 else if
@@ -4357,8 +4618,10 @@ public LibraryServerResult GetBrowseRecords(
43574618
}
43584619
}
43594620

4360-
// 注: 0 并不表示没有命中。命中数要看 searchresults.Length
4361-
result.Value = lRet;
4621+
#endif
4622+
4623+
// 注: 0 并不表示没有命中。命中数要看 searchresults.Length
4624+
result.Value = lRet;
43624625
result.ErrorInfo = strError;
43634626
return result;
43644627
}

DigitalPlatform.Text/dp2StringUtil.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public static string CanonicalizeDiscount(string strDiscount, string strPosition
277277
return "1.00";
278278
// TODO: 规整小数点后面的位数。两位小数以内,末尾不足的补充 0;多出来的去掉多余的末尾连续 0
279279
if (decimal.TryParse(strDiscount, out decimal discount) == false)
280-
throw new PositionException("折扣值 '' 不合法。应为一个小数", strPosition);
280+
throw new PositionException($"折扣值 '{strDiscount}' 不合法。应为一个小数", strPosition);
281281
return discount.ToString(CurrencyItem.fmt);
282282
}
283283

DigitalPlatform/ListViewUtil.cs

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ namespace DigitalPlatform.GUI
1414
{
1515
public class ListViewUtil
1616
{
17+
// 2022/11/29
18+
public static List<ListViewItem> GetItems(ListView list)
19+
{
20+
return list.TryGet(() =>
21+
{
22+
return list.Items.Cast<ListViewItem>().ToList();
23+
});
24+
}
25+
26+
public static List<ListViewItem> GetSelectedItems(ListView list)
27+
{
28+
return list.TryGet(() =>
29+
{
30+
return list.SelectedItems.Cast<ListViewItem>().ToList();
31+
});
32+
}
33+
1734
public static void BeginSelectItem(Control control, ListViewItem item)
1835
{
1936
control.BeginInvoke(new Action<ListViewItem>(

0 commit comments

Comments
 (0)