package com.kingdee.eas.custom.calcdailypay.task; import com.kingdee.bos.metadata.entity.*; import com.kingdee.bos.metadata.query.util.CompareType; import com.kingdee.bos.util.EASResource; import com.kingdee.shr.base.syssetting.exception.SHRWebException; import com.kingdee.shr.base.syssetting.exception.ShrWebBizException; import com.kingdee.shr.compensation.app.integrate.*; import com.kingdee.shr.compensation.app.utils.SubConstants; import com.kingdee.shr.compensation.integrate.verify.CycleVerify; import com.kingdee.shr.compensation.integrate.verify.ISubmitBillVerifyInterface; import com.kingdee.shr.compensation.integrate.verify.SubmitBillDisableElementVerify; import com.kingdee.shr.compensation.integrate.verify.SubmitBillEnableElementVerify; import com.kingdee.shr.compensation.util.budget.BudgetUtil; import com.google.common.collect.Maps; import org.apache.log4j.Logger; import com.kingdee.bos.*; import com.kingdee.bos.dao.ormapping.ObjectUuidPK; import java.sql.SQLException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Map; import com.kingdee.eas.common.EASBizException; import com.kingdee.eas.framework.CoreBaseInfo; import com.kingdee.eas.hr.base.HRBillStateEnum; import com.kingdee.eas.util.app.DbUtil; import com.kingdee.jdbc.rowset.IRowSet; /** * 自动提交日提报单 * @author coyle * 2025-05-25 */ public class AutoSubDayDetailFacadeControllerBean extends AbstractAutoSubDayDetailFacadeControllerBean { private static Logger logger = Logger.getLogger("com.kingdee.eas.custom.calcdailypay.task.AutoSubDayDetailFacadeControllerBean"); /** * * @param ctx * @param preCalcDays 日期偏移量,正数表示向后推,负数表示向前推 * @throws BOSException * @throws EASBizException */ public void _autoSubDayDetail(Context ctx, int preCalcDays) throws BOSException, EASBizException { // 获取当前日期 LocalDate currentDate = LocalDate.now(); // 根据preCalcDays计算起始日期和结束日期 LocalDate startDate = currentDate.minusDays( Math.abs(preCalcDays)); LocalDate endDate = currentDate; // 如果preCalcDays是正数,调整startDate和endDate的顺序 // if (preCalcDays > 0) { // LocalDate temp = startDate; // startDate = endDate; // endDate = temp; // } // 在日期范围内每天执行一次executeSubmit方法 while (!startDate.isAfter(endDate)) { try { executeSubmit(ctx, startDate); } catch (SQLException e) { logger.error("日提报自动提交sql执行异常"+e); e.printStackTrace(); } startDate = startDate.plusDays(1); } } private void executeSubmit(Context ctx, LocalDate date) throws BOSException, EASBizException, SQLException { // 这里是executeSubmit的具体实现 String field1 = "S64"; CalSubmitItemCollection subColl = CalSubmitItemFactory.getLocalInstance(ctx) .getCalSubmitItemCollection("SELECT ID,FieldSn,number where number = '"+SubConstants.COMRATE+"'"); if(subColl.size()>0) { CalSubmitItemInfo calSubmitItemInfo = subColl.get(0); int fieldSn = calSubmitItemInfo.getFieldSn(); field1 = "S"+fieldSn ; }else{ field1 = "S64"; logger.error("查询薪酬项目编码,没有找到"+SubConstants.COMRATE+"字段数据"); } // 假设你需要将日期格式化为特定格式 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String formattedDate = date.format(formatter); //业务逻辑 IBatchSubmitShemeBill billIns = BatchSubmitShemeBillFactory.getLocalInstance(ctx); FilterInfo filter = new FilterInfo(); filter.getFilterItems().add(new FilterItemInfo("billState", HRBillStateEnum.SAVED_VALUE, CompareType.EQUALS)); //提报方案时日提报的; filter.getFilterItems().add(new FilterItemInfo("submitScheme.submitSchemeType", SubmitSchemeType.TIMEPIECE_VALUE, CompareType.EQUALS)); filter.getFilterItems().add(new FilterItemInfo("applyDate", formattedDate , CompareType.LESS_EQUALS)); filter.getFilterItems().add(new FilterItemInfo("applyDate", formattedDate , CompareType.GREATER_EQUALS )); EntityViewInfo viewInfo = new EntityViewInfo(); viewInfo.setFilter(filter); try { BatchSubmitShemeBillCollection batchSubmitShemeBillCollection = billIns.getBatchSubmitShemeBillCollection(viewInfo); if (!batchSubmitShemeBillCollection.isEmpty()) { for (int i = 0; i < batchSubmitShemeBillCollection.size(); ++i) { BatchSubmitShemeBillInfo model = batchSubmitShemeBillCollection.get(i); // BatchSubmitShemeBillControllerBeanEx batchSubmitShemeBillControllerBeanEx = new BatchSubmitShemeBillControllerBeanEx(); // batchSubmitShemeBillControllerBeanEx._save(ctx,model); billIns.save(new ObjectUuidPK(model.getId()),model); String checkSql = "SELECT "+field1 +" FROM T_HR_TimepieceBillEntry WHERE FBillID = '"+model.getId().toString()+"' "; IRowSet executeQuery = DbUtil.executeQuery(ctx, checkSql); boolean isOk = true; while(executeQuery.next()) { String value = executeQuery.getString(field1); if(value == null ) { logger.error("日提报单"+model.getNumber()+"的"+field1+"字段值为空,无法提交"); isOk = false; break; } } if(!isOk) { continue; } beforeSubmit(ctx, model); billIns.submitEffect(model); } } } catch (SHRWebException e) { logger.error(e); } } ////////////DefaultSubmitShemeBillListHandler_beforeSubmit//////////// protected void beforeSubmit( Context ctx,CoreBaseInfo model) throws SHRWebException { BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo) model; this.reAssembleModel(ctx, info); this.verifyIsBillEntryEmpty(ctx, info); try { ISubmitBillVerifyInterface verifyInstance = this.getVerifyInstance(ctx, info); verifyInstance.verify(ctx, info, this.getVerifyParams()); BudgetUtil.verifyBudget(ctx, info); model.setInt("billState", 1); } catch (BOSException var8) { throw new SHRWebException(var8.getMessage(), var8); } catch (EASBizException var9) { throw new ShrWebBizException(var9.getMessage(), var9); } try { this.udpSubmitTime(ctx, info.getId().toString()); } catch (BOSException var7) { throw new SHRWebException(var7.getMessage(), var7); } } protected void reAssembleModel(Context ctx, BatchSubmitShemeBillInfo model) throws SHRWebException { String oql = "select *, entry.*,submitScheme.id,entry.submitElement.name,entry.person.name,entry.person.number where id = '%s'"; try { BatchSubmitShemeBillInfo info = BatchSubmitShemeBillFactory.getLocalInstance(ctx).getBatchSubmitShemeBillInfo(String.format(oql, model.getId().toString())); model.clear(); model.putAll(info); } catch (EASBizException e) { e.printStackTrace(); } catch (BOSException e) { e.printStackTrace(); } } protected void verifyIsBillEntryEmpty(Context ctx, BatchSubmitShemeBillInfo info) throws SHRWebException { if (info.getEntry() == null || info.getEntry().isEmpty()) { throw new ShrWebBizException(EASResource.getString( "com.kingdee.shr.compensation.resource.SubmitShemeBillResource", "label19", ctx.getLocale())); } } protected ISubmitBillVerifyInterface getVerifyInstance(Context ctx, BatchSubmitShemeBillInfo info) throws SHRWebException { if (null == info) { throw new ShrWebBizException("model can not be null."); } else { try { CalSubmitSchemeInfo calSubmitSchemeInfo = CalSubmitSchemeFactory.getLocalInstance(ctx) .getCalSubmitSchemeInfo(new ObjectUuidPK(info.getSubmitScheme().getId().toString())); ISubmitBillVerifyInterface instance = this .createVerifyInstance(calSubmitSchemeInfo.isIsEnableSubmitElement()); if (calSubmitSchemeInfo.isIscycle()) { instance = new CycleVerify((ISubmitBillVerifyInterface) instance); } return (ISubmitBillVerifyInterface) instance; } catch (EASBizException var5) { throw new ShrWebBizException(var5.getMessage(), var5); } catch (BOSException var6) { throw new SHRWebException(var6.getMessage(), var6); } } } protected ISubmitBillVerifyInterface createVerifyInstance(boolean isEnableSubmitElement) { return (ISubmitBillVerifyInterface) (isEnableSubmitElement ? new SubmitBillEnableElementVerify() : new SubmitBillDisableElementVerify()); } protected Map getVerifyParams() { return Maps.newHashMap(); } // protected void udpSubmitTime(Context ctx, String billId) throws BOSException { // String sql = "update T_HR_SBatchSubmitShemeBill set FSubmitTime = ? where FID = ?"; // Object[] param = new Object[]{new Date((new Date()).getTime()), billId}; // DbUtil.execute(ctx, sql, param); // } protected void udpSubmitTime(Context ctx, String billId) throws BOSException { String sql = "update T_HR_SBatchSubmitShemeBill set FSubmitTime = ? where FID = ?"; // 使用java.sql.Timestamp替代java.util.Date Object[] param = new Object[]{new java.sql.Timestamp(System.currentTimeMillis()), billId}; DbUtil.execute(ctx, sql, param); } }