Esempio n. 1
0
        public static string ExecuteGetPersons(string URI, PersonMoudle personMoudle, string token)
        {
            var url = returnParam(URI, personMoudle);

            try
            {
                var myRequest = HttpWebRequest.Create(url) as HttpWebRequest;
                myRequest.Method           = "GET";
                myRequest.ContentType      = "application/json;charset=UTF-8";
                myRequest.ReadWriteTimeout = 30000;
                if (token != null)
                {
                    myRequest.Headers.Add("Cookie", "JSESSIONID=636972042564F947376441F073B8160D;token=" + token);
                }
                var myResponse = myRequest.GetResponse() as HttpWebResponse;
                var sr         = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
                var res        = sr.ReadToEnd();
                return(res);
            }
            catch (WebException ex)
            {
                var rsp        = ex.Response as HttpWebResponse;
                var statucCode = (int)rsp.StatusCode;
                if (statucCode == 401)
                {
                    var sr  = new StreamReader(rsp.GetResponseStream(), Encoding.UTF8);
                    var res = sr.ReadToEnd();
                    return(res);
                }
                return(null);
            }
        }
Esempio n. 2
0
        /*****************************        定时任务调用方法:推送人员信息至大华闸机         ********************************/
        /// <summary>
        /// 人员信息  => 推送人员信息至大华
        /// </summary>
        public static object PUSH_DH_ADD_PERSON(PersonMoudle personMoudle)
        {
            X_SUBJECT_TOKEN = RedisHelper.GetDatabase(REDIS_LINE_RECORD_DB_LEVEL).StringGet(REDIS_TOKEN_SET_KEY);

            if (personMoudle.photoUrl != null && personMoudle.photoUrl.Length != 0)
            {
                personMoudle.photoBase64 = GetImageBase64Str.ImageBase64Str(personMoudle.photoUrl); //通过头像地址,获取头像Base64位字符串
            }
            return(HttpHelper.ExecutePostMachineInfo(Constants.CREATE_STUDENTS_INFO + "?sessionId=" + X_SUBJECT_TOKEN, JsonConvert.SerializeObject(personMoudle), X_SUBJECT_TOKEN));
        }
Esempio n. 3
0
        /// <summary>
        /// 组合Get请求的参数
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="personMoudle"></param>
        /// <returns></returns>
        public static string returnParam(string Url, PersonMoudle personMoudle)
        {
            var Param = new StringBuilder("?");

            if (personMoudle.code != null && personMoudle.code.Length != 0)
            {
                Param.Append("code=" + personMoudle.code + "&");
            }
            if (personMoudle.name != null && personMoudle.name.Length != 0)
            {
                Param.Append("name=" + personMoudle.name + "&");
            }
            if (personMoudle.contactNum != null && personMoudle.contactNum.Length != 0)
            {
                Param.Append("contactNum=" + personMoudle.contactNum + "&");
            }
            if (personMoudle.dormitoryCode != null && personMoudle.dormitoryCode.Length != 0)
            {
                Param.Append("dormitoryCode=" + personMoudle.dormitoryCode + "&");
            }
            if (personMoudle.dormitoryFloor != null && personMoudle.dormitoryFloor.Length != 0)
            {
                Param.Append("dormitoryFloor=" + personMoudle.dormitoryFloor + "&");
            }
            if (personMoudle.dormitoryRoom != null && personMoudle.dormitoryRoom.Length != 0)
            {
                Param.Append("dormitoryRoom=" + personMoudle.dormitoryRoom + "&");
            }
            if (personMoudle.dormitoryBed != null && personMoudle.dormitoryBed.Length != 0)
            {
                Param.Append("dormitoryBed=" + personMoudle.dormitoryBed + "&");
            }
            if (personMoudle.colleageCode != null && personMoudle.colleageCode.Length != 0)
            {
                Param.Append("colleageCode=" + personMoudle.colleageCode + "&");
            }
            if (personMoudle.colleageMajor != null && personMoudle.colleageMajor.Length != 0)
            {
                Param.Append("colleageMajor=" + personMoudle.colleageMajor + "&");
            }
            if (personMoudle.colleageGrade != null && personMoudle.colleageGrade.Length != 0)
            {
                Param.Append("colleageGrade=" + personMoudle.colleageGrade + "&");
            }
            if (personMoudle.colleageClass != null && personMoudle.colleageClass.Length != 0)
            {
                Param.Append("colleageClass=" + personMoudle.colleageClass + "&");
            }
            if (personMoudle.orgId != null && personMoudle.orgId.Length != 0)
            {
                Param.Append("orgId=" + personMoudle.orgId + "&");
            }
            return(Url + Param.ToString().Substring(0, Param.ToString().Length - 1));
        }
Esempio n. 4
0
 /// <summary>
 /// 人员信息 => 修改人员信息(大华)
 /// </summary>
 /// <param name="personMoudle"></param>
 public static object PUSH_DH_UPDATE_PERSON(PersonMoudle personMoudle)
 {
     X_SUBJECT_TOKEN = RedisHelper.GetDatabase(REDIS_LINE_RECORD_DB_LEVEL).StringGet(REDIS_TOKEN_SET_KEY);
     if (personMoudle.photoUrl != null && personMoudle.photoUrl.Length != 0)
     {
         personMoudle.photoBase64 = GetImageBase64Str.ImageBase64Str(personMoudle.photoUrl);//通过头像地址,获取头像Base64位字符串
     }
     if (default(int) == personMoudle.id)
     {
         var PersonJson = HttpHelper.ExecuteGetPersons(Constants.SELECT_STUDENTS_INFO, new PersonMoudle()
         {
             code = personMoudle.code
         }, X_SUBJECT_TOKEN);
         if (null != PersonJson)
         {
             var code = PersonJson.Parse2JObject().Value <int>("code");
             if (code == 200)
             {
                 personMoudle.id = PersonJson.Parse2JObject()["data"]["list"][0].Value <int>("id");
             }
         }
     }
     return(HttpHelper.ExecutePut(Constants.UPDATE_STUDENTS_INFO + "?sessionId=" + X_SUBJECT_TOKEN, JsonConvert.SerializeObject(personMoudle), X_SUBJECT_TOKEN));
 }
Esempio n. 5
0
 /// <summary>
 /// 查询大华设备的用户信息
 /// </summary>
 /// <param name="personMoudle"></param>
 /// <returns></returns>
 public static object SELECT_DH_PERSON(PersonMoudle personMoudle)
 {
     X_SUBJECT_TOKEN = RedisHelper.GetDatabase(REDIS_LINE_RECORD_DB_LEVEL).StringGet(REDIS_TOKEN_SET_KEY);
     return(HttpHelper.ExecuteGetPersons(Constants.SELECT_STUDENTS_INFO, personMoudle, X_SUBJECT_TOKEN));
 }
Esempio n. 6
0
        public void SendUserHeadIco(string[] userId)
        {
            var stuList    = Read <User>().Where(t => userId.Contains(t.Id)).ToList();
            var listPerson = new List <PersonMoudle>();

            foreach (var u in stuList)
            {
                var person = new PersonMoudle();
                if (u.DutyId.Contains("student"))
                {
                    var stu = Read <Student>(p => p.UserId == u.Id).FirstOrDefault();
                    person.code   = stu?.StudentNumber;
                    person.sex    = stu?.Gender == "0" ? 2 : 1;
                    person.idCode = stu?.CredNumber;
                    person.roleId = "student001";// "学生";

                    var ssdata = Query <DormStudent>(p => p.StudentId == stu.Id).FirstOrDefault();
                    person.dormitoryRoom = ssdata?.DormInfo?.Title;
                    person.dormitoryCode = ssdata?.DormInfo?.FloorNumber;
                    var ldid = ssdata?.DormInfo?.BuildingId;
                    // 闸机Id列表
                    var zjids = Read <Relevance>(p => p.SecondKey == ldid && p.Name == Relation.GateBuilding).Select(p => p.FirstKey).ToList();
                    // 楼栋Id列表
                    var lds = Read <Relevance>(p => p.Name == "Gate_Building" && zjids.Contains(p.FirstKey)).Select(p => p.SecondKey).ToList();

                    var ldNums = Read <Building>(p => lds.Contains(p.Id)).Select(t => t.BuildingNo).ToList().Distinct().OrderBy(t => t);
                    person.dormitoryCode = "";
                    foreach (var ld in ldNums)
                    {
                        person.dormitoryCode += (ld + "栋");
                    }
                }

                if (u.DutyId.Contains("teacher"))
                {
                    var tea = Read <Teacher>(p => p.UserId == u.Id).FirstOrDefault();
                    person.code = tea?.JobNumber;
                    //imgUri = tea?.FacePhoto;
                    person.sex    = tea?.Gender == "0" ? 2 : 1;
                    person.idCode = tea?.CredNumber;
                    person.roleId = "teacher001";// "教职工";
                }
                person.photoUrl = u.HeadIcon;
                person.orgId    = "org001";
                person.name     = u.Name;
                listPerson.Add(person);
            }

            string result = null;

            foreach (var person in listPerson)
            {
                try
                {
                    var dhUserstr = DHAccount.SELECT_DH_PERSON(new PersonMoudle {
                        code = person.code
                    });
                    var ResultList = (List <object>)dhUserstr.ToString().Parse2JObject()["data"]["list"].ToObject(typeof(List <object>));
                    if (null != ResultList && ResultList.Count() > 0)
                    {
                        //var jo = dhUserstr.ToString().ToJObject();
                        //int code = jo.Value<int>("code"); //返回码
                        //if (code == 200)
                        //{
                        //    var datas = (List<object>)jo["data"]["list"].ToObject(typeof(List<object>));
                        //    for (int i = 0; i < datas.Count; i++)
                        //    {
                        //        string id = jo["data"]["list"][i]["id"]?.ToString();
                        //        DHAccount.PUSH_DH_DELETE_PERSON(new string[] { id });
                        //    }
                        //}
                        try
                        {
                            person.dormitoryCode  = null;
                            person.dormitoryFloor = null;
                            person.dormitoryRoom  = null;
                            person.dormitoryArea  = null;
                            person.id             = ResultList.First().ToString().Parse2JObject().Value <int>("id");
                            DHAccount.PUSH_DH_UPDATE_PERSON(person);
                        }
                        catch (Exception e)
                        {
                            result += person.name + ",";
                        }
                    }
                    else
                    {
                        try
                        {
                            DHAccount.PUSH_DH_ADD_PERSON(person);
                        }
                        catch (Exception e)
                        {
                            result += person.name + ",";
                        }
                    }
                }
                catch
                {
                }
            }
            if (result != null)
            {
                throw new Exception("以下用户下载失败!" + result);
            }
        }