package yem.wmc.ydn.formplugin.form;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.MessageTypes;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import yem.base.common.utils.YEM;

/**
 * @author 金亮
 * @date 2024/5/7 16:35
 * @relevantfile  测试 使用代码新增《海运状态码》 基础资料
 * @description
 * @versions 1.0
 */
public class TestNewCreateBill extends AbstractFormPlugin {

    @Override
    public void afterDoOperation(AfterDoOperationEventArgs e) {
        super.afterDoOperation(e);
        String key = e.getOperateKey();
        if(key.equals("testnewcreate")){
            DynamicObject entity = this.getModel().getDataEntity(true);
            String name = entity.getDataEntityType().getName();
            DynamicObject bill = BusinessDataServiceHelper.newDynamicObject(name);
            bill.set("number","cs001");
            bill.set("name","cs001");
            bill.set("enable","1");//使用状态
            bill.set("status","C");//数据状态(单据状态)
            bill.set("createorg", YEM.getCurrentOrgId());//创建组织
            bill.set("creator",YEM.getCurrentUserId());//创建人
            bill.set("useorg", YEM.getCurrentOrgId());//业务组织
            bill.set("org", YEM.getCurrentOrgId());//组织
            SaveServiceHelper.save(new DynamicObject[]{bill});
            this.getView().showMessage("新增单据成功,单据编号为："+bill.get("number"),"", MessageTypes.Default);
        }
    }

}
