package com.kingdee.eas.custom.synctask.handler;

import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.hr.ats.*;
import com.kingdee.shr.ats.web.handler.FillSignCardBatchNewEditHandler;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
import com.kingdee.util.StringUtils;
import org.apache.log4j.Logger;

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

/**
 * @author qingwu
 * @date 2024/11/18
 * @apiNote
 */
public class FillSignCardBatchNewEditHandlerEx extends FillSignCardBatchNewEditHandler {

    Logger logger = Logger.getLogger(FillSignCardBatchNewEditHandlerEx.class);

    @Override
    protected void beforeSave(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model) throws SHRWebException {
        super.beforeSave(request, response, model);
        StringBuilder sb = new StringBuilder();
        FillSignCardInfo fillSignCardInfo = (FillSignCardInfo) model;
        FillSignCardEntryCollection entries = fillSignCardInfo.getEntries();
        for (int i = 0; i < entries.size(); i++) {
            FillSignCardEntryInfo fillSignCardEntryInfo = entries.get(i);
            FillSignReasonInfo reason = fillSignCardEntryInfo.getReason();
            String reasonName = reason.getName();
            String remark = fillSignCardEntryInfo.getRemark();
            logger.error("reasonNumber" + reasonName + "---remark" + remark);
            //003 = 其它
            if (reasonName.equals("其它") && StringUtils.isEmpty(remark)) {
                sb.append("第" + (i + 1) + "条补卡原因为其它备注必填，请维护数据后保存! ").append("\n");
            }
            logger.error("sb-----" + sb.toString());

            if (sb.length() > 0) {
                throw new ShrWebBizException(sb.toString());
            }
        }
    }
}
