|
|
@@ -1,11 +1,22 @@
|
|
|
package nckd.base.common.utils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import kd.bos.bos.servicehelper.ServiceFactory;
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.exception.KDBizException;
|
|
|
import kd.bos.fileservice.FileService;
|
|
|
import kd.bos.fileservice.FileServiceFactory;
|
|
|
+import kd.bos.servicehelper.workflow.WorkflowServiceHelper;
|
|
|
+import kd.bos.workflow.component.approvalrecord.IApprovalRecordGroup;
|
|
|
+import kd.bos.workflow.component.approvalrecord.IApprovalRecordItem;
|
|
|
+import kd.bos.workflow.engine.TaskService;
|
|
|
+import kd.bos.workflow.engine.WfUtils;
|
|
|
+import kd.bos.workflow.engine.impl.persistence.entity.task.component.ApprovalRecordItem;
|
|
|
+import kd.bos.workflow.service.WorkflowService;
|
|
|
+import nckd.base.common.config.ResCodeConfig;
|
|
|
+import nckd.base.common.constant.BaseFieldConst;
|
|
|
import nckd.base.common.constant.OperationKeyConst;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.io.*;
|
|
|
@@ -37,6 +48,10 @@ public class GzwCommonUtils {
|
|
|
*/
|
|
|
public static File createZipFile(String orgCode, String ver, String cusDateStr, Map<String, Object> xmlMap,
|
|
|
List<File> billAttrFileList, String apiCode) {
|
|
|
+ //单据XMl参数为空
|
|
|
+ if (xmlMap.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
List<File> xmlFileList = new ArrayList<>();
|
|
|
//生成单据数据XML文件
|
|
|
for (Map.Entry<String, Object> entry : xmlMap.entrySet()) {
|
|
|
@@ -73,6 +88,106 @@ public class GzwCommonUtils {
|
|
|
return GzwCommonUtils.saveXmlToFile(GzwXmlUtils.generateXml(dataList), xmlFileName);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置资源代号XML参数
|
|
|
+ *
|
|
|
+ * @param config 资源代号配置信息
|
|
|
+ * @param xmlMap 当前组织下所有的xml文件
|
|
|
+ * @param datasetData 当前资源代号XML参数
|
|
|
+ */
|
|
|
+ public static void setResCodeData(ResCodeConfig config, Map<String, Object> xmlMap, List<LinkedHashMap<String, Object>> datasetData) {
|
|
|
+ // 资源代号
|
|
|
+ String resCode = config.getResCode();
|
|
|
+ //获取XMLMap已生成的动态参数
|
|
|
+ List<LinkedHashMap<String, Object>> existingData =
|
|
|
+ (List<LinkedHashMap<String, Object>>) xmlMap.getOrDefault(resCode, new ArrayList<>());
|
|
|
+ //单据数据资源代号相同数据XML合并至一起
|
|
|
+ existingData.addAll(datasetData);
|
|
|
+ xmlMap.put(resCode, existingData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param bill 单据
|
|
|
+ * @param auditResMap 业务审批记录资源代号信息
|
|
|
+ * @param dataFlag 数据标识
|
|
|
+ * @param org 单据组织
|
|
|
+ * @param auditResCode 业务审批记录资源代号
|
|
|
+ * @param xmlMap 单据XML参数
|
|
|
+ */
|
|
|
+ public static void getBillApprovalRecordsData(DynamicObject bill, Map<String, String> auditResMap, String dataFlag,
|
|
|
+ DynamicObject org, String auditResCode, Map<String, Object> xmlMap) {
|
|
|
+
|
|
|
+ //获取单据审批记录
|
|
|
+ List<IApprovalRecordGroup> approvalRecords = WorkflowServiceHelper.getApprovalRecords(bill.getDynamicObjectType().getName(), bill.getPkValue().toString(), false);
|
|
|
+ if(ObjectUtils.isEmpty(approvalRecords)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //将审批记录格式化为map对象
|
|
|
+ List<Map<String, Object>> approvalRecordForFormat = getApprovalRecordForFormat(approvalRecords);
|
|
|
+
|
|
|
+ Map<String, Object> fixedData = GzwCommonUtils.getFixedData(auditResMap, org, dataFlag);
|
|
|
+
|
|
|
+ //当前附件表资源代号对应的XMl参数信息
|
|
|
+ List<LinkedHashMap<String, Object>> existingAttachData =
|
|
|
+ (List<LinkedHashMap<String, Object>>) xmlMap.getOrDefault(auditResCode, new ArrayList<>());
|
|
|
+
|
|
|
+ for (int i = 0; i < approvalRecordForFormat.size(); i++) {
|
|
|
+ Map<String, Object> map = approvalRecordForFormat.get(i);
|
|
|
+
|
|
|
+ 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.putAll(fixedData);
|
|
|
+ existingAttachData.add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新审批记录XML参数
|
|
|
+ xmlMap.put(auditResCode, existingAttachData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将单据附件信息转成动态参数及File文件
|
|
|
+ *
|
|
|
+ * @param billAttrMap 所有单据附件信息
|
|
|
+ * @param bill 当前单据
|
|
|
+ * @param attrResMap 业务招待附件表资源代号信息
|
|
|
+ * @param dataFlag 数据标识
|
|
|
+ * @param org 单据组织
|
|
|
+ * @param allAttachFiles 当前组织下所有的附件信息
|
|
|
+ * @param attrResCode 附件表资源代号
|
|
|
+ * @param xmlMap 当前组织下所有的xml文件
|
|
|
+ */
|
|
|
+ public static void getBillAttrDataAndFile(Map<String, List<Map<String, Object>>> billAttrMap, DynamicObject bill,
|
|
|
+ Map<String, String> attrResMap, String dataFlag, DynamicObject org,
|
|
|
+ List<File> allAttachFiles, String attrResCode, Map<String, Object> xmlMap) {
|
|
|
+ // 获取当前单据附件信息
|
|
|
+ List<Map<String, Object>> billAttachments = billAttrMap.getOrDefault(
|
|
|
+ bill.getString("id"),
|
|
|
+ Collections.emptyList()
|
|
|
+ );
|
|
|
+ if (billAttachments.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //当前附件表资源代号对应的XMl参数信息
|
|
|
+ List<LinkedHashMap<String, Object>> existingAttachData =
|
|
|
+ (List<LinkedHashMap<String, Object>>) xmlMap.getOrDefault(attrResCode, new ArrayList<>());
|
|
|
+
|
|
|
+ //将单据附件信息转成动态参数及File文件
|
|
|
+ GzwCommonUtils.getBillAttrDataAndFile(billAttachments, allAttachFiles, existingAttachData,
|
|
|
+ GzwCommonUtils.getFixedData(attrResMap, org, dataFlag));
|
|
|
+
|
|
|
+ //更新附件XML参数
|
|
|
+ xmlMap.put(attrResCode, existingAttachData);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param attachments 单据附件信息
|
|
|
* @param billAttrFileList 单据附件File文件
|
|
|
@@ -335,4 +450,96 @@ public class GzwCommonUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取审批记录格式化 参考按钮查看审批记录的实现
|
|
|
+ */
|
|
|
+ public static List<Map<String, Object>> getApprovalRecordForFormat(List<IApprovalRecordGroup> approvalRecordGroups) {
|
|
|
+ if (null != approvalRecordGroups && !approvalRecordGroups.isEmpty()) {
|
|
|
+ List<Map<String, Object>> approvalRecordList = new ArrayList<>(approvalRecordGroups.size() * 2);
|
|
|
+ Map<String, Object> approvalRecordMap = null;
|
|
|
+ List<IApprovalRecordItem> items = null;
|
|
|
+ String activityName = null;
|
|
|
+ List<IApprovalRecordGroup> approvalRecordItemsForCallActivities = null;
|
|
|
+ List<Map<String, Object>> approvalRecordItemsForCallActivityList = null;
|
|
|
+ String message = null;
|
|
|
+ String messageForAddSign = null;
|
|
|
+ ApprovalRecordItem recordItem = null;
|
|
|
+ Iterator<IApprovalRecordGroup> parentIterator = approvalRecordGroups.iterator();
|
|
|
+
|
|
|
+ label120:
|
|
|
+ while (true) {
|
|
|
+ IApprovalRecordGroup group;
|
|
|
+ do {
|
|
|
+ do {
|
|
|
+ do {
|
|
|
+ if (!parentIterator.hasNext()) {
|
|
|
+ return approvalRecordList;
|
|
|
+ }
|
|
|
+
|
|
|
+ group = (IApprovalRecordGroup) parentIterator.next();
|
|
|
+ } while (null == group);
|
|
|
+ items = group.getChildren();
|
|
|
+ } while (null == items);
|
|
|
+ } while (items.isEmpty());
|
|
|
+
|
|
|
+ Iterator<IApprovalRecordItem> childrenIterator = items.iterator();
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ while (true) {
|
|
|
+ IApprovalRecordItem item;
|
|
|
+ do {
|
|
|
+ if (!childrenIterator.hasNext()) {
|
|
|
+ continue label120;
|
|
|
+ }
|
|
|
+
|
|
|
+ item = (IApprovalRecordItem) childrenIterator.next();
|
|
|
+ } while (null == item);
|
|
|
+
|
|
|
+ recordItem = (ApprovalRecordItem) item;
|
|
|
+ if (recordItem.isCallActivity()) {
|
|
|
+ approvalRecordItemsForCallActivities = getTaskService().queryApprovalRecord(Long.valueOf(recordItem.getProcInstId()), (String) null);
|
|
|
+ approvalRecordItemsForCallActivityList = getApprovalRecordForFormat(approvalRecordItemsForCallActivities);
|
|
|
+ if (null != approvalRecordItemsForCallActivityList && !approvalRecordItemsForCallActivityList.isEmpty()) {
|
|
|
+ approvalRecordList.addAll(approvalRecordItemsForCallActivityList);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ approvalRecordMap = new HashMap<>(9);
|
|
|
+ activityName = item.getSubactivityname();
|
|
|
+ String activityId = item.getActivityId();
|
|
|
+ if (WfUtils.isEmpty(activityName)) {
|
|
|
+ activityName = item.getActivityName();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (WfUtils.isEmpty(activityName)) {
|
|
|
+ activityName = group.getActivityName();
|
|
|
+ }
|
|
|
+
|
|
|
+ approvalRecordMap.put("activityname", activityName);
|
|
|
+ approvalRecordMap.put("activityid", activityId);
|
|
|
+ approvalRecordMap.put("assignee", item.getAssignee());
|
|
|
+ approvalRecordMap.put("result", item.getResult());
|
|
|
+ message = item.getMessage();
|
|
|
+ messageForAddSign = item.getAddSignMsg();
|
|
|
+ if (WfUtils.isNotEmpty(messageForAddSign)) {
|
|
|
+ message = WfUtils.isEmpty(message) ? messageForAddSign : message + "\r\n" + messageForAddSign;
|
|
|
+ }
|
|
|
+
|
|
|
+ approvalRecordMap.put("message", null == message ? "" : message.replaceAll("\\<.*?>", ""));
|
|
|
+ approvalRecordMap.put("formatstrtime", "willApproval".equals(recordItem.getHandleState()) ? "" : item.getTime());
|
|
|
+ approvalRecordList.add(approvalRecordMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static TaskService getTaskService() {
|
|
|
+ WorkflowService wfService = (WorkflowService) ServiceFactory.getService(WorkflowService.class);
|
|
|
+ return wfService.getTaskService();
|
|
|
+ }
|
|
|
+
|
|
|
}
|