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

import com.aliyun.odps.utils.StringUtils;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.eas.common.EASAppException;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.compensation.SubmitShemeTemplateInfo;
import com.kingdee.shr.base.syssetting.BaseItemStateEnum;
import org.apache.log4j.Logger;

public class SubmitShemeTemplateControllerBean extends AbstractSubmitShemeTemplateControllerBean {
    private static Logger logger =
            Logger.getLogger(SubmitShemeTemplateControllerBean.class);


    /**
     * 启用指定的单据
     *
     * @param ctx    上下文对象，包含业务逻辑执行所需的环境信息
     * @param billID 单据ID，标识需要启用的单据
     * @throws BOSException    业务对象服务异常
     * @throws EASAppException EAS应用异常
     */
    @Override
    protected void _enable(Context ctx, String billID) throws BOSException, EASBizException {
        // 调用父类的启用方法执行实际的启用逻辑
        super._enable(ctx, billID);
        if (StringUtils.isBlank(billID)) {
            throw new BOSException("billID不能为空!");
        }
        SubmitShemeTemplateInfo info = getSubmitShemeTemplateInfo(ctx, new ObjectUuidPK(billID));
        BaseItemStateEnum state = info.getState();
        if (!BaseItemStateEnum.ENABLE.equals(state)) {
            SelectorItemCollection updateSic = new SelectorItemCollection();
            updateSic.add("state");
            info.setState(BaseItemStateEnum.ENABLE);
            updatePartial(ctx, info, updateSic);
        }
    }


    /**
     * 禁用指定的单据
     *
     * @param ctx    上下文对象，包含业务逻辑执行所需的环境信息
     * @param billID 单据ID，标识需要被禁用的单据
     * @throws BOSException    业务对象服务异常
     * @throws EASAppException EAS应用异常
     */
    @Override
    protected void _disable(Context ctx, String billID) throws BOSException, EASBizException {
        // 调用父类的禁用方法执行实际的禁用操作
        super._disable(ctx, billID);
        SubmitShemeTemplateInfo info = getSubmitShemeTemplateInfo(ctx, new ObjectUuidPK(billID));
        BaseItemStateEnum state = info.getState();
        if (!BaseItemStateEnum.DISABLE.equals(state)) {
            SelectorItemCollection updateSic = new SelectorItemCollection();
            updateSic.add("state");
            info.setState(BaseItemStateEnum.DISABLE);
            updatePartial(ctx, info, updateSic);
        }
    }

}