Skip to content

Commit

Permalink
整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
renyh committed Oct 13, 2023
1 parent 4251a43 commit 90495ed
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 31 deletions.
76 changes: 58 additions & 18 deletions dp2weixin.service/AreaLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ public int init(string libcfgFile, out string error)

public void SaveLib(LibEntity entity)
{

//dp2WeiXinService.Instance.WriteDebug("41");

// 2021/7/9 先找到这个老实例 ,以免丢信息
LibModel oldLib= this.GetLibCfgByName(entity.id, entity.libName);
LibModel oldLib= this.GetLibCfgByName(entity.id, entity.libName);

//dp2WeiXinService.Instance.WriteDebug("42");
// 先将已经对应的删除
DelLib(entity.id, entity.libName);

//dp2WeiXinService.Instance.WriteDebug("43");

// 先查一下有没有对应的地区
Area area = this.GetArea(entity.area);
Expand All @@ -121,8 +126,10 @@ public void SaveLib(LibEntity entity)
area.name = entity.area;
this._areas.Add(area);
}
//dp2WeiXinService.Instance.WriteDebug("44");

LibModel lib = area.GetLib(entity.id, entity.libName);
//dp2WeiXinService.Instance.WriteDebug("45");
if (lib == null)
{
lib = new LibModel();
Expand Down Expand Up @@ -150,42 +157,72 @@ public void SaveLib(LibEntity entity)
lib.bindFlag = oldLib.bindFlag;
}


//dp2WeiXinService.Instance.WriteDebug("46");
this.Save2Xml();

//dp2WeiXinService.Instance.WriteDebug("47");
}
}

public void Save2Xml()
{
//dp2WeiXinService.Instance.WriteDebug("461");

string xml = "";
foreach (Area area in this._areas)
{
xml += "<area name='" + area.name + "'>";

foreach (LibModel lib in area.libs)
if (area.libs != null)
{
xml += "<lib id='" + lib.libId +"'"
+ " name='" + lib.name + "'"
+ " libraryCode='" + lib.libraryCode + "'"
+ " patronDbName='" + lib.patronDbName + "'"
+ " departments='"+lib.departments+"'"
+ " patronBarcodeTail='"+ lib.patronBarcodeTail+"'" //2020/6/5增加证条码号尾号
+ " noticedll='" + lib.noticedll + "'" //2020/8/24 转发通知到第三方的接口
+ " bindStyle='" + lib.bindStyle+"'" // 2021/7/21 增加单一绑定开关
+ " patronMaskValue='" + lib.patronMaskValue + "'" // 2021/8/3 增加通知中屏幕读者信息
+ " fieldsMap='"+lib.fieldsMap+"'" // 2022/10/13 增加编目配置的字段规则
+ " biblioDbName='" + lib.biblioDbName + "'" //2022/10/13 加


+ " />";
foreach (LibModel lib in area.libs)
{
xml += "<lib id='" + lib.libId + "'"
+ " name='" + lib.name + "'"
+ " libraryCode='" + lib.libraryCode + "'"
+ " patronDbName='" + lib.patronDbName + "'"
+ " departments='" + lib.departments + "'"
+ " patronBarcodeTail='" + lib.patronBarcodeTail + "'" //2020/6/5增加证条码号尾号
+ " noticedll='" + lib.noticedll + "'" //2020/8/24 转发通知到第三方的接口
+ " bindStyle='" + lib.bindStyle + "'" // 2021/7/21 增加单一绑定开关
+ " patronMaskValue='" + lib.patronMaskValue + "'" // 2021/8/3 增加通知中屏幕读者信息
+ " fieldsMap='" + lib.fieldsMap + "'" // 2022/10/13 增加编目配置的字段规则
+ " biblioDbName='" + lib.biblioDbName + "'" //2022/10/13 加


+ " />";
}
}
xml += "</area>";
}
//dp2WeiXinService.Instance.WriteDebug("462");
xml = "<root>" + xml + "</root>";

//dp2WeiXinService.Instance.WriteDebug("463");

XmlDocument dom = new XmlDocument();
dom.LoadXml(xml);
dom.Save(this._libcfgfile);

//dp2WeiXinService.Instance.WriteDebug("464");

//if (this._libcfgfile == null)
//{
// dp2WeiXinService.Instance.WriteDebug("_libcfgfile=null");
//}
//else
// dp2WeiXinService.Instance.WriteDebug("_libcfgfile=["+this._libcfgfile+"]");

try
{
dom.Save(this._libcfgfile);
}
catch(Exception ex)
{
dp2WeiXinService.Instance.WriteDebug("异常:"+ex.Message);
throw ex;
}

// dp2WeiXinService.Instance.WriteDebug("465");
}

public Area GetArea(string name)
Expand All @@ -203,6 +240,9 @@ public void DelLib(string id, string name)
{
List<Area> delAreas = new List<Area>();

if (this._areas==null || this._areas.Count==0)
return;

foreach (Area area in this._areas)
{
List<LibModel> delLibs = new List<LibModel>();
Expand Down
46 changes: 33 additions & 13 deletions dp2weixinP2P/ApiControllers/LibrarySettingApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,45 @@ public LibSetResult CreateLib(string userName, string password, LibEntity item)
public ApiResult ChangeLib(string userName, string password,string libId, LibEntity item)
{
ApiResult result = new ApiResult();
long ret = 0;

// 检查是否已登录 2022/9/6
bool bLogin = this.CheckIsLogin(userName, password, out string error);
if (bLogin == false)
try
{
result.errorInfo = error;
result.errorCode = -1;
return result;
}

long ret = LibDatabase.Current.Update(libId, item);
//dp2WeiXinService.Instance.WriteDebug("1");

if (ret > 0)
{
// 更新内存 2016-9-13 jane
dp2WeiXinService.Instance.LibManager.UpdateLib(libId);
// 检查是否已登录 2022/9/6
bool bLogin = this.CheckIsLogin(userName, password, out string error);
if (bLogin == false)
{
result.errorInfo = error;
result.errorCode = -1;
return result;
}

//dp2WeiXinService.Instance.WriteDebug("2");

ret = LibDatabase.Current.Update(libId, item);

if (ret > 0)
{
// 更新内存 2016-9-13 jane
dp2WeiXinService.Instance.LibManager.UpdateLib(libId);
}

//dp2WeiXinService.Instance.WriteDebug("3");


dp2WeiXinService.Instance._areaMgr.SaveLib(item);

//dp2WeiXinService.Instance.WriteDebug("4");
}
catch (Exception ex)
{

dp2WeiXinService.Instance._areaMgr.SaveLib(item);
result.errorCode = -1;
result.errorInfo = "ChangeLib()出错:" + ex.Message;
}

result.errorCode = ret;
return result;
Expand Down

0 comments on commit 90495ed

Please sign in to comment.