add simutil cstNow, other times use this prop
This commit is contained in:
@@ -10,6 +10,11 @@ namespace SimApi.Helpers
|
|||||||
{
|
{
|
||||||
public static class SimApiUtil
|
public static class SimApiUtil
|
||||||
{
|
{
|
||||||
|
public static DateTime CstNow
|
||||||
|
{
|
||||||
|
get => DateTime.UtcNow.AddHours(8);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 检测手机号是否正确
|
/// 检测手机号是否正确
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -60,7 +65,7 @@ namespace SimApi.Helpers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static DateTime GetCstNow()
|
public static DateTime GetCstNow()
|
||||||
{
|
{
|
||||||
return DateTime.UtcNow.AddHours(8);
|
return CstNow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SimApi.Helpers;
|
||||||
|
|
||||||
namespace SimApi.Logger
|
namespace SimApi.Logger
|
||||||
{
|
{
|
||||||
@@ -30,7 +31,7 @@ namespace SimApi.Logger
|
|||||||
_ => defautColor
|
_ => defautColor
|
||||||
};
|
};
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
$"[ {Name} ][ {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")} ][ {logLevel.ToString()} ]");
|
$"[ {Name} ][ {SimApiUtil.CstNow.ToString("yyyy-MM-dd HH:mm:ss:ffff")} ][ {logLevel.ToString()} ]");
|
||||||
Console.ForegroundColor = defautColor;
|
Console.ForegroundColor = defautColor;
|
||||||
Console.WriteLine($"{state}");
|
Console.WriteLine($"{state}");
|
||||||
if (exception != null)
|
if (exception != null)
|
||||||
|
|||||||
@@ -1,23 +1,36 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using SimApi.Helpers;
|
||||||
|
|
||||||
namespace SimApi.Models
|
namespace SimApi.Models
|
||||||
{
|
{
|
||||||
public class SimApiBaseModel
|
public class SimApiBaseModel
|
||||||
{
|
{
|
||||||
protected virtual string[] MapperIgnoreField { get; set; } = {"Id", "CreatedAt", "UpdatedAt"};
|
protected virtual string[] MapperIgnoreField { get; set; } =
|
||||||
|
{
|
||||||
|
"Id", "CreatedAt", "UpdatedAt"
|
||||||
|
};
|
||||||
|
|
||||||
protected virtual string UpdatedTimeField { get; set; } = "UpdatedAt";
|
protected virtual string UpdatedTimeField { get; set; } = "UpdatedAt";
|
||||||
|
|
||||||
public void MapData<TS>(TS source, bool mapAll = false)
|
public void MapData<TS>(TS source, bool mapAll = false)
|
||||||
{
|
{
|
||||||
//获取要赋值的源数据不为null的项目
|
//获取要赋值的源数据不为null的项目
|
||||||
var sourceProps = source.GetType().GetProperties().Where(x => x.GetValue(source) != null)
|
var sourceProps = source.GetType().GetProperties().Where(x => x.GetValue(source) != null)
|
||||||
.Select(x => new {x.Name, x.PropertyType})
|
.Select(x => new
|
||||||
|
{
|
||||||
|
x.Name,
|
||||||
|
x.PropertyType
|
||||||
|
})
|
||||||
.ToDictionary(x => x.Name, x => x.PropertyType);
|
.ToDictionary(x => x.Name, x => x.PropertyType);
|
||||||
|
|
||||||
//获取目标对象的属性信息
|
//获取目标对象的属性信息
|
||||||
var targetProps = GetType().GetProperties().Select(x => new {x.Name, x.PropertyType})
|
var targetProps = GetType().GetProperties().Select(x => new
|
||||||
|
{
|
||||||
|
x.Name,
|
||||||
|
x.PropertyType
|
||||||
|
})
|
||||||
.ToDictionary(x => x.Name, x => x.PropertyType);
|
.ToDictionary(x => x.Name, x => x.PropertyType);
|
||||||
foreach (var sp in sourceProps)
|
foreach (var sp in sourceProps)
|
||||||
{
|
{
|
||||||
@@ -37,11 +50,19 @@ namespace SimApi.Models
|
|||||||
{
|
{
|
||||||
//获取要赋值的源数据不为null的项目
|
//获取要赋值的源数据不为null的项目
|
||||||
var sourceProps = source.GetType().GetProperties().Where(x => x.GetValue(source) != null)
|
var sourceProps = source.GetType().GetProperties().Where(x => x.GetValue(source) != null)
|
||||||
.Select(x => new {x.Name, x.PropertyType})
|
.Select(x => new
|
||||||
|
{
|
||||||
|
x.Name,
|
||||||
|
x.PropertyType
|
||||||
|
})
|
||||||
.ToDictionary(x => x.Name, x => x.PropertyType);
|
.ToDictionary(x => x.Name, x => x.PropertyType);
|
||||||
|
|
||||||
//获取目标对象的属性信息
|
//获取目标对象的属性信息
|
||||||
var targetProps = GetType().GetProperties().Select(x => new {x.Name, x.PropertyType})
|
var targetProps = GetType().GetProperties().Select(x => new
|
||||||
|
{
|
||||||
|
x.Name,
|
||||||
|
x.PropertyType
|
||||||
|
})
|
||||||
.ToDictionary(x => x.Name, x => x.PropertyType);
|
.ToDictionary(x => x.Name, x => x.PropertyType);
|
||||||
foreach (var sp in sourceProps)
|
foreach (var sp in sourceProps)
|
||||||
{
|
{
|
||||||
@@ -63,7 +84,7 @@ namespace SimApi.Models
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public void UpdateTime()
|
public void UpdateTime()
|
||||||
{
|
{
|
||||||
GetType().GetProperty(UpdatedTimeField)?.SetValue(this, DateTime.Now);
|
GetType().GetProperty(UpdatedTimeField)?.SetValue(this, SimApiUtil.CstNow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user