package com.kingdee.eas.hr.affair.app; import com.kingdee.bos.BOSException; import com.kingdee.bos.Context; import com.kingdee.bos.dao.IObjectPK; import com.kingdee.bos.dao.ormapping.ObjectUuidPK; import com.kingdee.bos.util.BOSUuid; import com.kingdee.eas.basedata.person.PersonFactory; import com.kingdee.eas.basedata.person.PersonInfo; import com.kingdee.eas.common.EASBizException; import com.kingdee.eas.custom.facade.leave.LeaveAllowanceFacadeFactory; import com.kingdee.eas.custom.utils.SendUtils; import com.kingdee.eas.framework.CoreBaseInfo; import com.kingdee.eas.hr.affair.*; import com.kingdee.eas.hr.base.HRBillBaseEntryInfo; import com.kingdee.eas.mobile.BOSMsgTypeEnum; import com.kingdee.eas.mobile.PriorityEnum; import com.kingdee.eas.rpts.ctrlreport.osf.OSFExecutor; import com.kingdee.eas.util.app.DbUtil; import com.kingdee.jdbc.rowset.IRowSet; import com.kingdee.util.DateTimeUtils; import java.sql.SQLException; import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.apache.hadoop.hive.ql.parse.HiveParser_IdentifiersParser.booleanValue_return; import org.apache.log4j.Logger; /** * @ClassName ResignBizBillControllerBeanEx * @Description 离职单controllerbean扩展类 * @Author VenkoXie * @Date 2024/1/25 17:11 * @Version 1.0 **/ public class ResignBizBillControllerBeanEx extends ResignBizBillControllerBean{ private static Logger logger = Logger.getLogger("com.kingdee.eas.hr.affair.app.ResignBizBillControllerBeanEx"); /** * 审批通过 * @param ctx * @param entry * @throws BOSException * @throws EASBizException */ @Override protected void _entryEffectOthers(Context ctx, HRBillBaseEntryInfo entry) throws BOSException, EASBizException { super._entryEffectOthers(ctx, entry); // HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entry; // PersonInfo pInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(affairEntry.getPerson().getId())); // LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(0, pInfo.getNumber()); } @Override protected void _auditEntryEffect(Context ctx, BOSUuid billID) throws BOSException, EASBizException { super._auditEntryEffect(ctx, billID); ResignBizBillEntryCollection entryCollection = ResignBizBillEntryFactory.getLocalInstance(ctx).getResignBizBillEntryCollection("where bill.id = '" + billID + "'"); int year = DateTimeUtils.getYear(new Date()); for (int i = 0; i < entryCollection.size(); i++) { HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i); PersonInfo pInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(affairEntry.getPerson().getId())); LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber()); LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareNursingLeave(year, pInfo.getNumber()); LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareParentalLeave(year, pInfo.getNumber()); ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); scheduledThreadPoolExecutor.schedule(()->{ try { LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber()); } catch (BOSException e) { e.printStackTrace(); } }, 1, TimeUnit.MINUTES); } //离职后更新薪酬结构失效日期 for (int i = 0; i < entryCollection.size(); i++) { HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i); String personId = affairEntry.getPerson().getId().toString(); 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+"'"; logger.error("更新薪酬结构失效日期SQL:"+sql); DbUtil.execute(ctx, sql); } } @Override protected IObjectPK _submitEffect(Context ctx, CoreBaseInfo model) throws BOSException, EASBizException { IObjectPK objectPk = super._submitEffect(ctx, model); ResignBizBillInfo resignBizBillInfo = ResignBizBillFactory.getLocalInstance(ctx).getResignBizBillInfo(objectPk); ResignBizBillEntryCollection entrys = resignBizBillInfo.getEntrys(); try { sendResignMessage(ctx, entrys); } catch (SQLException e) { e.printStackTrace(); } return objectPk; } private void sendResignMessage(Context ctx, ResignBizBillEntryCollection entryCollection) throws BOSException, SQLException, EASBizException { System.out.print("进来了邮件的方法"); for (int i = 0; i < entryCollection.size(); i++) { HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i); String personId = affairEntry.getPerson().getId().toString(); // String personName = affairEntry.getPerson().getName(); // 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"; 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" + "on a.fpersonid=b.fpersonid and a.fleffdt=b.fleffdt and a.cfhourlywage =b.cfhourlywage\r\n" + " left join t_pm_user c on a.fpersonid = c.fpersonid left join t_bd_person d on d.fid =a.fpersonid\r\n" + " where a.fpersonid='"+personId+"' and a.cfhourlywage is not null and a.cfhourlywage <> 0 and a.fislatestinaday = '1' "; logger.error("查询变动记录SQL:"+sql); IRowSet row = DbUtil.executeQuery(ctx, sql); String userId = ""; while(row.next()) { userId = row.getString("userid"); Date bizDate = affairEntry.getBizDate(); // Instant instant = bizDate.toInstant(); // 使用系统默认的时区来获取 LocalDate // ZoneId zoneId = ZoneId.systemDefault(); // LocalDate currentDate = instant.atZone(zoneId).toLocalDate(); // 格式化为英文月份 // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM", Locale.ENGLISH); // String thisMonthName = currentDate.format(formatter); String bizDateStr = com.kingdee.eas.custom.utils.DateTimeUtils.dateFormat(bizDate, "yyyy-MM-dd"); List list = new ArrayList(); list.add(userId); String title = "Reminder: Working hours submission"; StringBuffer body = new StringBuffer(); body.append("Dear "+row.getString("personName")+","); body.append("\r\n"); 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. "); body.append("Please refer to below instruction and select [Working hours submission for employees with ending PT assignments] in submission scheme in the system."); body.append("\r\n"); body.append("\r\n"); 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."); body.append("\r\n"); body.append("\r\n"); body.append("This is an automatic workflow email. Do not reply to this mail."); body.append("\r\n"); body.append("\r\n"); body.append("\r\n"); body.append("Best regards,"); body.append("\r\n"); body.append("Human Resources Department"); logger.error("离职发送邮件内容:"+body.toString()); SendUtils.msgGroupSend(ctx, title, PriorityEnum.HIGHT_VALUE, false, body.toString(), list, BOSMsgTypeEnum.V_TYPE_EMAIL, null); } } } @Override protected void _setAudited(Context ctx, BOSUuid billID) throws BOSException, EASBizException { super._setAudited(ctx, billID); ResignBizBillEntryCollection entryCollection = ResignBizBillEntryFactory.getLocalInstance(ctx).getResignBizBillEntryCollection("where bill.id = '" + billID + "'"); int year = DateTimeUtils.getYear(new Date()); for (int i = 0; i < entryCollection.size(); i++) { HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i); PersonInfo pInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(affairEntry.getPerson().getId())); LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber()); LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareNursingLeave(year, pInfo.getNumber()); LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareParentalLeave(year, pInfo.getNumber()); ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); scheduledThreadPoolExecutor.schedule(()->{ try { LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber()); } catch (BOSException e) { e.printStackTrace(); } }, 2, TimeUnit.MINUTES); } } /** * 反审批 * @param ctx * @param billId * @throws BOSException * @throws EASBizException */ @Override protected void _passUnaudit(Context ctx, BOSUuid billId) throws BOSException, EASBizException { super._passUnaudit(ctx, billId); ResignBizBillEntryCollection entryCollection = ResignBizBillEntryFactory.getLocalInstance(ctx).getResignBizBillEntryCollection("where bill.id = '" + billId + "'"); int year = DateTimeUtils.getYear(new Date()); for (int i = 0; i < entryCollection.size(); i++) { HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i); PersonInfo pInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(affairEntry.getPerson().getId())); LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber()); LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareNursingLeave(year, pInfo.getNumber()); LeaveAllowanceFacadeFactory.getLocalInstance(ctx).creareParentalLeave(year, pInfo.getNumber()); } //离职反审批后还原薪酬结构失效日期 for (int i = 0; i < entryCollection.size(); i++) { HRAffairBizBillEntryInfo affairEntry = (HRAffairBizBillEntryInfo)entryCollection.get(i); String personId = affairEntry.getPerson().getId().toString(); String sql = "/*dialect*/update T_HR_SFixAdjustSalary set FLeffectDay = CFHisLeffectDay where CFHisLeffectDay is not null " + " and FPERSONID = '"+personId+"' and FLEFFECTDAY = (SELECT max(FLEFFECTDAY) FROM T_HR_SFixAdjustSalary where FPERSONID = '"+personId+"')"; logger.error("更新薪酬结构失效日期SQL:"+sql); DbUtil.execute(ctx, sql); } } }