package com.kingdee.eas.custom.dormitorysystem.application.handler;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.eas.custom.dormitorysystem.application.utils.CheckDuplicateCheckInByBillIdUtil;
import com.kingdee.eas.custom.dormitorysystem.application.utils.ValidateRoomAvailableByBillIdsUtil;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.hr.base.HRBillBaseInfo;
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.log4j.Logger;

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

/**
 * @Description 入住申请单列表Handler
 * @Date 2025/4/24 13:47
 * @Created by Heyuan
 */
public class CheckInApplicationListHandler extends DormitoryApplicationListHandler {
    private static Logger logger = Logger.getLogger(CheckInApplicationListHandler.class);
    private Context ctx = SHRContext.getInstance().getContext();

    @Override
    protected void beforeSubmit(
            HttpServletRequest request,
            HttpServletResponse response,
            CoreBaseInfo model
    ) throws SHRWebException {
        try {
            HRBillBaseInfo hrBillBaseInfo = (HRBillBaseInfo) model;
            String billIds = hrBillBaseInfo.getId().toString();
            //根据单据id校验房间是否入住(批量)
            ValidateRoomAvailableByBillIdsUtil.startValidate(ctx, billIds);
            //检查入住申请单是否重复、入住信息是否重复,时间是否交叉
            CheckDuplicateCheckInByBillIdUtil.startValidate(ctx, billIds);
            super.beforeSubmit(request, response, model);
        } catch (BOSException e) {
            logger.error(e);
            throw new ShrWebBizException(e);
        }
    }
}
