Example #1
0
 public void SetEntity(EngineeringVolumeEntity Entity)
 {
     this.Number    = Entity.Number;
     this.Name      = Entity.Name;
     this.Designer  = Entity.Designer;
     this.Checker   = Entity.Checker;
     this.StartDate = Entity.StartDate;
     this.EndDate   = Entity.EndDate;
     this.Note      = Entity.Note;
     this.IsDelete  = Entity.IsDelete;
     this.IsDone    = Entity.IsDone;
 }
Example #2
0
 public EngineeringVolumeInfo(EngineeringVolumeEntity Entity) : this()
 {
     this.ID            = Entity.ID;
     this.EngineeringID = Entity.EngineeringID;
     this.SpecialtyID   = Entity.SpecialtyID;
     this.Number        = Entity.Number;
     this.Name          = Entity.Name;
     this.Designer      = Entity.Designer;
     this.Checker       = Entity.Checker;
     this.StartDate     = Entity.StartDate;
     this.EndDate       = Entity.EndDate;
     this.FinishDate    = Entity.FinishDate;
     this.Note          = Entity.Note;
     this.IsDone        = Entity.IsDone;
 }
        /// <summary>
        /// 新建卷册
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="EngineeringVolume"></param>
        /// <returns></returns>
        public async Task <int> Create(int UserID, EngineeringVolumeNewInfo EngineeringVolume)
        {
            var newVol = new EngineeringVolumeEntity();

            newVol.SetEntity(EngineeringVolume);
            newVol.EngineeringID = EngineeringVolume.EngineeringID;
            newVol.SpecialtyID   = EngineeringVolume.SpecialtyID;
            newVol.Designer      = EngineeringVolume.TaskUsers[0].User;
            newVol.Checker       = EngineeringVolume.TaskUsers[1].User;

            this._DB.Add(newVol);

            var specInfo = this._PMContext.EngineeringSpecialtyEntity.SingleOrDefault(s => s.EngineeringID == EngineeringVolume.EngineeringID && s.SpecialtyID == EngineeringVolume.SpecialtyID);

            // 新建的卷册这里开始一个生产流程
            var dicUser = new Dictionary <string, object>();

            EngineeringVolume.TaskUsers.ForEach(i =>
            {
                dicUser.Add(i.Owner, i.User);
            });

            var pid = ProcessEngine.Instance.CreateProcessInstance(specInfo.ProcessModel, UserID, dicUser);

            // 映射流程实例和卷册关系
            _IObjectProcessService.Add(new ObjectProcessEntity()
            {
                ObjectID  = newVol.ID,
                ObjectKey = this.Const_BusinessKeyName,
                ProcessID = new Guid(pid)
            });

            // 设置任务的计划时间
            BPMDBService.SetTaskDate(pid, newVol.StartDate, newVol.EndDate);

            await ProcessEngine.Instance.Start(pid);

            return(newVol.ID);
        }
        /// <summary>
        /// 批量更新卷册
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="EngineeringID"></param>
        /// <param name="SpecialtyID"></param>
        /// <param name="Entitys"></param>
        /// <returns></returns>
        public async Task <List <EngineeringVolumeEntity> > BatchUpdate(int UserID, int EngineeringID, long SpecialtyID, List <EngineeringVolumeNewInfo> Entitys)
        {
            var ids  = new List <int>();
            var news = new List <EngineeringVolumeEntity>();

            // 获取工程的专业信息
            var specInfo = this._PMContext.EngineeringSpecialtyEntity.SingleOrDefault(s => s.EngineeringID == EngineeringID && s.SpecialtyID == SpecialtyID);

            // 获取专业的流程信息
            //var processInfo = ProcessModelCache.Instance.GetModelInfo(specInfo.ProcessModel);

            foreach (var item in Entitys)
            {
                if (item.ID > 0)
                {
                    if (item.IsModified)
                    {
                        var obj = this._DB.SingleOrDefault(e => e.ID == item.ID);

                        // 更新卷册信息
                        obj.SetEntity(item);
                        obj.Designer = item.TaskUsers[0].User;
                        obj.Checker  = item.TaskUsers[1].User;
                        this._DB.Edit(obj);

                        // 更新流程用户
                        var process = _IObjectProcessService.Get(this.Const_BusinessKeyName, obj.ID);
                        ProcessEngine.Instance.SetProceeTaskUsers(process.ProcessID, item.TaskUsers);

                        // 更新任务用户
                        this._IUserTaskService.ResetTaskUser(process.ProcessID, item.TaskUsers);

                        // 设置任务的计划时间
                        BPMDBService.SetTaskDate(process.ProcessID.ToString(), obj.StartDate, obj.EndDate);
                    }

                    ids.Add(item.ID);
                }
                else
                {
                    // 新建卷册
                    var newVol = new EngineeringVolumeEntity();

                    newVol.SetEntity(item);
                    newVol.EngineeringID = EngineeringID;
                    newVol.SpecialtyID   = SpecialtyID;
                    newVol.Designer      = item.TaskUsers[0].User;
                    newVol.Checker       = item.TaskUsers[1].User;

                    this._DB.Add(newVol);

                    news.Add(newVol);
                    ids.Add(newVol.ID);

                    // 新建的卷册这里开始一个生产流程
                    var dicUser = new Dictionary <string, object>();
                    item.TaskUsers.ForEach(i =>
                    {
                        dicUser.Add(i.Owner, i.User);
                    });

                    var pid = ProcessEngine.Instance.CreateProcessInstance(specInfo.ProcessModel, UserID, dicUser);

                    // 映射流程实例和卷册关系
                    _IObjectProcessService.Add(new ObjectProcessEntity()
                    {
                        ObjectID  = newVol.ID,
                        ObjectKey = this.Const_BusinessKeyName,
                        ProcessID = new Guid(pid)
                    });

                    // 设置任务的计划时间
                    BPMDBService.SetTaskDate(pid, newVol.StartDate, newVol.EndDate);

                    await ProcessEngine.Instance.Start(pid);
                }
            }

            var q = ids.AsQueryable();

            // 要删除的卷册
            var deleteVolumes = this._DB.GetList(v => v.EngineeringID == EngineeringID && v.SpecialtyID == SpecialtyID && !q.Contains(v.ID));

            foreach (var vol in deleteVolumes)
            {
                // 获取卷册的流程实例ID
                var processMap = _IObjectProcessService.Get(this.Const_BusinessKeyName, vol.ID);

                // 删除流程实例
                if (ProcessEngine.Instance.DeleteProcess(processMap.ProcessID.ToString()))
                {
                    // 删除流程的任务
                    _IUserTaskService.DeleteProcessTask(processMap.ProcessID);

                    // 删除卷册和流程的映射关系
                    _IObjectProcessService.Delete(this.Const_BusinessKeyName, vol.ID);

                    // 删除卷册
                    vol.IsDelete = true;
                    this._PMContext.Entry(vol).State = System.Data.Entity.EntityState.Modified;
                }
            }

            this._PMContext.SaveChanges();
            return(news);
        }