Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
78fc72728b
|
|
@ -170,9 +170,9 @@ public class SupplierControl implements Serializable {
|
||||||
rowMsg.add("供应商附件名称为空");
|
rowMsg.add("供应商附件名称为空");
|
||||||
billStatus = false;
|
billStatus = false;
|
||||||
}
|
}
|
||||||
String attachmentUrl = attachmentBean.getAttachmentUrl();
|
String fileString = attachmentBean.getFileString();
|
||||||
if (StringUtils.isEmpty(attachmentUrl)) {
|
if (StringUtils.isEmpty(fileString)) {
|
||||||
rowMsg.add("供应商附件地址为空");
|
rowMsg.add("供应商附件文件流");
|
||||||
billStatus = false;
|
billStatus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +201,7 @@ public class SupplierControl implements Serializable {
|
||||||
bd_supplier.set("tqq9_basedatafield1", tqq9_basedatafield1);
|
bd_supplier.set("tqq9_basedatafield1", tqq9_basedatafield1);
|
||||||
bd_supplier.set("creator", creator);
|
bd_supplier.set("creator", creator);
|
||||||
bd_supplier.set("createtime", createtime);
|
bd_supplier.set("createtime", createtime);
|
||||||
bd_supplier.set("tqq9_textfield33", societycreditcode);
|
bd_supplier.set("societycreditcode", societycreditcode);
|
||||||
bd_supplier.set("tqq9_usagescenarios", tqq9_usagescenarios);
|
bd_supplier.set("tqq9_usagescenarios", tqq9_usagescenarios);
|
||||||
bd_supplier.set("tqq9_datefield5_clrq", tqq9_datefield5_clrq);
|
bd_supplier.set("tqq9_datefield5_clrq", tqq9_datefield5_clrq);
|
||||||
bd_supplier.set("tqq9_textfield210", tqq9_textfield210);
|
bd_supplier.set("tqq9_textfield210", tqq9_textfield210);
|
||||||
|
|
@ -307,17 +307,18 @@ public class SupplierControl implements Serializable {
|
||||||
SupplierModel.DataBean.AttachmentBean attachmentBean = attachment.get(j);
|
SupplierModel.DataBean.AttachmentBean attachmentBean = attachment.get(j);
|
||||||
|
|
||||||
String attachementname = attachmentBean.getAttachmentName();
|
String attachementname = attachmentBean.getAttachmentName();
|
||||||
BigDecimal attachementsize = BigDecimal.ZERO;
|
// BigDecimal attachementsize = BigDecimal.ZERO;
|
||||||
String attachementurl = attachmentBean.getAttachmentUrl();
|
String fileString = attachmentBean.getFileString();
|
||||||
|
// String attachementurl = attachmentBean.getAttachmentUrl();
|
||||||
|
|
||||||
/*DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("tqq9_registration", new QFilter[]{new QFilter("number", QCP.equals, "1134256")});
|
/*DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("tqq9_registration", new QFilter[]{new QFilter("number", QCP.equals, "1134256")});
|
||||||
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments("tqq9_registration", dynamicObject.getPkValue(), "tqq9_attachmentpanelsh");
|
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments("tqq9_registration", dynamicObject.getPkValue(), "tqq9_attachmentpanelsh");
|
||||||
Object url = attachments.get(0).get("url");
|
Object url = attachments.get(0).get("url");
|
||||||
attachementurl= (String) url;*/
|
attachementurl= (String) url;
|
||||||
String uid1 = uid.toString() + index++;
|
String uid1 = uid.toString() + index++;*/
|
||||||
Map<String, Object> uploadres = null;
|
Map<String, Object> uploadres = null;
|
||||||
try {
|
try {
|
||||||
uploadres = AttachmentFileUtil.saveUrlFile2Attchment(uid1, entityName, bd_supplier.getPkValue(), attachementurl, attachementname, attachementsize.toString(), "tqq9_attachmentpanelap");
|
uploadres = AttachmentFileUtil.saveUrlFile2Attchment(entityName, bd_supplier.getPkValue(), attachementname, fileString, "tqq9_attachmentpanelap");
|
||||||
} catch (Exception ee1) {
|
} catch (Exception ee1) {
|
||||||
rowMsg.add("第" + (j + 1) + "条附件信息处理错误,上传失败!The No." + j + 1 + " attachment information processing error." + ee1);
|
rowMsg.add("第" + (j + 1) + "条附件信息处理错误,上传失败!The No." + j + 1 + " attachment information processing error." + ee1);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -274,8 +274,8 @@ public class SupplierModel implements Serializable {
|
||||||
@ApiParam(value = "附件.附件名称", example = "50Kr3",required = true,position = 1)
|
@ApiParam(value = "附件.附件名称", example = "50Kr3",required = true,position = 1)
|
||||||
private String attachmentName;
|
private String attachmentName;
|
||||||
|
|
||||||
@ApiParam(value = "附件.附件地址", example = "hsUsx",required = true,position = 2)
|
@ApiParam(value = "附件文件流", example = "hsUsx",required = true,position = 2)
|
||||||
private String attachmentUrl;
|
private String fileString;
|
||||||
|
|
||||||
public String getAttachmentName() {
|
public String getAttachmentName() {
|
||||||
return attachmentName;
|
return attachmentName;
|
||||||
|
|
@ -285,13 +285,15 @@ public class SupplierModel implements Serializable {
|
||||||
this.attachmentName = attachmentName;
|
this.attachmentName = attachmentName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAttachmentUrl() {
|
public String getFileString() {
|
||||||
return attachmentUrl;
|
return fileString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAttachmentUrl(String attachmentUrl) {
|
public void setFileString(String fileString) {
|
||||||
this.attachmentUrl = attachmentUrl;
|
this.fileString = fileString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiModel
|
@ApiModel
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import kd.bos.logging.Log;
|
||||||
import kd.bos.logging.LogFactory;
|
import kd.bos.logging.LogFactory;
|
||||||
import kd.bos.servicehelper.AttachmentServiceHelper;
|
import kd.bos.servicehelper.AttachmentServiceHelper;
|
||||||
import kd.bos.servicehelper.MetadataServiceHelper;
|
import kd.bos.servicehelper.MetadataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
import kd.bos.util.FileNameUtils;
|
import kd.bos.util.FileNameUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
@ -30,6 +31,104 @@ import java.util.regex.Pattern;
|
||||||
public class AttachmentFileUtil {
|
public class AttachmentFileUtil {
|
||||||
|
|
||||||
private final static Log logger = LogFactory.getLog(AttachmentFileUtil.class);
|
private final static Log logger = LogFactory.getLog(AttachmentFileUtil.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将Base64字符串转换为InputStream
|
||||||
|
*
|
||||||
|
* @param base64String Base64编码的字符串
|
||||||
|
* @return InputStream对象
|
||||||
|
* @throws IllegalArgumentException 如果Base64字符串格式无效
|
||||||
|
*/
|
||||||
|
public static InputStream toInputStream(String base64String) {
|
||||||
|
if (base64String == null || base64String.trim().isEmpty()) {
|
||||||
|
return new ByteArrayInputStream(new byte[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 移除可能的空白字符和换行符
|
||||||
|
String cleanBase64 = base64String.replaceAll("\\s+", "");
|
||||||
|
|
||||||
|
// 解码Base64
|
||||||
|
byte[] decodedBytes = Base64.getDecoder().decode(cleanBase64);
|
||||||
|
|
||||||
|
// 创建InputStream
|
||||||
|
return new ByteArrayInputStream(decodedBytes);
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new IllegalArgumentException("无效的Base64字符串", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param entity 目标单据实体标识
|
||||||
|
* @param pk 目标数据id
|
||||||
|
* @param fileName 带存入文件名称
|
||||||
|
* @param base64Image base64文件流
|
||||||
|
* @param attachKey 附件面板标识
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static Map<String, Object> saveUrlFile2Attchment( String entity, Object pk, String fileName, String base64Image, String attachKey) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
// 示例Base64字符串
|
||||||
|
|
||||||
|
try (InputStream sourceFile = toInputStream(base64Image)) {
|
||||||
|
int sourceFileSize = sourceFile.available();
|
||||||
|
// 上传文件到缓存服务器
|
||||||
|
String tempPath = CacheFactory.getCommonCacheFactory().getTempFileCache().saveAsUrl(fileName, sourceFile, 7200);
|
||||||
|
if (tempPath.contains("tempfile/download.do?configKey")) {
|
||||||
|
//持久化附件到服务器
|
||||||
|
TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache();
|
||||||
|
InputStream in = cache.getInputStream(tempPath);
|
||||||
|
FileService service = FileServiceFactory.getAttachmentFileService();
|
||||||
|
FileService fs = FileServiceFactory.getAttachmentFileService();
|
||||||
|
RequestContext requestContext = RequestContext.get();
|
||||||
|
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
// 生成文件路径-上传附件时远程服务器需要存储文件的位置
|
||||||
|
String pathParam = FileNameUtils.getAttachmentFileName(requestContext.getTenantId(),
|
||||||
|
requestContext.getAccountId(), uuid, fileName);
|
||||||
|
FileItem fileItem = new FileItem(fileName, pathParam, in);
|
||||||
|
// cache.remove(url);
|
||||||
|
// 上传附件到文件服务器
|
||||||
|
tempPath =service.upload(fileItem);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
//将文件缓存中的附件文件上传到正式文件服务器
|
||||||
|
// MainEntityType dataEntityType = MetadataServiceHelper.getDataEntityType(entity);
|
||||||
|
// String appId = dataEntityType.getAppId();
|
||||||
|
// String path = AttachmentServiceHelper.saveTempToFileService(tempPath, appId, entity, pk, fileName);
|
||||||
|
|
||||||
|
//创建附件
|
||||||
|
List<Map<String, Object>> attachItems = new ArrayList<>();
|
||||||
|
Map<String, Object> attachItem = new HashMap<>();
|
||||||
|
attachItem.put("name", fileName);
|
||||||
|
attachItem.put("size", sourceFileSize);
|
||||||
|
|
||||||
|
|
||||||
|
attachItem.put("url", tempPath);
|
||||||
|
attachItem.put("creator", UserServiceHelper.getCurrentUserId());
|
||||||
|
|
||||||
|
|
||||||
|
attachItem.put("lastModified", System.currentTimeMillis());
|
||||||
|
// attachItem.put("uid", uid1);
|
||||||
|
attachItems.add(attachItem);
|
||||||
|
//该方法仅处理数据记录不涉及文件存储。
|
||||||
|
AttachmentServiceHelper.upload(entity, pk, attachKey, attachItems);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
logger.info("附件上传失败,堆栈信息e:", e);
|
||||||
|
result.put("isSuccess", "false");
|
||||||
|
result.put("msg", "上传服务器异常:" + e);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.put("isSuccess", "true");
|
||||||
|
result.put("msg", "附件上传成功");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param entity 目标单据实体标识
|
* @param entity 目标单据实体标识
|
||||||
* @param pk 目标数据id
|
* @param pk 目标数据id
|
||||||
|
|
@ -174,6 +273,7 @@ public class AttachmentFileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据地址获得数据的字节流并转换成大小
|
* 根据地址获得数据的字节流并转换成大小
|
||||||
|
*
|
||||||
* @param strUrl 网络连接地址
|
* @param strUrl 网络连接地址
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
@ -242,6 +342,7 @@ public class AttachmentFileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理url里的中文
|
* 处理url里的中文
|
||||||
|
*
|
||||||
* @param url
|
* @param url
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
@ -282,7 +383,8 @@ public class AttachmentFileUtil {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
fileName = disposition.substring(index + 10, disposition.length() - 1);
|
fileName = disposition.substring(index + 10, disposition.length() - 1);
|
||||||
}
|
}
|
||||||
} else { fileUrl= URLDecoder.decode(fileUrl);//前面中文encode了,这里decode才能保持原文件名
|
} else {
|
||||||
|
fileUrl = URLDecoder.decode(fileUrl);//前面中文encode了,这里decode才能保持原文件名
|
||||||
fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
|
fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue