コード例 #1
0
        public JsonResult PromoteApprovalTask(ApprovalTask _param)
        {
            try
            {
                DaoFactory.BeginTransaction();
                DObjectRepository.StatusPromote(false, CommonConstant.TYPE_APPROVAL_TASK, Convert.ToString(_param.BPolicyOID), Convert.ToInt32(_param.OID), Convert.ToInt32(_param.OID), _param.ActionType, "");
                ApprovalTaskRepository.UdtInboxTask(new ApprovalTask {
                    ActionType = _param.ActionType, Comment = _param.Comment, OID = _param.OID
                });

                if (_param.ActionType == CommonConstant.ACTION_REJECT)
                {
                    Approval tmpApproval = ApprovalRepository.SelApprovalNonStep(new Approval {
                        OID = _param.ApprovalOID
                    });
                    DObjectRepository.StatusPromote(false, CommonConstant.TYPE_APPROVAL, Convert.ToString(tmpApproval.BPolicyOID), Convert.ToInt32(tmpApproval.OID), Convert.ToInt32(tmpApproval.OID), _param.ActionType, "");

                    DObject targetDobj = DObjectRepository.SelDObject(new DObject {
                        OID = tmpApproval.TargetOID
                    });
                    DObjectRepository.StatusPromote(false, targetDobj.Type, Convert.ToString(targetDobj.BPolicyOID), Convert.ToInt32(targetDobj.OID), Convert.ToInt32(targetDobj.OID), _param.ActionType, "");
                    DaoFactory.Commit();
                    return(Json(CommonConstant.RETURN_SUCCESS));
                }

                bool         allSuccess      = true;
                ApprovalStep tmpApprovalStep = ApprovalStepRepository.SelApprovalStep(new ApprovalStep {
                    OID = _param.StepOID
                });
                tmpApprovalStep.InboxTask.ForEach(task =>
                {
                    if (task.BPolicy.Name != CommonConstant.POLICY_APPROVAL_COMPLETED)
                    {
                        allSuccess = false;
                    }
                });

                if (allSuccess)
                {
                    Approval tmpApproval = ApprovalRepository.SelApprovalNonStep(new Approval {
                        OID = _param.ApprovalOID
                    });
                    int cntCurrent = Convert.ToInt32(tmpApproval.CurrentNum);
                    cntCurrent += 1;
                    if (tmpApproval.ApprovalCount >= cntCurrent)
                    {
                        ApprovalRepository.UdtApproval(new Approval {
                            CurrentNum = cntCurrent, OID = tmpApproval.OID
                        });
                        ApprovalRepository.SelApproval(new Approval {
                            OID = tmpApproval.OID
                        }).InboxStep.Find(step => step.Ord == cntCurrent).InboxTask.ForEach(task =>
                        {
                            DObjectRepository.StatusPromote(false, CommonConstant.TYPE_APPROVAL_TASK, Convert.ToString(task.BPolicyOID), Convert.ToInt32(task.OID), Convert.ToInt32(task.OID), _param.ActionType, "");
                        });
                    }
                    else if (tmpApproval.ApprovalCount < cntCurrent)
                    {
                        ApprovalRepository.UdtApproval(new Approval {
                            CurrentNum = cntCurrent, OID = tmpApproval.OID
                        });
                        DObjectRepository.StatusPromote(false, CommonConstant.TYPE_APPROVAL, Convert.ToString(tmpApproval.BPolicyOID), Convert.ToInt32(tmpApproval.OID), Convert.ToInt32(tmpApproval.OID), _param.ActionType, "");

                        DObject targetDobj = DObjectRepository.SelDObject(new DObject {
                            OID = tmpApproval.TargetOID
                        });
                        DObjectRepository.StatusPromote(false, targetDobj.Type, Convert.ToString(targetDobj.BPolicyOID), Convert.ToInt32(targetDobj.OID), Convert.ToInt32(targetDobj.OID), _param.ActionType, "");
                    }
                }
                DaoFactory.Commit();
            }
            catch (Exception ex)
            {
                DaoFactory.Rollback();
                return(Json(new ResultJsonModel {
                    isError = true, resultMessage = ex.Message, resultDescription = ex.ToString()
                }));
            }
            return(Json(CommonConstant.RETURN_SUCCESS));
        }
コード例 #2
0
        public JsonResult InsApproval(Approval _param)
        {
            int result = 0;

            try
            {
                DaoFactory.BeginTransaction();

                DObject dobj = new DObject();
                if (_param.TargetOID == null)
                {
                    dobj.Type = CommonConstant.TYPE_SAVE_APPROVAL;
                    dobj.Name = _param.Name;
                }
                else
                {
                    dobj.Type = CommonConstant.TYPE_APPROVAL;
                    string strApprovalPrefix = dobj.Type + "-" + DateTime.Now.ToString("yyyyMMdd") + "-";
                    dobj.Name = strApprovalPrefix + SemsUtil.MakeSeq(DObjectRepository.SelNameSeq(new DObject {
                        Type = CommonConstant.TYPE_APPROVAL, Name = strApprovalPrefix + "%"
                    }), "000");
                    dobj.Description = _param.Description;
                }
                dobj.TableNm = CommonConstant.TABLE_APPROVAL;
                result       = DObjectRepository.InsDObject(dobj);

                _param.OID           = result;
                _param.ApprovalCount = _param.InboxStep.FindAll(step => step.ApprovalType.Equals(CommonConstant.TYPE_APPROVAL_APPROV) || step.ApprovalType.Equals(CommonConstant.TYPE_APPROVAL_AGREE)).Count;
                ApprovalRepository.InsApproval(_param);

                List <int> lPromoteOID = new List <int>();
                int        index       = 0;
                _param.InboxStep.ForEach(step =>
                {
                    step.ApprovalOID = result;
                    int stepResult   = ApprovalStepRepository.InsApprovalStep(step);

                    step.InboxTask.ForEach(task =>
                    {
                        if (dobj != null)
                        {
                            dobj = null;
                        }
                        dobj                     = new DObject();
                        dobj.Type                = CommonConstant.TYPE_APPROVAL_TASK;
                        dobj.TableNm             = CommonConstant.TABLE_APPROVAL_TASK;
                        string strApprovalPrefix = dobj.Type + "-" + DateTime.Now.ToString("yyyyMMdd") + "-";
                        dobj.Name                = strApprovalPrefix + SemsUtil.MakeSeq(DObjectRepository.SelNameSeq(new DObject {
                            Type = CommonConstant.TYPE_APPROVAL_TASK, Name = strApprovalPrefix + "%"
                        }), "000");
                        int taskResult = DObjectRepository.InsDObject(dobj);

                        task.ApprovalOID = result;
                        task.StepOID     = stepResult;
                        task.OID         = taskResult;
                        ApprovalTaskRepository.InsInboxTask(task);

                        if (index == 0)
                        {
                            lPromoteOID.Add(taskResult);
                        }
                    });
                    index++;
                });

                if (_param.TargetOID != null)
                {
                    DObject targetDobj = DObjectRepository.SelDObject(new DObject {
                        OID = _param.TargetOID
                    });
                    DObjectRepository.StatusPromote(false, targetDobj.Type, Convert.ToString(targetDobj.BPolicyOID), Convert.ToInt32(targetDobj.OID), Convert.ToInt32(targetDobj.OID), CommonConstant.ACTION_PROMOTE, null);
                    if (lPromoteOID != null && lPromoteOID.Count > 0)
                    {
                        lPromoteOID.ForEach(promoteOID =>
                        {
                            if (dobj != null)
                            {
                                dobj = null;
                            }
                            dobj = DObjectRepository.SelDObject(new DObject {
                                OID = promoteOID
                            });
                            DObjectRepository.StatusPromote(false, dobj.Type, Convert.ToString(dobj.BPolicyOID), Convert.ToInt32(dobj.OID), Convert.ToInt32(dobj.OID), CommonConstant.ACTION_PROMOTE, null);
                        });

                        DObject approvDobj = DObjectRepository.SelDObject(new DObject {
                            OID = result
                        });
                        DObjectRepository.StatusPromote(false, approvDobj.Type, Convert.ToString(approvDobj.BPolicyOID), Convert.ToInt32(approvDobj.OID), Convert.ToInt32(approvDobj.OID), CommonConstant.ACTION_PROMOTE, null);
                    }
                    ApprovalRepository.UdtApproval(new Approval {
                        OID = result, CurrentNum = 1
                    });
                }

                DaoFactory.Commit();
            }
            catch (Exception ex)
            {
                DaoFactory.Rollback();
                return(Json(new ResultJsonModel {
                    isError = true, resultMessage = ex.Message, resultDescription = ex.ToString()
                }));
            }
            return(Json(result));
        }