lb:pdf文件合并功能
This commit is contained in:
parent
5bc6e34327
commit
12142a62d1
@ -7,6 +7,7 @@ import kd.bos.cache.CacheFactory;
|
|||||||
import kd.bos.context.RequestContext;
|
import kd.bos.context.RequestContext;
|
||||||
import kd.bos.dataentity.entity.DynamicObject;
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.dataentity.entity.LocaleString;
|
||||||
import kd.bos.dataentity.resource.ResManager;
|
import kd.bos.dataentity.resource.ResManager;
|
||||||
import kd.bos.entity.EntityMetadataCache;
|
import kd.bos.entity.EntityMetadataCache;
|
||||||
import kd.bos.entity.MainEntityType;
|
import kd.bos.entity.MainEntityType;
|
||||||
@ -21,12 +22,17 @@ import kd.bos.form.control.AttachmentPanel;
|
|||||||
import kd.bos.form.control.Control;
|
import kd.bos.form.control.Control;
|
||||||
import kd.bos.form.control.EntryGrid;
|
import kd.bos.form.control.EntryGrid;
|
||||||
import kd.bos.form.events.AfterDoOperationEventArgs;
|
import kd.bos.form.events.AfterDoOperationEventArgs;
|
||||||
|
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.lang.Lang;
|
||||||
import kd.bos.metadata.dao.MetaCategory;
|
import kd.bos.metadata.dao.MetaCategory;
|
||||||
import kd.bos.metadata.dao.MetadataDao;
|
import kd.bos.metadata.dao.MetadataDao;
|
||||||
import kd.bos.metadata.form.ControlAp;
|
import kd.bos.metadata.form.ControlAp;
|
||||||
import kd.bos.metadata.form.FormMetadata;
|
import kd.bos.metadata.form.FormMetadata;
|
||||||
import kd.bos.metadata.form.control.AttachmentPanelAp;
|
import kd.bos.metadata.form.control.AttachmentPanelAp;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
import kd.bos.servicehelper.user.UserServiceHelper;
|
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
import kd.sdk.plugin.Plugin;
|
import kd.sdk.plugin.Plugin;
|
||||||
@ -49,6 +55,25 @@ public class PDFMergeDynamicPlugin extends AbstractFormPlugin implements Plugin
|
|||||||
@Override
|
@Override
|
||||||
public void afterCreateNewData(EventObject e) {
|
public void afterCreateNewData(EventObject e) {
|
||||||
super.afterCreateNewData(e);
|
super.afterCreateNewData(e);
|
||||||
|
IFormView parentView = this.getView().getParentView();
|
||||||
|
String parentFormName = parentView.getModel().getDataEntity().getDataEntityType().getName();
|
||||||
|
DynamicObject orgBillObject = BusinessDataServiceHelper.loadSingle("bos_entityobject",
|
||||||
|
new QFilter[]{new QFilter("number", QCP.equals, parentFormName)});
|
||||||
|
this.getView().getModel().setValue("yem_srcentity",orgBillObject);
|
||||||
|
this.getView().setEnable(false,"yem_srcentity");
|
||||||
|
Map<String,String> attachControl = getAttachControl(parentFormName);
|
||||||
|
Set<String> attachControlKey = attachControl.keySet();
|
||||||
|
// 初始化 [目标面板]下拉列表项集合
|
||||||
|
String currLCId = Lang.get().toString();// 获取当前语言代码
|
||||||
|
List<ComboItem> entryItems = new ArrayList<>();
|
||||||
|
for (String name : attachControlKey) {
|
||||||
|
ComboItem comboItem = new ComboItem();
|
||||||
|
comboItem.setValue(attachControl.get(name));
|
||||||
|
comboItem.setCaption(new LocaleString(currLCId, "" + name));
|
||||||
|
entryItems.add(comboItem);
|
||||||
|
}
|
||||||
|
ComboEdit yemTargetkey = this.getControl("yem_targetkey");
|
||||||
|
yemTargetkey.setComboItems(entryItems);
|
||||||
initData();
|
initData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,12 +96,13 @@ public class PDFMergeDynamicPlugin extends AbstractFormPlugin implements Plugin
|
|||||||
private void initData(){
|
private void initData(){
|
||||||
IFormView view = this.getView();
|
IFormView view = this.getView();
|
||||||
IDataModel model = view.getModel();
|
IDataModel model = view.getModel();
|
||||||
|
IFormView parentView = this.getView().getParentView();
|
||||||
|
String parentFormName = parentView.getModel().getDataEntity().getDataEntityType().getName();
|
||||||
// 清除分录
|
// 清除分录
|
||||||
model.deleteEntryData("yem_entryentity");
|
model.deleteEntryData("yem_entryentity");
|
||||||
FormShowParameter formShowParameter = view.getFormShowParameter();
|
FormShowParameter formShowParameter = view.getFormShowParameter();
|
||||||
String attachKey = formShowParameter.getCustomParam("srcAttachKey");
|
String attachKey = formShowParameter.getCustomParam("srcAttachKey");
|
||||||
if (YEM.isEmpty(attachKey))return;
|
if (YEM.isEmpty(attachKey))return;
|
||||||
IFormView parentView = view.getParentView();
|
|
||||||
if (parentView == null) return;
|
if (parentView == null) return;
|
||||||
DynamicObject dataEntity = parentView.getModel().getDataEntity();// 源单实体
|
DynamicObject dataEntity = parentView.getModel().getDataEntity();// 源单实体
|
||||||
// 获取附件
|
// 获取附件
|
||||||
@ -106,29 +132,31 @@ public class PDFMergeDynamicPlugin extends AbstractFormPlugin implements Plugin
|
|||||||
super.click(evt);
|
super.click(evt);
|
||||||
IFormView view = this.getView();
|
IFormView view = this.getView();
|
||||||
IFormView parentView = view.getParentView();
|
IFormView parentView = view.getParentView();
|
||||||
|
if (parentView == null)return;
|
||||||
Control source = (Control) evt.getSource();
|
Control source = (Control) evt.getSource();
|
||||||
String key = source.getKey();
|
String key = source.getKey();
|
||||||
// 获取需要合并的文件
|
// 获取需要合并的文件
|
||||||
EntryGrid treeEntryEntity = this.getControl("yem_entryentity");
|
EntryGrid treeEntryEntity = this.getControl("yem_entryentity");
|
||||||
|
String yemTargetkey = (String) view.getModel().getValue("yem_targetkey");
|
||||||
int[] rows = treeEntryEntity.getSelectRows();
|
int[] rows = treeEntryEntity.getSelectRows();
|
||||||
switch(key){
|
switch(key){
|
||||||
case "btnok":
|
case "btnok":
|
||||||
if (rows.length == 0 ){
|
|
||||||
this.getView().showErrorNotification(ResManager.loadKDString("请先选择需要合并的附件!", "PDFMergeDynamicPlugin_0", "yem-base"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (rows.length < 2 ){
|
if (rows.length < 2 ){
|
||||||
this.getView().showErrorNotification(ResManager.loadKDString("请至少选择两个文件进行合并!", "PDFMergeDynamicPlugin_1", "yem-base"));
|
this.getView().showErrorNotification(ResManager.loadKDString("请至少选择两个文件进行合并!", "PDFMergeDynamicPlugin_1", "yem-base"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (YEM.isEmpty(yemTargetkey)){
|
||||||
|
this.getView().showErrorNotification(ResManager.loadKDString("请先选择合并附件的目标面板!", "PDFMergeDynamicPlugin_0", "yem-base"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
Arrays.sort(rows);
|
Arrays.sort(rows);
|
||||||
try {
|
try {
|
||||||
mergeCreateFile(rows);
|
mergeCreateFile(rows,yemTargetkey);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
this.getView().showErrorNotification(ResManager.loadKDString("文件合并失败!", "PDFMergeDynamicPlugin_2", "yem-base"));
|
this.getView().showErrorNotification(ResManager.loadKDString("文件合并失败!", "PDFMergeDynamicPlugin_2", "yem-base"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
view.returnDataToParent("success");
|
view.returnDataToParent(yemTargetkey);
|
||||||
view.close();
|
view.close();
|
||||||
break;
|
break;
|
||||||
case "btncancel":
|
case "btncancel":
|
||||||
@ -144,12 +172,9 @@ public class PDFMergeDynamicPlugin extends AbstractFormPlugin implements Plugin
|
|||||||
|
|
||||||
|
|
||||||
// 合并生成文件并回传至源单
|
// 合并生成文件并回传至源单
|
||||||
private void mergeCreateFile(int[] rows) throws IOException {
|
private void mergeCreateFile(int[] rows ,String yemTargetkey ) throws IOException {
|
||||||
// 获取源单数据
|
// 获取源单数据
|
||||||
FormShowParameter formShowParameter = this.getView().getFormShowParameter();
|
|
||||||
String attachKey = formShowParameter.getCustomParam("targetAttachKey");
|
|
||||||
IFormView parentView = this.getView().getParentView();
|
IFormView parentView = this.getView().getParentView();
|
||||||
if (YEM.isEmpty(attachKey) || parentView == null)return;
|
|
||||||
DynamicObject obj = parentView.getModel().getDataEntity();// 源单实体
|
DynamicObject obj = parentView.getModel().getDataEntity();// 源单实体
|
||||||
SimpleDateFormat format = new SimpleDateFormat("HHmmss");
|
SimpleDateFormat format = new SimpleDateFormat("HHmmss");
|
||||||
String date = format.format(new Date());
|
String date = format.format(new Date());
|
||||||
@ -219,7 +244,7 @@ public class PDFMergeDynamicPlugin extends AbstractFormPlugin implements Plugin
|
|||||||
attachMap.put("creator", user == null ? "金小蝶":user.getString("name"));
|
attachMap.put("creator", user == null ? "金小蝶":user.getString("name"));
|
||||||
attachMap.put("description", "");//description
|
attachMap.put("description", "");//description
|
||||||
attachMap.put("type", "pdf");
|
attachMap.put("type", "pdf");
|
||||||
attachMap.put("fattachmentpanel",attachKey);
|
attachMap.put("fattachmentpanel",yemTargetkey);
|
||||||
attachMap.put("entityNum", "");
|
attachMap.put("entityNum", "");
|
||||||
attachMap.put("billPkId", 0L);
|
attachMap.put("billPkId", 0L);
|
||||||
attachMap.put("billno", "");
|
attachMap.put("billno", "");
|
||||||
@ -227,9 +252,9 @@ public class PDFMergeDynamicPlugin extends AbstractFormPlugin implements Plugin
|
|||||||
attachMap.put("endProgress", true);
|
attachMap.put("endProgress", true);
|
||||||
attachMap.put("filesource", 1);
|
attachMap.put("filesource", 1);
|
||||||
attachDataList.add(attachMap);
|
attachDataList.add(attachMap);
|
||||||
AttachmentPanel control = this.getView().getParentView().getControl(attachKey);
|
AttachmentPanel control = this.getView().getParentView().getControl(yemTargetkey);
|
||||||
control.upload(attachDataList);
|
control.upload(attachDataList);
|
||||||
this.getView().getParentView().updateView(attachKey);
|
this.getView().getParentView().updateView(yemTargetkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -286,19 +311,20 @@ public class PDFMergeDynamicPlugin extends AbstractFormPlugin implements Plugin
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取源单实体所有附件面板的key
|
* 获取源单实体所有附件面板的key\name
|
||||||
* @param formName 源单标识
|
* @param formName 源单标识
|
||||||
* */
|
* */
|
||||||
private List<String> getAttachControl(String formName){
|
private Map<String,String> getAttachControl(String formName){
|
||||||
MainEntityType entityType = EntityMetadataCache.getDataEntityType(formName);
|
MainEntityType entityType = EntityMetadataCache.getDataEntityType(formName);
|
||||||
FormMetadata taskMeta = (FormMetadata) MetadataDao.readRuntimeMeta(MetadataDao.getIdByNumber(
|
FormMetadata taskMeta = (FormMetadata) MetadataDao.readRuntimeMeta(MetadataDao.getIdByNumber(
|
||||||
entityType.getName(), MetaCategory.Form), MetaCategory.Form);
|
entityType.getName(), MetaCategory.Form), MetaCategory.Form);
|
||||||
List<ControlAp<?>> items = taskMeta.getItems();
|
List<ControlAp<?>> items = taskMeta.getItems();
|
||||||
// 附件面板标识集合。
|
// 附件面板标识集合。
|
||||||
List<String> attachmentPanelAp = new ArrayList<>();
|
Map<String,String> attachmentPanelAp = new HashMap<>();
|
||||||
items.forEach(item ->{
|
items.forEach(item ->{
|
||||||
if(item instanceof AttachmentPanelAp){
|
if(item instanceof AttachmentPanelAp){
|
||||||
attachmentPanelAp.add(item.getKey());
|
AttachmentPanelAp attachmentPanel = (AttachmentPanelAp) item;
|
||||||
|
attachmentPanelAp.put(String.valueOf(attachmentPanel.getName()),attachmentPanel.getKey());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return attachmentPanelAp;
|
return attachmentPanelAp;
|
||||||
|
Loading…
Reference in New Issue
Block a user