分析云 OA中部门分级思路和实现方法

描述:在客户碰到OA中部门分级有如下情况,部门中人员有挂在非末级部门上,如下图:

 

商务中心是末级部门,**应用事业部为二级部门。由于父子维度要求人员必须挂到末级部门,故使用父子维度无法处理该情况。

 

处理方式:

此时需要将各级部门都作为末级部门进行考虑处理。

将一级部门、二级部门、三级部门分别取出,并通过合并的方式,按照一级部门、二级部门、三级部门分别形成末级部门的形式,进而实现这种业务。

在做抽取的时候,需考虑将OA中人员单据根据人员ID关联人员和部门表,将部门ID抽取到事实表中,然后将事实表中的部门ID跟部门分级的末级部门ID关联,即实现按照人员的部门进行业务数据统计。

具体参考SQL如下:

复制代码
 1 --第三级部门
 2 select 
 3 a.SORT_ID,a.path as path,
 4 c.id as dim_id,cast(c.name as nvarchar(200)) as dim_name,
 5 a.id as dim1_id,cast(a.name as nvarchar(200)) as dim1_name,
 6 b.id as dim2_id,cast(b.name as nvarchar(200)) as dim2_name,
 7 c.id as dim3_id,cast(c.name as nvarchar(200)) as dim3_name 
 8 from 
 9 (select u.path,u.id,u.name,u.type ,u.SORT_ID  from org_unit u 
10 where u.IS_DELETED =0 and u.is_enable= 1 and len(u.path)=12 and u.path like '00000002%') a 
11 left join 
12 (  select u.path,u.id,u.name,u.type,u.SORT_ID   from org_unit u 
13 where u.IS_DELETED =0 and u.is_enable= 1  and len(u.path)=16 and u.path like '00000002%') b 
14 on a.path =left(b.path,12)
15 left join 
16 (  select u.path,u.id,u.name,u.type,u.SORT_ID   from org_unit u 
17 where u.IS_DELETED =0  and u.is_enable= 1 and len(u.path)=20 and u.path like '00000002%') c 
18 on b.path=left(c.path,16)
19 where c.id is not null
20 
21 union all
22     --第二级部门
23 select 
24 b.SORT_ID ,b.path as path, 
25 b.id as dim_id,cast(b.name as nvarchar(200))  as dim_name ,
26 a.id as dim1_id,cast(a.name as nvarchar(200))  as dim1_name,
27 b.id as dim2_id,cast(b.name as nvarchar(200))  as dim2_name,
28 cast('' as int ) as dim3_id,'' as dim3_name
29 from 
30 (select u.path,u.id,u.name,u.type ,u.SORT_ID  from org_unit u 
31 where u.IS_DELETED =0  and u.is_enable= 1 and len(u.path)=12 and u.path like '00000002%') a 
32 left join 
33 (  select u.path,u.id,u.name,u.type,u.SORT_ID   from org_unit u 
34 where u.IS_DELETED =0  and u.is_enable= 1 and len(u.path)=16 and u.path like '00000002%' ) b 
35 on a.path =left(b.path,12)
36 where b.id is not null 
37 
38 union all 
39     --第一级部门
40 select 
41 a.SORT_ID ,a.path as path, 
42 a.id as dim_id,cast(a.name as nvarchar(200)) as dim_name ,
43 a.id as dim1_id,cast(a.name as nvarchar(200)) as dim1_name,
44 cast('' as int ) as dim2_id, '' as dim2_name,
45 cast('' as int ) as dim3_id,'' as dim3_name
46 from 
47 (select u.path,u.id,u.name,u.type,u.SORT_ID   from org_unit u 
48 where u.IS_DELETED =0  and u.is_enable= 1 and len(u.path)=12 and u.path like '00000002%') a  
49 where a.id is not null 
复制代码

 

posted @   NULL66  阅读(235)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示