宁波既有建筑外墙脱落问卷调查
This commit is contained in:
@@ -5,241 +5,322 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Util;
|
||||
using Ewide.Core.Service;
|
||||
using Furion;
|
||||
using Furion.ClayObject.Extensions;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DataEncryption;
|
||||
using Furion.DataEncryption.Extensions;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Furion.RemoteRequest.Extensions;
|
||||
using Google.Protobuf.Reflection;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NPOI.HPSF;
|
||||
using Vote.Services.Dto;
|
||||
using Vote.Services.Entities;
|
||||
|
||||
namespace Vote.Services.ApiController
|
||||
{
|
||||
/// <summary>
|
||||
/// 共赴宁波之春
|
||||
/// 外墙调查问卷
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings("outsidewall", Order = 0)]
|
||||
[Route("/gb/yjb/api/outsidewall")]
|
||||
public class OutsideWallService : IDynamicApiController
|
||||
{
|
||||
private readonly IRepository<Entities.nbzc_person> repPerson;
|
||||
private readonly IRepository<Entities.nbzc_sms_code> repSmsCode;
|
||||
private readonly SqlSugarRepository<Entities.outside_wall> repoutside_wall;
|
||||
private readonly SqlSugarRepository<Entities.outside_wall_building> repoutside_wall_building;
|
||||
private readonly SqlSugarRepository<Entities.outside_wall_building_photo> repoutside_wall_building_photo;
|
||||
private readonly SqlSugarRepository<Entities.outside_wall_photo> repoutside_wall_photo;
|
||||
private readonly SqlSugarRepository<SysFile> rep_SysFile;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
readonly IOptions<UploadFileOptions> _options;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="_repNingbo"></param>
|
||||
public OutsideWallService(IRepository<Entities.nbzc_person> _repNingbo, IRepository<Entities.nbzc_sms_code> _repSmsCode, IMemoryCache memoryCache)
|
||||
/// <param name="_repoutside_wall"></param>
|
||||
/// <param name="_repoutside_wall_building"></param>
|
||||
/// <param name="_repoutside_wall_building_photo"></param>
|
||||
/// <param name="_repoutside_wall_photo"></param>
|
||||
/// <param name="memoryCache"></param>
|
||||
public OutsideWallService(SqlSugarRepository<Entities.outside_wall> _repoutside_wall, SqlSugarRepository<Entities.outside_wall_building> _repoutside_wall_building, SqlSugarRepository<Entities.outside_wall_building_photo> _repoutside_wall_building_photo, SqlSugarRepository<Entities.outside_wall_photo> _repoutside_wall_photo, IMemoryCache memoryCache, SqlSugarRepository<SysFile> _rep_SysFile, IOptions<UploadFileOptions> options)
|
||||
{
|
||||
repPerson = _repNingbo;
|
||||
this.repSmsCode = _repSmsCode;
|
||||
repoutside_wall = _repoutside_wall;
|
||||
repoutside_wall_building = _repoutside_wall_building;
|
||||
repoutside_wall_building_photo = _repoutside_wall_building_photo;
|
||||
repoutside_wall_photo = _repoutside_wall_photo;
|
||||
_memoryCache = memoryCache;
|
||||
_options = options;
|
||||
rep_SysFile = _rep_SysFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提交
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[Route("sendcode")]
|
||||
public async Task<dynamic> SendCode(NbzcSendCodeInput args)
|
||||
/// 获取三居系统中的社区
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("query/{id}")]
|
||||
public async Task<dynamic> Query(string id)
|
||||
{
|
||||
//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<int>("NingboZhiChun:OpenSms") == 1)
|
||||
var entity = await repoutside_wall.AsQueryable().FirstAsync(a => a.communityId == id);
|
||||
if (entity != null)
|
||||
{
|
||||
var cacheTokenValue = _memoryCache.Get<string>(_timeCacheKey);
|
||||
if (string.IsNullOrEmpty(cacheTokenValue))
|
||||
{
|
||||
var rslt = await App.GetConfig<string>("NingboZhiChun:SmsTokenUrl").SetBody(new { username = App.GetConfig<string>("NingboZhiChun:SmsAccount"), password = App.GetConfig<string>("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<string>("NingboZhiChun:SmsSendUrl")
|
||||
.SetHttpMethod(HttpMethod.Post)
|
||||
.SetHeaders(new Dictionary<string, object> { { "Authorization", "Bearer " + cacheTokenValue } })
|
||||
.SetBody(new { phone_number = args.phone, sms_content = $"您的验证码是:{code},10分钟内有效。" })
|
||||
.SendAsStringAsync();
|
||||
if (!Newtonsoft.Json.Linq.JObject.Parse(sendrslt)["issuccess"].Value<bool>())
|
||||
throw Oops.Oh("验证码短信发送失败.");
|
||||
var outside_wall_photos = await repoutside_wall_photo.AsQueryable().Where(a => a.outsidewallId == entity.Id).ToListAsync();
|
||||
entity.outside_wall_photos = outside_wall_photos;
|
||||
var outside_wall_buildings = await repoutside_wall_building.AsQueryable().Where(a => a.outsidewallId == entity.Id).ToListAsync();
|
||||
entity.outside_wall_buildings = outside_wall_buildings;
|
||||
return entity;
|
||||
}
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 提交
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
public async Task<dynamic> SubmitSubmit(NbzcSubmitInput args)
|
||||
/// 获取三居系统中的社区
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("communitys")]
|
||||
public async Task<List<SanjuCommunity>> GetCommunitys(string searchkey)
|
||||
{
|
||||
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<int>("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
|
||||
var cacheKey = "cache_GetCommunitys";
|
||||
List<SanjuCommunity> Communitys = null;
|
||||
Communitys = _memoryCache.Get<List<SanjuCommunity>>(cacheKey);
|
||||
if (Communitys == null || Communitys.Count == 0)
|
||||
{
|
||||
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
|
||||
//var aaaaaaaaaaaaaa = repoutside_wall.AsQueryable().ToList();
|
||||
var SanjuKey = App.GetConfig<string>("OutsideWallSetting:SanjuKey");
|
||||
var timeStamp = GetTimeStamp();
|
||||
var sign = (SanjuKey + timeStamp).ToMD5Encrypt();
|
||||
var GetCommunitysUrl = App.GetConfig<string>("OutsideWallSetting:GetCommunitys");
|
||||
var GetHouseInfoCitysByCommunityUrl = App.GetConfig<string>("OutsideWallSetting:GetHouseInfoCitysByCommunity");
|
||||
Communitys = await string.Format(GetCommunitysUrl, "")
|
||||
.SetHeaders(new Dictionary<string, object> { { "sign", sign }, { "timeStamp", timeStamp } })
|
||||
.GetAsAsync<List<SanjuCommunity>>();
|
||||
_memoryCache.Set(cacheKey, Communitys, DateTime.Now.AddHours(1));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(searchkey))
|
||||
return Communitys.Where(a => a.Name.Contains(searchkey)).ToList();
|
||||
return Communitys;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取三居系统中的社区
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("community/{id}")]
|
||||
public async Task<dynamic> GetCommunityInfo(string id)
|
||||
{
|
||||
var cacheKey = "cache_building_" + id;
|
||||
List<SanjuBuilding> building = _memoryCache.Get<List<SanjuBuilding>>(cacheKey);
|
||||
if (building == null)
|
||||
{
|
||||
var SanjuKey = App.GetConfig<string>("OutsideWallSetting:SanjuKey");
|
||||
var timeStamp = GetTimeStamp();
|
||||
var sign = (SanjuKey + timeStamp).ToMD5Encrypt();
|
||||
var GetHouseInfoCitysByCommunityUrl = App.GetConfig<string>("OutsideWallSetting:GetHouseInfoCitysByCommunity");
|
||||
building = await string.Format(GetHouseInfoCitysByCommunityUrl, id)
|
||||
.SetHeaders(new Dictionary<string, object> { { "sign", sign }, { "timeStamp", timeStamp } })
|
||||
.GetAsAsync<List<SanjuBuilding>>();
|
||||
_memoryCache.Set(cacheKey, building, DateTime.Now.AddHours(1));
|
||||
}
|
||||
return building;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时间戳
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string GetTimeStamp()
|
||||
{
|
||||
TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
return Convert.ToInt64(ts.TotalMilliseconds).ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 上传文件
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost("sysFileInfo/upload")]
|
||||
public async Task<string> UploadFileDefault(IFormFile file)
|
||||
{
|
||||
return await UploadFile(file, _options.Value.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除文件
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("sysFileInfo/delete/{id}")]
|
||||
public async Task DeleteFile(string id)
|
||||
{
|
||||
var entity = await rep_SysFile.AsQueryable().FirstAsync(a => a.Id == id);
|
||||
_ = entity == null ? throw Oops.Oh("参数异常") : "";
|
||||
var pathType = _options.Value.Default.path;
|
||||
var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, pathType);
|
||||
File.Delete(Path.Combine(filePath, entity.FileObjectName));
|
||||
await rep_SysFile.DeleteAsync(id);
|
||||
}
|
||||
/// <summary>
|
||||
/// 预览文件
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("sysFileInfo/preview/{id}")]
|
||||
public async Task<IActionResult> PreviewFileInfo(string id)
|
||||
{
|
||||
var file = await rep_SysFile.AsQueryable().FirstAsync(a => a.Id == id);
|
||||
_ = file == null ? throw Oops.Oh("参数异常") : "";
|
||||
var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, file.FileBucket, file.FileObjectName);
|
||||
var fileName = HttpUtility.UrlEncode(file.FileOriginName?.Replace(" ", null).Replace("\"", null), Encoding.UTF8);
|
||||
return new FileStreamResult(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Ewide.Core.Util.MimeMapping.GetMimeMapping(filePath)) { FileDownloadName = fileName };
|
||||
//return await DownloadFileInfo(input);
|
||||
}
|
||||
/// <summary>
|
||||
/// 上传文件
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="pathType"></param>
|
||||
/// <returns></returns>
|
||||
private static async Task<string> UploadFile(IFormFile file, FileDescription fileOption)
|
||||
{
|
||||
var pathType = fileOption.path;
|
||||
var mimeType = Ewide.Core.Util.MimeMapping.GetMimeMapping(file.FileName);
|
||||
if (!fileOption.contentType.Contains(mimeType))
|
||||
{
|
||||
throw Oops.Oh("上传文件mimeType错误!");
|
||||
}
|
||||
var fileId = Guid.NewGuid().ToString();
|
||||
var fileSizeKb = (long)(file.Length / 1024.0); // 文件大小KB
|
||||
if (fileSizeKb > fileOption.maxSize)
|
||||
{
|
||||
throw Oops.Oh("文件大小超过最大限制!");
|
||||
}
|
||||
var originalFilename = file.FileName; // 文件原始名称
|
||||
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
|
||||
var finalName = fileId + fileSuffix; // 生成文件的最终名称
|
||||
var filePath = Path.Combine(App.WebHostEnvironment.WebRootPath, pathType);
|
||||
if (!Directory.Exists(filePath))
|
||||
Directory.CreateDirectory(filePath);
|
||||
|
||||
using (var stream = File.Create(Path.Combine(filePath, finalName)))
|
||||
{
|
||||
await file.CopyToAsync(stream);
|
||||
}
|
||||
|
||||
var sysFileInfo = new SysFile
|
||||
{
|
||||
Id = fileId,
|
||||
FileLocation = (int)FileLocation.LOCAL,
|
||||
FileBucket = pathType,
|
||||
FileObjectName = finalName,
|
||||
FileOriginName = originalFilename,
|
||||
FileSuffix = fileSuffix.TrimStart('.'),
|
||||
FileSizeKb = fileSizeKb
|
||||
};
|
||||
model = await model.InsertOrUpdate();
|
||||
lastSend.IsDeleted = true;
|
||||
await repSmsCode.UpdateIncludeAsync(lastSend, new string[] { nameof(lastSend.IsDeleted) });
|
||||
var token = JWTEncryption.Encrypt(new Dictionary<string, object>() // 加密
|
||||
{
|
||||
{ "UserId", model.Id },
|
||||
{ "Account",model.phone }
|
||||
});
|
||||
return new { success = true, token };
|
||||
//await rep_SysFile.InsertAsync(sysFileInfo);
|
||||
await sysFileInfo.InsertAsync();
|
||||
|
||||
return fileId;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取我的报名
|
||||
/// 提交
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[Route("getmyinfo")]
|
||||
public async Task<dynamic> GetMyInfo(NbzcGetMyInfoInput args)
|
||||
[Consumes("application/json", "multipart/form-data")]
|
||||
[HttpPost("submit")]
|
||||
[AllowAnonymous]
|
||||
public async Task<dynamic> Submit([FromForm] OutsideWallInput args)
|
||||
{
|
||||
var newToken = args.token;
|
||||
nbzc_person entity = null;
|
||||
if (!string.IsNullOrEmpty(args.token))
|
||||
try
|
||||
{
|
||||
var tokenData = JWTEncryption.ReadJwtToken(args.token);
|
||||
//_ = (tokenData == null) ? throw Oops.Oh("您还没有提交过或者手机号码填写错误") : 1;
|
||||
if (tokenData == null)
|
||||
repoutside_wall.Ado.BeginTran();
|
||||
var wall = args.Adapt<outside_wall>();
|
||||
wall.Id = Guid.NewGuid().ToString();
|
||||
wall.createtime = DateTime.Now;
|
||||
wall.isdeleted = 0;
|
||||
wall = await repoutside_wall.InsertReturnEntityAsync(wall);
|
||||
if (args.fileList != 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<string, object>()
|
||||
foreach (var item in args.fileList)
|
||||
{
|
||||
{ "UserId", entity.Id },
|
||||
{ "Account",entity.phone }
|
||||
});
|
||||
await repoutside_wall_photo.InsertReturnEntityAsync(new outside_wall_photo
|
||||
{
|
||||
outsidewallId = wall.Id,
|
||||
sysfileid = item
|
||||
});
|
||||
}
|
||||
}
|
||||
foreach (var item in args.buildings)
|
||||
{
|
||||
var build = item.Adapt<outside_wall_building>();
|
||||
build.Id = Guid.NewGuid().ToString();
|
||||
build.outsidewallId = wall.Id;
|
||||
build.BuildingId = build.Id;
|
||||
build.createtime = DateTime.Now;
|
||||
build = await repoutside_wall_building.InsertReturnEntityAsync(build);
|
||||
if (item.problemfiles != null)
|
||||
{
|
||||
foreach (var item1 in item.problemfiles)
|
||||
{
|
||||
await repoutside_wall_building_photo.InsertReturnEntityAsync(new outside_wall_building_photo
|
||||
{
|
||||
outsidewallBuildingId = build.Id,
|
||||
sysfileid = item1.file,
|
||||
toward = item1.Toward
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
repoutside_wall.Ado.CommitTran();
|
||||
return "提交成功";
|
||||
}
|
||||
return new { success = true, entity, token = newToken };
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取时间线路人数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||||
[Route("getnumber")]
|
||||
public async Task<dynamic> GetNumber(NbzcGetNumberInput args)
|
||||
{
|
||||
var n = await repPerson.DetachedEntities.Where(a => !a.IsDeleted && a.date == args.date).CountAsync();
|
||||
return new { success = true, n = App.GetConfig<int>("NingboZhiChun:TotalCount") - n };
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取清单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
[Route("GetPersonList")]
|
||||
public async Task<dynamic> GetPersonList(NbzcGetListInput args)
|
||||
{
|
||||
var list = await repPerson.DetachedEntities.Where(a => !a.IsDeleted).OrderByDescending(a => a.CreatedTime).ToListAsync();
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导出Excel
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
[Route("export_excel")]
|
||||
public async Task<dynamic> 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 };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[UnitOfWork]
|
||||
[Route("query")]
|
||||
public async Task<dynamic> Query(NbzcQueryInput args)
|
||||
{
|
||||
List<nbzc_person> result = null;
|
||||
var iquery = repPerson.DetachedEntities.Where(a => !a.IsDeleted);
|
||||
if (args == null)
|
||||
result = await iquery.ToListAsync();
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
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();
|
||||
repoutside_wall.Ado.RollbackTran();
|
||||
throw Oops.Oh(ex.Message + ex.StackTrace);
|
||||
}
|
||||
return new { success = true, result };
|
||||
//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<int>("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<string, object>() // 加密
|
||||
//{
|
||||
// { "UserId", model.Id },
|
||||
// { "Account",model.phone }
|
||||
//});
|
||||
//return new { success = true, token };
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user