package tqq9.lc123.cloud.app.plugin.form.pm; import com.alibaba.nacos.common.utils.StringUtils; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.entity.datamodel.IDataModel; import kd.bos.entity.datamodel.events.ChangeData; import kd.bos.entity.datamodel.events.PropertyChangedArgs; import kd.bos.form.plugin.AbstractFormPlugin; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.sdk.plugin.Plugin; import tqq9.lc123.cloud.app.plugin.form.im.ReturnStockSyncNoticePlugin; import java.util.EventObject; import java.util.Map; /** * 表单通用插件,带出创建人部门,许可证号 * 注册证号:tqq9_registration * 许可证号:tqq9_licenseno * 创建部门:tqq9_dept * 需保持一致 */ public class BaseDataPlugin extends AbstractFormPlugin implements Plugin { private final static Log logger = LogFactory.getLog(BaseDataPlugin.class); @Override public void afterCreateNewData(EventObject e) { super.afterCreateNewData(e); IDataModel model = this.getModel(); DynamicObject dataEntity = model.getDataEntity(); DynamicObject creator = dataEntity.getDynamicObject("creator"); DynamicObject bos_user = BusinessDataServiceHelper.loadSingle("bos_user", new QFilter[]{new QFilter("id", QCP.equals, creator.getLong("id"))}); DynamicObjectCollection entryentity = bos_user.getDynamicObjectCollection("entryentity"); DynamicObject dept=null; for (DynamicObject dynamicObject : entryentity) { boolean ispartjob = dynamicObject.getBoolean("ispartjob"); if (!ispartjob){ dept=dynamicObject.getDynamicObject("dpt"); } } model.setValue("tqq9_dept",dept); this.getView().updateView(); } @Override public void propertyChanged(PropertyChangedArgs e) { super.propertyChanged(e); String key = e.getProperty().getName(); if (StringUtils.equals("tqq9_registration", key)) { StringBuilder stringBuilder=new StringBuilder(); ChangeData[] changeSet = e.getChangeSet(); ChangeData changeData = changeSet[0]; int rowIndex = changeData.getRowIndex(); DynamicObject newValue = (DynamicObject)changeData.getNewValue(); if(newValue!=null){ DynamicObject tqq9_registration = BusinessDataServiceHelper.loadSingle("tqq9_registration", new QFilter[]{new QFilter("id", QCP.equals, newValue.getLong("id"))}); DynamicObjectCollection tqq9_entry = tqq9_registration.getDynamicObjectCollection("tqq9_entry"); for (DynamicObject entry : tqq9_entry) { String supno = entry.getString("tqq9_e_supno"); stringBuilder.append(",").append(supno); } String substring = stringBuilder.substring(1); this.getModel().setValue("tqq9_licenseno",substring,rowIndex); } } this.getView().updateView(); } }