feat 电子餐券
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
using Dlhis.Canteen.EMealVoucher.Request;
|
||||
using Dlhis.Canteen.EMealVoucher.Response;
|
||||
using Dlhis.Canteen.EMealVoucher.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -8,4 +12,65 @@ namespace Dlhis.Canteen.EMealVoucher.Controllers;
|
||||
[ApiController]
|
||||
public class EMealVoucherController : ControllerBase
|
||||
{
|
||||
private readonly IEMealVoucherService _eMealVoucherService;
|
||||
|
||||
public EMealVoucherController(IEMealVoucherService eMealVoucherService)
|
||||
{
|
||||
_eMealVoucherService = eMealVoucherService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取我的电子餐券申请
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("my")]
|
||||
public async Task<Pagination<EMealVoucherPageResponse>> GetMyEMealVoucherPageAsync([FromQuery] EMealVoucherPageRequest request)
|
||||
{
|
||||
return await _eMealVoucherService.GetMyEMealVoucherPageAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查看电子餐券
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("no")]
|
||||
public async Task<List<EMealVoucherDetailResponse>> GetDetailsByNoAsync(string no)
|
||||
{
|
||||
return await _eMealVoucherService.GetDetailsByNoAsync(no);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取url签名
|
||||
/// </summary>
|
||||
/// <param name="detailId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("signature")]
|
||||
public async Task<string> GetQrCodeSignatureAsync(long detailId)
|
||||
{
|
||||
return await _eMealVoucherService.GetQrCodeSignatureAsync(detailId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新url签名
|
||||
/// </summary>
|
||||
/// <param name="detailId"></param>
|
||||
[HttpPost("signature/refresh")]
|
||||
public async Task RefreshSignatureAsync(long detailId)
|
||||
{
|
||||
await _eMealVoucherService.RefreshSignatureAsync(detailId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取二维码
|
||||
/// </summary>
|
||||
/// <param name="signature"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("qrcode")]
|
||||
public async Task<string> GetQrCodeAsync(string signature)
|
||||
{
|
||||
return await _eMealVoucherService.GetQrCodeAsync(signature);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Canteen.EMealVoucher.Request;
|
||||
|
||||
public class EMealVoucherPageRequest : PageDto
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace Dlhis.Canteen.EMealVoucher.Response;
|
||||
|
||||
public class EMealVoucherDetailResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用餐人
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 手机号
|
||||
/// </summary>
|
||||
public string Phone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 就餐开始
|
||||
/// </summary>
|
||||
public DateTime Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 就餐结束
|
||||
/// </summary>
|
||||
public DateTime End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 金额
|
||||
/// </summary>
|
||||
public decimal Balance { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Dlhis.Canteen.EMealVoucher.Response;
|
||||
|
||||
public class EMealVoucherPageResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
public string No { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Dlhis.Canteen.EMealVoucher.Request;
|
||||
using Dlhis.Canteen.EMealVoucher.Response;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Canteen.EMealVoucher.Services;
|
||||
|
||||
public interface IEMealVoucherService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<EMealVoucherPageResponse>> GetMyEMealVoucherPageAsync(EMealVoucherPageRequest request);
|
||||
|
||||
Task<List<EMealVoucherDetailResponse>> GetDetailsByNoAsync(string no);
|
||||
|
||||
Task<string> GetQrCodeSignatureAsync(long detailId);
|
||||
|
||||
Task RefreshSignatureAsync(long detailId);
|
||||
|
||||
Task<string> GetQrCodeAsync(string signature);
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using System.Text;
|
||||
using Dlhis.Canteen.EMealVoucher.Request;
|
||||
using Dlhis.Canteen.EMealVoucher.Response;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Canteen.EMealVoucher.Services.Implements;
|
||||
|
||||
public class EMealVoucherService : IEMealVoucherService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
|
||||
public EMealVoucherService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
|
||||
public async Task<Pagination<EMealVoucherPageResponse>> GetMyEMealVoucherPageAsync(EMealVoucherPageRequest request)
|
||||
{
|
||||
var code = _currentUser.GetUserClaim("jinko-code");
|
||||
code = "0123456";
|
||||
return await _dbContext.Queryable<EMealVoucherEntity>()
|
||||
.Where(x => x.Code == code)
|
||||
.OrderBy(x => x.Id, OrderByType.Desc)
|
||||
.Select<EMealVoucherPageResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<EMealVoucherDetailResponse>> GetDetailsByNoAsync(string no)
|
||||
{
|
||||
return await _dbContext.Queryable<EMealVoucherDetailEntity>()
|
||||
.Where(x => x.No == no)
|
||||
.Select<EMealVoucherDetailResponse>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> GetQrCodeSignatureAsync(long detailId)
|
||||
{
|
||||
return await GenerateSignatureAsync(detailId, false);
|
||||
}
|
||||
|
||||
public async Task RefreshSignatureAsync(long detailId)
|
||||
{
|
||||
await GenerateSignatureAsync(detailId, true);
|
||||
}
|
||||
|
||||
private async Task<string> GenerateSignatureAsync(long detailId, bool isRefresh)
|
||||
{
|
||||
var eMealVoucherDetail = await _dbContext.Queryable<EMealVoucherDetailEntity>().Where(x => x.Id == detailId).SingleAsync();
|
||||
eMealVoucherDetail.ThrowIfNull("数据不存在");
|
||||
if (eMealVoucherDetail.Signature.IsPresent())
|
||||
{
|
||||
if (isRefresh)
|
||||
{
|
||||
await _dbContext.Deleteable<EMealVoucherDetailQrCodeEntity>().Where(x => x.Signature == eMealVoucherDetail.Signature).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return eMealVoucherDetail.Signature;
|
||||
}
|
||||
}
|
||||
|
||||
eMealVoucherDetail.Signature = Guid.NewGuid().ToString().Replace("-", "") + DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
await _dbContext.UpdateAsync(eMealVoucherDetail);
|
||||
|
||||
return eMealVoucherDetail.Signature;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<string> GetQrCodeAsync(string signature)
|
||||
{
|
||||
var eMealVoucherDetail = await _dbContext.Queryable<EMealVoucherDetailEntity>().Where(x => x.Signature == signature).SingleAsync();
|
||||
eMealVoucherDetail.ThrowIfNull("无效地址");
|
||||
var eMealVoucher = await _dbContext.Queryable<EMealVoucherEntity>().Where(x => x.No == eMealVoucherDetail.No).SingleAsync();
|
||||
|
||||
var ts = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString().Reverse().Join(string.Empty);
|
||||
var originData = string.Concat(eMealVoucher.No, ":", ts, ":", eMealVoucher.Code, ":", eMealVoucherDetail.IdNo);
|
||||
|
||||
var qrCode = "02" + originData.ToArray().Select(x =>
|
||||
{
|
||||
var b = Encoding.ASCII.GetBytes(x.ToString());
|
||||
int i = b[0];
|
||||
return Convert.ToString(i);
|
||||
}).Join(string.Empty);
|
||||
|
||||
|
||||
await _dbContext.InsertAsync(new EMealVoucherDetailQrCodeEntity
|
||||
{
|
||||
Signature = signature,
|
||||
OriginData = originData,
|
||||
QrCode = qrCode
|
||||
});
|
||||
|
||||
return qrCode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user