Beispiel #1
0
        public object RegisterUser()
        {
            string fileName = DateTime.Now.ToString("yyyyMMdd") + ".log";
            string json     = HttpContext.Current.Request.Params["json"];

            try
            {
                if (!string.IsNullOrEmpty(json))
                {
                    ERCHTMS.Busines.BaseManage.UserBLL       userBll = new ERCHTMS.Busines.BaseManage.UserBLL();
                    ERCHTMS.Busines.BaseManage.DepartmentBLL deptBll = new ERCHTMS.Busines.BaseManage.DepartmentBLL();
                    dynamic dy = JsonConvert.DeserializeObject <ExpandoObject>(json);
                    if (string.IsNullOrEmpty(dy.userName))
                    {
                        return(new { code = 1, data = "", info = "参数:userName为空" });
                    }
                    if (string.IsNullOrEmpty(dy.mobile))
                    {
                        return(new { code = 1, data = "", info = "参数:mobile为空" });
                    }
                    if (string.IsNullOrEmpty(dy.deptName))
                    {
                        return(new { code = 1, data = "", info = "参数:deptName为空" });
                    }
                    //判断账号是否在系统中存在
                    bool result = userBll.ExistAccount(dy.mobile, "");
                    if (result)
                    {
                        string deptid  = new DataItemDetailBLL().GetItemValue("dept", "TryDept"); //所属单位ID,在后台配置(目前处理方案是在后台初始化好一个演示的单位,注册的用户直接挂在此单位即可)
                        string pathurl = new DataItemDetailBLL().GetItemValue("imgUrl");          //web平台对应的地址,放在编码配置也可后台直接后去,请根据实际情况处理
                        if (!string.IsNullOrEmpty(deptid))
                        {
                            var        dept = deptBll.GetEntity(deptid);
                            UserEntity user = new UserEntity();
                            user.UserId  = Guid.NewGuid().ToString();
                            user.Account = dy.mobile;
                            Random rnd = new Random();
                            string str = rnd.Next(10000, 99999).ToString();
                            user.RealName       = dy.userName;
                            user.Password       = str;
                            user.DepartmentId   = dept.DepartmentId;
                            user.DepartmentCode = dept.EnCode;
                            user.OrganizeId     = dept.OrganizeId;
                            user.OrganizeCode   = dept.EnCode;
                            user.Mobile         = dy.mobile;
                            user.IsEpiboly      = "0";
                            user.RoleName       = "公司级用户,公司管理员";
                            user.RoleId         = "aece6d68-ef8a-4eac-a746-e97f0067fab5,5af22786-e2f2-4a3d-8da3-ecfb16b96f36";
                            user.AllowStartTime = DateTime.Now;
                            user.AllowEndTime   = Convert.ToDateTime(user.AllowStartTime).AddDays(15);
                            user.Description    = dy.deptName;
                            user.IdentifyID     = "420115" + new Random().Next(1970, 2000) + "0722" + new Random().Next(1000, 9999);
                            user.IsPresence     = "1";
                            var tempdata = new
                            {
                                account      = dy.mobile,//账号
                                password     = str,
                                allowEndTime = Convert.ToDateTime(user.AllowEndTime).ToString("yyyy-MM-dd HH:mm:ss"),
                                path         = pathurl
                            };
                            userBll.SaveForm(user.UserId, user);
                            System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("~/logs/" + fileName), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ,注册成功,参数为:" + json + "\r\n");
                            return(new { code = 0, data = tempdata, info = "操作成功" });
                        }
                        else
                        {
                            return(new { code = 1, data = "", info = "试用单位未配置" });
                        }
                    }
                    else
                    {
                        return(new { code = 1, data = "", info = "手机号已存在!" });
                    }
                }
                else
                {
                    return(new { code = 1, data = "", info = "json参数为空" });
                }
            }
            catch (Exception ex)
            {
                System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("~/logs/" + fileName), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ,注册失败,异常信息:" + ex.Message + "参数为:" + json + "\r\n");
                return(new { code = 1, data = "", info = ex.Message });
            }
        }
Beispiel #2
0
        public object SyncToolsDepts()
        {
            try
            {
                DataTable dt = deptBll.GetDataTable(string.Format("select deptid,unitid,keys from BIS_TOOLSDEPT"));
                foreach (DataRow dr in dt.Rows)
                {
                    DepartmentEntity dept = deptBll.GetEntity(dr[0].ToString());
                    if (dept != null)
                    {
                        SstmsService.CheckHeader header = new SstmsService.CheckHeader();
                        header.Key = dr[2].ToString();
                        List <SstmsService.DictionaryEntry> dic = new List <SstmsService.DictionaryEntry>();
                        SstmsService.DictionaryEntry        de  = new SstmsService.DictionaryEntry();
                        de.Key   = "LaterID";
                        de.Value = dr[1].ToString();
                        dic.Add(de);
                        de       = new SstmsService.DictionaryEntry();
                        de.Key   = "Identify";
                        de.Value = "";
                        dic.Add(de);
                        // 实例化服务对象
                        SstmsService.DataServiceSoapClient service = new SstmsService.DataServiceSoapClient();
                        SstmsService.PersonInfo[]          data    = service.GetPersonsPage(header, dic.ToArray <SstmsService.DictionaryEntry>(), 1, 1000).List;
                        DepartmentEntity org = deptBll.GetEntity(dept.OrganizeId);
                        foreach (SstmsService.PersonInfo per in data)
                        {
                            string unitId   = per.OwnerDeptID;
                            string userId   = "";
                            string roleName = "承包商级用户";
                            string roleId   = "c5530ccf-e84e-4df8-8b27-fd8954a9bbe9";

                            if (dt.Rows.Count > 0)
                            {
                                string nature = dept.Nature;
                                switch (nature)
                                {
                                case "部门":
                                    roleName = "部门级用户";
                                    roleId   = "6c094cef-cca3-4b41-a71b-6ee5e6b89008";
                                    break;

                                case "专业":
                                    roleName = "专业级用户";
                                    roleId   = "e3062d59-2484-4046-a420-478886d58656";
                                    break;

                                case "班组":
                                    roleName = "班组级用户";
                                    roleId   = "d9432a6e-5659-4f04-9c10-251654199714";
                                    break;

                                case "厂级":
                                    roleName = "公司级用户";
                                    roleId   = "aece6d68-ef8a-4eac-a746-e97f0067fab5";
                                    break;

                                case "省级":
                                    roleName = "省级用户";
                                    roleId   = "9a834c93-ff60-440e-845d-79b311eeacae";
                                    break;
                                }
                                roleName += ",普通用户";
                                roleId   += ",2a878044-06e9-4fe4-89f0-ba7bd5a1bde6";
                                UserEntity user = userBll.GetUserByIdCard(per.IdentifyID);
                                if (user == null)
                                {
                                    //    userId = user.UserId;
                                    //}
                                    //else
                                    //{
                                    user         = new UserEntity();
                                    user.UserId  = Guid.NewGuid().ToString();
                                    user.Account = per.IdentifyID;
                                    userId       = user.UserId;
                                    // }

                                    user.MSN            = "1";
                                    user.UserType       = "一般工作人员";
                                    user.EnCode         = per.TraID;
                                    user.Degrees        = user.DegreesID = per.Degrees;
                                    user.Birthday       = per.BirthDay;
                                    user.RoleId         = roleId;
                                    user.RoleName       = roleName;
                                    user.IdentifyID     = per.IdentifyID;
                                    user.Gender         = per.Sex;
                                    user.Nation         = per.Nation;
                                    user.Email          = per.Email;
                                    user.EnterTime      = per.EntranceDate;
                                    user.RealName       = per.PersonName;
                                    user.Degrees        = per.Degrees;
                                    user.Native         = per.Native;
                                    user.DepartureTime  = per.LeaveDate;
                                    user.Telephone      = per.TelPhone;
                                    user.IsPresence     = per.IsOut == "是" ? "0" : "1";
                                    user.Password       = "******";
                                    user.DepartmentId   = dept.DepartmentId;
                                    user.DepartmentCode = dept.EnCode;
                                    user.OrganizeId     = dept.OrganizeId;
                                    user.OrganizeCode   = org.EnCode;
                                    user.Craft          = per.Category;
                                    user.IsEpiboly      = roleName.Contains("承包商") || roleName.Contains("分包商") ? "1" : "0";
                                    if (user.ModifyDate != null)
                                    {
                                        if (per.OperDate > user.ModifyDate)
                                        {
                                            userBll.SaveForm(userId, user);
                                        }
                                    }
                                    else
                                    {
                                        userBll.SaveForm(userId, user);
                                    }
                                }
                            }
                        }
                    }
                }
                Task.Factory.StartNew(() =>
                {
                    string fileName = DateTime.Now.ToString("yyyyMMdd") + ".log";
                    System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("~/logs/") + fileName, string.Format("{0}:同步工具箱人员信息成功\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                });
                return(new { Code = 1, message = "同步工具箱人员信息成功" });
            }
            catch (Exception ex)
            {
                Task.Run(() =>
                {
                    string fileName = DateTime.Now.ToString("yyyyMMdd") + ".log";
                    System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("~/logs/") + fileName, string.Format("{0}:{1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ex.Message));
                });
                return(new { code = 0, message = ex.Message });
            }
        }