|
@@ -429,23 +429,27 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // 2)删除历史附件
|
|
|
+ // 2)相同的单据第二次送入接口,新文件和历史文件重名时,删掉历史文件,新增新文件
|
|
|
+ // 获取历史单据全部附件
|
|
|
List<Map<String, Object>> atts = AttachmentServiceHelper.getAttachments(entityNumber, dynamicObject.getPkValue(),"attachmentpanel");
|
|
|
if (atts.size() > 0) {
|
|
|
- // 获取全部附件
|
|
|
Iterator<Map<String, Object>> iterator = atts.iterator();
|
|
|
// 遍历所有附件
|
|
|
while (iterator.hasNext()) {
|
|
|
Map map2 = iterator.next();
|
|
|
- String formId = map2.get("entityNum").toString();
|
|
|
- Object pkId = map2.get("billPkId"); // 单据id
|
|
|
- Object fileUid = map2.get("uid");
|
|
|
- //从数据库中删除上一次保存的附件
|
|
|
- AttachmentServiceHelper.remove(formId, pkId, fileUid);
|
|
|
+ String oldfileName = map2.get("name").toString();
|
|
|
+ if (attIsExist(allAttachmentsData,oldfileName)) {
|
|
|
+ // 接口送来的附件已经在历史单据中存在,需要删掉历史单据的附件
|
|
|
+ String formId = map2.get("entityNum").toString();
|
|
|
+ Object pkId = map2.get("billPkId"); // 单据id
|
|
|
+ Object fileUid = map2.get("uid");
|
|
|
+ //从数据库中删除上一次保存的附件
|
|
|
+ AttachmentServiceHelper.remove(formId, pkId, fileUid);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 3)附件保存入库
|
|
|
+ // 3)接口送入的附件全部保存入库
|
|
|
if (allAttachmentsData != null) {
|
|
|
Map<String, Object> attachmentInfos = new HashMap<>();
|
|
|
for (Map.Entry<String, List<Map<String,Object>>> entry : allAttachmentsData.entrySet()) {
|
|
@@ -483,4 +487,30 @@ public class ContractbillApiPlugin implements Serializable {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查历史附件文件名是否存在本次接口送入的附件中
|
|
|
+ * @param sendallAttachmentsData 接口送入的附件集合
|
|
|
+ * @param oldfileName 历史附件名称
|
|
|
+ * @return true:存在 ,false:不存在
|
|
|
+ */
|
|
|
+ boolean attIsExist(Map<String, List<Map<String,Object>>> sendallAttachmentsData, String oldfileName) {
|
|
|
+ if (sendallAttachmentsData != null) {
|
|
|
+ for (Map.Entry<String, List<Map<String,Object>>> entry : sendallAttachmentsData.entrySet()) {
|
|
|
+ if ("attachmentpanel".equals(entry.getKey())) {
|
|
|
+ // 取‘附件面板’的附件集合
|
|
|
+ List<Map<String, Object>> fileList = entry.getValue();
|
|
|
+ for (int i= 0; i < fileList.size(); i++) {
|
|
|
+ Map<String, Object> map = fileList.get(i);
|
|
|
+ String newfilename = map.get("fileName").toString();
|
|
|
+ if (oldfileName.equals(newfilename)) {
|
|
|
+ // 接口送入的附件名称,已经存在历史合同单据中,需要删掉历史合同单据的附件
|
|
|
+ return true; // 已存在
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false; // 不存在
|
|
|
+ }
|
|
|
+
|
|
|
}
|