// // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) // package nckd.fi.er.webapi.utils; import java.security.SecureRandom; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.id.ID; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.attachment.AttachmentFieldServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import nckd.fi.er.common.BillStatusEnum; import nckd.fi.er.webapi.model.BaseDataModel; import nckd.fi.er.webapi.model.BdAttachmentModel; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; public class BdAttachmentUtils { public BdAttachmentUtils() { } public static DynamicObject[] getAttachmentDynamicObject(List uidList) { QFilter filter = new QFilter("uid", "in", uidList); return BusinessDataServiceHelper.load("bd_attachment", "id,number,name,status,creator,modifier,enable,createtime,modifytime,masterid,uid,previewurl,type,tempfile,pageid,description,url,size,sort", filter.toArray()); } public static List getAttachments(List uidList) { DynamicObject[] loads = getAttachmentDynamicObject(uidList); return ArrayUtils.isNotEmpty(loads) ? DoMoConvertUtils.toListModel(loads, new BdAttachmentModel()) : null; } public static Object[] saveAttachments(List attachmentModelList) { if (CollectionUtils.isEmpty(attachmentModelList)) { return null; } else { DynamicObject[] oldAttachmentDynamicObject = getAttachmentDynamicObject((List)attachmentModelList.stream().map(BdAttachmentModel::getUid).collect(Collectors.toList())); Map oldAttachmentMap = new HashMap(0); if (ArrayUtils.isNotEmpty(oldAttachmentDynamicObject)) { oldAttachmentMap = (Map)Arrays.stream(oldAttachmentDynamicObject).collect(Collectors.toMap((d) -> { return d.getString("uid"); }, (d) -> { return d; })); } String uidPre = "rc-upload-" + System.currentTimeMillis() + "-"; int uidNum = (new SecureRandom()).nextInt(100); Date today = new Date(); BaseDataModel userBaseDataModel = new BaseDataModel(); userBaseDataModel.setId(String.valueOf(RequestContext.get().getCurrUserId())); List changeDynamicObjectList = new ArrayList(); List addDynamicObjectList = new ArrayList(); ArrayList addUids = new ArrayList(); Iterator var10 = attachmentModelList.iterator(); while(var10.hasNext()) { BdAttachmentModel attachmentModel = (BdAttachmentModel)var10.next(); String id = attachmentModel.getId(); if (StringUtils.isEmpty(id)) { id = String.valueOf(ID.genLongId()); attachmentModel.setId(id); } String number = attachmentModel.getNumber(); if (StringUtils.isEmpty(number)) { number = UUID.randomUUID().toString(); attachmentModel.setNumber(number); } String name = attachmentModel.getName(); attachmentModel.setCreator(userBaseDataModel); attachmentModel.setModifier(userBaseDataModel); attachmentModel.setModifyTime(today); attachmentModel.setCreateTime(today); String uid = attachmentModel.getUid(); if (StringUtils.isEmpty(uid)) { uid = uidPre + uidNum++; attachmentModel.setUid(uid); } attachmentModel.setType(name != null ? name.substring(name.lastIndexOf(46) + 1) : ""); attachmentModel.setTempFile("1"); String url = attachmentModel.getUrl(); if (url.contains("tempfile/download.do?configKey") && StringUtils.isNotEmpty(name)) { String path = AttachmentFieldServiceHelper.saveTempToFileService(url, id, name); attachmentModel.setUrl(path); } DynamicObject attachmentDynamicObject = (DynamicObject)((Map)oldAttachmentMap).remove(uid); if (null == attachmentDynamicObject) { attachmentDynamicObject = BusinessDataServiceHelper.newDynamicObject("bd_attachment"); DoMoConvertUtils.toDynamicObject(attachmentDynamicObject, attachmentModel); attachmentDynamicObject.set("status", BillStatusEnum.SUBMIT.getValue()); addDynamicObjectList.add(attachmentDynamicObject); addUids.add(attachmentModel.getUid()); } else { attachmentModel.setId(attachmentDynamicObject.getString("id")); BaseDataModel oldUserBaseDataModel = new BaseDataModel(); oldUserBaseDataModel.setId(attachmentDynamicObject.getString("creator.id")); attachmentModel.setCreator(oldUserBaseDataModel); attachmentModel.setCreateTime(attachmentDynamicObject.getDate("createtime")); DoMoConvertUtils.toDynamicObject(attachmentDynamicObject, attachmentModel); attachmentDynamicObject.set("status", BillStatusEnum.SUBMIT.getValue()); changeDynamicObjectList.add(attachmentDynamicObject); } } if (!CollectionUtils.isEmpty(addDynamicObjectList)) { SaveServiceHelper.save((DynamicObject[])addDynamicObjectList.toArray(new DynamicObject[0])); DynamicObject[] newAttachs = getAttachmentDynamicObject(addUids); changeDynamicObjectList.addAll(Arrays.asList(newAttachs)); } if (changeDynamicObjectList.size() > 0) { return SaveServiceHelper.save((DynamicObject[])changeDynamicObjectList.toArray(new DynamicObject[0])); } else { return null; } } } }