|
@@ -0,0 +1,449 @@
|
|
|
|
|
+package nckd.base.common.utils;
|
|
|
|
|
+
|
|
|
|
|
+import kd.bos.cache.CacheFactory;
|
|
|
|
|
+import kd.bos.cache.DistributeSessionlessCache;
|
|
|
|
|
+import kd.bos.context.RequestContext;
|
|
|
|
|
+import kd.bos.dataentity.OperateOption;
|
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
+import kd.bos.entity.operate.OperateOptionConst;
|
|
|
|
|
+import kd.bos.entity.operate.interaction.InteractionContext;
|
|
|
|
|
+import kd.bos.entity.operate.result.IOperateInfo;
|
|
|
|
|
+import kd.bos.entity.operate.result.OperationResult;
|
|
|
|
|
+import kd.bos.form.operate.MutexHelper;
|
|
|
|
|
+import kd.bos.logging.Log;
|
|
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
|
|
+import kd.bos.mutex.impl.MutexLockInfo;
|
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
|
+import kd.bos.servicehelper.operation.OperationServiceHelper;
|
|
|
|
|
+import kd.bos.servicehelper.workflow.WorkflowServiceHelper;
|
|
|
|
|
+import nckd.base.common.constant.BaseFieldConst;
|
|
|
|
|
+import nckd.base.common.constant.OperationKeyConst;
|
|
|
|
|
+import nckd.base.common.model.BaseModel;
|
|
|
|
|
+import nckd.base.common.model.BasePageModel;
|
|
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author 许永财-金蝶
|
|
|
|
|
+ * @module 销售管理平台
|
|
|
|
|
+ * @description
|
|
|
|
|
+ * @since 2025/3/5
|
|
|
|
|
+ */
|
|
|
|
|
+public final class WebApiUtils {
|
|
|
|
|
+ private WebApiUtils() {
|
|
|
|
|
+ }
|
|
|
|
|
+ /**log定义**/
|
|
|
|
|
+ private static final Log log = LogFactory.getLog(WebApiUtils.class);
|
|
|
|
|
+ /**缓存**/
|
|
|
|
|
+ static DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache();
|
|
|
|
|
+ /**数字定义**/
|
|
|
|
|
+ private static final int NUM = 43007523;
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 列表查询
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param queryBill queryBill
|
|
|
|
|
+ * @param qFilter qFilter
|
|
|
|
|
+ * @param selectProperties selectProperties
|
|
|
|
|
+ * @param pageNo pageNo
|
|
|
|
|
+ * @param pageSize pageSize
|
|
|
|
|
+ * @param orderBy orderBy
|
|
|
|
|
+ * @param baseModel baseModel
|
|
|
|
|
+ * @return BasePageModel
|
|
|
|
|
+ */
|
|
|
|
|
+ public static BasePageModel queryList(String queryBill, QFilter qFilter, String selectProperties, Integer pageNo, Integer pageSize, String orderBy, BaseModel baseModel) {
|
|
|
|
|
+
|
|
|
|
|
+ DynamicObject[] doArr = BusinessDataServiceHelper.load(queryBill, selectProperties, qFilter.toArray(), orderBy, null == pageNo ? 0 : pageNo - 1, null == pageSize ? 10 : pageSize);
|
|
|
|
|
+
|
|
|
|
|
+ if (null == doArr || doArr.length == 0) {
|
|
|
|
|
+ return new BasePageModel();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Object> listModel = DoMoConvertUtils.toListModel(doArr, baseModel);
|
|
|
|
|
+ return new BasePageModel(pageNo, pageSize, listModel);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static <T> T queryDetail(String queryBill, QFilter qFilter, String selectProperties, T t) {
|
|
|
|
|
+
|
|
|
|
|
+ DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(queryBill, selectProperties, qFilter.toArray());
|
|
|
|
|
+ if (null == dynamicObject) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return DoMoConvertUtils.toModel(dynamicObject, t);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存操作
|
|
|
|
|
+ */
|
|
|
|
|
+ public static OperationResult saveOperate(DynamicObject[] dynamicObjects) {
|
|
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
|
|
+ if (dynamicObjects == null || dynamicObjects.length == 0) {
|
|
|
|
|
+ OperationResult operationResult = new OperationResult();
|
|
|
|
|
+ operationResult.setSuccess(false);
|
|
|
|
|
+ operationResult.setMessage("操作对象不能为空。");
|
|
|
|
|
+ return operationResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ //设置单据生成渠道
|
|
|
|
|
+ setBillChannel(dynamicObjects);
|
|
|
|
|
+ // 设置保存参数,调用目标单保存服务,保存目标单(保存时自动反写源单)
|
|
|
|
|
+ OperateOption saveOption = OperateOption.create();
|
|
|
|
|
+ checkJxdOption(saveOption);
|
|
|
|
|
+ // 不执行警告级别校验器
|
|
|
|
|
+ saveOption.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(true));
|
|
|
|
|
+ // 不显示交互提示,自动执行到底
|
|
|
|
|
+ saveOption.setVariableValue(OperateOptionConst.IGNOREINTERACTION, String.valueOf(true));
|
|
|
|
|
+ // 全部校验通过才保存
|
|
|
|
|
+ saveOption.setVariableValue(OperateOptionConst.STRICTVALIDATION, String.valueOf(true));
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ OperationResult operationResult = OperationServiceHelper.executeOperate("save", dynamicObjects[0].getDataEntityType().getName(), dynamicObjects, saveOption);
|
|
|
|
|
+ log.info("saveOperate cost time:" + (endTime - startTime) + "ms");
|
|
|
|
|
+ return operationResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据用户登录channel 设置单据生成channel
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param dynamicObjects dynamicObjects
|
|
|
|
|
+ */
|
|
|
|
|
+ private static void setBillChannel(DynamicObject[] dynamicObjects) {
|
|
|
|
|
+ String channel = cache.get(getLoginChannelCacheKey(RequestContext.get().getCurrUserId()));
|
|
|
|
|
+ if (StringUtils.isBlank(channel)) {
|
|
|
|
|
+ log.error("未获取用户登录的channel");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (DynamicObject dynamicObject : dynamicObjects) {
|
|
|
|
|
+ if (dynamicObject.containsProperty("channel")) {
|
|
|
|
|
+ dynamicObject.set("channel", channel);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String getLoginChannelCacheKey(Long userId) {
|
|
|
|
|
+ return "lsist.loginchannel_" + userId;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 提交审核合成一步(前提是要保存)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bill
|
|
|
|
|
+ * @param isSubmitIgnoreWf
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public static OperationResult submitAndAuditOperate(DynamicObject bill, boolean isSubmitIgnoreWf) {
|
|
|
|
|
+ List<Object> saveSuccessPkIds = Collections.singletonList(bill.getPkValue());
|
|
|
|
|
+
|
|
|
|
|
+ OperationResult submitResult = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
|
|
+ OperateOption operateOption = OperateOption.create();
|
|
|
|
|
+ if (isSubmitIgnoreWf) {
|
|
|
|
|
+ //只要有WF标识,就不会触发工作流
|
|
|
|
|
+ operateOption.setVariableValue("WF", "TRUE");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 不执行警告级别校验器
|
|
|
|
|
+ operateOption.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(true));
|
|
|
|
|
+ long startSub = System.currentTimeMillis();
|
|
|
|
|
+ submitResult = OperationServiceHelper.executeOperate(OperationKeyConst.SUBMIT, bill.getDataEntityType().getName(), saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ long endsub = System.currentTimeMillis();
|
|
|
|
|
+ log.info("endsub-startSub={}", endsub - startSub);
|
|
|
|
|
+ if (!submitResult.isSuccess()) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_SUBMIT, bill.getDataEntityType().getName(), saveSuccessPkIds.toArray(), OperateOption.create());
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("submit fail cost : ", endTime - startTime + "ms");
|
|
|
|
|
+ return submitResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_SUBMIT, bill.getDataEntityType().getName(), saveSuccessPkIds.toArray(), OperateOption.create());
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (!isSubmitIgnoreWf) {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 如果进入审批流就直接返回给前端,无需走审核操作
|
|
|
|
|
+ */
|
|
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
|
|
+ Boolean existProc = WorkflowServiceHelper.existProcDefByEntityNumber(bill.getDataEntityType().getName());
|
|
|
|
|
+ if (existProc) {
|
|
|
|
|
+ boolean inProcess = false;
|
|
|
|
|
+ int waitTime = 0;
|
|
|
|
|
+ int times = 1;
|
|
|
|
|
+ while (!inProcess) {
|
|
|
|
|
+ log.info("wait wf result:{}", times);
|
|
|
|
|
+ try {
|
|
|
|
|
+ waitTime += 200;
|
|
|
|
|
+ times++;
|
|
|
|
|
+ if (waitTime > 5000) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("等待工作流返回");
|
|
|
|
|
+ Thread.sleep(200);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ log.error("提交审核合成一步(前提是要保存)报错:{}", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ Long processInstanceIdByBusinessKey = WorkflowServiceHelper.getProcessInstanceIdByBusinessKey(saveSuccessPkIds.get(0).toString());
|
|
|
|
|
+ if (processInstanceIdByBusinessKey != null) {
|
|
|
|
|
+ inProcess = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("query wf result cost:" + (endTime - startTime) + "ms");
|
|
|
|
|
+ if (inProcess) {
|
|
|
|
|
+ return submitResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
|
|
+ try {
|
|
|
|
|
+ OperateOption operateOption = OperateOption.create();
|
|
|
|
|
+ // 不执行警告级别校验器
|
|
|
|
|
+ operateOption.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(true));
|
|
|
|
|
+ OperationResult auditResult = OperationServiceHelper.executeOperate(OperationKeyConst.AUDIT, bill.getDataEntityType().getName(), saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ if (!auditResult.isSuccess()) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_AUDIT, bill.getDataEntityType().getName(), saveSuccessPkIds.toArray(), OperateOption.create());
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_SUBMIT, bill.getDataEntityType().getName(), saveSuccessPkIds.toArray(), OperateOption.create());
|
|
|
|
|
+ }
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("audit cost:" + (endTime - startTime) + "ms");
|
|
|
|
|
+ return auditResult;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_AUDIT, bill.getDataEntityType().getName(), saveSuccessPkIds.toArray(), OperateOption.create());
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_SUBMIT, bill.getDataEntityType().getName(), saveSuccessPkIds.toArray(), OperateOption.create());
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存提交合成一步
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bill bill
|
|
|
|
|
+ * @param isSubmitIgnoreWf 提交时是否跳过校验工作流
|
|
|
|
|
+ * @return OperationResult
|
|
|
|
|
+ */
|
|
|
|
|
+ public static OperationResult saveAndSubmitOperate(DynamicObject bill, boolean isSubmitIgnoreWf) {
|
|
|
|
|
+ return saveAndAuditOperate(bill, isSubmitIgnoreWf, false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存提交审核合成一步
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bill bill
|
|
|
|
|
+ * @param isSubmitIgnoreWf 提交时是否跳过校验工作流
|
|
|
|
|
+ * @return OperationResult
|
|
|
|
|
+ */
|
|
|
|
|
+ public static OperationResult saveAndAuditOperate(DynamicObject bill, boolean isSubmitIgnoreWf) {
|
|
|
|
|
+ return saveAndAuditOperate(bill, isSubmitIgnoreWf, true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存提交审核合成一步
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bill bill
|
|
|
|
|
+ * @param isSubmitIgnoreWf 提交时是否跳过校验工作流
|
|
|
|
|
+ * @param isAudit 是否审核
|
|
|
|
|
+ * @return OperationResult
|
|
|
|
|
+ */
|
|
|
|
|
+ public static OperationResult saveAndAuditOperate(DynamicObject bill, boolean isSubmitIgnoreWf, boolean isAudit) {
|
|
|
|
|
+
|
|
|
|
|
+ Object pkValue = bill.getPkValue();
|
|
|
|
|
+ boolean deleteFlag = pkValue == null || Long.parseLong(pkValue.toString()) == 0;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 调用保存操作
|
|
|
|
|
+ */
|
|
|
|
|
+ OperationResult saveResult = WebApiUtils.saveOperate(ArrayUtils.toArray(bill));
|
|
|
|
|
+ if (!saveResult.isSuccess()) {
|
|
|
|
|
+ return saveResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Object> saveSuccessPkIds = saveResult.getSuccessPkIds();
|
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 调用提交操作
|
|
|
|
|
+ */
|
|
|
|
|
+ if (!saveSuccessPkIds.isEmpty()) {
|
|
|
|
|
+ String entityKey = bill.getDataEntityType().getName();
|
|
|
|
|
+ String pkId = saveSuccessPkIds.get(0).toString();
|
|
|
|
|
+ MutexLockInfo lockInfo = new MutexLockInfo(String.valueOf(pkId), null, null, entityKey, OperationKeyConst.MODIFY, true, null);
|
|
|
|
|
+
|
|
|
|
|
+ OperateOption operateOption = OperateOption.create();
|
|
|
|
|
+ checkJxdOption(operateOption);
|
|
|
|
|
+ // 保存成功后干掉互斥锁 这里因为不太清楚锁的扭转状态 所以直接干掉
|
|
|
|
|
+ MutexHelper.release(entityKey, OperationKeyConst.MODIFY, pkId);
|
|
|
|
|
+ OperationResult submitResult = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
|
|
+ if (isSubmitIgnoreWf) {
|
|
|
|
|
+ //只要有WF标识,就不会触发工作流
|
|
|
|
|
+ operateOption.setVariableValue("WF", "TRUE");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 不执行警告级别校验器
|
|
|
|
|
+ operateOption.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(true));
|
|
|
|
|
+ submitResult = OperationServiceHelper.executeOperate(OperationKeyConst.SUBMIT, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ if (!submitResult.isSuccess()) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_SUBMIT, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ if (deleteFlag) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.DELETE, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ MutexHelper.require(lockInfo, stringBuilder);
|
|
|
|
|
+ }
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("submit fail cost : ", endTime - startTime + "ms");
|
|
|
|
|
+ return submitResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_SUBMIT, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ if (deleteFlag) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.DELETE, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 若提交失败 则重新锁上
|
|
|
|
|
+ MutexHelper.require(lockInfo, stringBuilder);
|
|
|
|
|
+ }
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (!isSubmitIgnoreWf) {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 如果进入审批流就直接返回给前端,无需走审核操作
|
|
|
|
|
+ */
|
|
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
|
|
+ Boolean existProc = WorkflowServiceHelper.existProcDefByEntityNumber(entityKey);
|
|
|
|
|
+ if (existProc) {
|
|
|
|
|
+ boolean inProcess = false;
|
|
|
|
|
+ int waitTime = 0;
|
|
|
|
|
+ int times = 1;
|
|
|
|
|
+ while (!inProcess) {
|
|
|
|
|
+ log.info("wait wf result:{}", times);
|
|
|
|
|
+ try {
|
|
|
|
|
+ waitTime += 200;
|
|
|
|
|
+ times++;
|
|
|
|
|
+ if (waitTime > 5000) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ Thread.sleep(200);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ log.error("保存提交审核合成一步报错:{}", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ Long processInstanceIdByBusinessKey = WorkflowServiceHelper.getProcessInstanceIdByBusinessKey(pkId);
|
|
|
|
|
+ if (processInstanceIdByBusinessKey != null) {
|
|
|
|
|
+ inProcess = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("query wf result cost:" + (endTime - startTime) + "ms");
|
|
|
|
|
+ if (inProcess) {
|
|
|
|
|
+ return submitResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (isAudit) {
|
|
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
|
|
+ try {
|
|
|
|
|
+ OperationResult auditResult = OperationServiceHelper.executeOperate(OperationKeyConst.AUDIT, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ long auditEndTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("audit operate cost:" + (auditEndTime - startTime) + "ms");
|
|
|
|
|
+ if (!auditResult.isSuccess()) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_AUDIT, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_SUBMIT, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ if (deleteFlag) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.DELETE, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ MutexHelper.require(lockInfo, stringBuilder);
|
|
|
|
|
+ }
|
|
|
|
|
+ long unAuditEnd = System.currentTimeMillis();
|
|
|
|
|
+ log.info("audit operate cost:" + (unAuditEnd - startTime) + "ms");
|
|
|
|
|
+ return auditResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_AUDIT, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.UN_SUBMIT, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ if (deleteFlag) {
|
|
|
|
|
+ OperationServiceHelper.executeOperate(OperationKeyConst.DELETE, entityKey, saveSuccessPkIds.toArray(), operateOption);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 若审核失败 则重新锁上
|
|
|
|
|
+ MutexHelper.require(lockInfo, stringBuilder);
|
|
|
|
|
+ }
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ }
|
|
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
|
|
+ log.info("audit cost:" + (endTime - startTime) + "ms");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return saveResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取组织id
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param org org
|
|
|
|
|
+ * @return {@link Long}
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Long getOrg(String org) {
|
|
|
|
|
+ return StringUtils.isBlank(org) ? RequestContext.get().getOrgId() : Long.parseLong(org);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 审核
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bill
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public static OperationResult auditOperate(DynamicObject bill) {
|
|
|
|
|
+ long id = bill.getLong(BaseFieldConst.ID);
|
|
|
|
|
+ Long[] ids = {id};
|
|
|
|
|
+ OperateOption operateOption = OperateOption.create();
|
|
|
|
|
+ // 不执行警告级别校验器
|
|
|
|
|
+ operateOption.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(true));
|
|
|
|
|
+ OperationResult auditResult = OperationServiceHelper.executeOperate(OperationKeyConst.AUDIT, bill.getDataEntityType().getName(), ids, OperateOption.create());
|
|
|
|
|
+ return auditResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 整合operation操作错误信息进行返回
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param opResult
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getErrMsg(OperationResult opResult) {
|
|
|
|
|
+ String message = opResult.getMessage();
|
|
|
|
|
+ StringBuilder detailMessage = new StringBuilder();
|
|
|
|
|
+ if (!StringUtils.isEmpty(message)) {
|
|
|
|
|
+ detailMessage.append(message);
|
|
|
|
|
+ }
|
|
|
|
|
+ for (IOperateInfo errInfo : opResult.getAllErrorOrValidateInfo()) {
|
|
|
|
|
+ detailMessage.append(errInfo.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ InteractionContext context = opResult.getInteractionContext();
|
|
|
|
|
+ if (!ObjectUtils.isEmpty(context)) {
|
|
|
|
|
+ detailMessage.append(context.getSimpleMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return detailMessage.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void checkJxdOption(OperateOption option) {
|
|
|
|
|
+ if (RequestContext.get().getCurrUserId() != NUM) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 不执行警告级别校验器
|
|
|
|
|
+ option.setVariableValue(OperateOptionConst.MUTEX_IGNORE_VALIDATION, String.valueOf(true));
|
|
|
|
|
+ // 不显示交互提示,自动执行到底
|
|
|
|
|
+ option.setVariableValue(OperateOptionConst.IGNOREINTERACTION, String.valueOf(true));
|
|
|
|
|
+ // 全部校验通过才保存
|
|
|
|
|
+ option.setVariableValue(OperateOptionConst.STRICTVALIDATION, String.valueOf(true));
|
|
|
|
|
+ // 跳过权限校验
|
|
|
|
|
+ option.setVariableValue("skipCheckDataPermission", "true");
|
|
|
|
|
+ option.setVariableValue("skipCheckSpecialDataPermission", "true");
|
|
|
|
|
+ option.setVariableValue(OperateOptionConst.ISHASRIGHT, "true");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|