部门对于服务人员设置 7.63 KB
参数:
p_dept_no,  0256601011001011
p_service_no   

1:参数为空校验
2:获取部门所在的机构:
select bi.branch_code
    from department_info di ,branch_info bi,branch_code_relation bcr
    where di.dept_no = p_dept_no
    and di.branch_code = bcr.relative_branch_code
    and bcr.branch_code = bi.branch_code
    and bi.branch_level = p_branch_level;

3.判断人员是否在机构下
2.1:判断机构等级:2级分公司和3级机构
select bi.branch_level
        from branch_info bi
       where bi.branch_code = p_branch_code;
2.1.1:如果是2级机构则表明是经代保单,需要对比在同一2级机构下即可
2.1.2:如果是3级机构需要对比是否为同一三级机构
判断是否在同一机构sql:
select bi.branch_code
        from branch_code_relation bcr, branch_info bi
       where bcr.relative_branch_code = p_branch_code
         and bcr.branch_code = bi.branch_code
         and bi.branch_level = p_branch_level
         and bcr.relative_grade < 1;
         
2.2:判断人员类型是否可以进行服务
2.2.1:判断是否为续收人员--查询staff_info表是否存在记录----->查询人员类型,判断是否为续收人员
查询staff_info表信息和department_info表信息




获取成功,当v_department_info.channel_type = '07'  人员为续收人员 -返回 05
如果获取失败:
 SELECT COUNT(DISTINCT si.emp_no)
           FROM staff_info si
          WHERE si.emp_no = p_emp_no
            AND si.emp_no LIKE 'H%';
查询表是否存在该人员,存在则返回05

返回值如果不等于05,则return


2.2.2:查询人员是否为离职或待离职
获取人员状态sql:
 SELECT decode(TRIM(es.emp_status_code),
                    '0501',
                    '01',
                    '0701',
                    '01',
                    '0301',
                    '01',
                    '0601',
                    '01',
                    '0801',
                    '01',
                    '0401',
                    '01',
                    '0201',
                    '01',
                    '0101',
                    '01',
                    '1101',
                    '01',
                    '0400',
                    '02',
                    '0102',
                    '02',
                    '0103',
                    '03',
                    '0403',
                    '04',
                    '0503',
                    '04',
                    '0203',
                    '04',
                    '0303',
                    '04',
                    '0104',
                    '04',
                    '0703',
                    '04',
                    '1103',
                    '04',
                    '0105',
                    '05',
                    '0404',
                    '06',
                    ''),
             si.is_valid
        INTO v_emp_status,
             v_is_valid
        FROM staff_info si,
             emp_status es
       WHERE si.emp_no = p_emp_no
         AND si.emp_status_code = es.emp_status_code;

其中v_is_valid = 'N'  作废也当离职
01-在职 02-休眠 03-待离职 04 -离职 05-培训 06-待入职

返回值为 03,04则直接return  'N'


--DMP-3970 待入职续收人员分单规则调整
  --待入职的,审批不通过的
  if v_emp_status in ('06') then
    select count(*)
      into v_count
      from renewal_staff_change_history rs
     where rs.emp_no = p_emp_no
       and rs.change_type = '01' --入职
       and rs.change_status in ('2', '3');
     if v_count = 0 then
       return('N');
     end if;
  end if;


--判断是否下月离职的人员,下月离职人员不再分单
  v_count := 0;
  select count(*)
    into v_count
    from renewal_staff_change_history rsch
   where rsch.emp_no = p_emp_no
     and rsch.pk_serial =  (select max(rs.pk_serial)
                                  from renewal_staff_change_history rs
                                 where rs.emp_no = p_emp_no
                                   and rs.change_status = '2'
                                   and rs.change_type = '12'
                                   and rs.start_date > sysdate);
   if v_count>0 then
     return('N');
   else
     return('Y');
N:表示不能进行服务,Y表示可以服务

----end

2.3:判断人员类型是否可以服务这个部门

2.3.1:查询岗位:select a.position from staff_info a where a.emp_no = p_emp_no;

    如果有在途的申请岗位,则以申请为准
    select rsch.post_code
        from renewal_staff_change_history rsch
       where rsch.emp_no = p_emp_no
         and rsch.pk_serial =
             (select max(rs.pk_serial)
                from renewal_staff_change_history rs
               where rs.emp_no = p_emp_no
                 and rs.change_status = '2'
                 and rs.change_type = '04' --04 岗位异动
                 and rs.start_date > sysdate);
 2.3.2:查询银代兼收权限        02银代    --------可能不需要校验   
         select a.market_flag, a.bank_flag, a.agent_flag
        from renewal_staff_info_other a
       where a.emp_no = p_emp_no;
       如果有在途申请的权限,则以申请的为准
       select rsch.market_flag, rsch.bank_flag, rsch.agent_flag
        from renewal_staff_change_history rsch
       where rsch.emp_no = p_emp_no
         and rsch.pk_serial =
             (select max(rs.pk_serial)
                from renewal_staff_change_history rs
               where rs.emp_no = p_emp_no
                 and rs.change_status = '2'
                 and (p_priv_flag = '01' and rs.change_type in ('16','04','05') or
                     p_priv_flag = '02' and rs.change_type in ('11','04','05') or
                     p_priv_flag = '03' and rs.change_type in ('13','04','05'))
                 and rs.start_date > sysdate);
                 
                 
                 
       
 p_priv_flag 权限类型,01个险,02银代,03经代
 取银代
 if p_priv_flag = '01' then
      v_other_priv := v_market_flag;
    elsif p_priv_flag = '02' then
      v_other_priv := v_bank_flag;
    elsif p_priv_flag = '03' then
      v_other_priv := v_agent_flag;
    end if;
    
 
 2.3.3:--在职督导,银代督导只能督导,不做服务
   if v_position in ('13','15')  then
      return('N');
   end if;
 2.3.4:个险只能服务个险部门
 select di.dept_type,di.branch_code
     into v_dept_type,v_dept_branch
     from department_info di
    where di.dept_no = p_dept_no;
    
     if v_position in ('12','13','14') and v_dept_type not in ('01','06') then
      return('N');
   end if;
 
 
 
 2.3.5:人员是否和部门在一个三级机构下   ----这个校验上个流程有,只需要调用就可以




2.4:判断这个部门是否已经存在服务人员,如果有,作废原记录

select count(*)
into v_count
from rn_dept_servicer a
where a.dept_no = p_dept_no
and a.is_valid = 'Y';

废除:
 update rn_dept_servicer rds
         set rds.is_valid = 'N'
       where rds.dept_no = p_dept_no
         and rds.is_valid = 'Y';
      
         
         
         

2.5:符合条件则 写入部门对于服务人员表表记录
insert into rn_dept_servicer (DEPT_NO, SERVICE_NO, IS_VALID, PK_SERIAL, FLOW_SEQ, UPDATED_USER, UPDATED_DATE, CREATED_USER, CREATED_DATE)
values ('025660101100101', 'H86360800000002', 'N', '20130000000000000185', '20130000000000000185', 'wu.zou@sino-life.com', to_date('31-03-2014 18:02:16', 'dd-mm-yyyy hh24:mi:ss'), 'liping2.huang@sino-life.com', to_date('19-04-2013 09:57:17', 'dd-mm-yyyy hh24:mi:ss'));




缺失表:renewal_staff_info_other  续收人员附加信息

renewal_staff_change_history  续收人员变更轨迹记录

BANK_STAFF_INFO_OTHER   银代人员信息

EMP_STATUS   人员状态基表