package com.kingdee.eas.custom.recuritment.web.handler;

import com.kingdee.bos.Context;
import com.kingdee.eas.custom.recuritment.task.BeisenTransferPhaseFacadeFactory;
import com.kingdee.eas.custom.recuritment.task.IBeisenTransferPhaseFacade;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
import com.kingdee.shr.recuritment.web.handler.OfferListHandler;
import com.kingdee.util.StringUtils;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description offer列表
 * @Date 2025/7/8 19:42
 * @Created by Heyuan
 */
public class OfferListHandlerEx extends OfferListHandler {
    /**
     * 终止入职
     *
     * @param request
     * @param response
     * @param modelMap
     * @throws SHRWebException
     */
    @Override
    public void stopOfferAction(
            HttpServletRequest request,
            HttpServletResponse response,
            ModelMap modelMap
    ) throws SHRWebException {
        super.stopOfferAction(request, response, modelMap);
        Context ctx = SHRContext.getInstance().getContext();
        String billIds = request.getParameter("billId");
        try {
            if (!StringUtils.isEmpty(billIds)) {
                //同步录用报批状态至北森
                IBeisenTransferPhaseFacade iBeisenTransferPhaseFacade =
                        BeisenTransferPhaseFacadeFactory.getLocalInstance(ctx);
                iBeisenTransferPhaseFacade.syncOfferToBeisen(billIds, 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new ShrWebBizException(e);
        }
    }

    /**
     * 反终止
     *
     * @param request
     * @param response
     * @param modelMap
     * @throws SHRWebException
     */
    @Override
    public void noStopOfferAction(
            HttpServletRequest request,
            HttpServletResponse response,
            ModelMap modelMap
    ) throws SHRWebException {
        super.noStopOfferAction(request, response, modelMap);
        Context ctx = SHRContext.getInstance().getContext();
        String billIds = request.getParameter("billId");
        try {
            if (!StringUtils.isEmpty(billIds)) {
                //同步录用报批状态至北森
                IBeisenTransferPhaseFacade iBeisenTransferPhaseFacade =
                        BeisenTransferPhaseFacadeFactory.getLocalInstance(ctx);
                iBeisenTransferPhaseFacade.syncOfferToBeisen(billIds, 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new ShrWebBizException(e);
        }
    }

    /**
     * 放弃入职
     *
     * @param request
     * @param response
     * @param modelMap
     * @throws SHRWebException
     */
    @Override
    public void abondonEntryAction(
            HttpServletRequest request,
            HttpServletResponse response,
            ModelMap modelMap
    ) throws SHRWebException {
        super.abondonEntryAction(request, response, modelMap);
        Context ctx = SHRContext.getInstance().getContext();
        String billIds = request.getParameter("billId");
        try {
            if (!StringUtils.isEmpty(billIds)) {
                //同步录用报批状态至北森
                IBeisenTransferPhaseFacade iBeisenTransferPhaseFacade =
                        BeisenTransferPhaseFacadeFactory.getLocalInstance(ctx);
                iBeisenTransferPhaseFacade.syncOfferToBeisen(billIds, 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new ShrWebBizException(e);
        }
    }
}
