예제 #1
0
        /// <summary>
        /// 检查任务是否第一次打开。如是,则更新任务状态为“已开始”,同时添加任务生命周期
        /// </summary>
        private void checkAndSignFirstOpen()
        {
            var isPassed = TaskLifecycleCache.getCache().FirstOrDefault(l => l.taskId == taskInfoId && l.taskState == (int)TaskStateEnum.Passed);
            var isOpened = TaskLifecycleCache.getCache().FirstOrDefault(l => l.taskId == taskInfoId && l.taskState == (int)TaskStateEnum.Running);

            if (isPassed != null && isOpened == null)//如果审批通过,但从未打开过
            {
                TaskCache.updateTaskState(taskInfoId, (int)TaskStateEnum.Running);
            }
        }
        public void init(int[] taskStateArray, TaskGridShownStyle style)
        {
            this._taskStateArray = taskStateArray;
            this._style          = style;
            var classList         = CodeCache.getClass();
            var brandList         = CodeCache.getBrand();
            var modelList         = CodeCache.getModel();
            var taskList          = TaskCache.getCache();
            var tasklifecycleList = TaskLifecycleCache.getCache();
            var taskModelMapList  = TaskModelMapCache.getCache();

            taskModelAllList = (from task in taskList
                                from classCode in classList
                                from tasklifecycle in tasklifecycleList
                                                                                                                                                      //from brandCode in brandList
                                                                                                                                                      //from taskModelMap in taskModelMapList
                                                                                                                                                      //where (taskStateArray == (int)TaskStateEnum.Completed ?
                                                                                                                                                      //    (task.taskState == taskStateArray || task.taskState == (int)TaskStateEnum.Rejected || task.taskState == (int)TaskStateEnum.Closed)
                                                                                                                                                      //    : (task.taskState == taskStateArray))//如果是展示已完成任务,则需要附带已关闭、已驳回的任务
                                where taskStateArray.Contains(task.taskState) &&
                                task.taskClass == classCode.id                                                                                        //&& taskModelMap.taskId == task.id && taskModelMap.brandId == brandCode.id
                                                                                                                                                      //todo 跟当前用户相关
                                && task.id == tasklifecycle.taskId && tasklifecycle.taskState == 5001 &&
                                (task.taskExecutor.Contains(User.currentUser.name) || tasklifecycle.taskStateChangeExecutor == User.currentUser.name) //当前用户创建或测试人包含当前用户
                                orderby task.createTime descending
                                select new TaskModel
            {
                taskId = task.id,
                taskName = task.taskName,
                taskStateId = task.taskState,
                taskStateName = taskStateDic[task.taskState],
                taskBrandModelName = string.Join(Environment.NewLine, from brandCode in brandList
                                                 from modelCode in modelList
                                                 from taskModelMap in taskModelMapList
                                                 where taskModelMap.taskId == task.id && taskModelMap.brandId == brandCode.id && taskModelMap.ModelId == modelCode.id
                                                 select brandCode.codeName + "    " + modelCode.codeName),
                taskClassName = classCode.codeName,
                taskStartTime = task.createTime,
                taskCode = task.taskCode,
                percent = task.percent,
                taskRound = task.taskRound
            }).ToList();
            doQuery(new TaskQueryItem());
            showStyle(style);
        }
        public void init(int taskInfoId)
        {
            var taskLifeList  = TaskLifecycleCache.getCache().Where(t => t.taskId == taskInfoId).OrderBy(t => t.taskState).ToList();
            var taskStateList = CodeCache.getState();
            var tempList      = from life in taskLifeList
                                from state in taskStateList
                                where life.taskState == state.id
                                select new
            {
                life,
                state
            };
            List <String> textList = new List <string>();

            foreach (var taskLife in tempList)
            {
                textList.Add(taskLife.life.taskStateDateTime + "                  状态:" + taskLife.state.codeName + "                  操作人:" + taskLife.life.taskStateChangeExecutor + "                  备注:" + taskLife.life.remark);
            }
            lbl_taskLifecycle.Text = string.Join(Environment.NewLine, textList);
        }
예제 #4
0
 /// <summary>
 /// 新增任务,及任务相关的表(任务指标映射表、任务生命周期表)
 /// </summary>
 /// <param name="task"></param>
 /// <param name="indicatorIdList"></param>
 public static void createTask(Tb_taskInfo task, List <int> indicatorIdList, Dictionary <int, List <int> > brandModelIdDic)
 {
     using (EFMySqlDbContext context = new Db.EFMySqlDbContext())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 //新增任务信息
                 context.Tb_taskInfos.Add(task);
                 context.SaveChanges();
                 context.Entry(task);
                 int taskId = task.id;
                 //添加任务生命周期
                 Tb_taskLifecycle lifecycle = new Tb_taskLifecycle();
                 lifecycle.taskId                  = taskId;
                 lifecycle.taskStateDateTime       = DateTime.Now;
                 lifecycle.taskStateChangeExecutor = User.currentUser.name;
                 lifecycle.taskState               = (int)TaskStateEnum.Created;
                 lifecycle.remark                  = string.Empty;
                 context.Tb_taskLifecycles.Add(lifecycle);
                 context.SaveChanges();
                 //添加任务型号映射
                 List <Tb_taskModelMap> tmmList = new List <Entity.Tb_taskModelMap>();
                 foreach (int brandId in brandModelIdDic.Keys)
                 {
                     foreach (int modelId in brandModelIdDic[brandId])
                     {
                         Tb_taskModelMap tmm = new Tb_taskModelMap();
                         tmm.taskId  = taskId;
                         tmm.brandId = brandId;
                         tmm.ModelId = modelId;
                         tmmList.Add(tmm);
                     }
                 }
                 context.Tb_taskModelMaps.AddRange(tmmList);
                 context.SaveChanges();
                 //添加任务指标映射
                 List <Tb_taskIndicatorMap> timList = new List <Tb_taskIndicatorMap>();
                 foreach (int indicatorId in indicatorIdList)
                 {
                     Tb_taskIndicatorMap tim = new Tb_taskIndicatorMap();
                     tim.taskId      = taskId;
                     tim.indicatorId = indicatorId;
                     timList.Add(tim);
                 }
                 context.Tb_taskIndicatorMaps.AddRange(timList);
                 context.SaveChanges();
                 //提交数据库
                 transaction.Commit();
                 //更新任务生命周期缓存
                 TaskLifecycleCache.addCacheOnly(lifecycle);
                 //更新品牌型号映射缓存
                 foreach (var tmm in tmmList)
                 {
                     TaskModelMapCache.addCacheOnly(tmm);
                 }
                 //更新指标映射缓存
                 foreach (var tim in timList)
                 {
                     TaskIndicatorMapCache.addCacheOnly(tim);
                 }
             }
             catch (Exception ex)
             {
                 transaction.Rollback();
                 throw ex;
             }
         }
     }
 }