Ejemplo n.º 1
0
        /// <summary>
        /// 更新微信用户
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public long Update(WxUserItem item)
        {
            dp2WeiXinService.Instance.WriteDebug("走进WxUserDatabase.Update(),id=" + item.id + " weixinid=" + item.weixinId);

            var filter = Builders <WxUserItem> .Filter.Eq("id", item.id);

            var update = Builders <WxUserItem> .Update
                         .Set("weixinId", item.weixinId)
                         .Set("libName", item.libName)
                         .Set("libId", item.libId)
                         .Set("bindLibraryCode", item.bindLibraryCode)

                         .Set("readerBarcode", item.readerBarcode)
                         .Set("readerName", item.readerName)
                         .Set("department", item.department)
                         .Set("phone", item.phone)
                         .Set("gender", item.gender)             // 2020/6/2 性别
                         .Set("patronState", item.patronState)
                         .Set("noPassReason", item.noPassReason) // 2020-3-8 不通过原因
                         .Set("isRegister", item.isRegister)     //2020-3-7 是否读者自助注册的
                         .Set("xml", item.xml)
                         .Set("recPath", item.recPath)

                         .Set("refID", item.refID)
                         .Set("createTime", item.createTime)
                         .Set("updateTime", item.updateTime)
                         .Set("isActive", item.isActive)


                         .Set("libraryCode", item.libraryCode)
                         .Set("type", item.type)
                         .Set("userName", item.userName)
                         .Set("isActiveWorker", item.isActiveWorker)

                         // 2016-8-26 jane 加
                         .Set("state", item.state)
                         .Set("remark", item.remark)
                         .Set("rights", item.rights)
                         .Set("appId", item.appId)
                         .Set("tracing", item.tracing)
                         .Set("location", item.location)       // 自己可管理的馆藏地
                         .Set("selLocation", item.selLocation) // 关注的馆藏地
                         .Set("verifyBarcode", item.verifyBarcode)
                         .Set("audioType", item.audioType)     //2018/1/2

                                                               /*
                                                                * public int showPhoto { get; set; }
                                                                * public int showCover { get; set; }
                                                                * public string bookSubject { get; set; } // 20170509加
                                                                */
                         .Set("showPhoto", item.showPhoto)
                         .Set("showCover", item.showCover)
                         .Set("bookSubject", item.bookSubject)
            ;

            UpdateResult ret = this.wxUserCollection.UpdateOne(filter, update);

            return(ret.ModifiedCount);
        }
Ejemplo n.º 2
0
        public WxUserItem CreatePublic(string weixinId, string libId, string bindLibraryCode)
        {
            WxUserItem userItem = new WxUserItem();

            userItem.weixinId = weixinId;
            userItem.libId    = libId;
            Library lib = dp2WeiXinService.Instance.LibManager.GetLibrary(libId);

            if (lib == null)
            {
                throw new Exception("libid=" + libId + "对应的对象没有找到。");
            }

            userItem.libName         = lib.Entity.libName;
            userItem.bindLibraryCode = bindLibraryCode; //界面上选择的绑定分馆
            if (String.IsNullOrEmpty(userItem.bindLibraryCode) == false)
            {
                userItem.libName = userItem.bindLibraryCode;
            }

            userItem.readerBarcode = "";
            userItem.readerName    = "";
            userItem.department    = "";
            userItem.phone         = "";
            userItem.gender        = "";
            userItem.patronState   = ""; //2020-3-7加
            userItem.noPassReason  = "";
            userItem.isRegister    = false;

            userItem.xml        = "";
            userItem.refID      = "";
            userItem.createTime = DateTimeUtil.DateTimeToString(DateTime.Now);
            userItem.updateTime = userItem.createTime;
            userItem.isActive   = 1;      // 活动

            userItem.libraryCode    = ""; //实际分馆
            userItem.type           = WxUserDatabase.C_Type_Worker;
            userItem.userName       = WxUserDatabase.C_Public;
            userItem.isActiveWorker = 0;     //是否是激活的工作人员账户,读者时均为0
            userItem.tracing        = "off"; //默认是关闭监控
            userItem.location       = "";
            userItem.selLocation    = "";
            userItem.verifyBarcode  = 0;
            userItem.audioType      = 4;
            userItem.state          = WxUserDatabase.C_State_Available; //1;
            userItem.remark         = "";
            userItem.rights         = "";
            userItem.showCover      = 1;
            userItem.showPhoto      = 1;

            WxUserDatabase.Current.Add(userItem);

            dp2WeiXinService.Instance.WriteDebug("自动以绑public身份新建一条");

            return(userItem);
        }
Ejemplo n.º 3
0
        /*
         * // 获取当前活动的读者账户
         * public WxUserItem GetActivePatron1(string weixinId,string libId)
         * {
         *  WxUserItem activePatron = null;
         *  int count = 0;
         *  List<WxUserItem> list = this.Get(weixinId, libId, C_Type_Patron);
         *  if (list != null && list.Count > 0)
         *  {
         *      foreach (WxUserItem item in list)
         *      {
         *          if (item.isActive == 1)
         *          {
         *              activePatron = item;
         *              count++;
         *          }
         *      }
         *  }
         *
         *  if (count>1)
         *      throw new Exception("程序异常:微信号活动读者数量有" +list.Count+"个");
         *
         *  return activePatron;
         * }
         */

        // 获取当前活动的账户  可能是读者也可能是工作人员,只有一个
        public WxUserItem GetActive(string weixinId)
        {
            WxUserItem        activeUser = null;
            List <WxUserItem> activeList = new List <WxUserItem>();

            // 这里不再区分图书馆和类型,读者与工作人员当前只能有一个活动的
            List <WxUserItem> list = this.Get(weixinId, "", -1);

            if (list != null && list.Count > 0)
            {
                foreach (WxUserItem item in list)
                {
                    if (item.isActive == 1)
                    {
                        activeList.Add(item);
                    }
                }
            }

            // 活动帐号大于,异常,自动将其它几条设为非活动。
            if (activeList.Count > 0)
            {
                // 认第一条为活动帐户
                activeUser = activeList[0];
                if (activeList.Count > 1)
                {
                    string strError = "发现微信号活动读者帐户有" + list.Count + "个,程序自动将除第1个外的其余帐户没为非活动态";
                    dp2WeiXinService.Instance.WriteDebug(strError);
                    for (int i = 1; i < activeList.Count; i++)
                    {
                        WxUserItem item = activeList[i];
                        item.isActive = 0;
                        WxUserDatabase.Current.Update(item);
                        dp2WeiXinService.Instance.WriteDebug(item.userName + "/" + item.readerBarcode);
                    }
                }
            }

            // 有绑号帐号,但没有对应的活动帐号,自动将第一个帐户设为活动帐户
            if (list.Count > 0 && activeList.Count == 0)
            {
                dp2WeiXinService.Instance.WriteDebug("发现微信号有绑定帐户,但当前没有活动帐户,自动将第一条设为活动帐户");
                activeUser          = list[0];
                activeUser.isActive = 1;
                WxUserDatabase.Current.Update(activeUser);
                dp2WeiXinService.Instance.WriteDebug(activeUser.userName + "/" + activeUser.readerBarcode);
            }


            return(activeUser);
        }
Ejemplo n.º 4
0
        public WxUserItem CreatePublic(string weixinId, string libId, string bindLibraryCode)
        {
            WxUserItem userItem = new WxUserItem();

            userItem.weixinId = weixinId;
            userItem.libId    = libId;
            Library lib = dp2WeiXinService.Instance.LibManager.GetLibrary(libId);

            userItem.libName         = lib.Entity.libName;
            userItem.bindLibraryCode = bindLibraryCode; //界面上选择的绑定分馆
            if (String.IsNullOrEmpty(userItem.bindLibraryCode) == false)
            {
                userItem.libName = userItem.bindLibraryCode;
            }

            userItem.readerBarcode = "";
            userItem.readerName    = "";
            userItem.department    = "";
            userItem.xml           = "";
            userItem.refID         = "";
            userItem.createTime    = DateTimeUtil.DateTimeToString(DateTime.Now);
            userItem.updateTime    = userItem.createTime;
            userItem.isActive      = 1;   // 活动

            userItem.libraryCode    = ""; //实际分馆
            userItem.type           = WxUserDatabase.C_Type_Worker;
            userItem.userName       = "******";
            userItem.isActiveWorker = 0;     //是否是激活的工作人员账户,读者时均为0
            userItem.tracing        = "off"; //默认是关闭监控
            userItem.location       = "";
            userItem.selLocation    = "";
            userItem.verifyBarcode  = 0;
            userItem.audioType      = 4;
            userItem.state          = 1;
            userItem.remark         = "";
            userItem.rights         = "";
            userItem.showCover      = 1;
            userItem.showPhoto      = 1;

            WxUserDatabase.Current.Add(userItem);

            dp2WeiXinService.Instance.WriteLog1("自动以绑public身份新建一条");

            return(userItem);
        }
Ejemplo n.º 5
0
        /// 新增绑定账户
        public WxUserItem Add(WxUserItem item)
        {
            lock (_sync_addUser)
            {
                dp2WeiXinService.Instance.WriteDebug("走进WxUserDatabase.Add(),id=" + item.id + " weixinid=" + item.weixinId);

                List <WxUserItem> itemList = this.Get(item.weixinId, item.libId, null, item.type, item.readerBarcode, item.userName, true);
                if (itemList.Count == 0)
                {
                    this.wxUserCollection.InsertOne(item);
                    dp2WeiXinService.Instance.WriteDebug("InsertOne(),id=" + item.id);
                }
                else
                {
                    dp2WeiXinService.Instance.WriteDebug("发现绑定帐户库中已有'" + item.readerBarcode + "'或'" + item.userName + "'对应的记录。");
                }
            }
            return(item);
        }
Ejemplo n.º 6
0
        /// 删除账户
        /// 如果删除的是读者账户,自动将对应图书馆第一个读者账户设为默认的
        public void Delete1(String id, out WxUserItem newActiveUser)
        {
            newActiveUser = null;

            dp2WeiXinService.Instance.WriteDebug("走进WxUserDatabase.Delete() id=" + id);

            if (string.IsNullOrEmpty(id) == true || id == "null")
            {
                return;
            }

            // 检查一下是否被删除读者是否为默认读者,如果是,后面把自动将默认值设了第一个读者上。
            WxUserItem userItem = this.GetById(id);

            if (userItem == null)
            {
                return;
            }
            dp2WeiXinService.Instance.WriteDebug("走进WxUserDatabase.Delete(),id=" + userItem.id + " weixinid=" + userItem.weixinId);

            string weixinId        = "";
            int    type            = -1;
            int    isActive        = 0;
            string libId           = "";
            string tracing         = "";
            string bindLibraryCode = "";

            if (userItem != null)
            {
                weixinId        = userItem.weixinId;
                type            = userItem.type;
                isActive        = userItem.isActive;
                libId           = userItem.libId;
                tracing         = userItem.tracing;
                bindLibraryCode = userItem.bindLibraryCode;
            }

            // 先删除
            IMongoCollection <WxUserItem> collection = this.wxUserCollection;
            var filter = Builders <WxUserItem> .Filter.Eq("id", id);

            collection.DeleteOne(filter);

            // 如果删除的是读者账户且是激活的,自动将本馆第一个读者账户设为默认的
            if (isActive == 1)
            {
                // 先取本馆的绑定帐户
                List <WxUserItem> list = this.Get(weixinId, libId, -1);
                if (list != null && list.Count > 0)
                {
                    newActiveUser = list[0];
                }

                // 如果本馆帐户没找到,则把该微信号绑定的第一个帐户设为活动的
                if (newActiveUser == null)
                {
                    list = this.Get(weixinId, "", -1);
                    if (list != null && list.Count > 0)
                    {
                        newActiveUser = list[0];
                    }
                }

                // 没有一个绑定帐户时,为刚才的馆创建一个public
                if (newActiveUser == null)
                {
                    newActiveUser = this.CreatePublic(weixinId, libId, bindLibraryCode);
                }

                // 设为活动状态,让外面调的函数设置,因为刚设数据库不行,也要更新当前session,这样外面一起做
                //this.SetActivePatron1(newActivePatron.weixinId, newActivePatron.id);
            }

            //// 如果是工作人员,且打开监控功能
            //if (type==1 && String.IsNullOrEmpty(tracing)==false && tracing !="off")
            //{
            //    dp2WeiXinService.Instance.UpdateMemoryTracingUser(weixinId, libId, "off");
            //}
        }
Ejemplo n.º 7
0
        // 根据weixinId得到当前活动帐户的信息
        public int GetActiveUser(string weixinId,
                                 out string error)
        {
            error = "";
            int nRet = 0;

            if (string.IsNullOrEmpty(weixinId) == true)
            {
                error = "weixinId都不能为空";
                return(-1);
            }

            this.WeixinId = weixinId;

            // 找到当前激活的帐户,有可能是工作人员,也有可能是读者帐号
            this.ActiveUser = WxUserDatabase.Current.GetActive(this.WeixinId);
            if (this.ActiveUser != null)
            {
                // 当前图书馆
                this.CurrentLib = dp2WeiXinService.Instance.LibManager.GetLibrary(this.ActiveUser.libId);

                //// 如果是工作人员,获取地应图书馆的读者类型和读者库,用于读者登记
                //if (this.ActiveUser.type == WxUserDatabase.C_Type_Worker
                //    && this.ActiveUser.userName != WxUserDatabase.C_Public)
                //{

                //    List<string> dataList = null;
                //    nRet = dp2WeiXinService.Instance.GetSystemParameter(
                //        this.CurrentLib.Entity,
                //        "_valueTable",
                //        "readerType",
                //        out dataList,
                //        out error);
                //    if (nRet == -1)
                //    {
                //        dp2WeiXinService.Instance.WriteErrorLog("!!!" + error);
                //        //return -1;
                //    }
                //    if (dataList != null && dataList.Count > 0)
                //    {
                //        string tempReaderTypes = dataList[0];
                //        string[] typeList = tempReaderTypes.Trim().Split(new char[] { ',' });

                //        string types = "";
                //        //这里要把不与当前馆匹配的 总馆或分馆的读者类型过滤掉,只剩下有用的类型
                //        // 为什么要用bindLibraryCode参数,而不用libraryCode,
                //        // 是因为libraryCode可能是多个分馆也可能是空,但绑定的只能选择一个范围内的馆,所以用bindLibraryCode表示当前馆更准备,而且是一个
                //        if (string.IsNullOrEmpty(this.ActiveUser.bindLibraryCode) == true)
                //        {
                //            foreach (string type in typeList)
                //            {
                //                if (type.Length >= 1 && type.Substring(0, 1) == "{")
                //                    continue;

                //                if (types != "")
                //                    types += ",";

                //                types += type;
                //            }
                //        }
                //        else
                //        {
                //            string fullLibCode = "{" + this.ActiveUser.bindLibraryCode + "}";
                //            foreach (string type in typeList)
                //            {
                //                if (type.IndexOf(fullLibCode) == -1)
                //                    continue;

                //                if (types != "")
                //                    types += ",";

                //                types += type;
                //            }

                //        }

                //        this.ReaderTypes = types;
                //    }


                // 2020-3-1觉得让馆员选择可能搞不清楚,还是统一使用配置文件设置的吧,与读者自助注册一样

                /*
                 * LoginInfo loginInfo = new LoginInfo(this.ActiveUser.userName, false);
                 * nRet = dp2WeiXinService.Instance.GetInfo(this.CurrentLib.Entity,
                 *  loginInfo,
                 *  "getSystemParameter",
                 *  "reader",
                 *  "dbnames",
                 *  out dataList,
                 *  out error);
                 * if (nRet == -1)
                 * {
                 *  dp2WeiXinService.Instance.WriteErrorLog("!!!" + error);
                 *  return -1;
                 * }
                 * if (dataList != null && dataList.Count > 0)
                 * {
                 *  this.ReaderDbnames = dataList[0];
                 * }
                 */

                //}
            }

            return(0);
        }
Ejemplo n.º 8
0
        public string GetReaderType(WxUserItem user,
                                    out string error)
        {
            error = "";
            if (user == null)
            {
                error = "传入的user为null";
                return("");
            }

            if (_readerTypes == null)
            {
                // 从服务器获取
                string tempReaderTypes = "";
                int    nRet            = dp2WeiXinService.Instance.GetReaderType(user.libId,
                                                                                 user,
                                                                                 out tempReaderTypes,
                                                                                 out error);
                if (nRet == -1)
                {
                    error = "获取读者类型出错:" + error;
                    dp2WeiXinService.Instance.WriteErrorLog("" + error);
                    return("");
                }

                string   types    = "";
                string[] typeList = tempReaderTypes.Trim().Split(new char[] { ',' });

                //这里要把不与当前馆匹配的 总馆或分馆的读者类型过滤掉,只剩下有用的类型
                // 为什么要用bindLibraryCode参数,而不用libraryCode,
                // 是因为libraryCode可能是多个分馆也可能是空,但绑定的只能选择一个范围内的馆,所以用bindLibraryCode表示当前馆更准备,而且是一个
                if (string.IsNullOrEmpty(this.ActiveUser.bindLibraryCode) == true)
                {
                    foreach (string type in typeList)
                    {
                        if (type.Length >= 1 && type.Substring(0, 1) == "{")
                        {
                            continue;
                        }

                        if (types != "")
                        {
                            types += ",";
                        }

                        types += type;
                    }
                }
                else
                {
                    string fullLibCode = "{" + this.ActiveUser.bindLibraryCode + "}";
                    foreach (string type in typeList)
                    {
                        if (type.IndexOf(fullLibCode) == -1)
                        {
                            continue;
                        }

                        if (types != "")
                        {
                            types += ",";
                        }

                        types += type;
                    }
                }

                // 设到内存里,下次就不用再获取了。
                this._readerTypes = types;
            }

            return(_readerTypes);
        }
Ejemplo n.º 9
0
        // 初始化
        public int Init1(string weixinId,
                         out string error)
        {
            error = "";
            int nRet = 0;

            if (string.IsNullOrEmpty(weixinId) == true)
            {
                error = "weixinId都不能为空";
                return(-1);
            }

            this.AddDebugInfo("初始化session,weixinId=" + weixinId);

            this.WeixinId = weixinId;

            // 找到对应的读者和工作人员
            this.Active = WxUserDatabase.Current.GetActive(this.WeixinId);
            if (this.Active != null)
            {
                // 当前图书馆
                this.CurrentLib = dp2WeiXinService.Instance.LibManager.GetLibrary(this.Active.libId);

                // 如果是工作人员,获取地应图书馆的读者类型和读者库,用于读者登记
                if (this.Active.type == WxUserDatabase.C_Type_Worker && this.Active.userName != "public")
                {
                    List <string> dataList = null;
                    nRet = dp2WeiXinService.Instance.GetSystemParameter(this.CurrentLib.Entity,
                                                                        "_valueTable",
                                                                        "readerType",
                                                                        out dataList,
                                                                        out error);
                    if (nRet == -1)
                    {
                        dp2WeiXinService.Instance.WriteErrorLog1("!!!" + error);
                        //return -1;
                    }
                    if (dataList != null && dataList.Count > 0)
                    {
                        readerTypes = dataList[0];
                    }

                    LoginInfo loginInfo = new LoginInfo(this.Active.userName, false);
                    nRet = dp2WeiXinService.Instance.GetInfo(this.CurrentLib.Entity,
                                                             loginInfo,
                                                             "getSystemParameter",
                                                             "reader",
                                                             "dbnames",
                                                             out dataList,
                                                             out error);
                    if (nRet == -1)
                    {
                        dp2WeiXinService.Instance.WriteErrorLog1("!!!" + error);
                        return(-1);
                    }
                    if (dataList != null && dataList.Count > 0)
                    {
                        readerDbnames = dataList[0];
                    }
                }
            }

            return(0);
        }