Beispiel #1
0
        public async Task <string> AddAsync(ProjectAddDto dto, string createId, string cqpUrl)
        {
            var entity = _mapper.Map <ProjectAddDto, ProjectEntity>(dto);

            entity.Init();
            entity.CreateUserId  = createId;
            entity.ProjectStatus = ProjectStatus.OnStart;//项目为起始状态
            var dbSet = _context.Projects;

            dbSet.Add(entity);
            var user = await _context.Users.FirstOrDefaultAsync(c => c.Id == createId);

            var chargePerson = await _context.Users.FirstOrDefaultAsync(c => c.Id == entity.ChargePersonId);

            if (user != null)
            {
                long.TryParse(user.UserQq, out long UserQQ);
                var cqp = new CQPHelper(cqpUrl);
                await cqp.SendPrivateMessage(new PrivateMsgDto
                {
                    qqid = UserQQ,
                    msg  = $"您好!项目:{entity.ProjectTitle} 已经被记录!负责人:{chargePerson?.RealName},QQ:{chargePerson?.UserQq}",
                });

                long.TryParse(entity.ChargePerson.UserQq, out long ChargeQQ);
                await cqp.SendPrivateMessage(new PrivateMsgDto
                {
                    qqid = ChargeQQ,
                    msg  = $"您好!项目:{entity.ProjectTitle} 已经被客服{user.RealName} 记录!客服QQ:{user.UserQq},请及时处理!",
                });
            }
            return(await _context.SaveChangesAsync() > 0 ? entity.Id : string.Empty);
        }
Beispiel #2
0
        public async Task <BaseResponse> AddProjectAsync(ProjectAddDto req, string account, string GroupId)
        {
            var data = await _pr.Find(a => a.GroupId == GroupId && a.ParentId == req.ParentId && a.Name == req.Name).FirstOrDefaultAsync();

            if (data != null)
            {
                return(new BaseResponse {
                    Success = false, Message = "该项目下已存在相同名称的项目或者场站"
                });
            }

            string pathId = null, PathName = null;

            //获取父项目
            if (req.ParentId.HasValue)     //存在父节点
            {
                var parent = await _pr.FindAsync(req.ParentId.Value);

                if (parent == null)
                {
                    return(new BaseResponse {
                        Success = false, Message = "输入的父项目不存在"
                    });
                }
                if (parent.ParentId == null)
                {
                    pathId   = $"{req.ParentId.Value}";
                    PathName = $"{parent.Name}";
                }
                else
                {
                    pathId   = $"{parent.PathId}/{req.ParentId.Value}";
                    PathName = $"{parent.PathName}/{parent.Name}";
                }
            }

            try
            {
                var entity = _mapper.Map <ProjectModel>(req);
                entity.Create   = account;
                entity.PathId   = pathId;
                entity.PathName = PathName;
                entity.GroupId  = GroupId;
                await _pr.AddAsync(entity);

                _log.LogInformation($"{account}添加标示为{entity.Id}项目名称为{entity.Name}的项目成功");
                return(new HandleResponse <int> {
                    Success = true, Message = "添加成功", Key = entity.Id
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}添加项目{req.Name}失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "添加失败,请联系管理员"
                });
            }
        }
Beispiel #3
0
        public async Task <ActionResult <BaseResponse> > Add(string GroupId, ProjectAddDto req)
        {
            var    GId     = User.Claims.FirstOrDefault(a => a.Type == "GroupId").Value;
            var    isAdmin = User.Claims.FirstOrDefault(a => a.Type == "IsAdmin").Value.ToLower() == "true" ? true : false;
            string Code    = User.Claims.FirstOrDefault(a => a.Type == "Code").Value;
            string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value;
            string Roles   = User.Claims.FirstOrDefault(a => a.Type == "Role").Value;

            if (req.ProjectType == 1 && !req.ParentId.HasValue)
            {
                return(new BaseResponse {
                    Success = false, Message = "场站必须添加在项目下"
                });
            }
            //是否管理员
            if (isAdmin)
            {
                if (GroupId != GId && Code != _config["Group"])
                {
                    return(new BaseResponse {
                        Success = false, Message = "用户没有权限添加此项目"
                    });
                }
            }
            else
            {
                if (req.ParentId.HasValue && req.ParentId.Value != 0)
                {
                    return(new BaseResponse {
                        Success = false, Message = "用户没有权限添加顶级项目"
                    });
                }
                else//非顶级项目
                {
                    string fullPath;
                    fullPath = await _ps.GetPathId(req.ParentId.Value);

                    if (fullPath == null)
                    {
                        return(new BaseResponse {
                            Success = false, Message = "输入的父项目不存在"
                        });
                    }
                    var bRet = await _rp.IsAuth(Roles, fullPath, 3);

                    if (!bRet)
                    {
                        return(new BaseResponse {
                            Success = false, Message = "用户没有权限添加此项目或者场站"
                        });
                    }
                }
            }
            var ret = await _ps.AddProjectAsync(req, Account, GroupId);

            return(ret);
        }
        public async Task <IActionResult> ServiceAdd(ProjectAddDto dto)
        {
            if (ModelState.IsValid)
            {
                var result = await _ProjectService.AddAsync(dto, User.Identity.GetLoginUserId(), _Configuration.GetSection("CqpApiUrl").Value);

                if (result.IsNotBlank())
                {
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.SettleInterval = EnumExtensions.SelectListFor(dto.SettleInterval);
            ViewBag.ProjectType    = EnumExtensions.SelectListFor(dto.ProjectType);
            return(View(dto));
        }