diff --git a/20220330_Vote/Ewide.Core/Service/File/Dto/FileOutput.cs b/20220330_Vote/Ewide.Core/Service/File/Dto/FileOutput.cs index ae043d6..0fe4308 100644 --- a/20220330_Vote/Ewide.Core/Service/File/Dto/FileOutput.cs +++ b/20220330_Vote/Ewide.Core/Service/File/Dto/FileOutput.cs @@ -11,4 +11,9 @@ public string Id { get; set; } public System.DateTime CreatedTime { get; set; } } + public class FileUploadsOutput + { + public string fileName { get; set; } + public string fileId { get; set; } + } } diff --git a/20220330_Vote/Ewide.Core/Service/File/SysFileService.cs b/20220330_Vote/Ewide.Core/Service/File/SysFileService.cs index 25c9447..55602c8 100644 --- a/20220330_Vote/Ewide.Core/Service/File/SysFileService.cs +++ b/20220330_Vote/Ewide.Core/Service/File/SysFileService.cs @@ -120,7 +120,42 @@ namespace Ewide.Core.Service { return await UploadFile(file, _configuration["UploadFile:Default:path"]); } - + /// + /// 上传文件 + /// + /// + /// + [HttpPost("/sysFileInfo/uploads")] + public async Task> UploadFilesDefault([FromForm] List files) + { + var list = new List(); + foreach (var file in files) + { + list.Add(await UploadFile(file, _configuration["UploadFile:Default:path"])); + } + return list; + } + /// + /// 批量上传文件 + /// + /// + /// + [Consumes("application/json", "multipart/form-data")] + [AllowAnonymous] + [HttpPost("/sysFileInfo/uploads")] + public async Task UploadFileDefault([FromForm] FormFileCollection files) + { + var rslt = new List(); + if (files?.Count > 20) + throw Oops.Oh("每次最多上传20个文件"); + foreach (var file in files) + { + var fileId = await UploadFile(file, _configuration["UploadFile:Default:path"]); + var fileoutput = new FileUploadsOutput { fileId = fileId, fileName = file.FileName }; + rslt.Add(fileoutput); + } + return rslt; + } /// /// 下载文件 /// @@ -152,7 +187,7 @@ namespace Ewide.Core.Service /// public async Task UploadFileDocument(IFormFile file) { - return await UploadFile(file, _configuration["UploadFile:Document:path"]); + return await UploadFile(file, _configuration["UploadFile:Document:path"]); } /// diff --git a/20220330_Vote/Ewide.Web.Entry/Controllers/OutsideWallController.cs b/20220330_Vote/Ewide.Web.Entry/Controllers/OutsideWallController.cs new file mode 100644 index 0000000..c65ae2e --- /dev/null +++ b/20220330_Vote/Ewide.Web.Entry/Controllers/OutsideWallController.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Ewide.Web.Entry.Controllers +{ + public class OutsideWallController : Controller + { + [AllowAnonymous] + public IActionResult Index() + { + return View(); + } + } +} diff --git a/20220330_Vote/Ewide.Web.Entry/Views/OutsideWall/Index.cshtml b/20220330_Vote/Ewide.Web.Entry/Views/OutsideWall/Index.cshtml new file mode 100644 index 0000000..4be905d --- /dev/null +++ b/20220330_Vote/Ewide.Web.Entry/Views/OutsideWall/Index.cshtml @@ -0,0 +1,878 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ +} + + + + + + + + + + + + + + +
+

宁波既有建筑外墙脱落问卷调查

+ + + + + + + + @* + + + + + + + + + + + *@ + + + + +
上传外墙照片
+
只能上传jpg/png文件,且不超过500kb
+
+ @*this.$refs.upload.submit();*@ + @* + 点击上传 +
只能上传jpg/png文件,且不超过500kb
+
*@ +
+ + + + + + + + + + + + + + + 例如:漏水、开裂、脱落 + + + + + + + + + + + + + + + @* + + + + + + + + + + + + + + *@ + + 14.问题发生后是否请人修复了? + + + + + + + 15.请提供修复单位的名称: + + + + 16.修复后的部位是否再次发生问题? + + + + + + + 20.若您愿意接受我们的现场调查,请惠赐您的联系方式。谢谢! + + + + + + + + + + + + 提交报名 + 我的报名 + +
+ + +
+ + + + + \ No newline at end of file diff --git a/20220330_Vote/Vote.Services/ApiController/OutsideWallService.cs b/20220330_Vote/Vote.Services/ApiController/OutsideWallService.cs new file mode 100644 index 0000000..8bec0a8 --- /dev/null +++ b/20220330_Vote/Vote.Services/ApiController/OutsideWallService.cs @@ -0,0 +1,245 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Ewide.Core; +using Ewide.Core.Util; +using Furion; +using Furion.ClayObject.Extensions; +using Furion.DatabaseAccessor; +using Furion.DataEncryption; +using Furion.DynamicApiController; +using Furion.FriendlyException; +using Furion.RemoteRequest.Extensions; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Caching.Memory; +using Newtonsoft.Json.Linq; +using Vote.Services.Dto; +using Vote.Services.Entities; + +namespace Vote.Services.ApiController +{ + /// + /// 共赴宁波之春 + /// + [ApiDescriptionSettings("outsidewall", Order = 0)] + [Route("/gb/yjb/api/outsidewall")] + public class OutsideWallService : IDynamicApiController + { + private readonly IRepository repPerson; + private readonly IRepository repSmsCode; + private readonly IMemoryCache _memoryCache; + /// + /// + /// + /// + public OutsideWallService(IRepository _repNingbo, IRepository _repSmsCode, IMemoryCache memoryCache) + { + repPerson = _repNingbo; + this.repSmsCode = _repSmsCode; + _memoryCache = memoryCache; + } + + /// + /// 提交 + /// + /// + [HttpPost] + [UnitOfWork] + [Microsoft.AspNetCore.Authorization.AllowAnonymous] + [Route("sendcode")] + public async Task SendCode(NbzcSendCodeInput args) + { + //var data = await repSmsCode.DetachedEntities.Where(p => p.phone == args.phone && !p.IsDeleted && p.expire_time > DateTime.Now) + // .FirstOrDefaultAsync(); + //_ = (data != null) ? throw Oops.Oh("已存在此号码的有效发送记录,不可重复发送") : 1; + var lastSend = await repSmsCode.DetachedEntities.Where(p => p.phone == args.phone && !p.IsDeleted).OrderByDescending(a => a.CreatedTime).FirstOrDefaultAsync(); + _ = lastSend != null && DateTime.Now <= lastSend.CreatedTime.Value.AddMinutes(1) ? throw Oops.Oh("发送过于频繁,请1分钟后再试") : 1; + + //_ = (await repPerson.DetachedEntities.Where(a => !a.IsDeleted && (a.phone == args.phone || a.cardno == args.cardno)).CountAsync() > 0) ? throw Oops.Oh("您已提交,无需再次获取验证码") : 1; + string _timeCacheKey = "sms_token_" + args.phone; + var code = new Random().Next(1001, 9999); + if (App.GetConfig("NingboZhiChun:OpenSms") == 1) + { + var cacheTokenValue = _memoryCache.Get(_timeCacheKey); + if (string.IsNullOrEmpty(cacheTokenValue)) + { + var rslt = await App.GetConfig("NingboZhiChun:SmsTokenUrl").SetBody(new { username = App.GetConfig("NingboZhiChun:SmsAccount"), password = App.GetConfig("NingboZhiChun:SmsPwd") }, "application/json").SetHttpMethod(HttpMethod.Post).SendAsStringAsync(); + cacheTokenValue = Newtonsoft.Json.Linq.JObject.Parse(rslt)["data"]["token"].ToString(); + var cacheEntryOptions = new MemoryCacheEntryOptions() + .SetSlidingExpiration(TimeSpan.FromMinutes(100)); + _memoryCache.Set(_timeCacheKey, cacheTokenValue, cacheEntryOptions); + } + var sendrslt = await App.GetConfig("NingboZhiChun:SmsSendUrl") + .SetHttpMethod(HttpMethod.Post) + .SetHeaders(new Dictionary { { "Authorization", "Bearer " + cacheTokenValue } }) + .SetBody(new { phone_number = args.phone, sms_content = $"您的验证码是:{code},10分钟内有效。" }) + .SendAsStringAsync(); + if (!Newtonsoft.Json.Linq.JObject.Parse(sendrslt)["issuccess"].Value()) + throw Oops.Oh("验证码短信发送失败."); + } + await new Entities.nbzc_sms_code + { + code = code.ToString(), + CreatedTime = DateTime.Now, + expire_time = DateTime.Now.AddMinutes(10), + IsDeleted = false, + phone = args.phone + }.InsertOrUpdate(); + return true; + } + /// + /// 提交 + /// + /// + [HttpPost] + [UnitOfWork] + [Microsoft.AspNetCore.Authorization.AllowAnonymous] + public async Task SubmitSubmit(NbzcSubmitInput args) + { + var lastSend = await repSmsCode.DetachedEntities.Where(p => p.phone == args.phone && !p.IsDeleted).OrderByDescending(a => a.CreatedTime).FirstOrDefaultAsync(); + _ = (lastSend == null || lastSend.code != args.code || lastSend.expire_time < DateTime.Now) ? throw Oops.Oh("验证码错误或已失效") : 1; + var totalCount = await repPerson.DetachedEntities.Where(a => !a.IsDeleted && a.date == args.date).CountAsync(); + _ = totalCount >= App.GetConfig("NingboZhiChun:TotalCount") ? throw Oops.Oh("提交失败,名额已满。") : 1; + _ = (await repPerson.DetachedEntities.Where(a => !a.IsDeleted && (a.phone == args.phone || a.cardno == args.cardno)).CountAsync() > 0) ? throw Oops.Oh("您已提交,无需再次提交") : 1; + var now = DateTime.Now; + var model = new Entities.nbzc_person + { + address = args.address, + phone = args.phone, + cardno = args.cardno, + CreatedTime = DateTime.Now, + date = args.date, + hangye = args.hangye, + IsDeleted = false, + line = args.line, + name = args.name, + weixin_number = args.weixin_number + }; + model = await model.InsertOrUpdate(); + lastSend.IsDeleted = true; + await repSmsCode.UpdateIncludeAsync(lastSend, new string[] { nameof(lastSend.IsDeleted) }); + var token = JWTEncryption.Encrypt(new Dictionary() // 加密 + { + { "UserId", model.Id }, + { "Account",model.phone } + }); + return new { success = true, token }; + } + /// + /// 获取我的报名 + /// + /// + [HttpPost] + [UnitOfWork] + [Microsoft.AspNetCore.Authorization.AllowAnonymous] + [Route("getmyinfo")] + public async Task GetMyInfo(NbzcGetMyInfoInput args) + { + var newToken = args.token; + nbzc_person entity = null; + if (!string.IsNullOrEmpty(args.token)) + { + var tokenData = JWTEncryption.ReadJwtToken(args.token); + //_ = (tokenData == null) ? throw Oops.Oh("您还没有提交过或者手机号码填写错误") : 1; + if (tokenData == null) + { + newToken = null; + } + else + { + var userId = tokenData.Claims.Where(a => a.Type == "UserId").FirstOrDefault().Value; + entity = await repPerson.DetachedEntities.Where(a => a.Id == userId).FirstOrDefaultAsync(); + } + } + else + { + _ = (string.IsNullOrEmpty(args.code)) ? throw Oops.Oh("验证码错误或已失效") : 1; + var lastSend = await repSmsCode.DetachedEntities.Where(p => p.phone == args.phone && !p.IsDeleted).OrderByDescending(a => a.CreatedTime).FirstOrDefaultAsync(); + _ = (lastSend == null || lastSend.code != args.code || lastSend.expire_time < DateTime.Now) ? throw Oops.Oh("验证码错误或已失效") : 1; + entity = await repPerson.DetachedEntities.Where(a => a.phone == args.phone && !a.IsDeleted).FirstOrDefaultAsync(); + if (entity != null) + newToken = JWTEncryption.Encrypt(new Dictionary() + { + { "UserId", entity.Id }, + { "Account",entity.phone } + }); + } + return new { success = true, entity, token = newToken }; + } + /// + /// 获取时间线路人数 + /// + /// + [HttpPost] + [UnitOfWork] + [Microsoft.AspNetCore.Authorization.AllowAnonymous] + [Route("getnumber")] + public async Task GetNumber(NbzcGetNumberInput args) + { + var n = await repPerson.DetachedEntities.Where(a => !a.IsDeleted && a.date == args.date).CountAsync(); + return new { success = true, n = App.GetConfig("NingboZhiChun:TotalCount") - n }; + } + /// + /// 获取清单 + /// + /// + [HttpPost] + [UnitOfWork] + [Route("GetPersonList")] + public async Task GetPersonList(NbzcGetListInput args) + { + var list = await repPerson.DetachedEntities.Where(a => !a.IsDeleted).OrderByDescending(a => a.CreatedTime).ToListAsync(); + return list; + } + + + + /// + /// 导出Excel + /// + /// + [HttpPost] + [UnitOfWork] + [Route("export_excel")] + public async Task ExportExcel(NbzcGetListInput args) + { + var list = await repPerson.DetachedEntities.Where(a => !a.IsDeleted).OrderByDescending(a => a.CreatedTime).ToListAsync(); + var filepath = Tools.ExcelHelper.WriteExcelNingBoZhiChun(list); + return new FileStreamResult(new FileStream(filepath, FileMode.Open), "application/octet-stream") { FileDownloadName = filepath }; + } + + /// + /// 查询 + /// + /// + [HttpPost] + [UnitOfWork] + [Route("query")] + public async Task Query(NbzcQueryInput args) + { + List result = null; + var iquery = repPerson.DetachedEntities.Where(a => !a.IsDeleted); + if (args == null) + result = await iquery.ToListAsync(); + else + { + if (!string.IsNullOrEmpty(args.date)) + iquery = iquery.Where(a => a.date == args.date); + if (!string.IsNullOrEmpty(args.name)) + iquery = iquery.Where(a => a.name.Contains(args.name)); + if (!string.IsNullOrEmpty(args.phone)) + iquery = iquery.Where(a => a.phone.Contains(args.phone)); + if (!string.IsNullOrEmpty(args.line)) + iquery = iquery.Where(a => a.line == args.line); + result = await iquery.ToListAsync(); + } + return new { success = true, result }; + } + } +}