背景:在单据转换时,附件是不能做值映射的。需要插件处理
//获取单据A主键
Object pkValueA = model.getDataEntity(true).getPkValue();
try {
List<AttDto> attDtoList = new ArrayList<>();
List<Map<String,Object>> list = AttachmentServiceHelper.getAttachments("kdec_bill001",pkValueA,"attachmentpanel");
for (Map<String, Object> stringObjectMap : list) {
Object attPkId = stringObjectMap.get("attPkId");
AttachmentDto attachmentInfoByAttPk = AttachmentServiceHelper.getAttachmentInfoByAttPk(attPkId);
//获取文件的相对路径对应物理表t_bd_materialmftinfo中的FFILEID
String resourcePath = attachmentInfoByAttPk.getResourcePath();
//构建附件数据传输对象
AttDto attDto = new AttDto();
attDto.setPath(resourcePath);
attDto.setAttKey("attachmentpanel");
attDto.setSize((long) AttachmentServiceHelper.getFileSizeByPath(attDto.getPath()));
attDtoList.add(attDto);
}
//绑定到单据B
String pkValueB = "1290532961849967616";
Map<String, Object> map = AttachmentServiceHelper.genBindingParam("kdec_bill001", pkValueB, attDtoList);
AttachmentServiceHelper.bindingAttachment(map);
} catch (Exception ex) {
ex.printStackTrace();
}
ps:附件已经上传到文件服务器后,单据关联附件实际就是操作t_bd_materialmftinfo附件关系物理表,在表中添加一条单据和附件的记录,调用AttachmentServiceHelper.bindingAttachment方法。此时文件服务器中源文件还是只有一份,删除了,单据A和单据B都会找不到相关附件
推荐阅读