FillSignCardBatchNewEditHandlerEx.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.kingdee.shr.customer.gtiit.handler;
  2. import java.sql.SQLException;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.HashSet;
  7. import java.util.Locale;
  8. import java.util.Map;
  9. import java.util.Set;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import org.apache.log4j.Logger;
  13. import com.kingdee.bos.BOSException;
  14. import com.kingdee.bos.Context;
  15. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  16. import com.kingdee.eas.common.EASBizException;
  17. import com.kingdee.eas.framework.CoreBaseInfo;
  18. import com.kingdee.eas.hr.ats.FillSignCardEntryCollection;
  19. import com.kingdee.eas.hr.ats.FillSignCardInfo;
  20. import com.kingdee.eas.hr.ats.FillSignReasonFactory;
  21. import com.kingdee.eas.hr.ats.FillSignReasonInfo;
  22. import com.kingdee.eas.util.app.DbUtil;
  23. import com.kingdee.jdbc.rowset.IRowSet;
  24. import com.kingdee.shr.ats.web.handler.FillSignCardBatchNewEditHandler;
  25. import com.kingdee.shr.base.syssetting.context.SHRContext;
  26. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  27. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  28. import com.kingdee.shr.customer.gtiit.util.BaseUtil;
  29. public class FillSignCardBatchNewEditHandlerEx extends FillSignCardBatchNewEditHandler{
  30. private static Logger logger =
  31. Logger.getLogger("com.kingdee.shr.customer.gtiit.handler.FillSignCardBatchNewEditHandlerEx");
  32. @Override
  33. protected void verifyModel(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
  34. throws SHRWebException {
  35. logger.error("进入多人补签卡校验");
  36. Context ctx = SHRContext.getInstance().getContext();
  37. FillSignCardInfo fillSignCardInfo = (FillSignCardInfo) model;
  38. FillSignCardEntryCollection entries = fillSignCardInfo.getEntries();
  39. Set<String> personIdSet = new HashSet<>();
  40. Map<String, Integer> personMap = new HashMap<>();
  41. for(int i=0;i<entries.size();i++) {
  42. String personId = entries.get(i).getPerson().getId().toString();
  43. Date attendDate = entries.get(i).getAttendDate();
  44. Calendar calendar = Calendar.getInstance();
  45. calendar.setTime(attendDate);
  46. String month = calendar.get(Calendar.MONTH)+1 >9?String.valueOf(calendar.get(Calendar.MONTH)+1):"0"+String.valueOf(calendar.get(Calendar.MONTH)+1);
  47. String mapKey = personId+calendar.get(Calendar.YEAR)+month;
  48. personIdSet.add(personId);
  49. FillSignReasonInfo fillSignReasonInfo = null;
  50. try {
  51. fillSignReasonInfo = FillSignReasonFactory.getLocalInstance(ctx).getFillSignReasonInfo(new ObjectUuidPK(entries.get(i).getReason().getId().toString()));
  52. } catch (EASBizException e) {
  53. e.printStackTrace();
  54. } catch (BOSException e) {
  55. e.printStackTrace();
  56. }
  57. if(fillSignReasonInfo!=null && "001".equals(fillSignReasonInfo.getNumber())) {
  58. if(personMap.containsKey(mapKey)) {
  59. personMap.put(mapKey, personMap.get(mapKey)+1);
  60. }else {
  61. personMap.put(mapKey, 1);
  62. }
  63. }
  64. }
  65. Map<String, String> personNameMap = BaseUtil.getPersonIdByName(ctx, personIdSet);
  66. logger.error("人员ID集合:"+personIdSet);
  67. logger.error("补卡信息集合:"+personMap);
  68. StringBuffer str = new StringBuffer();
  69. for(String personId:personIdSet) {
  70. str.append("'"+personId+"',");
  71. }
  72. if(str.length()>0) {
  73. String sql = "SELECT b.FPERSONID,count(1) count,year(b.FATTENDDATE) year ,month(b.FATTENDDATE) month FROM T_HR_ATS_FillSignCard a left join T_HR_ATS_FillSignCardEntry b on a.fid=b.fbillid left join T_HR_ATS_FillSignReason c on c.fid=b.freasonid "
  74. + "where c.FNUMBER = '001' and a.FBILLSTATE in ('2','3') and b.FPERSONID in ("+str.substring(0, str.length()-1)+") group by b.FPERSONID,year(b.FATTENDDATE),month(b.FATTENDDATE) ";
  75. logger.error("查询补签信息SQL:"+sql);
  76. try {
  77. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  78. while(rowSet.next()) {
  79. int count = rowSet.getInt("count");
  80. String personId = rowSet.getString("FPERSONID");
  81. String month = rowSet.getString("month").length()>1?rowSet.getString("month"):"0"+rowSet.getString("month");
  82. String mapKey = personId + rowSet.getString("year") + month;
  83. if(personMap.containsKey(mapKey)) {
  84. personMap.put(mapKey, personMap.get(mapKey)==null?0:personMap.get(mapKey)+count);
  85. }
  86. }
  87. } catch (BOSException e) {
  88. e.printStackTrace();
  89. } catch (SQLException e) {
  90. e.printStackTrace();
  91. }
  92. }
  93. logger.error("人员ID集合:"+personIdSet);
  94. logger.error("人员编码映射:"+personNameMap);
  95. logger.error("补卡信息集合:"+personMap);
  96. for(String key:personMap.keySet()) {
  97. if(personMap.get(key) > 3) {
  98. String period = key.substring(key.length()-6);
  99. String personId = key.substring(0,key.length()-6);
  100. String personName = personNameMap.get(personId);
  101. throw new ShrWebBizException("Employee ("+personName+") forgot to clock in more than three times during the period ("+period+")");
  102. }
  103. }
  104. super.verifyModel(request, response, model);
  105. }
  106. }