package com.kingdee.shr.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.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 {
    private Context ctx = SHRContext.getInstance().getContext();

    /**
     * 终止入职
     *
     * @param request
     * @param response
     * @param modelMap
     * @throws SHRWebException
     */
    public void executeSyncBeisenAction(
            HttpServletRequest request,
            HttpServletResponse response,
            ModelMap modelMap
    ) throws SHRWebException {
        String billIds = this.getBillId(request);
        if (org.apache.commons.lang3.StringUtils.isEmpty(billIds)) {
            throw new ShrWebBizException("单据id不能为空!");
        } else if (billIds.split(",").length > 1) {
            throw new ShrWebBizException("只能选中单行!");
        }
        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 stopOfferAction(
            HttpServletRequest request,
            HttpServletResponse response,
            ModelMap modelMap
    ) throws SHRWebException {
        super.stopOfferAction(request, response, modelMap);
        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 toPrePersonAction(
            HttpServletRequest request,
            HttpServletResponse response,
            ModelMap modelMap
    ) throws SHRWebException {
        super.toPrePersonAction(request, response, modelMap);
        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);
        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);
        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);
        }
    }
}
