예제 #1
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);
            }
        }
예제 #2
0
        /// <summary>
        /// 提交申请
        /// </summary>
        /// <param name="input"></param>
        public string Submit(VisitorApplyDto input, string img)
        {
            input.ImgUri = img;
            var currentUserId = Operator.GetCurrent().Id;
            var MSG           = "";
            var LimitCount    = Query <DormVisitLimit>(p => p.StudentId.Equals(currentUserId)).FirstOrDefault();

            if (LimitCount.UsableLimit == 0)
            {
                return("当前学生被访额度为0");
            }
            // var visit = input.MapTo<VisitApply>();//映射到数据库中对应的表
            var visit = new VisitorApply
            {
                ApplicantId    = currentUserId,
                VisitorGender  = input.VisitorGender,
                VisitorName    = input.VisitorName,
                VisitorIDCard  = input.VisitorIDCard,
                VisitReason    = input.VisitReason,
                VisitType      = input.VisitType,
                VisitStartTime = input.VisitStartTime,
                VisitEndTime   = input.VisitEndTime,
                Relationship   = input.Relationship,
                Status         = "0",
                ImgUri         = input.ImgUri
            };
            //获取学生所在的dormid
            var dormid = Read <DormStudent>(p => p.StudentId.Equals(currentUserId)).Select(p => p.DormId).FirstOrDefault();
            //获取dorm对应的楼栋Id
            var buildingId = Read <DormRoom>(p => p.Id.Equals(dormid)).Select(p => p.BuildingId).FirstOrDefault();
            //获取楼栋对应的宿管
            var Approvers = Read <Relevance>(p => p.Name.Equals("Building_User") && p.FirstKey.Equals(buildingId)).Select(p => p.SecondKey).ToListAsync().Result;

            if (null == Approvers)
            {
                throw new Exception("请先绑定宿管!");
            }
            if (visit.VisitType.Equals("0"))
            {
                var stu = Read <Student>(p => p.Id.Equals(input.VisitorId)).FirstOrDefault();
                visit.Status        = "1";
                visit.VisitorIDCard = stu.CredNumber;
                visit.VisitorGender = stu.Gender;
                AddAndSave(new VisitorApprove
                {
                    ApproverId    = Approvers.ToJson(),
                    VisitId       = visit.Id,
                    ApproveLevel  = 1,
                    ApproveResult = "1"
                });
                //人员在大华的ID
                var code      = Read <Student>(p => p.Id.Equals(input.VisitorId)).Select(p => p.StudentNumber).FirstOrDefault();
                var dhUserstr = DHAccount.SELECT_DH_PERSON(new PersonMoudle()
                {
                    code = code
                });
                var ResultList = (List <object>)dhUserstr.ToString().Parse2JObject()["data"]["list"].ToObject(typeof(List <object>));
                visit.DhId = ResultList.First().ToString().Parse2JObject().Value <int>("id").ToString();
                MSG        = PushVisitorSchool(buildingId, visit.VisitEndTime, Convert.ToInt32(visit.DhId));
                //添加校内访客成功: 访问额度 -1
                LimitCount.UsableLimit--;
            }
            else
            {
                AddAndSave(new VisitorApprove
                {
                    ApproverId    = Approvers.ToJson(),
                    VisitId       = visit.Id,
                    ApproveLevel  = 1,
                    ApproveResult = "0"
                });
            }
            visit.DormId     = dormid;
            visit.BuildingId = buildingId;
            visit.ImgUri     = input.ImgUri;
            AddAndSave(visit);
            SaveChanges();
            return(MSG);
        }