package com.kingdee.shr.recuritment.web.handler.recApproval;

import com.kingdee.bos.Context;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.recuritment.task.BeisenTransferPhaseFacadeFactory;
import com.kingdee.eas.custom.recuritment.task.IBeisenTransferPhaseFacade;
import com.kingdee.eas.hr.ats.AtsUtil;
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 org.apache.commons.lang3.StringUtils;
import org.springframework.ui.ModelMap;

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

/**
 * @Description 录用报批
 * @Date 2025/7/8 19:56
 * @Created by Heyuan
 */
public class RecApprovalListHandlerEx extends RecApprovalListHandler {
    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 (StringUtils.isEmpty(billIds)) {
            throw new ShrWebBizException("单据id不能为空!");
        } else if (billIds.split(",").length > 1) {
            throw new ShrWebBizException("只能选中单行!");
        }
        try {
            if (!com.kingdee.util.StringUtils.isEmpty(billIds)) {
                //同步录用报批状态至北森
                IBeisenTransferPhaseFacade iBeisenTransferPhaseFacade =
                        BeisenTransferPhaseFacadeFactory.getLocalInstance(ctx);
                iBeisenTransferPhaseFacade.syncRecApprovalToBeisen(billIds, 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new ShrWebBizException(e);
        }
    }

    /**
     * 终止报批
     *
     * @param request
     * @param response
     * @param modelMap
     * @throws SHRWebException
     */
    @Override
    public void stopBillAction(
            HttpServletRequest request,
            HttpServletResponse response,
            ModelMap modelMap
    ) throws SHRWebException {
        super.stopBillAction(request, response, modelMap);
        String billId = this.getBillId(request);
        if (StringUtils.isNotBlank(billId)) {
            try {
                //同步录用报批状态至北森
                IBeisenTransferPhaseFacade iBeisenTransferPhaseFacade =
                        BeisenTransferPhaseFacadeFactory.getLocalInstance(ctx);
                iBeisenTransferPhaseFacade.syncRecApprovalToBeisen(billId, 0);
            } catch (Exception e) {
                e.printStackTrace();
                throw new ShrWebBizException(e);
            }
        }
    }
}
