Ejemplo n.º 1
0
        private DepartmentResult DepartmentToResult(Department department)
        {
            var departmentResult = new DepartmentResult();

            departmentResult.Id             = department.DepartmentId;
            departmentResult.Name           = department.Name;
            departmentResult.ManagingUserId = department.ManagingUserId;
            departmentResult.AddressId      = department.AddressId;
            departmentResult.DepartmentType = department.DepartmentType;
            departmentResult.TimeZone       = department.TimeZone;
            departmentResult.CreatedOn      = department.CreatedOn;
            departmentResult.UpdatedOn      = department.UpdatedOn;
            departmentResult.Use24HourTime  = department.Use24HourTime;
            departmentResult.AdminUsers     = department.AdminUsers;

            if (department.Members != null && department.Members.Any())
            {
                departmentResult.Members = department.Members.Select(x => x.UserId).ToList();
            }
            else
            {
                departmentResult.Members = new List <string>();
            }

            departmentResult.EmailCode = _departmentSettingsService.GetDispatchEmailForDepartment(department.DepartmentId);

            return(departmentResult);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static DepartmentResult Create(DepartmentEntity model)
        {
            DepartmentResult resul       = new DepartmentResult();
            AccessToken      accessToken = TokenHelp.GetAccessToken();
            string           url         = DingTalkUrlHelp.CreateDepartment(accessToken.Value);

            resul = DingTalkHttpHelp <DepartmentResult> .Post(url, model.ToJson());

            return(resul);
        }
Ejemplo n.º 3
0
        public DepartmentResult GetPage(string filter, int?draw, int?initialPage, int?pageSize, string sortDir, string sortBy)
        {
            using (SATEntities db = new SATEntities())
            {
                var data = db.vw_Department.ToList();

                int recordsTotal = data.Count();

                if (!string.IsNullOrEmpty(filter))
                {
                    data = data.Where(x => x.DivName.Contains(filter) || x.DepName.Contains(filter)).ToList();
                }

                int recordsFiltered = data.Count();

                switch (sortBy)
                {
                case "DivName":
                    data = (sortDir == "asc") ? data.OrderBy(x => x.DivName).ToList() : data.OrderByDescending(x => x.DivName).ToList();
                    break;

                case "DepName":
                    data = (sortDir == "asc") ? data.OrderBy(x => x.DepName).ToList() : data.OrderByDescending(x => x.DepName).ToList();
                    break;

                case "Status":
                    data = (sortDir == "asc") ? data.OrderBy(x => x.DepStatus).ToList() : data.OrderByDescending(x => x.DepStatus).ToList();
                    break;
                }

                int start  = initialPage.HasValue ? (int)initialPage / (int)pageSize : 0;
                int length = pageSize ?? 10;

                var list = data.Select((s, i) => new DepartmentViewModel()
                {
                    RowNumber = i + 1,
                    DepID     = s.DepID,
                    DepName   = s.DepName,
                    DivID     = s.DivID,
                    DivName   = s.DivName,
                    DepStatus = (bool)s.DepStatus,
                    Status    = s.DepStatus == true ? EnumType.StatusName.Active : EnumType.StatusName.NotActive
                }).Skip(start * length).Take(length).ToList();


                DepartmentResult result = new DepartmentResult();
                result.draw            = draw ?? 0;
                result.recordsTotal    = recordsTotal;
                result.recordsFiltered = recordsFiltered;
                result.data            = list;

                return(result);
            }
        }
        private Department CreateOrUpdateDepartment(DepartmentResult departmentResult, Department department = null)
        {
            if (department == null)
            {
                department = new Department();
            }

            department.DepartmentCode  = departmentResult.DepartmentCode;
            department.SmgDepartmentId = departmentResult.Id;
            department.Name            = departmentResult.Name;

            return(department);
        }
Ejemplo n.º 5
0
        private async Task SaveDepartment()
        {
            var depInsert = new Department();

            depInsert.CompanyId = Login.CompanyId;
            depInsert.Code      = txtDepartmentCode.Text;
            depInsert.Name      = txtDepartmentName.Text.Trim();

            if (txtStaffCode.Text != "")
            {
                depInsert.StaffId = StaffID;
            }
            else
            {
                depInsert.StaffId = null;
            }

            depInsert.Note     = txtNote.Text.Trim();
            depInsert.UpdateBy = Login.UserId;
            depInsert.UpdateAt = DateTime.Now;
            depInsert.CreateBy = Login.UserId;
            depInsert.CreateAt = DateTime.Now;
            depInsert.Id       = DepartmentId;

            DepartmentResult  result = null;
            List <Department> list   = null;
            await ServiceProxyFactory.LifeTime(async factory =>
            {
                var service = factory.Create <DepartmentMasterClient>();
                result      = await service.SaveAsync(SessionKey, depInsert);
                list        = await GetDepartmentListAsync();
            });

            if (result.ProcessResult.Result)
            {
                DispStatusMessage(MsgInfSaveSuccess);
            }
            else
            {
                ShowWarningDialog(MsgErrSaveError);
            }
            grdDepartment.DataSource = new BindingSource(list, null);
            return;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 部門データ設定取得
        /// </summary>
        private void DisplayDepartmentData()
        {
            ClearStatusMessage();
            if (string.IsNullOrEmpty(txtDepartmentCode.Text))
            {
                return;
            }

            DepartmentResult result = null;
            var task = ServiceProxyFactory.LifeTime(async factory =>
            {
                var service = factory.Create <DepartmentMasterClient>();
                result      = await service.GetByCodeAndStaffAsync(SessionKey, CompanyId, txtDepartmentCode.Text);
            });

            ProgressDialog.Start(ParentForm, task, false, SessionKey);

            if (result.ProcessResult.Result && result.Department != null)
            {
                var department = result.Department;

                txtDepartmentName.Text = department.Name;
                txtStaffCode.Text      = department.StaffCode;
                lblStaffName.Text      = department.StaffName;
                txtNote.Text           = department.Note;
                DepartmentId           = department.Id;
                StaffID = department.StaffId;
                txtDepartmentCode.Enabled = false;
                BaseContext.SetFunction03Enabled(true);
                ClearStatusMessage();
                Modified = false;
            }
            else
            {
                DispStatusMessage(MsgInfSaveNewData, "請求部門");
                Modified     = true;
                DepartmentId = 0;
            }
        }
Ejemplo n.º 7
0
        private static void AddDepartment()
        {
            try
            {
                LogHelper        log   = LogFactory.GetLogger("AddDepartment");
                DepartmentEntity model = new DepartmentEntity();
                model.id               = "123";
                model.name             = "Test 钉钉数据对接测试2";
                model.createDeptGroup  = true;
                model.autoAddUser      = true;
                model.parentid         = "1";
                model.createDeptGroup  = true;
                model.sourceIdentifier = "";
                DepartmentResult Result = DepartmentBll.Create(model);

                if (Result != null)
                {
                    if (Result.errcode == 0)
                    {
                        log.Info("\r\n------------------------------------------------新增部门------------------------------------------------\n\n\r\n部门id为:" + Result.id + "\n");
                        Console.Write("创建成功,ID=" + Result.id);
                    }
                    else
                    {
                        Console.Write(Result.errmsg);
                    }
                }
                else
                {
                    Console.Write("无返回数据");
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
Ejemplo n.º 8
0
        private static void ImputEsbDepartment(string parentid)
        {
            try
            {
                Stopwatch watch = CommonHelper.TimerStart();
                watch = CommonHelper.TimerStart();
                LogHelper log = LogFactory.GetLogger("ImputEsbDepartment");
                List <DepartmentResult> resultList = new List <DepartmentResult>();
                SqlSugarClient          Edb        = new SqlSugarClient(new ConnectionConfig()
                {
                    ConnectionString      = Config.ESBConnectionString,
                    DbType                = DbType.SqlServer,
                    IsAutoCloseConnection = true
                });

                var Departmentlist = Edb.Queryable <V_Effective_Tbiz_DepartmentInfo, V_Effective_Tbiz_DepartmentTreeas>((a, b) => new object[] { JoinType.Inner, a.DepartmentId == b.TreeNode })
                                     .Select
                                     (
                    (a, b) =>
                    new V_Effective_Tbiz_DepartmentInfo
                {
                    DepartmentId = a.DepartmentId,
                    FullName     = a.FullName
                }
                                     ).ToList();

                log.Info("\r\n------------------------------------------------ESB部门数据导入------------------------------------------------\r\n");
                foreach (var item in Departmentlist)
                {
                    DepartmentEntity model = new DepartmentEntity();
                    model.name             = item.FullName;
                    model.createDeptGroup  = true;
                    model.autoAddUser      = true;
                    model.parentid         = parentid;
                    model.createDeptGroup  = true;
                    model.sourceIdentifier = item.DepartmentId;
                    DepartmentResult result = DepartmentBll.Create(model);
                    //将ESB中的id和名称存入到钉钉同步数据库中
                    result.ESB_DepartmentID   = item.DepartmentId;
                    result.ESB_DepartmentName = item.FullName;

                    if (result != null)
                    {
                        if (result.errcode == 0)
                        {
                            string json = result.id;

                            log.Debug("\n部门id为:" + result.id + "\n");
                            resultList.Add(result);
                            Console.Write("成功:" + json + "\n 已插入:" + (Convert.ToInt32(Departmentlist.IndexOf(item)) + 1) + "条,当前进度:" + (Math.Round(Convert.ToDecimal(Convert.ToDouble((Departmentlist.IndexOf(item) + 1)) / Convert.ToDouble(Departmentlist.Count)), 2, MidpointRounding.AwayFromZero) * 100) + "%\n\n");
                        }
                        else
                        {
                            Console.Write("\r\n" + result.errmsg + "\r\n");
                        }
                    }
                    else
                    {
                        Console.Write("\r\n无返回数据\r\n");
                    }
                }
                SqlSugarClient Ddb = new SqlSugarClient(new ConnectionConfig()
                {
                    ConnectionString      = Config.DingTalkConnectionString,
                    DbType                = DbType.SqlServer,
                    IsAutoCloseConnection = true,
                    InitKeyType           = InitKeyType.Attribute
                });
                Ddb.CodeFirst.InitTables(typeof(DepartmentResult));
                //删除目前记录的数据,初始化
                Ddb.Deleteable <DepartmentResult>().ExecuteCommand();
                int count = Ddb.Insertable <DepartmentResult>(resultList).ExecuteCommand();
                log.Info("\n钉钉接口对接成功后,插入到本地共:" + count + " 条数据,共耗时:" + CommonHelper.TimerEnd(watch) + "毫秒\n");
                Console.Write("\r\n钉钉接口对接成功后,插入到本地共 " + count + " 条数据,共耗时:" + CommonHelper.TimerEnd(watch) + "毫秒\r\n");
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
Ejemplo n.º 9
0
        private static string GetDingTalkDepartmentId(List <DepartmentResult> DTDepartList, string ESB_DepartmentID)
        {
            DepartmentResult model = DTDepartList.Where(e => e.ESB_DepartmentID == ESB_DepartmentID).FirstOrDefault <DepartmentResult>();

            return(model.id);
        }
        public static void AddEmployee(SqlSugarClient Edb, SqlSugarClient Ddb, V_EmployeeToDingTalk item)
        {
            LogHelper log = LogFactory.GetLogger("AddEmployee");

            try
            {
                EmployeeEntity model           = new EmployeeEntity();
                string         DD_DepartmentId = "1";
                if (!item.ESB_DepartmentId.Equals("1000000001"))
                {
                    try
                    {
                        DepartmentResult DD_DepModel = Ddb.Queryable <DepartmentResult>().With(SqlWith.NoLock).Where(it => it.ESB_DepartmentID.Equals(item.ESB_DepartmentId)).First();
                        if (DD_DepModel == null)
                        {
                            DD_DepartmentId = DepartmentForDingTalkBll.DD_DepartmentIsNullForDingTalk(Edb, Ddb, item.ESB_DepartmentId);
                        }
                        else
                        {
                            DD_DepartmentId = DD_DepModel.id;
                        }
                    }
                    catch
                    {
                        DD_DepartmentId = "1";
                    }
                }

                model.userid     = item.UserId;
                model.name       = item.Name;
                model.department = new List <int>(new int[] { Convert.ToInt32(DD_DepartmentId) });
                model.position   = item.PositionName;
                model.mobile     = item.Mobile;
                model.tel        = item.Telephone;
                model.workPlace  = "";
                model.remark     = "";
                model.email      = item.Email;
                model.jobnumber  = item.UserId;
                model.isSenior   = false;

                string param = model.ToJson();

                EmployeeResult Result = EmployeeBll.Create(param);
                if (Result != null)
                {
                    if (Result.errcode == "0")
                    {
                        //Console.Write("创建成功,UserId=" + Result.userid);
                    }
                    //该外部联系人已存在 ||	手机号码在公司中已存在
                    else if (Result.errcode == "40026" || Result.errcode == "60104")
                    {
                        string res = EmployeeBll.Delete(model.userid).errcode;
                        if (res != "0")
                        {
                            log.Error("\r\n EmployeeForDingTalkBll-AddEmployee() 手机号码在公司中已存在删除时报错,错误编号:" + res);
                        }
                        EmployeeResult Result2 = EmployeeBll.Create(model.ToJson());
                        if (Result2.errcode != "0")
                        {
                            if (Result2.errcode == "40022")
                            {
                                string Deletecode = EmployeeBll.Delete(model.userid).errcode;

                                string Createcode = EmployeeBll.Create(model.ToJson()).errcode;

                                if (Createcode != "0")
                                {
                                    Createcode = EmployeeBll.Create(model.ToJson()).errcode;
                                    if (Createcode != "0" && Createcode != "40021")
                                    {
                                        log.Error("\r\n AddEmployee - 行号507 成功删除员工信息,但是创建员工信息时报错,错误编码如下:" + Createcode);
                                    }
                                }
                                //手机号码在公司中已存在
                                if (Result2.errcode == "60104")
                                {
                                    log.Debug("\r\n EmployeeForDingTalkBll-AddEmployee() 手机号码在公司中已存在 时报错,信息如下" + Result2.errmsg + ",错误编码为:" + Result2.errcode + ", Json参数为:" + param);
                                }
                                else
                                {
                                    log.Error("\r\n EmployeeForDingTalkBll-AddEmployee() 该外部联系人已存在 ||	手机号码在公司中已存在 时报错,信息如下"+ Result2.errmsg + ",错误编码为:" + Result2.errcode + ", Json参数为:" + param);
                                }

                                Task.Factory.StartNew(() =>
                                {
                                    InsertErroUpdateEmployee(Ddb, model.userid, "", item.Mobile, Result.errcode);
                                    if (Deletecode != "0")
                                    {
                                        InsertErroUpdateEmployee(Ddb, model.userid, "", item.Mobile, "新增用户时,删除失败,错误编号:" + Deletecode);
                                    }
                                    if (Createcode != "0")
                                    {
                                        InsertErroUpdateEmployee(Ddb, model.userid, "", item.Mobile, "新增用户时,执行删除后创建失败,错误编号:" + Createcode);
                                    }
                                });
                            }
                        }
                    }
                    else
                    {
                        if (Result.errcode == "60103")
                        {
                            log.Debug("\r\n EmployeeForDingTalkBll-AddEmployee() " + Result.errmsg + ",错误编码为:" + Result.errcode + ",手机号为" + item.Mobile + ",用户id为" + item.UserId + " Json参数为:" + param);
                        }
                        else
                        {
                            log.Error("\r\n EmployeeForDingTalkBll-AddEmployee() " + Result.errmsg + ",错误编码为:" + Result.errcode);
                        }

                        Task.Factory.StartNew(() =>
                        {
                            InsertErroUpdateEmployee(Ddb, model.userid, "", item.Mobile, "新增用户时创建失败,错误编号:" + Result.errcode);
                        });
                    }
                }
                else
                {
                    //Console.Write("无返回数据");
                }
            }
            catch (Exception ex)
            {
                log.Error("\r\n EmployeeForDingTalkBll-AddEmployee() " + ex + "\r\n");
                //Console.Write(ex.Message);
            }
        }
        public static void EmployeeUpdateForDingTalk(SqlSugarClient Edb, SqlSugarClient Ddb, List <V_EmployeeToDingTalk> ESB_EmployeeList)
        {
            LogHelper log = LogFactory.GetLogger("EmployeeUpdateForDingTalk");
            List <V_EmployeeToDingTalk> EmpList = new List <V_EmployeeToDingTalk>();
            //获取ESB中目前已经更新的数据
            List <V_OperationObject> OperationList = Tbiz_OperationTempBll.GetOperationList(Edb, 1, 0);
            //根据ESB操作记录中更新的ID,查出目前的用户信息
            List <V_EmployeeToDingTalk> EmployeeList = ESB_EmployeeList.Where(p => OperationList.Exists(q => q.UserId == p.UserId)).ToList();

            log.Info("\r\n------------------------------------------------根据ESB更新钉钉中的人员信息------------------------------------------------\r\n");

            #region 循环更新到钉钉
            foreach (var item in EmployeeList)
            {
                if (item.Enabled == 1)
                {
                    string EmployeeJson = GetEmployee(item.UserId);
                    //用户ID在钉钉中不存在,即:离职用户重新录用时,应将该用户重新添加进钉钉
                    if (EmployeeJson.Equals("-1"))
                    {
                        AddEmployee(Edb, Ddb, item);
                        EmpList.Add(item);
                        continue;
                    }
                    else
                    {
                        EmployeeEntity   model           = Newtonsoft.Json.JsonConvert.DeserializeObject <EmployeeEntity>(EmployeeJson);
                        string           oldMobile       = model.mobile;
                        string           DD_DepartmentId = "1";
                        DepartmentResult DD_DepModel     = Ddb.Queryable <DepartmentResult>().With(SqlWith.NoLock).Where(it => it.ESB_DepartmentID.Equals(item.ESB_DepartmentId)).First();
                        if (DD_DepModel == null)
                        {
                            try
                            {
                                DD_DepartmentId = DepartmentForDingTalkBll.DD_DepartmentIsNullForDingTalk(Edb, Ddb, item.ESB_DepartmentId);
                            }
                            catch (Exception ex)
                            {
                                DD_DepartmentId = DepartmentForDingTalkBll.DD_DepartmentIsNullForDingTalk(Edb, Ddb, item.ESB_DepartmentId);
                            }
                        }
                        else
                        {
                            DD_DepartmentId = DD_DepModel.id;
                        }
                        model.userid     = item.UserId;
                        model.name       = item.Name;
                        model.department = new List <int>(new int[] { Convert.ToInt32(DD_DepartmentId) });
                        model.position   = item.PositionName;
                        model.mobile     = item.Mobile;
                        model.tel        = item.Telephone;
                        model.email      = item.Email;
                        model.jobnumber  = item.UserId;
                        string param = model.ToJson();

                        Result Result = EmployeeBll.Update(param);
                        if (Result != null)
                        {
                            if (Result.errcode == "0")
                            {
                                EmpList.Add(item);
                                //Console.Write("更新成功," + Result.errmsg);
                            }
                            else
                            {
                                //UserID不存在
                                if (Result.errcode == "60111")
                                {
                                    AddEmployee(Edb, Ddb, item);
                                    EmpList.Add(item);
                                    continue;
                                }
                                //更新手机号出错时
                                else if (Result.errcode == "40022" || Result.errcode == "40021" || Result.errcode == "60104" || Result.errcode == "60121")
                                {
                                    //40021	更换的号码已注册过钉钉,无法使用该号码
                                    //40022 企业中的手机号码和登陆钉钉的手机号码不一致,暂时不支持修改用户信息,可以删除后重新添加
                                    //60104	手机号码在公司中已存在
                                    //60121	找不到该用户

                                    string Deletecode = EmployeeBll.Delete(model.userid).errcode;

                                    string Createcode = EmployeeBll.Create(model.ToJson()).errcode;

                                    if (Createcode != "0")
                                    {
                                        Createcode = EmployeeBll.Create(model.ToJson()).errcode;
                                        if (Createcode != "0" && Createcode != "40021")
                                        {
                                            log.Error("\r\n EmployeeUpdateForDingTalk - 行号135 更新钉钉人员信息时,成功删除员工信息,但是创建员工信息时报错,错误编码如下:" + Createcode + ", 员工编号为:" + model.userid);
                                        }
                                    }

                                    EmpList.Add(item);

                                    Task.Factory.StartNew(() =>
                                    {
                                        InsertErroUpdateEmployee(Ddb, model.userid, oldMobile, item.Mobile, Result.errcode);
                                        if (Deletecode != "0")
                                        {
                                            InsertErroUpdateEmployee(Ddb, model.userid, oldMobile, item.Mobile, "删除失败,错误编号:" + Deletecode);
                                        }
                                        if (Createcode != "0")
                                        {
                                            InsertErroUpdateEmployee(Ddb, model.userid, oldMobile, item.Mobile, "执行删除后创建失败,错误编号:" + Createcode);
                                        }
                                    });

                                    //Console.Write("更新成功\r\n");
                                }
                                else
                                {
                                    //手机号码不合法
                                    if (Result.errcode == "60103")
                                    {
                                        model.mobile = oldMobile;
                                        Result       = EmployeeBll.Update(model.ToJson());
                                        if (Result.errcode == "0")
                                        {
                                            EmpList.Add(item);
                                        }
                                        else
                                        {
                                            log.Error("\r\n EmployeeForDingTalkBll-EmployeeUpdateForDingTalk() 失败后不更新手机号,还是失败,具体信息: " + Result.errmsg + "; UserId=" + item.UserId);
                                        }
                                    }
                                    //部门在钉钉中不存在的时候
                                    else if (Result.errcode == "60003")
                                    {
                                        model.department = new List <int>(new int[] { 1 });

                                        param = model.ToJson();

                                        Result r = EmployeeBll.Update(param);
                                        if (r.errcode == "0")
                                        {
                                            EmpList.Add(item);
                                        }
                                        else if (r.errcode == "40022" || r.errcode == "40021" || r.errcode == "60104" || r.errcode == "60121")
                                        {
                                            //40021	更换的号码已注册过钉钉,无法使用该号码
                                            //40022 企业中的手机号码和登陆钉钉的手机号码不一致,暂时不支持修改用户信息,可以删除后重新添加
                                            //60104	手机号码在公司中已存在
                                            //60121	找不到该用户

                                            string Deletecode = EmployeeBll.Delete(model.userid).errcode;

                                            string Createcode = EmployeeBll.Create(model.ToJson()).errcode;

                                            if (Createcode != "0")
                                            {
                                                Createcode = EmployeeBll.Create(model.ToJson()).errcode;
                                                if (Createcode != "0" && Createcode != "40021")
                                                {
                                                    log.Error("\r\n EmployeeUpdateForDingTalk - 行号199 更新钉钉人员信息时,成功删除员工信息,但是创建员工信息时报错,错误编码如下:" + Createcode);
                                                }
                                            }

                                            EmpList.Add(item);

                                            Task.Factory.StartNew(() =>
                                            {
                                                InsertErroUpdateEmployee(Ddb, model.userid, oldMobile, item.Mobile, r.errcode);
                                                if (Deletecode != "0")
                                                {
                                                    InsertErroUpdateEmployee(Ddb, model.userid, oldMobile, item.Mobile, "删除失败,错误编号:" + Deletecode);
                                                }
                                                if (Createcode != "0")
                                                {
                                                    InsertErroUpdateEmployee(Ddb, model.userid, oldMobile, item.Mobile, "执行删除后创建失败,错误编号:" + Createcode);
                                                }
                                            });

                                            //Console.Write("更新成功\r\n");
                                        }
                                        else
                                        {
                                            log.Debug("\r\n EmployeeForDingTalkBll-EmployeeUpdateForDingTalk() 钉钉中部,部门id=" + DD_DepartmentId + ",已将该人员挂在公司下," + Result.errmsg + "; UserId=" + item.UserId);

                                            Task.Factory.StartNew(() =>
                                            {
                                                InsertErroUpdateEmployee(Ddb, model.userid, oldMobile, item.Mobile, "更新用户时失败,错误编号:" + Result.errcode);
                                            });
                                        }
                                    }
                                    else
                                    {
                                        log.Error("\r\n EmployeeForDingTalkBll-EmployeeUpdateForDingTalk() " + Result.errmsg + "; UserId=" + item.UserId);

                                        Task.Factory.StartNew(() =>
                                        {
                                            InsertErroUpdateEmployee(Ddb, model.userid, oldMobile, item.Mobile, "更新用户时失败,错误编号:" + Result.errcode);
                                        });
                                    }
                                }
                            }
                        }
                        else
                        {
                            //Console.Write("无返回数据");
                        }
                    }
                }
                else
                {
                    Result Result = EmployeeBll.Delete(item.UserId);
                    if (Result != null)
                    {
                        //找不到该用户
                        if (Result.errcode == "0" || Result.errcode == "60121")
                        {
                            EmpList.Add(item);
                            //Console.Write("删除成功," + Result.errmsg + "\r\n");
                        }
                        else
                        {
                            log.Error("\r\n EmployeeForDingTalkBll-EmployeeUpdateForDingTalk() " + Result.errmsg + "; UserId=" + item.UserId);
                            //Console.Write("\r\n" + Result.errmsg + "; UserId=" + item.UserId);
                        }
                    }
                    else
                    {
                        //Console.Write("无返回数据");
                    }
                }
            }
            int d = 0;
            foreach (var item in EmpList)
            {
                d = Edb.Deleteable <Tbiz_OperationTemp>().Where(it => it.ObjectId.Equals(item.UserId)).ExecuteCommand();
            }
            #endregion
        }
        public static void InsertForDingTalk(SqlSugarClient Edb, SqlSugarClient Ddb, List <V_EmployeeToDingTalk> EmpList, V_EmployeeToDingTalk item)
        {
            LogHelper log             = LogFactory.GetLogger("InsertEmployeeForDingTalk");
            string    DD_DepartmentId = "1";

            if (!item.ESB_DepartmentId.Equals("1000000001"))
            {
                DepartmentResult DD_DepModel = Ddb.Queryable <DepartmentResult>().With(SqlWith.NoLock).Where(it => it.ESB_DepartmentID.Equals(item.ESB_DepartmentId)).First();
                if (DD_DepModel == null)
                {
                    DD_DepartmentId = DepartmentForDingTalkBll.DD_DepartmentIsNullForDingTalk(Edb, Ddb, item.ESB_DepartmentId);
                }
                else
                {
                    DD_DepartmentId = DD_DepModel.id;
                }
                try
                {
                    DD_DepartmentId = Ddb.Queryable <DepartmentResult>().With(SqlWith.NoLock).Where(it => it.ESB_DepartmentID.Equals(item.ESB_DepartmentId)).First().id;
                }
                catch (Exception ex)
                {
                    Console.Write("根据ESB_DepartmentId获取对应的钉钉id时报错,该ID为" + item.ESB_DepartmentId + ",错误信息为:" + ex + "\r\n");
                }
            }
            EmployeeEntity model = new EmployeeEntity();

            model.userid     = item.UserId;
            model.name       = item.Name;
            model.department = new List <int>(new int[] { Convert.ToInt32(DD_DepartmentId) });
            model.position   = item.PositionName;
            model.mobile     = item.Mobile;
            model.tel        = item.Telephone;
            model.workPlace  = "";
            model.remark     = "";
            model.email      = item.Email;
            model.jobnumber  = item.UserId;
            model.isSenior   = false;

            string param = model.ToJson();

            EmployeeResult Result = EmployeeBll.Create(param);

            if (Result != null)
            {
                if (Result.errcode == "0")
                {
                    EmpList.Add(item);
                    //Console.Write("创建成功,UserId=" + Result.userid + "\r\n");
                }
                else
                {
                    //UserID在公司中已存在
                    if (Result.errcode == "60102")
                    {
                        string EmployeeJson = GetEmployee(item.UserId);
                        model = Newtonsoft.Json.JsonConvert.DeserializeObject <EmployeeEntity>(EmployeeJson);

                        model.userid     = item.UserId;
                        model.name       = item.Name;
                        model.department = new List <int>(new int[] { Convert.ToInt32(DD_DepartmentId) });
                        model.position   = item.PositionName;
                        model.mobile     = item.Mobile;
                        model.tel        = item.Telephone;
                        model.email      = item.Email;
                        model.jobnumber  = item.UserId;
                        param            = model.ToJson();

                        Result res = EmployeeBll.Update(param);
                        if (res != null)
                        {
                            if (res.errcode == "0")
                            {
                                EmpList.Add(item);
                                //Console.Write("更新成功," + Result.errmsg);
                            }
                            else
                            {
                                log.Error("\r\n EmployeeForDingTalkBll-InsertForDingTalk() " + Result.errmsg + "; UserId=" + item.UserId);
                                //Console.Write("\r\n" + Result.errmsg + "; UserId=" + item.UserId);
                            }
                        }
                        else
                        {
                            //Console.Write("无返回数据");
                        }
                    }
                    else
                    {
                        if (Result.errcode == "60104")
                        {
                            log.Error("\r\n EmployeeForDingTalkBll-InsertForDingTalk() " + Result.errmsg + "; UserId=" + item.UserId);
                        }
                        else if (Result.errcode == "40026")
                        {
                            //该外部联系人已存在
                            AddEmployee(Edb, Ddb, item);
                            EmpList.Add(item);
                        }
                        else
                        {
                            log.Error("\r\n EmployeeForDingTalkBll-InsertForDingTalk() " + Result.errmsg + "; UserId=" + item.UserId);
                        }
                        //Console.Write("\r\n" + Result.errmsg + "; UserId=" + item.UserId);
                    }
                }
            }
            else
            {
                //Console.Write("无返回数据");
            }
        }
Ejemplo n.º 13
0
        public static string FirstInitialize(SqlSugarClient Ddb)
        {
            Ddb.CodeFirst.InitTables(typeof(Tbiz_ExistData));
            Ddb.DbMaintenance.TruncateTable("Tbiz_ExistData");

            //创建一个临时部门,用于存放管理员
            DepartmentEntity Deptmodel = new DepartmentEntity();

            Deptmodel.name             = "TempDepartment";
            Deptmodel.parentid         = "1";
            Deptmodel.sourceIdentifier = "";
            DepartmentResult DepResult    = DepartmentBll.Create(Deptmodel);
            string           TempDDDeptID = DepResult.id;

            //查出所有部门id
            GetDepartmentList DepartmentList = DepartmentBll.GetList();

            if (string.IsNullOrWhiteSpace(TempDDDeptID))
            {
                TempDDDeptID = DepartmentList.department.Where(e => e.name.Equals("TempDepartment")).ToList().FirstOrDefault().id;
            }
            var list = DepartmentList.department.Where(e => !e.id.Equals("1") && !e.id.Equals(TempDDDeptID)).ToList();

            foreach (var item in list)
            {
                //遍历每个id下的所有人员
                GetDepartmentForUserList UserList = DepartmentBll.GetByDepartmentIdForUserInfoList(item.id);
                foreach (var Useritem in UserList.userlist)
                {
                    try
                    {
                        //删除所有人员
                        Result Result = EmployeeBll.Delete(Useritem.userid);
                        //当删除失败时,将该人员转移到临时部门中
                        if (Result.errcode != "0")
                        {
                            Tbiz_ExistData model = new Tbiz_ExistData();
                            model.ObjectId   = Useritem.userid;
                            model.Type       = 1;
                            model.CreateDate = DateTime.Now;
                            Ddb.Insertable <Tbiz_ExistData>(model).ExecuteCommand();

                            string         EmployeeJson = EmployeeForDingTalkBll.GetEmployee(Useritem.userid);
                            EmployeeEntity Emodel       = Newtonsoft.Json.JsonConvert.DeserializeObject <EmployeeEntity>(EmployeeJson);
                            for (int i = 0; i < Emodel.department.Count; i++)
                            {
                                if (!Emodel.department[i].ToString().Equals("1"))
                                {
                                    Emodel.department.Remove(Emodel.department[i]);
                                }
                            }
                            Emodel.department.Add(Convert.ToInt32(TempDDDeptID));

                            string param = Emodel.ToJson();

                            Result uResult = EmployeeBll.Update(param);

                            if (uResult.errcode != "0")
                            {
                                Console.Write("\r\n" + uResult.errmsg + "\r\n");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Write("\r\n InitializeDingTalk-FirstInitialize() " + e + "\r\n");
                        log.Error(e);
                    }
                }
                //最后删除公司下的所有部门
                Result r = DepartmentBll.Delete(item.id);
                if (r.errcode != "0")
                {
                    Tbiz_ExistData model = new Tbiz_ExistData();
                    model.ObjectId   = item.id;
                    model.Type       = 0;
                    model.CreateDate = DateTime.Now;
                    Ddb.Insertable <Tbiz_ExistData>(model).ExecuteCommand();

                    Console.Write("\r\n" + r.errmsg + "\r\n");
                }
                Console.Write("\r\n 当前进度" + Math.Round(Convert.ToDecimal((Convert.ToDecimal(list.IndexOf(item)) / list.Count())), 2, MidpointRounding.AwayFromZero) * 100 + "%");
            }
            return(TempDDDeptID);
        }