package com.kingdee.shr.base.syssetting.app.io.impl.util;
import java.sql.SQLException;
import java.sql.Timestamp;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.List;import java.util.Map;import java.util.regex.Pattern;import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;import com.kingdee.bos.dao.IObjectPK;import com.kingdee.bos.dao.ormapping.ObjectUuidPK;import com.kingdee.bos.util.BOSUuid;import com.kingdee.eas.base.message.util.StringUtil;import com.kingdee.eas.basedata.person.PersonCollection;import com.kingdee.eas.util.app.DbUtil;import com.kingdee.jdbc.rowset.IRowSet;import com.kingdee.util.DateTimeUtils;import com.kingdee.util.StringUtils;/**
* 入职分配离职导入 */public class PersonResignOSDChangeImportCheck extends BizBillBaseImportCheck{ String errorMsg; //变动类型 private List<String> list1=new ArrayList<String>(); private List<String> list2=new ArrayList<String>(); private List<String> list3=new ArrayList<String>(); private List<String> list4=new ArrayList<String>(); private List<String> list5=new ArrayList<String>(); public static boolean checkIsVDateRule(String input){ Pattern pattern= Pattern.compile("((((19|20)\\d{2})-(0?(1|[3-9])|1[012])-(0?[1-9]|[12]\\d|30))|(((19|20)\\d{2})-(0?[13578]|1[02])-31)|(((19|20)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$"); return pattern.matcher(input).find(); } public static boolean checkSameDay(String d1,Date d2){ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); try { return DateTimeUtils.dayEquals(sdf.parse(d1),d2); } catch (ParseException e) { e.printStackTrace(); } return false; } public static Timestamp effect(String d){ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Timestamp ts = null; try { ts = new Timestamp(sdf.parse(d+" 00:00:00").getTime()); } catch (ParseException e) { e.printStackTrace(); } return ts; } /** * 一个变动操作 对应多个变动类型,查变动操作对应的 变动类型 * @throws SQLException * @throws BOSException */ public void doha(Context ctx) throws SQLException, BOSException{ StringBuffer sql=new StringBuffer(); sql.append(" select hrbizdefine.FNAME_L2 hrbizn,aar.FNAME_l2 aarn") .append(" from T_HR_HRBIZDEFCHANGEREASON hrea ") .append(" left join T_HR_HRBizDefine hrbizdefine on hrbizdefine.FID=hrea.FHRBIZDEFINEID ") .append(" left join T_HR_AffairActionReason aar on aar.FID =hrea.FACTIONREASONID "); IRowSet rs=DbUtil.executeQuery(ctx,sql.toString()); while(rs.next()){ if(rs.getString("hrbizn").equals("辞退")){ list1.add(rs.getString(2)); }else if(rs.getString("hrbizn").equals("辞职")){ list2.add(rs.getString(2)); }else if(rs.getString("hrbizn").equals("实习终止")){ list3.add(rs.getString(2)); }else if(rs.getString("hrbizn").equals("派遣终止")){ list4.add(rs.getString(2)); }else if(rs.getString("aarn").equals("临时工终止")){ list5.add(rs.getString(2)); } } } /** * 一个变动操作对应变动原因 * @param ctx * @throws BOSException * @throws SQLException */ public List<String> dohv(Context ctx,String hrBizDefine) throws BOSException, SQLException{ List<String> list=new ArrayList<String>(); //查变动操作对应的 变动原因 StringBuffer sql=new StringBuffer(); sql.append(" select v.FID,v.fname_l2 变动原因,v.FNUMBER 变动原因编码,dr.fid drId,dr.FNAME_l2 离职原因,dr.FNUMBER 变动原因编码 ") .append(" from T_HR_VariationReason v ") .append(" INNER JOIN T_HR_VariationReason v1 on v.FPARENTID=v1.fid ") .append(" left join T_HR_BDDIMISSIONREASON dr on v.FNUMBER = dr.FNUMBER "); if(hrBizDefine.equals("辞退")){ sql.append(" where v1.FNAME_l2='辞退原因' "); }else if(hrBizDefine.equals("辞职")){ sql.append(" where v1.FNAME_l2='辞职原因' "); } IRowSet rs=DbUtil.executeQuery(ctx,sql.toString()); while (rs.next()) { list.add(rs.getString(5)); } return list; } /** * 校验员工 */ @Override public String checkPerson(Context ctx, Map<String, String> validMap) throws BOSException { this.errorMsg = ""; String empNumber = (String) validMap.get("empNumber"); String empName = (String) validMap.get("empName"); int size = 0; if (StringUtils.isEmpty(empName)) { this.errorMsg = "人员姓名不能为空!"; return this.errorMsg; } PersonCollection pCol = getPersonInfoSize(ctx, empName, empNumber,null, null); if (pCol != null) { size = pCol.size(); } if (StringUtils.isEmpty(empNumber)) { if (size == 0) { this.errorMsg = "此在职人员不存在!"; return this.errorMsg; } if (size > 1) { this.errorMsg = "系统存在重名人员,请输入对应人员编码!"; return this.errorMsg; } } else if (size == 0) { this.errorMsg = "人员姓名和编码不匹配,请检查!"; return this.errorMsg; } /** * 员工当前最新的主要任职的企业任职经历的变动操作必须是“入职”或者“录用分配”, 若不是,则不允许导入,错误报告提示:“该员工非入职或分配当日离职,请由系统标准的离职功能进行操作。” */ IObjectPK personPK=getPid(empNumber, empName, ctx); IRowSet rs2 = getEmpOrgRelationTop1(ctx,personPK); String action=""; //select * from T_BD_EmployeeModle where fid ='CMqmxPRiSsmVY5/df9JXA2JCmZ4=' String forbidden="";//用户关系状态的用户状态,只不过这里是用工关系状态的 try { if(rs2.next()){ //变动操作 action=rs2.getString("action"); //用户状态 forbidden=rs2.getString("forbidden"); } } catch (SQLException e) { e.printStackTrace(); this.errorMsg="查询员工最新企业任职经历变动操作时发生错误"; return this.errorMsg; } if(!action.equals("入职")&&!action.equals("录用分配")){ this.errorMsg="编号为:"+empNumber+"的员工非入职或分配当日离职,请由系统标准的离职功能进行操作。"; return this.errorMsg; } /** * 1.将员工用工关系状态与员工原员工用工关系状态去比较 * * 2.填写的员工当前的用工关系状态对应的用户状态不能是“禁用”状态,若是,则不允许导入, 错误报告提示:“该员工当前状态不能进行离职操作。 */ String empType="";//用工关系状态 //用工关系状态校验 IRowSet empTypeRs=getEmpOrgRelationTop1(ctx, getPid(validMap.get("empNumber").toString(),validMap.get("empName").toString(),ctx)); try { if(empTypeRs.next()){ empType=empTypeRs.getString("empType"); } } catch (SQLException e) { e.printStackTrace(); } if(forbidden.equals("禁用")){ this.errorMsg="编号为:"+empNumber+"的员工当前状态不能进行离职操作。"; return this.errorMsg; } if(empType.equals("正式员工")){ if(!validMap.get("hrBizDefine").equals("辞退")&&!validMap.get("hrBizDefine").equals("辞职")){ errorMsg = " 员工当前的用工关系状态为正式员工,不能进行这种变动操作!"; return this.errorMsg; } }else if(empType.equals("实习员工")){ if(!validMap.get("hrBizDefine").equals("实习终止")){ errorMsg = " 员工当前的用工关系状态为实习员工,不能进行这种变动操作!"; return this.errorMsg; } }else if(empType.equals("劳务派遣工")){ if(!validMap.get("hrBizDefine").equals("派遣终止")){ errorMsg = " 员工当前的用工关系状态为劳务派遣工,不能进行这种变动操作!"; return this.errorMsg; } }else if(empType.equals("短期工")){ if(!validMap.get("hrBizDefine").equals("临时工终止")){ errorMsg = " 员工当前的用工关系状态为短期工,不能进行这种变动操作!"; return this.errorMsg; } } /** * 填写的离职日期必须与员工当前最新的主要任职的企业任职经历的开始日期是同一天,若不是,则不允许导入, 错误报告提示:“该员工非入职或分配当日离职,请由系统标准的离职功能进行操作。” */ if(StringUtil.isEmpty(validMap.get("bizDate").toString())){ this.errorMsg="离职时间不应为空。"; return this.errorMsg; }else{ //validMap.get("bizDate") excel填写的离职日期、 if(!checkIsVDateRule(validMap.get("bizDate").toString())){ this.errorMsg="离职日期应为YYYY-MM-DD格式。"; return this.errorMsg; } if(!checkSameDay(validMap.get("bizDate").toString(),getEnterDate(ctx, personPK))){ this.errorMsg="编号为:"+empNumber+"的员工非入职或分配当日离职,请由系统标准的离职功能进行操作。"; return this.errorMsg; } } return this.errorMsg; }@Override
public String checkActionReasonAndVariation(Context ctx,Map<String, String> validMap) throws BOSException { String errorMsg = ""; String operate = (String) validMap.get("hrBizDefine");//变动操作 String cellActionType = (String) validMap.get("affairActionReason");//变动类型 String cellVarReason = (String) validMap.get("variationReason");//变动原因 if(StringUtil.isEmpty(operate)){ this.errorMsg="变动操作不能为空!"; return this.errorMsg; } if(StringUtil.isEmpty(cellActionType)){ this.errorMsg="变动类型不能为空!"; return this.errorMsg; } if(StringUtil.isEmpty(cellVarReason)){ this.errorMsg="变动原因不能为空"; return this.errorMsg; } List<String> list11=null; try { doha(ctx); list11=dohv(ctx,operate); } catch (SQLException e) { return e.getMessage(); } if(!list11.contains(cellVarReason)){ this.errorMsg=operate+"与变动原因"+cellVarReason+"不匹配"; return this.errorMsg; } if(operate.equals("辞退")){ if(!list1.contains(cellActionType)){ this.errorMsg=operate+"对应的变动类型"+cellActionType+"不匹配,请检查!"; return this.errorMsg; } }else if(operate.equals("辞职")){ if(!list2.contains(cellActionType)){ this.errorMsg=operate+"对应的变动类型"+cellActionType+"不匹配,请检查!"; return this.errorMsg; } }else if(operate.equals("实习终止")){ if(!list3.contains(cellActionType)){ this.errorMsg=operate+"对应的变动类型"+cellActionType+"不匹配,请检查!"; return this.errorMsg; } }else if(operate.equals("派遣终止")){ if(!list4.contains(cellActionType)){ this.errorMsg=operate+"对应的变动类型"+cellActionType+"不匹配,请检查!"; return this.errorMsg; } }else if(operate.equals("临时工终止")){ if(!list5.contains(cellActionType)){ this.errorMsg=operate+"对应的变动类型"+cellActionType+"不匹配,请检查!"; return this.errorMsg; } }else{ this.errorMsg="变动操作有误!"; return this.errorMsg; } return this.errorMsg; }public String checkEmpType(Context ctx,Map<String, String> validMap) throws BOSException {
String errorMsg = ""; //用工关系状态 //原先用工关系状态是什么,就按照对应的离职单的操作做员工当天离职; //原先正式员工-离职员工 //原先实习-实习终止 //原先劳务派遣-派遣终止 //原先临时工-短期工终止 //但是这里的看员工在t_hr_emporgrelation这里看最新的数据,是入职的或者录用分配的才作当天离职; if(StringUtil.isEmpty(validMap.get("empType").toString())){ errorMsg="目标用工状态不应为空。"; return errorMsg; }else{ if(validMap.get("empType").equals("离职员工")){ if(!validMap.get("hrBizDefine").equals("辞退")&&!validMap.get("hrBizDefine").equals("辞职")){ errorMsg="离职员工应对应变动操作为辞退或辞职!"; return errorMsg; } }else if(validMap.get("empType").equals("实习终止")){ if(!validMap.get("hrBizDefine").equals("实习终止")){ errorMsg="实习终止对应变动操作为实习终止!"; return errorMsg; } }else if(validMap.get("empType").equals("派遣终止")){ if(!validMap.get("hrBizDefine").equals("派遣终止")){ errorMsg="派遣终止对应变动操作为派遣终止!"; return errorMsg; } }else if(validMap.get("empType").equals("短期工终止")){ if(!validMap.get("hrBizDefine").equals("临时工终止")){ errorMsg="短期工终止对应变动操作为临时工终止!"; return errorMsg; } }else{ errorMsg="目标用工状态有误!"; return errorMsg; } } return errorMsg; } public static IObjectPK getPid(String number,String name,Context ctx){ String sql="select fid from t_bd_person where fnumber='"+number+"' and fname_l2='"+name+"'"; IRowSet rs=null; IObjectPK pid=null; try { rs = DbUtil.executeQuery(ctx,sql); if(rs.next()){ pid=new ObjectUuidPK(BOSUuid.read(String.valueOf(rs.getString(1)))); } } catch (Exception e) { e.printStackTrace(); } return pid; } public static IRowSet getEmpOrgRelationTop1(Context ctx, IObjectPK personPK) throws BOSException { StringBuffer sql=new StringBuffer(); sql.append(" SELECT top 1 eor.fpersonid,eor.FEFFDT bizDate,eor.flastUpdateTime lastupdatetime,action.FNAME_L2 action,empType.FNAME_l2 empType, ") .append(" case empType.FUSERSTATE when 1 then '启用' when 2 then '禁用' else '其他'end as forbidden ") .append(" FROM t_hr_emporgrelation eor ") .append(" left join T_BD_PERSON person on person.FID =eor.fpersonid ") .append(" left join T_HR_HRBizDefine action on eor.FACTIONID=action.fid ") .append(" left join T_HR_EmpLaborRelation elr on elr.FID =eor.FLABORRELATIONID ") .append(" left join T_HR_BDEmployeeType empType on empType.FID=elr.FLABORRELATIONSTATEID ") .append(" where eor.FPERSONID ='").append(personPK).append("'") .append(" order by lastupdatetime desc "); IRowSet rs=DbUtil.executeQuery(ctx,sql.toString()); return rs; } //入职时间 public static Date getEnterDate(Context ctx, IObjectPK personPK){ String sql="SELECT FENTERDATE FROM T_HR_PERSONPOSITION where FPERSONID='"+personPK.toString()+"' "; Date enterdate = null; try { IRowSet rs=DbUtil.executeQuery(ctx,sql.toString()); enterdate = null; if(rs.next()){ enterdate=rs.getDate("FENTERDATE"); } } catch (Exception e) { e.printStackTrace(); } return enterdate; }}