package com.kingdee.eas.custom.integration.feishu.app;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.integration.feishu.FeishuApprovalGroupInfo;
import com.kingdee.eas.custom.integration.feishu.FeishuI18nResourcesFactory;
import com.kingdee.eas.custom.integration.feishu.FeishuI18nResourcesInfo;
import com.kingdee.eas.custom.integration.feishu.IFeishuI18nResources;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

public class FeishuApprovalGroupControllerBean extends AbstractFeishuApprovalGroupControllerBean {
    private static Logger logger = Logger.getLogger(FeishuApprovalGroupControllerBean.class);

    @Override
    protected IObjectPK _save(Context ctx, IObjectValue model) throws BOSException, EASBizException {
        FeishuApprovalGroupInfo info = (FeishuApprovalGroupInfo) model;
        FeishuI18nResourcesInfo groupName = info.getGroupName();
        if (groupName == null) {
            throw new BOSException("分组名称不能为空!");
        }
        String name = groupName.getName();
        if (StringUtils.isBlank(name)) {
            IFeishuI18nResources iFeishuI18nResources = FeishuI18nResourcesFactory.getLocalInstance(ctx);
            groupName = iFeishuI18nResources.getFeishuI18nResourcesInfo(new ObjectUuidPK(groupName.getId()));
            name = groupName.getName();
        }
        info.setName(name);
        return super._save(ctx, model);
    }

    @Override
    protected IObjectPK _addnew(Context ctx, IObjectValue model) throws BOSException, EASBizException {
        IObjectPK iObjectPK = super._addnew(ctx, model);
        //启用
        _enable(ctx, iObjectPK.toString());
        return iObjectPK;
    }
}