package com.kingdee.eas.custom.interfacelog.businessoperationlog.app;

import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.base.permission.UserInfo;
import org.apache.log4j.Logger;
import javax.ejb.*;
import java.rmi.RemoteException;
import com.kingdee.bos.*;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.rule.RuleExecutor;
import com.kingdee.bos.metadata.MetaDataPK;
import com.kingdee.bos.framework.ejb.AbstractEntityControllerBean;
import com.kingdee.bos.framework.ejb.AbstractBizControllerBean;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.service.ServiceContext;
import com.kingdee.bos.service.IServiceContext;

import com.kingdee.eas.framework.CoreBillEntryBaseCollection;
import com.kingdee.eas.custom.interfacelog.businessoperationlog.OperateLogEntryInfo;
import com.kingdee.eas.custom.interfacelog.businessoperationlog.OperateLogEntryCollection;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.eas.framework.app.CoreBillEntryBaseControllerBean;
import java.util.Date;

import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;

/**
 * OperateLogEntryControllerBean 类负责处理操作日志条目的业务逻辑，
 * 继承自 AbstractOperateLogEntryControllerBean 并对保存方法进行了扩展。
 */
public class OperateLogEntryControllerBean extends AbstractOperateLogEntryControllerBean {
    // 定义日志记录器，用于记录该类的运行信息
    private static final Logger logger = Logger.getLogger("com.kingdee.eas.custom.interfacelog.businessoperationlog.app.OperateLogEntryControllerBean");

    /**
     * 重写父类的保存方法，在保存操作日志条目之前设置创建日期和创建用户信息。
     *
     * @param ctx   业务操作的上下文信息
     * @param model 要保存的操作日志条目对象
     * @return 保存后对象的主键
     * @throws BOSException     当发生 BOS 相关异常时抛出
     * @throws EASBizException  当发生 EAS 业务相关异常时抛出
     */
    @Override
    protected IObjectPK _save(Context ctx, IObjectValue model) throws BOSException, EASBizException {
        // 将传入的对象转换为 OperateLogEntryInfo 类型
        OperateLogEntryInfo operateLogEntryInfo = (OperateLogEntryInfo) model;

        // 设置操作日志条目的创建日期为当前时间
        operateLogEntryInfo.setCreateDate(new Date());

        // 获取当前调用者的主键
        IObjectPK caller = ctx.getCaller();

        // 创建一个新的用户信息对象
        UserInfo userInfo = new UserInfo();

        // 检查调用者主键是否为空
        if (caller == null) {
            // 如果为空，设置默认的用户 ID
            userInfo.setId(BOSUuid.read("256c221a-0106-1000-e000-10d7c0a813f413B7DE7F"));
        } else {
            // 如果不为空，将调用者的主键转换为 BOSUuid 并设置为用户 ID
            userInfo.setId(BOSUuid.read(caller.toString()));
        }

        // 设置操作日志条目的创建用户信息
        operateLogEntryInfo.setCreateUser(userInfo);

        // 调用父类的保存方法完成保存操作
        return super._save(ctx, model);
    }
}