|
|
@@ -4,13 +4,22 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import kd.bos.bos.servicehelper.ServiceFactory;
|
|
|
import kd.bos.cache.CacheFactory;
|
|
|
import kd.bos.cache.TempFileCache;
|
|
|
+import kd.bos.coderule.api.CodeRuleInfo;
|
|
|
+import kd.bos.context.RequestContext;
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
+import kd.bos.dataentity.metadata.IDataEntityType;
|
|
|
+import kd.bos.dataentity.metadata.clr.DataEntityPropertyCollection;
|
|
|
+import kd.bos.db.DB;
|
|
|
import kd.bos.exception.KDBizException;
|
|
|
import kd.bos.fileservice.FileService;
|
|
|
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.AttachmentServiceHelper;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
|
|
|
import kd.bos.servicehelper.workflow.WorkflowServiceHelper;
|
|
|
import kd.bos.url.UrlService;
|
|
|
import kd.bos.workflow.component.approvalrecord.IApprovalRecordGroup;
|
|
|
@@ -40,6 +49,58 @@ import java.util.*;
|
|
|
*/
|
|
|
public class GzwCommonUtils {
|
|
|
|
|
|
+ /**
|
|
|
+ * @param formId 推送单据标识
|
|
|
+ * @param billNos 推送单据编号
|
|
|
+ * @param isSuccess 是否推送成功
|
|
|
+ * @param pushParam 推送报文
|
|
|
+ * @param returnParam 返回报文
|
|
|
+ * @param file 推送文件
|
|
|
+ * @return 创建推送日志
|
|
|
+ */
|
|
|
+ public static Map<String, Object> createPushLogDynamic(String formId, String billNos, Boolean isSuccess, String pushParam, String returnParam, File file) {
|
|
|
+ Map<String, Object> logMap = new HashMap<>();
|
|
|
+ DynamicObject log = BusinessDataServiceHelper.newDynamicObject("nckd_em_pushlog");
|
|
|
+ Long id = DB.genLongId(formId);
|
|
|
+ CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule(log.getDataEntityType().getName(), log, null);
|
|
|
+ log.set("id", id);
|
|
|
+ log.set("billno", CodeRuleServiceHelper.getNumber(codeRule, log));
|
|
|
+ log.set("billstatus", "C");
|
|
|
+ log.set("nckd_entityobject", formId);
|
|
|
+ log.set("nckd_bizbillnos", billNos);
|
|
|
+ log.set("nckd_pushuser", RequestContext.get().getCurrUserId());
|
|
|
+ log.set("nckd_pushtime", new Date());
|
|
|
+ log.set("nckd_pushstatus", isSuccess ? "success" : "error");
|
|
|
+ log.set("nckd_pushparam", "点击查看报文");
|
|
|
+ log.set("nckd_pushparam_tag", pushParam);
|
|
|
+ log.set("nckd_returnparam", "点击查看报文");
|
|
|
+ log.set("nckd_returnparam_tag", returnParam);
|
|
|
+ logMap.put("log", log);
|
|
|
+ if (file != null) {
|
|
|
+ //保存单据附件面板
|
|
|
+ //注册文件服务
|
|
|
+ TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache();
|
|
|
+ try {
|
|
|
+ String name = file.getName();
|
|
|
+ byte[] bytes = Files.readAllBytes(file.toPath());
|
|
|
+ String tempUrl = cache.saveAsUrl(name, bytes, 60 * 60 * 4);
|
|
|
+ String uid = "rc-upload-" + System.currentTimeMillis();
|
|
|
+ Map<String, Object> attachmentInfoMap = new HashMap<>(1);
|
|
|
+ Map<String, Object> fileInfo = new HashMap<>(8);
|
|
|
+ fileInfo.put("uid", uid);
|
|
|
+ fileInfo.put("url", tempUrl);
|
|
|
+ fileInfo.put("name", name);
|
|
|
+ fileInfo.put("size", bytes.length);
|
|
|
+ fileInfo.put("type", name.split("\\.")[1]);
|
|
|
+ attachmentInfoMap.put("attachmentpanel", Collections.singletonList(fileInfo));
|
|
|
+ logMap.put("logAttr", attachmentInfoMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new KDBizException("生成推送日志失败:" + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return logMap;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param sysCtrlParameter 系统参数
|
|
|
* @param zipFile zip文件
|
|
|
@@ -68,7 +129,7 @@ public class GzwCommonUtils {
|
|
|
public final static String FILEPATH = "gzw/";
|
|
|
|
|
|
/**
|
|
|
- * @param orgCode 企业统一社会信用代码
|
|
|
+ * @param uscc 集团统一社会信用代码
|
|
|
* @param ver 版本号
|
|
|
* @param cusDateStr 当前时间
|
|
|
* @param xmlMap 单据XML动态参数 key=资源代号 value = 动态参数
|
|
|
@@ -76,7 +137,7 @@ public class GzwCommonUtils {
|
|
|
* @param apiCode 接口代号
|
|
|
* @return 将单据数据动态参数生成XML文件,附件转为FIle文件,合并生成zip文件
|
|
|
*/
|
|
|
- public static File createZipFile(String orgCode, String ver, String cusDateStr, Map<String, Object> xmlMap,
|
|
|
+ public static File createZipFile(String uscc, String ver, String cusDateStr, Map<String, Object> xmlMap,
|
|
|
List<File> billAttrFileList, String apiCode) {
|
|
|
//单据XMl参数为空
|
|
|
if (xmlMap.isEmpty()) {
|
|
|
@@ -85,12 +146,12 @@ public class GzwCommonUtils {
|
|
|
List<File> xmlFileList = new ArrayList<>();
|
|
|
//生成单据数据XML文件
|
|
|
for (Map.Entry<String, Object> entry : xmlMap.entrySet()) {
|
|
|
- File xmlFile = GzwCommonUtils.createXMLFile(orgCode, entry.getKey(), ver, cusDateStr, (List<LinkedHashMap<String, Object>>) entry.getValue());
|
|
|
+ File xmlFile = GzwCommonUtils.createXMLFile(uscc, entry.getKey(), ver, cusDateStr, (List<LinkedHashMap<String, Object>>) entry.getValue());
|
|
|
xmlFileList.add(xmlFile);
|
|
|
}
|
|
|
|
|
|
//生成ZIP文件名称
|
|
|
- String zipFileName = GzwCommonUtils.generateFileName(orgCode, apiCode, ver, cusDateStr, GzwXmlUtils.ZIP);
|
|
|
+ String zipFileName = GzwCommonUtils.generateFileName(uscc, apiCode, ver, cusDateStr, GzwXmlUtils.ZIP);
|
|
|
|
|
|
//单据XML文件、单据附件File文件合并生成zip文件
|
|
|
File zip = GzwXmlUtils.createZipWithAttachments(xmlFileList, billAttrFileList, zipFileName);
|
|
|
@@ -103,7 +164,7 @@ public class GzwCommonUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param orgCode 企业统一社会信用代码
|
|
|
+ * @param orgCode 集团统一社会信用代码
|
|
|
* @param resCode 资源代号
|
|
|
* @param ver 版本号
|
|
|
* @param cusDateStr 当前时间
|
|
|
@@ -143,11 +204,12 @@ public class GzwCommonUtils {
|
|
|
* @param auditResMap 业务审批记录资源代号信息
|
|
|
* @param dataFlag 数据标识
|
|
|
* @param org 单据组织
|
|
|
+ * @param uscc 集团社会统一代码
|
|
|
* @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) {
|
|
|
+ DynamicObject org, String uscc, String auditResCode, Map<String, Object> xmlMap) {
|
|
|
|
|
|
//获取单据审批记录
|
|
|
List<IApprovalRecordGroup> approvalRecords = WorkflowServiceHelper.getApprovalRecords(bill.getDynamicObjectType().getName(), bill.getPkValue().toString(), false);
|
|
|
@@ -158,7 +220,7 @@ public class GzwCommonUtils {
|
|
|
//将审批记录格式化为map对象
|
|
|
List<Map<String, Object>> approvalRecordForFormat = getApprovalRecordForFormat(approvalRecords);
|
|
|
|
|
|
- Map<String, Object> fixedData = GzwCommonUtils.getFixedData(auditResMap, org, dataFlag);
|
|
|
+ Map<String, Object> fixedData = GzwCommonUtils.getFixedData(auditResMap, org, uscc, dataFlag);
|
|
|
|
|
|
//当前附件表资源代号对应的XMl参数信息
|
|
|
List<LinkedHashMap<String, Object>> existingAttachData =
|
|
|
@@ -194,11 +256,12 @@ public class GzwCommonUtils {
|
|
|
* @param allAttachFiles 当前组织下所有的附件信息
|
|
|
* @param attrResCode 附件表资源代号
|
|
|
* @param xmlMap 当前组织下所有的xml文件
|
|
|
+ * @param uscc 集团统一社会信用
|
|
|
*/
|
|
|
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,
|
|
|
- String attachmentServer) {
|
|
|
+ String attachmentServer, String uscc) {
|
|
|
// 获取当前单据附件信息
|
|
|
List<Map<String, Object>> billAttachments = billAttrMap.getOrDefault(
|
|
|
bill.getString("id"),
|
|
|
@@ -214,7 +277,7 @@ public class GzwCommonUtils {
|
|
|
|
|
|
//将单据附件信息转成动态参数及File文件
|
|
|
GzwCommonUtils.getBillAttrDataAndFile(billAttachments, allAttachFiles, existingAttachData,
|
|
|
- GzwCommonUtils.getFixedData(attrResMap, org, dataFlag), attachmentServer);
|
|
|
+ GzwCommonUtils.getFixedData(attrResMap, org, uscc, dataFlag), attachmentServer);
|
|
|
|
|
|
//更新附件XML参数
|
|
|
xmlMap.put(attrResCode, existingAttachData);
|
|
|
@@ -241,7 +304,7 @@ public class GzwCommonUtils {
|
|
|
//将单据附件转为File对象
|
|
|
File file = generateBillAttrToFile(fileMap, attachmentFileService);
|
|
|
//重新设置附件信息名称 文件名称添加MD5前缀
|
|
|
- fileMap.put("name",file.getName());
|
|
|
+ fileMap.put("name", file.getName());
|
|
|
billAttrFileList.add(file);
|
|
|
|
|
|
//附件动态参数
|
|
|
@@ -261,7 +324,6 @@ public class GzwCommonUtils {
|
|
|
attrMap.put("uuid", fileMap.get("uid"));
|
|
|
attrMap.put("biz_uuid", fileMap.get("billPkId"));
|
|
|
attrMap.put("file_name", fileMap.get("name"));
|
|
|
- //TODO mc参数未配置正确
|
|
|
attrMap.put("file_path", attachmentServer + fileMap.get("url").toString().split("path=")[1]);
|
|
|
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));
|
|
|
@@ -311,24 +373,48 @@ public class GzwCommonUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param operationKey 操作标识
|
|
|
- * @param obj 业务数据
|
|
|
+ * @param obj 业务数据
|
|
|
* @return 获取数据标识( 1 表示新增,2 表示修改,3 表示删除 ),默认为 1
|
|
|
*/
|
|
|
- public static String getDataFlag(String operationKey, DynamicObject obj) {
|
|
|
- //删除 = 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";
|
|
|
+ public static String getDataFlag(DynamicObject obj,String pushState) {
|
|
|
+ //是否推送
|
|
|
+ boolean isPush = obj.getBoolean("nckd_ispush");
|
|
|
+ //元数据
|
|
|
+ IDataEntityType dataEntityType = obj.getDataEntityType();
|
|
|
+ //字段属性
|
|
|
+ DataEntityPropertyCollection properties = dataEntityType.getProperties();
|
|
|
+ //获取单据状态标识
|
|
|
+ String statusSign = properties.containsKey("status") ? "status" : "billstatus";
|
|
|
+ //获取单据编码
|
|
|
+ String numberSign = properties.containsKey("number") ? "number" : "billno";
|
|
|
+ //单据已审核 且 未推送单据 标识 = 新增。 如果已推送,说明不需要再次推送
|
|
|
+ if ((obj.getString(statusSign).equals("C") || obj.getString(statusSign).equals("E")) && !isPush) {
|
|
|
+ if(pushState.equals("ZCTS")){
|
|
|
+ //设置已推送
|
|
|
+ obj.set("nckd_ispush", Boolean.TRUE);
|
|
|
+ }
|
|
|
+ return "1";
|
|
|
+ }
|
|
|
+ //单据非已审核 且 已推送 标识=删除。 如果未推送,说明数据还未审核过 或者 已进行过删除,也不需要再次推送
|
|
|
+ if (!obj.getString(statusSign).equals("C") && !obj.getString(statusSign).equals("E") && isPush) {
|
|
|
+ if(pushState.equals("ZCTS")){
|
|
|
+ //设置未推送
|
|
|
+ obj.set("nckd_ispush", Boolean.FALSE);
|
|
|
+ }
|
|
|
+ return "3";
|
|
|
+ }
|
|
|
+ //审核发起接口进行新增,反审核接口发起失败,不存在修改操作。
|
|
|
+ throw new KDBizException(String.format("%s,单据编号:%s,不满足推送条件,无法推送", dataEntityType.getDisplayName(), obj.getString(numberSign)));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param resMap 国资委采集平台对应的表名(文档提供)
|
|
|
* @param org 业务单元
|
|
|
- * @param dataFlag 数据标识 ( 1 表示新增,2 表示修改,3 表示删除 ),默认为 1
|
|
|
+ * @param uscc 集团统一社会信用代码
|
|
|
+ * @param dataFlag 数据标识 ( 1 表示新增,2 表示修改,3 表示删除 ),根据单据数据判断,未推送数据推送为1,已推送数据再次推送为2,删除为3
|
|
|
* @return XML固定参数内容 不要动key值,固定参数
|
|
|
*/
|
|
|
- public static Map<String, Object> getFixedData(Map<String, String> resMap, DynamicObject org, String dataFlag) {
|
|
|
+ public static Map<String, Object> getFixedData(Map<String, String> resMap, DynamicObject org, String uscc, String dataFlag) {
|
|
|
//单位编码 统一社会信用代码
|
|
|
String code = org.getString("uniformsocialcreditcode");
|
|
|
//单位名称
|
|
|
@@ -337,11 +423,11 @@ public class GzwCommonUtils {
|
|
|
|
|
|
//资源简称
|
|
|
fixedData.put("resCaption", resMap.get("nckd_rescaption"));
|
|
|
- //上报单位 编 码
|
|
|
+ //资源代号
|
|
|
fixedData.put("resCode", resMap.get("nckd_rescode"));
|
|
|
- //上报单位 编 码
|
|
|
- fixedData.put("EXT_REPORTSOCIALCODE", code);
|
|
|
- //单 位 编 码
|
|
|
+ //上报单位 编 码(集团)
|
|
|
+ fixedData.put("EXT_REPORTSOCIALCODE", uscc);
|
|
|
+ //单 位 编 码(实际业务单据单位)
|
|
|
fixedData.put("EXT_CORPSOCIALCODE", code);
|
|
|
//数据标识
|
|
|
fixedData.put("EXT_DATAFLAG", dataFlag);
|
|
|
@@ -422,7 +508,7 @@ public class GzwCommonUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param orgCode 业务单元.统一社会信用代码
|
|
|
+ * @param orgCode 集团统一社会信用代码
|
|
|
* @param resCode 接口代号/资源代号
|
|
|
* @param ver 版本号
|
|
|
* @param cusDateStr 当前时间
|
|
|
@@ -616,7 +702,7 @@ public class GzwCommonUtils {
|
|
|
throw new RuntimeException(ex);
|
|
|
}
|
|
|
//审批流程无法获取
|
|
|
- if(ObjectUtils.isEmpty(sessions)){
|
|
|
+ if (ObjectUtils.isEmpty(sessions)) {
|
|
|
return null;
|
|
|
}
|
|
|
//取第一个视图,随便取的,不知道是不是当前页面操作的视图,其他场景使用自己考虑,只用来操作插件下载文件
|