fix 调试问题
This commit is contained in:
@@ -21,39 +21,42 @@ public class MiddleService : IMiddleService
|
||||
public async Task<OrderResultResponse> MiddleUploadAsync(BalanceRecordEntity entity)
|
||||
{
|
||||
entity.Id = 0;
|
||||
await _dbContext.InsertAsync(entity);
|
||||
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
if (!await _dbContext.Queryable<BalanceRecordEntity>().AnyAsync(x => x.No == entity.No))
|
||||
{
|
||||
var mealUser = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == entity.UserCode).FirstAsync();
|
||||
if (mealUser == null)
|
||||
await _dbContext.InsertAsync(entity);
|
||||
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
mealUser = new GainfoMealEntity
|
||||
var mealUser = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == entity.UserCode).FirstAsync();
|
||||
if (mealUser == null)
|
||||
{
|
||||
UserNo = entity.No,
|
||||
UserCode = entity.UserCode,
|
||||
Balance = 0,
|
||||
BalanceOfRecharge = 0,
|
||||
BalanceOfSubsidies = 0,
|
||||
Version = 0
|
||||
};
|
||||
mealUser = new GainfoMealEntity
|
||||
{
|
||||
UserNo = entity.No,
|
||||
UserCode = entity.UserCode,
|
||||
Balance = 0,
|
||||
BalanceOfRecharge = 0,
|
||||
BalanceOfSubsidies = 0,
|
||||
Version = 0
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(mealUser);
|
||||
}
|
||||
await _dbContext.InsertAsync(mealUser);
|
||||
}
|
||||
|
||||
//重新核算
|
||||
var balance = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.UserCode == entity.UserCode)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.SumAsync(x => x.Amount);
|
||||
//重新核算
|
||||
var balance = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.UserCode == entity.UserCode)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.SumAsync(x => x.Amount);
|
||||
|
||||
await _dbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.Balance == balance)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserCode == mealUser.UserCode && x.Version == mealUser.Version)
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}, 5);
|
||||
await _dbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.Balance == balance)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserCode == mealUser.UserCode && x.Version == mealUser.Version)
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}, 5);
|
||||
}
|
||||
|
||||
//获取人员余额
|
||||
return await _dbContext.Queryable<GainfoMealEntity>()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Middle.Entities;
|
||||
|
||||
public class LocalBalanceRecordEntity : BalanceRecordEntity
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public new int Id { get; set; }
|
||||
|
||||
public bool IsSync { get; set; }
|
||||
|
||||
@@ -1,8 +1,52 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace Dlhis.Middle.Entities;
|
||||
|
||||
public class LocalBusinessShiftMealRelationshipEntity : BusinessShiftMealRelationshipEntity
|
||||
[SugarTable(TableName = "BusinessShiftMealRelationship", TableDescription = "营业点餐次组合")]
|
||||
public class LocalBusinessShiftMealRelationshipEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
public new int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 餐别Code
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "餐别Code", UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })]
|
||||
public Guid ShiftCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐别手工号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "餐别编码")]
|
||||
public string ShiftCustomCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 餐次
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "餐次", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert), UniqueGroupNameList = new[] { "idx_CanteenBusinessShiftRelationship_shiftcode_shifttype" })]
|
||||
public ShiftEnumType ShiftType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 经营开始时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "经营开始时间")]
|
||||
public DateTime Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 经营结束时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "经营结束时间")]
|
||||
public DateTime End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 序号
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "序号")]
|
||||
public int Sequence { get; set; }
|
||||
|
||||
|
||||
public string TenantId { get; set; }
|
||||
|
||||
}
|
||||
@@ -33,6 +33,7 @@ public class Startup : DefaultStartup
|
||||
|
||||
return handler;
|
||||
});
|
||||
services.AddHostedService<BalanceRecordCheckBackgroundService>();
|
||||
services.AddHostedService<HealthCheckBackgroundService>();
|
||||
services.AddMemoryCache();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
|
||||
namespace Dlhis.Middle.Request;
|
||||
|
||||
public class OrderAddRequest
|
||||
public class OrderAddRequest : IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否离线数据
|
||||
@@ -37,4 +38,15 @@ public class OrderAddRequest
|
||||
public DateTime? CostDateTime { get; set; }
|
||||
|
||||
public string Image { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (!CostDateTime.HasValue)
|
||||
{
|
||||
CostDateTime = DateTime.Now;
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
@@ -24,12 +24,8 @@ public class OrderResultResponse
|
||||
/// </summary>
|
||||
public string DepartmentName { get; set; }
|
||||
|
||||
|
||||
[JsonIgnore]
|
||||
public decimal CurrentBalance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 余额
|
||||
/// </summary>
|
||||
public string Balance => CurrentBalance.ToString("f2");
|
||||
public decimal Balance { get; set; }
|
||||
}
|
||||
@@ -11,8 +11,5 @@ public interface ICanteenSettingService : IScopeDependency
|
||||
/// <param name="tenantId"></param>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<CanteenSettingItemEnumType, string>> GetUserSettingAsync(string userNo, string tenantId);
|
||||
|
||||
|
||||
Task<TimeOnly?> GetBusinessSwitchTimeAsync(string tenantId);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ public class BalanceRecordCheckBackgroundService : BackgroundService
|
||||
var balanceRecords = await db.Queryable<LocalBalanceRecordEntity>().Where(x => x.TenantId == factory).Where(x => !x.IsSync).ToListAsync(stoppingToken);
|
||||
if (balanceRecords.Any())
|
||||
{
|
||||
_logger.LogInformation("上传离线订单");
|
||||
foreach (var balanceRecord in balanceRecords)
|
||||
{
|
||||
await db.Client.Ado.BeginTranAsync();
|
||||
@@ -70,9 +71,8 @@ public class BalanceRecordCheckBackgroundService : BackgroundService
|
||||
if (r.Code == ApiStateCode.Success)
|
||||
{
|
||||
var d = r.Data;
|
||||
var balance = decimal.Parse(d.Balance);
|
||||
await db.Updateable<LocalGainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == balance)
|
||||
.SetColumns(x => x.Balance == d.Balance)
|
||||
.Where(x => x.UserCode == d.UserCode)
|
||||
.ExecuteCommandAsync(stoppingToken);
|
||||
|
||||
@@ -144,7 +144,7 @@ public class BalanceRecordCheckBackgroundService : BackgroundService
|
||||
|
||||
var tokenResponse = await httpClient.PostAsync($"https://{_hostName}/api/User/OAuth2/clientgrant", new StringContent(JsonConvert.SerializeObject(new
|
||||
{
|
||||
ClientId = "e569c2aaa98e300c",
|
||||
ClientId = "e509c2aaa98e300c",
|
||||
ClientSecret = "6184d8979fc48105"
|
||||
}), Encoding.UTF8, "application/json"));
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Dlhis.Middle.Entities;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
@@ -19,7 +20,7 @@ public class CanteenSettingService : ICanteenSettingService
|
||||
|
||||
public async Task<Dictionary<CanteenSettingItemEnumType, string>> GetUserSettingAsync(string userNo, string tenantId)
|
||||
{
|
||||
var settings = await _context.Queryable<CanteenSettingEntity>()
|
||||
var settings = await _context.Queryable<LocalCanteenSettingEntity>()
|
||||
.Where(x => x.Enable)
|
||||
.Where(x => x.TenantId == tenantId)
|
||||
.Where(x => x.UniqueType == CanteenSettingUnqiueEnumType.Person && x.UniqueValue == userNo || x.UniqueType == CanteenSettingUnqiueEnumType.Tenant)
|
||||
@@ -33,72 +34,4 @@ public class CanteenSettingService : ICanteenSettingService
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task<TimeOnly?> GetBusinessSwitchTimeAsync(string tenantId)
|
||||
{
|
||||
var setting = await _context.Queryable<CanteenSettingEntity>()
|
||||
.Where(x => x.Enable)
|
||||
.Where(x => x.TenantId == tenantId)
|
||||
.Where(x => x.Item == CanteenSettingItemEnumType.BusinessSwitchTime)
|
||||
.FirstAsync();
|
||||
|
||||
try
|
||||
{
|
||||
return TimeOnly.Parse(setting.Value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//*********************************************** help methods ***************************************************//
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检验参数
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
private static bool IsValidFormat<T>(string value, CanteenSettingItemEnumType? type = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//判断0/1
|
||||
if (type == CanteenSettingItemEnumType.AllowSendAtMeal ||
|
||||
type == CanteenSettingItemEnumType.AllowRepeatInOneShift ||
|
||||
type == CanteenSettingItemEnumType.AllowNoBalance ||
|
||||
type == CanteenSettingItemEnumType.AllowCrossTenant)
|
||||
{
|
||||
var intvaule = int.Parse(value);
|
||||
if (intvaule == 0 || intvaule == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == CanteenSettingItemEnumType.BusinessSwitchTime)
|
||||
{
|
||||
var timeOnly = value.Adapt<TimeOnly>();
|
||||
return timeOnly.Minute == 0 && timeOnly.Second == 0;
|
||||
}
|
||||
|
||||
//mapster
|
||||
value.Adapt<T>();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace Dlhis.Middle.Services.Implements;
|
||||
|
||||
public class HealthCheckService : IHealthCheckService
|
||||
{
|
||||
private bool _isOffline = true;
|
||||
private bool _isOffline = false;
|
||||
private readonly string _hostName;
|
||||
private readonly ILogger<HealthCheckService> _logger;
|
||||
private int _successRetry;
|
||||
@@ -26,14 +26,14 @@ public class HealthCheckService : IHealthCheckService
|
||||
var tcpClient = new TcpClient();
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("tcp connecting {host} {port}", _hostName, 443);
|
||||
_logger.LogDebug("tcp connecting {host} {port}", _hostName, 443);
|
||||
await tcpClient.ConnectAsync(_hostName, 443);
|
||||
_retry++;
|
||||
_logger.LogInformation("retry {retry}", _retry);
|
||||
_logger.LogDebug("retry {retry}", _retry);
|
||||
if (tcpClient.Connected)
|
||||
{
|
||||
_successRetry++;
|
||||
_logger.LogInformation("success connected {count}", _successRetry);
|
||||
_logger.LogDebug("success connected {count}", _successRetry);
|
||||
if (_successRetry == 4)
|
||||
{
|
||||
_isOffline = false;
|
||||
@@ -43,7 +43,7 @@ public class HealthCheckService : IHealthCheckService
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("wait next check in {waitTime}", _successRetry * 1000);
|
||||
_logger.LogDebug("wait next check in {waitTime}", _successRetry * 1000);
|
||||
await Task.Delay(_successRetry * 1000);
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class HealthCheckService : IHealthCheckService
|
||||
{
|
||||
_successRetry = 0;
|
||||
_isOffline = true;
|
||||
_logger.LogInformation("current is {status}", "unavailable");
|
||||
_logger.LogDebug("current is {status}", "unavailable");
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +42,8 @@ public class OrderService : IOrderService
|
||||
if (remoteResult.Code == ApiStateCode.Success)
|
||||
{
|
||||
var d = remoteResult.Data;
|
||||
var balance = decimal.Parse(d.Balance);
|
||||
await _dbContext.Updateable<LocalGainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == balance)
|
||||
.SetColumns(x => x.Balance == d.Balance)
|
||||
.Where(x => x.UserCode == d.UserCode)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
@@ -52,15 +51,12 @@ public class OrderService : IOrderService
|
||||
return remoteResult;
|
||||
}
|
||||
|
||||
//尝试匹配userId
|
||||
_ = long.TryParse(request.UserUniqueNo, out var userId);
|
||||
|
||||
//根据档案号
|
||||
var gainfo = await _dbContext.Queryable<LocalGainfoEntity>()
|
||||
.Where(x => x.Code == request.UserUniqueNo || x.Id == userId || x.CardNo == request.UserUniqueNo)
|
||||
.Where(x => x.Code == request.UserUniqueNo || x.CardNo == request.UserUniqueNo)
|
||||
.FirstAsync();
|
||||
|
||||
var message = string.Empty;
|
||||
var message = "消费成功";
|
||||
|
||||
gainfo.ThrowIfNull("无消费权限");
|
||||
|
||||
@@ -78,9 +74,9 @@ public class OrderService : IOrderService
|
||||
|
||||
|
||||
//获取人员余额
|
||||
var data = await _dbContext.Queryable<GainfoEntity>()
|
||||
.LeftJoin<DepartmentEntity>((ga, department) => ga.DepartmentNo == department.No)
|
||||
.LeftJoin<GainfoMealEntity>((ga, department, mealUser) => ga.No == mealUser.UserNo)
|
||||
var data = await _dbContext.Queryable<LocalGainfoEntity>()
|
||||
.LeftJoin<LocalDepartmentEntity>((ga, department) => ga.DepartmentNo == department.No)
|
||||
.LeftJoin<LocalGainfoMealEntity>((ga, department, mealUser) => ga.No == mealUser.UserNo)
|
||||
.Where(ga => ga.Id == gainfo.Id)
|
||||
.Select((ga, department, mealUser) => new OrderResultResponse
|
||||
{
|
||||
@@ -88,7 +84,7 @@ public class OrderService : IOrderService
|
||||
UserName = ga.Name,
|
||||
DepartmentNo = ga.DepartmentNo,
|
||||
DepartmentName = department.Name,
|
||||
CurrentBalance = mealUser.Balance
|
||||
Balance = mealUser.Balance
|
||||
})
|
||||
.SingleAsync();
|
||||
|
||||
@@ -134,8 +130,8 @@ public class OrderService : IOrderService
|
||||
|
||||
var shift = shifts.FirstOrDefault(x => new TimePeriod
|
||||
{
|
||||
Start = x.Start,
|
||||
End = x.End
|
||||
Start = TimeOnly.FromDateTime(x.Start),
|
||||
End = TimeOnly.FromDateTime(x.End)
|
||||
}.IsPresent1(request.CostDateTime));
|
||||
shift.ThrowIfNull("非就餐时间,无法消费");
|
||||
|
||||
@@ -192,7 +188,7 @@ public class OrderService : IOrderService
|
||||
{
|
||||
var gainfoMeal = await _dbContext.Queryable<LocalGainfoMealEntity>().Where(x => x.UserNo == balanceRecord.UserNo).SingleAsync();
|
||||
//金额+-
|
||||
gainfoMeal.Balance += balanceRecord.Amount;
|
||||
gainfoMeal.Balance -= Math.Abs(balanceRecord.Amount);
|
||||
|
||||
(gainfoMeal.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
|
||||
@@ -217,7 +213,7 @@ public class OrderService : IOrderService
|
||||
/// <param name="shift"></param>
|
||||
/// <param name="costDateTime"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<DateTime> GetCostDateAsync(BusinessShiftMealRelationshipEntity shift, DateTime costDateTime)
|
||||
private async Task<DateTime> GetCostDateAsync(LocalBusinessShiftMealRelationshipEntity shift, DateTime costDateTime)
|
||||
{
|
||||
var switchTime = await GetSettingAsync<TimeOnly?>(shift.TenantId, CanteenSettingItemEnumType.BusinessSwitchTime);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class RemoteOrderService : IRemoteOrderService
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> AbleRemoteCallAsync()
|
||||
{
|
||||
if (await _dbContext.Queryable<LocalOrderEntity>().AnyAsync(x => !x.IsSync))
|
||||
if (await _dbContext.Queryable<LocalBalanceRecordEntity>().AnyAsync(x => !x.IsSync))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,17 @@
|
||||
"Factory": "",
|
||||
"HostName": "face.jinkosolar.com",
|
||||
"AllowedHosts": "*",
|
||||
"SwaggerOptions": {
|
||||
"Enable": true,
|
||||
"Authority": "http://identity.oauth.svc.cluster.local",
|
||||
"ClientId": "4fb184324eac4180",
|
||||
"ClientSecret": "8ac8f235152f1524",
|
||||
"Scopes": {
|
||||
"openid": "openid",
|
||||
"profile": "profile",
|
||||
"yikatong": "yikatong"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
Reference in New Issue
Block a user