-- 创建经理门店基础信息视图（精简版）
-- 只包含必要的基础数据，不包含生命线设置

DROP VIEW IF EXISTS v_manager_store_basic;

CREATE VIEW v_manager_store_basic AS
SELECT 
    u.F_Id AS manager_user_id, -- 使用正确的用户ID字段
    u.F_RealName AS manager_name,
    u.F_GW AS manager_position,
    u.F_OrganizeId AS manager_organize_id,
    org.F_Id AS business_unit_id,
    org.F_FullName AS business_unit_name,
    org.F_ParentId AS parent_organize_id,
    parent_org.F_FullName AS parent_organize_name,
    md.F_Id AS store_id,
    md.mdbm AS store_code,
    md.dm AS store_name,
    md.syb AS store_business_unit_id
FROM BASE_USER u
INNER JOIN BASE_ORGANIZE org ON u.F_OrganizeId = org.F_Id
INNER JOIN BASE_ORGANIZE parent_org ON org.F_ParentId = parent_org.F_Id
INNER JOIN lq_mdxx md ON md.syb = org.F_Id
WHERE u.F_EnabledMark = 1 
    AND u.F_DeleteMark IS NULL
    AND org.F_EnabledMark = 1 
    AND org.F_DeleteMark IS NULL
    AND parent_org.F_EnabledMark = 1 
    AND parent_org.F_DeleteMark IS NULL
    AND (u.F_GW LIKE '%经理%' OR u.F_GW LIKE '%总经理%')
    AND parent_org.F_FullName = '事业部';