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.eas.common.EASBizException;
import com.kingdee.eas.custom.integration.feishu.FeishuI18nResourcesInfo;
import com.kingdee.shr.base.syssetting.api.bean.SHRCodingRule;
import com.kingdee.shr.base.syssetting.util.NumberRuleHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

public class FeishuI18nResourcesControllerBean extends AbstractFeishuI18nResourcesControllerBean {
    private static Logger logger = Logger.getLogger(FeishuI18nResourcesControllerBean.class);


    @Override
    protected IObjectPK _addnew(Context ctx, IObjectValue model) throws BOSException, EASBizException {
        FeishuI18nResourcesInfo info = (FeishuI18nResourcesInfo) model;
        String number = info.getNumber();
        if (StringUtils.isBlank(number)) {
            try {
                SHRCodingRule shrCodingRule = NumberRuleHelper.getCodingNumber(ctx, info, "00000000-0000-0000-0000-000000000000CCE7AED4");
                info.setNumber(shrCodingRule.getCodingRuleNumber());
            } catch (Exception e) {
                e.printStackTrace();
                throw new BOSException("生成飞书多语言资源编码失败，请检查规则定义是否存在 : " + e.getMessage());
            }
        }
        IObjectPK iObjectPK = super._addnew(ctx, model);
        //启用
        _enable(ctx, iObjectPK.toString());
        return iObjectPK;
    }
}