diff --git a/main/java/shkd/repc/repmd/formplugin/ProjectBbFormPlugin.java b/main/java/shkd/repc/repmd/formplugin/ProjectBbFormPlugin.java index 12dd8c2..bd383b1 100644 --- a/main/java/shkd/repc/repmd/formplugin/ProjectBbFormPlugin.java +++ b/main/java/shkd/repc/repmd/formplugin/ProjectBbFormPlugin.java @@ -2,11 +2,19 @@ package shkd.repc.repmd.formplugin; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.form.control.AttachmentPanel; import kd.bos.form.plugin.AbstractFormPlugin; +import kd.bos.servicehelper.AttachmentServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.web.actions.utils.FilePathUtil; +import java.io.IOException; import java.math.BigDecimal; +import java.net.URLDecoder; import java.util.EventObject; +import java.util.List; +import java.util.Map; public class ProjectBbFormPlugin extends AbstractFormPlugin { @@ -15,7 +23,7 @@ public class ProjectBbFormPlugin extends AbstractFormPlugin { super.afterBindData(e); Long lastprojectid = (Long)this.getModel().getValue("lastprojectid");//上版本项目ID(修订使用) - if (null != lastprojectid ) { + if (lastprojectid != 0 ) { DynamicObject projectbill = BusinessDataServiceHelper.loadSingle(lastprojectid, "repmd_projectbill"); if (null != projectbill) { BigDecimal qeugDecimalfield5 = (BigDecimal)this.getModel().getValue("qeug_decimalfield5");//改建后可出租面积(㎡) @@ -26,12 +34,39 @@ public class ProjectBbFormPlugin extends AbstractFormPlugin { if (qeugTextfield3.isEmpty()) { this.getModel().setValue("qeug_textfield3", projectbill.getString("qeug_textfield3")); } -// DynamicObjectCollection collection = this.getModel().getDataEntity().getDynamicObjectCollection("attachmentpanel");//附件 -// if (collection.isEmpty()) { -// -// } + //附件 + AttachmentPanel qeug_attachmentpanelap = this.getView().getControl("attachmentpanel"); + List> attachments = qeug_attachmentpanelap.getAttachmentData(); + if (attachments.isEmpty()) { + List> attachmentData = AttachmentServiceHelper.getAttachments("kded_sourcebill", + projectbill.getLong("id"), "attachmentpanel"); + attachmentData.forEach(attach -> { + try { + //源附件数据的lastModified是timestamp,会出现强转long错误在此置null + attach.put("lastModified", null); + //源附件数据的url已经过URL编码,需要在此先解码获取原始下载路径,AttachmentServiceHelper.upload()会进行URL编码 + attach.put("url", getPathfromDownloadUrl(URLDecoder.decode(String.valueOf(attach.get("url")), "UTF-8"))); + //调用AttachmentServiceHelper.upload(formId, pkId, attachKey, attachments)将附件数据上传到目标附件面板 + AttachmentServiceHelper.upload(getView().getEntityId(), getModel().getValue("id"), "attachmentpanel", attachmentData); + + } catch (IOException ex) { + //do something with log. + ex.printStackTrace(); + } + }); + } } } - + } + /** + * 获取文件服务器相对路径 + * @param url + * @return + * @throws IOException + */ + private String getPathfromDownloadUrl(String url) throws IOException { + String path = StringUtils.substringAfter(url, "path="); + path = URLDecoder.decode(path, "UTF-8"); + return FilePathUtil.dealPath(path, "attach"); } }