我的问题是这样的,客户的组织架构是集团化运作,他们需要共用同一套系统,各个分公司只能看到自己的单据,而集团可以看到所有子公司的单,请问数据库该如何设计,还有就是过滤条件是不是每个地方都需要加,有没有更简洁的方式?2.还有一个问题就是子公司下假如还有办事处怎么处理,也就是说子公司可以看到他自己的单据还有其下属办事处的单,办事处多个如何处理?想了就头大,还望大家指点一二。

解决方案 »

  1.   

    ID    部门名称      父部门ID
    1     XX公司           0
    2   XX公司YY子公司     1
    3   某某部门            2
    4   XX公司ZZ子公司     1
      

  2.   


    表ta存储的是组织机构信息,也可以当做权限控制表
    create table ta(id int,parentID int ,code varchar(50))
    insert ta values(1,0,'00')
    insert ta values(2,1,'0001')
    insert ta values(3,2,'000001')
    假设tb存储的是信息select * from tb a join ta b on 连接条件
    where b.code like(select code from ta where id = @id)+'%'
      

  3.   

    階級权限过滤数據,給個思路:建立個權限表與資料表關聯,用不同的ID(11029,11021...代表集團、單位、部門設計等) select * from wko_epmc where wko_planner in (11029)
    依次類推,寫權限代碼(用權限代碼控制打開程序瀏覽不民的資料內容等
      

  4.   


    declare @table table (序号 int,部门 varchar(20),部门编号 varchar(20))
    insert into @table
    select 1,'总部','aaa' union all
    select 2,'第一分公司','aaa111' union all
    select 3,'第二分公司','aaa222' union all
    select 4,'第三分公司','aaa333' union all
    select 5,'办事处1','aaa111001' union all
    select 6,'办事处1','aaa222001' union all
    select 7,'办事处1','aaa333001' union all
    select 8,'办事处2','aaa111002' union all
    select 9,'办事处2','aaa222002' union all
    select 10,'办事处2','aaa333002'union all
    select 11,'办事处3','aaa111003'
    select * from @table
    /*
    序号          部门                   部门编号
    ----------- -------------------- --------------------
    1           总部                    aaa
    2           第一分公司              aaa111
    3           第二分公司              aaa222
    4           第三分公司              aaa333
    5           办事处1                 aaa111001
    6           办事处1                 aaa222001
    7           办事处1                 aaa333001
    8           办事处2                 aaa111002
    9           办事处2                 aaa222002
    10          办事处2                 aaa333002
    11          办事处3                 aaa111003(11 row(s) affected)
    */--如果是某部门登陆,按其部门编号进行模糊查询就行
    declare @t varchar(20)
    set @t='第一分公司'
    select @t=部门编号 from @table where 部门=@t
    select * from @table where 部门编号 like @t +'%'
    /*
    序号          部门                   部门编号
    ----------- -------------------- --------------------
    2           第一分公司              aaa111
    5           办事处1                 aaa111001
    8           办事处2                 aaa111002
    11          办事处3                 aaa111003(4 row(s) affected)
    */