package com.kingdee.eas.hr.affair.app;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
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.hr.affair.*;
import com.kingdee.eas.hr.base.HRBillBaseEntryInfo;
import com.kingdee.util.DateTimeUtils;

import java.util.Date;
import java.util.HashMap;

/**
 * @ClassName FluctuationBizBillControllerBeanEx
 * @Description 调动单controllerbean扩展
 * @Author VenkoXie
 * @Date 2024/2/22 11:02
 * @Version 1.0
 **/
public class FluctuationBizBillControllerBeanEx extends FluctuationBizBillControllerBean{

    /**
     * 审批通过
     * @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;
        HashMap param = new HashMap();
        int year = DateTimeUtils.getYear(new Date());
        PersonInfo pInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(affairEntry.getPerson().getId()));
        LeaveAllowanceFacadeFactory.getLocalInstance(ctx).createAnnualLeave(year, pInfo.getNumber());
    }

    /**
     * 反审批
     * @param ctx
     * @param billId
     * @throws BOSException
     * @throws EASBizException
     */
    @Override
    protected void _passUnaudit(Context ctx, BOSUuid billId) throws BOSException, EASBizException {
        super._passUnaudit(ctx, billId);
        FluctuationBizBillEntryCollection entryCollection = FluctuationBizBillEntryFactory.getLocalInstance(ctx).getFluctuationBizBillEntryCollection("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());
        }
    }
}
