119 lines
5.8 KiB
Java
119 lines
5.8 KiB
Java
package shkd.repc.rebm.formplugin;
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
import kd.bos.dataentity.entity.LocaleString;
|
|
import kd.bos.dataentity.utils.StringUtils;
|
|
import kd.bos.entity.datamodel.IDataModel;
|
|
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
|
import kd.bos.form.control.RichTextEditor;
|
|
import kd.bos.form.field.ComboEdit;
|
|
import kd.bos.form.field.ComboItem;
|
|
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.scm.bid.common.constant.bill.OptionalColumnConstant;
|
|
import kd.scm.bid.common.constant.entity.BidTemplateMangeEntity;
|
|
import kd.scm.bid.common.constant.entity.BidTemplateTypeEntity;
|
|
import kd.scm.bid.formplugin.bill.helper.TemplateManageHelper;
|
|
import kd.sdk.plugin.Plugin;
|
|
import shkd.repc.rebm.formplugin.fieldinsert.entity.ModelType;
|
|
import shkd.repc.rebm.formplugin.fieldinsert.tool.TextUtil;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
* 函件模板解析
|
|
* @author 李贵强
|
|
*/
|
|
public class CustomFieldInsertPlugin extends AbstractFormPlugin implements Plugin {
|
|
|
|
|
|
@Override
|
|
public void afterBindData(EventObject e) {
|
|
super.afterBindData(e);
|
|
DynamicObject templateType = (DynamicObject) this.getModel().getValue(BidTemplateMangeEntity.TYPE);
|
|
if (null != templateType) {
|
|
String modelType = templateType.getString(BidTemplateTypeEntity.NUMBER);
|
|
if (null != modelType) {
|
|
//作为基础资料编码
|
|
ModelType type = ModelType.fromString(modelType);
|
|
DynamicObject insertDynamic = BusinessDataServiceHelper.loadSingle("qeug_insertfield", (new QFilter("number", QCP.equals, type.toString())).toArray());
|
|
if (null != insertDynamic) {
|
|
//默认取数
|
|
String defaultField = insertDynamic.getString("qeug_defaultfield");
|
|
ComboEdit comboEdit = this.getView().getControl(BidTemplateMangeEntity.OPTIONALCOLUMN);
|
|
List<ComboItem> modelItems = new ArrayList<>();
|
|
OptionalColumnConstant aColumnConstant = new OptionalColumnConstant(defaultField);
|
|
List<Map<String, String>> columns = aColumnConstant.getColumns();
|
|
|
|
DynamicObjectCollection insertEntry = insertDynamic.getDynamicObjectCollection("qeug_entryentity");
|
|
if (insertEntry != null && insertEntry.size() != 0) {
|
|
//获取扩展字段
|
|
for (DynamicObject entryDynamic : insertEntry) {
|
|
HashMap<String, String> map = new HashMap<>(10);
|
|
//key
|
|
String fieldType = entryDynamic.getString("qeug_fieldtype");
|
|
//value
|
|
String fieldName = entryDynamic.getString("qeug_fieldname");
|
|
map.put(fieldType, fieldName);
|
|
columns.add(map);
|
|
}
|
|
//循环加入插入字段
|
|
for (int i = 0; i < columns.size(); i++) {
|
|
Map<String, String> map2 = (Map) columns.get(i);
|
|
Iterator iterator = map2.entrySet().iterator();
|
|
Map.Entry<String, String> entry = (Map.Entry) iterator.next();
|
|
modelItems.add(new ComboItem(new LocaleString((String) entry.getValue()), (String) entry.getValue()));
|
|
}
|
|
comboEdit.setComboItems(modelItems);
|
|
this.getView().updateView(BidTemplateMangeEntity.OPTIONALCOLUMN);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void propertyChanged(PropertyChangedArgs e) {
|
|
super.propertyChanged(e);
|
|
String fieldKey = e.getProperty().getName();
|
|
if (StringUtils.equals(fieldKey, BidTemplateMangeEntity.OPTIONALCOLUMN)) {
|
|
IDataModel model = this.getModel();
|
|
String label = model.getValue(BidTemplateMangeEntity.OPTIONALCOLUMN).toString();
|
|
if (!"".equals(label)) {
|
|
String value = "";
|
|
DynamicObject modelType = (DynamicObject) model.getValue(BidTemplateMangeEntity.TYPE);
|
|
OptionalColumnConstant aColumnConstant = new OptionalColumnConstant(modelType.getString(BidTemplateTypeEntity.MODELTYPE));
|
|
List<Map<String, String>> columns = aColumnConstant.getColumns();
|
|
|
|
for (int i = 0; i < columns.size(); ++i) {
|
|
Map<String, String> map = (Map) columns.get(i);
|
|
Iterator var9 = map.entrySet().iterator();
|
|
boolean found = false;
|
|
|
|
while (var9.hasNext()) {
|
|
Map.Entry<String, String> entry = (Map.Entry) var9.next();
|
|
if (((String) entry.getValue()).equals(label)) {
|
|
value = (String) entry.getValue();
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!found) {
|
|
value = label;
|
|
}
|
|
}
|
|
|
|
RichTextEditor editor = (RichTextEditor) this.getView().getControl(BidTemplateMangeEntity.RICHEDITOR);
|
|
String pString = TemplateManageHelper.getProjectTag(label, TemplateManageHelper.getSpecialValue(value));
|
|
String newText = TextUtil.removeLastLineIfMatch(editor, pString);
|
|
editor.setText(newText);
|
|
String text = editor.getText() == null ? pString : editor.getText() + pString;
|
|
editor.setText(text);
|
|
}
|
|
}
|
|
}
|
|
} |