public async Task GetSendItems(string historyId)
        {
            var results = LiteDb.Fetch <SendItem>(s => s.historyId == historyId);

            // 获取状态
            await ResponseSuccessAsync(results);
        }
Exemplo n.º 2
0
        public async Task GetAllSuccessRate()
        {
            // 找到当前的用户名
            var userId = Token.UserId;
            // 获取用户发送的历史组
            var historyGroups = LiteDb.Fetch <HistoryGroup>(g => g.userId == userId).ToList();

            if (historyGroups.Count < 1)
            {
                // 返回1
                await ResponseSuccessAsync(1);

                return;
            }
            ;


            // 查找历史组下面的所有的发件
            var sendItems = LiteDb.Fetch <SendItem>(Query.In(Fields.historyId, new BsonArray(historyGroups.ConvertAll(hg => new BsonValue(hg._id)))));

            if (sendItems.Count < 1)
            {
                // 返回1
                await ResponseSuccessAsync(1);

                return;
            }

            // 计算比例
            var successItems = sendItems.FindAll(item => item.isSent);

            await ResponseSuccessAsync(successItems.Count * 1.0 / sendItems.Count);
        }
Exemplo n.º 3
0
        public async Task GetEmails(string id)
        {
            var group = LiteDb.SingleOrDefault <Group>(g => g._id == id);

            if (group == null)
            {
                await ResponseErrorAsync($"未通过{id}找到组");

                return;
            }

            List <EmailInfo> results = new List <EmailInfo>();

            if (group.groupType == "send")
            {
                var emails = LiteDb.Fetch <SendBox>(e => e.groupId == id).ToList();
                results.AddRange(emails);
            }
            else
            {
                var emails = LiteDb.Fetch <ReceiveBox>(e => e.groupId == id).ToList();
                results.AddRange(emails);
            }

            await ResponseSuccessAsync(results);
        }
        public async Task GetTemplates()
        {
            // 获取用户名
            List <Template> results = LiteDb.Fetch <Template>(t => t.userId == Token.UserId);

            await ResponseSuccessAsync(results);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 生成之后的操作
        /// </summary>
        /// <param name="sendItems"></param>
        /// <param name="receiveBoxes"></param>
        protected override void PreviewItemCreated(List <SendItem> sendItems, List <ReceiveBox> receiveBoxes)
        {
            // 生成发送的组
            // 获取发件箱

            // 判断数据中是否有发件人
            var            senderIds = new List <string>();
            List <SendBox> senders   = null;

            if (senderIds.Count > 0)
            {
                // 使用选择发件人发件
                senders = LiteDb.Fetch <SendBox>(sd => senderIds.Contains(sd._id));
            }
            else
            {
                senders = LiteDb.Database.GetCollection <SendBox>().FindAll().ToList();
            }

            // 添加历史
            HistoryGroup historyGroup = new HistoryGroup()
            {
                userId       = _userId,
                createDate   = DateTime.Now,
                subject      = Subject,
                data         = JsonConvert.SerializeObject(Data),
                receiverIds  = receiveBoxes.ConvertAll(rec => rec._id),
                templateId   = Template._id,
                templateName = Template.name,
                senderIds    = senders.ConvertAll(s => s._id),
                sendStatus   = SendStatus.Sending,
            };

            LiteDb.Database.GetCollection <HistoryGroup>().Insert(historyGroup);

            // 反回发件信息
            _info.historyId = historyGroup._id;

            // 如果选择发件人,默认从数据中读取发件人,所以选择的发件人数量为0
            if (Receivers == null || Receivers.Count < 1)
            {
                _info.selectedReceiverCount = 0;
            }
            else
            {
                _info.selectedReceiverCount = receiveBoxes.Count;
            }

            _info.dataReceiverCount    = Data.Count;
            _info.acctualReceiverCount = sendItems.Count;
            _info.ok          = true;
            _info.senderCount = senders.Count;

            // 将所有的待发信息添加到数据库
            sendItems.ForEach(item => item.historyId = historyGroup._id);
            LiteDb.Database.GetCollection <SendItem>().InsertBulk(sendItems);
        }
        public async Task GetHistory(string historyId)
        {
            var history = LiteDb.SingleById <HistoryGroup>(historyId);

            // 获取成功的数量
            history.successCount = LiteDb.Fetch <SendItem>(s => s.historyId == history._id && s.isSent).Count;


            // 获取状态
            await ResponseSuccessAsync(history);
        }
Exemplo n.º 7
0
        public async Task GetGroups([QueryField] string groupType)
        {
            if (string.IsNullOrEmpty(groupType))
            {
                await ResponseErrorAsync("请传递组的类型:[send,receive]");
            }
            ;

            var results = LiteDb.Fetch <Group>(g => g.groupType == groupType).ToList();

            await ResponseSuccessAsync(results);
        }
        public async Task GetHistories()
        {
            var histories = LiteDb.Fetch <HistoryGroup>(h => h.userId == Token.UserId).OrderByDescending(item => item._id);

            foreach (HistoryGroup history in histories)
            {
                // 获取成功的数量
                history.successCount = LiteDb.Fetch <SendItem>(s => s.historyId == history._id && s.isSent).Count;
            }

            // 获取状态
            await ResponseSuccessAsync(histories);
        }
Exemplo n.º 9
0
        public async Task GetHistoryResult(string id)
        {
            HistoryGroup historyGroup = LiteDb.SingleById <HistoryGroup>(id);
            // 获取成功的数量
            int successCount = LiteDb.Fetch <SendItem>(s => s.historyId == id && s.isSent).Count;

            JObject result;

            if (successCount == historyGroup.receiverIds.Count)
            {
                string msg = $"发送成功!共发送:{successCount}/{historyGroup.receiverIds.Count}";
                result = new JObject(new JProperty("message", msg), new JProperty("ok", true));
            }
            else
            {
                string msg = $"未完全发送,共发送:{successCount}/{historyGroup.receiverIds.Count}。请在发件历史中查询重发";
                result = new JObject(new JProperty("message", msg), new JProperty("ok", false));
            }
            await ResponseSuccessAsync(result);
        }
Exemplo n.º 10
0
        public async Task UpdateUserAvatar()
        {
            // 获取 body 传输的 url
            var avatarUrl = Body.SelectToken(Fields.avatar).ValueOrDefault(string.Empty);
            var userId    = Body.SelectToken(Fields.userId).ValueOrDefault(string.Empty);

            if (string.IsNullOrEmpty(avatarUrl))
            {
                await ResponseErrorAsync("请在 data 中传入 avatarUrl");

                return;
            }

            if (string.IsNullOrEmpty(userId))
            {
                await ResponseErrorAsync("请在 data 中传入 userName");

                return;
            }

            var user = LiteDb.Fetch <User>(u => u.userId == userId).FirstOrDefault();

            if (user == null)
            {
                await ResponseErrorAsync("用户不存在");

                return;
            }

            // 更新头像
            LiteDb.Upsert2(s => s.userId == Token.UserId, new User()
            {
                avatar = avatarUrl,
            }, new UpdateOptions()
            {
                Fields.avatar
            });

            await ResponseSuccessAsync("success");
        }
Exemplo n.º 11
0
        public async Task GetINboxTypeAndCount()
        {
            // 找到当前的用户名
            var userId = Token.UserId;
            // 获取用户发送的历史组
            var historyGroups  = LiteDb.Fetch <HistoryGroup>(g => g.userId == userId).ToList();
            var defaultResults = new JArray()
            {
                new JObject()
                {
                    { "name", "未发件" }, { "value", 0 }
                }
            };

            if (historyGroups.Count < 1)
            {
                // 返回默认值
                try
                {
                    await ResponseSuccessAsync(defaultResults);
                }
                catch (Exception e)
                {
                    ;
                }
                return;
            }
            ;


            // 查找历史组下面的所有的发件
            var sendItems = LiteDb.Fetch <SendItem>(Query.In(Fields.historyId, new BsonArray(historyGroups.ConvertAll(hg => new BsonValue(hg._id)))));

            if (sendItems.Count < 1)
            {
                // 返回1
                await ResponseSuccessAsync(defaultResults);

                return;
            }

            // 计算每个邮箱对应的值
            Dictionary <string, int> resultDic = new Dictionary <string, int>();
            var regex = new Regex(@"@\w+([-.]\w+)*\.\w+([-.]\w+)*$");

            foreach (var sendItem in sendItems)
            {
                var emailType = regex.Match(sendItem.receiverEmail);
                if (!emailType.Success)
                {
                    continue;
                }

                var typeKey = emailType.Value;
                if (resultDic.ContainsKey(typeKey))
                {
                    resultDic[typeKey] = resultDic[typeKey] + 1;
                }
                else
                {
                    resultDic.Add(typeKey, 1);
                }
            }

            await ResponseSuccessAsync(resultDic.ToList().ConvertAll(item =>
            {
                return(new JObject(new JProperty(Fields.name, item.Key), new JProperty(Fields.value, item.Value)));
            }));
        }