Example #1
0
        /// <summary>
        /// 创建或更新任务
        /// </summary>
        /// <param name="request"></param>
        public Task addOrUpdateTask(Task task)
        {
            // 如果存在父节点任务 则判断时间范围要在父节点任务的时间范围内 如果没有父节点任务 则判断时间范围要在项目的时间范围内
            if (task.ParentId == 0)
            {
                var project = Db.Queryable <Project>().Where(u => u.Id == task.ProjectId).Single();
                if (project.StartTime > task.StartTime || project.EndTime < task.EndTime)
                {
                    throw new Exception("该任务的时间范围必须包含在所属项目的时间范围内");
                }
            }
            else
            {
                var parentTask = SimpleDb.AsQueryable().Where(u => u.Id == task.ParentId).First();
                if (parentTask.StartTime > task.StartTime || parentTask.EndTime < task.EndTime)
                {
                    throw new Exception("该任务的时间范围必须包含在上级任务的时间范围内");
                }

                // 如果上级任务存在任务提交记录 则无法新增
                if (Db.Queryable <TaskRecord>().Where(u => u.TaskId == task.ParentId).Count() > 0 && task.Id == 0)
                {
                    throw new Exception("该任务存在任务提交记录 则无法新增子任务");
                }
            }

            task.CreateTime    = DateTime.Now;
            task.SubmitterId   = user.UserId;
            task.SubmitterName = user.UserName;
            task.Progress      = 0;
            ChangeModuleCascade(task);

            return(Db.Saveable(task).ExecuteReturnEntity());
        }
Example #2
0
        /// <summary>
        /// 获取项目列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public PageResponse <List <Project> > findProjects(QueryProjectOrTaskRequest request)
        {
            var total = 0;

            var sugarQueryableList = SimpleDb.AsQueryable().Where(u =>
                                                                  u.Name.Contains(request.key) && SqlFunc.Between(u.CreateTime, request.startTime, request.endTime));

            if (!string.IsNullOrEmpty(request.type))
            {
                sugarQueryableList = sugarQueryableList.Where(u => u.Type == request.type);
            }

            // 如果是管理员 才查看所有项目 否则查询自己负责或者自己提交的项目
            var roleId = Db.Queryable <UserRole>().Where(u => u.UserId == user.UserId).Select(u => u.RoleId).First();

            if (roleId != 1)
            {
                sugarQueryableList = sugarQueryableList.Where(u => u.ChargeUserId == user.UserId || u.SubmitterId == user.UserId);
            }

            var list = sugarQueryableList.OrderBy(u => request.sortColumn,
                                                  request.sortType == "asc" ? OrderByType.Asc : OrderByType.Desc)
                       .ToPageList(request.page, request.limit, ref total);

            var pageResponse = new PageResponse <List <Project> > {
                Total = total, Result = list
            };

            return(pageResponse);
        }
        /// <summary>
        /// 审批不同意
        /// </summary>
        /// <param name="taskRecordId"></param>
        /// <param name="opinion"></param>
        public int disagree(int taskRecordId, string opinion)
        {
            // 新增approve record记录
            var approveRecord = new ApproveRecord
            {
                ApproverId = user.UserId,
                CreateTime = DateTime.Now,
                DocId      = taskRecordId,
                Opinion    = opinion,
                Result     = "审批拒绝",
                Type       = 2
            };

            Db.Insertable(approveRecord).ExecuteReturnIdentity();

            // 修改task record状态
            var taskRecord = SimpleDb.GetSingle(u => u.Id == taskRecordId);

            taskRecord.Status = 2;
            SimpleDb.Update(taskRecord);

            // todo 发送相关消息

            return(taskRecord.Id);
        }
Example #4
0
        /// <summary>
        /// 如果一个类有层级结构(树状),则修改该节点时,要修改该节点的所有子节点
        /// //修改对象的级联ID,生成类似XXX.XXX.X.XX
        /// </summary>
        /// <param name="task"></param>
        private void ChangeModuleCascade(Task task)
        {
            string cascadeId;
            var    currentCascadeId = 1; //当前结点的级联节点最后一位
            var    sameLevels       = SimpleDb.AsQueryable().Where(u => u.ParentId == task.ParentId && u.Id != task.Id).ToList();

            foreach (var obj in sameLevels)
            {
                var objCascadeId = int.Parse(obj.CascadeId.TrimEnd('.').Split('.').Last());
                if (currentCascadeId <= objCascadeId)
                {
                    currentCascadeId = objCascadeId + 1;
                }
            }

            if (task.ParentId > 0)
            {
                var parenntTask = SimpleDb.GetSingle(u => u.Id == task.ParentId);
                if (parenntTask != null)
                {
                    cascadeId = parenntTask.CascadeId + currentCascadeId + ".";
                }
                else
                {
                    throw new Exception("未能找到该组织的父节点信息");
                }
            }
            else
            {
                cascadeId = ".0." + currentCascadeId + ".";
            }

            task.CascadeId = cascadeId;
        }
Example #5
0
        /// <summary>
        /// 找到上级任务负责人 如果上级是自己则继续向上找 直到找到非自己为止
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="user"></param>
        /// <returns>返回找到负责人的userId</returns>
        public int getTaskSuperior(int taskId, UserAuthSession user)
        {
            var task = SimpleDb.GetSingle(u => u.Id == taskId);

            if (task.ChargeUserId != user.UserId)
            {
                throw new Exception("您与选中任务无关联,无法提交");
            }

            while (true)
            {
                task = SimpleDb.GetSingle(u => u.Id == task.ParentId);

                if (task == null)
                {
                    break;
                }

                if (task.ChargeUserId != user.UserId)
                {
                    break;
                }
            }

            if (task == null)
            {
                throw new Exception("暂无可用上级,请联系管理员重新分配");
            }

            return(task.ChargeUserId);
        }
Example #6
0
        public TableModel <User> GetPageList(int pageIndex, int pageSize)
        {
            int         totalNumber = 0;
            int         totalPage   = 0;
            List <User> data        = SimpleDb.AsQueryable().Where(t => t.Age == 12).ToPageList(pageIndex, pageSize, ref totalNumber, ref totalPage);
            Page        page        = Utils.GetPage(pageIndex, pageSize, totalNumber, totalPage);

            return(new TableModel <User>()
            {
                count = data.Count, page = page, data = data
            });
        }
Example #7
0
        /// <summary>
        /// 获取用户
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public List <Users> findUsers(string key)
        {
            var list = SimpleDb.AsQueryable().Where(u => u.userName.Contains(key)).ToList();

            if (list.Count != 0)
            {
                return(list);
            }
            // 如果不是字符串包含 则按拼音首字母或者全拼来进行搜索
            var totalList = SimpleDb.AsQueryable().ToList();

            list.AddRange(totalList.Where(user =>
                                          Pinyin.GetInitials(user.userName).ToLower().StartsWith(key) ||
                                          Pinyin.GetPinyin(user.userName).Replace(" ", "").StartsWith(key)));

            return(list);
        }
Example #8
0
        /// <summary>
        /// 快速回复消息
        /// </summary>
        public void quickComment(int parentId, string content, int docId, int targetId)
        {
            var comment = new Comment
            {
                ParentId    = parentId,
                Attachment  = string.Empty,
                Content     = content,
                CreateTime  = DateTime.Now,
                DocId       = docId,
                HaveRead    = 0,
                SubmitterId = user.UserId,
                TargetId    = targetId,
                Type        = 0
            };

            SimpleDb.Insert(comment);
        }
        /// <summary>
        /// 用户名密码登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public Response Login(string username, string password)
        {
            var result = new Response <string>();

            try
            {
                // 密码加密
                password = Md5.Encrypt(password);
                // 防sql注入
                username = Md5.avoidSqlInjection(username);

                var userInfo = SimpleDb.GetSingle(u => u.userName.Equals(username));

                if (userInfo == null)
                {
                    throw new Exception("用户不存在");
                }
                if (!Md5.Encrypt(userInfo.passWord).Equals(password))
                {
                    throw new Exception("密码不正确");
                }

                var currentSession = new UserAuthSession
                {
                    UserId       = userInfo.userId,
                    WechatUserId = userInfo.wechatUserId,
                    UserName     = userInfo.userName,
                    Token        = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
                    CreateTime   = DateTime.Now
                };

                _cacheContext.Set(currentSession.Token, currentSession, DateTime.Now.AddDays(10));
                result.Result = currentSession.Token;
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
            }

            return(result);
        }
Example #10
0
        /// <summary>
        /// 前端展示项目任务树
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        public Dictionary <string, object> getProjectTaskTree(int projectId)
        {
            var member = Db.Queryable <ProjectMember>().Where(u => u.ProjectId == projectId && u.UserId == user.UserId)
                         .ToList()[0];

            var treeList = new List <Task>();

            // 如果是项目经理或是管理员 才能查询到项目中所有子任务 否则查询到自己负责任务的所有下级任务以及和自己负责任务相关联的上级任务
            var allTaskList = Db.Queryable <Task>().Where(u => u.ProjectId == projectId);

            if (!member.ProjectRole.Equals("项目经理"))
            {
                var inferiorTaskList = allTaskList.Where(u => u.ChargeUserId == user.UserId).ToList();
                treeList.AddRange(inferiorTaskList);

                foreach (var inferiorTask in inferiorTaskList)
                {
                    var list = Db.Queryable <Task>().Where(u => !u.CascadeId.Equals(inferiorTask.CascadeId) && (
                                                               u.CascadeId.Contains(inferiorTask.CascadeId) ||
                                                               inferiorTask.CascadeId.Contains(u.CascadeId)))
                               .ToList();

                    treeList.AddRange(list);
                }
            }
            else
            {
                treeList = allTaskList.ToList();
            }

            var taskTree = treeList.GenerateVueTaskTree(u => u.Id, u => u.ParentId);

            // 处理返回tree 添加根节点 根节点名称为项目名称
            var project = SimpleDb.GetSingle(u => u.Id == projectId);
            var result  = new Dictionary <string, object>
            {
                { "id", 0 }, { "label", project.Name }, { "children", taskTree }, { "chargeUserName", project.ChargeUserName },
                { "status", 0 }
            };

            return(result);
        }
Example #11
0
        /// <summary>
        /// 开始任务操作按钮
        /// </summary>
        /// <param name="taskId"></param>
        public void beginTask(int taskId)
        {
            // 修改任务状态为 进行中
            var task = SimpleDb.AsQueryable().Where(u => u.Id == taskId).First();

            task.Status = 1;
            SimpleDb.Update(task);

            // 新增任务记录:开始任务
            var taskRecord = new TaskRecord
            {
                Status        = 1,
                CreateTime    = DateTime.Now,
                Desc          = "任务开始",
                SubmitterId   = user.UserId,
                SubmitterName = user.UserName,
                TaskId        = taskId
            };

            Db.Insertable(taskRecord).ExecuteCommand();
        }
        /// <summary>
        /// 通过token获取用户信息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public Dictionary <string, object> getInfo(string token)
        {
            var result = _cacheContext.Get <UserAuthSession>(token);

            // 获取用户角色
            var roleList = Db.Queryable <UserRole, Role>((ur, r) =>
                                                         new object[] { JoinType.Left, ur.RoleId == r.Id }).Where(ur => ur.UserId == result.UserId)
                           .Select((ur, r) => new { r.Name }).ToList();

            // 获取用户头像
            var avatar = SimpleDb.GetSingle(u => u.userId == result.UserId).avatar;

            return(new Dictionary <string, object>
            {
                { "name", result.UserName },
                { "userId", result.UserId },
                { "wechatUserId", result.WechatUserId },
                { "avatar", avatar },
                { "role", roleList }
            });
        }
        /// <summary>
        /// 获取我已提交
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public PageResponse <string> getMySubmitList(QueryPendingRequest request)
        {
            var query = SimpleDb.AsQueryable().Where(u => u.SubmitterId == user.UserId && u.Desc.Contains(request.key));

            if (!string.IsNullOrEmpty(request.startTime) && !string.IsNullOrEmpty(request.endTime))
            {
                query = query.Where(u => SqlFunc.Between(u.CreateTime, request.startTime, request.endTime));
            }

            var total = 0;
            var json  = query.Select(u => new
            {
                id         = u.Id, submitterName = u.SubmitterName, desc = u.Desc, status = u.Status, createTime = u.CreateTime,
                attachment = u.Attachment, percent = u.Percent, taskId = u.TaskId
            }).ToPageList(request.page, request.limit, ref total).ToJson();

            // 此处返回json的原因是 目前审批类别只有任务完成情况 以后可能会新增审批类别 所以统一转成json返回
            var pageResponse = new PageResponse <string> {
                Total = total, Result = json
            };

            return(pageResponse);
        }
 public RecommendationsController(SimpleDb dbContext)
 {
     _dbContext = dbContext;
 }
Example #15
0
 /// <summary>
 /// 批量更新任务占比
 /// </summary>
 /// <param name="list"></param>
 public void updateTaskWeight(List <Task> list)
 {
     SimpleDb.UpdateRange(list);
 }
Example #16
0
 /// <summary>
 /// 异步更新
 /// </summary>
 /// <param name="columns">要更新的列的内容</param>
 /// <param name="whereLambda">更新条件</param>
 /// <returns></returns>
 public async Task <bool> UpdateEntityAsync(Expression <Func <T, T> > columns, Expression <Func <T, bool> > whereLambda)
 {
     return(await SimpleDb.UpdateAsync(columns, whereLambda));
 }
Example #17
0
        /// <summary>
        /// 找出同级别任务的占比 来进行百分百分配
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        public List <Task> getSameLevelTask(int taskId)
        {
            var task = SimpleDb.GetSingle(u => u.Id == taskId);

            return(SimpleDb.AsQueryable().Where(u => u.ParentId == task.ParentId).ToList());
        }
Example #18
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public bool UpdateEntity(T t)
 {
     return(SimpleDb.Update(t));
 }
Example #19
0
 /// <summary>
 /// 任务删除
 /// </summary>
 /// <param name="taskId"></param>
 public void deleteTask(int taskId)
 {
     SimpleDb.DeleteById(taskId);
     Db.Deleteable <TaskRecord>().Where(u => u.TaskId == taskId);
 }
Example #20
0
 protected SimpleDb SimpleDb() {
     const string domainName = "ToDoAppTests";
     var simpleDb = new SimpleDb(domainName);
     simpleDb.Savant.SimpleDB.DeleteDomain(new DeleteDomainRequest { DomainName = domainName });
     return simpleDb;
 }
Example #21
0
 /// <summary>
 /// 异步更新
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public async Task <bool> UpdateEntityAsync(T t)
 {
     return(await SimpleDb.UpdateAsync(t));
 }
Example #22
0
 public bool Update(User entity)
 {
     return(SimpleDb.Update(entity));
 }
Example #23
0
 public void Setup() {
     simpleDb = SimpleDb();
     laden = new Remote_ToDo_Liste_laden(simpleDb);
     speichern = new Remote_ToDo_Liste_speichern(simpleDb);
 }
Example #24
0
 public User Get(long id)
 {
     return(SimpleDb.GetById(id));
 }
Example #25
0
 public bool Dels(dynamic[] ids)
 {
     return(SimpleDb.DeleteByIds(ids));
 }
Example #26
0
 public bool Add(User entity)
 {
     return(SimpleDb.Insert(entity));
 }
Example #27
0
 /// <summary>
 /// 通过id获取task
 /// </summary>
 /// <param name="taskId"></param>
 /// <returns></returns>
 public Task getTaskById(int taskId)
 {
     return(SimpleDb.GetSingle(u => u.Id == taskId));
 }
Example #28
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="columns">要更新的列的内容</param>
 /// <param name="whereLambda">更新条件</param>
 /// <returns></returns>
 public bool UpdateEntity(Expression <Func <T, T> > columns, Expression <Func <T, bool> > whereLambda)
 {
     return(SimpleDb.Update(columns, whereLambda));
 }
Example #29
0
        /// <summary>
        /// 通过id获取project
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Project getProjectById(int id)
        {
            var project = SimpleDb.GetSingle(u => u.Id == id);

            return(project);
        }
Example #30
0
 /// <summary>
 /// 批量添加
 /// </summary>
 /// <param name="list">对象集合</param>
 /// <returns></returns>
 public bool AddListEntity(List <T> list)
 {
     return(SimpleDb.InsertRange(list));
 }
Example #31
0
 /// <summary>
 /// 异步单个添加
 /// </summary>
 /// <param name="t">添加对象</param>
 /// <returns></returns>
 public async Task <bool> AddEntityAsync(T t)
 {
     return(await SimpleDb.InsertAsync(t));
 }
Example #32
0
 /// <summary>
 /// 异步批量添加
 /// </summary>
 /// <param name="list">对象集合</param>
 /// <returns></returns>
 public async Task <bool> AddListEntityAsync(List <T> list)
 {
     return(await SimpleDb.InsertRangeAsync(list));
 }