IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_depart_shpmodify]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_depart_shpmodify]
GO

-- 生成时间:2018-08-02 07:57:53 by ebs-core  
CREATE  procedure mps_depart_shpmodify(
@dpid bigint, 
@cmpid int,
@branchid int,
@userdpid int,
@useruid int,
@userotid int, 
@dp_bcid int,
@dp_code varchar(30),
@dp_innercode varchar(20),
@dp_depart nvarchar(100),
@dp_fullname nvarchar(200),
@dp_order int,
@dp_level int,
@dp_dpstdid int,
@dp_fdpid int,
@dp_ffdpid int,
@dp_foreign int,
@dp_display nvarchar(200),
@dp_hassub int,
@dp_salebudget int,
@dp_feebudget int,
@dp_phone varchar(30),
@dp_province nvarchar(50),
@dp_municipal nvarchar(50),
@dp_county nvarchar(50),
@dp_location nvarchar(100),
@dp_note nvarchar(500),
@dp_etnum int,
@dp_plnum int,
@dp_category1 nvarchar(50),
@dp_category2 nvarchar(50),
@dp_category3 nvarchar(50),
@dp_longitude decimal(18,9),
@dp_latitude decimal(18,9),
@dp_opentime nvarchar(100),
@dp_news nvarchar(200),
@dp_status nvarchar(50),
@dp_key varchar(100),
@dp_isdepart int,
@dp_managearea nvarchar(50),
@dp_manager1 nvarchar(50),
@dp_mcuid1 int,
@dp_manager2 nvarchar(50),
@dp_mcuid2 int,
@dp_manager3 nvarchar(50),
@dp_mcuid3 int,
@dp_manager4 nvarchar(50),
@dp_mcuid4 int,
@dp_manager5 nvarchar(50),
@dp_mcuid5 int,
@dp_manager6 nvarchar(50),
@dp_mcuid6 int,
@dp_manager7 nvarchar(50),
@dp_mcuid7 int,
@dp_manager8 nvarchar(50),
@dp_mcuid8 int,
@dp_manager9 nvarchar(50),
@dp_mcuid9 int,
@dp_manager10 nvarchar(50),
@dp_mcuid10 int,
@dp_use int,
@dp_mcuid int,
@dp_manager nvarchar(50),
@dp_dingid int,
@dp_dingbcid int,
@dp_fffdpid int,
@dp_ext1 varchar(255),
@dp_ext2 varchar(255),
@dp_ext3 varchar(255),
@dp_ext4 varchar(MAX),
@dp_num1 decimal(18,2),
@dp_num2 decimal(18,2),
@dp_num3 decimal(18,2) ) 
as  
begin  
set nocount on  
declare @nonedate datetime 
set @nonedate = CONVERT(datetime,'1910-1-1')
 declare @operation varchar(50)
declare @errorinfo nvarchar(4000) 
 set @operation = 'continue' 
set @errorinfo = '' 
if (dbo.mps_sys_checkkeywords('shp.check',@cmpid,0,'','')=0)
begin
exec mps_depart_shpcheck @cmpid,@branchid,@userdpid,@useruid,@userotid,@dpid,@operation output,@errorinfo output
if @operation = 'abort'
begin
select @operation operation, @errorinfo errorinfo
return 
end
end

declare @existcode int,@exbcid int
if @dp_code != '_none_'
begin
select @exbcid = dp_bcid from mps_depart where dp_id = @dpid
select @existcode = count(*) from mps_depart  where dp_cmpid = @cmpid and dp_code = @dp_code and dp_id != @dpid
if @existcode>0
begin
select 'error' error,'此公司已存在门店编号：'+@dp_code as errorinfo
return 
end
end

 --- 以下是预处理事件中的临时表
 update mps_depart set 
dp_bcid=case when @dp_bcid is null or @dp_bcid = -999999999  then dp_bcid else @dp_bcid end,dp_code=case when @dp_code is null or @dp_code = '_none_'  then dp_code else @dp_code end,dp_innercode=case when @dp_innercode is null or @dp_innercode = '_none_'  then dp_innercode else @dp_innercode end,dp_depart=case when @dp_depart is null or @dp_depart = '_none_'  then dp_depart else @dp_depart end,dp_fullname=case when @dp_fullname is null or @dp_fullname = '_none_'  then dp_fullname else @dp_fullname end,dp_order=case when @dp_order is null or @dp_order = -999999999  then dp_order else @dp_order end,dp_level=case when @dp_level is null or @dp_level = -999999999  then dp_level else @dp_level end,dp_dpstdid=case when @dp_dpstdid is null or @dp_dpstdid = -999999999  then dp_dpstdid else @dp_dpstdid end,dp_fdpid=case when @dp_fdpid is null or @dp_fdpid = -999999999  then dp_fdpid else @dp_fdpid end,dp_ffdpid=case when @dp_ffdpid is null or @dp_ffdpid = -999999999  then dp_ffdpid else @dp_ffdpid end,dp_foreign=case when @dp_foreign is null or @dp_foreign = -999999999  then dp_foreign else @dp_foreign end,dp_display=case when @dp_display is null or @dp_display = '_none_'  then dp_display else @dp_display end,dp_hassub=case when @dp_hassub is null or @dp_hassub = -999999999  then dp_hassub else @dp_hassub end,dp_salebudget=case when @dp_salebudget is null or @dp_salebudget = -999999999  then dp_salebudget else @dp_salebudget end,dp_feebudget=case when @dp_feebudget is null or @dp_feebudget = -999999999  then dp_feebudget else @dp_feebudget end,dp_phone=case when @dp_phone is null or @dp_phone = '_none_'  then dp_phone else @dp_phone end,dp_province=case when @dp_province is null or @dp_province = '_none_'  then dp_province else @dp_province end,dp_municipal=case when @dp_municipal is null or @dp_municipal = '_none_'  then dp_municipal else @dp_municipal end,dp_county=case when @dp_county is null or @dp_county = '_none_'  then dp_county else @dp_county end,dp_location=case when @dp_location is null or @dp_location = '_none_'  then dp_location else @dp_location end,dp_note=case when @dp_note is null or @dp_note = '_none_'  then dp_note else @dp_note end,dp_etnum=case when @dp_etnum is null or @dp_etnum = -999999999  then dp_etnum else @dp_etnum end,dp_plnum=case when @dp_plnum is null or @dp_plnum = -999999999  then dp_plnum else @dp_plnum end,dp_category1=case when @dp_category1 is null or @dp_category1 = '_none_'  then dp_category1 else @dp_category1 end,dp_category2=case when @dp_category2 is null or @dp_category2 = '_none_'  then dp_category2 else @dp_category2 end,dp_category3=case when @dp_category3 is null or @dp_category3 = '_none_'  then dp_category3 else @dp_category3 end,dp_longitude=case when @dp_longitude is null or @dp_longitude = -999999999  then dp_longitude else @dp_longitude end,dp_latitude=case when @dp_latitude is null or @dp_latitude = -999999999  then dp_latitude else @dp_latitude end,dp_opentime=case when @dp_opentime is null or @dp_opentime = '_none_'  then dp_opentime else @dp_opentime end,dp_news=case when @dp_news is null or @dp_news = '_none_'  then dp_news else @dp_news end,dp_status=case when @dp_status is null or @dp_status = '_none_'  then dp_status else @dp_status end,dp_key=case when @dp_key is null or @dp_key = '_none_'  then dp_key else @dp_key end,dp_isdepart=case when @dp_isdepart is null or @dp_isdepart = -999999999  then dp_isdepart else @dp_isdepart end,dp_managearea=case when @dp_managearea is null or @dp_managearea = '_none_'  then dp_managearea else @dp_managearea end,dp_manager1=case when @dp_manager1 is null or @dp_manager1 = '_none_'  then dp_manager1 else @dp_manager1 end,dp_mcuid1=case when @dp_mcuid1 is null or @dp_mcuid1 = -999999999  then dp_mcuid1 else @dp_mcuid1 end,dp_manager2=case when @dp_manager2 is null or @dp_manager2 = '_none_'  then dp_manager2 else @dp_manager2 end,dp_mcuid2=case when @dp_mcuid2 is null or @dp_mcuid2 = -999999999  then dp_mcuid2 else @dp_mcuid2 end,dp_manager3=case when @dp_manager3 is null or @dp_manager3 = '_none_'  then dp_manager3 else @dp_manager3 end,dp_mcuid3=case when @dp_mcuid3 is null or @dp_mcuid3 = -999999999  then dp_mcuid3 else @dp_mcuid3 end,dp_manager4=case when @dp_manager4 is null or @dp_manager4 = '_none_'  then dp_manager4 else @dp_manager4 end,dp_mcuid4=case when @dp_mcuid4 is null or @dp_mcuid4 = -999999999  then dp_mcuid4 else @dp_mcuid4 end,dp_manager5=case when @dp_manager5 is null or @dp_manager5 = '_none_'  then dp_manager5 else @dp_manager5 end,dp_mcuid5=case when @dp_mcuid5 is null or @dp_mcuid5 = -999999999  then dp_mcuid5 else @dp_mcuid5 end,dp_manager6=case when @dp_manager6 is null or @dp_manager6 = '_none_'  then dp_manager6 else @dp_manager6 end,dp_mcuid6=case when @dp_mcuid6 is null or @dp_mcuid6 = -999999999  then dp_mcuid6 else @dp_mcuid6 end,dp_manager7=case when @dp_manager7 is null or @dp_manager7 = '_none_'  then dp_manager7 else @dp_manager7 end,dp_mcuid7=case when @dp_mcuid7 is null or @dp_mcuid7 = -999999999  then dp_mcuid7 else @dp_mcuid7 end,dp_manager8=case when @dp_manager8 is null or @dp_manager8 = '_none_'  then dp_manager8 else @dp_manager8 end,dp_mcuid8=case when @dp_mcuid8 is null or @dp_mcuid8 = -999999999  then dp_mcuid8 else @dp_mcuid8 end,dp_manager9=case when @dp_manager9 is null or @dp_manager9 = '_none_'  then dp_manager9 else @dp_manager9 end,dp_mcuid9=case when @dp_mcuid9 is null or @dp_mcuid9 = -999999999  then dp_mcuid9 else @dp_mcuid9 end,dp_manager10=case when @dp_manager10 is null or @dp_manager10 = '_none_'  then dp_manager10 else @dp_manager10 end,dp_mcuid10=case when @dp_mcuid10 is null or @dp_mcuid10 = -999999999  then dp_mcuid10 else @dp_mcuid10 end,dp_use=case when @dp_use is null or @dp_use = -999999999  then dp_use else @dp_use end,dp_mcuid=case when @dp_mcuid is null or @dp_mcuid = -999999999  then dp_mcuid else @dp_mcuid end,dp_manager=case when @dp_manager is null or @dp_manager = '_none_'  then dp_manager else @dp_manager end,dp_dingid=case when @dp_dingid is null or @dp_dingid = -999999999  then dp_dingid else @dp_dingid end,dp_dingbcid=case when @dp_dingbcid is null or @dp_dingbcid = -999999999  then dp_dingbcid else @dp_dingbcid end,dp_fffdpid=case when @dp_fffdpid is null or @dp_fffdpid = -999999999  then dp_fffdpid else @dp_fffdpid end,dp_ext1=case when @dp_ext1 is null or @dp_ext1 = '_none_'  then dp_ext1 else @dp_ext1 end,dp_ext2=case when @dp_ext2 is null or @dp_ext2 = '_none_'  then dp_ext2 else @dp_ext2 end,dp_ext3=case when @dp_ext3 is null or @dp_ext3 = '_none_'  then dp_ext3 else @dp_ext3 end,dp_ext4=case when @dp_ext4 is null or @dp_ext4 = '_none_'  then dp_ext4 else @dp_ext4 end,dp_num1=case when @dp_num1 is null or @dp_num1 = -999999999  then dp_num1 else @dp_num1 end,dp_num2=case when @dp_num2 is null or @dp_num2 = -999999999  then dp_num2 else @dp_num2 end,dp_num3=case when @dp_num3 is null or @dp_num3 = -999999999  then dp_num3 else @dp_num3 end
where dp_id=@dpid 
 if (@operation='continue') 
 begin
 set @nonedate = @nonedate 
 
 select 'ok' operation, '' errorinfo 
end  else 
begin
select @operation operation, @errorinfo errorinfo  
end


if(@dp_fdpid>0)
begin
delete from mps_depart_title where dt_dpid = @dpid
insert into mps_depart_title(dt_dpid,dt_otid)
select @dpid,dt_otid from mps_depart_title where dt_dpid = @dp_fdpid
end

update mps_depart set dp_fullname = dp_depart,dp_display =  dp_depart
where dp_id = @dpid and dp_depart != ' and dp_isdepart = 1 and dp_fullname = ' 
 
set nocount off 
end