|
@@ -2,11 +2,17 @@ package nckd.base.common.utils;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import kd.bos.bos.servicehelper.ServiceFactory;
|
|
import kd.bos.bos.servicehelper.ServiceFactory;
|
|
|
|
|
+import kd.bos.cache.CacheFactory;
|
|
|
|
|
+import kd.bos.cache.TempFileCache;
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.exception.KDBizException;
|
|
import kd.bos.exception.KDBizException;
|
|
|
import kd.bos.fileservice.FileService;
|
|
import kd.bos.fileservice.FileService;
|
|
|
import kd.bos.fileservice.FileServiceFactory;
|
|
import kd.bos.fileservice.FileServiceFactory;
|
|
|
|
|
+import kd.bos.fileservice.extension.FileServiceExtFactory;
|
|
|
|
|
+import kd.bos.form.IFormView;
|
|
|
|
|
+import kd.bos.mvc.SessionManager;
|
|
|
import kd.bos.servicehelper.workflow.WorkflowServiceHelper;
|
|
import kd.bos.servicehelper.workflow.WorkflowServiceHelper;
|
|
|
|
|
+import kd.bos.url.UrlService;
|
|
|
import kd.bos.workflow.component.approvalrecord.IApprovalRecordGroup;
|
|
import kd.bos.workflow.component.approvalrecord.IApprovalRecordGroup;
|
|
|
import kd.bos.workflow.component.approvalrecord.IApprovalRecordItem;
|
|
import kd.bos.workflow.component.approvalrecord.IApprovalRecordItem;
|
|
|
import kd.bos.workflow.engine.TaskService;
|
|
import kd.bos.workflow.engine.TaskService;
|
|
@@ -20,7 +26,9 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
+import java.nio.file.Files;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -32,6 +40,28 @@ import java.util.*;
|
|
|
*/
|
|
*/
|
|
|
public class GzwCommonUtils {
|
|
public class GzwCommonUtils {
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param sysCtrlParameter 系统参数
|
|
|
|
|
+ * @param zipFile zip文件
|
|
|
|
|
+ * @return API响应参数
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Map<String, Object> pushGzwApi(Map<String, Object> sysCtrlParameter, File zipFile) {
|
|
|
|
|
+ //环境地址
|
|
|
|
|
+ String address = (String) sysCtrlParameter.get("nckd_gzw_address");
|
|
|
|
|
+ //请求路径
|
|
|
|
|
+ String path = (String) sysCtrlParameter.get("nckd_gzw_path");
|
|
|
|
|
+ String url = address + path;
|
|
|
|
|
+ //接口代号
|
|
|
|
|
+ String apiCode = (String) sysCtrlParameter.get("nckd_apicode");
|
|
|
|
|
+ //版本
|
|
|
|
|
+ String ver = (String) sysCtrlParameter.get("nckd_ver");
|
|
|
|
|
+ //客户端标识
|
|
|
|
|
+ String user = (String) sysCtrlParameter.get("nckd_user");
|
|
|
|
|
+ //客户端密码
|
|
|
|
|
+ String password = (String) sysCtrlParameter.get("nckd_password");
|
|
|
|
|
+ return HttpUtils.uploadFile(url, zipFile, apiCode, user, password, ver, zipFile.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* File文件夹相对路径
|
|
* File文件夹相对路径
|
|
|
*/
|
|
*/
|
|
@@ -107,22 +137,21 @@ public class GzwCommonUtils {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- *
|
|
|
|
|
* 将单据审批记录转换成XML参数
|
|
* 将单据审批记录转换成XML参数
|
|
|
*
|
|
*
|
|
|
- * @param bill 单据
|
|
|
|
|
- * @param auditResMap 业务审批记录资源代号信息
|
|
|
|
|
- * @param dataFlag 数据标识
|
|
|
|
|
- * @param org 单据组织
|
|
|
|
|
|
|
+ * @param bill 单据
|
|
|
|
|
+ * @param auditResMap 业务审批记录资源代号信息
|
|
|
|
|
+ * @param dataFlag 数据标识
|
|
|
|
|
+ * @param org 单据组织
|
|
|
* @param auditResCode 业务审批记录资源代号
|
|
* @param auditResCode 业务审批记录资源代号
|
|
|
- * @param xmlMap 单据XML参数
|
|
|
|
|
|
|
+ * @param xmlMap 单据XML参数
|
|
|
*/
|
|
*/
|
|
|
public static void getBillApprovalRecordsData(DynamicObject bill, Map<String, String> auditResMap, String dataFlag,
|
|
public static void getBillApprovalRecordsData(DynamicObject bill, Map<String, String> auditResMap, String dataFlag,
|
|
|
DynamicObject org, String auditResCode, Map<String, Object> xmlMap) {
|
|
DynamicObject org, String auditResCode, Map<String, Object> xmlMap) {
|
|
|
|
|
|
|
|
//获取单据审批记录
|
|
//获取单据审批记录
|
|
|
List<IApprovalRecordGroup> approvalRecords = WorkflowServiceHelper.getApprovalRecords(bill.getDynamicObjectType().getName(), bill.getPkValue().toString(), false);
|
|
List<IApprovalRecordGroup> approvalRecords = WorkflowServiceHelper.getApprovalRecords(bill.getDynamicObjectType().getName(), bill.getPkValue().toString(), false);
|
|
|
- if(ObjectUtils.isEmpty(approvalRecords)){
|
|
|
|
|
|
|
+ if (ObjectUtils.isEmpty(approvalRecords)) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -139,13 +168,13 @@ public class GzwCommonUtils {
|
|
|
Map<String, Object> map = approvalRecordForFormat.get(i);
|
|
Map<String, Object> map = approvalRecordForFormat.get(i);
|
|
|
|
|
|
|
|
LinkedHashMap<String, Object> data = new LinkedHashMap<>();
|
|
LinkedHashMap<String, Object> data = new LinkedHashMap<>();
|
|
|
- data.put("uuid",map.get("activityid"));
|
|
|
|
|
- data.put("biz_uuid",bill.getString(BaseFieldConst.ID));
|
|
|
|
|
- data.put("node_name",map.get("activityname"));
|
|
|
|
|
- data.put("handler",map.get("assignee"));
|
|
|
|
|
- data.put("handle_status",map.get("result"));
|
|
|
|
|
- data.put("handle_time",map.get("formatstrtime"));
|
|
|
|
|
- data.put("handle_opinion",map.get("message"));
|
|
|
|
|
|
|
+ data.put("uuid", map.get("activityid"));
|
|
|
|
|
+ data.put("biz_uuid", bill.getString(BaseFieldConst.ID));
|
|
|
|
|
+ data.put("node_name", map.get("activityname"));
|
|
|
|
|
+ data.put("handler", map.get("assignee"));
|
|
|
|
|
+ data.put("handle_status", map.get("result"));
|
|
|
|
|
+ data.put("handle_time", map.get("formatstrtime"));
|
|
|
|
|
+ data.put("handle_opinion", map.get("message"));
|
|
|
data.putAll(fixedData);
|
|
data.putAll(fixedData);
|
|
|
existingAttachData.add(data);
|
|
existingAttachData.add(data);
|
|
|
}
|
|
}
|
|
@@ -168,7 +197,8 @@ public class GzwCommonUtils {
|
|
|
*/
|
|
*/
|
|
|
public static void getBillAttrDataAndFile(Map<String, List<Map<String, Object>>> billAttrMap, DynamicObject bill,
|
|
public static void getBillAttrDataAndFile(Map<String, List<Map<String, Object>>> billAttrMap, DynamicObject bill,
|
|
|
Map<String, String> attrResMap, String dataFlag, DynamicObject org,
|
|
Map<String, String> attrResMap, String dataFlag, DynamicObject org,
|
|
|
- List<File> allAttachFiles, String attrResCode, Map<String, Object> xmlMap) {
|
|
|
|
|
|
|
+ List<File> allAttachFiles, String attrResCode, Map<String, Object> xmlMap,
|
|
|
|
|
+ String attachmentServer) {
|
|
|
// 获取当前单据附件信息
|
|
// 获取当前单据附件信息
|
|
|
List<Map<String, Object>> billAttachments = billAttrMap.getOrDefault(
|
|
List<Map<String, Object>> billAttachments = billAttrMap.getOrDefault(
|
|
|
bill.getString("id"),
|
|
bill.getString("id"),
|
|
@@ -184,7 +214,7 @@ public class GzwCommonUtils {
|
|
|
|
|
|
|
|
//将单据附件信息转成动态参数及File文件
|
|
//将单据附件信息转成动态参数及File文件
|
|
|
GzwCommonUtils.getBillAttrDataAndFile(billAttachments, allAttachFiles, existingAttachData,
|
|
GzwCommonUtils.getBillAttrDataAndFile(billAttachments, allAttachFiles, existingAttachData,
|
|
|
- GzwCommonUtils.getFixedData(attrResMap, org, dataFlag));
|
|
|
|
|
|
|
+ GzwCommonUtils.getFixedData(attrResMap, org, dataFlag), attachmentServer);
|
|
|
|
|
|
|
|
//更新附件XML参数
|
|
//更新附件XML参数
|
|
|
xmlMap.put(attrResCode, existingAttachData);
|
|
xmlMap.put(attrResCode, existingAttachData);
|
|
@@ -200,7 +230,7 @@ public class GzwCommonUtils {
|
|
|
public static void getBillAttrDataAndFile(List<Map<String, Object>> attachments,
|
|
public static void getBillAttrDataAndFile(List<Map<String, Object>> attachments,
|
|
|
List<File> billAttrFileList,
|
|
List<File> billAttrFileList,
|
|
|
List<LinkedHashMap<String, Object>> attrDataList,
|
|
List<LinkedHashMap<String, Object>> attrDataList,
|
|
|
- Map<String, Object> fixedData) {
|
|
|
|
|
|
|
+ Map<String, Object> fixedData, String attachmentServer) {
|
|
|
if (attachments.isEmpty()) {
|
|
if (attachments.isEmpty()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -211,11 +241,11 @@ public class GzwCommonUtils {
|
|
|
//将单据附件转为File对象
|
|
//将单据附件转为File对象
|
|
|
File file = generateBillAttrToFile(fileMap, attachmentFileService);
|
|
File file = generateBillAttrToFile(fileMap, attachmentFileService);
|
|
|
//重新设置附件信息名称 文件名称添加MD5前缀
|
|
//重新设置附件信息名称 文件名称添加MD5前缀
|
|
|
-// fileMap.put("name",file.getName());
|
|
|
|
|
|
|
+ fileMap.put("name",file.getName());
|
|
|
billAttrFileList.add(file);
|
|
billAttrFileList.add(file);
|
|
|
|
|
|
|
|
//附件动态参数
|
|
//附件动态参数
|
|
|
- LinkedHashMap<String, Object> attrMapData = createBillAttrData(fileMap);
|
|
|
|
|
|
|
+ LinkedHashMap<String, Object> attrMapData = createBillAttrData(fileMap, attachmentServer);
|
|
|
attrMapData.putAll(fixedData);
|
|
attrMapData.putAll(fixedData);
|
|
|
attrDataList.add(attrMapData);
|
|
attrDataList.add(attrMapData);
|
|
|
|
|
|
|
@@ -226,12 +256,13 @@ public class GzwCommonUtils {
|
|
|
* @param fileMap 单据附件信息
|
|
* @param fileMap 单据附件信息
|
|
|
* @return 创建单据附件信息动态参数
|
|
* @return 创建单据附件信息动态参数
|
|
|
*/
|
|
*/
|
|
|
- public static LinkedHashMap<String, Object> createBillAttrData(Map<String, Object> fileMap) {
|
|
|
|
|
|
|
+ public static LinkedHashMap<String, Object> createBillAttrData(Map<String, Object> fileMap, String attachmentServer) {
|
|
|
LinkedHashMap<String, Object> attrMap = new LinkedHashMap<>();
|
|
LinkedHashMap<String, Object> attrMap = new LinkedHashMap<>();
|
|
|
attrMap.put("uuid", fileMap.get("uid"));
|
|
attrMap.put("uuid", fileMap.get("uid"));
|
|
|
attrMap.put("biz_uuid", fileMap.get("billPkId"));
|
|
attrMap.put("biz_uuid", fileMap.get("billPkId"));
|
|
|
attrMap.put("file_name", fileMap.get("name"));
|
|
attrMap.put("file_name", fileMap.get("name"));
|
|
|
- attrMap.put("file_path", fileMap.get("relativeUrl"));
|
|
|
|
|
|
|
+ //TODO mc参数未配置正确
|
|
|
|
|
+ attrMap.put("file_path", attachmentServer + fileMap.get("url").toString().split("path=")[1]);
|
|
|
attrMap.put("file_type", fileMap.get("type"));
|
|
attrMap.put("file_type", fileMap.get("type"));
|
|
|
attrMap.put("create_time", DateUtil.date2str((Date) fileMap.get("lastModified"), DateUtil.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS));
|
|
attrMap.put("create_time", DateUtil.date2str((Date) fileMap.get("lastModified"), DateUtil.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS));
|
|
|
|
|
|
|
@@ -245,17 +276,14 @@ public class GzwCommonUtils {
|
|
|
*/
|
|
*/
|
|
|
public static File generateBillAttrToFile(Map<String, Object> fileMap, FileService attachmentFileService) {
|
|
public static File generateBillAttrToFile(Map<String, Object> fileMap, FileService attachmentFileService) {
|
|
|
String fileName = (String) fileMap.get("name");
|
|
String fileName = (String) fileMap.get("name");
|
|
|
- // 获取相对路径
|
|
|
|
|
|
|
+ // 获取绝对路径
|
|
|
String relativeUrl = (String) fileMap.get("relativeUrl");
|
|
String relativeUrl = (String) fileMap.get("relativeUrl");
|
|
|
|
|
|
|
|
- //MD5
|
|
|
|
|
- String md5 = calculateMD5(relativeUrl);
|
|
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
|
- attachmentFileService.download(relativeUrl, out, null);
|
|
|
|
|
- InputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
|
|
|
|
|
+ //读取两次,单向流第二次读取都是空数据
|
|
|
|
|
+ String md5 = calculateMD5(attachmentFileService.getInputStream(relativeUrl));
|
|
|
File file = null;
|
|
File file = null;
|
|
|
try {
|
|
try {
|
|
|
- file = inputStreamToFile(in, FILEPATH + md5 + "_" + fileName);
|
|
|
|
|
|
|
+ file = inputStreamToFile(attachmentFileService.getInputStream(relativeUrl), FILEPATH + md5 + "_" + fileName);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new KDBizException("附件上传异常" + e.getMessage());
|
|
throw new KDBizException("附件上传异常" + e.getMessage());
|
|
|
}
|
|
}
|
|
@@ -288,8 +316,10 @@ public class GzwCommonUtils {
|
|
|
* @return 获取数据标识( 1 表示新增,2 表示修改,3 表示删除 ),默认为 1
|
|
* @return 获取数据标识( 1 表示新增,2 表示修改,3 表示删除 ),默认为 1
|
|
|
*/
|
|
*/
|
|
|
public static String getDataFlag(String operationKey, DynamicObject obj) {
|
|
public static String getDataFlag(String operationKey, DynamicObject obj) {
|
|
|
- //删除 = 3 ,非删除从数据库取出来得数据则是修改=2,不是从数据库取出的则是新增 = 1
|
|
|
|
|
- return operationKey.equals(OperationKeyConst.DELETE) ? "3" : obj.getDataEntityState().getFromDatabase() ? "2" : "1";
|
|
|
|
|
|
|
+ //删除 = 3 ,非删除从数据库取出来得数据则是修改=2,不是从数据库取出的则是新增 = 1 。 根据数据判断
|
|
|
|
|
+// return operationKey.equals(OperationKeyConst.DELETE) ? "3" : obj.getDataEntityState().getFromDatabase() ? "2" : "1";
|
|
|
|
|
+ //删除 = 3,非删除是否推送国资委为false = 新增 ,true为修改。根据字段值判断
|
|
|
|
|
+ return operationKey.equals(OperationKeyConst.DELETE) ? "3" : obj.getBoolean("nckd_ispush") ? "2" : "1";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -423,24 +453,24 @@ public class GzwCommonUtils {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @param filePath 文件路径
|
|
|
|
|
|
|
+ * @param inputStream 文件路径
|
|
|
* @return md5
|
|
* @return md5
|
|
|
*/
|
|
*/
|
|
|
- public static String calculateMD5(String filePath) {
|
|
|
|
|
- try (InputStream fis = new FileInputStream(filePath)) {
|
|
|
|
|
- // 获取 MD5 MessageDigest 实例
|
|
|
|
|
|
|
+ public static String calculateMD5(InputStream inputStream) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 获取 MD5 MessageDigest 实例
|
|
|
MessageDigest digest = MessageDigest.getInstance("MD5");
|
|
MessageDigest digest = MessageDigest.getInstance("MD5");
|
|
|
|
|
|
|
|
- // 用于保存读取的字节数
|
|
|
|
|
|
|
+ // 用于保存读取的字节数
|
|
|
byte[] byteArray = new byte[1024];
|
|
byte[] byteArray = new byte[1024];
|
|
|
int bytesCount;
|
|
int bytesCount;
|
|
|
|
|
|
|
|
- // 读取文件内容,并更新摘要信息
|
|
|
|
|
- while ((bytesCount = fis.read(byteArray)) != -1) {
|
|
|
|
|
|
|
+ // 读取流内容,并更新摘要信息
|
|
|
|
|
+ while ((bytesCount = inputStream.read(byteArray)) != -1) {
|
|
|
digest.update(byteArray, 0, bytesCount);
|
|
digest.update(byteArray, 0, bytesCount);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 获取文件的 MD5 值,返回的是字节数组,转换成 16 进制数表示byte[] bytes = digest.digest();
|
|
|
|
|
|
|
+ // 获取 MD5 值,返回的是字节数组,转换成 16 进制数表示
|
|
|
byte[] bytes = digest.digest();
|
|
byte[] bytes = digest.digest();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
StringBuilder sb = new StringBuilder();
|
|
|
for (byte b : bytes) {
|
|
for (byte b : bytes) {
|
|
@@ -448,7 +478,7 @@ public class GzwCommonUtils {
|
|
|
}
|
|
}
|
|
|
return sb.toString().toUpperCase();
|
|
return sb.toString().toUpperCase();
|
|
|
} catch (NoSuchAlgorithmException | IOException e) {
|
|
} catch (NoSuchAlgorithmException | IOException e) {
|
|
|
- throw new KDBizException("文件名称生成MD5失败:" + e);
|
|
|
|
|
|
|
+ throw new KDBizException("生成MD5失败:" + e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -544,4 +574,57 @@ public class GzwCommonUtils {
|
|
|
return wfService.getTaskService();
|
|
return wfService.getTaskService();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 后台操作插件获取表单IFormView下载File文件
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param zipFile zip文件
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void download(File zipFile) {
|
|
|
|
|
+ IFormView view = getView();
|
|
|
|
|
+ if (null == view) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ //注册文件服务
|
|
|
|
|
+ TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache();
|
|
|
|
|
+ try {
|
|
|
|
|
+ String tempUrl = cache.saveAsFullUrl(zipFile.getName(), Files.readAllBytes(zipFile.toPath()), 60 * 60 * 4);
|
|
|
|
|
+ view.download(tempUrl);
|
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
|
+ throw new RuntimeException(ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @return 返回表单视图(可能为null)
|
|
|
|
|
+ */
|
|
|
|
|
+ public static IFormView getView() {
|
|
|
|
|
+ // 获取单据页面视图
|
|
|
|
|
+ SessionManager sm = SessionManager.getCurrent();
|
|
|
|
|
+ Field field = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ //获取私有参数
|
|
|
|
|
+ field = sm.getClass().getDeclaredField("ipageCache");
|
|
|
|
|
+ } catch (NoSuchFieldException ex) {
|
|
|
|
|
+ throw new RuntimeException(ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ field.setAccessible(true);
|
|
|
|
|
+ Map<?, ?> sessions = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ //获取私有参数值
|
|
|
|
|
+ sessions = (Map<?, ?>) field.get(sm);
|
|
|
|
|
+ } catch (IllegalAccessException ex) {
|
|
|
|
|
+ throw new RuntimeException(ex);
|
|
|
|
|
+ }
|
|
|
|
|
+ //审批流程无法获取
|
|
|
|
|
+ if(ObjectUtils.isEmpty(sessions)){
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ //取第一个视图,随便取的,不知道是不是当前页面操作的视图,其他场景使用自己考虑,只用来操作插件下载文件
|
|
|
|
|
+ IFormView formView = sm.getView(sessions.keySet().iterator().next().toString());
|
|
|
|
|
+// if (formView == null) {
|
|
|
|
|
+// throw new KDException("获取视图失败");
|
|
|
|
|
+// }
|
|
|
|
|
+ return formView;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|