コード例 #1
0
ファイル: AppReservation.cs プロジェクト: renyh1013/dp2
        // TODO: 各个环节要改为尽量使用 refID。要做大量测试
        // text-level: 内部处理
        // 在 预约到书 库中,追加一条新的记录,并作 email / dpmail / mq 通知
        // 注:本函数可能要删除部分通知记录
        // parameters:
        //      strItemBarcode  册条码号。必须是册条码号。如果册条码号为空,参考ID需要使用 strRefID 参数
        //      strRefID        参考ID
        //      bOnShelf    要通知的册是否在架。在架指并没有人借阅过,本来就在书架上。
        //      strLibraryCode  读者所在的馆代码
        //      strReaderXml    预约了图书的读者的XML记录。用于消息通知接口
        int AddNotifyRecordToQueueDatabase(
            // RmsChannelCollection channels,
            RmsChannel channel,
            string strItemBarcodeParam,
            string strRefIDParam,
            string strItemXml,
            bool bOnShelf,
            string strLibraryCode,
            string strReaderBarcode,
            string strReaderXml,
            out List<string> DeletedNotifyRecPaths,
            out string strError)
        {
            strError = "";
            DeletedNotifyRecPaths = new List<string>();

            // 2010/12/31
            if (String.IsNullOrEmpty(this.ArrivedDbName) == true)
            {
                strError = "预约到书库尚未定义, AddNotifyRecordToQueue()调用失败";
                return -1;
            }

            // 准备写记录
            byte[] timestamp = null;
            byte[] output_timestamp = null;
            string strOutputPath = "";
            int nRet = 0;
            long lRet = 0;

            if (String.IsNullOrEmpty(strItemBarcodeParam) == true)
            {
                // 如果检索用的册条码号为空,加上对命中结果数量不设限,那就会造成系统严重繁忙。
                strError = "参数strItemBarcode中的册条码号不能为空。";
                return -1;
            }

#if NO
            RmsChannel channel = channels.GetChannel(this.WsUrl);
            if (channel == null)
            {
                strError = "get channel error";
                return -1;
            }
#endif

        REDODELETE:
            // 如果队列中已经存在同册条码号的记录, 要先删除
            string strNotifyXml = "";
            // 获得预约到书队列记录
            // return:
            //      -1  error
            //      0   not found
            //      1   命中1条
            //      >1  命中多于1条
            nRet = GetArrivedQueueRecXml(
                // channels,
                channel,
                strItemBarcodeParam,
                out strNotifyXml,
                out timestamp,
                out strOutputPath,
                out strError);
            if (nRet == -1)
            {
                // 写入错误日志?
                this.WriteErrorLog("在还书操作中,检索册条码号为 " + strItemBarcodeParam + " 的预约到书库记录时出错: " + strError);
            }
            if (nRet >= 1)
            {
                int nRedoDeleteCount = 0;
            // TODO: 这一段删除代码可以专门编制在一个函数中,不必这么费力循环。可以优化处理
            REDO_DELETE:
                lRet = channel.DoDeleteRes(strOutputPath,
                    timestamp,
                    out output_timestamp,
                    out strError);
                if (lRet == -1)
                {
                    // 时间戳不匹配
                    if (channel.ErrorCode == ChannelErrorCode.TimestampMismatch
                        && nRedoDeleteCount < 10)
                    {
                        nRedoDeleteCount++;
                        timestamp = output_timestamp;
                        goto REDO_DELETE;
                    }

                    // 写入错误日志?
                    this.WriteErrorLog("在还书操作中,加入新预约到书记录前, 删除已存在的预约到书库记录 '" + strOutputPath + "' 出错: " + strError);
                }

                DeletedNotifyRecPaths.Add(strOutputPath);    // 记忆已经被删除的记录路径 2007/7/5 

                goto REDODELETE;    // 如果有多条,循环删除
            }

            XmlDocument itemdom = null;
            nRet = LibraryApplication.LoadToDom(strItemXml,
                out itemdom,
                out strError);
            if (nRet == -1)
            {
                strError = "装载册记录 '" + strItemBarcodeParam + "' 的 XML 进入 DOM 时发生错误: " + strError;
                return -1;
            }

            string strLocation = DomUtil.GetElementText(itemdom.DocumentElement, "location");
            strLocation = StringUtil.GetPureLocationString(strLocation);

            string strAccessNo = DomUtil.GetElementText(itemdom.DocumentElement, "accessNo");

            /*
  <reservations>
        <request reader="R0000001" requestDate="Mon, 05 Sep 2016 16:57:47 +0800" operator="R0000001" /> 
  </reservations>
             * */
            // 从册记录 reservations 元素下找第一个 request 元素,其 requestDate 属性
            string strRequestDate = "";
            XmlElement request = itemdom.DocumentElement.SelectSingleNode("reservations/request") as XmlElement;
            if (request != null)
                strRequestDate = request.GetAttribute("requestDate");

            // 创建预约到书记录
            XmlDocument new_queue_dom = new XmlDocument();
            new_queue_dom.LoadXml("<root />");

            // TODO: 以后增加 <refID> 元素,存储册记录的参考ID

#if NO
            XmlNode nodeItemBarcode = DomUtil.SetElementText(dom.DocumentElement, "itemBarcode", strItemBarcode);

            // 在<itemBarcode>元素中增加一个onShelf属性,表示属于在架情况
            Debug.Assert(nodeItemBarcode != null, "");
            if (bOnShelf == true)
                DomUtil.SetAttr(nodeItemBarcode, "onShelf", "true");
#endif
            string strItemRefID = "";   // 计划存储纯粹的 refid
            string strItemBarcode = strItemBarcodeParam;    // 计划存储纯粹的册条码号

            // 兼容 strItemBarcode 中含有前缀的用法
            string strHead = "@refID:";
            if (StringUtil.HasHead(strItemBarcodeParam, strHead, true) == true)
            {
                strItemRefID = strItemBarcodeParam.Substring(strHead.Length);
                strItemBarcode = "";
            }

            string strUnionItemBarcode = GetUnionBarcode(strItemBarcode, strItemRefID);

            if (this.ArrivedDbKeysContainsRefIDKey() == true)
            {
                DomUtil.SetElementText(new_queue_dom.DocumentElement, "itemBarcode", strItemBarcode);
                DomUtil.SetElementText(new_queue_dom.DocumentElement, "refID", strItemRefID);
            }
            else
            {
                if (string.IsNullOrEmpty(strItemBarcode) == true)
                {
                    if (string.IsNullOrEmpty(strItemRefID) == true)
                    {
                        strError = "AddNotifyRecordToQueue() 函数当 strItemBarcode 参数为空的时候,必须让 strRefID 参数不为空";
                        return -1;
                    }

                    Debug.Assert(string.IsNullOrEmpty(strItemRefID) == false, "");
                    // 旧的用法。避免检索时候查不到
                    DomUtil.SetElementText(new_queue_dom.DocumentElement, "itemBarcode", "@refID:" + strItemRefID);
                }
                else
                    DomUtil.SetElementText(new_queue_dom.DocumentElement, "itemBarcode", strItemBarcode); // 2015/5/20 添加,修正 BUG
            }

            // 改为存储在元素中 2015/5/7
            if (bOnShelf == true)
                DomUtil.SetElementText(new_queue_dom.DocumentElement, "onShelf", "true");

            // 2012/10/26
            DomUtil.SetElementText(new_queue_dom.DocumentElement, "libraryCode", strLibraryCode);

            DomUtil.SetElementText(new_queue_dom.DocumentElement, "readerBarcode", strReaderBarcode);
            DomUtil.SetElementText(new_queue_dom.DocumentElement, "notifyDate", this.Clock.GetClock());

            // 2015/6/13
            DomUtil.SetElementText(new_queue_dom.DocumentElement, "location", strLocation);

            string strPath = this.ArrivedDbName + "/?";

            // 写新记录
            lRet = channel.DoSaveTextRes(
                strPath,
                new_queue_dom.OuterXml,
                false,
                "content,ignorechecktimestamp",
                timestamp,
                out output_timestamp,
                out strOutputPath,
                out strError);
            if (lRet == -1)
            {
                // 写入错误日志 2007/1/3 
                this.WriteErrorLog("创建新的预约到书队列记录时出错: " + strError);
                return -1;
            }

            string strReaderEmailAddress = "";
            string strName = "";
            nRet = GetReaderNotifyInfo(
                strReaderXml,
                out strName,
                out strReaderEmailAddress,
                out strError);
            if (nRet == -1)
                return -1;

            // 获得图书摘要信息
            string strSummary = "";     // 没有被截断的摘要字符串
            string strShortSummary = "";    // 截断后的摘要字符串
            string strBiblioRecPath = "";

            nRet = this.GetBiblioSummary(strUnionItemBarcode,
                "", //  strConfirmItemRecPath,
                null,   //  strBiblioRecPathExclude,
                -1, // 25,
                out strBiblioRecPath,
                out strSummary,
                out strError);
            if (nRet == -1)
            {
                strSummary = "ERROR: " + strError;
            }
            else
            {
                strShortSummary = LibraryApplication.CutSummary(strSummary, 25);
            }

#if NO
            // 临时的SessionInfo对象
            SessionInfo sessioninfo = new SessionInfo(this);
            // 模拟一个账户
            Account account = new Account();
            account.LoginName = "CacheBuilder";
            account.Password = "";
            account.Rights = "getbibliosummary";

            account.Type = "";
            account.Barcode = "";
            account.Name = "AddNotifyRecordToQueue";
            account.UserID = "AddNotifyRecordToQueue";
            account.RmsUserName = this.ManagerUserName;
            account.RmsPassword = this.ManagerPassword;

            sessioninfo.Account = account;
            try
            {

                string strBiblioRecPath = "";
                LibraryServerResult result = this.GetBiblioSummary(
                    sessioninfo,
                    strItemBarcode,
                    "", // strConfirmItemRecPath,
                    null,
                    out strBiblioRecPath,
                    out strSummary);
                if (result.Value == -1)
                {
                    strSummary = "ERROR: " + result.ErrorInfo;
                }
                else
                {
                    // 截断
                    if (strSummary.Length > 25)
                        strSummary = strSummary.Substring(0, 25) + "...";
                }
            }
            finally
            {
                sessioninfo.Close();
                sessioninfo = null;
            }
#endif

            // 发送短消息通知
            string strTotalError = "";

            // *** dpmail
            if (this.MessageCenter != null
                && StringUtil.IsInList("dpmail", this.ArrivedNotifyTypes))
            {
                string strTemplate = "";
                // 获得邮件模板
                nRet = GetMailTemplate(
                    "dpmail",
                    bOnShelf == false ? "预约到书通知" : "预约到书通知(在架)",
                    out strTemplate,
                    out strError);
                if (nRet == -1)
                    return -1;
                if (nRet == 0)
                {
                    strError = "预约到书通知<mailTemplate/template>尚未配置。";
                    return -1;
                }

                /*
                %item%  册信息
                %reservetime%   保留期限
                %today% 发出email的当天
                %summary% 书目摘要
                %itembarcode% 册条码号 
                %name% 读者姓名
                 * */
                Hashtable table = new Hashtable();
                table["%item%"] = "(册条码号为: " + strUnionItemBarcode + " URL为: " + this.OpacServerUrl + "/book.aspx?barcode=" + strUnionItemBarcode + " )";
                table["%reservetime%"] = this.GetDisplayTimePeriodStringEx(this.ArrivedReserveTimeSpan);
                table["%today%"] = DateTime.Now.ToString();
                table["%summary%"] = strShortSummary;
                table["%itembarcode%"] = strUnionItemBarcode;
                table["%name%"] = strName;
                string strBody = "";

                nRet = GetMailText(strTemplate,
                    table,
                    out strBody,
                    out strError);
                if (nRet == -1)
                    return -1;

                if (String.IsNullOrEmpty(this.MessageCenter.MessageDbName) == false)
                {
                    Debug.Assert(channel.Container != null, "");
                    // 发送消息
                    nRet = this.MessageCenter.SendMessage(
                        channel.Container,  // channels,
                        strReaderBarcode,
                        "图书馆",
                        "预约到书通知",
                        "text",
                        strBody,
                        false,
                        out strError);
                    if (nRet == -1)
                    {
                        strTotalError += "发送dpmail消息时出错: " + strError + "\r\n";
                    }
                }
            }

            // 2016/4/26
            // *** mq
            if (string.IsNullOrEmpty(this.OutgoingQueue) == false
                && StringUtil.IsInList("mq", this.ArrivedNotifyTypes))
            {
                XmlDocument dom = new XmlDocument();
                dom.LoadXml("<root />");

                /* 元素名
                 * type 消息类型。预约到书通知
                 * itemBarcode 册条码号
                 * location 馆藏地 2016/9/5
                 * refID    册的参考 ID
                 * onShelf 是否在架。true/false
                 * opacURL  图书在 OPAC 中的 URL。相对路径
                 * requestDate 预约请求创建时间 2016/9/5
                 * reserveTime 保留的时间
                 * today 今天的日期
                 * summary 书目摘要
                 * patronName   读者姓名
                 * patronRecord 读者 XML 记录
 * */
                DomUtil.SetElementText(dom.DocumentElement, "type", "预约到书通知");

                DomUtil.SetElementText(dom.DocumentElement,
                    "itemBarcode", strItemBarcode);
                DomUtil.SetElementText(dom.DocumentElement,
                    "location", strLocation);
                // 2016/11/15
                DomUtil.SetElementText(dom.DocumentElement,
                    "accessNo", strAccessNo);

                // 2016/9/5
                if (string.IsNullOrEmpty(strItemRefID))
                    strItemRefID = DomUtil.GetElementText(itemdom.DocumentElement, "refID");

                DomUtil.SetElementText(dom.DocumentElement,
                    "refID", strItemRefID);
                DomUtil.SetElementText(dom.DocumentElement,
                    "onShelf", bOnShelf ? "true" : "false");

                DomUtil.SetElementText(dom.DocumentElement,
                    "opacURL", this.OpacServerUrl + "/book.aspx?barcode="
                    + strUnionItemBarcode);
                DomUtil.SetElementText(dom.DocumentElement,
                    "requestDate", strRequestDate);
                DomUtil.SetElementText(dom.DocumentElement,
                    "reserveTime", this.GetDisplayTimePeriodStringEx(this.ArrivedReserveTimeSpan));
                DomUtil.SetElementText(dom.DocumentElement,
                    "today", DateTime.Now.ToString());
                DomUtil.SetElementText(dom.DocumentElement,
                    "summary", strSummary);
                DomUtil.SetElementText(dom.DocumentElement,
                    "patronName", strName);

                string strReaderRefID = "";
                {
                    XmlDocument readerdom = new XmlDocument();
                    readerdom.LoadXml(strReaderXml);

                    strReaderRefID = DomUtil.GetElementText(readerdom.DocumentElement, "refID");

                    XmlElement record = dom.CreateElement("patronRecord");
                    dom.DocumentElement.AppendChild(record);
                    record.InnerXml = readerdom.DocumentElement.InnerXml;

                    DomUtil.DeleteElement(record, "borrowHistory");
                    DomUtil.DeleteElement(record, "password");
                    DomUtil.DeleteElement(record, "fingerprint");
                    DomUtil.SetElementText(record, "libraryCode", strLibraryCode);
                }

                try
                {
                    MessageQueue queue = new MessageQueue(this.OutgoingQueue);

                    // 向 MSMQ 消息队列发送消息
                    nRet = ReadersMonitor.SendToQueue(queue,
                        (string.IsNullOrEmpty(strReaderRefID) ? strReaderBarcode : "!refID:" + strReaderRefID)
                        + "@LUID:" + this.UID,
                        "xml",
                        dom.DocumentElement.OuterXml,
                        out strError);
                    if (nRet == -1)
                    {
                        strTotalError += "发送 MQ 消息时出错: " + strError + "\r\n";
                    }
                }
                catch (Exception ex)
                {
                    strTotalError += "创建路径为 '" + this.OutgoingQueue + "' 的 MessageQueue 对象失败: " + ExceptionUtil.GetDebugText(ex);
                }
            }

            // ** email
            if (String.IsNullOrEmpty(strReaderEmailAddress) == false
                && StringUtil.IsInList("email", this.ArrivedNotifyTypes))
            {
                string strTemplate = "";
                // 获得邮件模板
                nRet = GetMailTemplate(
                    "email",
                    bOnShelf == false ? "预约到书通知" : "预约到书通知(在架)",
                    out strTemplate,
                    out strError);
                if (nRet == -1)
                    return -1;
                if (nRet == 0)
                {
                    strError = "预约到书通知<mailTemplate/template>尚未配置。";
                    return -1;
                }

                /*
                %item%  册信息
                %reservetime%   保留期限
                %today% 发出email的当天
                %summary% 书目摘要
                %itembarcode% 册条码号 
                %name% 读者姓名
                 * */
                Hashtable table = new Hashtable();
                table["%item%"] = "(册条码号为: " + strUnionItemBarcode + " URL为: " + this.OpacServerUrl + "/book.aspx?barcode=" + strUnionItemBarcode + " )";
                table["%reservetime%"] = this.GetDisplayTimePeriodStringEx(this.ArrivedReserveTimeSpan);
                table["%today%"] = DateTime.Now.ToString();
                table["%summary%"] = strShortSummary;
                table["%itembarcode%"] = strUnionItemBarcode;
                table["%name%"] = strName;

                string strBody = "";

                nRet = GetMailText(strTemplate,
                    table,
                    out strBody,
                    out strError);
                if (nRet == -1)
                    return -1;

                {
                    // 发送email
                    // return:
                    //      -1  error
                    //      0   not found smtp server cfg
                    //      1   succeed
                    nRet = SendEmail(strReaderEmailAddress,
                        "预约到书通知",
                        strBody,
                        "text",
                        out strError);
                    if (nRet == -1)
                    {
                        strTotalError += "发送email消息时出错: " + strError + "\r\n";
                    }
                }
            }

            // *** external messageinterfaces
            if (this.m_externalMessageInterfaces != null)
            {
                foreach (MessageInterface message_interface in this.m_externalMessageInterfaces)
                {
                    // types
                    if (StringUtil.IsInList(message_interface.Type, this.ArrivedNotifyTypes) == false)
                        continue;

                    string strTemplate = "";
                    // 获得邮件模板
                    nRet = GetMailTemplate(
                        message_interface.Type,
                        bOnShelf == false ? "预约到书通知" : "预约到书通知(在架)",
                        out strTemplate,
                        out strError);
                    if (nRet == -1)
                        return -1;
                    if (nRet == 0)
                    {
                        strError = "预约到书通知<mailTemplate/template>尚未配置。";
                        return -1;
                    }

                    /*
                    %item%  册信息
                    %reservetime%   保留期限
                    %today% 发出email的当天
                %summary% 书目摘要
                %itembarcode% 册条码号 
                %name% 读者姓名
                     * */
                    Hashtable table = new Hashtable();
                    table["%item%"] = "(册条码号为: " + strUnionItemBarcode + " URL为: " + this.OpacServerUrl + "/book.aspx?barcode=" + strUnionItemBarcode + " )";
                    table["%reservetime%"] = this.GetDisplayTimePeriodStringEx(this.ArrivedReserveTimeSpan);
                    table["%today%"] = DateTime.Now.ToString();
                    table["%summary%"] = strShortSummary;
                    table["%itembarcode%"] = strUnionItemBarcode;
                    table["%name%"] = strName;

                    string strBody = "";

                    nRet = GetMailText(strTemplate,
                        table,
                        out strBody,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    // 发送消息
                    nRet = message_interface.HostObj.SendMessage(
                        strReaderBarcode,
                        strReaderXml,
                        strBody,
                        strLibraryCode,
                        out strError);
                    if (nRet == -1)
                    {
                        strTotalError += "发送" + message_interface.Type + "消息时出错: " + strError + "\r\n";
                    }
                }
            }

            if (String.IsNullOrEmpty(strTotalError) == false)
            {
                strError = strTotalError;
                return -1;
            }

            return 0;
        }
コード例 #2
0
ファイル: AppReservation.cs プロジェクト: paopaofeng/dp2
        // text-level: 内部处理
        // 在 预约到书 库中,追加一条新的记录
        // 并作email通知
        // 注:本函数可能要删除部分通知记录
        // parameters:
        //      strItemBarcode  册条码号。必须是册条码号。如果册条码号为空,参考ID需要使用 strRefID 参数
        //      strRefID        参考ID
        //      bOnShelf    要通知的册是否在架。在架指并没有人借阅过,本来就在书架上。
        //      strLibraryCode  读者所在的馆代码
        //      strReaderXml    预约了图书的读者的XML记录。用于消息通知接口
        int AddNotifyRecordToQueue(
            // RmsChannelCollection channels,
            RmsChannel channel,
            string strItemBarcode,
            string strRefID,
            string strItemXml,
            bool bOnShelf,
            string strLibraryCode,
            string strReaderBarcode,
            string strReaderXml,
            out List<string> DeletedNotifyRecPaths,
            out string strError)
        {
            strError = "";
            DeletedNotifyRecPaths = new List<string>();
            
            // 2010/12/31
            if (String.IsNullOrEmpty(this.ArrivedDbName) == true)
            {
                strError = "预约到书库尚未定义, AddNotifyRecordToQueue()调用失败";
                return -1;
            }

            // 准备写记录
            byte[] timestamp = null;
            byte[] output_timestamp = null;
            string strOutputPath = "";
            int nRet = 0;
            long lRet = 0;

            if (String.IsNullOrEmpty(strItemBarcode) == true)
            {
                // 如果检索用的册条码号为空,加上对命中结果数量不设限,那就会造成系统严重繁忙。
                strError = "参数strItemBarcode中的册条码号不能为空。";
                return -1;
            }

#if NO
            RmsChannel channel = channels.GetChannel(this.WsUrl);
            if (channel == null)
            {
                strError = "get channel error";
                return -1;
            }
#endif

        REDODELETE:
            // 如果队列中已经存在同册条码号的记录, 要先删除
            string strNotifyXml = "";
            // 获得预约到书队列记录
            // return:
            //      -1  error
            //      0   not found
            //      1   命中1条
            //      >1  命中多于1条
            nRet = GetArrivedQueueRecXml(
                // channels,
                channel,
                strItemBarcode,
                out strNotifyXml,
                out timestamp,
                out strOutputPath,
                out strError);
            if (nRet == -1)
            {
                // 写入错误日志?
                this.WriteErrorLog("在还书操作中,检索册条码号为 " + strItemBarcode + " 的预约到书库记录时出错: " + strError);
            }
            if (nRet >= 1)
            {
                int nRedoDeleteCount = 0;
            // TODO: 这一段删除代码可以专门编制在一个函数中,不必这么费力循环。可以优化处理
            REDO_DELETE:
                lRet = channel.DoDeleteRes(strOutputPath,
                    timestamp,
                    out output_timestamp,
                    out strError);
                if (lRet == -1)
                {
                    // 时间戳不匹配
                    if (channel.ErrorCode == ChannelErrorCode.TimestampMismatch
                        && nRedoDeleteCount < 10)
                    {
                        nRedoDeleteCount++;
                        timestamp = output_timestamp;
                        goto REDO_DELETE;
                    }

                    // 写入错误日志?
                    this.WriteErrorLog("在还书操作中,加入新预约到书记录前, 删除已存在的预约到书库记录 '" + strOutputPath + "' 出错: " + strError);
                }

                DeletedNotifyRecPaths.Add(strOutputPath);    // 记忆已经被删除的记录路径 2007/7/5 

                goto REDODELETE;    // 如果有多条,循环删除
            }

            XmlDocument itemdom = null;
            nRet = LibraryApplication.LoadToDom(strItemXml,
                out itemdom,
                out strError);
            if (nRet == -1)
            {
                strError = "装载册记录 '"+strItemBarcode+"' 的 XML 进入 DOM 时发生错误: " + strError;
                return -1;
            }

            string strLocation = DomUtil.GetElementText(itemdom.DocumentElement, "location");
            strLocation = StringUtil.GetPureLocationString(strLocation);

            // 创建预约到书记录
            XmlDocument new_queue_dom = new XmlDocument();
            new_queue_dom.LoadXml("<root />");

            // TODO: 以后增加 <refID> 元素,存储册记录的参考ID

#if NO
            XmlNode nodeItemBarcode = DomUtil.SetElementText(dom.DocumentElement, "itemBarcode", strItemBarcode);

            // 在<itemBarcode>元素中增加一个onShelf属性,表示属于在架情况
            Debug.Assert(nodeItemBarcode != null, "");
            if (bOnShelf == true)
                DomUtil.SetAttr(nodeItemBarcode, "onShelf", "true");
#endif
            // 兼容 strItemBarcode 中含有前缀的用法
            string strHead = "@refID:";
            if (StringUtil.HasHead(strItemBarcode, strHead, true) == true)
            {
                strRefID = strItemBarcode.Substring(strHead.Length);
                strItemBarcode = "";
            }

            if (this.ArrivedDbKeysContainsRefIDKey() == true)
            {
                DomUtil.SetElementText(new_queue_dom.DocumentElement, "itemBarcode", strItemBarcode);
                DomUtil.SetElementText(new_queue_dom.DocumentElement, "refID", strRefID);
            }
            else
            {
                if (string.IsNullOrEmpty(strItemBarcode) == true)
                {
                    if (string.IsNullOrEmpty(strRefID) == true)
                    {
                        strError = "AddNotifyRecordToQueue() 函数当 strItemBarcode 参数为空的时候,必须让 strRefID 参数不为空";
                        return -1;
                    }

                    Debug.Assert(string.IsNullOrEmpty(strRefID) == false, "");
                    // 旧的用法。避免检索时候查不到
                    DomUtil.SetElementText(new_queue_dom.DocumentElement, "itemBarcode", "@refID:" + strRefID);
                }
                else
                    DomUtil.SetElementText(new_queue_dom.DocumentElement, "itemBarcode", strItemBarcode); // 2015/5/20 添加,修正 BUG
            }

            // 改为存储在元素中 2015/5/7
            if (bOnShelf == true)
                DomUtil.SetElementText(new_queue_dom.DocumentElement, "onShelf", "true");

            // 2012/10/26
            DomUtil.SetElementText(new_queue_dom.DocumentElement, "libraryCode", strLibraryCode);

            DomUtil.SetElementText(new_queue_dom.DocumentElement, "readerBarcode", strReaderBarcode);
            DomUtil.SetElementText(new_queue_dom.DocumentElement, "notifyDate", this.Clock.GetClock());

            // 2015/6/13
            DomUtil.SetElementText(new_queue_dom.DocumentElement, "location", strLocation);

            string strPath = this.ArrivedDbName + "/?";

            // 写新记录
            lRet = channel.DoSaveTextRes(
                strPath,
                new_queue_dom.OuterXml,
                false,
                "content,ignorechecktimestamp",
                timestamp,
                out output_timestamp,
                out strOutputPath,
                out strError);
            if (lRet == -1)
            {
                // 写入错误日志 2007/1/3 
                this.WriteErrorLog("创建新的预约到书队列记录时出错: " + strError);
                return -1;
            }

            string strReaderEmailAddress = "";
            string strName = "";
            nRet = GetReaderNotifyInfo(
                strReaderXml,
                out strName,
                out strReaderEmailAddress,
                out strError);
            if (nRet == -1)
                return -1;

            // 获得图书摘要信息
            string strSummary = "";
            string strBiblioRecPath = "";

            nRet = this.GetBiblioSummary(strItemBarcode,
                "", //  strConfirmItemRecPath,
                null,   //  strBiblioRecPathExclude,
                25,
                out strBiblioRecPath,
                out strSummary,
                out strError);
            if (nRet == -1)
            {
                strSummary = "ERROR: " + strError;
            }
#if NO
            // 临时的SessionInfo对象
            SessionInfo sessioninfo = new SessionInfo(this);
            // 模拟一个账户
            Account account = new Account();
            account.LoginName = "CacheBuilder";
            account.Password = "";
            account.Rights = "getbibliosummary";

            account.Type = "";
            account.Barcode = "";
            account.Name = "AddNotifyRecordToQueue";
            account.UserID = "AddNotifyRecordToQueue";
            account.RmsUserName = this.ManagerUserName;
            account.RmsPassword = this.ManagerPassword;

            sessioninfo.Account = account;
            try
            {

                string strBiblioRecPath = "";
                LibraryServerResult result = this.GetBiblioSummary(
                    sessioninfo,
                    strItemBarcode,
                    "", // strConfirmItemRecPath,
                    null,
                    out strBiblioRecPath,
                    out strSummary);
                if (result.Value == -1)
                {
                    strSummary = "ERROR: " + result.ErrorInfo;
                }
                else
                {
                    // 截断
                    if (strSummary.Length > 25)
                        strSummary = strSummary.Substring(0, 25) + "...";
                }
            }
            finally
            {
                sessioninfo.Close();
                sessioninfo = null;
            }
#endif


            // 发送短消息通知
            string strTotalError = "";

            // *** dpmail
            if (this.MessageCenter != null)
            {
                string strTemplate = "";
                // 获得邮件模板
                nRet = GetMailTemplate(
                    "dpmail",
                    bOnShelf == false ? "预约到书通知" : "预约到书通知(在架)",
                    out strTemplate,
                    out strError);
                if (nRet == -1)
                    return -1;
                if (nRet == 0)
                {
                    strError = "预约到书通知<mailTemplate/template>尚未配置。";
                    return -1;
                }

                /*
                %item%  册信息
                %reservetime%   保留期限
                %today% 发出email的当天
                %summary% 书目摘要
                %itembarcode% 册条码号 
                %name% 读者姓名
                 * */
                Hashtable table = new Hashtable();
                table["%item%"] = "(册条码号为: " + strItemBarcode + " URL为: " + this.OpacServerUrl + "/book.aspx?barcode=" + strItemBarcode + " )";
                table["%reservetime%"] = this.GetDisplayTimePeriodStringEx(this.ArrivedReserveTimeSpan);
                table["%today%"] = DateTime.Now.ToString();
                table["%summary%"] = strSummary;
                table["%itembarcode%"] = strItemBarcode;
                table["%name%"] = strName;
                string strBody = "";

                nRet = GetMailText(strTemplate,
                    table,
                    out strBody,
                    out strError);
                if (nRet == -1)
                    return -1;

                if (String.IsNullOrEmpty(this.MessageCenter.MessageDbName) == false)
                {
                    Debug.Assert(channel.Container != null, "");
                    // 发送消息
                    nRet = this.MessageCenter.SendMessage(
                        channel.Container,  // channels,
                        strReaderBarcode,
                        "图书馆",
                        "预约到书通知",
                        "text",
                        strBody,
                        false,
                        out strError);
                    if (nRet == -1)
                    {
                        strTotalError += "发送dpmail消息时出错: " + strError + "\r\n";
                    }
                }
            }

            // ** email
            if (String.IsNullOrEmpty(strReaderEmailAddress) == false)
            {
                string strTemplate = "";
                // 获得邮件模板
                nRet = GetMailTemplate(
                    "email",
                    bOnShelf == false ? "预约到书通知" : "预约到书通知(在架)",
                    out strTemplate,
                    out strError);
                if (nRet == -1)
                    return -1;
                if (nRet == 0)
                {
                    strError = "预约到书通知<mailTemplate/template>尚未配置。";
                    return -1;
                }

                /*
                %item%  册信息
                %reservetime%   保留期限
                %today% 发出email的当天
                %summary% 书目摘要
                %itembarcode% 册条码号 
                %name% 读者姓名
                 * */
                Hashtable table = new Hashtable();
                table["%item%"] = "(册条码号为: " + strItemBarcode + " URL为: " + this.OpacServerUrl + "/book.aspx?barcode=" + strItemBarcode + " )";
                table["%reservetime%"] = this.GetDisplayTimePeriodStringEx(this.ArrivedReserveTimeSpan);
                table["%today%"] = DateTime.Now.ToString();
                table["%summary%"] = strSummary;
                table["%itembarcode%"] = strItemBarcode;
                table["%name%"] = strName;

                string strBody = "";

                nRet = GetMailText(strTemplate,
                    table,
                    out strBody,
                    out strError);
                if (nRet == -1)
                    return -1;

                {
                    // 发送email
                    // return:
                    //      -1  error
                    //      0   not found smtp server cfg
                    //      1   succeed
                    nRet = SendEmail(strReaderEmailAddress,
                        "预约到书通知",
                        strBody,
                        "text",
                        out strError);
                    if (nRet == -1)
                    {
                        strTotalError += "发送email消息时出错: " + strError + "\r\n";
                    }
                }
            }

            // *** external messageinterfaces
            if (this.m_externalMessageInterfaces != null)
            {
                foreach (MessageInterface message_interface in this.m_externalMessageInterfaces)
                {
                    string strTemplate = "";
                    // 获得邮件模板
                    nRet = GetMailTemplate(
                        message_interface.Type,
                        bOnShelf == false ? "预约到书通知" : "预约到书通知(在架)",
                        out strTemplate,
                        out strError);
                    if (nRet == -1)
                        return -1;
                    if (nRet == 0)
                    {
                        strError = "预约到书通知<mailTemplate/template>尚未配置。";
                        return -1;
                    }

                    /*
                    %item%  册信息
                    %reservetime%   保留期限
                    %today% 发出email的当天
                %summary% 书目摘要
                %itembarcode% 册条码号 
                %name% 读者姓名
                     * */
                    Hashtable table = new Hashtable();
                    table["%item%"] = "(册条码号为: " + strItemBarcode + " URL为: " + this.OpacServerUrl + "/book.aspx?barcode=" + strItemBarcode + " )";
                    table["%reservetime%"] = this.GetDisplayTimePeriodStringEx(this.ArrivedReserveTimeSpan);
                    table["%today%"] = DateTime.Now.ToString();
                    table["%summary%"] = strSummary;
                    table["%itembarcode%"] = strItemBarcode;
                    table["%name%"] = strName;

                    string strBody = "";

                    nRet = GetMailText(strTemplate,
                        table,
                        out strBody,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    // 发送消息
                    nRet = message_interface.HostObj.SendMessage(
                        strReaderBarcode,
                        strReaderXml,
                        strBody,
                        strLibraryCode,
                        out strError);
                    if (nRet == -1)
                    {
                        strTotalError += "发送"+message_interface.Type+"消息时出错: " + strError + "\r\n";
                    }
                }
            }

            if (String.IsNullOrEmpty(strTotalError) == false)
            {
                strError = strTotalError;
                return -1;
            }

            return 0;
        }