Beispiel #1
0
        /// <summary>
        /// 将id部门下的人员转到parentid部门下
        /// </summary>
        /// <param name="id"></param>
        /// <param name="parentid"></param>
        private static void DepartmentUserMove(string id, int parentid)
        {
            GetDepartmentList DepartmentList = DepartmentBll.GetList();

            var dddd = DepartmentList.department.Where(e => e.id.Equals(id)).ToList().FirstOrDefault();

            if (dddd != null)
            {
                //钉钉中存在该部门,检查该部门下是否有人,没人的并且重复的部门删除钉钉中该部门,并且删除钉钉关系表和钉钉树关系表
                GetDepartmentForUserList UserList = DepartmentBll.GetByDepartmentIdForUserInfoList(dddd.id);
                Console.Write("\n" + dddd.name + " DD_ID=" + dddd.id + ",其下共有" + UserList.userlist.Count + "个人!\r\n");
                foreach (var Useritem in UserList.userlist)
                {
                    string         EmployeeJson = EmployeeForDingTalkBll.GetEmployee(Useritem.userid);
                    EmployeeEntity Emodel       = JsonHelper.JsonToModel <EmployeeEntity>(EmployeeJson);
                    Emodel.department = new List <int>()
                    {
                        parentid
                    };
                    string param = Emodel.ToJson();

                    Result uResult = EmployeeBll.Update(param);
                    if (uResult.errcode != "0")
                    {
                        Console.Write("\r\n" + uResult.errmsg + "\r\n");
                    }
                }
            }
        }
Beispiel #2
0
        private static void OperationRepeatData3()
        {
            GetDepartmentList DepartmentList = DepartmentBll.GetList();

            string sql  = @"
                            with ta as(
                            select *   from DepartmentResult where ESB_DepartmentID in(
                            select ESB_DepartmentID from DepartmentResult group by ESB_DepartmentID having count(1)>1
                            )
                            ),tb as(
                            select a.* from [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentInfo a inner join [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentTreeas b
                            on a.DepartmentId=b.TreeNode
                            ),tc as(
                            select tb.fullname a,ta.* from ta left join tb 
                            on ta.ESB_DepartmentName=tb.FullName
                            where tb.fullname is null
                            ),td as(
                            select a.* from [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentInfo a inner join tc
                            on tc.ESB_DepartmentId=a.DepartmentId
                            )
                            select distinct td.fullname aa,tc.* from tc right join  td
                            on tc.ESB_DepartmentId=td.DepartmentId
                            order by td.fullname
                        ";
            string sql2 = @"
                            with ta as(
                            select *   from DepartmentResult where ESB_DepartmentID in(
                            select ESB_DepartmentID from DepartmentResult group by ESB_DepartmentID having count(1)>1
                            )
                            ),tb as(
                            select a.* from [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentInfo a inner join [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentTreeas b
                            on a.DepartmentId=b.TreeNode
                            ),tc as(
                            select tb.fullname a,ta.* from ta left join tb 
                            on ta.ESB_DepartmentName=tb.FullName
                            where tb.fullname is null
                            ),td as(
                            select a.* from [PM.WebApi].dbo.V_Effective_Tbiz_DepartmentInfo a inner join tc
                            on tc.ESB_DepartmentId=a.DepartmentId
                            ),te as(
                            select a.* from td inner join DepartmentResult a
                            on td.DepartmentID=a.ESB_DepartmentID and td.FullName=a.ESB_DepartmentName
                            )select '' aa,'' a  ,* from te
                            order by ESB_DepartmentID
                        ";

            SqlSugarClient Ddb = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString      = Config.DingTalkConnectionString,
                DbType                = DbType.SqlServer,
                IsAutoCloseConnection = true,
                InitKeyType           = InitKeyType.Attribute
            });

            List <DepartmentResult> list = Ddb.Ado.SqlQuery <DepartmentResult>(sql);

            List <DepartmentResult> list2 = Ddb.Ado.SqlQuery <DepartmentResult>(sql2);

            foreach (var item in list)
            {
                var dddd = DepartmentList.department.Where(e => e.id.Equals(item.id)).ToList().FirstOrDefault();
                if (dddd != null)
                {
                    //钉钉中存在该部门,检查该部门下是否有人,没人的并且重复的部门删除钉钉中该部门,并且删除钉钉关系表和钉钉树关系表
                    GetDepartmentForUserList UserList = DepartmentBll.GetByDepartmentIdForUserInfoList(dddd.id);
                    Console.Write("\n" + dddd.name + " DD_ID=" + dddd.id + ",其下共有" + UserList.userlist.Count + "个人!\r\n");
                    string id = list2.Where(it => it.ESB_DepartmentID.Equals(item.ESB_DepartmentID)).FirstOrDefault().id;
                    if (UserList.userlist.Count != 0)
                    {
                        //将该部门下的人迁移到正确的部门下
                        foreach (var Useritem in UserList.userlist)
                        {
                            string         EmployeeJson = EmployeeForDingTalkBll.GetEmployee(Useritem.userid);
                            EmployeeEntity Emodel       = JsonHelper.JsonToModel <EmployeeEntity>(EmployeeJson);
                            Emodel.department = new List <int>()
                            {
                                Convert.ToInt32(id)
                            };
                            string param = Emodel.ToJson();

                            Result uResult = EmployeeBll.Update(param);
                            if (uResult.errcode != "0")
                            {
                                Console.Write("\r\n" + uResult.errmsg + "\r\n");
                            }
                        }


                        //删除钉钉中的部门
                        var a = DepartmentBll.Delete(dddd.id);
                        //删除钉钉关系表和钉钉树关系表
                        int i = Ddb.Deleteable <DepartmentResult>().Where(it => it.id.Equals(item.id)).ExecuteCommand();
                        i = Ddb.Deleteable <DepartmentTrees>().Where(it => it.DD_Id.Equals(item.id)).ExecuteCommand();
                    }
                }
            }
            Console.Write("\r\n处理完毕");
        }