IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_g_category_bizinfo]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_g_category_bizinfo]
GO
CREATE procedure [dbo].[mps_g_category_bizinfo](
@cmpid int,
@useruid int,
@useradmin int ,
@category nvarchar(200) ,
@mobile int =default
)
as
begin
set nocount on 
if (@mobile is null or @mobile=-999999999) set @mobile=1 
declare @biztype varchar(30) 
set @biztype = 'biz_c' 
if (charindex('/',@category)>0) set @biztype='biz_sc' 
select * from mps_template where tmp_cmpid=@cmpid and tmp_type=@biztype and tmp_objid=0 and (tmp_objid2=@useradmin or tmp_objid2=0) and tmp_caption=@category order by tmp_objid2 desc 
-- 获取有之相关的所有业务单信息
declare @c1 nvarchar(100) 
declare @c2 nvarchar(100) 
declare @i int 
set @i = CHARINDEX('/',@category) 
if (@i>0) 
begin
set @c1 = SUBSTRING(@category ,  1 , @i-1) 
set @c2 = SUBSTRING(@category ,  @i+1 , LEN(@category) - @i) 
end else 
begin
set @c1 = @category 
set @c2 = '' 
end 
declare @t table(bizid int , ok int) 
if (@c2='') 
insert into @t(bizid,ok) 
select biz_id ,0
from mps_biztype  
where biz_cmpid=@cmpid and biz_category=@c1 and (biz_hidemenu=1 or biz_hidemenu_mobile=1) 
else 
insert into @t(bizid,ok) 
select biz_id , 0
from mps_biztype  
        where biz_cmpid=@cmpid and biz_category=@c1 and biz_subcategory=@c2 and (biz_hidemenu=1 or biz_hidemenu_mobile=1)
    
    update @t set ok=1 
    from mps_biztype_users 
    where bp_bizid=bizid and bp_cuid=@useruid and 
(bp_type='bizaudit' or bp_type='bizabolish' or bp_type='bizdelete' or bp_type='biznew' or bp_type='bizview' )

declare @t2 table(bizid int , ok int) 
if (@c2='') 
insert into @t2(bizid,ok) 
select pt_id ,0
from mps_programtype  
where pt_cmpid=@cmpid and pt_category=@c1 and (pt_hidemenu=1 or pt_hidemenu_mobile=1) and pt_merge=0
else 
insert into @t2(bizid,ok) 
select pt_id , 0
from mps_programtype  
        where pt_cmpid=@cmpid and pt_category=@c1 and pt_subcategory=@c2 and (pt_hidemenu=1 or pt_hidemenu_mobile=1) and pt_merge=0 and 
        pt_program=0 and pt_system=2 
        
    update @t2 set ok=1 
    from mps_programtype_users 
    where pp_ptid=bizid and pp_cuid=@useruid and 
(pp_type='prgaudit' or pp_type='prgabolish' or pp_type='prgdelete' or pp_type='prgnew' or pp_type='prgview' )

if (@mobile=0)
begin        
select distinct biz_order,biz_id,biz_formstyle,biz_hidemenu,biz_hidemenu_mobile,biz_icon,biz_title,biz_category , biz_subcategory  , 0 biz_comefrom , 0 biz_flag 
from mps_biztype , @t 
where biz_id=bizid and ok=1 and biz_hidemenu_mobile=1
union 
select distinct '' biz_order,pt_id biz_id,
1 biz_formstyle,pt_hidemenu biz_hidemenu,pt_hidemenu_mobile biz_hidemenu_mobile, 
pt_icon biz_icon,pt_caption biz_title,pt_category biz_category , pt_subcategory biz_subcategory  , 
0 biz_comefrom , 1 biz_flag 
from mps_programtype , @t2 
where pt_id=bizid and ok=1  and pt_hidemenu_mobile=1

order by biz_category , biz_subcategory ,biz_order , biz_title 
end else 
if (@mobile=1)
begin        
select distinct biz_order,biz_id,biz_formstyle,biz_hidemenu,biz_hidemenu_mobile,biz_icon,biz_title,biz_category , biz_subcategory  , 0 biz_comefrom , 0 biz_flag 
from mps_biztype , @t 
where biz_id=bizid and ok=1  and biz_hidemenu=1
union 
select distinct '' biz_order,pt_id biz_id,
1 biz_formstyle,pt_hidemenu biz_hidemenu,pt_hidemenu_mobile biz_hidemenu_mobile, 
pt_icon biz_icon,pt_caption biz_title,pt_category biz_category , pt_subcategory biz_subcategory  , 
0 biz_comefrom , 1 biz_flag 
from mps_programtype , @t2 
where pt_id=bizid and ok=1 and pt_hidemenu=1

order by biz_category , biz_subcategory ,biz_order , biz_title 
endelse 
begin        
select distinct biz_order,biz_id,biz_formstyle,biz_hidemenu,biz_hidemenu_mobile,biz_icon,biz_title,biz_category , biz_subcategory  , 0 biz_comefrom , 0 biz_flag 
from mps_biztype , @t 
where biz_id=bizid and ok=1  
union 
select distinct '' biz_order,pt_id biz_id,
1 biz_formstyle,pt_hidemenu biz_hidemenu,pt_hidemenu_mobile biz_hidemenu_mobile, 
pt_icon biz_icon,pt_caption biz_title,pt_category biz_category , pt_subcategory biz_subcategory  , 
0 biz_comefrom , 1 biz_flag 
from mps_programtype , @t2 
where pt_id=bizid and ok=1 

order by biz_category , biz_subcategory ,biz_order , biz_title 
end
set nocount off 
end