diff --git a/main/java/shkd/repc/repmd/formplugin/ProjectBbFormPlugin.java b/main/java/shkd/repc/repmd/formplugin/ProjectBbFormPlugin.java index bd383b1..2aef3a5 100644 --- a/main/java/shkd/repc/repmd/formplugin/ProjectBbFormPlugin.java +++ b/main/java/shkd/repc/repmd/formplugin/ProjectBbFormPlugin.java @@ -1,10 +1,10 @@ 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.AttachmentDto; import kd.bos.servicehelper.AttachmentServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.web.actions.utils.FilePathUtil; @@ -37,27 +37,65 @@ public class ProjectBbFormPlugin extends AbstractFormPlugin { //附件 AttachmentPanel qeug_attachmentpanelap = this.getView().getControl("attachmentpanel"); List> attachments = qeug_attachmentpanelap.getAttachmentData(); + List> attachmentData1 = null; if (attachments.isEmpty()) { - List> attachmentData = AttachmentServiceHelper.getAttachments("kded_sourcebill", + attachmentData1 = AttachmentServiceHelper.getAttachments("repmd_projectbill", 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(); - } - }); + uploadTargetAttachmentsSameUrl("repmd_projectbill",this.getModel().getDataEntity().getPkValue(), + "attachmentpanel",attachmentData1); + } + String textareafield = (String)this.getModel().getValue("qeug_textareafield");//工程填写:说明 + if (textareafield.isEmpty()) { + this.getModel().setValue("qeug_textareafield", projectbill.getString("qeug_textareafield")); + } + //工程附件 + AttachmentPanel qeug_attachmentpanel = this.getView().getControl("qeug_attachmentpanel"); + List> attachmentss = qeug_attachmentpanel.getAttachmentData(); + List> attachmentData2 = null; + if (attachmentss.isEmpty()) { + attachmentData2 = AttachmentServiceHelper.getAttachments("repmd_projectbill", + projectbill.getLong("id"), "qeug_attachmentpanel"); + uploadTargetAttachmentsSameUrl("repmd_projectbill",this.getModel().getDataEntity().getPkValue(), + "qeug_attachmentpanel",attachmentData2); + } + if (attachmentData1 != null && !attachmentData1.isEmpty() && attachments.isEmpty()) { + this.getView().updateView(); + return; + } + if (attachmentData2 != null && !attachmentData2.isEmpty() && attachmentss.isEmpty()) { + this.getView().updateView(); } } } } + + /** + * 附件拷贝到目标单,源单和目标单共同引用一条附件信息 + * ps:如果删除上游单据,下游单据需要需要自己处理删除bos_attachment中的记录 + * @param targetBillNo 目标单标识 + * @param targetPkid 目标单pkid + * @param attachKey 目标单附件面板标识 + * @param attachments 源附件信息集合 + */ + public static void uploadTargetAttachmentsSameUrl(String targetBillNo, Object targetPkid, String attachKey, List> attachments) { + for (Map attachItem : attachments) { + //获取附件文件的对象 + DynamicObject obj = AttachmentServiceHelper.getAttCreatorByUID((String) attachItem.get("uid")); + //获取附件相关信息 + AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(obj.getPkValue()); + //获取文件的物理路径 + String resourcePath = attachmentDto.getResourcePath(); + attachItem.put("url", resourcePath); + //修改时间格式处理 + attachItem.put("lastModified", null); + //备注 + Object description = attachItem.get("description"); + attachItem.put("description", description); + } + //维护单据和附件的关系(非文件上传) + AttachmentServiceHelper.upload(targetBillNo, targetPkid, attachKey, attachments); + } + /** * 获取文件服务器相对路径 * @param url