IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_update_employee]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_update_employee]
GO
CREATE PROCEDURE [dbo].[mps_update_employee]  
 @cu_id int,  
 @cu_cmpid int,  
 @cu_bcid int,  
 @cu_branch nvarchar(50),  
 @cu_dpid int,  
 @cu_depart nvarchar(50),  
 @cu_fastkey varchar(50),  
 @cu_code varchar(32),  
 @cu_account varchar(32),  
 @cu_star int,  
 @cu_gender int,  
 @cu_security int,  
 @cu_function int,  
 @cu_name nvarchar(50),  
 @cu_mobile varchar(20),  
 @cu_contact nvarchar(100),  
 @cu_nation nvarchar(30),  
 @cu_address nvarchar(100),  
 @cu_post varchar(6),  
 @cu_position nvarchar(30),  
 @cu_qq varchar(20),  
 @cu_identtype nvarchar(10),  
 @cu_identno varchar(18),  
 @cu_email varchar(100),  
 @cu_otid int,  
 @cu_title nvarchar(50),  
 @cu_duty nvarchar(50),  
 @cu_party nvarchar(50),  
 @cu_origin nvarchar(30),  
 @cu_academic nvarchar(30),  
 @cu_height int,  
 @cu_major nvarchar(30),  
 @cu_college nvarchar(50),  
 @cu_graduate datetime,  
 @cu_degrees nvarchar(30),  
 @cu_marriage nvarchar(10),  
 @cu_entrytime datetime,  
 @cu_dimission datetime,  
 @cu_salary int,  
 @cu_status nvarchar(10),  
 @cu_login int,  
 @cu_icon int,  
 @cu_sign int,  
 @cu_birth varchar(10),  
 @cu_use int,  
 @cu_relationshipobj1 bigint ,  
 @cu_managelevel int,  
 @cu_professionlevel int,
 @cu_ccphonenumber varchar(50)
AS  
BEGIN  
 SET NOCOUNT ON;  

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
 declare @nonedate datetime  
 declare @lguid int  
 declare @cu_otlevel int  
 set @nonedate=CONVERT(datetime,'1910-1-1')  
 update mps_employee set  
 cu_cmpid=case when @cu_cmpid is null or @cu_cmpid = -999999999  then cu_cmpid else @cu_cmpid end,  
 cu_bcid=case when @cu_bcid is null or @cu_bcid = -999999999  then cu_bcid else @cu_bcid end,  
 cu_dpid=case when @cu_dpid is null or @cu_dpid = -999999999  then cu_dpid else @cu_dpid end,  
 cu_star=case when @cu_star is null or @cu_star = -999999999  then cu_star else @cu_star end,  
 cu_gender=case when @cu_gender is null or @cu_gender = -999999999  then cu_gender else @cu_gender end,  
 cu_use=case when @cu_use is null or @cu_use = -999999999  then cu_use else @cu_use end,  
 cu_height=case when @cu_height is null or @cu_height = -999999999  then cu_height else @cu_height end,  
 cu_salary=case when @cu_salary is null or @cu_salary = -999999999  then cu_salary else @cu_salary end,  
 cu_login=case when @cu_login is null or @cu_login = -999999999  then cu_login else @cu_login end,  
 cu_icon=case when @cu_icon is null or @cu_icon = -999999999  then cu_icon else @cu_icon end,  
 cu_sign=case when @cu_sign is null or @cu_sign = -999999999  then cu_sign else @cu_sign end,  
 cu_security=case when @cu_security is null or @cu_security = -999999999  then cu_security else @cu_security end,  
 cu_function=case when @cu_function is null or @cu_function = -999999999  then cu_function else @cu_function end,  
 cu_otid=case when @cu_otid is null or @cu_otid = -999999999  then cu_otid else @cu_otid end,  
 cu_graduate=case when @cu_graduate is null or @cu_graduate = @nonedate  then cu_graduate else @cu_graduate end,  
 cu_entrytime=case when @cu_entrytime is null or @cu_entrytime = @nonedate  then cu_entrytime else @cu_entrytime end,  
 cu_dimission=case when @cu_dimission is null or @cu_dimission = @nonedate  then cu_dimission else @cu_dimission end,  
 cu_relationshipobj1=case when @cu_relationshipobj1 is null or @cu_relationshipobj1 = -999999999  then cu_relationshipobj1 else @cu_relationshipobj1 end,  
 cu_fastkey=case when @cu_fastkey is null or @cu_fastkey = '_none_'  then cu_fastkey else @cu_fastkey end,  
 cu_ccphonenumber=case when @cu_ccphonenumber is null or @cu_ccphonenumber = '_none_'  then cu_ccphonenumber else @cu_ccphonenumber end,  
 cu_code=case when @cu_code is null or @cu_code = '_none_'  then cu_code else @cu_code end,  
 cu_account=case when @cu_account is null or @cu_account = '_none_'  then cu_account else @cu_account end,  
 cu_mobile=case when @cu_mobile is null or @cu_mobile = '_none_'  then cu_mobile else @cu_mobile end,  
 cu_post=case when @cu_post is null or @cu_post = '_none_'  then cu_post else @cu_post end,  
 cu_qq=case when @cu_qq is null or @cu_qq = '_none_'  then cu_qq else @cu_qq end,  
 cu_identno=case when @cu_identno is null or @cu_identno = '_none_'  then cu_identno else @cu_identno end,  
 cu_email=case when @cu_email is null or @cu_email = '_none_'  then cu_email else @cu_email end,  
 cu_birth=case when @cu_birth is null or @cu_birth = '_none_'  then cu_birth else @cu_birth end,  
 cu_branch=case when @cu_branch is null or @cu_branch = '_none_'  then cu_branch else @cu_branch end,  
 cu_depart=case when @cu_depart is null or @cu_depart = '_none_'  then cu_depart else @cu_depart end,  
 cu_name=case when @cu_name is null or @cu_name = '_none_'  then cu_name else @cu_name end,  
 cu_contact=case when @cu_contact is null or @cu_contact = '_none_'  then cu_contact else @cu_contact end,  
 cu_nation=case when @cu_nation is null or @cu_nation = '_none_'  then cu_nation else @cu_nation end,  
 cu_address=case when @cu_address is null or @cu_address = '_none_'  then cu_address else @cu_address end,  
 cu_college=case when @cu_college is null or @cu_college = '_none_'  then cu_college else @cu_college end,  
 cu_degrees=case when @cu_degrees is null or @cu_degrees = '_none_'  then cu_degrees else @cu_degrees end,  
 cu_marriage=case when @cu_marriage is null or @cu_marriage = '_none_'  then cu_marriage else @cu_marriage end,  
 cu_status=case when @cu_status is null or @cu_status = '_none_'  then cu_status else @cu_status end,  
 cu_duty=case when @cu_duty is null or @cu_duty = '_none_'  then cu_duty else @cu_duty end,  
 cu_party=case when @cu_party is null or @cu_party = '_none_'  then cu_party else @cu_party end,  
 cu_origin=case when @cu_origin is null or @cu_origin = '_none_'  then cu_origin else @cu_origin end,  
 cu_academic=case when @cu_academic is null or @cu_academic = '_none_'  then cu_academic else @cu_academic end,  
 cu_major=case when @cu_major is null or @cu_major = '_none_'  then cu_major else @cu_major end,  
 cu_position=case when @cu_position is null or @cu_position = '_none_'  then cu_position else @cu_position end,  
 cu_identtype=case when @cu_identtype is null or @cu_identtype = '_none_'  then cu_identtype else @cu_identtype end,  
 cu_title=case when @cu_title is null or @cu_title = '_none_'  then cu_title else @cu_title end,  
 cu_otlevel=case when @cu_otlevel is null or @cu_otlevel = -999999999  then cu_otlevel else @cu_otlevel end,  
 cu_power = case when @cu_function = 4 then 'all' else '' end,
 cu_managelevel=case when @cu_managelevel is null or @cu_managelevel = -999999999  then cu_managelevel else @cu_managelevel end,  
 cu_professionlevel=case when @cu_professionlevel is null or @cu_professionlevel = -999999999  then cu_professionlevel else @cu_professionlevel end  
 where cu_id=@cu_id  
 
if(@cu_otid>0) 
begin
update mps_employee set cu_title = (select top 1 ot_title from mps_title where ot_id = @cu_otid) 
where cu_id = @cu_id
end
--更新mps_login表  
update mps_login
set cu_account = _employee.cu_account,  
    cu_callname = _employee.cu_name,  
    cu_gender = _employee.cu_gender,  
    cu_bcid = _employee.cu_bcid,  
    cu_branch = _employee.cu_branch,  
    cu_dpid = _employee.cu_dpid,  
    cu_depart = _employee.cu_depart,  
    cu_otid = _employee.cu_otid,  
    cu_title = _employee.cu_title,  
    cu_function = _employee.cu_function,  
    cu_mobile = _employee.cu_mobile,  
    cu_otlevel = _employee.cu_otlevel,  
    cu_managelevel = _employee.cu_managelevel,  
    cu_professionlevel = _employee.cu_professionlevel
from mps_employee _employee
where _employee.cu_id=@cu_id
and mps_login.cu_id=@cu_id
--更新mps_login_role表  
update mps_login_role  
set lgu_bcid = _employee.cu_bcid,  
lgu_branch = _employee.cu_branch,  
lgu_dpid = _employee.cu_dpid,  
lgu_depart = _employee.cu_depart,  
lgu_otid = _employee.cu_otid,  
lgu_title = _employee.cu_title,  
lgu_function = _employee.cu_function,  
lgu_name = _employee.cu_name,  
lgu_otlevel = _employee.cu_otlevel,  
lgu_managelevel = _employee.cu_managelevel,  
lgu_professionlevel = _employee.cu_professionlevel
from mps_employee _employee
where lgu_cuid = @cu_id 
and   lgu_defaultrole=0  
and   cu_id = lgu_cuid
-- 更新登录表中的代岗位信息 author:f
exec mps_update_logindeparttitles @cu_id
END