Skip to content

Commit

Permalink
整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
renyh committed Oct 14, 2022
1 parent ac99a01 commit 358c884
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 35 deletions.
72 changes: 43 additions & 29 deletions dp2weixin.service/dp2WeiXinService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8613,6 +8613,13 @@ public class Record
}

// 编辑书目
// loginUserName:使用的dp2library帐号,一般为馆员帐户
// loginUserType:空表示馆员,如果是读者传"patron"
// weixinId:前端用户唯一id
// libId:图书馆id
// biblioFields:书目对象,是一个结构,里面有路径、要编辑的字段。
// outputBiblioPath:返回的书目路径
// outputTimestamp:返回的书目时间戳
public int SetBiblio(string loginUserName,
string loginUserType,
string weixinId,
Expand All @@ -8622,23 +8629,20 @@ public int SetBiblio(string loginUserName,
out string outputTimestamp,
out string strError)
{
// 检查传入的参数
//strError = "loginUserName=" + loginUserName + ";"
// + "loginUserType=" + loginUserType + ";"
// + "weixinId=" + weixinId + ";"
// + "libId=" + libId + "\r\n"
// + JsonConvert.SerializeObject(biblio);


// 调点对点接口处理
strError = "";
int nRet = 0;
outputBiblioPath = "";
outputTimestamp = "";


// todo,未用type
LoginInfo loginInfo = new LoginInfo(loginUserName, false);


// 调dp2接口时,使用的dp2帐户
LoginInfo loginInfo = GetLoginInfo(loginUserName, loginUserType);// new LoginInfo(loginUserName, false);

// 根据id找到图书馆对象
LibEntity lib = this.GetLibById(libId);
Expand All @@ -8648,18 +8652,19 @@ public int SetBiblio(string loginUserName,
return -1;
}

int nRet = 0;

string biblioXml = "";
string biblioXml = ""; //书目xml
if (biblio.Action == C_Action_new)
{
// todo 新增需要改变
// marc工作单格式 todo 新增需要什么的初始化
string strMarc = @"?????nam0 22????? 45__
100 ǂa20071012d2007 ekmy0chiy1050 ea
1010 ǂachi
102 ǂaCNǂb110000";

// 工作单到MarcRecord对象,方便用MarcQuery处理。
MarcRecord temp = MarcRecord.FromWorksheet(strMarc);

MarcRecord temp = MarcRecord.FromWorksheet(strMarc); //new MarcRecord(strMarc);
// 给marc中设置字段
MarcRecord record= MarcHelper.SetFields(temp, biblio.Fields);
nRet = MarcUtil.Marc2Xml(record.Text,
"unimarc",
Expand All @@ -8668,25 +8673,28 @@ 1010 ǂachi
if (nRet == -1)
return -1;
}
else if (biblio.Action == C_Action_change)
else if (biblio.Action == C_Action_change) //修改
{
// 调接口,把数据取出来,和时间戳
// 先调接口把书目数据取出来
List<string> dataList = null;
nRet = this.GetBiblioInfo(lib,
loginInfo,
biblio.BiblioPath,
"xml,timestamp",
"xml,timestamp", //xml和时间戳
out dataList,
out strError);
if (nRet == -1 || nRet == 0)
return nRet;

string oldbiblioXml = dataList[0];
// todo 使用前端传过来的

// 使用前端传过来的
//biblio.Timestamp = dataList[1];

// xml转成MarcRecord对象
MarcRecord temp =MarcHelper.MarcXml2MarcRecord(oldbiblioXml, out string outMarcSyntax, out strError);

// 根据接口传入的字段组合字符串设置marc对应的字段
MarcRecord record = MarcHelper.SetFields(temp, biblio.Fields);
nRet = MarcUtil.Marc2Xml(record.Text,
"unimarc",
Expand All @@ -8701,6 +8709,7 @@ 1010 ǂachi
}
else
{
// 目前仅支持new,change,delete。先不支持其它动作
strError = "SetBiblio()接口不能识别的action[" + biblio.Action + "]";
return -1;
}
Expand All @@ -8717,7 +8726,6 @@ public class Entity
public string ErrorInfo { get; set; }
public string ErrorCode { get; set; }
}

public class Record
{
public string RecPath { get; set; }
Expand All @@ -8726,30 +8734,36 @@ public class Record
public string Timestamp { get; set; }
}
*/
Record newRecord = new Record();
newRecord.RecPath = biblio.BiblioPath;
newRecord.Format = "xml";
newRecord.Data = biblioXml;

//实体集合
List<Entity> entities = new List<Entity>();

// 本接口目前仅支持处理一条记录
Entity entity = new Entity();
entity.Action = biblio.Action;

//新记录
Record newRecord = new Record();
newRecord.RecPath = biblio.BiblioPath;
newRecord.Format = "xml";
newRecord.Data = biblioXml;
entity.NewRecord = newRecord;

List<Entity> entities = new List<Entity>();
//加到集合里
entities.Add(entity);

// 删除
// 编辑和删除时,需要设置旧记录,包括旧记录的路径和时间戳
if (biblio.Action == "change" || biblio.Action == "delete")
{
Record oldRecord = new Record();
oldRecord.RecPath = biblio.BiblioPath;
oldRecord.Timestamp = biblio.Timestamp;

// 给entity设置上旧记录
entity.OldRecord = oldRecord;
}

//string outputXml = "";

// 调点对点接口
// 调点对点接口,对应dp2的setBiblioInfo接口
CancellationToken cancel_token = new CancellationToken();
string id = Guid.NewGuid().ToString();
SetInfoRequest request = new SetInfoRequest(id,
Expand All @@ -8759,10 +8773,11 @@ public class Record
entities);
try
{
// 连接
MessageConnection connection = this._channels.GetConnectionTaskAsync(
this._dp2MServerUrl,
"").Result;

//发起请求
SetInfoResult result = connection.SetInfoTaskAsync(
lib.capoUserName,
request,
Expand All @@ -8788,7 +8803,6 @@ public class Record
}

return (int)result.Value;

}
catch (AggregateException ex)
{
Expand All @@ -8800,7 +8814,7 @@ public class Record
strError = ex.Message;
return -1;
}

//结束
}

//
Expand Down
10 changes: 5 additions & 5 deletions dp2weixinP2P/ApiControllers/BiblioApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,11 @@ public ApiResult SetItem(string loginUserName,


// 编辑书目
//loginUserName:使用的dp2library帐号,即前端当前绑定的帐户,如果是读者则传读者证条码;如果是馆员帐户,传馆员用户名
//loginUserType:空表示馆员,如果是读者传"patron"
//weixinId:前端用户唯一id
//libId:图书馆id
//biblioFields:书目对象,是一个结构,里面有路径、要编辑的字段。
// loginUserName:使用的dp2library帐号,一般为馆员帐户
// loginUserType:空表示馆员,如果是读者传"patron"
// weixinId:前端用户唯一id
// libId:图书馆id
// biblioFields:书目对象,是一个结构,里面有路径、要编辑的字段。
public SetBiblioResult SetBiblio(string loginUserName,
string loginUserType,
string weixinId,
Expand Down
2 changes: 1 addition & 1 deletion dp2weixinP2P/Controllers/BiblioController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public ActionResult BiblioEdit(string code, string state, string biblioPath)
html += @"<div class='mui-content-padded'>"
+ "<button id='btnOpeType' class='mui-btn mui-btn-block mui-btn-primary' onclick='saveBiblio()'>" + btnName + "</button>"
+ "<div class='link-area'><center>"
+ "&nbsp;&nbsp;<a id='again' "+style+" href='JavaScript:void(0)' onclick='gotoUrl(\"" + biblioEditUrl+"\")'>再次新增书目</a>"
+ "<a id='again' "+style+" href='JavaScript:void(0)' onclick='gotoUrl(\"" + biblioEditUrl+"\")'>新增书目</a>"
+ "&nbsp;&nbsp;<a id='detail' "+style+" href='JavaScript:void(0)' onclick='gotoUrl(\"" + detailUrl + "\")'>查看书目详情</a>"
+ "&nbsp;&nbsp;<a href='JavaScript:void(0)' onclick='gotoUrl(\"" + biblioSearchUrl + "\")'>返回书目查询</a>"

Expand Down

0 comments on commit 358c884

Please sign in to comment.