c9c36d3a251a849eba7198a55cf767b238ddf55b.svn-base 24 KB

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