package nckd.jxccl.opmc.pm.plugin.form;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;

import java.util.EventObject;

/**
 * @ClassName: ImportKpiImportTemplateFormPlugin
 * @Description: 绩效结果导入模板表单插件
 * @Author: PJJ
 * @Date: 2026/1/6 下午5:13
 * @Version: 1.0
 */
public class ImportKpiImportTemplateFormPlugin extends AbstractFormPlugin{
    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);
        //设置默认数据
        createDefaultRow();
    }

    private void createDefaultRow() {
        //查询考核维度项目 中 非考核项目数据
        QFilter qFilter = new QFilter("nckd_check", QCP.equals, false);
        qFilter.and("status",QCP.equals,"C");
        qFilter.and("enable",QCP.equals,"1");
        DynamicObject[] examineDimension = BusinessDataServiceHelper.load("nckd_examine_dimension", "number,name,nckd_check,nckd_datatype", qFilter.toArray(),"number");
        //赋值非考核项目分录行
        DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("nckd_outimptplentry");
        for (DynamicObject obj : examineDimension) {
            DynamicObject row = entryEntity.addNew();
            row.set("nckd_textfield",">>");
            row.set("nckd_examine_dimension",obj);
            row.set("nckd_examinename",obj.getString("name"));
            row.set("nckd_examineid",obj.getLong("id"));
            row.set("nckd_examinenumber",obj.getString("number"));
            row.set("nckd_datatype",obj.getDynamicObject("nckd_datatype"));
            row.set("nckd_check",false);
        }
    }
}
