EmployeeUtil.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.kingdee.shr.affair.web.handler.util;
  2. import java.sql.SQLException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import org.apache.commons.lang3.StringUtils;
  6. import com.kingdee.bos.BOSException;
  7. import com.kingdee.bos.Context;
  8. import com.kingdee.eas.util.app.DbUtil;
  9. import com.kingdee.jdbc.rowset.IRowSet;
  10. import com.kingdee.shr.base.syssetting.app.io.fileImport.ImportException;
  11. import com.kingdee.shr.base.syssetting.context.SHRContext;
  12. public class EmployeeUtil {
  13. /**
  14. * 获取当前最大的员工编码
  15. * @return
  16. * @throws BOSException
  17. * @throws SQLException
  18. */
  19. public int getFnumber() throws BOSException, SQLException{
  20. int fnumber = 0;
  21. String fnumberSql = "SELECT max(a.number) as number FROM ( \n" +
  22. " SELECT max(fnumber) as number FROM T_bd_person \n" +
  23. " union \n" +
  24. " SELECT max(CFEmpNumber) as number FROM T_HR_PreEntry \n" +
  25. " union \n" +
  26. " select max(b.fempNumber) as number from T_HR_EmpEnrollBizBill as a ,\n" +
  27. " T_HR_EmpEnrollBizBillEntry as b where a.fid = b.FBILLID \n" +
  28. " ) a";
  29. Context ctx = SHRContext.getInstance().getContext();
  30. IRowSet rs = DbUtil.executeQuery(ctx, fnumberSql);
  31. while(rs.next()){
  32. fnumber = rs.getInt("number");
  33. fnumber = Integer.valueOf(fnumber) + 1;
  34. }
  35. return fnumber;
  36. }
  37. /**
  38. * 用户名唯一校验
  39. * @param userName
  40. * @param fid 非本单据ID校验
  41. * @return
  42. * @throws BOSException
  43. * @throws SQLException
  44. */
  45. public Boolean checkUserName(String userName,String fid,String fnumber) throws BOSException, SQLException{
  46. StringBuffer userNameSql = new StringBuffer();
  47. userNameSql.append("select * from ( ");
  48. userNameSql.append("select fid,fnumber from t_bd_person where Upper(CFUserName) = Upper('" + userName + "')");
  49. userNameSql.append(" union ");
  50. userNameSql.append(" select fid,null from T_HR_PreEntry where Upper(CFUserName_l1) = Upper('" + userName + "') ");
  51. userNameSql.append(" ) a where 1 = 1 ");
  52. if(StringUtils.isNotBlank(fid)){
  53. userNameSql.append(" and fid != '" + fid + "'");
  54. }
  55. if(StringUtils.isNotBlank(fnumber)){
  56. userNameSql.append(" and fnumber != '" + fnumber + "'");
  57. }
  58. System.out.print("用户名唯一校验:"+userNameSql.toString());
  59. Context ctx = SHRContext.getInstance().getContext();
  60. IRowSet rs = DbUtil.executeQuery(ctx, userNameSql.toString());
  61. if(rs.next()){
  62. return false;
  63. }
  64. return true;
  65. }
  66. /**
  67. * 再入职判断ְ
  68. * @param idCard
  69. * @param name
  70. * @param birthday
  71. * @return
  72. * @throws SQLException
  73. * @throws BOSException
  74. */
  75. public void checkIsReEntry(String idCard,String name ,Date birthday) throws SQLException, BOSException{
  76. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  77. String personBirthday = sdf.format(birthday);
  78. String checkSql = "select FIDCardNO,FPASSPORTNO from t_bd_person" +
  79. " where FIDCardNO = '" + idCard + "' " +
  80. " or (to_char(FBirthday,'yyyy-MM-dd') = '" + personBirthday + "' and UPPER(FName_L1) = UPPER('"+ name +"') ) ";
  81. Context ctx = SHRContext.getInstance().getContext();
  82. System.out.println("再入职校验sql" + checkSql);
  83. IRowSet rs = DbUtil.executeQuery(ctx, checkSql);
  84. if(rs.next()){
  85. if(StringUtils.isNotBlank(rs.getString("FIDCardNO"))){
  86. throw new ImportException("Employee is re-entry employee, ID number:" + rs.getString("FIDCardNO"));
  87. }
  88. if(StringUtils.isNotBlank(rs.getString("FPASSPORTNO"))){
  89. throw new ImportException("Employee is re-entry employee, passport number:" + rs.getString("FPASSPORTNO"));
  90. }
  91. }
  92. }
  93. /**
  94. * 工作邮箱唯一校验
  95. * @param email
  96. * @param fid
  97. * @param fnumber
  98. * @return
  99. * @throws BOSException
  100. * @throws SQLException
  101. */
  102. public Boolean checkEmail(String email,String fid,String fnumber) throws BOSException, SQLException{
  103. StringBuffer emailSql = new StringBuffer();
  104. emailSql.append("select * from ( ");
  105. emailSql.append("select fid,fnumber from t_bd_person where Upper(FEMail) = Upper('" + email + "')");
  106. emailSql.append(" union ");
  107. emailSql.append(" select fid,null from T_HR_PreEntry where Upper(CFWorkemail) = Upper('" + email + "') ");
  108. emailSql.append(" ) a where 1 = 1 ");
  109. if(StringUtils.isNotBlank(fid)){
  110. emailSql.append(" and fid != '" + fid + "'");
  111. }
  112. if(StringUtils.isNotBlank(fnumber)){
  113. emailSql.append(" and fnumber != '" + fnumber + "'");
  114. }
  115. Context ctx = SHRContext.getInstance().getContext();
  116. System.out.println("工作邮箱唯一校验:" + emailSql);
  117. IRowSet rs = DbUtil.executeQuery(ctx, emailSql.toString());
  118. if(rs.next()){
  119. return false;
  120. }
  121. return true;
  122. }
  123. }