技术宅,fat-man

增加语言的了解程度可以避免写出愚蠢的代码

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

重构代码

复制代码
function sync_dept_delete($dept_info, $sir_domain, $dept_id = 0){
    // 查出域名对应的id
    if($dept_id == 0 || $dept_id == ""){
        $dept_id = Check_Address_Sort_Menu_Import($sir_domain);
    }
    echo "dept_id is $dept_id\n";

    // 删除员工
    $member_arr = $dept_info["members"];
    if(count($member_arr) > 0){
        for($i = 0; $i < count($member_arr); $i++){
            $loginname = $member_arr[$i];//用户名
            $email = strtolower(trim($loginname . "@" . $sir_domain));
            remove_employee($email, $dept_id, $sir_domain);
        }
        return true;
    }

    // 删除子部门
    $sub_dept_infos = $dept_info["subdepts"];
    if(count($sub_dept_infos) > 0){
        $sub_dept_name = $sub_dept_infos[0]["name"];
        $sub_dept_id = Get_Address_Sort_Menu_Import_Dept($sub_dept_name, $dept_id);

        if(sync_dept_delete( $sub_dept_infos[0], $sir_domain, $sub_dept_id)){
            return true;
        }
    }

    // 不能删除名为全体人员的部门,它是特殊部门
    $dept_name = $dept_info["name"];
    if($dept_name != "全体人员"){
        remove_dept($dept_id, $dept_name, $sir_domain);
        return true;
    }

    echo "the directory $dept_name can not remove \n";
    return false;
}

function remove_employee($email, $dept_id, $sir_domain){
    global $obj_db;
    echo "remove employee $email\n";

    $query = "select id from user where uid='$email'";
    $rs = $obj_db->simplequery($query);
    $num = $obj_db->numrows($rs);

    if($num > 0){
        $row = $obj_db->fetchrow($rs, $fetchmode = DB_FETCHMODE_ASSOC);
        $id = $row["id"];
        Operate_Manage_User("delete", $id);
    }


    Operate_Address_Tree( $dept_id,  "", $email,  "", "", $sir_domain, "delete");
    // Operate_Address_Tree($it_id,$name,$email,$tel,$dept,$User_Domain,$operate_type)
    // "delete from address_tree where it_id='$it_id' and email='$email';"
}

function remove_dept($dept_id, $dept_name, $sir_domain){
    echo "remove dept $dept_id\n";
    Operate_Address_Item_Tree($dept_id, $dept_name, $sir_domain, "delete");
}
复制代码

 

posted on   codestyle  阅读(358)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
历史上的今天:
2014-04-10 objective-C: nonatomic retain copy assgin 等属性详解
2014-04-10 Objective-C 入门(给新人的)
2013-04-10 Linux下log4shell的安装和使用
2012-04-10 代码的持续改进
点击右上角即可分享
微信分享提示