This commit is contained in:
2021-10-19 06:29:11 +08:00
commit 60131e4608
131 changed files with 46479 additions and 0 deletions
+113
View File
@@ -0,0 +1,113 @@
@page
@model _2021_backend.Pages.Message.IndexModel
@{
}
@{
ViewData["Title"] = "发送短信";
}
<h5 class="text-red">
<strong>@Html.DisplayFor(model => Model.Errmsg)</strong>
</h5>
<h3><strong>发送短信</strong></h3>
<form method="post">
<input type="hidden" asp-for="pageid" />
<input type="submit" value="拉取5天内的回复短信" class="btn btn-primary" asp-page-handler="Pull" />
<input type="submit" value="发送报名确认短信" class="btn btn-primary" asp-page-handler="Sign" />
<input type="submit" value="发送确认短信" class="btn btn-primary" asp-page-handler="ResultAccept" />
<input type="submit" value="发送拒绝短信" class="btn btn-primary" asp-page-handler="ResultReject" />
</form>
<br />
<h3><strong>短信记录</strong></h3>
<hr />
<form method="post" class="form-inline">
<input type="hidden" asp-for="pageid" />
<div class="m-2">
<label class="form-check-label">
<input class="form-check-input" asp-for="showSend" />发出的短信
</label>
</div>
<div class="m-2">
<label class="form-check-label">
<input class="form-check-input" asp-for="showReceive" /> 收到的短信
</label>
</div>
<label asp-for="SearchString" class="control-label">按名字筛选</label>
<div class="m-2">
<input type="text" class="form-control" id="searchString" placeholder="输入部分姓名" asp-for="SearchString" name="SearchString">
</div>
<input type="submit" class="btn btn-primary" value="Go!" />
</form>
<table class="table">
<thead>
<tr>
<th>
发送者
</th>
<th>
学生姓名
</th>
<th>
发送时间
</th>
<th>
短信类型
</th>
<th>
短信内容
</th>
</tr>
</thead>
<tbody>
@if (Model.Messages.Count == 0)
{
@:暂无短信
}
else
{
@foreach (var e in Model.Messages)
{
<tr>
<td>
@Html.DisplayFor(it => e.Sender)
</td>
<td>
@{
var stu = Model.Context.Students.Find(e.Host);
string name = stu.Name;
@Html.DisplayFor(it => name)
}
</td>
<td>
@{
var str = e.SendTime.ToString("MM月dd日 hh:mm:ss");
@Html.DisplayFor(it => str)
}
</td>
<td>
@Html.DisplayFor(it => e.Type)
</td>
<td>
@if (e.Type == _2021_backend.Models.SMSType.Reply)
{
@Html.DisplayFor(it => e.Data[0])
}
</td>
</tr>
}
}
</tbody>
</table>
<nav>
<ul class="pagination">
<li class="page-item @(Model.pageid==0 ? "disabled" : "")"><a class="page-link" asp-route-pageId="@(Model.pageid-1) " >Prev</a></li>
@for (int i = 0; i < Model.PageCount; i++)
{
<li class="page-item @(Model.pageid==i ? "active" : "")"><a class="page-link" asp-route-pageId="@i" >@i</a></li>
}
<li class="page-item @(Model.pageid>=Model.PageCount -1? "disabled" : "")"><a class="page-link" asp-route-pageId="@(Model.pageid+1)" >Next</a></li>
</ul>
</nav>
+135
View File
@@ -0,0 +1,135 @@
using _2021_backend.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
namespace _2021_backend.Pages.Message
{
public class IndexModel : PageModel
{
public readonly _2021_backend.Data.BackendContext Context;
[BindProperty]
public string Errmsg { get; set; }
[BindProperty]
public string SearchString { get; set; }
[BindProperty]
public bool showSend { get; set; }
[BindProperty]
public bool showReceive { get; set; }
[BindProperty]
public int pageid { get; set; }
public static int pageSize = 30;
public List<SMS> Messages { get; set; }
public int PageCount { get; set; }
public IndexModel(_2021_backend.Data.BackendContext context)
{
Context = context;
}
public IActionResult Construct(int PageId)
{
List<Guid> stus;
IQueryable<Guid> q;
if (!String.IsNullOrEmpty(SearchString)) q = from e in Context.Students where e.Name.Contains(SearchString) select e.Guid;
else q = from e in Context.Students select e.Guid;
stus = q.ToList();
var q2 = from e in Context.SMS where stus.Contains(e.Host) select e;
if (showReceive && !showSend) q2 = from e in q2 where e.Type == SMSType.Reply select e;
else if (!showReceive && showSend) q2 = from e in q2 where e.Type != SMSType.Reply select e;
Messages = q2.ToList();
Messages.Sort((SMS a, SMS b) => b.SendTime.CompareTo(a.SendTime));
int cnt = Messages.Count;
PageCount = (int)Math.Ceiling((double)cnt / (double)pageSize);
if (PageId >= PageCount) PageId = PageCount - 1;
if (PageId < 0) PageId = 0;
pageid = PageId;
int count = (PageId + 1) * pageSize > cnt ? (cnt - PageId * pageSize) : pageSize;
Messages = Messages.GetRange(PageId * pageSize, count);
return Page();
}
public async Task<IActionResult> OnGetAsync(int PageId)
{
return Construct(PageId);
}
public async Task<IActionResult> OnPostAsync(int PageId)
{
return Construct(PageId);
}
public async void OnPostPullAsync(int PageId)
{
var stu = Context.Students.ToList();
foreach (var e in stu)
{
await Utils.TencentSMS.Pull(Context, e, true);
}
Construct(PageId);
}
public async Task<IActionResult> OnPostSignAsync(int PageId)
{
var stu = Context.Students.ToList();
foreach (var e in stu)
{
if (e.Status == status.刚报名)
await Utils.TencentSMS.Send(Context, SMSType.Signed, e, Context.Users.Find(Guid.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
}
return Construct(PageId);
}
public async Task<IActionResult> OnPostResultRejectAsync(int PageId)
{
var stu = Context.Students.ToList();
foreach (var e in stu)
{
if (e.Status == status.不通过)
{
if (!Context.SMS.Any(it => it.Host == e.Guid && it.Type == SMSType.Reject))
await Utils.TencentSMS.Send(Context, SMSType.Reject, e, Context.Users.Find(Guid.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
}
}
return Construct(PageId);
}
public async Task<IActionResult> OnPostResultAccpetAsync(int PageId)
{
var stu = Context.Students.ToList();
foreach (var e in stu)
{
if (e.Status == status.通过)
{
if (!Context.SMS.Any(it => it.Host == e.Guid && it.Type == SMSType.Accept))
await Utils.TencentSMS.Send(Context, SMSType.Accept, e, Context.Users.Find(Guid.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value)).Name);
}
}
return Construct(PageId);
}
}
}