EarlyWarningFacadeControllerBean.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. package com.kingdee.eas.custom.facade;
  2. import java.sql.SQLException;
  3. import java.text.SimpleDateFormat;
  4. import java.time.LocalDate;
  5. import java.time.format.DateTimeFormatter;
  6. import java.util.ArrayList;
  7. import java.util.Calendar;
  8. import java.util.HashMap;
  9. import java.util.HashSet;
  10. import java.util.List;
  11. import java.util.Locale;
  12. import java.util.Map;
  13. import java.util.Set;
  14. import java.util.stream.Collectors;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.apache.log4j.Logger;
  17. import com.kingdee.bos.BOSException;
  18. import com.kingdee.bos.Context;
  19. import com.kingdee.eas.base.param.IParamControl;
  20. import com.kingdee.eas.base.param.ParamControlFactory;
  21. import com.kingdee.eas.common.EASBizException;
  22. import com.kingdee.eas.custom.utils.SendUtils;
  23. import com.kingdee.eas.mobile.BOSMsgTypeEnum;
  24. import com.kingdee.eas.mobile.MimeTypeEnum;
  25. import com.kingdee.eas.mobile.PriorityEnum;
  26. import com.kingdee.eas.util.app.DbUtil;
  27. import com.kingdee.jdbc.rowset.IRowSet;
  28. /**
  29. * 后台任务发送预警消息 个人加班邮件预警
  30. * @author xiaoxin
  31. *
  32. */
  33. public class EarlyWarningFacadeControllerBean extends AbstractEarlyWarningFacadeControllerBean
  34. {
  35. private static Logger logger =
  36. Logger.getLogger("com.kingdee.eas.custom.facade.EarlyWarningFacadeControllerBean");
  37. /**
  38. * 发送提交加班费用申请通知
  39. */
  40. @Override
  41. protected void _overExpenseApply(Context ctx) throws BOSException, EASBizException {
  42. try {
  43. String sql = "SELECT u.fid,emp.jobgradename FROM T_PM_USER u left join T_BD_Person p on u.FPERSONID = p.fid " +
  44. "left join (select gra.fname_l2 jobgradename,e.fpersonid from (SELECT FPERSONID,max(fleffdt) as maxDate FROM T_HR_EmpPostExperienceHis group by FPERSONID) as h " +
  45. "left join T_HR_EmpPostExperienceHis e on e.fpersonid= h.FPERSONID and fleffdt = h.maxDate " +
  46. "left join (SELECT * FROM T_HR_EmpPostRank where fislatest='1') r on r.fpersonid = e.fpersonid " +
  47. "left join T_HR_JobGrade gra on gra.fid=r.fjobgradeid) emp on p.fid=emp.fpersonid "
  48. + "left join T_HR_EmpLaborRelationHis l on l.fpersonid=p.fid "
  49. + "where l.fstartdatetime <= now() and l.fenddatetime >= now()";
  50. logger.error("加班费用申请SQL:"+sql);
  51. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  52. Set<String> userIdSet = new HashSet<String>();
  53. while(rowSet.next()) {
  54. String jobGradeName = rowSet.getString("jobgradename");
  55. if(StringUtils.isNotBlank(jobGradeName)) {
  56. jobGradeName = jobGradeName.replace("L", "");
  57. jobGradeName = jobGradeName.replace("-", ".");
  58. Double gradeLevel = Double.parseDouble(jobGradeName);
  59. //获取职等为1-10的用户ID
  60. if(gradeLevel>=1D && gradeLevel<=16D) {
  61. userIdSet.add(rowSet.getString("fid"));
  62. }
  63. }
  64. }
  65. logger.error("用户ID集合:"+userIdSet.toString());
  66. LocalDate currentDate = LocalDate.now();
  67. // 格式化为英文月份
  68. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM", Locale.ENGLISH);
  69. //获取这个月的英文月份
  70. String thisMonthName = currentDate.format(formatter);
  71. //获取上个月的英文月份
  72. LocalDate previousMonthDate = currentDate.minusMonths(1);
  73. String LastMonthName = previousMonthDate.format(formatter);
  74. IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
  75. String shrEnvironmentIP = ipc.getParamValue(null, "shrEnvironmentIP");
  76. String day = "";
  77. //自助加班时间设置
  78. String baseSql = "select fname_l1 from T_HR_ATS_OverTimeReason where FNUMBER = 'zbjbsj001'";
  79. IRowSet baseRow = DbUtil.executeQuery(ctx, baseSql);
  80. while(baseRow.next()) {
  81. day = baseRow.getString("fname_l1");
  82. }
  83. this.sendEmail(ctx, userIdSet, "reminder of OT application submission", "This is a kind reminder that your "+LastMonthName+" OT application should be submitted via the following link before "+thisMonthName+" "+day+"th. Thanks for your cooperation.\r\n" +
  84. shrEnvironmentIP + "/home.do\r\n" +
  85. "Those who have no OT request please disregard this reminder.\r\n" +
  86. "\r\n" +
  87. "Best regards,\r\n" +
  88. "Human Resources Department");
  89. } catch (Exception e) {
  90. logger.error("发送提交加班费用申请通知失败:"+e.getMessage());
  91. }
  92. }
  93. /**
  94. * 转正审批提醒通知
  95. */
  96. @Override
  97. protected void _becomeWorkApply(Context ctx) throws BOSException, EASBizException {
  98. // String sql = "select s.FPERSONUSERID,r.fsenderid from T_BAS_AssignRead r "
  99. // + "left join T_WFR_Assign s on r.FASSIGNID = s.FASSIGNID "
  100. // + "where r.FBOSTYPE = 'B65CCEF1' and s.FBIZOBJID in "
  101. // + "(SELECT a.fid FROM T_HR_EMPHIREBIZBILL a "
  102. // + "left join T_HR_EMPHIREBIZBILLEntry b on a.fid=b.fbillid "
  103. // + "where now()>= DATEADD(day, -7,b.fbizdate) "
  104. // + "and now()<= b.fbizdate and a.FBILLSTATE = '2')";
  105. //获取转正前一周的审批人和提交人信息
  106. String sql = "select s.FPERSONUSERID,r.fsenderid,u.FNAME_L1 readUserName,s.assignUserName,p.fname_l1 personName,p.fnumber personNumber from T_BAS_AssignRead r \r\n" +
  107. "left join T_PM_User u on r.FSENDERID = u.FID \r\n" +
  108. "left join (SELECT a.*,b.FNAME_L1 assignUserName FROM T_WFR_Assign a left join T_PM_User b on a.FPERSONUSERID = b.FID ) s on r.FASSIGNID = s.FASSIGNID \r\n" +
  109. "left join (SELECT a.fid,b.FPERSONID FROM T_HR_EMPHIREBIZBILL a left join T_HR_EMPHIREBIZBILLEntry b on a.fid=b.fbillid ) emp on emp.fid = s.FBIZOBJID \r\n" +
  110. "left join t_bd_person p on p.fid = emp.fpersonid \r\n" +
  111. "where r.FBOSTYPE = 'B65CCEF1' and s.FBIZOBJID in (SELECT a.fid FROM T_HR_EMPHIREBIZBILL a \r\n" +
  112. " left join T_HR_EMPHIREBIZBILLEntry b on a.fid=b.fbillid \r\n" +
  113. " where now()>= DATEADD(day, -7,b.fbizdate) and now()<= b.fbizdate and a.FBILLSTATE = '2')";
  114. logger.error("获取转正单审批人SQL:"+sql);
  115. try {
  116. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  117. IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
  118. String shrEnvironmentIP = ipc.getParamValue(null, "shrEnvironmentIP");
  119. Set<String> senderSet = new HashSet<String>();
  120. while(rowSet.next()) {
  121. StringBuffer approvalBuffer = new StringBuffer();
  122. approvalBuffer.append("Dear "+rowSet.getString("assignUserName")+",");
  123. approvalBuffer.append("\r\n");
  124. approvalBuffer.append("\r\n");
  125. approvalBuffer.append("This is a kind reminder for approving "+rowSet.getString("personName")+"'s probation workflow in Kingdee system. Could you please login to the system by using below link?");
  126. approvalBuffer.append("\r\n");
  127. approvalBuffer.append("\r\n");
  128. approvalBuffer.append(shrEnvironmentIP + "/home.do");
  129. approvalBuffer.append("\r\n");
  130. approvalBuffer.append("\r\n");
  131. approvalBuffer.append("Please kindly check To-Be-Processed in My Tasks and approve/reject at your earliest convenience. Feel free to let us know if any problem. Many thanks!");
  132. approvalBuffer.append("\r\n");
  133. approvalBuffer.append("\r\n");
  134. approvalBuffer.append("\r\n");
  135. approvalBuffer.append("Best regards,");
  136. approvalBuffer.append("\r\n");
  137. approvalBuffer.append("Human Resources Department");
  138. this.sendEmail(ctx, rowSet.getString("FPERSONUSERID"), "Reminder to probation approval", approvalBuffer.toString());
  139. String senders = rowSet.getString("fsenderid")+rowSet.getString("personNumber");
  140. if(!senderSet.contains(senders)) {
  141. StringBuffer senderBuffer = new StringBuffer();
  142. senderBuffer.append("Dear "+rowSet.getString("readUserName")+",");
  143. senderBuffer.append("\r\n");
  144. senderBuffer.append("\r\n");
  145. senderBuffer.append("This is a kind reminder for approving "+rowSet.getString("personName")+"'s probation workflow in Kingdee system. Could you please login to the system by using below link?");
  146. senderBuffer.append("\r\n");
  147. senderBuffer.append("\r\n");
  148. senderBuffer.append(shrEnvironmentIP + "/home.do");
  149. senderBuffer.append("\r\n");
  150. senderBuffer.append("\r\n");
  151. senderBuffer.append("Please kindly check To-Be-Processed in My Tasks and approve/reject at your earliest convenience. Feel free to let us know if any problem. Many thanks!");
  152. senderBuffer.append("\r\n");
  153. senderBuffer.append("\r\n");
  154. senderBuffer.append("\r\n");
  155. senderBuffer.append("Best regards,");
  156. senderBuffer.append("\r\n");
  157. senderBuffer.append("Human Resources Department");
  158. this.sendEmail(ctx, rowSet.getString("fsenderid"), "Reminder to probation approval", senderBuffer.toString());
  159. }
  160. senderSet.add(senders);
  161. }
  162. } catch (Exception e) {
  163. logger.error("转正审批提醒通知失败:"+e.getMessage());
  164. }
  165. }
  166. @Override
  167. protected void _overAuditApply(Context ctx) throws BOSException, EASBizException {
  168. }
  169. /**
  170. * 考勤异常预警通知
  171. */
  172. @Override
  173. protected void _attendanceAbnormalApply(Context ctx) throws BOSException, EASBizException {
  174. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  175. Calendar calendar = Calendar.getInstance();
  176. String nowDate = sdf.format(calendar.getTime());
  177. calendar.add(Calendar.DAY_OF_MONTH, -1);
  178. String yesterday = sdf.format(calendar.getTime());
  179. //获取当天考勤异常总数
  180. String sql = "SELECT count(1) count FROM (select FPROPOSER from T_HR_ATS_AbnormalAttendance where FAttendanceDate >= '"+yesterday+"' and FAttendanceDate < '"+nowDate+"' and fstatus='1' and foperationstatus='1' group by FPROPOSER)";
  181. logger.error("当天考勤异常人数SQL:"+sql);
  182. try {
  183. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  184. int count = 0;
  185. while(rowSet.next()) {
  186. count = rowSet.getInt("count");
  187. }
  188. IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
  189. String attendThreshold = ipc.getParamValue(null, "attendThreshold");
  190. logger.error("考勤异常阈值:"+attendThreshold);
  191. int threshold = Integer.valueOf(attendThreshold);
  192. if(count <= threshold) {
  193. return;
  194. }
  195. String roleSql = "select c.fid from T_WFR_WFROLE a left join T_WFR_PERSONROLE b on a.fid=b.froleid left join T_PM_USER c on b.FPSERSONID = c.FPERSONID where a.FNUMBER in ('101','102') and c.fid is not null";
  196. logger.error("获取工作流角色对应用户SQL:"+roleSql);
  197. IRowSet roleRow = DbUtil.executeQuery(ctx, roleSql);
  198. Set<String> userIdSet = new HashSet<String>();
  199. while(roleRow.next()) {
  200. userIdSet.add(roleRow.getString("fid"));
  201. }
  202. String shrEnvironmentIP = ipc.getParamValue(null, "shrEnvironmentIP");
  203. logger.error("用户ID集合:"+userIdSet.toString());
  204. String title = "Unusual Attendance Exceptions Reminder "+yesterday;
  205. String content = "Dear HR and IT administrator,\r\n" +
  206. " \r\n" +
  207. "There are "+count+" staff had attendance exception record on "+yesterday+", please log in the system to check the details and handle them as soon as possible if necessary.\r\n" +
  208. " \r\n" +
  209. shrEnvironmentIP+"\r\n" +
  210. " \r\n" +
  211. "GTIIT HR System";
  212. this.sendEmail(ctx, userIdSet, title, content);
  213. } catch (SQLException e) {
  214. e.printStackTrace();
  215. logger.error("考勤异常预警失败:"+e.getMessage());
  216. }
  217. }
  218. /**
  219. * 个人异常考勤(已废弃)
  220. */
  221. @Override
  222. protected void _thatAttendAbnormal(Context ctx) throws BOSException, EASBizException {
  223. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  224. Calendar calendar = Calendar.getInstance();
  225. String nowDate = sdf.format(calendar.getTime());
  226. calendar.add(Calendar.DAY_OF_MONTH, -1);
  227. String yesterday = sdf.format(calendar.getTime());
  228. IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
  229. String shrEnvironmentIP = ipc.getParamValue(null, "shrEnvironmentIP");
  230. String sql = "select b.fid personId,f.fid,a.FATTENDANCEVALUE,j.fname_l1 attendanceName from T_HR_ATS_AbnormalAttendance a "
  231. + "left join T_BD_Person b on a.FPROPOSER = b.fid "
  232. + "left join (select c.fpersonid,d.CFWorkercategoryID from (SELECT FPERSONID,max(FlEFFDT) as maxDate FROM T_HR_EmpOrgRelation where fassignType = '1' group by FPERSONID) c "
  233. + "left join T_HR_EmpOrgRelation d on c.fpersonid = d.fpersonid and c.maxdate=d.FlEFFDT where d.fassignType = '1') e on e.fpersonid=b.fid "
  234. + "left join t_pm_user f on f.FPERSONID = b.fid "
  235. + "left join CT_MP_Fullorpart g on g.fid=b.cfftorptid "
  236. + "left join CT_MP_WorkerCategory h on h.fid=e.CFWorkercategoryID "
  237. + "left join T_HR_ATS_AttendanceProject j on j.fid=a.FATTENDANCEPROJECT "
  238. + "where g.fnumber='FULL' and h.fnumber in ('GTIIT_GAS','GTIIT_PSS','GTIIT_SAS') "
  239. + " and a.FAttendanceDate>='"+yesterday+"' and a.FAttendanceDate<='"+nowDate+"' and a.fstatus='1' and a.foperationstatus='1'";
  240. logger.error("个人考勤异常SQL:"+sql);
  241. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  242. Set<String> personIdSet = new HashSet<String>();
  243. Map<String, List<Map<String, String>>> map = new HashMap<>();
  244. try {
  245. while(rowSet.next()) {
  246. personIdSet.add(rowSet.getString("personId"));
  247. String userId = rowSet.getString("fid");
  248. if(StringUtils.isEmpty(userId)) {
  249. continue;
  250. }
  251. if(map.containsKey(userId)) {
  252. List<Map<String, String>> list = map.get(userId);
  253. Map<String, String> attendMap = new HashMap<String, String>();
  254. attendMap.put("attendanceName", rowSet.getString("attendanceName"));
  255. attendMap.put("attendanceCount", rowSet.getString("FATTENDANCEVALUE"));
  256. list.add(attendMap);
  257. map.put(userId, list);
  258. }else {
  259. List<Map<String, String>> list = new ArrayList<Map<String, String>>();
  260. Map<String, String> attendMap = new HashMap<String, String>();
  261. attendMap.put("attendanceName", rowSet.getString("attendanceName"));
  262. attendMap.put("attendanceCount", rowSet.getString("FATTENDANCEVALUE"));
  263. list.add(attendMap);
  264. map.put(userId, list);
  265. }
  266. }
  267. } catch (SQLException e) {
  268. e.printStackTrace();
  269. }
  270. logger.error("人员ID集合:"+personIdSet.toString());
  271. if(personIdSet.size()<=60) {
  272. for(String key:map.keySet()) {
  273. List<Map<String, String>> list = map.get(key)==null?new ArrayList<Map<String, String>>():map.get(key);
  274. StringBuffer strBuffer = new StringBuffer();
  275. strBuffer.append("You have attendance exception record on "+yesterday+" ");
  276. StringBuffer attendBuffer = new StringBuffer();
  277. for(int i=0;i<list.size();i++) {
  278. Map<String, String> attendMap = list.get(i);
  279. attendBuffer.append(attendMap.get("attendanceName")+": "+attendMap.get("attendanceCount")+",");
  280. }
  281. if(attendBuffer.length()>0) {
  282. strBuffer.append("(");
  283. strBuffer.append(attendBuffer.deleteCharAt(attendBuffer.length()-1));
  284. strBuffer.append("), ");
  285. }
  286. strBuffer.append("please log in the system to check and correct it as soon as possible.");
  287. strBuffer.append("\r\n");
  288. strBuffer.append(shrEnvironmentIP + "/home.do");
  289. this.sendEmail(ctx, key, "Attendance Exception Notification", strBuffer.toString());
  290. }
  291. }else {
  292. Set<String> userIdSet = new HashSet<String>();
  293. String roleSql = "select c.fid from T_WFR_WFROLE a left join T_WFR_PERSONROLE b on a.fid=b.froleid left join T_PM_USER c on b.FPSERSONID = c.FPERSONID where a.FNUMBER in ('103','104') and c.fid is not null";
  294. logger.error("获取工作流角色对应用户SQL:"+roleSql);
  295. IRowSet roleRow = DbUtil.executeQuery(ctx, roleSql);
  296. try {
  297. while(roleRow.next()) {
  298. userIdSet.add(roleRow.getString("fid"));
  299. }
  300. } catch (SQLException e) {
  301. e.printStackTrace();
  302. }
  303. logger.error("用户ID集合:"+userIdSet.toString());
  304. this.sendEmail(ctx, userIdSet, "Attendance Exception Notification", "Today, more than 60% of administrative staff have abnormal attendance. There may be a problem with the system interface. Please contact itsupport@gtiit.edu.cn or the system administrator to check.");
  305. }
  306. }
  307. /**
  308. * 个人异常考勤预警(按月)
  309. */
  310. @Override
  311. protected void _monthAttendAbnormal(Context ctx) throws BOSException, EASBizException {
  312. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  313. Calendar calendar = Calendar.getInstance();
  314. calendar.set(Calendar.DAY_OF_MONTH, 1);
  315. String thisMonthDate = sdf.format(calendar.getTime());
  316. calendar.add(Calendar.MONTH, -1);
  317. int thisYear = calendar.get(Calendar.YEAR);
  318. String lastMonthDate = sdf.format(calendar.getTime());
  319. LocalDate currentDate = LocalDate.now();
  320. // 格式化为英文月份
  321. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM", Locale.ENGLISH);
  322. //获取这个月的英文月份简写
  323. String thisMonthName = currentDate.format(formatter);
  324. //获取上个月的英文月份简写
  325. LocalDate previousMonthDate = currentDate.minusMonths(1);
  326. String LastMonthName = previousMonthDate.format(formatter);
  327. IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
  328. String shrEnvironmentIP = ipc.getParamValue(null, "shrEnvironmentIP");
  329. //获取员工上月的异常考勤次数
  330. String sql = "select b.fid personId,f.fid,sum(a.FATTENDANCEVALUE) FATTENDANCEVALUE from T_HR_ATS_AbnormalAttendance a "
  331. + "left join T_BD_Person b on a.FPROPOSER = b.fid "
  332. + "left join (select c.fpersonid,d.CFWorkercategoryID from (SELECT FPERSONID,max(FlEFFDT) as maxDate FROM T_HR_EmpOrgRelation where fassignType = '1' group by FPERSONID) c "
  333. + "left join T_HR_EmpOrgRelation d on c.fpersonid = d.fpersonid and c.maxdate=d.FlEFFDT where d.fassignType = '1') e on e.fpersonid=b.fid "
  334. + "left join t_pm_user f on f.FPERSONID = b.fid "
  335. + "left join CT_MP_Fullorpart g on g.fid=b.cfftorptid "
  336. + "left join CT_MP_WorkerCategory h on h.fid=e.CFWorkercategoryID "
  337. + "left join T_HR_ATS_AttendanceProject j on j.fid=a.FATTENDANCEPROJECT "
  338. + "where g.fnumber='FULL' and h.fnumber in ('GTIIT_GAS','GTIIT_PSS','GTIIT_SAS') "
  339. + " and a.FAttendanceDate>='"+lastMonthDate+"' and a.FAttendanceDate<'"+thisMonthDate+"' and a.fstatus='1' and a.foperationstatus='1' group by b.fid,f.fid";
  340. logger.error("个人考勤异常SQL:"+sql);
  341. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  342. Set<String> userIdSet = new HashSet<String>();
  343. try {
  344. while(rowSet.next()) {
  345. String personId = rowSet.getString("personId");
  346. String userId = rowSet.getString("fid");
  347. String attendanceValue = rowSet.getString("FATTENDANCEVALUE");
  348. if(StringUtils.isEmpty(userId) || StringUtils.isEmpty(personId) || StringUtils.isEmpty(attendanceValue)) {
  349. continue;
  350. }
  351. StringBuffer mesBuffer = new StringBuffer();
  352. mesBuffer.append("You have "+attendanceValue+" attendance exception(s) in "+LastMonthName+", "+thisYear+", please log in the system via the following link to check and correct it(them) as soon as possible.");
  353. mesBuffer.append("\r\n");
  354. mesBuffer.append("Line manger's approval of your correction shall be done by "+thisMonthName+" 5th.");
  355. mesBuffer.append("\r\n");
  356. mesBuffer.append("\r\n");
  357. mesBuffer.append(shrEnvironmentIP + "/home.do");
  358. mesBuffer.append("\r\n");
  359. mesBuffer.append("\r\n");
  360. mesBuffer.append("GTIIT HR System");
  361. this.sendEmail(ctx, userId, "Attendance Exception Notification", mesBuffer.toString());
  362. userIdSet.add(userId);
  363. }
  364. } catch (SQLException e) {
  365. e.printStackTrace();
  366. }
  367. logger.error("用户ID集合:"+userIdSet.toString());
  368. }
  369. /**
  370. * 已废弃
  371. */
  372. @Override
  373. protected void _departAttendAbnormal(Context ctx) throws BOSException, EASBizException {
  374. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  375. Calendar calendar = Calendar.getInstance();
  376. calendar.set(Calendar.DAY_OF_MONTH, 1);
  377. String thisMonthDate = sdf.format(calendar.getTime());
  378. calendar.add(Calendar.MONTH, -1);
  379. int thisYear = calendar.get(Calendar.YEAR);
  380. String lastMonthDate = sdf.format(calendar.getTime());
  381. LocalDate currentDate = LocalDate.now();
  382. // 格式化为英文月份
  383. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM", Locale.ENGLISH);
  384. //获取这个月的英文月份简写
  385. String thisMonthName = currentDate.format(formatter);
  386. //获取上个月的英文月份简写
  387. LocalDate previousMonthDate = currentDate.minusMonths(1);
  388. String LastMonthName = previousMonthDate.format(formatter);
  389. IParamControl ipc = ParamControlFactory.getLocalInstance(ctx);
  390. String shrEnvironmentIP = ipc.getParamValue(null, "shrEnvironmentIP");
  391. String sql = "select b.fid personId,f.fid,sum(a.FATTENDANCEVALUE) FATTENDANCEVALUE from T_HR_ATS_AbnormalAttendance a "
  392. + "left join T_BD_Person b on a.FPROPOSER = b.fid "
  393. + "left join (select c.fpersonid,d.CFWorkercategoryID from (SELECT FPERSONID,max(FlEFFDT) as maxDate FROM T_HR_EmpOrgRelation where fassignType = '1' group by FPERSONID) c "
  394. + "left join T_HR_EmpOrgRelation d on c.fpersonid = d.fpersonid and c.maxdate=d.FlEFFDT where d.fassignType = '1') e on e.fpersonid=b.fid "
  395. + "left join t_pm_user f on f.FPERSONID = b.fid "
  396. + "left join CT_MP_Fullorpart g on g.fid=b.cfftorptid "
  397. + "left join CT_MP_WorkerCategory h on h.fid=e.CFWorkercategoryID "
  398. + "left join T_HR_ATS_AttendanceProject j on j.fid=a.FATTENDANCEPROJECT "
  399. + "where g.fnumber='FULL' and h.fnumber in ('GTIIT_GAS','GTIIT_PSS','GTIIT_SAS') "
  400. + " and a.FAttendanceDate>='"+lastMonthDate+"' and a.FAttendanceDate<'"+thisMonthDate+"' and a.fstatus='1' and a.foperationstatus='1' group by b.fid,f.fid";
  401. logger.error("个人考勤异常SQL:"+sql);
  402. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  403. Set<String> userIdSet = new HashSet<String>();
  404. String title = "Attendance Exception Notification";
  405. try {
  406. while(rowSet.next()) {
  407. String personId = rowSet.getString("personId");
  408. String userId = rowSet.getString("fid");
  409. String attendanceValue = rowSet.getString("FATTENDANCEVALUE");
  410. if(StringUtils.isEmpty(userId) || StringUtils.isEmpty(personId) || StringUtils.isEmpty(attendanceValue)) {
  411. continue;
  412. }
  413. // StringBuffer mesBuffer = new StringBuffer();
  414. // mesBuffer.append("<html><head></head><body>");
  415. // mesBuffer.append("<span>You have "+attendanceValue+" attendance exception(s) in "+LastMonthName+", "+thisYear+", please log in the system via the following link to check and correct it(them) as soon as possible.</span><br>");
  416. // mesBuffer.append("<span>Line manger's approval of your correction shall be done by "+thisMonthName+" 5th.</span><br>");
  417. // mesBuffer.append("<br>");
  418. // mesBuffer.append("<span><a href=\"https://gtiit.kdeascloud.com/shr/home.do\">https://gtiit.kdeascloud.com/shr/home.do</a></span><br>");
  419. // mesBuffer.append("<br>");
  420. // mesBuffer.append("<span>GTIIT HR System</span><br>");
  421. // mesBuffer.append("</body></html>");
  422. StringBuffer mesBuffer = new StringBuffer();
  423. mesBuffer.append("You have "+attendanceValue+" attendance exception(s) in "+LastMonthName+", "+thisYear+", please log in the system via the following link to check and correct it(them) as soon as possible.");
  424. mesBuffer.append("\r\n");
  425. mesBuffer.append("Line manger's approval of your correction shall be done by "+thisMonthName+" 5th.");
  426. mesBuffer.append("\r\n");
  427. mesBuffer.append("\r\n");
  428. mesBuffer.append(shrEnvironmentIP + "/home.do");
  429. mesBuffer.append("\r\n");
  430. mesBuffer.append("\r\n");
  431. mesBuffer.append("GTIIT HR System");
  432. logger.error("邮件内容:"+mesBuffer.toString());
  433. logger.error("人员ID:"+personId);
  434. SendUtils.msgSend(ctx, title, PriorityEnum.HIGHT_VALUE, false, mesBuffer.toString(), personId,
  435. BOSMsgTypeEnum.V_TYPE_EMAIL, null, null, MimeTypeEnum.HTML);
  436. userIdSet.add(userId);
  437. }
  438. } catch (SQLException e) {
  439. e.printStackTrace();
  440. }
  441. logger.error("用户ID集合:"+userIdSet.toString());
  442. }
  443. public void sendEmail(Context ctx, Set<String> userIdSet, String title, String body) throws BOSException, EASBizException {
  444. if(userIdSet.size() == 0) {
  445. return;
  446. }
  447. List<String> list = userIdSet.stream().collect(Collectors.toList());
  448. SendUtils.msgGroupSend(ctx, title, PriorityEnum.HIGHT_VALUE, false, body, list, BOSMsgTypeEnum.V_TYPE_EMAIL, null);
  449. }
  450. public void sendEmail(Context ctx, String userId, String title, String body) throws BOSException, EASBizException {
  451. List<String> list = new ArrayList<String>();
  452. list.add(userId);
  453. SendUtils.msgGroupSend(ctx, title, PriorityEnum.HIGHT_VALUE, false, body, list, BOSMsgTypeEnum.V_TYPE_EMAIL, null);
  454. }
  455. }