324e3b45759f5dabcadfacd90a8976aa2d33de46.svn-base 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. package com.kingdee.eas.custom.facade.worktime;
  2. import java.sql.SQLException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.HashSet;
  7. import java.util.Map;
  8. import java.util.Set;
  9. import org.apache.log4j.Logger;
  10. import com.kingdee.bos.BOSException;
  11. import com.kingdee.bos.Context;
  12. import com.kingdee.eas.common.EASBizException;
  13. import com.kingdee.eas.custom.utils.SendUtils;
  14. import com.kingdee.eas.mobile.BOSMsgTypeEnum;
  15. import com.kingdee.eas.mobile.MimeTypeEnum;
  16. import com.kingdee.eas.mobile.PriorityEnum;
  17. import com.kingdee.eas.util.app.DbUtil;
  18. import com.kingdee.jdbc.rowset.IRowSet;
  19. import com.kingdee.shr.base.syssetting.context.SHRContext;
  20. /**
  21. * 所有待审批单据的当前审批人状态为离职则提醒
  22. *
  23. * @author ISSUSER
  24. *
  25. */
  26. public class DepartStatusFacadeControllerBean extends AbstractDepartStatusFacadeControllerBean {
  27. private static Logger logger = Logger
  28. .getLogger("com.kingdee.eas.custom.facade.worktime.DepartStatusFacadeControllerBean");
  29. @Override
  30. protected void _departStatus(Context ctx) throws BOSException {
  31. String title = "Notification of Approver Resignation";
  32. // 邮件内容
  33. String content = getContent(ctx);
  34. try {
  35. // 收件人
  36. IRowSet recipientRowSet = getRecipient(ctx);
  37. while (recipientRowSet.next()) {
  38. // SendUtils.msgSend(ctx, title, PriorityEnum.HIGHT_VALUE, false, content,
  39. // "1CV1Xix+Qua9UEeo/uZ6TIDvfe0=",
  40. // BOSMsgTypeEnum.V_TYPE_EMAIL, null, null, MimeTypeEnum.HTML);
  41. SendUtils.msgSend(ctx, title, PriorityEnum.HIGHT_VALUE, false, content,
  42. recipientRowSet.getString("FPSERSONID"), BOSMsgTypeEnum.V_TYPE_EMAIL, null, null,
  43. MimeTypeEnum.HTML);
  44. }
  45. } catch (SQLException e) {
  46. // TODO 自动生成的 catch 块
  47. e.printStackTrace();
  48. } catch (EASBizException e) {
  49. // TODO 自动生成的 catch 块
  50. e.printStackTrace();
  51. }
  52. }
  53. /**
  54. * 查询所有单据的审批人 是离职状态的
  55. */
  56. public IRowSet getApproved(Context ctx) {
  57. // 获取当前日期
  58. Date nowDate = new Date();
  59. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  60. String strDate = sdf.format(nowDate);
  61. // 查询所有单据的审批人并且是离职状态的
  62. StringBuffer approvedSql = new StringBuffer();
  63. approvedSql.append(
  64. "SELECT c.fid as personid,c.fnumber as personnumber,c.fname_l1 as name FROM T_HR_EmpLaborRelationHis a left join T_HR_BDEmployeeType b on a.FLaborRelationStateID=b.fid left join t_bd_person c on a.FPersonID=c.fid");
  65. approvedSql
  66. .append(" where b.FinService in('2') and a.FPersonID in (SELECT FPERSONEMPID FROM T_WFR_Assign) and ");
  67. approvedSql.append("a.FStartDateTime <= '" + strDate + "'");
  68. approvedSql.append(" and FEndDateTime>='" + strDate + "'");
  69. IRowSet rs = null;
  70. try {
  71. rs = DbUtil.executeQuery(ctx, approvedSql.toString());
  72. } catch (BOSException e) {
  73. e.printStackTrace();
  74. }
  75. return rs;
  76. }
  77. /**
  78. * 统计审批人是离职的 单据条数
  79. */
  80. public Map<String, String> getCountBill(Context ctx) {
  81. // 用set统计处离职的人员
  82. Set<String> departSet = new HashSet();
  83. // 存储审批人id和统计数
  84. Map<String, String> approvedMap = new HashMap();
  85. IRowSet approvedRowSet = getApproved(ctx);
  86. try {
  87. while (approvedRowSet.next()) {
  88. departSet.add(approvedRowSet.getString("personid"));
  89. }
  90. // 审批人是离职的 单据条数
  91. StringBuffer countBillSql = new StringBuffer();
  92. countBillSql.append("SELECT count(*) as count, FPERSONEMPID FROM T_WFR_Assign ");
  93. if (!departSet.isEmpty()) {
  94. countBillSql.append(" where FPERSONEMPID in (");
  95. for (String depart : departSet) {
  96. countBillSql.append("'");
  97. countBillSql.append(depart);
  98. countBillSql.append("'");
  99. countBillSql.append(",");
  100. }
  101. // 删除最后一个逗号
  102. countBillSql.deleteCharAt(countBillSql.length() - 1);
  103. countBillSql.append(")");
  104. }
  105. countBillSql.append(" group by FPERSONEMPID");
  106. IRowSet countRowSet = DbUtil.executeQuery(ctx, countBillSql.toString());
  107. while (countRowSet.next()) {
  108. approvedMap.put(countRowSet.getString("FPERSONEMPID"), countRowSet.getString("count"));
  109. }
  110. } catch (SQLException | BOSException e) {
  111. // TODO 自动生成的 catch 块
  112. e.printStackTrace();
  113. }
  114. return approvedMap;
  115. }
  116. /**
  117. * 查询角色107的人员id 收件人
  118. */
  119. public IRowSet getRecipient(Context ctx) {
  120. String sql = "SELECT a.FPSERSONID FROM T_WFR_PERSONROLE a left join T_WFR_WFROLE b on a.FROLEID=b.fid where b.FNUMBER='107'";
  121. IRowSet reRowSet = null;
  122. try {
  123. reRowSet = DbUtil.executeQuery(ctx, sql);
  124. } catch (BOSException e) {
  125. // TODO 自动生成的 catch 块
  126. e.printStackTrace();
  127. }
  128. return reRowSet;
  129. }
  130. /**
  131. * 拼接内容
  132. */
  133. public String getContent(Context ctx) {
  134. StringBuffer content = new StringBuffer();
  135. content.append("<html><head></head><body>");
  136. content.append("<span>Dear HR and IT:</span><br>");
  137. content.append("<span></span><br>");
  138. content.append(
  139. "<span>The following employees are inactive in HR system but there are still some workflows waiting for their approval.</span><br>");
  140. content.append("<span></span><br>");
  141. content.append(
  142. "<span>If the person will be rehired soon, you can ignore this message.After the rehire is finished, the workflow will be normal.</span><br>");
  143. content.append("<span></span><br>");
  144. content.append(
  145. "<span>If the person will not be rehired soon, you need to identify the new approver and notify the system administrator to manually assign the workflow to the new approver.</span><br>");
  146. content.append("<span></span><br>");
  147. content.append(
  148. "<table border=\'1\' cellspacing=\'0\' style=\'border:solid 1px #E8F2F9;font-size=8px;;font-size:10px;\'>");
  149. content.append(
  150. "<tr style=\'background-color: #428BCA; color:#ffffff\'><th>Person Number</th><th>Name</th><th>Document quantity</th></tr>");
  151. IRowSet approvedRowSet = getApproved(ctx);
  152. Map<String, String> countBillMap = getCountBill(ctx);
  153. try {
  154. approvedRowSet.beforeFirst();
  155. while (approvedRowSet.next()) {
  156. String personId = approvedRowSet.getString("personid");
  157. // 如果人员id在map里面就拼接
  158. if (countBillMap.containsKey(personId)) {
  159. content.append("<tr>");
  160. content.append("<td>" + approvedRowSet.getString("personnumber") + "</td>"); // 第一列
  161. content.append("<td>" + approvedRowSet.getString("name") + "</td>"); // 第二列
  162. content.append("<td>" + countBillMap.get(personId) + "</td>"); // 三列
  163. content.append("</tr>");
  164. countBillMap.remove(personId);
  165. }
  166. }
  167. content.append("</body></html>");
  168. } catch (SQLException e) {
  169. // TODO 自动生成的 catch 块
  170. e.printStackTrace();
  171. }
  172. return content.toString();
  173. }
  174. }