函件模板二开lv1.0
This commit is contained in:
parent
ea50ab9820
commit
b36597ab05
|
@ -1,14 +1,119 @@
|
||||||
package shkd.repc.rebm.formplugin;
|
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.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 kd.sdk.plugin.Plugin;
|
||||||
|
import shkd.repc.rebm.formplugin.fieldinsert.entity.ModelType;
|
||||||
|
import shkd.repc.rebm.formplugin.fieldinsert.tool.TextUtil;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动态表单插件
|
* 函件模板解析
|
||||||
* @author LiGuiQiang
|
* @author 李贵强
|
||||||
*/
|
*/
|
||||||
public class CustomFieldInsertPlugin extends AbstractFormPlugin implements Plugin {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,148 @@
|
||||||
|
package shkd.repc.rebm.formplugin;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
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.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.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.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 函件模板生成
|
||||||
|
* @author 李贵强
|
||||||
|
*/
|
||||||
|
public class CustomFieldReplacePlugin extends AbstractFormPlugin implements Plugin {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void propertyChanged(PropertyChangedArgs e) {
|
||||||
|
super.propertyChanged(e);
|
||||||
|
String fieldKey = e.getProperty().getName();
|
||||||
|
if (StringUtils.equals(fieldKey, BidAnnouncementConstant.BIDANNTEMPLATE)) {
|
||||||
|
//获取上游单据所需字段
|
||||||
|
//父页面id
|
||||||
|
Map<String, Object> customParams = this.getView().getFormShowParameter().getCustomParams();
|
||||||
|
Long pkValue = (Long)customParams.get("pkid");
|
||||||
|
//公告模板
|
||||||
|
DynamicObject announcement = (DynamicObject) this.getModel().getValue(BidAnnouncementConstant.BIDANNTEMPLATE);
|
||||||
|
//函件模板
|
||||||
|
DynamicObject correspondence = announcement.getDynamicObject(BidTemplateMangeEntity.TYPE);
|
||||||
|
//模板类型名称
|
||||||
|
String name = correspondence.getString(BidTemplateTypeEntity.NAME);
|
||||||
|
ModelType type = ModelType.fromString(name);
|
||||||
|
//获取扩展字段上添加字段
|
||||||
|
DynamicObject extendedDynamic = BusinessDataServiceHelper.loadSingle("qeug_insertfield", (new QFilter("number", QCP.equals, type.toString())).toArray());
|
||||||
|
if (null != extendedDynamic) {
|
||||||
|
DynamicObjectCollection insertEntry = extendedDynamic.getDynamicObjectCollection("qeug_entryentity");
|
||||||
|
if (null != insertEntry && insertEntry.size() != 0) {
|
||||||
|
Map<String, String> replacements = new HashMap<>();
|
||||||
|
for (DynamicObject entry : insertEntry) {
|
||||||
|
//父页面单据标识
|
||||||
|
String sourceId = entry.getString("qeug_sourceid");
|
||||||
|
//父页面字段类型
|
||||||
|
String fieldType = entry.getString("qeug_fieldtype");
|
||||||
|
//父页面字段标识
|
||||||
|
String fieldId = entry.getString("qeug_fieldid");
|
||||||
|
//扩展字段名称
|
||||||
|
String fieldName = entry.getString("qeug_fieldname");
|
||||||
|
String fatherParam = this.getFatherParam(pkValue, sourceId, fieldId,fieldType);
|
||||||
|
replacements.put(fieldName,fatherParam);
|
||||||
|
}
|
||||||
|
RichTextEditor editor = (RichTextEditor) this.getView().getControl(BidAnnouncementConstant.RICHTEXTEDITORAP);
|
||||||
|
String text = editor.getText();
|
||||||
|
if (text!=null){
|
||||||
|
String newText = replacePlaceholders(text, replacements);
|
||||||
|
editor.setText(newText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取父页面字段值
|
||||||
|
* @param pkValue 单据id
|
||||||
|
* @param sourceId 单据标识
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下拉项的名称
|
||||||
|
* @param param 下拉项value
|
||||||
|
* @param sourceId 单据标识
|
||||||
|
* @param fieldId 字段标识
|
||||||
|
* @return name
|
||||||
|
*/
|
||||||
|
public String getParamFromMap(String param,String sourceId,String fieldId){
|
||||||
|
String name="";
|
||||||
|
List<ValueMapItem> comboItems = ((ComboProp) EntityMetadataCache.getDataEntityType(sourceId).getProperty(fieldId)).getComboItems();
|
||||||
|
if (comboItems!=null&&comboItems.size()!=0){
|
||||||
|
for (ValueMapItem comboItem : comboItems) {
|
||||||
|
String value = comboItem.getValue();
|
||||||
|
if (value.equals(param)){
|
||||||
|
name = String.valueOf(comboItem.getName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义的replace方法,通过传入一个Map来替换对应的占位符
|
||||||
|
* @param input 文本
|
||||||
|
* @param replacements 替换值
|
||||||
|
* @return 替换后的文本
|
||||||
|
*/
|
||||||
|
public static String replacePlaceholders(String input, Map<String, String> replacements) {
|
||||||
|
// 正则表达式匹配{xxx}的模式
|
||||||
|
Pattern pattern = Pattern.compile("\\{([^}]+)\\}");
|
||||||
|
Matcher matcher = pattern.matcher(input);
|
||||||
|
|
||||||
|
StringBuffer result = new StringBuffer();
|
||||||
|
|
||||||
|
// 查找所有匹配的占位符并替换
|
||||||
|
while (matcher.find()) {
|
||||||
|
String placeholder = matcher.group(1); // 获取占位符名称
|
||||||
|
String replacement = replacements.get(placeholder); // 获取替换值
|
||||||
|
if (replacement == null) {
|
||||||
|
replacement = ""; // 如果Map中没有替换值,默认替换为空
|
||||||
|
}
|
||||||
|
matcher.appendReplacement(result, replacement);
|
||||||
|
}
|
||||||
|
matcher.appendTail(result);
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package shkd.repc.rebm.formplugin.fieldinsert.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author LiGuiQiang
|
||||||
|
*/
|
||||||
|
|
||||||
|
public enum ModelType {
|
||||||
|
INVITATION("邀请函"),
|
||||||
|
OBJECTION_LETTER("质疑函"),
|
||||||
|
THANK_YOU_LETTER("感谢信"),
|
||||||
|
TENDER_ANNOUNCEMENT("招标公告"),
|
||||||
|
TENDER_RESULT_ANNOUNCEMENT("中标公告"),
|
||||||
|
BID_NOTICE("中标通知书"),
|
||||||
|
BUSINESS_NEGOTIATION_INVITATION("商务谈判邀约函"),
|
||||||
|
EVALUATION_INVITATION("评标邀请函");
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
ModelType(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModelType fromString(String value) {
|
||||||
|
for (ModelType type : ModelType.values()) {
|
||||||
|
if (type.getValue().equals(value)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown model type: " + value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package shkd.repc.rebm.formplugin.fieldinsert.tool;
|
||||||
|
|
||||||
|
|
||||||
|
import kd.bos.form.control.RichTextEditor;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对函件模板中的Text进行改动工具类
|
||||||
|
* @date 2024-11-30
|
||||||
|
* @author LiGuiQiang
|
||||||
|
*/
|
||||||
|
public class TextUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除oldText最后一行,如果最后一行的名称与pString一致
|
||||||
|
* @param editor 编辑模型
|
||||||
|
* @param pString 要插入字段的文本形式
|
||||||
|
*/
|
||||||
|
public static String removeLastLineIfMatch(RichTextEditor editor, String pString) {
|
||||||
|
// 获取oldText内容
|
||||||
|
String oldText = editor.getText();
|
||||||
|
|
||||||
|
// 提取oldText和pString中的最后一行名称部分
|
||||||
|
String oldTextLastLineName = extractLastLineName(oldText);
|
||||||
|
String pStringLastLineName = extractLastLineName(pString);
|
||||||
|
|
||||||
|
// 比较两个名称是否一致
|
||||||
|
if (oldTextLastLineName != null && oldTextLastLineName.equals(pStringLastLineName)) {
|
||||||
|
// 如果一致,则移除oldText的最后一行
|
||||||
|
oldText = removeLastLine(oldText);
|
||||||
|
}
|
||||||
|
|
||||||
|
return oldText;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取最后一行的名称部分(例如 "测试名称.测试:")
|
||||||
|
*/
|
||||||
|
private static String extractLastLineName(String text) {
|
||||||
|
// 假设每行的名称部分格式为:<strong>名称:</strong>
|
||||||
|
String[] lines = text.split("<p");
|
||||||
|
String lastLine = lines[lines.length - 1];
|
||||||
|
|
||||||
|
// 使用正则表达式提取标签中的名称部分
|
||||||
|
String regex = "<strong[^>]*>(.*?):</strong>";
|
||||||
|
Pattern pattern = Pattern.compile(regex);
|
||||||
|
Matcher matcher = pattern.matcher(lastLine);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
// 返回名称部分,如 "测试名称.测试"
|
||||||
|
return matcher.group(1);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除文本中的最后一行
|
||||||
|
* 重写的插入方法和系统自带的冲突,不移除会插入两条数据
|
||||||
|
* @param text 原始文本
|
||||||
|
* @return 正确的原始文本
|
||||||
|
*/
|
||||||
|
private static String removeLastLine(String text) {
|
||||||
|
// 根据<p>标签分割文本
|
||||||
|
String[] lines = text.split("<p");
|
||||||
|
if (lines.length > 1) {
|
||||||
|
// 移除最后一行并返回剩余部分
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 1; i < lines.length - 1; i++) {
|
||||||
|
sb.append("<p").append(lines[i]);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
// 如果没有多余的行,直接返回原始文本
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,16 +19,19 @@ import kd.sdk.plugin.Plugin;
|
||||||
import kd.tmc.tm.business.validate.business.BusinessUnauditOpValidator;
|
import kd.tmc.tm.business.validate.business.BusinessUnauditOpValidator;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标准单据列表插件
|
* 标准单据列表插件
|
||||||
*/
|
*/
|
||||||
public class ExamTaskSummaryListPlugin extends AbstractListPlugin implements Plugin {
|
public class ExamTaskSummaryListPlugin extends AbstractListPlugin implements Plugin {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerListener(EventObject e) {
|
||||||
|
super.registerListener(e);
|
||||||
|
this.addClickListeners();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
|
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
|
||||||
super.afterDoOperation(afterDoOperationEventArgs);
|
super.afterDoOperation(afterDoOperationEventArgs);
|
||||||
|
|
Loading…
Reference in New Issue