Browse Source

回退到指定节点。调试完成

wanyuan 9 months ago
parent
commit
579d27a2f6

+ 3 - 3
tc-service/tap-task/src/main/java/com/minto/app/task/manager/TaskColApproval.java

@@ -92,16 +92,16 @@ public class TaskColApproval implements ColApproval {
             colId = colSummary.getId()+"";
         }
         HttpServletRequest request = WebUtil.getRequest();
+        Long requestColId = ReqUtil.getLong(request, "colId");
         Long affairId = ReqUtil.getLong(request, "affairId", UUIDUtil.UUIDAbsLong());
         Long relPersonId = ReqUtil.getLong(request, "relPersonId", 0L);
         IColManager colManager = AppContext.getBean(IColManager.class);
         ColAffairBean affairBean = colManager.findColAffairById(affairId);
-        boolean doIt = affairBean != null && (AppContext.currentUserId().equals(affairBean.getPersonId()) || (!relPersonId.equals(0L))) && (
+        boolean doIt = requestColId == null && affairBean != null && (
+                AppContext.currentUserId().equals(affairBean.getPersonId()) || (!relPersonId.equals(0L))) && (
                 ColEnum.ColAffairStateEnum.WaitDo.getKey() == affairBean.getAstate()
                         || ColEnum.ColAffairStateEnum.Read.getKey() == affairBean.getAstate()
                         || ColEnum.ColAffairStateEnum.WaitRedo.getKey() == affairBean.getAstate());
-
-
         return "/task/showAuditInfo/"+type+"?auditRelId="+auditRelId+"&colId="+colId+"&doIt="+doIt;
     }
 

+ 225 - 66
tip-front/src/main/java/com/minto/app/collaboration/controller/ColDoController.java

@@ -5,8 +5,13 @@
 
 package com.minto.app.collaboration.controller;
 
+import java.text.ParseException;
+import java.util.*;
+import java.util.stream.Collectors;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import com.google.common.collect.Lists;
-import com.minto.app.collaboration.manager.ColApproval;
 import com.minto.app.behavior.beans.BehSummaryBean;
 import com.minto.app.behavior.enums.BehaviorEnum.BehSummaryBehTypeEnum;
 import com.minto.app.behavior.manager.IBehManager;
@@ -14,6 +19,7 @@ import com.minto.app.collaboration.beans.*;
 import com.minto.app.collaboration.bo.*;
 import com.minto.app.collaboration.enums.ColEnum;
 import com.minto.app.collaboration.enums.ColEnum.*;
+import com.minto.app.collaboration.manager.ColApproval;
 import com.minto.app.collaboration.manager.ColTab;
 import com.minto.app.collaboration.manager.IColManager;
 import com.minto.app.collaboration.util.ColHelper;
@@ -32,26 +38,27 @@ import com.minto.app.organization.beans.OrgPersonBean;
 import com.minto.app.organization.beans.OrgRelationBean;
 import com.minto.app.organization.beans.OrgUnitBean;
 import com.minto.app.organization.manager.IOrgManager;
+import com.minto.app.performance.service.impl.SummaryScoreWebServiceImpl;
 import com.minto.app.resource.beans.CommonResourceRelationBean;
 import com.minto.app.resource.bo.CommonResourceRelationBO;
 import com.minto.app.resource.bo.IResource;
+import com.minto.app.resource.enums.ResourceEnum;
 import com.minto.app.resource.enums.ResourceEnum.ResourceRelationTypeEnum;
 import com.minto.app.resource.enums.ResourceEnum.ResourceTypeEnum;
 import com.minto.app.resource.manager.IResourceManager;
 import com.minto.app.resource.util.CommonRelationBeanCopier;
+import com.minto.app.space.beans.SpaceFileBean;
+import com.minto.app.space.bo.SpaceFileBO;
+import com.minto.app.space.manager.ISpaceManager;
 import com.minto.app.task.beans.TaskMemberBean;
 import com.minto.app.task.controller.TaskByTypeController;
 import com.minto.app.task.enums.TaskEnum;
 import com.minto.app.task.manager.ITaskManager;
 import com.minto.app.task.util.TaskByTypeUtil;
-import com.minto.tip.affair.manager.AffairManager;
 import com.minto.app.tc.knowledge.beans.ArcSummaryBean;
 import com.minto.app.tc.knowledge.enums.KmEnum;
 import com.minto.app.tc.knowledge.enums.KmEnum.KmPrivActionEnum;
 import com.minto.app.tc.knowledge.manager.IKnowledgeManager;
-import com.minto.app.space.bo.SpaceFileBO;
-import com.minto.app.space.beans.SpaceFileBean;
-import com.minto.app.space.manager.ISpaceManager;
 import com.minto.app.template.beans.TemplateCategoryBean;
 import com.minto.app.template.manager.ITemplateManager;
 import com.minto.app.workflow.beans.NodeBO;
@@ -63,6 +70,7 @@ import com.minto.core.base.BaseEnum;
 import com.minto.core.common.AppContext;
 import com.minto.core.constants.BaseConstants;
 import com.minto.core.util.*;
+import com.minto.tip.affair.manager.AffairManager;
 import com.minto.tip.common.authenticate.bo.User;
 import com.minto.tip.common.exceptions.BusinessException;
 import org.apache.commons.lang3.StringUtils;
@@ -78,12 +86,6 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.servlet.ModelAndView;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.text.ParseException;
-import java.util.*;
-import java.util.stream.Collectors;
-
 
 @Controller
 @RequestMapping("/doCollaboration")
@@ -238,6 +240,149 @@ public class ColDoController {
         return null;
     }
 
+
+    /**
+     * 批量回退事项流程节点。
+     * @param request HTTP请求对象,包含回退节点等信息。
+     * @param response HTTP响应对象,用于向客户端发送响应。
+     * @return ModelAndView 对象,用于视图解析。
+     * @throws Exception 如果操作失败,抛出异常。
+     */
+    @PostMapping(value = "/doSendBack", params = {"m=batchSendBack"})
+    public ModelAndView doBatchSendBack(HttpServletRequest request, HttpServletResponse response) throws Exception{
+        // 初始化结果集
+        Map<String, Object> result = new HashMap<String, Object>();
+        try{
+            boolean sendMsg = false;
+                    //获取回退到的节点码
+            String backNode = ReqUtil.getString(request, "backNode");
+            ColAffairBO firstAffair = null;
+            boolean runNext = true;
+            do{
+                Map<String, Object> objectMap = AppContext.getThreadContext("batchSendBackMap");
+                if(objectMap == null){
+                    objectMap = new HashMap<>();
+                }
+                //获取当前待办基本信息
+                Long curAffairId = objectMap.containsKey("affairId") ? (Long)objectMap.get("affairId") :
+                        ReqUtil.getLong(request, "affairId");
+                ColAffairBean curAffair = colManager.findColAffairById(curAffairId);
+                Long curNodeId = curAffair.getNodeId();
+                Long curColId = curAffair.getColId();
+                Long curUserId = curAffair.getPersonId();
+                ProcessBO process = workflowManager.getProcessById(curNodeId, WorkflowTypeEnum.col, curUserId, null);
+                // 判断是否需要继续回退
+                if(process.getCurrentNode().equals(backNode)){
+                    break;
+                }
+                // 初始化下一个节点的参数
+                Map<String, Object> nextParams = new HashMap<>();
+                // 获取上级节点包含的任务列表
+                List<Long> parentTCs = workflowManager.getParentTCs(curNodeId);
+                if(CollectionUtil.isNotEmpty(parentTCs)){
+                    // 获取上一个流程节点
+                    List<ColAffairBean> perAffairs = colManager.findColAffairByNodeId(parentTCs.get(0));
+                    if(CollectionUtil.isEmpty(perAffairs)){
+                        throw new BusinessException("数据错误,上个节点不存在,colNodeId:" + curNodeId);
+                    }
+                    ColAffairBean perAffair = perAffairs.get(0);
+                    Long preNodeId = perAffair.getNodeId();
+                    Long preColId = perAffair.getColId();
+                    Long preUserId = perAffair.getPersonId();
+                    //流程框架回退
+                    workflowManager.sendBack(AppContext.currentLoginCorporation(), curNodeId,
+                            WorkflowEnum.WorkflowTypeEnum.col.getKey(), curUserId);
+
+                    // 根据请求和回退类型初始化事务对象
+                    ColAffairBO affairBO = getDoAffairBO(request, "回退", false);
+                    if(firstAffair == null){
+                        firstAffair = affairBO;
+                        // 执行回退操作
+                        colManager.doColSendBack(AppContext.currentLoginCorporation(), affairBO);
+                    }
+
+                    Long sourceId = affairBO.getAffairBean().getColId();
+                    if(sourceId!=null){
+                        // 恢复上一个节点的待办数据
+                        ColSummaryBean summary = colManager.findColSummaryById(sourceId);
+                        colManager.saveColSummaryWaiteDoBeans(summary, preUserId, perAffair.getId());
+                    }
+                    /* 回退删除自己生成的待办数据  edited by lijun at 2020/9/21 17:53 */
+                    Criterion cri = Restrictions.eq("relationVs1", sourceId);
+                    cri = Restrictions.and(cri,Restrictions.eq("relationVs2", affairBO.getAffairBean().getId()));
+                    commonManager.deleteByCriterion(cri);
+                    // 准备下一次循环的数据
+                    if(runNext){
+                        nextParams.put("affairId", perAffair.getId());
+                        nextParams.put("privilegeId", perAffair.getPrivilegeId());
+                        ColNodeBean preNode = colManager.findColNodeById(preNodeId);
+                        nextParams.put("creatorId", preNode.getCreatorId());
+                    }
+                } else{
+                    // 说明是发起者节点,获取发起者节点
+                    Long colId = ReqUtil.getLong(request, "colId");
+                    ColSummaryBean summaryBean = colManager.findColSummaryById(colId);
+                    //获取事项参与人与姓名
+                    List<ColAffairBean> affairBeans = colManager.findColAffairByColId(summaryBean.getId());
+                    ColAffairBean startAffair = affairBeans.stream().filter(e ->
+                            e.getPersonId().longValue() == summaryBean.getCreatorId().longValue()
+                                    && e.getAstate() == ColAffairStateEnum.Sent.getKey()).findFirst().orElse(null);
+                    if(startAffair != null){
+                        // 撤销流程
+                        Map<String, Object> map = new HashMap<>();
+                        cancelFlow(curColId, curNodeId, null, map);
+                        if(Boolean.FALSE.equals(map.get("sendFlowResult"))){
+                            throw new BusinessException(String.valueOf(map.get("message")));
+                        }
+                        // 根据请求和回退类型初始化事务对象
+                        ColAffairBO affairBO = getDoAffairBO(request, "回退", false);
+                        if(firstAffair == null){
+                            firstAffair = affairBO;
+                            // 执行回退操作
+                            colManager.doColSendBack(AppContext.currentLoginCorporation(), affairBO);
+                        }
+                        Long sourceId = affairBO.getAffairBean().getColId();
+                        if(sourceId != null){
+                            resourceManager.deleteRelationshipBySourceId(new Long[]{sourceId});
+                        }
+                        /* 回退删除自己生成的待办数据  edited by lijun at 2020/9/21 17:53 */
+                        Criterion cri = Restrictions.eq("relationVs1", sourceId);
+                        cri = Restrictions.and(cri,Restrictions.eq("relationVs2", affairBO.getAffairBean().getId()));
+                        commonManager.deleteByCriterion(cri);
+                        colManager.deleteColAffairByColNodeId(curNodeId);
+                        sendMsg = true;
+                        // 准备下一次循环的数据
+                        //Long nodeId = startAffair.getNodeId();
+                        //ColNodeBean colNodeBean = colManager.findColNodeById(nodeId);
+                        //nextParams.put("creatorId", colNodeBean.getCreatorId());
+                        //nextParams.put("affairId", startAffair.getId());
+                        //nextParams.put("privilegeId", startAffair.getPrivilegeId());
+                        runNext = false;
+                    }
+                }
+                AppContext.putThreadContext("batchSendBackMap", nextParams);
+            } while(runNext);
+            if(sendMsg){
+                sendMessage(request, firstAffair);
+            }
+            recordBehavior(request, firstAffair.getAffairBean().getColId(), new Date(),BehSummaryBehTypeEnum.SendBackCol);
+            // 设置操作成功提示信息
+            result.put("state", "success");
+            result.put("message", ResourceUtil.getString("common.operation.successful.label"));
+        } catch(Exception e){
+            // 记录操作失败日志
+            log.error(ExceptionUtil.printExceptionStackTrace(e));
+            // 设置操作失败提示信息
+            result.put("state", "error");
+            result.put("message", ResourceUtil.getString("common.operation.fail.label"));
+        } finally{
+            // 响应客户端
+            AppContext.removeThreadContext("batchSendBackMap");
+            RespUtil.rendJson(response, result);
+        }
+        return null;
+    }
+
     /**
      * 暂停、终止
      * @param request
@@ -990,6 +1135,10 @@ public class ColDoController {
      */
     public List<ColAffairBO> getDoAffairBOs(HttpServletRequest request, String doStateDes, Boolean isReply) throws Exception {
         Long cid = AppContext.currentLoginCorporation();
+        Map<String, Object> objectMap = AppContext.removeThreadContext("batchSendBackMap");
+        if(objectMap == null){
+            objectMap = new HashMap<>();
+        }
         /*包含其他页面的变得元素信息*/
         Long personId = AppContext.currentUserId();
         Long colId = ReqUtil.getLong(request, "colId");
@@ -1002,10 +1151,14 @@ public class ColDoController {
         //                e.printStackTrace();
         //            }
         //        }
-        Long affairId = ReqUtil.getLong(request, "affairId");
-        Integer privilegeId = ReqUtil.getInt(request, "privilegeId");
+        Long affairId = objectMap.containsKey("affairId") ? (Long)objectMap.get("affairId") :
+                ReqUtil.getLong(request, "affairId");
+        Integer privilegeId = objectMap.containsKey("privilegeId") ?
+                objectMap.get("privilegeId") == null ? null : Integer.valueOf(objectMap.get("privilegeId").toString()) :
+                ReqUtil.getInt(request, "privilegeId");
         // 协同发起人
-        Long creatorId = ReqUtil.getLong(request, "creatorId");
+        Long creatorId = objectMap.containsKey("creatorId") ? (Long)objectMap.get("creatorId") :
+                ReqUtil.getLong(request, "creatorId");
         Long parentId = ReqUtil.getLong(request, "parentId", 0L);
         Long toPersonId = ReqUtil.getLong(request, "personId");
         Integer ptype = ReqUtil.getInt(request, "ptype", ColProcessTypeEnum.CommonOpinion.getKey());
@@ -1633,7 +1786,7 @@ public class ColDoController {
 
                     // colManager.updateColAffairStateByIds(new Long[] { affairId }, ColAffairStateEnum.Read.getKey());
                     colManager.updateColAffairsState(Lists.newArrayList(affairBean), ColEnum.ColAffairStateEnum.Read.getKey());
-                    
+
                     // model.put("commonActions", commonActionsMap);
                     Long nodeId = affairBean.getNodeId();
                     ColNodeBean colNodeBean = colManager.findColNodeById(nodeId);
@@ -1963,69 +2116,75 @@ public class ColDoController {
             Long tcId = ids[0];
             String title = ReqUtil.getString(request, "title", null);
             Long colId = ReqUtil.getLong(request, "colId", null);
+            cancelFlow(colId, tcId, title, map);
+        } catch (Exception e) {
+            log.error(ExceptionUtil.printExceptionStackTrace(e));
+            map.put("sendFlowResult", Boolean.FALSE);
+            map.put("state", "error");
+            map.put("message", "撤销失败");
+        } finally {
+            RespUtil.rendJson(response, map);
+        }
+        return mv;
+    }
 
-            /* @author : inspired(胡启林);Description:检查是否有已处理的节点信息,已处理则不能撤销	(edit) lastdate : 2020/3/4  */
-            List<ColAffairBean> colAffairBeans = null;
-            ColSummaryBean colSummaryBean = null;
-            if(colId!=null){
-                colAffairBeans = colManager.findColAffairByColId(colId);
-                colSummaryBean = colManager.findColSummaryById(colId);
-            }else{
-                colAffairBeans = colManager.findColAffairByNodeId(tcId);
-                ColNodeBean colNodeById = colManager.findColNodeById(tcId);
-                if (colNodeById != null) {
-                    colSummaryBean = colManager.findColSummaryById(colNodeById.getColId());
-                }
+    private void cancelFlow(Long colId, Long tcId, String title, Map<String, Object> map){
+        /* @author : inspired(胡启林);Description:检查是否有已处理的节点信息,已处理则不能撤销	(edit) lastdate : 2020/3/4  */
+        List<ColAffairBean> colAffairBeans = null;
+        ColSummaryBean colSummaryBean = null;
+        if(colId !=null){
+            colAffairBeans = colManager.findColAffairByColId(colId);
+            colSummaryBean = colManager.findColSummaryById(colId);
+        }else{
+            colAffairBeans = colManager.findColAffairByNodeId(tcId);
+            ColNodeBean colNodeById = colManager.findColNodeById(tcId);
+            if (colNodeById != null) {
+                colSummaryBean = colManager.findColSummaryById(colNodeById.getColId());
             }
-            Boolean canUndo = true;//是否能撤销
+        }
+        Boolean canUndo = true;//是否能撤销
 
-            if (CollectionUtil.isNotEmpty(colAffairBeans) && canUndo) {
-                for(ColAffairBean cola : colAffairBeans){
-                    if(cola.getAstate() == ColEnum.ColAffairStateEnum.Finished.getKey()){
-                        canUndo = false;
-                        break;
-                    }
+        if (CollectionUtil.isNotEmpty(colAffairBeans) && canUndo) {
+            for(ColAffairBean cola : colAffairBeans){
+                if(cola.getAstate() == ColAffairStateEnum.Finished.getKey()){
+                    canUndo = false;
+                    break;
                 }
             }
-            if(canUndo){
-                Boolean canCancle = colManager.cancelFlow(AppContext.currentLoginCorporation(),
-                    AppContext.currentUserId(), tcId, WorkflowEnum.WorkflowTypeEnum.col.getKey(), colSummaryBean);
-                if (canCancle) {
-                    map.put("sendFlowResult", Boolean.TRUE);
-                    map.put("state", "success");
-                    map.put("message", "撤销成功");
-                    /* @author : inspired(胡启林);Description:撤销协同后删除待办数据	(edit) lastdate : 2020/3/10  */
-                    if(colId==null && colSummaryBean!=null){
-                        colId = colSummaryBean.getId();
-                    }
-                    Criterion cri = Restrictions.eq("relationVs1", colId);
-                    commonManager.deleteByCriterion(cri);
-                    // 记录行为
-                    ColHelper.recordBehavior(ResourceTypeEnum.Collaboration.getKey(), tcId, new Date(), BehSummaryBehTypeEnum.CancelCol, colSummaryBean,
-                            AppContext.currentUserId(), title);
-                } else {
-                    map.put("sendFlowResult", Boolean.FALSE);
-                    map.put("state", "error");
-                    map.put("message", "当前流程流转完毕,不能撤销");
+        }
+        if(canUndo){
+            Boolean canCancle = colManager.cancelFlow(AppContext.currentLoginCorporation(),
+                AppContext.currentUserId(), tcId, WorkflowTypeEnum.col.getKey(), colSummaryBean);
+            if (canCancle) {
+                map.put("sendFlowResult", Boolean.TRUE);
+                map.put("state", "success");
+                map.put("message", "撤销成功");
+                /* @author : inspired(胡启林);Description:撤销协同后删除待办数据	(edit) lastdate : 2020/3/10  */
+                if(colId ==null && colSummaryBean!=null){
+                    colId = colSummaryBean.getId();
                 }
-            }else{
+                Criterion cri = Restrictions.eq("relationVs1", colId);
+                commonManager.deleteByCriterion(cri);
+                // 记录行为
+                if(title == null){
+                    title = colSummaryBean == null ? "" : colSummaryBean.getTitle();
+                }
+                ColHelper.recordBehavior(ResourceTypeEnum.Collaboration.getKey(), tcId, new Date(), BehSummaryBehTypeEnum.CancelCol, colSummaryBean,
+                        AppContext.currentUserId(), title);
+            } else {
                 map.put("sendFlowResult", Boolean.FALSE);
                 map.put("state", "error");
-                String message = "当前流程流转中,不能撤销";
-                if (colSummaryBean != null && colSummaryBean.getCstate() == ColEnum.ColSummaryStateEnum.Finished.getKey()) {
-                    message = "当前流程流转完毕,不能撤销";
-                }
-                map.put("message", message);
+                map.put("message", "当前流程流转完毕,不能撤销");
             }
-        } catch (Exception e) {
-            log.error(ExceptionUtil.printExceptionStackTrace(e));
+        }else{
             map.put("sendFlowResult", Boolean.FALSE);
             map.put("state", "error");
-            map.put("message", "撤销失败");
-        } finally {
-            RespUtil.rendJson(response, map);
+            String message = "当前流程流转中,不能撤销";
+            if (colSummaryBean != null && colSummaryBean.getCstate() == ColSummaryStateEnum.Finished.getKey()) {
+                message = "当前流程流转完毕,不能撤销";
+            }
+            map.put("message", message);
         }
-        return mv;
     }
 
     @PostMapping("/doTakeBack")

+ 3 - 1
tip-front/src/main/webapp/tc_suite/collaboration/js/col.js

@@ -1453,7 +1453,7 @@ col.doIndex.advancePOSave = function(code, editApi) {
                             let nodeId = this.content.$("#sendBackNodeId").val();
                             if(nodeId){
                                 $("#backNode").val(nodeId)
-                                col.doIndex.doColCall()
+                                col.doIndex.doColCall({preActionUrl: "", sendFlowResult: true});
 
                             }
                         },
@@ -1978,6 +1978,7 @@ col.doIndex.doColSava = function(result){
         var flagUrl = 0;
         //撤回和退回特殊处理 shan.wen 2018-08-16
         if(result.preActionUrl == "/doCollaboration/doCancelFlow" || result.preActionUrl == "/wf/doSendBack"){
+            debugger;
             flagUrl =1;
         }
         /*//撤回就不弹窗提示,就不会重新加载页签
@@ -1992,6 +1993,7 @@ col.doIndex.doColSava = function(result){
             if(result.preActionUrl == "/doCollaboration/doCancelFlow") {
                 backType = 0;
             }else if(result.preActionUrl == "/wf/doSendBack"){
+                debugger;
                 backType = 1;
                 $("#savePOForm").append("<input type='hidden' name='preNodeId' value="+result.preNodeId+" />"); //上一个节点的id
                 $("#savePOForm").append("<input type='hidden' name='preActorId' value="+result.preActorId+" />"); //上一个节点的id

+ 1 - 0
tip-front/src/main/webapp/tc_tap/workflow/js/process.js

@@ -808,6 +808,7 @@ var nodeArray = new Array();
 			$("#tcId").val(preNode.baseInfo[0]);
             preActionUrl = "/doCollaboration/doCancelFlow";
 		}else{
+			debugger;
             preActionUrl = "/wf/doSendBack";
 		}