package com.kingdee.eas.custom.esign.app;

import com.kingdee.bos.dao.ormapping.CanNotDeleteException;
import com.kingdee.eas.custom.esign.AttachmentStoragePathConfigInfo;
import com.kingdee.shr.base.syssetting.BaseItemStateEnum;
import org.apache.log4j.Logger;

import com.kingdee.bos.*;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.eas.common.EASBizException;

import java.sql.Connection;

/**
 * 附件存储路径配置
 */
public class AttachmentStoragePathConfigControllerBean extends AbstractAttachmentStoragePathConfigControllerBean {
    private static Logger logger = Logger.getLogger(AttachmentStoragePathConfigControllerBean.class);


    /**
     * 检查附件存储路径配置信息是否可以删除
     *
     * @param ctx 上下文对象
     * @param pk 对象主键
     * @param cn 数据库连接
     * @throws CanNotDeleteException 当数据处于启用状态或发生业务异常时抛出
     */
    @Override
    protected void _canDelete(Context ctx, IObjectPK pk, Connection cn) throws CanNotDeleteException {
        super._canDelete(ctx, pk, cn);
        try {
            // 获取附件存储路径配置信息并检查状态
            AttachmentStoragePathConfigInfo info = getAttachmentStoragePathConfigInfo(ctx, pk);
            BaseItemStateEnum state = info.getState();
            if (BaseItemStateEnum.ENABLE.equals(state)) {
                throw new CanNotDeleteException("启用的数据，不允许删除！");
            }
        } catch (BOSException e) {
            logger.error(e.getMessage(), e);
            throw new CanNotDeleteException(e);
        } catch (EASBizException e) {
            logger.error(e.getMessage(), e);
            throw new CanNotDeleteException(e);
        }
    }


}