8b3e9c604505d6b3f680bfde0ef8bc9020cd3330.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package com.kingdee.eas.hr.affair.app;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.dao.IObjectPK;
  5. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  6. import com.kingdee.bos.util.BOSUuid;
  7. import com.kingdee.eas.basedata.person.PersonFactory;
  8. import com.kingdee.eas.basedata.person.PersonInfo;
  9. import com.kingdee.eas.common.EASBizException;
  10. import com.kingdee.eas.custom.facade.leave.LeaveAllowanceFacadeFactory;
  11. import com.kingdee.eas.custom.utils.SendUtils;
  12. import com.kingdee.eas.framework.CoreBaseInfo;
  13. import com.kingdee.eas.hr.affair.*;
  14. import com.kingdee.eas.hr.base.HRBillBaseEntryInfo;
  15. import com.kingdee.eas.mobile.BOSMsgTypeEnum;
  16. import com.kingdee.eas.mobile.PriorityEnum;
  17. import com.kingdee.eas.rpts.ctrlreport.osf.OSFExecutor;
  18. import com.kingdee.eas.util.app.DbUtil;
  19. import com.kingdee.jdbc.rowset.IRowSet;
  20. import com.kingdee.util.DateTimeUtils;
  21. import java.sql.SQLException;
  22. import java.time.Instant;
  23. import java.time.LocalDate;
  24. import java.time.ZoneId;
  25. import java.time.format.DateTimeFormatter;
  26. import java.util.ArrayList;
  27. import java.util.Calendar;
  28. import java.util.Date;
  29. import java.util.HashMap;
  30. import java.util.List;
  31. import java.util.Locale;
  32. import java.util.concurrent.ScheduledThreadPoolExecutor;
  33. import java.util.concurrent.TimeUnit;
  34. import org.apache.hadoop.hive.ql.parse.HiveParser_IdentifiersParser.booleanValue_return;
  35. import org.apache.log4j.Logger;
  36. /**
  37. * @ClassName ResignBizBillControllerBeanEx
  38. * @Description 离职单controllerbean扩展类
  39. * @Author VenkoXie
  40. * @Date 2024/1/25 17:11
  41. * @Version 1.0
  42. **/
  43. public class ResignBizBillControllerBeanEx extends ResignBizBillControllerBean{
  44. private static Logger logger =
  45. Logger.getLogger("com.kingdee.eas.hr.affair.app.ResignBizBillControllerBeanEx");
  46. /**
  47. * 审批通过
  48. * @param ctx
  49. * @param entry
  50. * @throws BOSException
  51. * @throws EASBizException
  52. */
  53. @Override
  54. protected void _entryEffectOthers(Context ctx, HRBillBaseEntryInfo entry) throws BOSException, EASBizException {
  55. super._entryEffectOthers(ctx, entry);
  56. // HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entry;
  57. // PersonInfo pInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(affairEntry.getPerson().getId()));
  58. // LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(0, pInfo.getNumber());
  59. }
  60. @Override
  61. protected void _auditEntryEffect(Context ctx, BOSUuid billID) throws BOSException, EASBizException {
  62. super._auditEntryEffect(ctx, billID);
  63. ResignBizBillEntryCollection entryCollection = ResignBizBillEntryFactory.getLocalInstance(ctx).getResignBizBillEntryCollection("where bill.id = '" + billID + "'");
  64. int year = DateTimeUtils.getYear(new Date());
  65. for (int i = 0; i < entryCollection.size(); i++) {
  66. HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i);
  67. PersonInfo pInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(affairEntry.getPerson().getId()));
  68. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber());
  69. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareNursingLeave(year, pInfo.getNumber());
  70. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareParentalLeave(year, pInfo.getNumber());
  71. ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
  72. scheduledThreadPoolExecutor.schedule(()->{
  73. try {
  74. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber());
  75. } catch (BOSException e) {
  76. e.printStackTrace();
  77. }
  78. }, 1, TimeUnit.MINUTES);
  79. }
  80. //离职后更新薪酬结构失效日期
  81. for (int i = 0; i < entryCollection.size(); i++) {
  82. HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i);
  83. String personId = affairEntry.getPerson().getId().toString();
  84. String sql = "/*dialect*/update T_HR_SFixAdjustSalary a set CFHisLeffectDay = FLeffectDay,FLeffectDay = b.FBIZDATE from T_HR_ResignBizBillEntry b where a.FPERSONID = b.FPERSONID and a.FLEFFECTDAY > b.FBIZDATE and a.FPERSONID = '"+personId+"'";
  85. logger.error("更新薪酬结构失效日期SQL:"+sql);
  86. DbUtil.execute(ctx, sql);
  87. }
  88. }
  89. @Override
  90. protected IObjectPK _submitEffect(Context ctx, CoreBaseInfo model) throws BOSException, EASBizException {
  91. IObjectPK objectPk = super._submitEffect(ctx, model);
  92. ResignBizBillInfo resignBizBillInfo = ResignBizBillFactory.getLocalInstance(ctx).getResignBizBillInfo(objectPk);
  93. ResignBizBillEntryCollection entrys = resignBizBillInfo.getEntrys();
  94. try {
  95. sendResignMessage(ctx, entrys);
  96. } catch (SQLException e) {
  97. e.printStackTrace();
  98. }
  99. return objectPk;
  100. }
  101. private void sendResignMessage(Context ctx, ResignBizBillEntryCollection entryCollection) throws BOSException, SQLException, EASBizException {
  102. System.out.print("进来了邮件的方法");
  103. for (int i = 0; i < entryCollection.size(); i++) {
  104. HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i);
  105. String personId = affairEntry.getPerson().getId().toString();
  106. // String personName = affairEntry.getPerson().getName();
  107. // String sql = "SELECT a.*,b.fid userid FROM T_HR_EmpOrgRelation a left join t_pm_user b on a.fpersonid = b.fpersonid where a.fpersonid = '"+personId+"' and a.fislatestinaday = '1' and a.cfhourlywage is not null and a.cfhourlywage <> 0 and year(a.fleffdt) = 2199";
  108. String sql="SELECT a.*,c.fid as userid,d.fname_l1 as personName FROM T_HR_EmpOrgRelation a right join (SELECT max(a.fleffdt)as fleffdt,a.cfhourlywage as cfhourlywage, a.fpersonid as fpersonid FROM T_HR_EmpOrgRelation a where a.fpersonid='"+personId+"' and a.cfhourlywage is not null and a.cfhourlywage <> 0 and a.fislatestinaday = '1' group by a.fpersonid,a.cfhourlywage)b\r\n" +
  109. "on a.fpersonid=b.fpersonid and a.fleffdt=b.fleffdt and a.cfhourlywage =b.cfhourlywage\r\n" +
  110. " left join t_pm_user c on a.fpersonid = c.fpersonid left join t_bd_person d on d.fid =a.fpersonid\r\n" +
  111. " where a.fpersonid='"+personId+"' and a.cfhourlywage is not null and a.cfhourlywage <> 0 and a.fislatestinaday = '1' ";
  112. logger.error("查询变动记录SQL:"+sql);
  113. IRowSet row = DbUtil.executeQuery(ctx, sql);
  114. String userId = "";
  115. while(row.next()) {
  116. userId = row.getString("userid");
  117. Date bizDate = affairEntry.getBizDate();
  118. // Instant instant = bizDate.toInstant();
  119. // 使用系统默认的时区来获取 LocalDate
  120. // ZoneId zoneId = ZoneId.systemDefault();
  121. // LocalDate currentDate = instant.atZone(zoneId).toLocalDate();
  122. // 格式化为英文月份
  123. // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM", Locale.ENGLISH);
  124. // String thisMonthName = currentDate.format(formatter);
  125. String bizDateStr = com.kingdee.eas.custom.utils.DateTimeUtils.dateFormat(bizDate, "yyyy-MM-dd");
  126. List<String> list = new ArrayList<String>();
  127. list.add(userId);
  128. String title = "Reminder: Working hours submission";
  129. StringBuffer body = new StringBuffer();
  130. body.append("Dear "+row.getString("personName")+",");
  131. body.append("\r\n");
  132. body.append("As your part-time assignment will end on "+bizDateStr+", please remember to submit working hours in the system if you have unapplied working hours. ");
  133. body.append("Please refer to below instruction and select [Working hours submission for employees with ending PT assignments] in submission scheme in the system.");
  134. body.append("\r\n");
  135. body.append("\r\n");
  136. body.append("Please submit working hours before "+bizDateStr+", otherwise you cannot login to the system to submit it and late submission will not be accepted.");
  137. body.append("\r\n");
  138. body.append("\r\n");
  139. body.append("This is an automatic workflow email. Do not reply to this mail.");
  140. body.append("\r\n");
  141. body.append("\r\n");
  142. body.append("\r\n");
  143. body.append("Best regards,");
  144. body.append("\r\n");
  145. body.append("Human Resources Department");
  146. logger.error("离职发送邮件内容:"+body.toString());
  147. SendUtils.msgGroupSend(ctx, title, PriorityEnum.HIGHT_VALUE, false, body.toString(), list, BOSMsgTypeEnum.V_TYPE_EMAIL, null);
  148. }
  149. }
  150. }
  151. @Override
  152. protected void _setAudited(Context ctx, BOSUuid billID) throws BOSException, EASBizException {
  153. super._setAudited(ctx, billID);
  154. ResignBizBillEntryCollection entryCollection = ResignBizBillEntryFactory.getLocalInstance(ctx).getResignBizBillEntryCollection("where bill.id = '" + billID + "'");
  155. int year = DateTimeUtils.getYear(new Date());
  156. for (int i = 0; i < entryCollection.size(); i++) {
  157. HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i);
  158. PersonInfo pInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(affairEntry.getPerson().getId()));
  159. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber());
  160. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareNursingLeave(year, pInfo.getNumber());
  161. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareParentalLeave(year, pInfo.getNumber());
  162. ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
  163. scheduledThreadPoolExecutor.schedule(()->{
  164. try {
  165. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber());
  166. } catch (BOSException e) {
  167. e.printStackTrace();
  168. }
  169. }, 2, TimeUnit.MINUTES);
  170. }
  171. }
  172. /**
  173. * 反审批
  174. * @param ctx
  175. * @param billId
  176. * @throws BOSException
  177. * @throws EASBizException
  178. */
  179. @Override
  180. protected void _passUnaudit(Context ctx, BOSUuid billId) throws BOSException, EASBizException {
  181. super._passUnaudit(ctx, billId);
  182. ResignBizBillEntryCollection entryCollection = ResignBizBillEntryFactory.getLocalInstance(ctx).getResignBizBillEntryCollection("where bill.id = '" + billId + "'");
  183. int year = DateTimeUtils.getYear(new Date());
  184. for (int i = 0; i < entryCollection.size(); i++) {
  185. HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i);
  186. PersonInfo pInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(affairEntry.getPerson().getId()));
  187. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber());
  188. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareNursingLeave(year, pInfo.getNumber());
  189. LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareParentalLeave(year, pInfo.getNumber());
  190. }
  191. //离职反审批后还原薪酬结构失效日期
  192. for (int i = 0; i < entryCollection.size(); i++) {
  193. HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i);
  194. String personId = affairEntry.getPerson().getId().toString();
  195. String sql = "/*dialect*/update T_HR_SFixAdjustSalary set FLeffectDay = CFHisLeffectDay where CFHisLeffectDay is not null "
  196. + " and FPERSONID = '"+personId+"' and FLEFFECTDAY = (SELECT max(FLEFFECTDAY) FROM T_HR_SFixAdjustSalary where FPERSONID = '"+personId+"')";
  197. logger.error("更新薪酬结构失效日期SQL:"+sql);
  198. DbUtil.execute(ctx, sql);
  199. }
  200. }
  201. }