From ae637b2b48aa249a78d12b4e9e2f40b17837af3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=B4=B5=E5=BC=BA?= Date: Wed, 5 Mar 2025 15:13:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BD=E4=BB=B6=E6=A8=A1=E6=9D=BF=E4=BC=98?= =?UTF-8?q?=E5=8C=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formplugin/CustomFieldReplacePlugin.java | 58 ++++++++-- .../formplugin/CustomFieldTemplatePlugin.java | 105 +++++++++++++++++- 2 files changed, 150 insertions(+), 13 deletions(-) diff --git a/main/java/shkd/repc/rebm/formplugin/CustomFieldReplacePlugin.java b/main/java/shkd/repc/rebm/formplugin/CustomFieldReplacePlugin.java index 9bcc9dc..ca231bc 100644 --- a/main/java/shkd/repc/rebm/formplugin/CustomFieldReplacePlugin.java +++ b/main/java/shkd/repc/rebm/formplugin/CustomFieldReplacePlugin.java @@ -2,22 +2,28 @@ package shkd.repc.rebm.formplugin; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.metadata.IDataEntityProperty; import kd.bos.dataentity.utils.StringUtils; import kd.bos.entity.EntityMetadataCache; import kd.bos.entity.ValueMapItem; import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.entity.property.BasedataProp; import kd.bos.entity.property.ComboProp; import kd.bos.form.control.RichTextEditor; import kd.bos.form.plugin.AbstractFormPlugin; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.MetadataServiceHelper; import kd.scm.bid.common.constant.entity.BidAnnouncementConstant; import kd.scm.bid.common.constant.entity.BidTemplateMangeEntity; import kd.scm.bid.common.constant.entity.BidTemplateTypeEntity; import kd.sdk.plugin.Plugin; import shkd.repc.rebm.formplugin.fieldinsert.entity.ModelType; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -83,18 +89,46 @@ public class CustomFieldReplacePlugin extends AbstractFormPlugin implements Plug * @param fieldId 字段标识 * @return 字段值 */ - public String getFatherParam(Long pkValue,String sourceId,String fieldId,String fieldType){ - String result=""; - DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(sourceId, (new QFilter("id", QCP.equals, pkValue)).toArray()); - if (dynamicObject!=null){ - String param = dynamicObject.getString(fieldId); - if (fieldType.equals("下拉列表") || fieldType.equals("单据状态")){ - result = getParamFromMap(param, sourceId, fieldId); - }else{ - return param; - } + public String getFatherParam(Long pkValue, String sourceId, String fieldId, String fieldType) { + if (pkValue == null || sourceId == null || fieldId == null || fieldType == null) { + return ""; } - return result; + + DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(sourceId, + new QFilter("id", QCP.equals, pkValue).toArray()); + if (dynamicObject == null) { + return ""; + } + + switch (fieldType) { + case "ComboProp": + String param = dynamicObject.getString(fieldId); + return getComboPropName(param, sourceId, fieldId); + + case "BasedataProp": + DynamicObject dynamicObj = dynamicObject.getDynamicObject(fieldId); + if (dynamicObj != null) { + IDataEntityProperty property = MetadataServiceHelper.getDataEntityType(sourceId).getProperty(fieldId); + if (property instanceof BasedataProp) { + String displayProp = ((BasedataProp) property).getDisplayProp(); + return dynamicObj.getString(displayProp); + } + } + break; + + case "DecimalProp": + BigDecimal decimalValue = dynamicObject.getBigDecimal(fieldId); + return decimalValue != null ? decimalValue.setScale(2, BigDecimal.ROUND_HALF_UP).toString() : "0.00"; + + case "DateTimeProp": + Date date = dynamicObject.getDate(fieldId); + return date != null ? new SimpleDateFormat("yyyy-MM-dd").format(date) : ""; + + default: + return ""; + } + + return ""; } /** @@ -104,7 +138,7 @@ public class CustomFieldReplacePlugin extends AbstractFormPlugin implements Plug * @param fieldId 字段标识 * @return name */ - public String getParamFromMap(String param,String sourceId,String fieldId){ + public String getComboPropName(String param,String sourceId,String fieldId){ String name=""; List comboItems = ((ComboProp) EntityMetadataCache.getDataEntityType(sourceId).getProperty(fieldId)).getComboItems(); if (comboItems!=null&&comboItems.size()!=0){ diff --git a/main/java/shkd/repc/rebm/formplugin/CustomFieldTemplatePlugin.java b/main/java/shkd/repc/rebm/formplugin/CustomFieldTemplatePlugin.java index 6b7ef66..3ca1510 100644 --- a/main/java/shkd/repc/rebm/formplugin/CustomFieldTemplatePlugin.java +++ b/main/java/shkd/repc/rebm/formplugin/CustomFieldTemplatePlugin.java @@ -2,12 +2,22 @@ package shkd.repc.rebm.formplugin; import kd.bos.bill.AbstractBillPlugIn; import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.entity.LocaleString; +import kd.bos.dataentity.metadata.IDataEntityProperty; +import kd.bos.dataentity.metadata.dynamicobject.DynamicProperty; import kd.bos.dataentity.utils.StringUtils; import kd.bos.entity.datamodel.events.PropertyChangedArgs; -import kd.bos.entity.property.ComboProp; +import kd.bos.entity.property.*; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.field.BasedataEdit; +import kd.bos.metadata.dao.MetaCategory; +import kd.bos.metadata.dao.MetadataDao; +import kd.bos.metadata.form.FormMetadata; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.MetadataServiceHelper; import kd.sdk.plugin.Plugin; /** @@ -19,11 +29,25 @@ public class CustomFieldTemplatePlugin extends AbstractBillPlugIn implements Plu public void propertyChanged(PropertyChangedArgs e) { super.propertyChanged(e); String fieldKey = e.getProperty().getName(); + //模板类型 if (StringUtils.equals(fieldKey, "qeug_templatetype")) { handleSetFieldsValue(); } + //分录源单标识 + else if (StringUtils.equals(fieldKey, "qeug_sourceid")){ + handleSetEntityName(); + } + //分录字段标识 + else if (StringUtils.equals(fieldKey, "qeug_fieldid")){ + handleSetEntryFieldsValue(); + } } + + + /** + * 设置表头字段 + */ private void handleSetFieldsValue() { //获取选中下拉值 String value = (String) this.getModel().getValue("qeug_templatetype"); @@ -73,4 +97,83 @@ public class CustomFieldTemplatePlugin extends AbstractBillPlugIn implements Plu this.getModel().setValue("number",value); this.getModel().setValue("name",displayName+"扩展字段"); } + + /** + * 源单名称赋值 + */ + private void handleSetEntityName() { + //分录数据 + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("qeug_entryentity"); + //选中的分录数据 + EntryGrid entryGrid = this.getControl("qeug_entryentity"); + int[] selectRows = entryGrid.getSelectRows(); + if (selectRows.length==1) { + String entityName = entryEntity.get(selectRows[0]).getString("qeug_sourceid"); + if (!entityName.isEmpty()){ + String id = MetadataDao.getIdByNumber(entityName, MetaCategory.Form); + if (null==id){ + this.getView().showMessage("请填写正确的源单标识!"); + return; + } + FormMetadata formMeta = (FormMetadata) MetadataDao.readRuntimeMeta(id, MetaCategory.Form); + //单据名称 + LocaleString name = formMeta.getName(); + if (null!=name){ + this.getModel().setValue("qeug_sourcename",name); + } + } + } + this.getView().updateView("qeug_entryentity"); + } + + /** + *设置分录字段 + */ + private void handleSetEntryFieldsValue() { + //分录数据 + DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("qeug_entryentity"); + //选中的分录数据 + EntryGrid entryGrid = this.getControl("qeug_entryentity"); + int[] selectRows = entryGrid.getSelectRows(); + if (selectRows.length==1){ + String entityName = entryEntity.get(selectRows[0]).getString("qeug_sourceid"); + if (!entityName.isEmpty()){ + String fieldName = entryEntity.get(selectRows[0]).getString("qeug_fieldid"); + if (!fieldName.isEmpty()){ + IDataEntityProperty property = MetadataServiceHelper.getDataEntityType(entityName).getProperty(fieldName); + if (null==property){ + this.getView().showMessage("源单:"+entityName+"未找到字段:"+fieldName+"信息!"); + return; + } + //字段名 + String localeValue_zh_cn = property.getDisplayName().getLocaleValue_zh_CN(); + this.getModel().setValue("qeug_fieldname",localeValue_zh_cn,selectRows[0]); + //字段类型 + String fieldType; + if (property instanceof TextProp){ + fieldType="TextProp"; + }else if (property instanceof DecimalProp){ + fieldType="DecimalProp"; + }else if (property instanceof DateTimeProp){ + fieldType="DateTimeProp"; + }else if (property instanceof BasedataProp){ + fieldType="BasedataProp"; + }else if (property instanceof ComboProp){ + fieldType="ComboProp"; + }else if (property instanceof BooleanProp){ + fieldType="BooleanProp"; + }else if (property instanceof VarcharProp) { + fieldType = "VarcharProp"; + }else if (property instanceof LongProp){ + fieldType="LongProp"; + }else { + this.getView().showMessage("暂不支持该字段类型!"); + return; + } + this.getModel().setValue("qeug_fieldtype",fieldType,selectRows[0]); + } + } + } + this.getView().updateView("qeug_entryentity"); + } } \ No newline at end of file